Subject: Re: gcc Q - a bit off topic
To: Bill Studenmund <>
From: Andrew Brown <>
List: current-users
Date: 10/21/1997 23:08:06
>I'm trying to debug some reference-keeping code I've added to the kernel.
>I've got an addref and a delref function. When the ref count goes to 0,
>the object gets deleted.


>Unfortunatly I've got a leak. I add a reference which doesn't get deleted.

i could see that one coming a mile away.  is it a reference to itself?
there's an ai koan about this...

>I want to turn the call to the addref and delref functions into macros,
>and print out what source file they were called from. Does anyone know how
>to do this? I.E. is there a variable in gcc which is the name of the
>source file being compiled? Or anything else which would help?

i use the following pre-processor tokens, as per ansi x3.159-1989 (or
there abouts :), section a 12.10:

 __LINE__  a decimal constant containing the current source line
 __FILE__  a string literal containing the name of the file being
 __DATE__  a string literal containing the date of compilation, in the
           form "Mmm dd yyyy".
 __TIME__  a string literal..., in the form "hh:mm:ss".

and i use them in macro wrappers to functions all the time, although i
discovered them quite more accidentally.  i didn't actually look
(although i know where they are) i just said "wouldn't it be nice if
this worked" and it did.

>The calls happen as part of normal kernel life, so I'd rather not have to
>go through the debugger and manually do a back trace & a continue for each

no, of course not.  :)

|-----< "CODE WARRIOR" >-----| (TheMan)        * "ah!  i see you have the internet                               that goes *ping*!"      * "information is power -- share the wealth."