2008-11-03 3 views
15

Ich möchte eine Stapelüberwachung in einem Fehlerdialogfeld in Delphi 2007 (Win32) anzeigen.Zeigen Sie den Aufrufstapel in einer Delphi Win32-Anwendung an

Idealerweise würde ich so etwas wie dies mag:

try 
    //do something 
except on e : exception do 
    begin 
    //rollback a transaction or whatever i need to do here  
    MessageDlg('An error has occurred!' + #13#10 + 
       e.Message + #13#10 + 
       'Here is the stack trace:' + #13#10 + 
       e.StackTrace,mtError,[mbOK],0); 
    end; //except 
end; /try-except 

Und für die Ausgabe in den IDE wie der Call Stack sein:

MYPROGRAM.SomeFunction 
MYPROGRAM.SomeProcedure 
MYPROGRAM.MYPROGRAM 
:7c817067 kernel32.RegisterWaitForInputIdle + 0x49 
+1

OT: Ich würde ['sLineBreak'] (http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/System_sLineBreak.html) anstelle von hardcoded' # 13 # verwenden 10'. –

Antwort

23

madExcept hat eine Methode Stacktrace (in Einheit madStackTrace), die das tun.

JEDI Code Library bietet ähnliche Funktionalität in Einheit JclDebug.

+5

madExcept ist nicht für die kommerzielle Nutzung frei. JclDebug ist kostenlos und Open Source. Es gibt auch EurekaLog (http://www.eurekalog.com/) –

+0

AFAIK, Eurekalog verwendet den JEDI-Code. –

+1

>>> Eurekalog verwendet den JEDI-Code Das ist nicht 100% richtig. Ja, EL enthält Teile des JCL-Codes, aber nur für das unterstützende JDBG-Format und ähnliche Probleme. Die Engine selbst ist von Grund auf neu geschrieben. Auch EL verwendet ein eigenes Format für Debug-Informationen (nicht JDBG). – Alex

8

Wir verwenden Exceptional Magic und es funktioniert wirklich gut für uns. Mit ihm können Sie etwas tun:

try 
    raise Exception.Create('Something bad happened...'); 
except 
    on e: Exception do begin 
     CallStack := TStringList.Create; 
     try 
      ExceptionHook.LogException; // Logs call stack 
      ExceptionHook.CallStack.Dump(CallStack); 
      ShowMessage(CallStack.Text); 
     finally 
      CallStack.Free; 
      end; 
     end; 
    end; 

Dies ergibt einen ziemlich detaillierten Call-Stack:

Exception 'Exception' in module BOAppTemplate.exe at 003F3C36 
Something bad happened... 

Module: BOAppUnit, Source: BOAppUnit.pas, Line 66 
Procedure: MyProcedure 

Call stack: 
:007F4C36 [BOAppTemplate.exe] MyProcedure (BOAppUnit.pas, line 66) 
:7C812AFB [kernel32.dll] 
:007F4C36 [BOAppTemplate.exe] MyProcedure (BOAppUnit.pas, line 66) 
:00404DF4 [BOAppTemplate.exe] System::__linkproc__ AfterConstruction 
Recursive call (2 times): 
:007F4C36 [BOAppTemplate.exe] MyProcedure (BOAppUnit.pas, line 66) 
:007F4CE6 [BOAppTemplate.exe] MyProcedure (BOAppUnit.pas, line 79) 
:007F4D22 [BOAppTemplate.exe] Boappunit::TBOAppForm::Button1Click (BOAppUnit.pas, line 82) 
:004604C2 [BOAppTemplate.exe] Controls::TControl::Click 
:004487FB [BOAppTemplate.exe] Stdctrls::TButton::Click 
:004488F9 [BOAppTemplate.exe] Stdctrls::TButton::CNCommand 
:0045FFBA [BOAppTemplate.exe] Controls::TControl::WndProc 

Außergewöhnliche Magie ist nur $ 25, ohne die Quelle, also ist es relativ billig. Ich hoffe, das hilft!