public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* process stack question
@ 2003-06-19 19:18 Robert Schweikert
  2003-06-19 19:35 ` Paul Rolland
  0 siblings, 1 reply; 3+ messages in thread
From: Robert Schweikert @ 2003-06-19 19:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: Robert Schweikert

I have been searching for some documentation on how to get at
information regarding the process stack but I didn't find much and from
what I found it was not clear to me how I could use the information.

Here is what I am after.

We have some rudimentary memory tracking tools in our application and
I'd like to put some debug output in that allows me to write the name of
the routine I am in to some debug log.

My thinking is that I should be able to get a hold of the process call
stack and using the top of the stack I should have the name of the
function/method I am in. 

Any help on how to go about this would be appreciated. A pointer to any
documentation on how to get a hold of the stack, or the public API for
this is of course welcome.

Thanks,
Robert
-- 
Robert Schweikert <Robert.Schweikert@abaqus.com>
ABAQUS

^ permalink raw reply	[flat|nested] 3+ messages in thread
* RE: process stack question
@ 2003-06-20  1:02 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 3+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-06-20  1:02 UTC (permalink / raw)
  To: 'Robert Schweikert',
	'linux-kernel@vger.kernel.org'
  Cc: 'Robert Schweikert'


> From: Robert Schweikert [mailto:Robert.Schweikert@abaqus.com]
> 
> My thinking is that I should be able to get a hold of the process call
> stack and using the top of the stack I should have the name of the
> function/method I am in.

What about something like getting the value of the EIP at
that point (will require some assembly-fu, most probably) and 
calling the equivalent of:

$ addr2line -f -e my-program ADDR

#define _GNU_SOURCE
#include <stdio.h>

const char *program_name;

void some_function (void)
{
  int cnt = 0;
  unsigned long my_eip;
  char *command;
  
  for (cnt = 0; cnt < 10; cnt++) {
    printf ("%d ", cnt);
    fflush (stdout);
  }
  printf ("\n");
  asm volatile (
    "    call 2f               \n"
    "2:                        \n"
    "    pop %0                \n"
    : "=r" (my_eip));
  printf ("I am at 0x%lx\n", my_eip);
  asprintf (&command, "addr2line -f -e \"%s\" 0x%lx\n",
	    program_name, my_eip);
  system (command);
}

int main (int argc, char **argv) 
{
  program_name = argv[0];
  some_function();
  return 0;
}

Not the most elegant solution, but gives an idea. Surely you
can call the equivalent of addr2line by linking into libbfd.
YMMV.

Iñaky Pérez-González -- Not speaking for Intel -- all opinions are my own
(and my fault)

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

end of thread, other threads:[~2003-06-20  0:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-19 19:18 process stack question Robert Schweikert
2003-06-19 19:35 ` Paul Rolland
  -- strict thread matches above, loose matches on Subject: below --
2003-06-20  1:02 Perez-Gonzalez, Inaky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox