Search code examples
c++qtgdb

Break in GDB when program counter is certain value


I am attempting to debug a segmentation fault using GDB (on Windows 10 using the Qt toolchain). I know that the segmentation fault occurs because the program counter gets set to 0x30 (obviously an invalid instruction address). However, by the time I get notified that a segmentation fault has occurred, I am already in invalid memory space and have no way to backtrace the function calls that got me to that point.

For example, this is the output of backtrace after the segmentation fault is detected:

#0  0x0000000000000030 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Is there a way to instruction GDB to break immediately when the PC is set to a certain value but before the next instruction is executed?

I tried break *0x30 but this didn't accomplish what I want.

Or perhaps, is there a different way to debug this type of segmentation fault?


Solution

  • Is there a way to instruction GDB to break immediately when the PC is set to a certain value

    No.

    Implementing such a feature would require single-stepping the program, which is too slow for any practical program.