public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* function logging
@ 2002-04-16  8:37 Calin Vatavu
  2002-04-16  9:26 ` Wei Qin
  0 siblings, 1 reply; 2+ messages in thread
From: Calin Vatavu @ 2002-04-16  8:37 UTC (permalink / raw)
  To: gcc-help


I'm trying to log EVERY function call in a library (gtk+ for example) and I 
did it by inserting the line: 

int dummy = printf (" %s %d", __FILE__, __LINE__); 

in ALL functions (at the beginning). I used a perl script which can, 
ofcourse, be fooled in some cases (like enum {...). thus I think I need a 
c-parser which can give me the position of the starting of the function body 
in the file.
Cab gcc give me the access to its internals to accomplish this ? 

And a second problem, how can I know the caller of the current function 
(like the perl's caller() function) ?
I need the backtrace in every function call. 

Does anybody know some debugging tricks like this ? 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: function logging
  2002-04-16  8:37 function logging Calin Vatavu
@ 2002-04-16  9:26 ` Wei Qin
  0 siblings, 0 replies; 2+ messages in thread
From: Wei Qin @ 2002-04-16  9:26 UTC (permalink / raw)
  To: Calin Vatavu; +Cc: gcc-help



On Tue, 16 Apr 2002, Calin Vatavu wrote:

>
> I'm trying to log EVERY function call in a library (gtk+ for example) and I
> did it by inserting the line:
>
> int dummy = printf (" %s %d", __FILE__, __LINE__);
>
> in ALL functions (at the beginning). I used a perl script which can,
> ofcourse, be fooled in some cases (like enum {...). thus I think I need a
> c-parser which can give me the position of the starting of the function body
> in the file.
> Cab gcc give me the access to its internals to accomplish this ?

C parser is a big hassle for this. The cases that the perl script may be
fooled is limited to a few keywords and you can easily exclude them. But
make sure that your perl script work on the pre-processed C
code but annotate the stubs back into the raw C code.


>
> And a second problem, how can I know the caller of the current function
> (like the perl's caller() function) ?
> I need the backtrace in every function call.
>

You can keep a global stack and push function names into the stack.
Popping is hard. One way I can think of is to
1. insert a pop at the end of each function body &&
2. #define return pop_code;return

This should work unless when longjmp is used.


Wei

> Does anybody know some debugging tricks like this ?
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-04-16 15:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-16  8:37 function logging Calin Vatavu
2002-04-16  9:26 ` Wei Qin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).