1

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

or

$ pwd
/tmp
$ 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")?

3

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

$ cat wrapper.sh
#!/bin/bash
p="test"
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, privacy policy and cookie policy

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