Re: Getting call stack (like dbx where cmd)

From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 10/30/04


Date: Sat, 30 Oct 2004 06:25:30 GMT

Adrian wrote:
>
> Is there a way (understandably non-portable) to get the
> call stack from within a function? That is, assuming the
> application has been compiled with symbols, get the list
> of calling function names (similar to dbx "where" command").
>
> I am working with IBM compiler and AIX but any other
> OS/compiler solution would be interesting as well.
>
> To answer the inevitable question why I want this,
> I am writing a simple profiler for my library. However,
> within the library I want to distinguish which part of
> the application I was called from....

Since you know the CPU things are running on, it should not be hard
to write a couple of callable assembly language routines to return
those values. Something like:

   void *getbp(void);
   void *getsp(void);

They might even be implemented as inline, since they should be very
short, and that will avoid complications of digging into the
stack. getbp would probable resolve to "mov ax,bp".

Implementation is OT here, however how they should be integrated
into a C program is not.

-- 
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!


Relevant Pages

  • Re: Getting call stack (like dbx where cmd)
    ... Adrian wrote: ... > call stack from within a function? ... > I am working with IBM compiler and AIX but any other ... Since you know the CPU things are running on, ...
    (comp.lang.c)
  • [PATCH x86 for review II] [14/39] x86_64: cleanup Doc/x86_64/ files
    ... Linux/x86-64 supports CPU hotplug now. ... Interrupt stack. ... This feature is called the Interrupt Stack Table ... Used for interrupt 12 - Stack Fault Exception. ...
    (Linux-Kernel)
  • Re: [git pull] core fixes
    ... > Suresh and I looked at the oops and looks like the root cause is in ... > - CPU B gets the call function interrupt and starts going through the ... > CPU A's stack, as that element is still in call_function_queue ... > - CPU B sees the wait flag and just clears the flag ...
    (Linux-Kernel)
  • RE: tcp/ip hardware offload
    ... This isn't just TCP/IP stack specific. ... I know for CPU thermal testing Intel ... > announced gigabit network adapters with full protocol offload. ...
    (Vuln-Dev)
  • Re: [PATCH] no need to check for NULL before calling kfree()-fs/ext2/
    ... >> that the return address be written to memory (the stack), ... > 1) On a modern cpu, a miss of the branch predictor is quite expensive. ... It can't be on machines that have a "call" instruction. ... That's what the advertising hype is all about. ...
    (Linux-Kernel)