Reputation: 5146
I am trying to launch a legacy application in GDB, and it requires that it's argv[0]
value not contain anything other than alphanumeric characters.
Whenever I launch the program in GDB it seems that it expands the name to be the full path before running the program, so I get an error like (because it can't deal with the slashes):
"Cannot find /home/user/myapp ..."
Is it possible to run a program in GDB with a relative path, so that it will just see "myapp"?
Upvotes: 1
Views: 1672
Reputation: 10271
Gdb normally runs target commands using the shell command line
exec program_pathname program_arguments
But it has a set exec-wrapper
command that will change this to
exec exec_wrapper program_pathname program_arguments
The exec_wrapper is often another command, but it can be an option that the exec
command accepts.
Many shells (bash, zsh, ksh93) support a -a
option to the exec
command to set argv[0].
So, if your shell supports exec -a
, you can do the following to invoke /home/user/myapp
with argv[0]==myapp
:
(gdb) set exec-wrapper -a myapp
Upvotes: 2