This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: using GDB with C-Preprocessor directives (Macros)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]