Live data from Hacker News

Learning C with gdb

hackerschool.com

91–98 of 98 posts

Re: Learning C with gdb

#91
post #72

The visual debugger in both Eclipse CDT and Visual C++ let you do things like create breakpoints, step through your program, monitor variable values, even create conditional breakpoints that are triggered when a particular lineof code is executed n number of times or when some particular expression involving variables in the local context of the breakpoint turn true. My question is, what advantages do you get in usin…

Flip it around: what advantage does a "nice graphical UI" give you for what is fundamentally a text processing problem. Except for the most basic stuff (starting, stopping, setting a breakpoint at a line, looking at a variable value) everything you want to do in gdb involves something approximating a query language: set a watchpoint on the 32 bit quantity stored at this address; dump memory from this pointer; call th…

> Watching your code run and hitting a "next" button repeatedly isn't really a good use of the tool.

It's really useful to get yourself familiar with someone else's code.

Re: Learning C with gdb

#93
post #85

Very interesting! But I'd say this is too dangerous because of the misleading conclusions that it'd "make" you realize. Relying on what is printed out of printing a pointer value (which is not what the author is doing) is also misleading. Concluding stuff like "the size of an int is 4" or "size of double is 8" is also misleading. Again, it's not the conclusions the author is realizing, but for someone doing explorato…

That's not undefined, it's simply the bitwise representation of a 32 bits integer.

C allows more than 1 representation for integers. I know at least 3 possible ones: two's complement, ones' complement and signed magnitude.

The "natural wrap up" is not the same in all of the representations.

When the integer is unsigned, C gives you more guarantees, but for signed types, you're out of luck, and get to undefined bahvior land.

Check this out: http://web.torek.net/torek/c/numbers.html

And as an after note...

The maximum int may be less than 2^31-1. Maybe your C implementation decides that your int type will be a 16bits object with values ranging from -2^15 to 2^15-1. In that case, that integer literal would not be an int, and is likely to be a long, and maybe, in this same implementation, a long is a 61bit object ranging from -2^63 to 2^63-1. In that case, that assertion is just plain false. That's not the system exposed in the article though. But it could happen in some other system.

This can be true even on a 32bit system.

Re: Learning C with gdb

#94

Earlier quoted context omitted.

ddd is a graphical frontend to gdb and a few other debuggers (like jdb). ddd's UI is straight out of the 90s era of commercial Unices, but I prefer it to gdb since it visualizes source code with breakpoints and the ip and has some nice variable displaying / plotting features (ie it's very easy to visualize a matrix AS a matrix if you're doing some graphics work) edit: ddd also has a gdb prompt at the bottom, so you r…

cgdb is a nice visualization frontend too: http://cgdb.github.com/&#62 ;

And for the die hard Emacs users there's: http://emacs-fu.blogspot.com/2009/02/fancy-debugging-with-gd...

I generally try to refrain from bringing up Emacs in threads that have nothing to do with it (since Emacs does everything) but I was pleasantly surprised by its gdb support and I have used it extensively in the past.

Re: Learning C with gdb

#95
post #54

I'm surprised nobody's linked the gdb reference card. It's fairly old now, but it's still handy if you don't use gdb that often: http://users.ece.utexas.edu/~adnan/gdb-refcard.pdf

Many thanks for this link. Exactly what I need at the moment.

Re: Learning C with gdb

#96

Earlier quoted context omitted.

ddd is a graphical frontend to gdb and a few other debuggers (like jdb). ddd's UI is straight out of the 90s era of commercial Unices, but I prefer it to gdb since it visualizes source code with breakpoints and the ip and has some nice variable displaying / plotting features (ie it's very easy to visualize a matrix AS a matrix if you're doing some graphics work) edit: ddd also has a gdb prompt at the bottom, so you r…

cgdb is a nice visualization frontend too: http://cgdb.github.com/&#62 ;

How does this compare to gdb TUI? For the most part I find TUI adequate but I'm always open to alternatives.

Re: Learning C with gdb

#97

Earlier quoted context omitted.

I'm not really comparing it to anything, just speaking from experience of having waited many hours waiting for C programs to compile in the past.

Isn't the job of your Makefile to require recompilation of only those source files that have changed? I just did a random google of "how long to compile linux kernel" and came across this: https://plus.google.com/u/0/+LinusTorvalds/posts/6BxnSisp8fU One nice excerpt: "Total build time after make clean is about 1min, give or take 10secs. `touch include/linux/version.h` is 6 seconds to rebuild. Just doing a rebuild wit…

You've probably never tried compiling the linux kernel back in the late 90s with a top of the line machine (hint - gcc was slow, it would take over 35 minutes or so to compile from scratch) ;)
Post reply on HN