Live data from Hacker News

Learning C with gdb

hackerschool.com

41–50 of 98 posts

Re: Learning C with gdb

#41
post #36

Earlier quoted context omitted.

gdb being a utility, I believe the student is generally expected to learn it on their own if they like. Much like version control and other things that make the life of a coder easier, but aren't actually part of "Computer Science".

A course learning C is not a course in debugging or learning any particular debugger. When you are just learning the language, printf is probably the best way to do it. On the other hand, a follow-up course on actual debugging is probably warranted. Debugging might not be part of the Science bit of Computer Science but it is on the practical end of the Computer bit which you'll probably run into doing the Science bit…

Our Computing Systems course had two projects that absolutely required using gdb:

http://courses.cs.vt.edu/~cs3214/fall2011/bomblab/bomblab-cs...

http://courses.cs.vt.edu/~cs3214/fall2011/buflab/buflab-cs32...

Our version of the course was adapted from the CMU course: http://csapp.cs.cmu.edu/ I thought it was an excellent course. It taught students both concepts and skills that I had picked up in a much more ad-hoc manner.

Re: Learning C with gdb

#42
post #21

Earlier quoted context omitted.

GDB can step through instruction by instruction, and you can easily examine registers.

Can I do this with a hand-written assembly program, i.e. not necessarily one that has been compiled with as and subject to GNU default optimisations or "constraints"?

Yes.

Re: Learning C with gdb

#43

If you enjoyed this, then you'll certainly enjoy the programming chapter of 'Hacking: The Art of Exploitation' by Jon Erickson ( http://en.wikipedia.org/wiki/Hacking:_The_Art_of_Exploitatio... ). The first half of the book is a similar exploration of C programming using GDB to explain everything. Recommended.

Hacker School agrees--we have two copies in our library :)

Re: Learning C with gdb

#44
post #26
post #24

Earlier quoted context omitted.

This is an area where many college professors fall short. In my intro to CS class we learned C, and the professor explicitly told us to debug our code with printf statements. It wasn't until my first job that I even found out about gdb. I can't believe how much time I wasted trying to debug C and C++ code in college with nothing more than printf and cout.

What makes it even worse is the lack of a REPL means that between each change you need to recompile. In any large program this is going to take minutes and they add up. A simple GDB invocation is not only a better way of tracking it down, but can potently save hours.

When QA will found bug in your program in testing or staging environment, they will send you your logs, which will be empty. They will not allow you to use testing or staging (or production :-) ) for development.

Re: Learning C with gdb

#46
post #21

Earlier quoted context omitted.

GDB can step through instruction by instruction, and you can easily examine registers.

Can I do this with a hand-written assembly program, i.e. not necessarily one that has been compiled with as and subject to GNU default optimisations or "constraints"?

The commands you want are "stepi" (single-step one instruction), "disass" (disassemble at the current point in the program), and "info registers" (show you what's in all of the registers). These work equally well for hand-written assembly and for any arbitrary compiled program.

Re: Learning C with gdb

#47

gdb is like acid, works everywhere : https://stripe.com/blog/exploring-python-using-gdb

That post was one of the things that inspired me to start tinkering with gdb. Very cool stuff.

It broke a mental barrier I had gdb begin for `native only` programs.

Re: Learning C with gdb

#49

There was a debugger posted here to HN awhile back that actually displayed structs and pointers graphically. What was the name of that project, and is it still around? I was trying to find it the other day. I thought that was a dynamite tool for students. With LLVM, we should be able to have a REPL for C. as a pedagogical tool.

I believe it was Tenacious-C: http://tenaciousc.com/
Post reply on HN