Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JclDebug not including line numbers

I just recently upgraded from Delphi 7 to Delphi 10.1 Berlin and got jedi vcl 2.8 installed. Failed to installed for 32-bit (bcc32.exe not found) but was successful for 64-bit but that's another issue.

I am using jclDebug to capture error messages and I am using it according to: https://blog.gurock.com/working-with-delphis-new-exception-stacktrace.

unit StackTrace;

interface

uses
SysUtils, Classes, JclDebug;

implementation

function GetExceptionStackInfoProc(P: PExceptionRecord): Pointer;
var
  LLines: TStringList;
  LText: String;
  LResult: PChar;
begin
  LLines := TStringList.Create;
  try
    JclLastExceptStackListToStrings(LLines, True, True, True, True);
    LText := LLines.Text;
    LResult := StrAlloc(Length(LText));
    StrCopy(LResult, PChar(LText));
    Result := LResult;
  finally
    LLines.Free;
  end;
end;

function GetStackInfoStringProc(Info: Pointer): string;
begin
  Result := string(PChar(Info));
end;

procedure CleanUpStackInfoProc(Info: Pointer);
begin
  StrDispose(PChar(Info));
end;

initialization
// Start the Jcl exception tracking and register our Exception
// stack trace provider.
if JclStartExceptionTracking then
begin
  Exception.GetExceptionStackInfoProc := GetExceptionStackInfoProc;
  Exception.GetStackInfoStringProc := GetStackInfoStringProc;
  Exception.CleanUpStackInfoProc := CleanUpStackInfoProc;
  JCLdebug.JclStackTrackingOptions:=[stStack, stRawMode]; // I added this hoping it would help.
end;

finalization
// Stop Jcl exception tracking and unregister our provider.
if JclExceptionTrackingActive then
begin
  Exception.GetExceptionStackInfoProc := nil;
  Exception.GetStackInfoStringProc := nil;
  Exception.CleanUpStackInfoProc := nil;
  JclStopExceptionTracking;
end;
end.

When I catch an exception I log it to this method

procedure TLoggerForDynacViews.Log(sLog:wideString; ExceptObj:TObject = nil; displayErrorCaught : Boolean = true);
        var myFile: TextFile;
        sFile : String;
        StrList: TStringList;
        companyId : String;
    begin

      try
        sFile := Globals.LogFileName;
        try
          companyId := Store.CompanyId;
        except
          companyId := 'N/A';
        end;
        try

          AssignFile(myFile, sFile);
          if (FileExists(sFile)) then
            Append(myFile)
          else
            Rewrite(myFile);

          WriteLn(myFile, companyId + ' ('+ExcelApp.Caption +')');
          if (ExceptObj <> nil) then begin
            try
              StrList := TStringList.Create;
              StrList.Add(Format('{ Original Exception - %s }', [Exception(ExceptObj).Message]));
              StrList.Add(Exception(ExceptObj).StackTrace);
              StrList.Add('{ _______End of the exception stact trace block_______ }');
              StrList.Add(' ');
              if displayErrorCaught then
                ShowMessage('Error has been caught.  See DynacViews->About->Log File for details.');
              WriteLn(myFile, FormatDateTime('c',Now) + ' - ' + StrList.Text);
              Exit;
            finally
              StrList.Free;
            end;
          end;


          WriteLn(myFile, FormatDateTime('c',Now) + ' - ' + sLog);
        finally
          CloseFile(myFile);
        end;
      except

      end;
    end;

But I am not getting line numbers. In Delphi 7 I was getting very useful output but with the latest delphi and jcldebug I am getting helpful but not as nearly has helpful as it could be.

12/09/2016 11:59:55 AM - { Original Exception - Access violation at address  0000000012D60027 in module 'DynacViews2b.dll'. Read of address 000000000000002A  }
(00000000006F1E1D){DynacViews2b.dll} [0000000012E62E1D]  JclDebug._ZN8Jcldebug17TJclStackInfoListC3EbiPvbS1_S1_ + $10D
(00000000006F19F8){DynacViews2b.dll} [0000000012E629F8]   JclDebug._ZN8Jcldebug18JclCreateStackListEbiPvbS0_ + $48
(00000000006F1909){DynacViews2b.dll} [0000000012E62909] JclDebug._ZN8Jcldebug21DoExceptionStackTraceEPN6System7TObjectEPvbS3_ + $79
(00000000006F3233){DynacViews2b.dll} [0000000012E64233] JclDebug._ZN8Jcldebug14DoExceptNotifyEPN6System7TObjectEPvbS3_ + $93
(00000000006E4B85){DynacViews2b.dll} [0000000012E55B85] JclHookExcept._ZN13Jclhookexcept13TNotifierItem8DoNotifyEPN6System7TObjectEPvbS4_ + $35
(00000000006E4DCC){DynacViews2b.dll} [0000000012E55DCC] JclHookExcept._ZN13Jclhookexcept14DoExceptNotifyEPN6System7TObjectEPvbS3_ + $BC
(00000000006E4F1E){DynacViews2b.dll} [0000000012E55F1E] JclHookExcept._ZN13Jclhookexcept20HookedRaiseExceptionEjjjPNS_19TExceptionArgumentsE + $6E
(000000000000EBB6){DynacViews2b.dll} [000000001277FBB6] System._ZN6System14_RaiseAtExceptEPNS_7TObjectEPv + $106
(000000000000EBE1){DynacViews2b.dll} [000000001277FBE1] System._ZN6System12_RaiseExceptEPNS_7TObjectE + $11
(0000000000166164){DynacViews2b.dll} [00000000128D7164] System.Win.ComObj._ZN6System3Win6Comobj19DispatchInvokeErrorEiRK12tagEXCEPINFO + $C4
(0000000000165BA5){DynacViews2b.dll} [00000000128D6BA5] System.Win.ComObj._ZN6System3Win6Comobj14DispatchInvokeENS_15DelphiInterfaceI9IDispatchEEPNS_9TCallDescEPNS_11StaticArrayIiLi65536EEEPvPNS_7VariantE + $275
(0000000000166087){DynacViews2b.dll} [00000000128D7087] System.Win.ComObj._ZN6System3Win6Comobj13VarDispInvokeEPNS_7VariantERKS2_PNS_9TCallDescEPv + $B7
(000000000005162E){DynacViews2b.dll} [00000000127C262E] System.Variants._ZN6System8Variants14DispInvokeCoreEP8TVarDataRKS1_PNS_9TCallDescEPv + $BE
(0000000000051731){DynacViews2b.dll} [00000000127C2731] System.Variants._ZN6System8Variants11_DispInvokeEP8TVarDataRKS1_PNS_9TCallDescE + $41
(000000000071A595){DynacViews2b.dll} [0000000012E8B595] ExcelWrapperTypes._ZN17Excelwrappertypes25TCustomDocumentProperties8GetValueEN6System13UnicodeStringERKNS1_7VariantE + $75
(000000000071A7D8){DynacViews2b.dll} [0000000012E8B7D8] ExcelWrapperTypes._ZN17Excelwrappertypes25TCustomDocumentProperties9GetStringEN6System13UnicodeStringES2_ + $78
(0000000000692BFF){DynacViews2b.dll} [0000000012E03BFF] StoreClasses._ZN12Storeclasses8TStorage23loadCustomDocumentPropsEN6System15DelphiInterfaceIN12Excelwrapper9IWorkbookEEE + $72F
(0000000000720329){DynacViews2b.dll} [0000000012E91329] DynacViewForBook._ZN16Dynacviewforbook17TDynacViewForBook14GetViewForBookEN6System15DelphiInterfaceIN9Excel20009_WorkbookEEEb + $69
(0000000000728978){DynacViews2b.dll} [0000000012E99978] AddinMenu._ZN9Addinmenu20TColumnTemplatesMenuC3EPN8Adxaddin19TadxCommandBarPopupEU9__closurePFvN6System13UnicodeStringEE + $E8
(000000000072867A){DynacViews2b.dll} [0000000012E9967A] AddinMenu._ZN9Addinmenu11TColumnMenuC3EPN8Adxaddin15TadxContextMenuEU9__closurePFvN6System13UnicodeStringEE + $13A
(00000000007258DE){DynacViews2b.dll} [0000000012E968DE] AddinMenu._ZN9Addinmenu11TDynacMenus9BuildMenuEU9__closurePFvN6System13UnicodeStringEE + $9E
(000000000075CB3C){DynacViews2b.dll} [0000000012ECDB3C] DynacViewBook._ZN13Dynacviewbook14TDynacViewBook13BuildMainMenuEv + $8C
(0000000000740B02){DynacViews2b.dll} [0000000012EB1B02] DynacViewBook._ZN13Dynacviewbook14TDynacViewBook18OnWorkbookActivateEv + $6F2
(00000000007CE499){DynacViews2b.dll} [0000000012F3F499] DynacViews2b_IMPL._ZN17Dynacviews2b_impl12TAddInModule18OnWorkbookActivateEPN6System7TObjectENS1_15DelphiInterfaceIN9Excel20009_WorkbookEEE + $49
(00000000005A79DA){DynacViews2b.dll} [0000000012D189DA] adxHostAppEvents._ZN16Adxhostappevents18TadxExcelAppEvents11InvokeEventEiRN6System12DynamicArrayINS1_10OleVariantEEE + $A2A
(00000000005A0CC1){DynacViews2b.dll} [0000000012D11CC1] adxHostAppEvents._ZN16Adxhostappevents17TadxEventDispatch6InvokeEiRK5_GUIDitPvS4_S4_S4_ + $151
(00000000002CE49D){EXCEL.EXE   } [000000013F9EF49D] Unknown function at  + $2CF49D
(00000000002CE2E6){EXCEL.EXE   } [000000013F9EF2E6] Unknown function at  + $2CF2E6
(000000000017BA40){EXCEL.EXE   } [000000013F89CA40] Unknown function at  + $17CA40
(0000000000120138){EXCEL.EXE   } [000000013F841138] Unknown function at  + $121138
(000000000011FB65){EXCEL.EXE   } [000000013F840B65] Unknown function at  + $120B65
(000000000011F95F){EXCEL.EXE   } [000000013F84095F] Unknown function at  + $12095F
(0000000000129B75){EXCEL.EXE   } [000000013F84AB75] Unknown function at  + $12AB75
(00000000000E0BD0){EXCEL.EXE   } [000000013F801BD0] Unknown function at  + $E1BD0
(000000000006B44A){EXCEL.EXE   } [000000013F78C44A] Unknown function at  + $6C44A
(0000000000EB6035){EXCEL.EXE   } [00000001405D7035] Unknown function at LinkASPPModelTable + $3F60E5
(0000000000BA53BD){EXCEL.EXE   } [00000001402C63BD] Unknown function at LinkASPPModelTable + $E546D
(00000000000587D5){EXCEL.EXE   } [000000013F7797D5] Unknown function at  + $597D5
(00000000000BE448){EXCEL.EXE   } [000000013F7DF448] Unknown function at  + $BF448
(0000000000019484){EXCEL.EXE   } [000000013F73A484] Unknown function at  + $1A484
(00000000000F1D01){EXCEL.EXE   } [000000013F812D01] Unknown function at  + $F2D01
(00000000000149BD){kernel32.dll} [00000000779E59BD] BaseThreadInitThunk + $D
(00000000000292E1){ntdll.dll   } [0000000077C1A2E1] RtlUserThreadStart + $21

While the above is helpful I really miss the line numbers.

For my project Debug Information is true and include remote debug symbols. I am not sure what properties need to be set.

Edit: Issue appears to be due to my map file not having line numbers in it. My delphi 7 map file has many :

Line numbers for DynacViewBook(DynacViewBook.pas) segment .text

But I have none of these in my Delphi 10.1 map file.

Here is my options for linking delphi linker options

like image 671
Chris B. Avatar asked Oct 23 '25 19:10

Chris B.


1 Answers

So I finally figured it out. Part of the problem when I migrated from Delphi 7 to Delphi 10.1 was I did not ensure that my compiling and linking options transferred correctly. I made an assumption that the settings were correct.

The reason I was missing linking information was I needed in the compiling options Use Debug .DCU's to see my own pas files and Local Symbols to see the delphi pas files along with Debug Information.

I had to delete my .dcu's and re-compile before the line information appeared.

Edit: Strange thing is the mapping file contains the name

DynacViewBook.TDynacViewBook.OnWorkbookActivate

and

DynacViewBook.$pdata$_ZN13Dynacviewbook14TDynacViewBook18OnWorkbookActivateEv

And the StackTrace contains the ugly method not the pretty method name. My delphi 7 map file does not contain any ugly names.

Even the delphi debug information is ugly names. Must be a setting.

like image 176
Chris B. Avatar answered Oct 26 '25 09:10

Chris B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!