Changeset 167 for ExceptionLogger/UStackTrace.pas
- Timestamp:
- Feb 10, 2011, 4:07:44 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ExceptionLogger/UStackTrace.pas
r39 r167 24 24 MaxDepth: Integer; 25 25 procedure GetExceptionBackTrace; 26 procedure GetCallStack; 26 procedure GetCallStack(BP: Pointer); 27 procedure GetCurrentCallStack; 27 28 constructor Create; 28 29 end; … … 54 55 end; 55 56 56 procedure TStackTrace.GetCallStack ;57 procedure TStackTrace.GetCallStack(BP: Pointer); 57 58 var 58 59 I: Longint; 59 60 prevbp: Pointer; 60 CallerFrame, 61 CallerAddress, 62 bp: Pointer; 61 CallerFrame: Pointer; 62 CallerAddress: Pointer; 63 63 StackFrameInfo: TStackFrameInfo; 64 64 begin 65 65 Clear; 66 //routine adapted from fpc source67 68 bp := get_frame;69 //This trick skip SendCallstack item70 // bp := get_caller_frame(get_frame);71 66 try 72 prevbp := bp - 1;73 67 I := 0; 74 //is_dev:=do_isdevice(textrec(f).Handle); 75 while bp > prevbp do begin 76 CallerAddress := get_caller_addr(bp); 77 CallerFrame := get_caller_frame(bp); 78 if (CallerAddress = nil) then 79 Break; 80 StackFrameInfo := TStackFrameInfo.Create; 81 StackFrameInfo.GetFrameInfo(CallerAddress); 82 StackFrameInfo.Index := I + 1; 83 Add(StackFrameInfo); 84 Inc(I); 85 if (I >= MaxDepth) or (CallerFrame = nil) then 86 Break; 87 prevbp := bp; 88 bp := CallerFrame; 89 end; 90 except 91 { prevent endless dump if an exception occured } 92 end; 68 while (BP <> nil) and (I < MaxDepth) do begin 69 CallerAddress := TStackFrameInfo(get_caller_addr(BP)); 70 StackFrameInfo := TStackFrameInfo.Create; 71 StackFrameInfo.GetFrameInfo(CallerAddress); 72 StackFrameInfo.Index := I + 1; 73 Add(StackFrameInfo); 74 Inc(I); 75 BP := TStackFrameInfo(get_caller_frame(BP)); 76 end; 77 except 78 { prevent endless dump if an exception occured } 79 end; 93 80 end; 94 81 … … 122 109 end; 123 110 124 111 procedure TStackTrace.GetCurrentCallStack; 112 begin 113 GetCallStack(get_frame); 114 end; 125 115 126 116 end.
Note:
See TracChangeset
for help on using the changeset viewer.