lldb: argument starting with hash disappears.

Here's a simple C++ program that echoes its arguments...

#include <stdio.h>

int main(int argc, char* argv[])
{
    for (int i=0; i<argc; ++i) printf("%d  %s\n", i, argv[i]);
}

This works as expected...

> ./test arg1 #arg2 arg3
0  ./test
1  arg1
2  #arg2
3  arg3

Running under lldb gives this...

> lldb ./test arg1 #arg2 arg3
(lldb) target create "./test"
Current executable set to '/Users/richard/Work/test' (arm64).
(lldb) settings set -- target.run-args  "arg1" "#arg2" "arg3"
(lldb) run
Process 6138 launched: '/Users/richard/Work/test' (arm64)
0  /Users/richard/Work/test
1  arg1
Process 6138 exited with status = 0 (0x00000000) 

I get the same if I quote the arguments, or if I add them to the run line. Stepping into main() we see the argv and args values are as though we only had the first argument. If I quote the second argument and add an initial space " #arg1" then it works.

I first saw this on an M1 running Sequoia 13.1. It am now on OS 13.3.

lldb --version
lldb-1600.0.39.109 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)

Answered by DTS Engineer in 823897022

I generally run a command with arguments using r:

% lldb Test773781 
(lldb) target create "Test773781"
;
(lldb) r arg1 #arg2 arg3
;
0 …/Test773781
1 arg1

The interesting thing here is that LLDB has the right arguments:

(lldb) settings show target.run-args
target.run-args (arguments) =
  [0]: "arg1"
  [1]: "#arg2"
  [2]: "arg3"

It’s just not applying them at launch.

Notably, the r command is an alias for process launch:

(lldb) help r
Launch the executable in the debugger.

Syntax: r [<run-args>]
  r [<run-args>]
'r' is an abbreviation for 'process launch -X true --'

Note that -X option. Its long name is --shell-expand-args. If you set it to false, it resolves this issue:

(lldb) process launch -X false 
…
0 …/Test773781
1 arg1
2 #arg2
3 arg3

So it seems that LLDB’s shell-like argument expansion is interpreting the # as a comment. Fun times!

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I generally run a command with arguments using r:

% lldb Test773781 
(lldb) target create "Test773781"
;
(lldb) r arg1 #arg2 arg3
;
0 …/Test773781
1 arg1

The interesting thing here is that LLDB has the right arguments:

(lldb) settings show target.run-args
target.run-args (arguments) =
  [0]: "arg1"
  [1]: "#arg2"
  [2]: "arg3"

It’s just not applying them at launch.

Notably, the r command is an alias for process launch:

(lldb) help r
Launch the executable in the debugger.

Syntax: r [<run-args>]
  r [<run-args>]
'r' is an abbreviation for 'process launch -X true --'

Note that -X option. Its long name is --shell-expand-args. If you set it to false, it resolves this issue:

(lldb) process launch -X false 
…
0 …/Test773781
1 arg1
2 #arg2
3 arg3

So it seems that LLDB’s shell-like argument expansion is interpreting the # as a comment. Fun times!

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It’s better to reply as a reply, rather than in the comments; see Quinn’s Top Ten DevForums Tips for this and other titbits.

so the -X shell processing in lldb is different to the actual shell.

Yes. This is LLDB’s idea of shell processing; it doesn’t invoke an actual shell.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

lldb: argument starting with hash disappears.
 
 
Q