0

I've been working my way through CS50 and I'm having a problem I hope someone can help me with. I can't get GDB to function at all, and I think it might be a problem with startup - when I type "gdb" and hit enter, the next line says (gdb), but I never get the block of documentation text. Then, when I try to run any programs or anything, it says, without fail. "Undefined command: "". Try help". Any idea how to fix this? It's making pset 3 very difficult.

here's what I've been trying

I then received advice to put "--args" in front of my gdb commands, but that's not working for me either. See below for things I've tried and the results.

enter image description here

I'd really appreciate advice as to the specific syntax to use - I've watched the GDB short over and over and searched online, but all the guides assume more C/GDB knowledge than I have. I've never used a debugger before, so beginner's tips are really appreciated. Thanks!

[Editor: changed "pset4" in title, text and tags to correctly say pset3 (week 4 is pset3) No other changes.]

2

To debug "find" with gdb, enter the following command:

gdb find

You need to enter the filename of the executable as a parameter following gdb on the command line. Don't use ./ or .c when you enter the command on the command line. After that, the (gdb) prompt will appear. To run your program, simply enter r followed by whatever parameters you want to send to find. For example, r 12 will run the program and send 12 to find as the needle. I haven't figured how you would pipe the output of generate or the contents of a file into this, maybe someone else has that answer. But, if you're debugging, you'll be better off sending in a small list of 3 or 4 numbers manually anyways. Running or stepping through will get you to where you can enter them. Remember to use CTRL-D to end the list input, not CTRL-C.

Useful commands are step, or s; next or n; break; and others. Google gdb cheat sheet for a useful list of commands.

If you enter the run command again, it will ask if you want to restart. Don't be confused. Enter yes, it will reinitialize everything and give you a clean start.

This should get you going. If you have any more questions, add a comment. If you're satisfied with this, please mark the question as answered. Let's keep up on forum maintenance. ;-)

0

I haven't figured how you would pipe the output of generate or the contents of a file into this, maybe someone else has that answer.

Here's how I use GDB for find.c using the argument 10 for the needle, and the contents of file num.txt for the haystack; I also set a breakpoint at the search function prior to running the program:

jharvard@appliance (~/Dropbox/pset3/find): gdb ./find
Reading symbols from ./find...done.
(gdb) b search
Breakpoint 1 at 0x8048939: file helpers.c, line 66.
(gdb) r 10 < num.txt
Starting program: /home/jharvard/Dropbox/pset3/find/find 10 < num.txt

When stepping through the search function, use the 's' command rather than 'n' to see the steps within each called function.

(I too wonder why I don't get the block of documentation text when starting GDB as seen in the GDB short video.)

  • My code: jharvard@appliance (~/Dropbox/pset3/find): gdb (gdb) find Missing search parameters. (gdb) find 12 Argument required (expression to compute). (gdb) r 12 Starting program: 12 No executable file specified. Use the "file" or "exec-file" command. (gdb) ./find Undefined command: "". Try "help". (gdb) find Missing search parameters. (gdb) find 42 Argument required (expression to compute). (gdb) HELP! It is not running gdb at all! What am I doing wrong? – user8354 Aug 27 '15 at 22:48
  • Sorry for the garbled code. I took a screen shot, but it won't let me add it. – user8136 Aug 27 '15 at 23:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .