Maybe the source of the pstack(1) utility will help me: (online git from debian ). Unfortunately, this is only x86 32-bit
http://anonscm.debian.org/gitweb/?p=collab-maint/pstack.git;a=blob;f=pstack.c;h=61beb8d10fa490492ab351115f261614d00adb6d;hb=HEAD#l547
547 static int crawl(int pid) 548 { 549 unsigned long pc, fp, nextfp, nargs, i, arg; 550 int error_occured = 0; 551 552 errno = 0; 553 fp = -1; 554 555 pc = ptrace(PTRACE_PEEKUSER, pid, EIP * 4, 0); 556 if (pc != -1 || !errno) 557 fp = ptrace(PTRACE_PEEKUSER, pid, EBP * 4, 0); 558 559 if ((pc != -1 && fp != -1) || !errno) { 560 print_pc(pc); 561 for ( ; !errno && fp; ) { 562 nextfp = ptrace(PTRACE_PEEKDATA, pid, fp, 0); 563 if (nextfp == (unsigned) -1 && errno) break; 564 565 nargs = (nextfp - fp - 8) / 4; 566 if (nargs > MAXARGS) nargs = MAXARGS; 567 if (nargs > 0) { 568 fputs(" (", stdout); 569 for (i = 1; i <= nargs; i++) { 570 arg = ptrace(PTRACE_PEEKDATA, pid, fp + 4 * (i + 1), 0); 571 if (arg == (unsigned) -1 && errno) break; 572 printf("%lx", arg); 573 if (i < nargs) fputs(", ", stdout); 574 } 575 fputc(')', stdout); 576 nargs = nextfp - fp - 8 - (4 * nargs); 577 if (!errno && nargs > 0) printf(" + %lx\n", nargs); 578 else fputc('\n', stdout); 579 } else fputc('\n', stdout); 580 581 if (errno || !nextfp) break; 582 pc = ptrace(PTRACE_PEEKDATA, pid, fp + 4, 0); 583 if (pc == (unsigned) -1 && errno) break; 584 fp = nextfp; 585 print_pc(pc); 586 } 587 if (fp) error_occured = 1; 588 } else error_occured = 1; 589 590 if (error_occured) perror("crawl"); 591 else errno = 0; 592 return errno; 593 } 594
In addition, a quick test says that it is not very reliable, but sometimes it can print something.
source share