1
votes

We have a large binary compiled with -g and -O compiler flags. The issue is that setting the breakpoint in some files/line does not breaks at that file/line or breaks in some other line while debugging using gdb. I understand that this could be due to due to the -O compiler flag (used for optimization). Unfortunately I am not in a position to remove the compiler -O flag as there are many a scripts level that I need to take care.

How can I ensure to make the code breaks at a file/line place I want? Is there a line of code that I can add which will always be not optimized or will break when debugging using gdb - I tried something like this -

int x; int y;

But still then the GDB break point did not work properly - how can I set it correctly?

1

1 Answers

1
votes

There are two problems I can think of, inlining and optimisation. Since there is no standard way to tell the compiler to disable inlining and/or optimisation, you'll only be able to do it in a compiler specific way.

To disable inlining in GCC, you can use __attribute__((noinline)) on the method.

To disallow the compiler to optimise functions away (and, untested, give you a stable line of code where you can set your breakpoint), just add this to the code;

asm ("");

Both of these are documented at this page.