I have an error in my server.c file for PSET6 but have no idea how to find it. I am trying to use GDB and it does not seem to be very useful.

I would love some help learning how to better debug this kind of program AND if you could take a look at my code and see if you can spot any of the problems for a start.

My github is: https://github.com/Maddy12/CS50/tree/master/pset6


GDB should be a very useful tool for debugging server. The waiting is the hardest part. Remember server will be waiting for input from a browser/curl to process something or waiting for gdb to continue processing. If it seems to be doing nothing, it probably is waiting. BTW the way to use gdb on a program that requires arguments is something like this:

user@ide50:~/workspace/2016/pset6 $ gdb ./server
Reading symbols from ./server...done.
(gdb) break parse
Breakpoint 1 at 0x402569: file server.c, line 710.
(gdb) run ./public

ie include the arguments at the run command in gdb (instead of the command line call to gdb).

Since you are not specific about errors, a cursory read of your code indicates:

  • You might want to rethink your load function. It will not work on php files > 512 bytes. More info here.
  • You might want to rethink your indexes function. I can't say, at a glance, whether or not it will work. I can say that it is far more complicated than it needs to be which translates to more places bugs can get a foothold. More info here. (sp. response to original question)
  • parse has a memory leak.

With practice, patience and perseverance, gdb will help you get to the goal.

  • I'm trying to run gdb, but it just says this: Starting program: /home/ubuntu/workspace/pset6/server ./public Using /home/ubuntu/workspace/pset6/public for server's root Listening on port 8080, and I can't move to next line or execute any commands. Help? – Useful_Investigator Jul 5 '16 at 6:55

You must log in to answer this question.

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