It is currently Wed Jul 18, 2018 11:06 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Get full backtrace
PostPosted: Sat Jul 07, 2018 8:52 pm 
Offline
New User
New User

Joined: Sat Jul 07, 2018 6:50 pm
Posts: 1
I'm looking for a way to get backtrace information under Windows.
Unfortunately CaptureStackBackTrace do something strange. For example:
Code:
;DisableDebugger

Prototype.i CaptureStackBackTrace(FramesToSkip.i, FramesToCapture.i,  *BackTrace, *BackTraceHash);
Global CaptureStackBackTrace.CaptureStackBackTrace
Global *BackTrace

Procedure BackTraceInit()
 
  Protected Kernel32.i = OpenLibrary(#PB_Any, "Kernel32.dll")
  If Not Kernel32 = 0
    CaptureStackBackTrace.CaptureStackBackTrace = GetFunction(Kernel32, "RtlCaptureStackBackTrace")
    If Not CaptureStackBackTrace.CaptureStackBackTrace
      OutputDebugString_("RtlCaptureStackBackTrace = 0")
      ProcedureReturn 0
    EndIf 
    *BackTrace = AllocateMemory(512) ; = 128 frames (XP only 63 max)
    ProcedureReturn 1
  Else
    OutputDebugString_("OpenLibrary failed")
    ProcedureReturn 0
  EndIf
 
EndProcedure

Procedure ErrorHandler()
  Protected.i framesNum, x, frame
  Protected ErrorMessage$
 
  framesNum = CaptureStackBackTrace(1, 63,  *BackTrace, #Null); 1 - skip this frame
 
  If framesNum
    ErrorMessage$ + "BT (" + Str(framesNum) + ") "
    For x=0 To framesNum Step 4 ; (8 for x64)?
      frame = PeekI(*BackTrace+x)
      If Not frame = 0
        ErrorMessage$ + Hex(frame) + Chr(13) 
      EndIf   
    Next   
    If *BackTrace : FillMemory(*BackTrace, 512) : EndIf
  Else
    If *BackTrace : FillMemory(*BackTrace, 512) : EndIf
      OutputDebugString_("CaptureStackBackTrace fail")
  EndIf   
 
    Debug ErrorMessage$
    ;OutputDebugString_(ErrorMessage$)
EndProcedure

Procedure x5()
ErrorHandler()
EndProcedure

Procedure x4()
 x5()
EndProcedure

Procedure x3()
 x4()
EndProcedure

Procedure x2()
 x3()
EndProcedure

Procedure x1()
 x2()
EndProcedure

BackTraceInit()
x1()



As we can see here
Image
all calls in the right places.

We expect addresses of x1() - x5() at the output, but what we get is just one frame from ntdll (or from our app in other cases, nevermind).
What am I doing wrong? Where is full calls list?

P.S.
Or maybe you have better solution not based on CaptureStackBackTrace?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye