My speller.c works (finally), but the output is wrong. How do I step through dictionary.c with gdb? Typing "n" repeatedly on gdb speller gives each line of speller.c, but nothing in the called dictionary.c functions. Typing "s" repeatedly in speller.c seems to lead to a nonsensical infinite loop. I'd like to go through dictionary.c line by line.

What am I doing wrong? Thanks in advance.

1 Answer 1


Here's what works for me: Set a breakpoint at main (in speller), run with your arguments. When it breaks, it has loaded all the code you will need to set breakpoints in dictionary. continue (c) will then proceed to the next breakpoint, presumably in dictionary. Here's an additional 1000 words.

user@ide50:~/workspace/2015/pset5 $ gdb ./speller
Reading symbols from ./speller...done.
(gdb) break main
Breakpoint 1 at 0x4009f9: file speller.c, line 28.
(gdb) run test.txt test.txt
Starting program: /home/ubuntu/workspace/2015/pset5/speller test.txt test.txt

Breakpoint 1, main (argc=3, argv=0x7fffffffde88)
    at speller.c:28
28          if (argc != 2 && argc != 3)
(gdb) break load
Breakpoint 2 at 0x401306: file dictionary.c, line 72.
(gdb) continue

Breakpoint 2, load (fname=0x7fffffffe2c7 "test.txt")
    at dictionary.c:72
72          FILE* inptr = fopen(fname,"r");

Just a note about the difference between 'n' and 's' from (gdb) help next:

Unlike "step", if the current source line calls a subroutine, this command does not enter the subroutine, but instead steps over the call, in effect treating it as a single source line.

Happy debugging!

  • Terrific. It worked. I appreciate your help.
    – sfbob
    Commented Apr 1, 2016 at 21:33

You must log in to answer this question.

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