AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Debuginformation mit eigenem Programm auswerten
Thema durchsuchen
Ansicht
Themen-Optionen

Debuginformation mit eigenem Programm auswerten

Ein Thema von I.A · begonnen am 20. Feb 2007 · letzter Beitrag vom 20. Feb 2007
Antwort Antwort
I.A

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

Debuginformation mit eigenem Programm auswerten

  Alt 20. Feb 2007, 12: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
shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#2

Re: Debuginformation mit eigenem Programm auswerten

  Alt 20. Feb 2007, 16:29
Die Deklaration in Unit Windows sieht so aus:
function WaitForDebugEvent(var lpDebugEvent: TDebugEvent; dwMilliseconds: DWORD): BOOL; stdcall; Also muss der Aufruf so aussehen:
WaitForDebugEvent(DebugEv, INFINITE); // ohne @-Zeichen Ansonsten: so einfach ist die Ganze Sache nicht.
http://msdn2.microsoft.com/en-us/library/ms681423.aspx
Andreas
  Mit Zitat antworten Zitat
20. Feb 2007, 17:51
Dieses Thema wurde von "r_kerber" von "Programmieren allgemein" nach "Windows API / MS.NET Framework API" verschoben.
Frage zur Windows API
I.A

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

Re: Debuginformation mit eigenem Programm auswerten

  Alt 20. Feb 2007, 20:57
Danke shmia. Da brauch ich mich nich zu wundern, das mein Code nich gefunzt hat. Werde meinen Code morgen ändern.

Hab Deinen Microsoft Link mal angeklickt. Da muss ich ja sagen, das die Hilfe von Turbo Delphi richtig gut ist. Viel mehr steht bei Microsoft dann auch nich mehr. Ist wirklich nich so ganz einfach, aber ich will das jetzt schaffen, einen kleinen Debugger zu bauen. Und wenn der erst mal nur an eine Sprache gebunden ist. Haptsache der funzt erst mal. Hab ich mir nun mal vorgenommen. Die Profies schaffen's ja auch. Und ich habe dazu Zeit. Die Profis haben Termine.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:02 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz