I have a binary test that I want to debug with gdb. As you can see pwd is /tmp:

$ gdb
(gdb) file test
Reading symbols from /tmp/test...(no debugging symbols found)...done.
(gdb) pwd
Working directory /tmp
(gdb) run
Starting program: /tmp/test


$ pwd
$ gdb test
Reading symbols from /tmp/test...(no debugging symbols found)...done.
The target architecture is assumed to be i386
(gdb) run
Starting program: /tmp/test

The problem is that gdb executes the file with the absolut path /tmp/test instead of the realtiv path test. Which means argv[0]="/tmp/test".

How can I make gdb execute the file with the relativ path (argv[0]="test")?

1 Answer 1


Figured it out myself with a cool trick I didn't know before - set exec-wrapper

$ cat wrapper.sh
exec -a "$p" "$@"

and in gdb

(gdb) set exec-wrapper ./wrapper.sh

This way you can set the argv[0] to whatever you want.

source: https://sourceware.org/ml/gdb/2013-05/msg00049.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.