使用GDB调试从shell脚本调用的C ++程序 [英] Use GDB to debug a C++ program called from a shell script

查看:1333
本文介绍了使用GDB调试从shell脚本调用的C ++程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常复杂的shell脚本,其中它调用一个C + +程序我想通过GDB调试。从shell中分离这个c ++程序是非常困难的,因为它有很多的变量和很多环境变量设置。

I have a extremely complicated shell script, within which it calls a C++ program I want to debug via GDB. It is extremely hard to seperate this c++ program from the shell since it has a lot of franches and a lot of environmental variables setting.

我不知道有没有办法在这个shell脚本上调用GDB?看起来像gdb要求我直接调用一个C ++程序。

I wonder is there a way to invoke GDB on this shell script? Looks like gdb requires me to call on a C++ program directly.

谢谢!

推荐答案

您可以执行以下两个选项:

There are two options that you can do:

1 )直接在shell脚本中调用GDB。这意味着你没有标准的和标准的重定向。

1) invoke GDB directly within the shell script. This would imply that you don't have standard in and standard out redirected.

2)运行shell脚本,然后将调试器附加到已经运行的c ++进程,像这样:gdb progname 1234其中1234是正在运行的c ++进程的进程ID。

2) run the shell script and then attach the debugger to the already running c++ process like so: gdb progname 1234 where 1234 is the process ID of the running c++ process.

如果您需要在程序开始运行之前执行操作,则选项1将是更好的选择,否则选项2是更清洁的方式。

If you need to do things before the program starts running then option 1 would be the better choice, otherwise option 2 is the cleaner way.

这篇关于使用GDB调试从shell脚本调用的C ++程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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