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…
How Does a C Debugger Work? (2014)
11–20 of 32 posts
Re: How Does a C Debugger Work? (2014)
#12Earlier 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…
Re: How Does a C Debugger Work? (2014)
#13Isn't it possible the compiler will re-order or combine statements differently than how they are written in source?
Re: How Does a C Debugger Work? (2014)
#14Earlier 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…
Re: How Does a C Debugger Work? (2014)
#15What about optimizations? Isn't it possible the compiler will re-order or combine statements differently than how they are written in source?
Re: How Does a C Debugger Work? (2014)
#16Re: How Does a C Debugger Work? (2014)
#17It 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…
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)
#18It 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.
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)
#19What 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?