Launch application in gdb with non-path name

被刻印的时光 ゝ 提交于 2020-01-07 06:27:10

问题


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"?


回答1:


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 any arbitrary string 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


来源:https://stackoverflow.com/questions/38957892/launch-application-in-gdb-with-non-path-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!