Live data from Hacker News

How Does a C Debugger Work? (2014)

blog.0x972.info

11–20 of 32 posts

Re: How Does a C Debugger Work? (2014)

#11

Earlier quoted context omitted.

Having come from a background of WinDbg (Windows) and DEBUG (DOS) before it, GDB feels very "unergonomic" in comparison. The general verbosity (why do you need an asterisk in front of an address when writing a breakpoint --- as the title of this site so prominently reminds?), lack of a regular hexdump command (16-byte hex+ASCII format) and the rather perplexing behaviour of the "disassemble" command ( https://stackov…

gdb) watch my_ptr what does this mean? watch when the value at the address given by my_ptr changes, or watch when the value of my_ptr changes (i.e. it is modified to point to a different location) ? gdb) watch * my_ptr Ah ... now it's clear what is meant. gdb) watch 0xfeedface hmm, now 0xfeedface is not a variable but literally an address. But wait, is it? What does this mean? Watch the value at memory location 0xfee…

I think GDB is an example of a program which should've been designed around a kind of inverse Greenspun's tenth rule principle i.e. vague semantics and weird syntax so just build a lisp from the start to control it.

Re: How Does a C Debugger Work? (2014)

#12

Earlier quoted context omitted.

Having come from a background of WinDbg (Windows) and DEBUG (DOS) before it, GDB feels very "unergonomic" in comparison. The general verbosity (why do you need an asterisk in front of an address when writing a breakpoint --- as the title of this site so prominently reminds?), lack of a regular hexdump command (16-byte hex+ASCII format) and the rather perplexing behaviour of the "disassemble" command ( https://stackov…

gdb) watch my_ptr what does this mean? watch when the value at the address given by my_ptr changes, or watch when the value of my_ptr changes (i.e. it is modified to point to a different location) ? gdb) watch * my_ptr Ah ... now it's clear what is meant. gdb) watch 0xfeedface hmm, now 0xfeedface is not a variable but literally an address. But wait, is it? What does this mean? Watch the value at memory location 0xfee…

Wasn't that _exactly_ the OP's point? That GDB is a fine C debugger but its logic and UX choices do not make much sense for debugging assembly code (e.g. there are no asterisks in assembly addresses, so no consistency there, etc.).

Re: How Does a C Debugger Work? (2014)

#14

Earlier quoted context omitted.

Really? I use GDB all the time to debug assembly, it's quite good at it. Perhaps there's something much better that I'm not aware of?

Having come from a background of WinDbg (Windows) and DEBUG (DOS) before it, GDB feels very "unergonomic" in comparison. The general verbosity (why do you need an asterisk in front of an address when writing a breakpoint --- as the title of this site so prominently reminds?), lack of a regular hexdump command (16-byte hex+ASCII format) and the rather perplexing behaviour of the "disassemble" command ( https://stackov…

If you can use DDD (which is an interface to GDB), it shows the disassembly.

Re: How Does a C Debugger Work? (2014)

#17

It writes an invalid instruction at this location. What ever this instruction, it just has to be invalid. On x86 at least, it is a valid instruction. INT3, or CC in hex. There are also the debug registers which implement breakpoints without modifying any code, although it's limited to a maximum of 4 at once. Characterising gdb as a "C debugger" is quite appropriate --- try to debug the Asm directly with it is an excr…

Author here.

I will rewrite this sentence, "invalid instruction" is too limited. It should be something like "an instruction that traps, and which isn't already used for another purpose". Syscalls trap but they are already used; and INT3/CC are valid instructions.

Re: How Does a C Debugger Work? (2014)

#18
post #8

It writes an invalid instruction at this location. What ever this instruction, it just has to be invalid. RISC-V actually did this in a special instruction called ebreak. It can change the CPU privileged mode into Debug Mode.

Author here.

As I mentioned above, I will rewrite this sentence to include dedicated special instructions. It was a wording mistake not to mention it!

Re: How Does a C Debugger Work? (2014)

#19
post #13

What about optimizations? Isn't it possible the compiler will re-order or combine statements differently than how they are written in source?

Yes, it is. Do you have a specific question?

I think their question was this: how is it that I can step through and see the expected changes to my variables, given that the optimiser is permitted to re-order/elide/restructure my code?
Post reply on HN