【问题标题】:How to debug a C++ program that takes input from a script in gdb如何调试从 gdb 中的脚本获取输入的 C++ 程序
【发布时间】:2014-08-12 23:03:59
【问题描述】:

背景信息:C++ 程序(LAMMPS - 一个开源)接受一个输入脚本,该脚本包含所有要执行的命令。可执行文件名为“lmp_fedora”,输入脚本名为“in.hit”。程序的运行命令“./lmp_fedora

我的问题:我正在尝试调试 LAMMPS 中的 .cpp 文件之一。

我的尝试: 1. 我尝试了“gdb lmp_fedora

我的问题:如何使用 gdb 调试输入脚本(具有链接到 c++ 项目的命令)?

【问题讨论】:

    标签: c++ linux lammps


    【解决方案1】:

    你使用 gdb run 命令:

    $ gdb lmp_fedora
    (gdb) run <in.hit
    

    来自帮助:

    (gdb) help run
    Start debugged program.  You may specify arguments to give it.
    Args may include "*", or "[...]"; they are expanded using "sh".
    Input and output redirection with ">", "<", or ">>" are also allowed.
    
    With no arguments, uses arguments last specified (with "run" or "set args").
    To cancel previous arguments and run with no arguments,
    use "set args" without arguments.
    

    【讨论】:

    • 对不起,这可能是一个愚蠢的问题:所以我使用了你给出的命令,程序只是从头到尾运行了脚本。我想知道我是否可以设置断点?
    • 当然,在使用run之前先使用break命令设置断点。
    【解决方案2】:

    当您说gdb foo &lt; bar 时,表示bar 输入到gdb,而不是foo

    我想你要使用的是gdb 命令set args

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-30
      • 2018-06-06
      • 2017-05-28
      • 1970-01-01
      • 2015-12-31
      • 1970-01-01
      • 2020-10-09
      • 1970-01-01
      相关资源
      最近更新 更多