简体   繁体   中英

How to debug a C++ program that takes input from a script in gdb

Background info: The C++ program(LAMMPS - an open source) takes in a input script that has all the commands to be executed. The executable is named "lmp_fedora", input script named "in.hit". The program's run command "./lmp_fedora < in.hit"

My Problem: I am trying to debug one of the .cpp files in LAMMPS.

My Attempts: 1. I tried "gdb lmp_fedora < in.hit", but it failed. 2. Also tried to find the pid of the running program using ps aux, but wasn't sure which id it was.

My Question: How do you debug a input script(that has commands linked to c++ project) using gdb?

You use the gdb run command:

$ gdb lmp_fedora
(gdb) run <in.hit

From the help:

(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.

When you say gdb foo < bar that means bar is input to gdb , not to foo .

I think what you want to use is the gdb command set args .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM