home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / ddjmag / ddj9209.zip / TRACE.ASC < prev    next >
INI File  |  1992-08-19  |  1KB  |  63 lines

  1. [LISTING ONE]
  2.  
  3. /* stackdump.c -- a program to dump the stack */
  4.  
  5. #define SPARC 1
  6. #define IBM 0
  7.  
  8. void fun1a();
  9. void fun1b();
  10. void fun2();
  11. void stackdump();
  12.  
  13. main()      /* call function fun1a or function fun1b */
  14. {
  15.   char text[16];
  16.   strcpy(text,"main text");
  17.   fun1a();
  18. }
  19. void fun1a()
  20. {
  21.   char text[16];
  22.   strcpy(text,"fun1a text");
  23.   fun2();
  24. }
  25. void fun1b()
  26. {
  27.   char text[16];
  28.   strcpy(text,"fun1b text");
  29.   fun2();
  30. }
  31. void fun2()
  32. { int jj;
  33.   char text[16];
  34.   strcpy(text,"fun2 text");
  35. #if SPARC
  36.   printf("main address=%x\n",main);
  37.   printf("fun1a address=%x\n",fun1a);
  38.   printf("fun1b address=%x\n",fun1b);
  39.   printf("fun2 address=%x\n\n",fun2);
  40. #else if IBM
  41.   printf("main address=%x -> %x\n",main, *(unsigned long *)main);
  42.   printf("fun1a address=%x -> %x\n",fun1a, *(unsigned long *)fun1a);
  43.   printf("fun1b address=%x -> %x\n",fun1b, *(unsigned long *)fun1b);
  44.   printf("fun2 address=%x -> %x\n",fun2, *(unsigned long *)fun2);
  45. #endif
  46.   stackdump(&jj-32);   /* the 32 gives us the stack before variable jj */
  47. }
  48. void stackdump(start)
  49. unsigned long start;
  50. {
  51.   int i,j;
  52.   for (i=0;i<128;i++)
  53.     {
  54.       printf("%08x ", (long)start);
  55.       printf("%08x ", *(unsigned long *)(start));
  56.       for (j=0;j<4;j++,start++)
  57.         printf("%c", isprint( *(unsigned char *)(start)) ?
  58.                           *(unsigned char *)(start) : ' ');
  59.       printf("\n");
  60.     }
  61. }
  62.  
  63.