在 gdb 中使用非路径名启动应用程序 [英] Launch application in gdb with non-path name

查看:15
本文介绍了在 gdb 中使用非路径名启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 GDB 中启动旧版应用程序,它要求它的 argv[0] 值不包含除字母数字字符以外的任何内容.

每当我在 GDB 中启动程序时,它似乎会在运行程序之前将名称扩展为完整路径,所以我收到如下错误(因为它无法处理斜杠):

找不到/home/user/myapp ..."

是否可以使用相对路径在 GDB 中运行程序,以便它只会看到myapp"?

解决方案

Gdb 正常使用shell命令行运行目标命令

<上一页>执行 program_pathname program_arguments

但它有一个 set exec-wrapper 命令将其更改为

<上一页>exec exec_wrapper program_pathname program_arguments

exec_wrapper 通常是另一个命令,但它可以是 exec 命令接受的选项.

许多 shell(bash、zsh、ksh93)支持 exec 命令的 -a 选项来设置 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 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

这篇关于在 gdb 中使用非路径名启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆