1

I run this command in my terminal,

gcc -g -I/usr/include -g sample_client.c lsp.o lspmessage.pb-c.o -o sample_client -L/usr/lib -lprotobuf-c

in my file directory, I can see a sample_client file. Its property is executable. However, when I run

(gdb) sample_client

I got this,

Undefined command: "sample_client".

How can I debug?

unwind
  • 391,730
  • 64
  • 469
  • 606
user2036452
  • 53
  • 1
  • 5

3 Answers3

2
$ gdb ./sample_client
(gdb) run

To pass command-line arguments to your program use --args:

$ gdb --args ./sample_client arg1 arg2 arg3
(gdb) run
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • Thank you for your help. Could you please recommend some material with examples to learn gdb stuff. I am quite new to gdb. – user2036452 Feb 04 '13 at 15:43
  • @user2036452, note that the need to add `./` to executable name is not related to gdb, this is just the fact that unix shells do not add current directory to `$PATH` for [security reasons](http://stackoverflow.com/a/6331085/693538), so when you type just `sample_client` without adding a path to it, then Bash will look for it only in the directories listed in `$PATH` (`/bin`, `/usr/bin` and so on) and fail to do it. That is a big difference from windows cmd shell. – NIA Feb 04 '13 at 16:06
1

When you start gdb, you need to tell it which binary (executable) to debug:

$ gdb ./sample_client

Then, to run the program inside gdb, use the run command:

(gdb) run

You should probably give the fine documentation some quality time.

unwind
  • 391,730
  • 64
  • 469
  • 606
0
gdb <binary file here>
run < <flags here>

Also, refer to this quick reference for future operations: http://www.stanford.edu/class/cs107/other/gdbrefcard.pdf

BThomas
  • 1
  • 1