Issue |
128432
|
Summary |
LLDB, after exec and re-run, uses wrong argv
|
Labels |
new issue
|
Assignees |
|
Reporter |
comex
|
If you launch a process in LLDB, the process execs, and you tell LLDB to re-launch, it will exec the new binary but with the old argv (including argv[0]).
I encountered this when using `uv run lldb -- python script.py` to debug a Python script in a [uv](https://github.com/astral-sh/uv) virtual environment. On the second run, `sys.path` would be wrong.
Reproduced on macOS 15.3.1 (24D70) with `lldb-1600.0.39.109` (from Xcode) as well as 14f33c6bc130 (latest `main`).
To reproduce, build this C file (which just prints argv along with the executable path):
```c
// clang -o argv-vs-executable argv-vs-executable.c
#include <stdio.h>
#include <assert.h>
#include <mach-o/dyld.h>
int main(int argc, char **argv) {
char exec_path[1024];
assert(!_NSGetExecutablePath(exec_path, &(uint32_t){sizeof(exec_path)}));
printf("_NSGetExecutablePath=>%s\n", exec_path);
printf("argc=%d\n", argc);
for (int i = 0; i < argc; i++) {
printf("argv[%d] = '%s'\n", i, argv[i]);
}
}
```
Then run: `lldb -- /bin/bash -c 'exec ./argv-vs-executable'`
Then input the commands `r` to run, then `c` to continue, then `r` to run again.
I get the following output. As you can see, on the first run, LLDB launches `bash`, then `bash` execs `./argv-vs-executable` with an appropriate argv. But on the second run, LLDB launches `./argv-vs-executable` directly, yet `argv` is still the one from `bash`.
```
(lldb) target create "/bin/bash"
Current executable set to '/bin/bash' (arm64e).
(lldb) settings set -- target.run-args "-c" "exec ./argv-vs-executable"
(lldb) r
Process 41856 launched: '/bin/bash' (arm64e)
Process 41856 stopped
* thread #2, stop reason = exec
frame #0: 0x0000000100010b30 dyld`_dyld_start
dyld`_dyld_start:
-> 0x100010b30 <+0>: mov x0, sp
0x100010b34 <+4>: and sp, x0, #0xfffffffffffffff0
0x100010b38 <+8>: mov x29, #0x0 ; =0
0x100010b3c <+12>: mov x30, #0x0 ; =0
Target 0: (argv-vs-executable) stopped.
(lldb) c
Process 41856 resuming
_NSGetExecutablePath=>/tmp/argv-vs-executable
argc=1
argv[0] = './argv-vs-executable'
Process 41856 exited with status = 0 (0x00000000)
(lldb) r
Process 41862 launched: '/private/tmp/argv-vs-executable' (arm64)
_NSGetExecutablePath=>/private/tmp/argv-vs-executable
argc=3
argv[0] = '/bin/bash'
argv[1] = '-c'
argv[2] = 'exec ./argv-vs-executable'
Process 41862 exited with status = 0 (0x00000000)
(lldb)
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs