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

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4267
    • Oxygen Basic
Stack Traces (Rosetta)
« on: June 28, 2012, 05:27:16 AM »
Macro for capturing the stack and reporting its contents.

Code: (o2) [Select]
'32bit x86
 
static string Report
 
 
macro ReportStack(n)
'===================
 
  '
  scope
  '
  static sys stack[0X100],stackptr,e
  '
  'CAPTURE IMAGE OF UP TO 256 ENTRIES
  '
  '
  mov eax,n
  cmp eax,0x100
  (
    jle exit
    mov eax,0x100 'UPPER LIMIT
  )
  mov e,eax
  mov stackptr,esp
  lea edx,stack
  mov ecx,e
  mov esi,esp
  (
    mov eax,[esi]
    mov [edx],eax
    add esi,4
    add edx,4
    dec ecx
    jg repeat
  )
  sys i
  string cr=chr(13)+chr(10), tab=chr(9)
  '
  for i=1 to e
    report+=hex(stackptr+(i-1)*4,8) tab hex(i-1,2) tab hex(stack[  i  ],8) cr
  next
  '
  end scope
  '
end macro
 
'====
'TEST
'====
 
  function foo()
  '=============
 
  push 0x44556677
  push 0x33445566
  push 0x22334455
  push 0x11223344
  ReportStack( 8 )
 
  end function
 
Report+="Trace inside foo"+chr(13)+chr(10)
foo()
print report
'putfile "s.txt",Report
 
/*
RESULT:
 
Trace inside foo
0017FE00 00 11223344
0017FE04 01 22334455
0017FE08 02 33445566
0017FE0C 03 44556677
0017FE10 04 005EAB1C
0017FE14 05 0017FE40
0017FE18 06 10002D5F
0017FE1C 07 00000000
*/

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

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