Author Topic: Stack Traces (Rosetta)  (Read 3312 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Stack Traces (Rosetta)
« on: June 28, 2012, 05:27:16 AM »
Macro for capturing the stack and reporting its contents.

Code: OxygenBasic
  1. '32bit x86
  2.  
  3. static string Report
  4.  
  5.  
  6. macro ReportStack(n)
  7. '===================
  8.  
  9.   '
  10.  scope
  11.   '
  12.  static sys stack[0X100],stackptr,e
  13.   '
  14.  'CAPTURE IMAGE OF UP TO 256 ENTRIES
  15.  '
  16.  '
  17.  mov eax,n
  18.   cmp eax,0x100
  19.   (
  20.     jle exit
  21.     mov eax,0x100 'UPPER LIMIT
  22.  )
  23.   mov e,eax
  24.   mov stackptr,esp
  25.   lea edx,stack
  26.   mov ecx,e
  27.   mov esi,esp
  28.   (
  29.     mov eax,[esi]
  30.     mov [edx],eax
  31.     add esi,4
  32.     add edx,4
  33.     dec ecx
  34.     jg repeat
  35.   )
  36.   sys i
  37.   string cr=chr(13)+chr(10), tab=chr(9)
  38.   '
  39.  for i=1 to e
  40.     report+=hex(stackptr+(i-1)*4,8) tab hex(i-1,2) tab hex(stack[  i  ],8) cr
  41.   next
  42.   '
  43.  end scope
  44.   '
  45. end macro
  46.  
  47. '====
  48. 'TEST
  49. '====
  50.  
  51.   function foo()
  52.   '=============
  53.  
  54.   push 0x44556677
  55.   push 0x33445566
  56.   push 0x22334455
  57.   push 0x11223344
  58.   ReportStack( 8 )
  59.  
  60.   end function
  61.  
  62. Report+="Trace inside foo"+chr(13)+chr(10)
  63. foo()
  64. print report
  65. 'putfile "s.txt",Report
  66.  
  67. /*
  68. RESULT:
  69.  
  70. Trace inside foo
  71. 0017FE00        00      11223344
  72. 0017FE04        01      22334455
  73. 0017FE08        02      33445566
  74. 0017FE0C        03      44556677
  75. 0017FE10        04      005EAB1C
  76. 0017FE14        05      0017FE40
  77. 0017FE18        06      10002D5F
  78. 0017FE1C        07      00000000
  79. */
  80.  

http://rosettacode.org/wiki/Stack_traces#OxygenBasic

Charles
« Last Edit: June 28, 2012, 05:33:11 AM by Charles Pegge »