⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.pas

📁 一个编译器源代码。用法看里面的“使用说明”
💻 PAS
字号:
unit Debug;

interface

uses
  Windows, SysUtils;

procedure AppDebug(Filename, Params: String; DebugIt: Boolean);

implementation

// For more stuff -> Iczelion's Win32 Assembly Tutorial 28-30 (c:\masm\...)

procedure AppDebug(Filename, Params: String; DebugIt: Boolean);
var
  startup: STARTUPINFO;
  dbgevent: DEBUG_EVENT;
  pi: PROCESS_INFORMATION;
  str: String;
  dodebug: Boolean;
procedure ShowMenu;
begin
  if DebugIt then
  begin
    Write('- ');
    ReadLn(str);
    { Show/set registers and other debug functions }
  end;
end;
begin
  dodebug := True;
  GetStartupInfo(startup);
  CreateProcess(nil,PChar(Filename+' '+Params),nil,nil,False,DEBUG_PROCESS+DEBUG_ONLY_THIS_PROCESS,nil,nil,startup,pi);
  while dodebug = True do
  begin
    WaitForDebugEvent(dbgevent,INFINITE);
    if dbgevent.dwDebugEventCode = EXIT_PROCESS_DEBUG_EVENT then
    begin
      if DebugIt then WriteLn('Debug: Debug exits process.');
      dodebug := False;
    end
    else if dbgevent.dwDebugEventCode = CREATE_PROCESS_DEBUG_EVENT then
    begin
      if DebugIt then WriteLn('File Handle:    '+IntToHex(dbgevent.CreateProcessInfo.hFile,8)+#13#10+
                              'Process Handle: '+IntToHex(Int64(dbgevent.CreateProcessInfo.hProcess),8)+#13#10+
                              'Thread Handle:  '+IntToHex(dbgevent.CreateProcessInfo.hThread,8)+#13#10+
                              'Image Base:     '+IntToHex(Int64(dbgevent.CreateProcessInfo.lpBaseOfImage),8)+#13#10+
                              'Start Address:  '+IntToHex(Int64(dbgevent.CreateProcessInfo.lpStartAddress),8));
    end
    else if dbgevent.dwDebugEventCode = CREATE_THREAD_DEBUG_EVENT then
    begin
      if DebugIt then WriteLn('Debug: A new thread is created.');
    end
    else if dbgevent.dwDebugEventCode = EXIT_THREAD_DEBUG_EVENT then
    begin
      if DebugIt then WriteLn('Debug: A thread is destroyed.');
    end
    else if dbgevent.dwDebugEventCode = EXCEPTION_DEBUG_EVENT then
    begin
      if dbgevent.Exception.ExceptionRecord.ExceptionCode = EXCEPTION_BREAKPOINT then
      begin
        ContinueDebugEvent(dbgevent.dwProcessId,dbgevent.dwThreadId,DBG_CONTINUE);
      end
      else
      begin
        WriteLn('Debug Error: ...');
        { Find line out of offset }
      end;
    end;
    { After each statement in source (or run to cursor) -> ShowMenu;}
    ContinueDebugEvent(dbgevent.dwProcessId,dbgevent.dwThreadId,DBG_EXCEPTION_NOT_HANDLED);
  end;
  CloseHandle(pi.hProcess);
  CloseHandle(pi.hThread);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -