1

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?

Zulu
  • 8,765
  • 9
  • 49
  • 56
slin6174
  • 108
  • 2
  • 10

2 Answers2

2

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.
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • Sorry this might be a silly question: So I used the commands you gave and the program just ran the script from beginning to end. I was wondering if I can set breakpoints? – slin6174 Jun 23 '14 at 00:29
  • Sure, use the `break` command to set breakpoints before using `run`. – Greg Hewgill Jun 23 '14 at 00:30
0

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.

Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135