printStackTrace.c 723 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Print a stacktrace on i386 with
  2. // signal support (on Linux at least)
  3. // Does not do symbol lookup.
  4. // need to write binutils map file
  5. // parser, or steal code from
  6. // addr2line
  7. void printStackTrace(void)
  8. {
  9. volatile void *firstvar;
  10. char *frame, *pf, *eip;
  11. frame = ((char *)(&firstvar)) + 4;
  12. while(1)
  13. {
  14. eip = (char *)(*(int *)(frame + 4));
  15. if(!memcmp(eip, "\x58\xb8\x77\x00\x00\x00\xcd\x80", 8))
  16. {
  17. printf("Signal hander for signal %i\n", *(int *)(frame + 8));
  18. pf = (char *)(*(int *)(frame + 36));
  19. eip = (char *)(*(int *)(frame + 68));
  20. }
  21. else
  22. {
  23. pf = (char *)(*(int *)frame);
  24. }
  25. printf("Prev frame: %p, Prev EIP: %p\n", pf, eip);
  26. frame = pf;
  27. if(frame == NULL)
  28. break;
  29. }
  30. }
  31. // end