Messages in this thread | | | From | "Perez-Gonzalez, Inaky" <> | Subject | RE: process stack question | Date | Thu, 19 Jun 2003 18:02:48 -0700 |
| |
> 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) - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |