Einzelnen Beitrag anzeigen

I.A

Registriert seit: 14. Jan 2007
83 Beiträge
 
#1

Debuginformation mit eigenem Programm auswerten

  Alt 20. Feb 2007, 13:40
Hallo!

Ich will folgende Funktion aufrufen: WaitForDebugEvent(@DebugEv, INFINITE);

Delphi-Quellcode:

(*

Das hier habe ich mir aus der Delphi Hilfe für Win32 von Turbo Delphi 2006
hierher kopiert, um den üblichen Aufruf zu sehen und nach Pascal portieren
zu können.

DEBUG_EVENT DebugEv;                  // debugging event information
DWORD dwContinueStatus = DBG_CONTINUE; // exception continuation

for(;;)
{

// Wait for a debugging event to occur. The second parameter indicates
// that the function does not return until a debugging event occurs.

    WaitForDebugEvent(&DebugEv, INFINITE);

// Process the debugging event code.

    switch (DebugEv.dwDebugEventCode)
    {
        case EXCEPTION_DEBUG_EVENT:
        // Process the exception code. When handling
        // exceptions, remember to set the continuation
        // status parameter (dwContinueStatus). This value
        // is used by the ContinueDebugEvent function.

            switch (DebugEv.u.Exception.ExceptionRecord.ExceptionCode)
            {
                case EXCEPTION_ACCESS_VIOLATION:
                // First chance: Pass this on to the system.
                // Last chance: Display an appropriate error.
                    break;

                case EXCEPTION_BREAKPOINT:
                // First chance: Display the current
                // instruction and register values.
                    break;

                case EXCEPTION_DATATYPE_MISALIGNMENT:
                // First chance: Pass this on to the system.
                // Last chance: Display an appropriate error.
                    break;

                case EXCEPTION_SINGLE_STEP:
                // First chance: Update the display of the
                // current instruction and register values.
                    break;

                case DBG_CONTROL_C:
                // First chance: Pass this on to the system.
                // Last chance: Display an appropriate error.
                    break;

                default;
                // Handle other exceptions.
                    break;
            }

        case CREATE_THREAD_DEBUG_EVENT:
        // As needed, examine or change the thread's registers
        // with the GetThreadContext and SetThreadContext functions;
        // and suspend and resume thread execution with the
        // SuspendThread and ResumeThread functions.
            break;

        case CREATE_PROCESS_DEBUG_EVENT:
        // As needed, examine or change the registers of the
        // process's initial thread with the GetThreadContext and
        // SetThreadContext functions; read from and write to the
        // process's virtual memory with the ReadProcessMemory and
        // WriteProcessMemory functions; and suspend and resume
        // thread execution with the SuspendThread and ResumeThread
        // functions. Be sure to close the handle to the process image
        // file with CloseHandle.
            break;

        case EXIT_THREAD_DEBUG_EVENT:
        // Display the thread's exit code.
            break;

        case EXIT_PROCESS_DEBUG_EVENT:
        // Display the process's exit code.
            break;

        case LOAD_DLL_DEBUG_EVENT:
        // Read the debugging information included in the newly
        // loaded DLL. Be sure to close the handle to the loaded DLL
        // with CloseHandle.
            break;

        case UNLOAD_DLL_DEBUG_EVENT:
        // Display a message that the DLL has been unloaded.
            break;

        case OUTPUT_DEBUG_STRING_EVENT:
        // Display the output debugging string.
            break;

    }

// Resume executing the thread that reported the debugging event.

ContinueDebugEvent(DebugEv.dwProcessId, DebugEv.dwThreadId, dwContinueStatus);

}
*)

unit dbgbase;

interface

uses
  SysUtils,
  Windows,
  Messages,
  ShellApi;

type
  lpDebugEvent = PDebugEvent;

const
  dwContinueStatus = DBG_CONTINUE;

var
  DebugEv: TDebugEvent;


implementation

function Debug: DWORD;
begin
  WaitForDebugEvent(@DebugEv, INFINITE); //Hier die Fehlermeldung des Compilers
end;


end.
Der Compiler meckert hier mit der Fehlermeldung:

[Pascal Fehler] dbgbase.pas(127): E2033 Die Typen der tatsächlichen und formalen Var-Parameter müssen übereinstimmen

Deshalb meine Fragen:

-Wie muss ich die Variable DebugEv definieren, damit der Compiler das schluckt?

-Wo erhalte ich eine Doku zum Aufbau der Debuginformation.
{Für Dwarf habe ich was da, aber wie ist das Debuginfo-Format bei Borland?}
{Wenn ich also mit eigenem Debugger Delphi Exe-n debuggen will?}

-Welche Hesderinfo ist für heutiges Windows verbindlich? Gibt es da zwischen den Windows
Versionen Unterschiede? Hab mal im Lazarus Projekt gestöbert. Die nehmen Dwarf Debuginfo.
Nur brauch ich da auch eine prinzipielle Methode, an die Programmstartadresse
ranzukommen und dann Schrittbetrieb zu machen. Wie geht sowas. Ich blicke bei den Lazarusquellen
nich durch. Außerdem bringt mir eine dort definierte Prozedur

DumpPEHeader(ProcessHandle,Degugaddr)

die Meldung "Ungültiger DOD Header"

Nur NT Header abzusuchen bringt auch nix.

-Wie realisiere ich, so ich alle Debuginfos habe und deren Format kapiert,
den Schrittbetrieb. Wo gibt es dazu weitere Infos. Die Microsoft Doku ist mir da
zu kryptisch. Gibt es bessere Dokus? Wenn ja, wo?

-Hab mal in die Windows Unit geguckt. Es gibt dort im DebugEv.Exception-Feld ein Datenfeld
dwFirstChance. Aber ein Feld für LastChance konnte ich nicht finden. Was muss in dwFirstChance stehen,
damit ich debuggen kann?

-Wie definiere ich überhaupt Haltepunkte (Breakpoints)? Wenn ich auf Assemblerlevel debuggen will, müsste
ich ja nach jedem einzelenen Befehl anhalten, außer, wenn ich den Call insgesamt überspringen will.
Aber auf Sourcelevel???? Woher weiß der Debugger, wie lang meine Pascalanweisung ist?

Fragen über Fragen. Aber wenn man schon mal Zeit hat. Hab das Projekt mit paar Kumpels in Arbeit.
Jetzt mach ich erst mal n break und hoffe, das Ihr mir helfen könnt. Danke schon mal.
  Mit Zitat antworten Zitat