<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/128432>128432</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLDB, after exec and re-run, uses wrong argv
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
comex
</td>
</tr>
</table>
<pre>
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)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycV11v6joW_TXmZSuRY5OQPPAQymF0pau5R3Pvw7xVTmKIrxI78gct8-tH2wmFlrZnNBXnAPb-XHt5OQjn1ElLuSX5juT7lQi-N3bbmlG-rhrTXba_HeFiAgwi6LYHAZM1rXQOlIbff9_vCHsC38u3ZfkqW4eLQnfR0cthiJbgDViZzIHQQnl4UcMQXWIMLV-gUVrYCzQBN30f183QgbCnMxBWKt0OoVP6FFdIvqMk3xNWpYTWhNa_gdStCdpLKzvwvXLw0ksNwaELKWg4gw0ahqFrIElguvjeaHCtVZNPpwspKNbZySacQMDP-21sWQDJd-Ecc5a995MjvCbsQNjhpHwfmrQ1I2EH4bwVQ-J6wg7hTFgFZ2V9EANIfVbW6FFqnwL8oWOHTrZGd1gZAkMK6i4unYTvsZ4XE4YOGgkv1ujT0ui_5GRNF1rZgdEwivaPPyHLU55miBJb7zcUs0YMSUGx3yQrKE1pyqs0oxVGJqw8WjPCv1vTSTQXDl5wXsJBtj5y3hZNm_FoOAgvncdYo1CaFPQG-l842KUcrL8JaljAf4KjGiT6v_Sq7eHv4DxMVmnv5pGKwejTbdTIheBFM0iI7bMK8aU15ouvFr9EvKEdhD5BYmKg5OySO-fHpXT25DOBJBD-5HynTNoT_uNhSzgnrf98bxRtnxjCDt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