Changeset 167 for ExceptionLogger


Ignore:
Timestamp:
Feb 10, 2011, 4:07:44 PM (14 years ago)
Author:
george
Message:
  • Added: Method for obtaining call stack from specified address.
Location:
ExceptionLogger
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ExceptionLogger/UExceptionForm.lfm

    r64 r167  
    1010  OnDestroy = FormDestroy
    1111  OnShow = FormShow
    12   LCLVersion = '0.9.29'
     12  LCLVersion = '0.9.31'
    1313  object ButtonClose: TButton
    1414    Left = 611
     
    3636    Top = 3
    3737    Width = 678
    38     ActivePage = TabSheet1
     38    ActivePage = TabSheet2
    3939    Anchors = [akTop, akLeft, akRight, akBottom]
    40     TabIndex = 0
     40    TabIndex = 1
    4141    TabOrder = 2
    4242    object TabSheet1: TTabSheet
     
    7676          end       
    7777          item
     78            Caption = 'Line'
     79            Width = 71
     80          end       
     81          item
    7882            Caption = 'Class'
    7983            Width = 150
     
    8690            Caption = 'Unit'
    8791            Width = 150
    88           end       
    89           item
    90             Caption = 'Line'
    91             Width = 71
    9292          end>
    93         ItemIndex = -1
    9493        ReadOnly = True
    9594        RowSelect = True
  • ExceptionLogger/UExceptionForm.lrt

    r40 r167  
    1 TEXCEPTIONFORM.EXCEPTIONFORM.CAPTION=Exception info
     1TEXCEPTIONFORM.CAPTION=Exception info
    22TEXCEPTIONFORM.BUTTONCLOSE.CAPTION=Close
    33TEXCEPTIONFORM.BUTTONKILL.CAPTION=Terminate
     
    66TEXCEPTIONFORM.LISTVIEW1.COLUMNS[0].CAPTION=Index
    77TEXCEPTIONFORM.LISTVIEW1.COLUMNS[1].CAPTION=Address
    8 TEXCEPTIONFORM.LISTVIEW1.COLUMNS[2].CAPTION=Class
    9 TEXCEPTIONFORM.LISTVIEW1.COLUMNS[3].CAPTION=Procedure/method
    10 TEXCEPTIONFORM.LISTVIEW1.COLUMNS[4].CAPTION=Unit
    11 TEXCEPTIONFORM.LISTVIEW1.COLUMNS[5].CAPTION=Line
     8TEXCEPTIONFORM.LISTVIEW1.COLUMNS[2].CAPTION=Line
     9TEXCEPTIONFORM.LISTVIEW1.COLUMNS[3].CAPTION=Class
     10TEXCEPTIONFORM.LISTVIEW1.COLUMNS[4].CAPTION=Procedure/method
     11TEXCEPTIONFORM.LISTVIEW1.COLUMNS[5].CAPTION=Unit
    1212TEXCEPTIONFORM.CHECKBOXIGNORE.CAPTION=Next time ignore this exception
  • ExceptionLogger/UExceptionForm.pas

    r129 r167  
    8181        Caption := IntToStr(Index);
    8282        SubItems.Add(IntToHex(Address, 8));
     83        SubItems.Add(IntToStr(LineNumber));
    8384        SubItems.Add(FunctionClassName);
    8485        SubItems.Add(FunctionName);
    8586        SubItems.Add(Source);
    86         SubItems.Add(IntToStr(LineNumber));
    8787      end;
    8888    end;
  • ExceptionLogger/UExceptionLogger.pas

    r165 r167  
    140140
    141141procedure TExceptionLogger.ExceptionHandler(Sender: TObject; E: Exception);
     142var
     143  Thread: TThread;
    142144begin
    143145  BackTraceStrFunc := @StabBackTraceStr;
  • ExceptionLogger/UStackTrace.pas

    r39 r167  
    2424    MaxDepth: Integer;
    2525    procedure GetExceptionBackTrace;
    26     procedure GetCallStack;
     26    procedure GetCallStack(BP: Pointer);
     27    procedure GetCurrentCallStack;
    2728    constructor Create;
    2829  end;
     
    5455end;
    5556
    56 procedure TStackTrace.GetCallStack;
     57procedure TStackTrace.GetCallStack(BP: Pointer);
    5758var
    5859  I: Longint;
    5960  prevbp: Pointer;
    60   CallerFrame,
    61   CallerAddress,
    62   bp: Pointer;
     61  CallerFrame: Pointer;
     62  CallerAddress: Pointer;
    6363  StackFrameInfo: TStackFrameInfo;
    6464begin
    6565  Clear;
    66   //routine adapted from fpc source
    67 
    68   bp := get_frame;
    69   //This trick skip SendCallstack item
    70   // bp := get_caller_frame(get_frame);
    7166  try
    72     prevbp := bp - 1;
    7367    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;
    9380end;
    9481
     
    122109end;
    123110
    124 
     111procedure TStackTrace.GetCurrentCallStack;
     112begin
     113  GetCallStack(get_frame);
     114end;
    125115
    126116end.
Note: See TracChangeset for help on using the changeset viewer.