launch.json's fields have ambiguity with how final target is created:
- There are dedicated fields to specify target like "program", "pid", "waitFor"
- There are "launchCommands" and "attachCommands" fields that might or might not create a target.
Current implementation for handling of "launchCommands" and "attachCommands" implies
they are rather mutually exclusive with other target defining parameters like "program", "pid" etc
in case they create a new target.
So user can provide in the launch.json fields "program", "pid", "core_file" and these parameters
will be silently ignored by implementation in case "launchCommands" and "attachCommands" are provided
as well and create a new target. For attach "core_file" is ignored in case "attachCommands"
field is just provided, no matter whether commands create or not target.
At the same time, implementation always creates target by means of CreateTargetFromArguments()
API in expectance of target dedicated fields in launch.json like "program", "pid", even in case
"launchCommands" and "attachCommands" (that do create a target) are provided.
Creation of this first, "auxilary" target, introduces issue with target settings specified for second
target and created by "launchCommands" or "attachCommands": target settings for the second target are 'hijacked'
by target created by CreateTargetFromArguments() call and not applied to target created
by "launchCommands"/"attachCommands".
For example, for "launchCommands":
settings set target.exec-search-paths /some/path
target create /some/file
target.exec-search-paths is not applied to the final target created in "launchCommands".
The setting is applied to previously created "auxilary" target which doesn't become selected.
This breaks debugging of the target created by "launchCommands"/"attachCommands".
A possible workaround for the issue would be a strict requirement to set target settings
after target creation command, however it might not be feasible for some settings and
inconsistent with cli lldb usage results where this issue is not reproduced.
This change avoids creation of "auxilary" target in case "launchCommands"/"attachCommands"
are provided. It also uses proper SetTarget() setter to set final target and subscribe it
for notifications.
An error is reported in case debug configuration contains target related keys
("program", "coreFile" etc) along with "launchCommands" or "attachCommands".
This change potentially can break the case when user provides "launchCommands"/"attachCommands"
that don't create a target, but rely on the "auxilary" target that they can tune further by commands
in "launchCommands", "attachCommands". This doesn't look like a correct usage intent to me
because it requires from users quite thorough inspection of 'launch'/'attach' requests implementation and
understanding which launch.json fields are ignored or not by implementation.
In case user needs to tune created target I would recommend to create new "postTargetCommands" launch.json
field with clear instructions to not create target and assume that target already exists.
Test plan:
./bin/lldb-dotest ../llvm-project/lldb/test/API/tools/lldb-vscode/
...
Ran 53 tests in 99.606s
RESULT: PASSED (48 passes, 0 failures, 0 errors, 4 skipped, 0 expected failures, 0 unexpected successes)
We can't print to stderr or stdout since this is where the VS code DAP packets get delivered.
We have two options here IMHO:
We can deliver this to the "Debugger Console" using: