accessing call stack and symbol table

accessing call stack and symbol table

Post by Aryeh Friedm » Sun, 17 Mar 2002 06:25:52



I need to find away to examine a process's memory, call stack and
symbol table WHILE it is running.  Preferablly I do not want to use
ptrace since the process itself needs to examine the these values.
The application is where it function X which can be called by an
arbitary number of other functions (directly or indirectly).  Function
X needs to know for any given parameter the first function in the call
stack that has that parameter as a paramter.  Ex.

#define MAXLINE 1024

main()
{
        a("hi");
        b("foo");

Quote:}

a(char *s)
{
        b(s);

Quote:}

b(char *s)
{
        c(s);

Quote:}

c(char *s)
{
        char func_name[MAXLINE];

        func_name=find_func(s,"char *");        // the function that I
am asking about in the post

        printf("%s\n",func_name);

Quote:}

would print:

int a("hi")
int b("foo")

The actual output will be a lot more terse.

 
 
 

accessing call stack and symbol table

Post by Paul Pluzhniko » Mon, 18 Mar 2002 15:30:45



> I need to find away to examine a process's memory,

Accessing process's memory from within the process
itself should pose little difficulty ;-)

Quote:> call stack and symbol table WHILE it is running.  

Doing so is quite possible, but very system-dependent
and not entirely trivial.

To get you started with call-stack, look at mpatrol sources:
http://www.cbmamiga.demon.co.uk/mpatrol

Quote:> Preferablly I do not want to use
> ptrace since the process itself needs to examine the these values.

I do not believe a process can ptrace itself.

Quote:> The application is where it function X which can be called by an
> arbitary number of other functions (directly or indirectly).  Function
> X needs to know for any given parameter the first function in the call
> stack that has that parameter as a paramter.  Ex.

You are not asking for just call stack, you are also asking
the 'X()' to decode all arguments to all functions in the
current call stack.

To decode parameters, your executable would have to
be compiled with '-g', and you would need to dig
into whatever debug format your platform uses.

For a single platform support, you are looking at
something like 1-2 month of development effort.

Do you really want it this bad?
Perhaps there is an easier way to achieve whatever X()
is intended to achieve?

Cheers,

 
 
 

accessing call stack and symbol table

Post by Steve Colema » Thu, 28 Mar 2002 07:28:42



> I need to find away to examine a process's memory, call stack and
> symbol table WHILE it is running.  

I have seen a number of ways to do this in the past but none are that
portable.

If you are using gcc on your system you can look at the function
__builtin_return_address(const int) and it will return a pointer to a
function name for the stack frame number provided, though it must be a
constant int for some reason.

Another but more complicated way is to exec gdb in a pipe and have it
perform a backtrace for you. This is more portable because each OS has
it's own implimentation for walking the stack and gdb always knows how
to do it, so you don't have to modify your code for each OS you need to
run on.

--

 High Performance, fault tolerant, distributed, real-time computing
 <<-------->> Johns Hopkins Applied Physics Laboratory <<--------->>
Balt:443-778-6330 Fax:443-778-5597 Wash:240-228-6330 Fax:240-228-5597

 
 
 

1. Generating call stack with local symbols

Hi,
I would like to generate a call stack with all local symbols and values for
parameters when a specific error is detected in my application. I cannot
deploy a full debug build, though. What options do I have? Is there a way to
use a build with only symbols info but without full debug info? Or, is it
possible to have a symbol server running on the internet so that my
application can access when needed? Basically, pstack() output contains only
the function name and addresses of args, but I would like to have the call
stack info with all parameters and values without deploying a full debug
build.

Any suggestion would be appreciated.
Thanks
--
Peter

2. ? route add -host HOST gateway (not directly attached)

3. to access kernel symbol table

4. Can FC 2975 (10/100/1000) Ethernet card work with S7A?

5. programatically accessing call stack information

6. Problems with PS/2 Mouse and Linux - more

7. Add Symbol into the symbol table?

8. 3com 3C509 dosn't work??

9. Symbol Table and Unmatching Module Symbol Errors

10. Matrox Mystique ands X.

11. where are process-table, region-table, inode-table?

12. C programming Error : Assertion failed: table->edgeH == VL_EDGE_NO_WRITE || table->edgeH == VL_EDGE_ZERO_FILL || table ?

13. Call Stack for Apache