using GDB with C-Preprocessor directives (Macros)
Puneet Singhal
puneet@opussoft.com
Mon Mar 19 19:56:00 GMT 2001
Title: using GDB with C-Preprocessor directives (Macros)
Hi Aditya
ÃÂ
for debugging Macros, u cannot use GDB bcoz GDB uses
code after preprocessing.
ÃÂ
if you r using gcc then u can use the -E switch to only
pre process and not compile or link.
trap the output in a file and check out the expansion
of the macros.
ÃÂ
have fun,
Puneet
this for quite some time and would sincerely
appreciate any help.
I am trying to use gdb for a C program which makes
heavy use of C macros.
The function ldpCreateIncarn() is called with
parameter u2IncarnId set to 0.
UINT1 ldpCreateIncarn (UINT2 u2IncarnId)
{ ÃÂ ÃÂ
UINT1 u1HoldPrio;
ÃÂ ÃÂ LDP_ASSERT(u2IncarnId ==
LDP_CUR_INCARN); ÃÂ ÃÂ if (
LDP_INCARN_STATUS(u2IncarnId) == ACTIVE )ÃÂ ÃÂ ÃÂ { ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ return LDP_FAILURE;
ÃÂ ÃÂ }
ÃÂ ÃÂ gblTmrMemChkId = 1; ÃÂ ÃÂ gblSNMPMemChkId = 1; . . . }
After call to LDP_INCARN_STATUS(u2IncarnId) the
value of u2IncarnId MYSTERIOUSLY changes to
1.LDP_INCARN_STATUS is a macro defined as follows
#define LDP_INCARN_STATUS(x)
(gLdpInfo.LdpIncarn[(x)].IncarnRowStatus)
...it only reads the status from a global
data-stucture and checks to see if it is ACTIVE. It does not change the value
of "x" in any way.
But after processing this macro the value of
u2IncarnId changes unexplicably ????
Also in this function I have some other Macros
like
INIT_LBL_MGR_INFO(u2IncarnId) which are defined as #define INIT_LBL_MGR_INFO(x)
gLdpInfo.LdpIncarn[(x)].LdpLblMgrInfo.u4NumGrpsActive = LDP_ZERO;
At the time of entering such macros u2IncarnId is
set to 0 but after processing the macro its value cahnges to 168 !!
(gdb) p u2IncarnId $19 = 0 (gdb) n (gdb) p u2IncarnId $20 =
168
If I am missing something obvious please forgive
me. I have spent the whole day trying to figure out where I am going wrong. Thanks
in Advance, Aditya
More information about the Gcc-help
mailing list