LLDB Fails to Handle Empty Arguments

When attempting to pass an empty argument to LLDB, the debugger does not handle the input correctly, resulting in unexpected behavior. This issue arises when trying to provide an empty argument string to LLDB during debugging sessions.

Steps to Reproduce:

  1. Launch LLDB and start debugging a target program.
  2. At a breakpoint or while the program is paused, attempt to input an empty argument by using the appropriate command (e.g., run "" or process launch -- "").
  3. Observe that LLDB does not handle the empty argument as expected and may display errors or unexpected behavior.

Expected Behavior:
LLDB should gracefully handle empty arguments provided through relevant commands during debugging sessions. The debugger should accurately process the empty argument and continue the debugging session without errors or unintended outcomes.

Actual Behavior:
LLDB fails to properly handle empty arguments, potentially leading to error messages or unpredictable behavior during the debugging process.

Additional Information:
This issue can impact debugging workflows where empty arguments are necessary for testing specific program behavior. Providing support for empty arguments in LLDB would enhance its usability and accuracy during debugging sessions.

Environment:
lldb-1403.0.17.67
Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)

Can you attach a terminal session with the commands that lead to to the errors you are seeing? For me (printem just echos the arguments passed to it):

lldb /tmp/printem
(lldb) target create “/tmp/printem”
Current executable set to ‘/tmp/printem’ (arm64).
(lldb) run “”
Process 26099 launched: ‘/tmp/printem’ (arm64)
Arg: 0 - ‘/tmp/printem’
Arg: 1 - ‘’
Process 26099 exited with status = 0 (0x00000000)
(lldb) process launch “”
Process 26113 launched: ‘/tmp/printem’ (arm64)
Arg: 0 - ‘/tmp/printem’
Arg: 1 - ‘’
Process 26113 exited with status = 0 (0x00000000)
(lldb) process launch – “”
Process 26116 launched: ‘/tmp/printem’ (arm64)
Arg: 0 - ‘/tmp/printem’
Arg: 1 - ‘’
Process 26116 exited with status = 0 (0x00000000)

all seem to work.


int main(int argc, char *argv[]) {
    printf("Number of arguments: %d\n", argc);
    
    for (int i = 0; i < argc; i++) {
        printf("Argument %d: %s\n", i, argv[i]);
    }
    
    return 0;
}```

clang -o printem printem.c

./printem "1" "2" "" "4"

Number of arguments: 5
Argument 0: ./printem
Argument 1: 1
Argument 2: 2
Argument 3:
Argument 4: 4


lldb -b -o run -k bt ./printem "1" "2" "" "4"


```(lldb) target create "./printem"
Current executable set to '/Users/printem' (arm64).
(lldb) settings set -- target.run-args  "1" "2" "4"
(lldb) run
Number of arguments: 4
Argument 0: /Users/printem
Argument 1: 1
Argument 2: 2
Argument 3: 4
Process 84115 exited with status = 0 (0x00000000)```

I’ve just built lldb with top-of-tree on llvm.org and here’s what I’ve observed.

I can reproduce what you’ve observed:

% ./bin/lldb -b -o run -k bt ~/tmp/printem "1" "2" "" "4"
(lldb) target create "/Users/alex/tmp/printem"
Current executable set to '/Users/alex/tmp/printem' (arm64).
(lldb) settings set -- target.run-args  "1" "2" "4"
(lldb) run
Number of arguments: 4
Argument 0: /Users/alex/tmp/printem
Argument 1: 1
Argument 2: 2
Argument 3: 4
Process 39076 exited with status = 0 (0x00000000)
Process 39076 launched: '/Users/alex/tmp/printem' (arm64)

Notice that the empty argument isn’t propagated to target.run-args. If I manually write the run-args myself, it’s respected though.

% ./bin/lldb ~/tmp/printem
(lldb) target create "/Users/alex/tmp/printem"
Current executable set to '/Users/alex/tmp/printem' (arm64).
(lldb) settings set -- target.run-args "1" "2" "" "4"
(lldb) r
Process 39003 launched: '/Users/alex/tmp/printem' (arm64)
Number of arguments: 5
Argument 0: /Users/alex/tmp/printem
Argument 1: 1
Argument 2: 2
Argument 3:
Argument 4: 4
Process 39003 exited with status = 0 (0x00000000)

Looks like the bug is in the empty arguments not being propagated to target.run-args from the shell invocation.

Presumably there’s one too many levels of evaluating that command line. This works as a workaround:

$ lldb /tmp/printem foo bar ‘“”’ baz
(lldb) target create “/tmp/printem”
Current executable set to ‘/tmp/printem’ (arm64).
(lldb) settings set – target.run-args “foo” “bar” “""” “baz”
(lldb) run
Process 39057 launched: ‘/tmp/printem’ (arm64)
Arg: 0 - ‘/tmp/printem’
Arg: 1 - ‘foo’
Arg: 2 - ‘bar’
Arg: 3 - ‘’
Arg: 4 - ‘baz’

Process 39057 exited with status = 0 (0x00000000)