public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Anyone know some reasonably portable way to determine the return address of a function?
@ 2000-06-09 13:52 David Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: David Taylor @ 2000-06-09 13:52 UTC (permalink / raw)
  To: George T. Talbot; +Cc: gdb

    Date: Tue, 06 Jun 2000 18:52:45 -0400
    From: "George T. Talbot" <george@moberg.com>

    I'm working on some library code in Linux, and, for debugging purposes, I'd
    like to be able to call dlinfo() on the return address of a function in my
    library so that I can track usage of the function:

    #define magic()         ...woudln't I like to know...

If you're using gcc, look in the gcc documentation at
__builtin_return_address.

    void    some_library_function(void)
    {
	    void*   return_address = magic();
	    Dl_info info;

	    if (dlinfo(return_address, &info))
		    fprintf(some_log_file, "some_library_function() called from %s in executable
    %s.\n",
			    info.dli_sname, info.dli_fname);
	    else
		    fprintf(some_log_file, "some_library_function() called from unknown
    caller.\n");


	    ...do the actual work...
    }

    -----
    void    some_code(void)
    {
	    ...
	    some_library_function();
	    ...
    }


    In other words, I want magic() above to return the address in some_code()
    where some_library_function() was called.

    Please cc: me if you post a reply to the list, in case I miss your reply.
    --
    George T. Talbot
    <george at moberg dot com>

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

* Anyone know some reasonably portable way to determine the return address of a function?
@ 2000-06-06 15:47 George T. Talbot
  0 siblings, 0 replies; 2+ messages in thread
From: George T. Talbot @ 2000-06-06 15:47 UTC (permalink / raw)
  To: gdb

I'm working on some library code in Linux, and, for debugging purposes, I'd
like to be able to call dlinfo() on the return address of a function in my
library so that I can track usage of the function:

#define	magic()		...woudln't I like to know...

void	some_library_function(void)
{
	void*	return_address = magic();
	Dl_info	info;

	if (dlinfo(return_address, &info))
		fprintf(some_log_file, "some_library_function() called from %s in executable
%s.\n",
			info.dli_sname, info.dli_fname);
	else
		fprintf(some_log_file, "some_library_function() called from unknown
caller.\n");


	...do the actual work...
}

-----
void	some_code(void)
{
	...
	some_library_function();
	...
}


In other words, I want magic() above to return the address in some_code()
where some_library_function() was called.

Please cc: me if you post a reply to the list, in case I miss your reply.
--
George T. Talbot
<george at moberg dot com>

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

end of thread, other threads:[~2000-06-09 13:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-09 13:52 Anyone know some reasonably portable way to determine the return address of a function? David Taylor
  -- strict thread matches above, loose matches on Subject: below --
2000-06-06 15:47 George T. Talbot

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).