问题描述
我试图在GDB中启动遗留应用程序,并且它要求它的 argv [0]
值不包含除字母数字字符以外的任何内容。 b
$ b
每当我在GDB中启动程序时,它似乎会在运行程序之前将名称扩展为完整路径,所以出现类似的错误(因为它无法处理斜杠):
找不到/ home / user / myapp ...
是否可以运行在GDB中有一个相对路径的程序,所以它只会看到myapp?
Gdb通常运行目标命令shell命令行
exec 程序路径名 program_arguments
但它有一个命令会将其更改为
exec exec_wra pper program_pathname program_arguments
exec_wrapper em>通常是另一个命令,但它可以是 exec
命令接受的任意字符串。
许多shell (bash,zsh,ksh93)为 exec
命令支持 -a
选项来设置argv [0]。
所以,如果你的shell支持 exec -a
,你可以执行以下操作来调用 / home / user / myapp
与argv [0] == myapp
:
(gdb)set exec-wrapper -a myapp
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"?
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
这篇关于使用非路径名称在gdb中启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!