Ignore:
Timestamp:
Aug 17, 2011, 10:08:55 AM (13 years ago)
Author:
george
Message:
  • Modified: Now detailed info is displayed after user click Details. User will see at first only necessary error message.
  • Modified: Now methods in TStackTrace class loads call stack and exception stack only as list of frame address. Then delayed GetInfo method should be called to fully load call stack debug information. This is useful in case of external debug file where loading time could be significant.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ExceptionLogger/UStackTrace.pas

    r167 r264  
    2222
    2323  TStackTrace = class(TObjectList)
     24    Frames: array of Pointer;
    2425    MaxDepth: Integer;
    2526    procedure GetExceptionBackTrace;
    2627    procedure GetCallStack(BP: Pointer);
    2728    procedure GetCurrentCallStack;
     29    procedure GetInfo;
    2830    constructor Create;
    2931  end;
     
    6668  try
    6769    I := 0;
     70    SetLength(Frames, 0);
    6871    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);
     72      SetLength(Frames, Length(Frames) + 1);
     73      Frames[I] := TStackFrameInfo(get_caller_addr(BP));
    7474      Inc(I);
    7575      BP := TStackFrameInfo(get_caller_frame(BP));
     
    8989var
    9090  FrameCount: Integer;
    91   Frames: PPointer;
     91  FramesList: PPointer;
    9292  FrameNumber: Integer;
    93   StackFrameInfo: TStackFrameInfo;
    9493begin
    95   Clear;
    96   StackFrameInfo := TStackFrameInfo.Create;
    97   StackFrameInfo.GetFrameInfo(ExceptAddr);
    98   StackFrameInfo.Index := 1;
    99   Add(StackFrameInfo);
     94  SetLength(Frames, 1);
     95  Frames[0] := ExceptAddr;
    10096  FrameCount := ExceptFrameCount;
    101   Frames := ExceptFrames;
     97  FramesList := ExceptFrames;
    10298  if FrameCount > MaxDepth then FrameCount := MaxDepth;
     99  SetLength(Frames, FrameCount + 1);
    103100  for FrameNumber := 0 to FrameCount - 1 do begin
    104     StackFrameInfo := TStackFrameInfo.Create;
    105     StackFrameInfo.GetFrameInfo(Frames[FrameNumber]);
    106     StackFrameInfo.Index := FrameNumber + 1;
    107     Add(StackFrameInfo);
     101    Frames[FrameNumber + 1] := FramesList[FrameNumber]
    108102  end;
    109103end;
     
    114108end;
    115109
     110procedure TStackTrace.GetInfo;
     111var
     112  I: Integer;
     113  StackFrameInfo: TStackFrameInfo;
     114begin
     115  Clear;
     116  for I := 0 to High(Frames) do begin
     117    StackFrameInfo := TStackFrameInfo.Create;
     118    StackFrameInfo.GetFrameInfo(Frames[I]);
     119    StackFrameInfo.Index := I + 1;
     120    Add(StackFrameInfo);
     121  end;
     122end;
     123
    116124end.
    117125
Note: See TracChangeset for help on using the changeset viewer.