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