nisargjhaveri / vscode-ios-debug

iOS debugging in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=nisargjhaveri.ios-debug
86 stars 10 forks source link

Predefined variable support #10

Closed gdier closed 1 year ago

gdier commented 1 year ago

My workspace has multi-target applications, so I wrote a vscode plugin for target selection. Now I need create a lot of launch configurations for each target, it works fine but seems ugly :P. May properties like iosBundleId and iosTarget support vscode predefined variables as below?

    {
      "type": "lldb",
      "iosBundleId": "${command:custom-plugin.target-bundle}",
      "iosTarget": "last-selected",
      "name": "iOS",
      "preLaunchTask": "Build Target",
      "program": "${workspaceFolder}/${command:custom-plugin.target-path}",
      "request": "launch",
      "sourceMap": {
        "./": "${workspaceFolder}"
      },
      "presentation": {
        "hidden": false,
        "group": "Build",
      }
    },

Thanks a lot.

nisargjhaveri commented 1 year ago

The config you mentioned should already work. Currently, only iosTarget param is not configurable with variable substitution. Apart from that, variables in iosBundleId, program and other params should work just fine.

Does it not work for you? Does it give any errors? Can you please provide the logs from the output panel in that case?

gdier commented 1 year ago

Thanks for the answer.

As I tested iosBundleId doesn't work, you may simply change bundle id to ${input:xxxx} for test, there is no input box be shown. variables in program is work fine.

The reason why I need iosTarget support variable is that I have some target for local arch test. Seems like keep both iosTarget and iosBundleId blank cause launch for local test, if the plugin only test iOSBundleId, it will be fine too ^_^

[2023-2-6 17:58] [INFO] resolveDebugConfiguration {
    "type": "lldb",
    "iosBundleId": "${input:getIOSBundleId}",
    "iosTarget": "last-selected",
    "name": "iOS",
    "preLaunchTask": "Build Target",
    "program": "${workspaceFolder}/${input:getTargetProgramPath}",
    "request": "launch",
    "sourceMap": {
        "./": "${workspaceFolder}"
    },
    "presentation": {
        "hidden": false,
        "group": "Build"
    },
    "__configurationTarget": 6,
    "relativePathBase": "dhsaflkasdjdflksaj",
    "_adapterSettings": {
        "displayFormat": "auto",
        "showDisassembly": "auto",
        "dereferencePointers": true,
        "suppressMissingSourceFiles": true,
        "evaluationTimeout": 5,
        "consoleMode": "commands",
        "sourceLanguages": null,
        "terminalPromptClear": null,
        "evaluateForHovers": true,
        "commandCompletions": true,
        "reproducer": false
    }
}
gdier commented 1 year ago

Sorry for closed by mistake

nisargjhaveri commented 1 year ago

I tried the following in launch.json with the Sample App . Seems to work for me. It prompts for the bundle id input and launches the app correctly.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Sample App",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/build/Debug-${command:ios-debug.targetSdk}/Sample App.app",
            "iosBundleId": "${input:bundleId}",
            "iosTarget": "select",
            "preLaunchTask": "${defaultBuildTask}"
        }
    ],
    "inputs": [
        {
            "id": "bundleId",
            "type": "promptString",
            "description": "Bundle ID",
        }
    ]
}

The log you provided is just the first entry. There should be an entry with resolveDebugConfigurationWithSubstitutedVariables, which is logged after the variable substitution. Do you see that? If not, some variable resolution might be failing.

nisargjhaveri commented 1 year ago

Supporting variable substitution in iosTarget is slightly tricky. We're using iosTarget as an indication to know if the current debug session is for iOS or not since we're using the underlying lldb as type. Also, we need iosTarget to be resolved before variable substitution to support to ios-debug.target* commands that can be useful for other parameters in the config. I'd be very happy if we can find a solution that can support variable substitutions in iosTarget while still supporting these commands.

The reason why I need iosTarget support variable is that I have some target for local arch test. Seems like keep both iosTarget and iosBundleId blank cause launch for local test, if the plugin only test iOSBundleId, it will be fine too ^_^

We're only checking iosTarget to see if we're targeting iOS or not. When iosTarget is falsy, we simply don't do anything. All the other options are ignored and we and let lldb debugger launch/attach the program locally as it would normally do. For the time being I'd suggest having different configs for iOS and local tests. See the combination of type: "lldb" and iosTarget as a new debugger type if we had one for ios.

gdier commented 1 year ago

Thanks for the sample, it really works for me! I found a bug in my plugin command "getIOSBundleId". So the first question is my fault TAT.

ios-debug plugin helps us a lot, we are using it on an project over million lines, now we can coding and debugging without xcode👍. Thanks again.

Our workspace is like this

libCrossPlatform
-- srcs
-- tests
Apps
-- iOS
---- srcs
-- Android
---- srcs

We put iOS and android projects in one workspace (include uni-tests), we must write separate launch configurations for all target now. This is why I want using single configuration for building and debugging.

As I test simctl launch using bundle id of last install package automatically without input, so checking iosTarget is the right plan. Thanks for your explain, now we are using 3 configurations for iOS or android or local uni-test target.