def METHOD_NAME(ctx, project_config, env_name, load_mode, verbose, __unprocessed):
    platform = PlatformFactory.from_env(env_name, autoinstall=True)
    debug_config = DebugConfigFactory.new(
        platform,
        project_config,
        env_name,
    )
    if "--version" in __unprocessed:
        raise ReturnErrorCode(
            subprocess.run(
                [debug_config.client_executable_path, "--version"], check=True
            ).returncode
        )
    try:
        fs.ensure_udev_rules()
    except exception.InvalidUdevRules as exc:
        click.echo(str(exc))
    rebuild_prog = False
    preload = debug_config.load_cmds == ["preload"]
    load_mode = load_mode or debug_config.load_mode
    if load_mode == "always":
        rebuild_prog = preload or not helpers.has_debug_symbols(
            debug_config.program_path
        )
    elif load_mode == "modified":
        rebuild_prog = helpers.is_prog_obsolete(
            debug_config.program_path
        ) or not helpers.has_debug_symbols(debug_config.program_path)
    if not (debug_config.program_path and os.path.isfile(debug_config.program_path)):
        rebuild_prog = True
    if preload or (not rebuild_prog and load_mode != "always"):
        # don't load firmware through debug server
        debug_config.load_cmds = []
    if rebuild_prog:
        click.echo("Preparing firmware for debugging...")
        helpers.predebug_project(
            ctx, os.getcwd(), project_config, env_name, preload, verbose
        )
        # save SHA sum of newly created prog
        if load_mode == "modified":
            helpers.is_prog_obsolete(debug_config.program_path)
    if not os.path.isfile(debug_config.program_path):
        raise DebugInvalidOptionsError("Program/firmware is missed")
    return debug_config