开发者

How to tell GCC to emit a specific debugging symbol named by me?

I am writing a stateful scanne开发者_开发知识库r and I want to have a debugging symbol for every state change.

In my code I call a macro SETSTATE(ST_xxx) for instance, which does some nasty things, BUT I could easily also tell GCC to emit at that point a specific debugging symbol based on that name ST_xxx.

What I need to accomplish is setting a breakpoint in gdb.

I suppose it should be a #pragma or something.

If I only knew how ...


Though I might misunderstand the question, how about making a dummy function and calling that in SETSTATE, then setting a breakpoint in that function?
For example:

void dummy_breakpoint() {}

#define SETSTATE(st) dummy_breakpoint(); ...usual process...

Setting break dummy_breakpoint in .gdbinit might help some labor savings.

EDIT:
How about setting a watch-point in SETSTATE like the following, and setting watch dummy_variable in .gdbinit?

char dummy_variable; /* global variable */

#define SETSTATE(st) ++ dummy_variable; ...usual process...

However, this might make the program's execution be slower if your environment doesn't provide hardware watch-point...


If you want debugging symbols as a point of reference, you can use labels to create these (just make sure they aren't stripped out of the debug info if unreferenced), though having never used used gdb i'm not sure if it'll pick up labels like ollydbg does with obj scanning/analysis. but seeing as its breakpoints your after, why not just use a debug trap, like msvc's __debugbreak()?, something from here might be of use for the gcc variant: Is there a portable equivalent to DebugBreak()/__debugbreak?


On compile use -D ST_xxx

I use this for enabling debugging messages, using macros. It defines the constant ST_xxx with value 1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜