Re: Question on finding the caller function in C.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Not sure this really belongs on linux-arm, but...

On Sat, Mar 7, 2009 at 1:29 PM, Ravi Sankar <ravisankar.g@xxxxxxxxx> wrote:

> Hi,
>
> I would like to know how can I get the function name of the caller in c?.
>
> Like
> // c code
>
> void foo(void)
> {
>
> bar();
> }
>
> void bar(void)
> {
>  // who is my caller?
> }
>
> I don't want to change the caller function code to add arguments etc.
>
> I am doing this for a debugger which shall run on cortex-a8 & Linux. Thanks
> for your help.
>
> All i know is that I can know the caller function address using
> "__builtin__return_address(0)".
> I wonder how can I use this to find out the function name as 'c' string?
>
> Any help is highly appreciated.


You'll need the symbol table information that the linker can provide.  I'm
rusty on such options, but I think ld takes the -M option to produce a map.

At any rate, that will have to be an input into your program, in some way,
so that you can look up the caller's return address in your table to
determine the caller.

I've done this in other operating systems (pSOS, for one) to provide
profiling information.  It worked just fine.




>
>
> --,
> BR,
> Ravi Sankar Guntur.
> -------------------------------------------------------------------
> List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
> FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
> Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php
>
-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php

[Linux ARM]     [Linux ARM MSM]     [Linux ARM Kernel]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

Add to Google Follow linuxarm on Twitter