VS Code Version: 1.124.2
OS Version: Ubuntu 26.04 kernel 7.0.0 (compiled from source).
Steps to Reproduce:
1 Find a example C program that demonstrates the use of argp (there are lots around).
2 Using gdb from a command line, debug that app using the "--args" flag plus various args for the app.
for example /usr/bin/gdb --args ./testapp --device=/dev/xyz --syslog --ver=9 --show --quiet --config=/etc/xyz.conf
3 Now try debugging that using Visual Code, without using the launch setting "miDebuggerArgs".
You will find the test app won't process its args corrrectly.
4 Now try debugging again but using the launch setting "miDebuggerArgs": "--args".
You will find the test app still won't process its args correctly.
The problem (this took me an entire day to figure out because the problem wasn't in my test app at all!).
(The following example outputs are from my test app using the different ways of launching gdb described above) .
Debugging my test app using gdb from the command line works perfectly because the "--args" option appears just before the target executable, and so gdb passes all the following arguments to the target main().
ARGP_KEY_INIT
parse_opt() key:64 char:d arg:/dev/xyz
parse_opt() key:6C char:l arg:(null)
parse_opt() key:76 char:v arg:9
parse_opt() key:73 char:s arg:(null)
parse_opt() key:71 char:q arg:(null)
parse_opt() key:63 char:c arg:/etc/xyz.conf
ARGP_KEY_NO_ARGS
ARGP_KEY_END
ARGP_KEY_SUCCESS
ARGP_KEY_FINI
argp_parse() done
The above is the expected output with all app arguments correctly processed.
However using Visual Code debugging without the "miDebuggerArgs": "--args" launch property -
ARGP_KEY_INIT
parse_opt() key:64 char:d arg:/dev/xyz --syslog --verbose=9 --showkey --quiet --config=/etc/xyz.conf
ARGP_KEY_NO_ARGS
ARGP_KEY_END
ARGP_KEY_SUCCESS
ARGP_KEY_FINI
argp_parse() done
This is incorrect. The app only processed a single argument that was the entire argument string given to the app.
And using Visual Code debugging with the "miDebuggerArgs": "--args" launch property -
ARGP_KEY_INIT
parse_opt() key:64 char:d arg:/dev/xyz --syslog --verbose=9 --showkey --quiet --config=/etc/xyz.conf
ARGP_KEY_NO_ARGS
ARGP_KEY_END
ARGP_KEY_SUCCESS
ARGP_KEY_FINI
argp_parse() done
This is still incorrect, adding the "--arg" option via the "miDebuggerArgs" launch property didn't do anything as it was not placed in the correct position when invoking gdb.
I get this in my Visual Code terminal window after a run using the "--arg" property -
[1] + Done "/usr/bin/gdb" --interpreter=mi --args --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-u5ai3hek.04x" 1>"/tmp/Microsoft-MIEngine-Out-lot3j3jx.fqc"
Perhaps Visual Code should have placed "--args" after the "--tty" ????
Steps to Reproduce:
1 Find a example C program that demonstrates the use of argp (there are lots around).
2 Using gdb from a command line, debug that app using the "--args" flag plus various args for the app.
for example /usr/bin/gdb --args ./testapp --device=/dev/xyz --syslog --ver=9 --show --quiet --config=/etc/xyz.conf
3 Now try debugging that using Visual Code, without using the launch setting "miDebuggerArgs".
You will find the test app won't process its args corrrectly.
4 Now try debugging again but using the launch setting "miDebuggerArgs": "--args".
You will find the test app still won't process its args correctly.
The problem (this took me an entire day to figure out because the problem wasn't in my test app at all!).
(The following example outputs are from my test app using the different ways of launching gdb described above) .
Debugging my test app using gdb from the command line works perfectly because the "--args" option appears just before the target executable, and so gdb passes all the following arguments to the target main().
ARGP_KEY_INIT
parse_opt() key:64 char:d arg:/dev/xyz
parse_opt() key:6C char:l arg:(null)
parse_opt() key:76 char:v arg:9
parse_opt() key:73 char:s arg:(null)
parse_opt() key:71 char:q arg:(null)
parse_opt() key:63 char:c arg:/etc/xyz.conf
ARGP_KEY_NO_ARGS
ARGP_KEY_END
ARGP_KEY_SUCCESS
ARGP_KEY_FINI
argp_parse() done
The above is the expected output with all app arguments correctly processed.
However using Visual Code debugging without the "miDebuggerArgs": "--args" launch property -
ARGP_KEY_INIT
parse_opt() key:64 char:d arg:/dev/xyz --syslog --verbose=9 --showkey --quiet --config=/etc/xyz.conf
ARGP_KEY_NO_ARGS
ARGP_KEY_END
ARGP_KEY_SUCCESS
ARGP_KEY_FINI
argp_parse() done
This is incorrect. The app only processed a single argument that was the entire argument string given to the app.
And using Visual Code debugging with the "miDebuggerArgs": "--args" launch property -
ARGP_KEY_INIT
parse_opt() key:64 char:d arg:/dev/xyz --syslog --verbose=9 --showkey --quiet --config=/etc/xyz.conf
ARGP_KEY_NO_ARGS
ARGP_KEY_END
ARGP_KEY_SUCCESS
ARGP_KEY_FINI
argp_parse() done
This is still incorrect, adding the "--arg" option via the "miDebuggerArgs" launch property didn't do anything as it was not placed in the correct position when invoking gdb.
I get this in my Visual Code terminal window after a run using the "--arg" property -
[1] + Done "/usr/bin/gdb" --interpreter=mi --args --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-u5ai3hek.04x" 1>"/tmp/Microsoft-MIEngine-Out-lot3j3jx.fqc"
Perhaps Visual Code should have placed "--args" after the "--tty" ????