mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-23 00:19:37 +02:00
* backup
git-svn-id: trunk@9697 -
This commit is contained in:
parent
b79d6a7b7d
commit
cec4ac6957
6
.gitattributes
vendored
6
.gitattributes
vendored
@ -626,6 +626,7 @@ debugger/watchesdlg.pp svneol=native#text/pascal
|
||||
debugger/watchpropertydlg.lfm svneol=native#text/plain
|
||||
debugger/watchpropertydlg.lrs svneol=native#text/pascal
|
||||
debugger/watchpropertydlg.pp svneol=native#text/pascal
|
||||
debugger/windebug/fpdd/fpdumpdwarf.lpr svneol=native#text/pascal
|
||||
debugger/windebug/fpwd/README.txt svneol=native#text/plain
|
||||
debugger/windebug/fpwd/fpwd.lpr svneol=native#text/pascal
|
||||
debugger/windebug/fpwd/fpwdcommand.pas svneol=native#text/pascal
|
||||
@ -638,10 +639,15 @@ debugger/windebug/test/asmtest.lpr svneol=native#text/pascal
|
||||
debugger/windebug/test/asmtestunit.lfm svneol=native#text/plain
|
||||
debugger/windebug/test/asmtestunit.lrs svneol=native#text/plain
|
||||
debugger/windebug/test/asmtestunit.pas svneol=native#text/pascal
|
||||
debugger/windebug/winddwarf.pas svneol=native#text/pascal
|
||||
debugger/windebug/winddwarfconst.pas svneol=native#text/pascal
|
||||
debugger/windebug/windebugger.pp svneol=native#text/pascal
|
||||
debugger/windebug/windextra.pp svneol=native#text/pascal
|
||||
debugger/windebug/windisas.pp svneol=native#text/plain
|
||||
debugger/windebug/windloader.pp svneol=native#text/pascal
|
||||
debugger/windebug/windpetypes.pp svneol=native#text/pascal
|
||||
debugger/windebug/windsymbols.pas svneol=native#text/pascal
|
||||
debugger/windebug/windutil.pp svneol=native#text/pascal
|
||||
designer/abstractcompiler.pp svneol=native#text/pascal
|
||||
designer/abstracteditor.pp svneol=native#text/pascal
|
||||
designer/abstractfilesystem.pp svneol=native#text/pascal
|
||||
|
219
debugger/windebug/fpdd/fpdumpdwarf.lpr
Normal file
219
debugger/windebug/fpdd/fpdumpdwarf.lpr
Normal file
@ -0,0 +1,219 @@
|
||||
{ $Id$ }
|
||||
{
|
||||
---------------------------------------------------------------------------
|
||||
fpdumpdwarf - DWARF debug dump
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Utility to test and dump DWARF dubug info.
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
@created(Sat Jul 1th WET 2006)
|
||||
@lastmod($Date$)
|
||||
@author(Marc Weustink <marc@@dommelstein.nl>)
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* This source is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This code is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* General Public License for more details. *
|
||||
* *
|
||||
* A copy of the GNU General Public License is available on the World *
|
||||
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
||||
* obtain it by writing to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
* *
|
||||
***************************************************************************
|
||||
}
|
||||
program FPDumpDwarf;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Classes, Windows, SysUtils, WinDDwarf, WinDPETypes, WinDDwarfConst,
|
||||
WinDSymbols, WinDLoader;
|
||||
|
||||
var
|
||||
ModulePtr: Pointer;
|
||||
Is64: Boolean;
|
||||
Sections: TStringList;
|
||||
hMap, hFile: THandle;
|
||||
DosHeader: PImageDosHeader;
|
||||
NtHeaders: PImageNtHeaders;
|
||||
SectionHeader, InfoSH, AbbrevSH: PImageSectionHeader;
|
||||
n, idx: Integer;
|
||||
SectionName: array[0..IMAGE_SIZEOF_SHORT_NAME] of Char;
|
||||
AbbrevPtr, AbbrevPtrMax, AbbrevBase: Pointer;
|
||||
InfoPtr, InfoPtrMax: Pointer;
|
||||
InfoOffset: Int64;
|
||||
Abb: Cardinal;
|
||||
CUHeader, NextCUHeader: PDwarfCUHeader32;
|
||||
p: Pointer;
|
||||
|
||||
Dwarf: TDbgDwarf;
|
||||
AbbrevDecoder: TDwarfAbbrevDecoder;
|
||||
|
||||
Loader: TDbgImageLoader;
|
||||
|
||||
begin
|
||||
if ParamCount < 1
|
||||
then begin
|
||||
WriteLN('Usage: FPDumpDwarf <filename>');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
Loader := TDbgWinPEImageLoader.Create(ParamStr(1));
|
||||
|
||||
(*
|
||||
hFile := CreateFile(PChar(ParamStr(1)), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if hFile = INVALID_HANDLE_VALUE
|
||||
then begin
|
||||
WriteLN('Cannot open file: ', ParamStr(1));
|
||||
Exit;
|
||||
end;
|
||||
|
||||
try
|
||||
hMap := 0;
|
||||
ModulePtr := nil;
|
||||
Sections := nil;
|
||||
try
|
||||
hMap := CreateFileMapping(hFile, nil, PAGE_READONLY{ or SEC_IMAGE}, 0, 0, nil);
|
||||
if hMap = 0
|
||||
then begin
|
||||
WriteLn('Could not create module mapping');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
ModulePtr := MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
|
||||
if ModulePtr = nil
|
||||
then begin
|
||||
WriteLn('Could not map view');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
DosHeader := ModulePtr;
|
||||
if (DosHeader^.e_magic <> IMAGE_DOS_SIGNATURE)
|
||||
or (DosHeader^.e_lfanew = 0)
|
||||
then begin
|
||||
WriteLn('Invalid DOS header');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
NTHeaders := ModulePtr + DosHeader^.e_lfanew;
|
||||
|
||||
if NTHeaders^.Signature <> IMAGE_NT_SIGNATURE
|
||||
then begin
|
||||
WriteLn('Invalid NT header: ', IntToHex(NTHeaders^.Signature, 8));
|
||||
Exit;
|
||||
end;
|
||||
|
||||
Is64 := NTHeaders^.OptionalHeader.Magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
|
||||
|
||||
Sections := TStringList.Create;
|
||||
Sections.CaseSensitive := False;
|
||||
Sections.Duplicates := dupIgnore;
|
||||
Sections.Sorted := True;
|
||||
for n := 0 to NtHeaders^.FileHeader.NumberOfSections - 1 do
|
||||
begin
|
||||
SectionHeader := @NTHeaders^.OptionalHeader + NTHeaders^.FileHeader.SizeOfOptionalHeader + SizeOf(SectionHeader^) * n;
|
||||
// make a null terminated name
|
||||
Move(SectionHeader^.Name, SectionName, IMAGE_SIZEOF_SHORT_NAME);
|
||||
SectionName[IMAGE_SIZEOF_SHORT_NAME] := #0;
|
||||
if (SectionName[0] = '/') and (SectionName[1] in ['0'..'9'])
|
||||
then begin
|
||||
// long name
|
||||
p := ModulePtr + NTHeaders^.FileHeader.PointerToSymbolTable + NTHeaders^.FileHeader.NumberOfSymbols * IMAGE_SIZEOF_SYMBOL + StrToIntDef(PChar(@SectionName[1]), 0);
|
||||
Sections.AddObject(PChar(p), TObject(SectionHeader));
|
||||
end
|
||||
else begin
|
||||
// short name
|
||||
Sections.AddObject(SectionName, TObject(SectionHeader));
|
||||
end
|
||||
end;
|
||||
|
||||
WriteLN('Sections:');
|
||||
for n := 0 to Sections.Count - 1 do
|
||||
WriteLn(' ', Sections[n], #9'@$', Format('%p', [Pointer(Sections.Objects[n])]));
|
||||
|
||||
idx := Sections.IndexOf('.debug_info');
|
||||
if idx = -1
|
||||
then begin
|
||||
WriteLn('.debug_info section not found. Nothing to do.');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
InfoSH := Pointer(Sections.Objects[idx]);
|
||||
InfoPtr := ModulePtr + InfoSH^.PointerToRawData;
|
||||
InfoPtrMax := InfoPtr + InfoSH^.Misc.VirtualSize - 1;
|
||||
InfoOffset := PtrUInt(InfoPtr) - NTHeaders^.OptionalHeader.ImageBase - InfoSH^.VirtualAddress;
|
||||
|
||||
idx := Sections.IndexOf('.debug_abbrev');
|
||||
if idx = -1
|
||||
then begin
|
||||
WriteLn('.debug_abbrev section not found. Nothing to do.');
|
||||
Exit;
|
||||
end;
|
||||
AbbrevSH := Pointer(Sections.Objects[idx]);
|
||||
AbbrevPtr := ModulePtr + AbbrevSH^.PointerToRawData;
|
||||
AbbrevPtrMax := AbbrevPtr + AbbrevSH^.Misc.VirtualSize - 1;
|
||||
AbbrevBase := AbbrevPtr - NTHeaders^.OptionalHeader.ImageBase - AbbrevSH^.VirtualAddress;
|
||||
*)
|
||||
Dwarf := TDbgDwarf.Create(Loader);
|
||||
n := Dwarf.LoadCompilationUnits;
|
||||
for idx := 0 to n - 1 do
|
||||
begin
|
||||
Dwarf.CompilationUnits[idx].LoadAbbrevs;
|
||||
AbbrevDecoder := TDwarfAbbrevDecoder.Create(Dwarf.CompilationUnits[idx]);
|
||||
AbbrevDecoder.Decode;
|
||||
end;
|
||||
|
||||
(*
|
||||
CUHeader := InfoPtr;
|
||||
while (CUHeader <> nil) and (CUHeader^.Length > 0) and (CUHeader <= InfoPtrMax) do
|
||||
begin
|
||||
WriteLN('Compilation unit:');
|
||||
WriteLn(' length: ', CUHeader^.Length);
|
||||
WriteLn(' version: ', CUHeader^.Version);
|
||||
WriteLn(' abbrev offset: ', IntToHex(CUHeader^.AbbrevOffset, 8));
|
||||
WriteLn(' address size: ', CUHeader^.AddressSize);
|
||||
|
||||
NextCUHeader := @CUHeader^.Version + CUHeader^.Length;
|
||||
|
||||
p := AbbrevBase + CUHeader^.AbbrevOffset;
|
||||
if (p < AbbrevPtr) or (p > AbbrevPtrMax)
|
||||
then begin
|
||||
WriteLN('Warning: Abbrev offset not in .debug_abbrev section');
|
||||
end;
|
||||
|
||||
if NextCUHeader < InfoPtrMax
|
||||
then Abbrev := TDbgDwarf.Create(InfoOffset, p, AbbrevBase + NextCUHeader^.AbbrevOffset)
|
||||
else Abbrev := TDbgDwarf.Create(InfoOffset, p, AbbrevPtrMax);
|
||||
|
||||
p := CUHeader + 1;
|
||||
Abbrev.Decode(p, Pointer(NextCUHeader) - 1);
|
||||
|
||||
FreeAndNil(Abbrev);
|
||||
|
||||
CUHeader := NextCUHeader;
|
||||
end;
|
||||
*)
|
||||
Dwarf.Free;
|
||||
Loader.Free;
|
||||
(*
|
||||
finally
|
||||
UnmapViewOfFile(ModulePtr);
|
||||
CloseHandle(hMap);
|
||||
Sections.Free;
|
||||
end;
|
||||
finally
|
||||
CloseHandle(hFile);
|
||||
end;
|
||||
*)
|
||||
end.
|
||||
|
@ -44,7 +44,7 @@ uses
|
||||
FPWDLoop,
|
||||
FPWDPEImage,
|
||||
FPWDType,
|
||||
WinDebugger, WinDExtra;
|
||||
WinDebugger, WinDExtra, WinDPETypes, WinDSymbols, WinDDwarfConst, WinDDwarf;
|
||||
|
||||
function CtrlCHandler(CtrlType: Cardinal): BOOL; stdcall;
|
||||
begin
|
||||
|
@ -481,6 +481,15 @@ begin
|
||||
else WriteLN('Unknown mode: "', AParams, '"')
|
||||
end;
|
||||
|
||||
procedure HandleSetBoll(AParams: String);
|
||||
var
|
||||
MODE: array[Boolean] of String = ('off', 'on');
|
||||
begin
|
||||
if AParams = ''
|
||||
then WriteLN(' Break on library load: ', MODE[GBreakOnLibraryLoad])
|
||||
else GBreakOnLibraryLoad := (Length(Aparams) > 1) and (AParams[2] in ['n', 'N'])
|
||||
end;
|
||||
|
||||
|
||||
//=================
|
||||
//=================
|
||||
@ -590,6 +599,7 @@ begin
|
||||
|
||||
MSetCommands.AddCommand(['help', 'h', '?'], @HandleSetHelp, 'set help [<param>]: Shows help for param or this help if none given');
|
||||
MSetCommands.AddCommand(['mode', 'm'], @HandleSetMode, 'set mode 32|64: Set the mode for retrieving process info');
|
||||
MSetCommands.AddCommand(['break_on_library_load', 'boll'], @HandleSetBOLL, 'set break_on_library_load on|off: Pause running when a library is loaded (default off)');
|
||||
end;
|
||||
|
||||
procedure Finalize;
|
||||
|
@ -50,6 +50,7 @@ var
|
||||
{$else}
|
||||
GMode: TMWDMode = dm64;
|
||||
{$endif}
|
||||
GBreakOnLibraryLoad: Boolean = False;
|
||||
|
||||
GCurrentContext: PContext;
|
||||
|
||||
|
@ -71,6 +71,9 @@ begin
|
||||
if GMainProcess = nil
|
||||
then GMainProcess := Proc;
|
||||
GProcessMap.Add(AEvent.dwProcessId, Proc);
|
||||
if GBreakOnLibraryLoad
|
||||
then GState := dsPause;
|
||||
GCurrentProcess := proc;
|
||||
end;
|
||||
|
||||
procedure HandleCreateThread(const AEvent: TDebugEvent);
|
||||
@ -176,19 +179,21 @@ begin
|
||||
end;
|
||||
|
||||
procedure HandleLoadDll(const AEvent: TDebugEvent);
|
||||
//var
|
||||
// Proc: TDbgProcess;
|
||||
// Lib: TDbgLibrary;
|
||||
var
|
||||
Proc: TDbgProcess;
|
||||
Lib: TDbgLibrary;
|
||||
begin
|
||||
WriteLN('Base adress: ', FormatAddress(AEvent.LoadDll.lpBaseOfDll));
|
||||
|
||||
|
||||
// if GetProcess(AEvent.dwProcessId, Proc)
|
||||
// then begin
|
||||
// Lib := Proc.AddLib(AEvent.LoadDll);
|
||||
// WriteLN('Name: ', Lib.Name);
|
||||
// DumpPEImage(Proc.Handle, Lib.BaseAddr);
|
||||
// end;
|
||||
if GetProcess(AEvent.dwProcessId, Proc)
|
||||
and Proc.GetLib(AEvent.LoadDll.hFile, Lib)
|
||||
then begin
|
||||
WriteLN('Name: ', Lib.Name);
|
||||
DumpPEImage(Proc.Handle, Lib.BaseAddr);
|
||||
end;
|
||||
if GBreakOnLibraryLoad
|
||||
then GState := dsPause;
|
||||
end;
|
||||
|
||||
procedure HandleOutputDebug(const AEvent: TDebugEvent);
|
||||
|
@ -36,153 +36,13 @@ unit FPWDPEImage;
|
||||
{$mode objfpc}{$H+}
|
||||
interface
|
||||
|
||||
{$IF DECLARED(TImageNtHeaders)}
|
||||
{$DEFINE _headers_translated_in_rtl_}
|
||||
{$ENDIF}
|
||||
|
||||
uses
|
||||
Windows, SysUtils, FPWDGLobal, WinDExtra;
|
||||
|
||||
const
|
||||
IMAGE_FILE_MACHINE_IA64 = $0200; { Intel IPF }
|
||||
IMAGE_FILE_MACHINE_AMD64 = $8664; { x64 }
|
||||
|
||||
IMAGE_FILE_LARGE_ADDRESS_AWARE = $0020; { The application can handle addresses larger than 2 GB. }
|
||||
|
||||
IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT = 13; { Delay import table }
|
||||
IMAGE_DIRECTORY_ENTRY_COM_DECRIPTOR = 14; { COM descriptor table }
|
||||
|
||||
IMAGE_NT_OPTIONAL_HDR32_MAGIC = $010B;
|
||||
IMAGE_NT_OPTIONAL_HDR64_MAGIC = $020B;
|
||||
|
||||
IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 8; { Windows CE system }
|
||||
IMAGE_SUBSYSTEM_XBOX = 9; { Xbox system }
|
||||
|
||||
|
||||
IMAGE_LIBRARY_PROCESS_INIT = $0001; // Reserved.
|
||||
IMAGE_LIBRARY_PROCESS_TERM = $0002; // Reserved.
|
||||
IMAGE_LIBRARY_THREAD_INIT = $0004; // Reserved.
|
||||
IMAGE_LIBRARY_THREAD_TERM = $0008; // Reserved.
|
||||
IMAGE_DLLCHARACTERISTICS_NO_ISOLATION = $0200; { Image understands isolation and doesn't want it }
|
||||
IMAGE_DLLCHARACTERISTICS_NO_SEH = $0400; { Image does not use SEH. No SE handler may reside in this image }
|
||||
IMAGE_DLLCHARACTERISTICS_NO_BIND = $0800; { do not bind this image }
|
||||
// $1000; { Reserved. }
|
||||
IMAGE_DLLCHARACTERISTICS_WDM_DRIVER = $2000; { dll is a WDM driver }
|
||||
// $4000; { Reserved. }
|
||||
IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = $8000;
|
||||
|
||||
|
||||
// Reserved section characteristics
|
||||
IMAGE_SCN_TYPE_REG = $00000000; // Reserved.
|
||||
IMAGE_SCN_TYPE_DSECT = $00000001; // Reserved.
|
||||
IMAGE_SCN_TYPE_NOLOAD = $00000002; // Reserved.
|
||||
IMAGE_SCN_TYPE_GROUP = $00000004; // Reserved.
|
||||
IMAGE_SCN_TYPE_COPY = $00000010; // Reserved.
|
||||
IMAGE_SCN_TYPE_OVER = $00000400; // Reserved.
|
||||
IMAGE_SCN_MEM_PROTECTED = $00004000; // Obsolete
|
||||
IMAGE_SCN_MEM_SYSHEAP = $00010000; // Obsolete
|
||||
|
||||
{$IFDEF _headers_translated_in_rtl_}
|
||||
|
||||
type
|
||||
(*
|
||||
typedef struct _IMAGE_OPTIONAL_HEADER64 {
|
||||
WORD Magic;
|
||||
BYTE MajorLinkerVersion;
|
||||
BYTE MinorLinkerVersion;
|
||||
DWORD SizeOfCode;
|
||||
DWORD SizeOfInitializedData;
|
||||
DWORD SizeOfUninitializedData;
|
||||
DWORD AddressOfEntryPoint;
|
||||
DWORD BaseOfCode;
|
||||
ULONGLONG ImageBase;
|
||||
DWORD SectionAlignment;
|
||||
DWORD FileAlignment;
|
||||
WORD MajorOperatingSystemVersion;
|
||||
WORD MinorOperatingSystemVersion;
|
||||
WORD MajorImageVersion;
|
||||
WORD MinorImageVersion;
|
||||
WORD MajorSubsystemVersion;
|
||||
WORD MinorSubsystemVersion;
|
||||
DWORD Win32VersionValue;
|
||||
DWORD SizeOfImage;
|
||||
DWORD SizeOfHeaders;
|
||||
DWORD CheckSum;
|
||||
WORD Subsystem;
|
||||
WORD DllCharacteristics;
|
||||
ULONGLONG SizeOfStackReserve;
|
||||
ULONGLONG SizeOfStackCommit;
|
||||
ULONGLONG SizeOfHeapReserve;
|
||||
ULONGLONG SizeOfHeapCommit;
|
||||
DWORD LoaderFlags;
|
||||
DWORD NumberOfRvaAndSizes;
|
||||
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
|
||||
} IMAGE_OPTIONAL_HEADER64, *PIMAGE_OPTIONAL_HEADER64;
|
||||
*)
|
||||
PImageOptionalHeader64 = ^TImageOptionalHeader64;
|
||||
_IMAGE_OPTIONAL_HEADER64 = packed record
|
||||
Magic: Word;
|
||||
MajorLinkerVersion: Byte;
|
||||
MinorLinkerVersion: Byte;
|
||||
SizeOfCode: DWORD;
|
||||
SizeOfInitializedData: DWORD;
|
||||
SizeOfUninitializedData: DWORD;
|
||||
AddressOfEntryPoint: DWORD;
|
||||
BaseOfCode: DWORD;
|
||||
// BaseOfData: DWORD;
|
||||
ImageBase: Int64;
|
||||
SectionAlignment: DWORD;
|
||||
FileAlignment: DWORD;
|
||||
MajorOperatingSystemVersion: Word;
|
||||
MinorOperatingSystemVersion: Word;
|
||||
MajorImageVersion: Word;
|
||||
MinorImageVersion: Word;
|
||||
MajorSubsystemVersion: Word;
|
||||
MinorSubsystemVersion: Word;
|
||||
Win32VersionValue: DWORD;
|
||||
SizeOfImage: DWORD;
|
||||
SizeOfHeaders: DWORD;
|
||||
CheckSum: DWORD;
|
||||
Subsystem: Word;
|
||||
DllCharacteristics: Word;
|
||||
SizeOfStackReserve: Int64;
|
||||
SizeOfStackCommit: Int64;
|
||||
SizeOfHeapReserve: Int64;
|
||||
SizeOfHeapCommit: Int64;
|
||||
LoaderFlags: DWORD;
|
||||
NumberOfRvaAndSizes: DWORD;
|
||||
DataDirectory: packed array[0..IMAGE_NUMBEROF_DIRECTORY_ENTRIES-1] of TImageDataDirectory;
|
||||
end;
|
||||
TImageOptionalHeader64 = _IMAGE_OPTIONAL_HEADER64;
|
||||
IMAGE_OPTIONAL_HEADER64 = _IMAGE_OPTIONAL_HEADER64;
|
||||
|
||||
|
||||
|
||||
(*
|
||||
typedef struct _IMAGE_NT_HEADERS64 {
|
||||
DWORD Signature;
|
||||
IMAGE_FILE_HEADER FileHeader;
|
||||
IMAGE_OPTIONAL_HEADER64 OptionalHeader;
|
||||
} IMAGE_NT_HEADERS64, *PIMAGE_NT_HEADERS64;
|
||||
|
||||
*)
|
||||
|
||||
PImageNtHeaders64 = ^TImageNtHeaders64;
|
||||
_IMAGE_NT_HEADERS64 = packed record
|
||||
Signature: DWORD;
|
||||
FileHeader: TImageFileHeader;
|
||||
OptionalHeader: TImageOptionalHeader64;
|
||||
end;
|
||||
TImageNtHeaders64 = _IMAGE_NT_HEADERS64;
|
||||
IMAGE_NT_HEADERS64 = _IMAGE_NT_HEADERS64;
|
||||
|
||||
{$ENDIF}
|
||||
Windows, SysUtils, FPWDGLobal, WinDExtra, WinDPETypes;
|
||||
|
||||
procedure DumpPEImage(const AProcessHandle: THandle; const AAdress: TDbgPtr);
|
||||
|
||||
implementation
|
||||
|
||||
{$IFDEF _headers_translated_in_rtl_}
|
||||
const
|
||||
DIR_NAMES: array[0..IMAGE_NUMBEROF_DIRECTORY_ENTRIES-1] of string = (
|
||||
'EXPORT',
|
||||
@ -223,13 +83,13 @@ begin
|
||||
end;
|
||||
|
||||
if (DosHeader.e_magic <> IMAGE_DOS_SIGNATURE)
|
||||
or (DosHeader._lfanew = 0)
|
||||
or (DosHeader.e_lfanew = 0)
|
||||
then begin
|
||||
WriteLN('Invalid DOS header');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
if not ReadProcessMemory(AProcessHandle, Pointer(PChar(AAdress) + DosHeader._lfanew), @NTHeaders, SizeOf(NTHeaders), BytesRead)
|
||||
if not ReadProcessMemory(AProcessHandle, Pointer(PChar(AAdress) + DosHeader.e_lfanew), @NTHeaders, SizeOf(NTHeaders), BytesRead)
|
||||
then begin
|
||||
WriteLN('Unable to retrieve NT headers');
|
||||
Exit;
|
||||
@ -299,8 +159,8 @@ begin
|
||||
WriteLN(' SizeOfCode: ', OH^.SizeOfCode);
|
||||
WriteLN(' SizeOfInitializedData: ', OH^.SizeOfInitializedData);
|
||||
WriteLN(' SizeOfUninitializedData: ', OH^.SizeOfUninitializedData);
|
||||
WriteLN(' AddressOfEntryPoint: ', FormatAdress(OH^.AddressOfEntryPoint));
|
||||
WriteLN(' BaseOfCode: ', FormatAdress(OH^.BaseOfCode));
|
||||
WriteLN(' AddressOfEntryPoint: ', FormatAddress(OH^.AddressOfEntryPoint));
|
||||
WriteLN(' BaseOfCode: ', FormatAddress(OH^.BaseOfCode));
|
||||
if Is64
|
||||
then begin
|
||||
WriteLN(' ImageBase: $', IntToHex(OH^.ImageBase, 16));
|
||||
@ -393,7 +253,7 @@ begin
|
||||
WriteLN('Sections: ');
|
||||
for n := 0 to NtHeaders.FileHeader.NumberOfSections - 1 do
|
||||
begin
|
||||
if not ReadProcessMemory(AProcessHandle, Pointer(Cardinal(AAdress) + DosHeader._lfanew + SizeOF(NTHeaders) - SizeOF(NTHeaders.OptionalHeader) + NTHeaders.FileHeader.SizeOfOptionalHeader + SizeOf(SectionHeader) * n), @SectionHeader, SizeOf(SectionHeader), BytesRead)
|
||||
if not ReadProcessMemory(AProcessHandle, Pointer(PtrUInt(AAdress + DosHeader.e_lfanew + SizeOF(NTHeaders) - SizeOF(NTHeaders.OptionalHeader) + NTHeaders.FileHeader.SizeOfOptionalHeader + SizeOf(SectionHeader) * n)), @SectionHeader, SizeOf(SectionHeader), BytesRead)
|
||||
then begin
|
||||
WriteLN('Unable to retrieve section: ', n);
|
||||
Continue;
|
||||
@ -403,13 +263,13 @@ begin
|
||||
Move(Name, SectionName, IMAGE_SIZEOF_SHORT_NAME);
|
||||
SectionName[IMAGE_SIZEOF_SHORT_NAME] := #0;
|
||||
WriteLN(' Name: ',SectionName);
|
||||
WriteLN(' Misc.PhysicalAddress: ',FormatAdress(Misc.PhysicalAddress));
|
||||
WriteLN(' Misc.PhysicalAddress: ',FormatAddress(Misc.PhysicalAddress));
|
||||
WriteLN(' Misc.VirtualSize: ',Misc.VirtualSize);
|
||||
WriteLN(' VirtualAddress: ',FormatAdress(VirtualAddress));
|
||||
WriteLN(' VirtualAddress: ',FormatAddress(VirtualAddress));
|
||||
WriteLN(' SizeOfRawData: ',SizeOfRawData);
|
||||
WriteLN(' PointerToRawData: ',FormatAdress(PointerToRawData));
|
||||
WriteLN(' PointerToRelocations: ',FormatAdress(PointerToRelocations));
|
||||
WriteLN(' PointerToLinenumbers: ',FormatAdress(PointerToLinenumbers));
|
||||
WriteLN(' PointerToRawData: ',FormatAddress(PointerToRawData));
|
||||
WriteLN(' PointerToRelocations: ',FormatAddress(PointerToRelocations));
|
||||
WriteLN(' PointerToLinenumbers: ',FormatAddress(PointerToLinenumbers));
|
||||
WriteLN(' NumberOfRelocations: ',NumberOfRelocations);
|
||||
WriteLN(' NumberOfLinenumbers: ',NumberOfLinenumbers);
|
||||
Write(' Characteristics: ', IntToHex(Characteristics, 8), ' [');
|
||||
@ -449,12 +309,6 @@ begin
|
||||
|
||||
end;
|
||||
end;
|
||||
{$ELSE}
|
||||
procedure DumpPEImage(const AProcessHandle: THandle; const AAdress: TDbgPtr);
|
||||
begin
|
||||
{$WARNING PEHeaders not yet translated}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
|
||||
|
@ -13,24 +13,18 @@
|
||||
@lastmod($Date$)
|
||||
@author(Marc Weustink <marc@@dommelstein.nl>)
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* This source is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This code is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* General Public License for more details. *
|
||||
* *
|
||||
* A copy of the GNU General Public License is available on the World *
|
||||
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
||||
* obtain it by writing to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
* *
|
||||
***************************************************************************
|
||||
*****************************************************************************
|
||||
* *
|
||||
* This file is part of the Lazarus Project *
|
||||
* *
|
||||
* See the file COPYING.modifiedLGPL, included in this distribution, *
|
||||
* for details about the copyright. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* *
|
||||
*****************************************************************************
|
||||
}
|
||||
unit FPWDType;
|
||||
|
||||
|
1217
debugger/windebug/winddwarf.pas
Normal file
1217
debugger/windebug/winddwarf.pas
Normal file
File diff suppressed because it is too large
Load Diff
598
debugger/windebug/winddwarfconst.pas
Normal file
598
debugger/windebug/winddwarfconst.pas
Normal file
@ -0,0 +1,598 @@
|
||||
{ $Id$ }
|
||||
{
|
||||
---------------------------------------------------------------------------
|
||||
winddwarfconst.pas - Windows debugger - Dwarf constants
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
This unit contains the constants defined for the dward debugging format.
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
@created(Fri Jul 7th WET 2006)
|
||||
@lastmod($Date$)
|
||||
@author(Marc Weustink <marc@@dommelstein.nl>)
|
||||
|
||||
*****************************************************************************
|
||||
* *
|
||||
* This file is part of the Lazarus Project *
|
||||
* *
|
||||
* See the file COPYING.modifiedLGPL, included in this distribution, *
|
||||
* for details about the copyright. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* *
|
||||
*****************************************************************************
|
||||
}
|
||||
unit WinDDwarfConst;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
const
|
||||
|
||||
{ tag encodings }
|
||||
|
||||
DW_TAG_array_type = $01;
|
||||
DW_TAG_class_type = $02;
|
||||
DW_TAG_entry_point = $03;
|
||||
DW_TAG_enumeration_type = $04;
|
||||
DW_TAG_formal_parameter = $05;
|
||||
DW_TAG_imported_declaration = $08;
|
||||
DW_TAG_label = $0a;
|
||||
DW_TAG_lexical_block = $0b;
|
||||
DW_TAG_member = $0d;
|
||||
DW_TAG_pointer_type = $0f;
|
||||
DW_TAG_reference_type = $10;
|
||||
DW_TAG_compile_unit = $11;
|
||||
DW_TAG_string_type = $12;
|
||||
DW_TAG_structure_type = $13;
|
||||
DW_TAG_subroutine_type = $15;
|
||||
DW_TAG_typedef = $16;
|
||||
DW_TAG_union_type = $17;
|
||||
DW_TAG_unspecified_parameters = $18;
|
||||
DW_TAG_variant = $19;
|
||||
DW_TAG_common_block = $1a;
|
||||
DW_TAG_common_inclusion = $1b;
|
||||
DW_TAG_inheritance = $1c;
|
||||
DW_TAG_inlined_subroutine = $1d;
|
||||
DW_TAG_module = $1e;
|
||||
DW_TAG_ptr_to_member_type = $1f;
|
||||
DW_TAG_set_type = $20;
|
||||
DW_TAG_subrange_type = $21;
|
||||
DW_TAG_with_stmt = $22;
|
||||
DW_TAG_access_declaration = $23;
|
||||
DW_TAG_base_type = $24;
|
||||
DW_TAG_catch_block = $25;
|
||||
DW_TAG_const_type = $26;
|
||||
DW_TAG_constant = $27;
|
||||
DW_TAG_enumerator = $28;
|
||||
DW_TAG_file_type = $29;
|
||||
DW_TAG_friend = $2a;
|
||||
DW_TAG_namelist = $2b;
|
||||
DW_TAG_namelist_item = $2c;
|
||||
DW_TAG_packed_type = $2d;
|
||||
DW_TAG_subprogram = $2e;
|
||||
DW_TAG_template_type_parameter = $2f;
|
||||
DW_TAG_template_value_parameter = $30;
|
||||
DW_TAG_thrown_type = $31;
|
||||
DW_TAG_try_block = $32;
|
||||
DW_TAG_variant_part = $33;
|
||||
DW_TAG_variable = $34;
|
||||
DW_TAG_volatile_type = $35;
|
||||
// --- DWARF3 ---
|
||||
DW_TAG_dwarf_procedure = $36;
|
||||
DW_TAG_restrict_type = $37;
|
||||
DW_TAG_interface_type = $38;
|
||||
DW_TAG_namespace = $39;
|
||||
DW_TAG_imported_module = $3a;
|
||||
DW_TAG_unspecified_type = $3b;
|
||||
DW_TAG_partial_unit = $3c;
|
||||
DW_TAG_imported_unit = $3d;
|
||||
DW_TAG_condition = $3f;
|
||||
DW_TAG_shared_type = $40;
|
||||
// --- ---
|
||||
DW_TAG_lo_user = $4080;
|
||||
DW_TAG_hi_user = $ffff;
|
||||
|
||||
|
||||
{ Child determination encodings }
|
||||
|
||||
DW_CHILDREN_no = $00;
|
||||
DW_CHILDREN_yes = $01;
|
||||
|
||||
|
||||
{ Attribute encodings }
|
||||
|
||||
DW_AT_sibling = $01 ; // reference
|
||||
DW_AT_location = $02 ; // block, loclistptr
|
||||
DW_AT_name = $03 ; // string
|
||||
DW_AT_ordering = $09 ; // constant
|
||||
DW_AT_byte_size = $0b ; // block, constant, reference
|
||||
DW_AT_bit_offset = $0c ; // block, constant, reference
|
||||
DW_AT_bit_size = $0d ; // block, constant, reference
|
||||
DW_AT_stmt_list = $10 ; // lineptr
|
||||
DW_AT_low_pc = $11 ; // address
|
||||
DW_AT_high_pc = $12 ; // address
|
||||
DW_AT_language = $13 ; // constant
|
||||
DW_AT_discr = $15 ; // reference
|
||||
DW_AT_discr_value = $16 ; // constant
|
||||
DW_AT_visibility = $17 ; // constant
|
||||
DW_AT_import = $18 ; // reference
|
||||
DW_AT_string_length = $19 ; // block, loclistptr
|
||||
DW_AT_common_reference = $1a ; // reference
|
||||
DW_AT_comp_dir = $1b ; // string
|
||||
DW_AT_const_value = $1c ; // block, constant, string
|
||||
DW_AT_containing_type = $1d ; // reference
|
||||
DW_AT_default_value = $1e ; // reference
|
||||
DW_AT_inline = $20 ; // constant
|
||||
DW_AT_is_optional = $21 ; // flag
|
||||
DW_AT_lower_bound = $22 ; // block, constant, reference
|
||||
DW_AT_producer = $25 ; // string
|
||||
DW_AT_prototyped = $27 ; // flag
|
||||
DW_AT_return_addr = $2a ; // block, loclistptr
|
||||
DW_AT_start_scope = $2c ; // constant
|
||||
DW_AT_bit_stride = $2e ; // constant
|
||||
DW_AT_upper_bound = $2f ; // block, constant, reference
|
||||
DW_AT_abstract_origin = $31 ; // reference
|
||||
DW_AT_accessibility = $32 ; // constant
|
||||
DW_AT_address_class = $33 ; // constant
|
||||
DW_AT_artificial = $34 ; // flag
|
||||
DW_AT_base_types = $35 ; // reference
|
||||
DW_AT_calling_convention = $36 ; // constant
|
||||
DW_AT_count = $37 ; // block, constant, reference
|
||||
DW_AT_data_member_location = $38 ; // block, constant, loclistptr
|
||||
DW_AT_decl_column = $39 ; // constant
|
||||
DW_AT_decl_file = $3a ; // constant
|
||||
DW_AT_decl_line = $3b ; // constant
|
||||
DW_AT_declaration = $3c ; // flag
|
||||
DW_AT_discr_list = $3d ; // block
|
||||
DW_AT_encoding = $3e ; // constant
|
||||
DW_AT_external = $3f ; // flag
|
||||
DW_AT_frame_base = $40 ; // block, loclistptr
|
||||
DW_AT_friend = $41 ; // reference
|
||||
DW_AT_identifier_case = $42 ; // constant
|
||||
DW_AT_macro_info = $43 ; // macptr
|
||||
DW_AT_namelist_item = $44 ; // block
|
||||
DW_AT_priority = $45 ; // reference
|
||||
DW_AT_segment = $46 ; // block, loclistptr
|
||||
DW_AT_specification = $47 ; // reference
|
||||
DW_AT_static_link = $48 ; // block, loclistptr
|
||||
DW_AT_type = $49 ; // reference
|
||||
DW_AT_use_location = $4a ; // block, loclistptr
|
||||
DW_AT_variable_parameter = $4b ; // flag
|
||||
DW_AT_virtuality = $4c ; // constant
|
||||
DW_AT_vtable_elem_location = $4d ; // block, loclistptr
|
||||
// --- DWARF3 ---
|
||||
DW_AT_allocated = $4e ; // block, constant, reference
|
||||
DW_AT_associated = $4f ; // block, constant, reference
|
||||
DW_AT_data_location = $50 ; // block
|
||||
DW_AT_byte_stride = $51 ; // block, constant, reference
|
||||
DW_AT_entry_pc = $52 ; // address
|
||||
DW_AT_use_UTF8 = $53 ; // flag
|
||||
DW_AT_extension = $54 ; // reference
|
||||
DW_AT_ranges = $55 ; // rangelistptr
|
||||
DW_AT_trampoline = $56 ; // address, flag, reference, string
|
||||
DW_AT_call_column = $57 ; // constant
|
||||
DW_AT_call_file = $58 ; // constant
|
||||
DW_AT_call_line = $59 ; // constant
|
||||
DW_AT_description = $5a ; // string
|
||||
DW_AT_binary_scale = $5b ; // constant
|
||||
DW_AT_decimal_scale = $5c ; // constant
|
||||
DW_AT_small = $5d ; // reference
|
||||
DW_AT_decimal_sign = $5e ; // constant
|
||||
DW_AT_digit_count = $5f ; // constant
|
||||
DW_AT_picture_string = $60 ; // string
|
||||
DW_AT_mutable = $61 ; // flag
|
||||
DW_AT_threads_scaled = $62 ; // flag
|
||||
DW_AT_explicit = $63 ; // flag
|
||||
DW_AT_object_pointer = $64 ; // reference
|
||||
DW_AT_endianity = $65 ; // constant
|
||||
DW_AT_elemental = $66 ; // flag
|
||||
DW_AT_pure = $67 ; // flag
|
||||
DW_AT_recursive = $68 ; // flag
|
||||
// --- ---
|
||||
DW_AT_lo_user = $2000; // ---
|
||||
DW_AT_hi_user = $3fff; // ---
|
||||
|
||||
|
||||
{ Attribute form encodings }
|
||||
|
||||
DW_FORM_addr = $01; // address
|
||||
DW_FORM_block2 = $03; // block
|
||||
DW_FORM_block4 = $04; // block
|
||||
DW_FORM_data2 = $05; // constant
|
||||
DW_FORM_data4 = $06; // constant, lineptr, loclistptr, macptr, rangelistptr
|
||||
DW_FORM_data8 = $07; // constant, lineptr, loclistptr, macptr, rangelistptr
|
||||
DW_FORM_string = $08; // string
|
||||
DW_FORM_block = $09; // block
|
||||
DW_FORM_block1 = $0a; // block
|
||||
DW_FORM_data1 = $0b; // constant
|
||||
DW_FORM_flag = $0c; // flag
|
||||
DW_FORM_sdata = $0d; // constant
|
||||
DW_FORM_strp = $0e; // string
|
||||
DW_FORM_udata = $0f; // constant
|
||||
DW_FORM_ref_addr = $10; // reference
|
||||
DW_FORM_ref1 = $11; // reference
|
||||
DW_FORM_ref2 = $12; // reference
|
||||
DW_FORM_ref4 = $13; // reference
|
||||
DW_FORM_ref8 = $14; // reference
|
||||
DW_FORM_ref_udata = $15; // reference
|
||||
DW_FORM_indirect = $16; //
|
||||
|
||||
|
||||
{ DWARF operation encodings }
|
||||
|
||||
DW_OP_addr = $03; // 1 constant address (size target specific)
|
||||
DW_OP_deref = $06; // 0
|
||||
DW_OP_const1u = $08; // 1 1-byte constant
|
||||
DW_OP_const1s = $09; // 1 1-byte constant
|
||||
DW_OP_const2u = $0a; // 1 2-byte constant
|
||||
DW_OP_const2s = $0b; // 1 2-byte constant
|
||||
DW_OP_const4u = $0c; // 1 4-byte constant
|
||||
DW_OP_const4s = $0d; // 1 4-byte constant
|
||||
DW_OP_const8u = $0e; // 1 8-byte constant
|
||||
DW_OP_const8s = $0f; // 1 8-byte constant
|
||||
DW_OP_constu = $10; // 1 ULEB128 constant
|
||||
DW_OP_consts = $11; // 1 SLEB128 constant
|
||||
DW_OP_dup = $12; // 0
|
||||
DW_OP_drop = $13; // 0
|
||||
DW_OP_over = $14; // 0
|
||||
DW_OP_pick = $15; // 1 1-byte stack index
|
||||
DW_OP_swap = $16; // 0
|
||||
DW_OP_rot = $17; // 0
|
||||
DW_OP_xderef = $18; // 0
|
||||
DW_OP_abs = $19; // 0
|
||||
DW_OP_and = $1a; // 0
|
||||
DW_OP_div = $1b; // 0
|
||||
DW_OP_minus = $1c; // 0
|
||||
DW_OP_mod = $1d; // 0
|
||||
DW_OP_mul = $1e; // 0
|
||||
DW_OP_neg = $1f; // 0
|
||||
DW_OP_not = $20; // 0
|
||||
DW_OP_or = $21; // 0
|
||||
DW_OP_plus = $22; // 0
|
||||
DW_OP_plus_uconst = $23; // 1 ULEB128 addend
|
||||
DW_OP_shl = $24; // 0
|
||||
DW_OP_shr = $25; // 0
|
||||
DW_OP_shra = $26; // 0
|
||||
DW_OP_xor = $27; // 0
|
||||
DW_OP_skip = $2f; // 1 signed 2-byte constant
|
||||
DW_OP_bra = $28; // 1 signed 2-byte constant
|
||||
DW_OP_eq = $29; // 0
|
||||
DW_OP_ge = $2a; // 0
|
||||
DW_OP_gt = $2b; // 0
|
||||
DW_OP_le = $2c; // 0
|
||||
DW_OP_lt = $2d; // 0
|
||||
DW_OP_ne = $2e; // 0
|
||||
DW_OP_lit0 = $30; // 0 literals 0..31 = (DW_OP_lit0 + literal)
|
||||
DW_OP_lit1 = $31; // 0
|
||||
DW_OP_lit2 = $32; // 0
|
||||
DW_OP_lit3 = $33; // 0
|
||||
DW_OP_lit4 = $34; // 0
|
||||
DW_OP_lit5 = $35; // 0
|
||||
DW_OP_lit6 = $36; // 0
|
||||
DW_OP_lit7 = $37; // 0
|
||||
DW_OP_lit8 = $38; // 0
|
||||
DW_OP_lit9 = $39; // 0
|
||||
DW_OP_lit10 = $3a; // 0
|
||||
DW_OP_lit11 = $3b; // 0
|
||||
DW_OP_lit12 = $3c; // 0
|
||||
DW_OP_lit13 = $3d; // 0
|
||||
DW_OP_lit14 = $3e; // 0
|
||||
DW_OP_lit15 = $3f; // 0
|
||||
DW_OP_lit16 = $40; // 0
|
||||
DW_OP_lit17 = $41; // 0
|
||||
DW_OP_lit18 = $42; // 0
|
||||
DW_OP_lit19 = $43; // 0
|
||||
DW_OP_lit20 = $44; // 0
|
||||
DW_OP_lit21 = $45; // 0
|
||||
DW_OP_lit22 = $46; // 0
|
||||
DW_OP_lit23 = $47; // 0
|
||||
DW_OP_lit24 = $48; // 0
|
||||
DW_OP_lit25 = $49; // 0
|
||||
DW_OP_lit26 = $4a; // 0
|
||||
DW_OP_lit27 = $4b; // 0
|
||||
DW_OP_lit28 = $4c; // 0
|
||||
DW_OP_lit29 = $4d; // 0
|
||||
DW_OP_lit30 = $4e; // 0
|
||||
DW_OP_lit31 = $4f; // 0
|
||||
DW_OP_reg0 = $50; // 0 reg 0..31 = (DW_OP_reg0 + regnum)
|
||||
DW_OP_reg1 = $51; // 0
|
||||
DW_OP_reg2 = $52; // 0
|
||||
DW_OP_reg3 = $53; // 0
|
||||
DW_OP_reg4 = $54; // 0
|
||||
DW_OP_reg5 = $55; // 0
|
||||
DW_OP_reg6 = $56; // 0
|
||||
DW_OP_reg7 = $57; // 0
|
||||
DW_OP_reg8 = $58; // 0
|
||||
DW_OP_reg9 = $59; // 0
|
||||
DW_OP_reg10 = $5a; // 0
|
||||
DW_OP_reg11 = $5b; // 0
|
||||
DW_OP_reg12 = $5c; // 0
|
||||
DW_OP_reg13 = $5d; // 0
|
||||
DW_OP_reg14 = $5e; // 0
|
||||
DW_OP_reg15 = $5f; // 0
|
||||
DW_OP_reg16 = $60; // 0
|
||||
DW_OP_reg17 = $61; // 0
|
||||
DW_OP_reg18 = $62; // 0
|
||||
DW_OP_reg19 = $63; // 0
|
||||
DW_OP_reg20 = $64; // 0
|
||||
DW_OP_reg21 = $65; // 0
|
||||
DW_OP_reg22 = $66; // 0
|
||||
DW_OP_reg23 = $67; // 0
|
||||
DW_OP_reg24 = $68; // 0
|
||||
DW_OP_reg25 = $69; // 0
|
||||
DW_OP_reg26 = $6a; // 0
|
||||
DW_OP_reg27 = $6b; // 0
|
||||
DW_OP_reg28 = $6c; // 0
|
||||
DW_OP_reg29 = $6d; // 0
|
||||
DW_OP_reg30 = $6e; // 0
|
||||
DW_OP_reg31 = $6f; // 0
|
||||
DW_OP_breg0 = $70; // 1 SLEB128 offsetbase register 0..31 = (DW_OP_breg0 + regnum)
|
||||
DW_OP_breg1 = $71; // 1
|
||||
DW_OP_breg2 = $72; // 1
|
||||
DW_OP_breg3 = $73; // 1
|
||||
DW_OP_breg4 = $74; // 1
|
||||
DW_OP_breg5 = $75; // 1
|
||||
DW_OP_breg6 = $76; // 1
|
||||
DW_OP_breg7 = $77; // 1
|
||||
DW_OP_breg8 = $78; // 1
|
||||
DW_OP_breg9 = $79; // 1
|
||||
DW_OP_breg10 = $7a; // 1
|
||||
DW_OP_breg11 = $7b; // 1
|
||||
DW_OP_breg12 = $7c; // 1
|
||||
DW_OP_breg13 = $7d; // 1
|
||||
DW_OP_breg14 = $7e; // 1
|
||||
DW_OP_breg15 = $7f; // 1
|
||||
DW_OP_breg16 = $80; // 1
|
||||
DW_OP_breg17 = $81; // 1
|
||||
DW_OP_breg18 = $82; // 1
|
||||
DW_OP_breg19 = $83; // 1
|
||||
DW_OP_breg20 = $84; // 1
|
||||
DW_OP_breg21 = $85; // 1
|
||||
DW_OP_breg22 = $86; // 1
|
||||
DW_OP_breg23 = $87; // 1
|
||||
DW_OP_breg24 = $88; // 1
|
||||
DW_OP_breg25 = $89; // 1
|
||||
DW_OP_breg26 = $8a; // 1
|
||||
DW_OP_breg27 = $8b; // 1
|
||||
DW_OP_breg28 = $8c; // 1
|
||||
DW_OP_breg29 = $8d; // 1
|
||||
DW_OP_breg30 = $8e; // 1
|
||||
DW_OP_breg31 = $8f; // 1
|
||||
DW_OP_regx = $90; // 1 ULEB128 register
|
||||
DW_OP_fbreg = $91; // 1 SLEB128 offset
|
||||
DW_OP_bregx = $92; // 2 ULEB128 register followed bySLEB128 offset
|
||||
DW_OP_piece = $93; // 1 ULEB128 size of piece addressed
|
||||
DW_OP_deref_size = $94; // 1 1-byte size of data retrieved
|
||||
DW_OP_xderef_size = $95; // 1 1-byte size of data retrieved
|
||||
DW_OP_nop = $96; // 0
|
||||
// --- DWARF3 ---
|
||||
DW_OP_push_object_address = $97; // 0
|
||||
DW_OP_call2 = $98; // 1 2-byte offset of DIE
|
||||
DW_OP_call4 = $99; // 1 4-byte offset of DIE
|
||||
DW_OP_call_ref = $9a; // 1 4- or 8-byte offset of DIE
|
||||
DW_OP_form_tls_address = $9b; // 0
|
||||
DW_OP_call_frame_cfa = $9c; // 0
|
||||
DW_OP_bit_piece = $9d; // 2
|
||||
// --- ---
|
||||
DW_OP_lo_user = $e0; //
|
||||
DW_OP_hi_user = $ff; //
|
||||
|
||||
|
||||
{ Base type encoding values }
|
||||
|
||||
DW_ATE_address = $01;
|
||||
DW_ATE_boolean = $02;
|
||||
DW_ATE_complex_float = $03;
|
||||
DW_ATE_float = $04;
|
||||
DW_ATE_signed = $05;
|
||||
DW_ATE_signed_char = $06;
|
||||
DW_ATE_unsigned = $07;
|
||||
DW_ATE_unsigned_char = $08;
|
||||
// --- DWARF3 ---
|
||||
DW_ATE_imaginary_float = $09;
|
||||
DW_ATE_packed_decimal = $0a;
|
||||
DW_ATE_numeric_string = $0b;
|
||||
DW_ATE_edited = $0c;
|
||||
DW_ATE_signed_fixed = $0d;
|
||||
DW_ATE_unsigned_fixed = $0e;
|
||||
DW_ATE_decimal_float = $0f;
|
||||
// --- ---
|
||||
DW_ATE_lo_user = $80;
|
||||
DW_ATE_hi_user = $ff;
|
||||
|
||||
|
||||
{ Decimal sign encodings }
|
||||
|
||||
// --- DWARF3 ---
|
||||
DW_DS_unsigned = $01;
|
||||
DW_DS_leading_overpunch = $02;
|
||||
DW_DS_trailing_overpunch = $03;
|
||||
DW_DS_leading_separate = $04;
|
||||
DW_DS_trailing_separate = $05;
|
||||
// --- ---
|
||||
|
||||
|
||||
{ Endianity encodings }
|
||||
|
||||
// --- DWARF3 ---
|
||||
DW_END_default = $00;
|
||||
DW_END_big = $01;
|
||||
DW_END_little = $02;
|
||||
DW_END_lo_user = $40;
|
||||
DW_END_hi_user = $ff;
|
||||
// --- ---
|
||||
|
||||
|
||||
{ Accessibility encodings }
|
||||
|
||||
DW_ACCESS_public = $01;
|
||||
DW_ACCESS_protected = $02;
|
||||
DW_ACCESS_private = $03;
|
||||
|
||||
|
||||
{ Visibility encodings }
|
||||
|
||||
DW_VIS_local = $01;
|
||||
DW_VIS_exported = $02;
|
||||
DW_VIS_qualified = $03;
|
||||
|
||||
|
||||
{ Virtuality encodings }
|
||||
|
||||
DW_VIRTUALITY_none = $00;
|
||||
DW_VIRTUALITY_virtual = $01;
|
||||
DW_VIRTUALITY_pure_virtual = $02;
|
||||
|
||||
|
||||
{ Language names }
|
||||
|
||||
DW_LANG_C89 = $0001;
|
||||
DW_LANG_C = $0002;
|
||||
DW_LANG_Ada83 = $0003; // reserved
|
||||
DW_LANG_C_plus_plus = $0004;
|
||||
DW_LANG_Cobol74 = $0005; // reserved
|
||||
DW_LANG_Cobol85 = $0006; // reserved
|
||||
DW_LANG_Fortran77 = $0007;
|
||||
DW_LANG_Fortran90 = $0008;
|
||||
DW_LANG_Pascal83 = $0009;
|
||||
DW_LANG_Modula2 = $000a;
|
||||
// --- DWARF3 ---
|
||||
DW_LANG_Java = $000b;
|
||||
DW_LANG_C99 = $000c;
|
||||
DW_LANG_Ada95 = $000d; // reserved
|
||||
DW_LANG_Fortran95 = $000e;
|
||||
DW_LANG_PLI = $000f; // reserved
|
||||
DW_LANG_ObjC = $0010;
|
||||
DW_LANG_ObjC_plus_plus = $0011;
|
||||
DW_LANG_UPC = $0012;
|
||||
DW_LANG_D = $0013;
|
||||
// --- ---
|
||||
DW_LANG_lo_user = $8000;
|
||||
DW_LANG_hi_user = $ffff;
|
||||
|
||||
|
||||
{ Address class encoding }
|
||||
|
||||
DW_ADDR_none = $00;
|
||||
|
||||
|
||||
{ Identifier case encodings }
|
||||
|
||||
DW_ID_case_sensitive = $00;
|
||||
DW_ID_up_case = $01;
|
||||
DW_ID_down_case = $02;
|
||||
DW_ID_case_insensitive = $03;
|
||||
|
||||
|
||||
{ Calling convention encodings }
|
||||
|
||||
DW_CC_normal = $01;
|
||||
DW_CC_program = $02;
|
||||
DW_CC_nocall = $03;
|
||||
DW_CC_lo_user = $40;
|
||||
DW_CC_hi_user = $ff;
|
||||
|
||||
|
||||
{ Inline encodings }
|
||||
|
||||
DW_INL_not_inlined = $00;
|
||||
DW_INL_inlined = $01;
|
||||
DW_INL_declared_not_inlined = $02;
|
||||
DW_INL_declared_inlined = $03;
|
||||
|
||||
|
||||
{ Ordering encodings }
|
||||
|
||||
DW_ORD_row_major = $00;
|
||||
DW_ORD_col_major = $01;
|
||||
|
||||
|
||||
{ Discriminant descriptor encodings }
|
||||
|
||||
DW_DSC_label = $00;
|
||||
DW_DSC_range = $01;
|
||||
|
||||
|
||||
{ Line Number Standard Opcode Encodings }
|
||||
|
||||
DW_LNS_copy = $01;
|
||||
DW_LNS_advance_pc = $02;
|
||||
DW_LNS_advance_line = $03;
|
||||
DW_LNS_set_file = $04;
|
||||
DW_LNS_set_column = $05;
|
||||
DW_LNS_negate_stmt = $06;
|
||||
DW_LNS_set_basic_block = $07;
|
||||
DW_LNS_const_add_pc = $08;
|
||||
DW_LNS_fixed_advance_pc = $09;
|
||||
// --- DWARF3 ---
|
||||
DW_LNS_set_prologue_end = $0a;
|
||||
DW_LNS_set_epilogue_begin = $0b;
|
||||
DW_LNS_set_isa = $0c;
|
||||
// --- ---
|
||||
|
||||
|
||||
{ Line Number Extended Opcode Encodings }
|
||||
|
||||
DW_LNE_end_sequence = $01;
|
||||
DW_LNE_set_address = $02;
|
||||
DW_LNE_define_file = $03;
|
||||
// --- DWARF3 ---
|
||||
DW_LNE_lo_user = $80;
|
||||
DW_LNE_hi_user = $ff;
|
||||
// --- ---
|
||||
|
||||
|
||||
{ Macinfo Type Encodings }
|
||||
|
||||
DW_MACINFO_define = $01;
|
||||
DW_MACINFO_undef = $02;
|
||||
DW_MACINFO_start_file = $03;
|
||||
DW_MACINFO_end_file = $04;
|
||||
DW_MACINFO_vendor_ext = $ff;
|
||||
|
||||
|
||||
{ Call frame instruction encodings }
|
||||
|
||||
// Special codes, operand is encoded in bit 5..0
|
||||
DW_CFA_advance_loc = $40; // delta
|
||||
DW_CFA_offset = $80; // register ULEB128 offset
|
||||
DW_CFA_restore = $C0; // register
|
||||
//--
|
||||
DW_CFA_nop = $00;
|
||||
DW_CFA_set_loc = $01; // address
|
||||
DW_CFA_advance_loc1 = $02; // 1-byte delta
|
||||
DW_CFA_advance_loc2 = $03; // 2-byte delta
|
||||
DW_CFA_advance_loc4 = $04; // 4-byte delta
|
||||
DW_CFA_offset_extended = $05; // ULEB128 register, ULEB128 offset
|
||||
DW_CFA_restore_extended = $06; // ULEB128 register
|
||||
DW_CFA_undefined = $07; // ULEB128 register
|
||||
DW_CFA_same_value = $08; // ULEB128 register
|
||||
DW_CFA_register = $09; // ULEB128 register, ULEB128 register
|
||||
DW_CFA_remember_state = $0a;
|
||||
DW_CFA_restore_state = $0b;
|
||||
DW_CFA_def_cfa = $0c; // ULEB128 register, ULEB128 offset
|
||||
DW_CFA_def_cfa_register = $0d; // ULEB128 register
|
||||
DW_CFA_def_cfa_offset = $0e; // ULEB128 offset
|
||||
// --- DWARF3 ---
|
||||
DW_CFA_def_cfa_expression = $0f; // BLOCK
|
||||
DW_CFA_expression = $10; // ULEB128 register, BLOCK
|
||||
DW_CFA_offset_extended_sf = $11; // ULEB128 register, SLEB128 offset
|
||||
DW_CFA_def_cfa_sf = $12; // ULEB128 register, SLEB128 offset
|
||||
DW_CFA_def_cfa_offset_sf = $13; // SLEB128 offset
|
||||
DW_CFA_val_offset = $14; // ULEB128 , ULEB128
|
||||
DW_CFA_val_offset_sf = $15; // ULEB128 , SLEB128
|
||||
DW_CFA_val_expression = $16; // ULEB128 , BLOCK
|
||||
// --- ---
|
||||
DW_CFA_lo_user = $1c;
|
||||
DW_CFA_hi_user = $3f;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
||||
|
@ -58,21 +58,83 @@ type
|
||||
property Handle: THandle read FHandle;
|
||||
property SingleStepping: boolean read FSingleStepping;
|
||||
end;
|
||||
|
||||
TDbgSymbolKind = (
|
||||
skNone, // undefined type
|
||||
skUser, // userdefined type, this sym refers to another sym defined elswhere
|
||||
skInstance, // the main exe/dll, containing all other syms
|
||||
skUnit, // contains syms defined in this unit
|
||||
//--------------------------------------------------------------------------
|
||||
skRecord, // the address member is the relative location within the
|
||||
skObject, // structure
|
||||
skClass,
|
||||
skInterface,
|
||||
skProcedure,
|
||||
skFunction,
|
||||
//--------------------------------------------------------------------------
|
||||
skArray,
|
||||
//--------------------------------------------------------------------------
|
||||
skInteger, // Basic types, these cannot have references or children
|
||||
skCardinal, // only size matters ( char(1) = Char, char(2) = WideChar
|
||||
skBoolean, // cardinal(1) = Byte etc.
|
||||
skChar,
|
||||
skFloat,
|
||||
skString,
|
||||
skAnsiString,
|
||||
skCurrency,
|
||||
skVariant,
|
||||
skWideString,
|
||||
skEnum,
|
||||
skSet,
|
||||
//--------------------------------------------------------------------------
|
||||
skRegister // the Address member is the register number
|
||||
//--------------------------------------------------------------------------
|
||||
);
|
||||
|
||||
TDbgSymbolFlag =(
|
||||
sfPointer, // The sym is a pointer to the reference
|
||||
sfConst, // The sym is a constan and cannot be modified
|
||||
sfVar,
|
||||
sfOut,
|
||||
sfpropGet,
|
||||
sfPropSet,
|
||||
sfPropStored
|
||||
);
|
||||
TDbgSymbolFlags = set of TDbgSymbolFlag;
|
||||
|
||||
{ TDbgSymbol }
|
||||
|
||||
(*
|
||||
TDbgSymbol = class(TObject)
|
||||
private
|
||||
FList: TStringList;
|
||||
FName: String;
|
||||
FOffset: Integer;
|
||||
FLength: Integer;
|
||||
function GetAddress: Pointer;
|
||||
FKind: TDbgSymbolKind;
|
||||
FAddress: TDbgPtr;
|
||||
FParent: TDbgSymbol;
|
||||
FSize: Integer;
|
||||
FFile: String;
|
||||
FLine: Integer;
|
||||
FFlags: TDbgSymbolFlags;
|
||||
FReference: TDbgSymbol;
|
||||
function GetChild(AIndex: Integer): TDbgSymbol;
|
||||
function GetCount: Integer;
|
||||
protected
|
||||
public
|
||||
constructor Create(const AName: String; const AOffset: Integer);
|
||||
property Address: Pointer read GetAddress;
|
||||
property Length: Integer read FLength;
|
||||
procedure AddChild(const AChild: TDbgSymbol);
|
||||
constructor Create(const AName: String; AKind: TDbgSymbolKind; AAddress: TDbgPtr; ASize: Integer = 0; const AFile: String = ''; ALine: Integer = -1; AFlags: TDbgSymbolFlags = []; const AReference: TDbgSymbol = nil);
|
||||
destructor Destroy; override;
|
||||
property Count: Integer read GetCount;
|
||||
property Name: String read FName;
|
||||
property Kind: TDbgSymbolKind read FKind;
|
||||
property Address: TDbgPtr read FAddress;
|
||||
property Size: Integer read FSize;
|
||||
property FileName: String read FFile;
|
||||
property Line: Integer read FLine;
|
||||
property Flags: TDbgSymbolFlags read FFlags;
|
||||
property Reference: TDbgSymbol read FReference;
|
||||
property Parent: TDbgSymbol read FParent;
|
||||
property Children[AIndex: Integer]: TDbgSymbol read GetChild;
|
||||
end;
|
||||
*)
|
||||
|
||||
TDbgBreakpoint = class;
|
||||
TDbgBreakpointEvent = procedure(const ASender: TDbgBreakpoint; const AContext: TContext) of object;
|
||||
@ -91,6 +153,8 @@ type
|
||||
end;
|
||||
|
||||
|
||||
{ TDbgInstance }
|
||||
|
||||
TDbgInstance = class(TObject)
|
||||
private
|
||||
FName: String;
|
||||
@ -98,6 +162,8 @@ type
|
||||
FModuleHandle: THandle;
|
||||
FBaseAddr: TDbgPtr;
|
||||
FBreakList: TList;
|
||||
FSymbols: TDbgSymbol;
|
||||
procedure BuildSymbols;
|
||||
procedure CheckName;
|
||||
procedure SetName(const AValue: String);
|
||||
public
|
||||
@ -141,9 +207,9 @@ type
|
||||
function AddBreak(const ALocation: TDbgPtr): TDbgBreakpoint;
|
||||
function AddLib(const AInfo: TLoadDLLDebugInfo): TDbgLibrary;
|
||||
procedure AddThread(const AID: Integer; const AInfo: TCreateThreadDebugInfo);
|
||||
// function GetLib(const AHandle: THandle; var ALib: TDbgLibrary): Boolean;
|
||||
function GetLib(const AHandle: THandle; out ALib: TDbgLibrary): Boolean;
|
||||
function GetThread(const AID: Integer; out AThread: TDbgThread): Boolean;
|
||||
procedure Interrupt;
|
||||
function GetThread(const AID: Integer; var AThread: TDbgThread): Boolean;
|
||||
procedure ContinueDebugEvent(const AThread: TDbgThread; const ADebugEvent: TDebugEvent);
|
||||
function HandleDebugEvent(const ADebugEvent: TDebugEvent): Boolean;
|
||||
function RemoveBreak(const ALocation: TDbgPtr): TDbgBreakpoint;
|
||||
@ -166,7 +232,7 @@ type
|
||||
implementation
|
||||
|
||||
uses
|
||||
SysUtils;
|
||||
SysUtils, WinDSymbols;
|
||||
|
||||
procedure LogLastError;
|
||||
begin
|
||||
@ -175,6 +241,12 @@ end;
|
||||
|
||||
{ TDbgInstance }
|
||||
|
||||
procedure TDbgInstance.BuildSymbols;
|
||||
begin
|
||||
FSymbols := TDbgSymbol.Create(FName, skInstance, FBaseAddr);
|
||||
AddSymbols(FSymbols, FModuleHandle);
|
||||
end;
|
||||
|
||||
procedure TDbgInstance.CheckName;
|
||||
begin
|
||||
if FName = ''
|
||||
@ -191,6 +263,7 @@ begin
|
||||
FBaseAddr := ABaseAddr;
|
||||
FModuleHandle := AModuleHandle;
|
||||
FBreakList := TList.Create;
|
||||
FProcess := AProcess;
|
||||
|
||||
inherited Create;
|
||||
|
||||
@ -224,6 +297,7 @@ begin
|
||||
then W := ADefaultName;
|
||||
|
||||
SetName(W);
|
||||
BuildSymbols;
|
||||
end;
|
||||
|
||||
destructor TDbgInstance.Destroy;
|
||||
@ -237,6 +311,7 @@ begin
|
||||
FBreakList.Clear;
|
||||
|
||||
FreeAndNil(FBreakList);
|
||||
FreeAndNil(FSymbols);
|
||||
inherited;
|
||||
end;
|
||||
|
||||
@ -324,26 +399,28 @@ begin
|
||||
inherited;
|
||||
end;
|
||||
|
||||
(*
|
||||
function TDbgProcess.GetLib(const AHandle: THandle; var ALib: TDbgLibrary): Boolean;
|
||||
function TDbgProcess.GetLib(const AHandle: THandle; out ALib: TDbgLibrary): Boolean;
|
||||
var
|
||||
n: Integer;
|
||||
Iterator: TMapIterator;
|
||||
Lib: TDbgLibrary;
|
||||
begin
|
||||
for n := 0 to FLibraries.Count - 1 do
|
||||
begin
|
||||
Lib := TDbgLibrary(FLibraries[n]);
|
||||
if Lib.ModuleHandle <> AHandle then Continue;
|
||||
|
||||
Result := True;
|
||||
ALib := Lib;
|
||||
Exit;
|
||||
end;
|
||||
Result := False;
|
||||
Iterator := TMapIterator.Create(FLibMap);
|
||||
while not Iterator.EOM do
|
||||
begin
|
||||
Iterator.GetData(Lib);
|
||||
Result := Lib.ModuleHandle = AHandle;
|
||||
if Result
|
||||
then begin
|
||||
ALib := Lib;
|
||||
Break;
|
||||
end;
|
||||
Iterator.Next;
|
||||
end;
|
||||
Iterator.Free;
|
||||
end;
|
||||
*)
|
||||
|
||||
function TDbgProcess.GetThread(const AID: Integer; var AThread: TDbgThread): Boolean;
|
||||
function TDbgProcess.GetThread(const AID: Integer; out AThread: TDbgThread): Boolean;
|
||||
var
|
||||
Thread: TDbgThread;
|
||||
begin
|
||||
@ -604,24 +681,52 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
|
||||
(*
|
||||
{ TDbgSymbol }
|
||||
|
||||
constructor TDbgSymbol.Create(const AName: String; const ASection: TDbgSection; const AOffset: Integer);
|
||||
function TDbgSymbol.GetChild(AIndex: Integer): TDbgSymbol;
|
||||
begin
|
||||
Result := TDbgSymbol(FList.Objects[AIndex]);
|
||||
end;
|
||||
|
||||
function TDbgSymbol.GetCount: Integer;
|
||||
begin
|
||||
Result := FList.Count;
|
||||
end;
|
||||
|
||||
procedure TDbgSymbol.AddChild(const AChild: TDbgSymbol);
|
||||
begin
|
||||
FList.AddObject(AChild.Name, AChild);
|
||||
AChild.FParent := Self;
|
||||
end;
|
||||
|
||||
constructor TDbgSymbol.Create(const AName: String; AKind: TDbgSymbolKind; AAddress: TDbgPtr; ASize: Integer; const AFile: String; ALine: Integer; AFlags: TDbgSymbolFlags = []; const AReference: TDbgSymbol = nil);
|
||||
begin
|
||||
FList := TStringList.Create;
|
||||
FList.CaseSensitive := True;
|
||||
FList.Duplicates := dupError;
|
||||
FList.Sorted := True;
|
||||
|
||||
FName := AName;
|
||||
FSection := ASection;
|
||||
FOffset := AOffset;
|
||||
FLength := 0;
|
||||
FKind := AKind;
|
||||
FAddress := AAddress;
|
||||
FSize := ASize;
|
||||
FFile := AFile;
|
||||
FLine := ALine;
|
||||
FReference := AReference;
|
||||
FFlags := AFlags;
|
||||
|
||||
inherited Create;
|
||||
end;
|
||||
|
||||
function TDbgSymbol.GetAddress: Pointer;
|
||||
destructor TDbgSymbol.Destroy;
|
||||
var
|
||||
n: Integer;
|
||||
begin
|
||||
Result := PChar(FSection.StartAddr) + FOffset - FSection.FOffset;
|
||||
for n := 0 to FList.Count - 1 do
|
||||
FList.Objects[n].Free;
|
||||
FreeAndNil(FList);
|
||||
inherited Destroy;
|
||||
end;
|
||||
*)
|
||||
|
||||
{ TDbgBreak }
|
||||
|
||||
|
273
debugger/windebug/windloader.pp
Normal file
273
debugger/windebug/windloader.pp
Normal file
@ -0,0 +1,273 @@
|
||||
{ $Id$ }
|
||||
{
|
||||
---------------------------------------------------------------------------
|
||||
windloader.pp - Native windows debugger - Section loader
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
This unit contains helper classes for loading secions form images.
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
@created(Mon Aug 1st WET 2006)
|
||||
@lastmod($Date$)
|
||||
@author(Marc Weustink <marc@@dommelstein.nl>)
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* This source is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This code is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* General Public License for more details. *
|
||||
* *
|
||||
* A copy of the GNU General Public License is available on the World *
|
||||
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
||||
* obtain it by writing to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
* *
|
||||
***************************************************************************
|
||||
}
|
||||
unit WinDLoader;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
{$ifdef windows}
|
||||
Windows,
|
||||
{$endif}
|
||||
Classes, SysUtils, WinDPETypes;
|
||||
|
||||
type
|
||||
TDbgImageSection = record
|
||||
RawData: Pointer;
|
||||
Size: QWord;
|
||||
VirtualAdress: QWord;
|
||||
end;
|
||||
PDbgImageSection = ^TDbgImageSection;
|
||||
|
||||
|
||||
{ TDbgImageLoader }
|
||||
|
||||
TDbgImageLoader = class(TObject)
|
||||
private
|
||||
FFileName: String;
|
||||
FSections: TStringList;
|
||||
function GetSection(const AName: String): PDbgImageSection;
|
||||
protected
|
||||
procedure Add(const AName: String; ARawData: Pointer; ASize: QWord; AVirtualAdress: QWord);
|
||||
procedure LoadSections; virtual; abstract;
|
||||
procedure UnloadSections; virtual; abstract;
|
||||
public
|
||||
constructor Create(const AFileName: String); virtual;
|
||||
destructor Destroy; override;
|
||||
property FileName: String read FFileName;
|
||||
property Section[const AName: String]: PDbgImageSection read GetSection;
|
||||
end;
|
||||
|
||||
{ TDbgPEImageLoader }
|
||||
|
||||
TDbgPEImageLoader = class(TDbgImageLoader)
|
||||
private
|
||||
protected
|
||||
function LoadData(out AModuleBase: Pointer; out AHeaders: PImageNtHeaders): Boolean; virtual; abstract;
|
||||
procedure LoadSections; override;
|
||||
procedure UnloadData; virtual; abstract;
|
||||
procedure UnloadSections; override;
|
||||
public
|
||||
end;
|
||||
|
||||
{ TDbgWinPEImageLoader }
|
||||
|
||||
TDbgWinPEImageLoader = class(TDbgPEImageLoader)
|
||||
private
|
||||
FFileHandle: THandle;
|
||||
FMapHandle: THandle;
|
||||
FModulePtr: Pointer;
|
||||
procedure DoCleanup;
|
||||
protected
|
||||
constructor Create(const AFileName: String); override;
|
||||
function LoadData(out AModuleBase: Pointer; out AHeaders: PImageNtHeaders): Boolean; override;
|
||||
procedure UnloadData; override;
|
||||
public
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TDbgImageLoader }
|
||||
|
||||
procedure TDbgImageLoader.Add(const AName: String; ARawData: Pointer; ASize: QWord; AVirtualAdress: QWord);
|
||||
var
|
||||
p: PDbgImageSection;
|
||||
idx: integer;
|
||||
begin
|
||||
idx := FSections.AddObject(AName, nil);
|
||||
New(p);
|
||||
P^.RawData := ARawData;
|
||||
p^.Size := ASize;
|
||||
p^.VirtualAdress := AVirtualAdress;
|
||||
FSections.Objects[idx] := TObject(p);
|
||||
end;
|
||||
|
||||
constructor TDbgImageLoader.Create(const AFileName: String);
|
||||
begin
|
||||
inherited Create;
|
||||
FFileName := AFileName;
|
||||
FSections := TStringList.Create;
|
||||
FSections.Sorted := True;
|
||||
FSections.Duplicates := dupError;
|
||||
FSections.CaseSensitive := False;
|
||||
LoadSections;
|
||||
end;
|
||||
|
||||
destructor TDbgImageLoader.Destroy;
|
||||
var
|
||||
n: integer;
|
||||
begin
|
||||
UnloadSections;
|
||||
for n := 0 to FSections.Count - 1 do
|
||||
Dispose(PDbgImageSection(FSections.Objects[n]));
|
||||
FSections.Clear;
|
||||
inherited Destroy;
|
||||
FreeAndNil(FSections);
|
||||
end;
|
||||
|
||||
function TDbgImageLoader.GetSection(const AName: String): PDbgImageSection;
|
||||
var
|
||||
idx: integer;
|
||||
begin
|
||||
idx := FSections.IndexOf(AName);
|
||||
if idx = -1
|
||||
then Result := nil
|
||||
else Result := PDbgImageSection(FSections.Objects[idx]);
|
||||
end;
|
||||
|
||||
{ TDbgPEImageLoader }
|
||||
|
||||
procedure TDbgPEImageLoader.LoadSections;
|
||||
var
|
||||
ModulePtr: Pointer;
|
||||
Is64: Boolean;
|
||||
NtHeaders: PImageNtHeaders;
|
||||
SectionHeader: PImageSectionHeader;
|
||||
n, idx: Integer;
|
||||
p: Pointer;
|
||||
SectionName: array[0..IMAGE_SIZEOF_SHORT_NAME] of Char;
|
||||
begin
|
||||
if not LoadData(ModulePtr, NtHeaders) then Exit;
|
||||
|
||||
if NtHeaders^.Signature <> IMAGE_NT_SIGNATURE
|
||||
then begin
|
||||
WriteLn('Invalid NT header: ', IntToHex(NtHeaders^.Signature, 8));
|
||||
Exit;
|
||||
end;
|
||||
|
||||
Is64 := NtHeaders^.OptionalHeader.Magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
|
||||
|
||||
for n := 0 to NtHeaders^.FileHeader.NumberOfSections - 1 do
|
||||
begin
|
||||
SectionHeader := @NtHeaders^.OptionalHeader + NtHeaders^.FileHeader.SizeOfOptionalHeader + SizeOf(SectionHeader^) * n;
|
||||
// make a null terminated name
|
||||
Move(SectionHeader^.Name, SectionName, IMAGE_SIZEOF_SHORT_NAME);
|
||||
SectionName[IMAGE_SIZEOF_SHORT_NAME] := #0;
|
||||
if (SectionName[0] = '/') and (SectionName[1] in ['0'..'9'])
|
||||
then begin
|
||||
// long name
|
||||
p := ModulePtr + NTHeaders^.FileHeader.PointerToSymbolTable + NTHeaders^.FileHeader.NumberOfSymbols * IMAGE_SIZEOF_SYMBOL + StrToIntDef(PChar(@SectionName[1]), 0);
|
||||
Add(PChar(p), ModulePtr + SectionHeader^.PointerToRawData, SectionHeader^.Misc.VirtualSize, SectionHeader^.VirtualAddress);
|
||||
end
|
||||
else begin
|
||||
// short name
|
||||
Add(SectionName, ModulePtr + SectionHeader^.PointerToRawData, SectionHeader^.Misc.VirtualSize, SectionHeader^.VirtualAddress);
|
||||
end
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDbgPEImageLoader.UnloadSections;
|
||||
begin
|
||||
UnloadData;
|
||||
end;
|
||||
|
||||
{ TDbgWinPEImageLoader }
|
||||
|
||||
constructor TDbgWinPEImageLoader.Create(const AFileName: String);
|
||||
begin
|
||||
FFileHandle := INVALID_HANDLE_VALUE;
|
||||
FMapHandle := 0;
|
||||
FModulePtr := nil;
|
||||
inherited Create(AFileName);
|
||||
end;
|
||||
|
||||
procedure TDbgWinPEImageLoader.DoCleanup;
|
||||
begin
|
||||
if FModulePtr <> nil
|
||||
then UnmapViewOfFile(FModulePtr);
|
||||
if FMapHandle <> 0
|
||||
then CloseHandle(FMapHandle);
|
||||
if FFileHandle <> INVALID_HANDLE_VALUE
|
||||
then CloseHandle(FFileHandle);
|
||||
|
||||
FFileHandle := INVALID_HANDLE_VALUE;
|
||||
FMapHandle := 0;
|
||||
FModulePtr := nil;
|
||||
end;
|
||||
|
||||
function TDbgWinPEImageLoader.LoadData(out AModuleBase: Pointer; out AHeaders: PImageNtHeaders): Boolean;
|
||||
var
|
||||
DosHeader: PImageDosHeader;
|
||||
begin
|
||||
Result := False;
|
||||
FFileHandle := CreateFile(PChar(FileName), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if FFileHandle = INVALID_HANDLE_VALUE
|
||||
then begin
|
||||
WriteLN('Cannot open file: ', FileName);
|
||||
Exit;
|
||||
end;
|
||||
|
||||
try
|
||||
FMapHandle := CreateFileMapping(FFileHandle, nil, PAGE_READONLY{ or SEC_IMAGE}, 0, 0, nil);
|
||||
if FMapHandle = 0
|
||||
then begin
|
||||
WriteLn('Could not create module mapping');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
FModulePtr := MapViewOfFile(FMapHandle, FILE_MAP_READ, 0, 0, 0);
|
||||
if FModulePtr = nil
|
||||
then begin
|
||||
WriteLn('Could not map view');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
DosHeader := FModulePtr;
|
||||
if (DosHeader^.e_magic <> IMAGE_DOS_SIGNATURE)
|
||||
or (DosHeader^.e_lfanew = 0)
|
||||
then begin
|
||||
WriteLn('Invalid DOS header');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
AModuleBase := FModulePtr;
|
||||
AHeaders := FModulePtr + DosHeader^.e_lfanew;
|
||||
Result := True;
|
||||
finally
|
||||
if not Result
|
||||
then begin
|
||||
// something failed, do some cleanup
|
||||
DoCleanup;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDbgWinPEImageLoader.UnloadData;
|
||||
begin
|
||||
DoCleanup;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -55,7 +55,7 @@ const
|
||||
|
||||
{$endif}
|
||||
|
||||
{$alignment 2}
|
||||
{$packrecords 2}
|
||||
|
||||
type
|
||||
_IMAGE_DOS_HEADER = record // DOS .EXE header
|
||||
@ -81,7 +81,7 @@ type
|
||||
end;
|
||||
IMAGE_DOS_HEADER = _IMAGE_DOS_HEADER;
|
||||
TImageDosHeader = _IMAGE_DOS_HEADER;
|
||||
PImageDosHeader = TImageDosHeader;
|
||||
PImageDosHeader = ^TImageDosHeader;
|
||||
|
||||
type
|
||||
_IMAGE_OS2_HEADER = record // OS/2 .EXE header
|
||||
@ -178,7 +178,7 @@ type
|
||||
TImageVXDHeader = _IMAGE_VXD_HEADER;
|
||||
PImageVXDHeader = ^TImageVXDHeader;
|
||||
|
||||
{$alignement 4}
|
||||
{$packrecords 4}
|
||||
|
||||
//
|
||||
// File header format.
|
||||
@ -430,12 +430,12 @@ type
|
||||
|
||||
{$ifdef WIN64}
|
||||
IMAGE_NT_HEADERS = IMAGE_NT_HEADERS64;
|
||||
TImageNtHHeaders = TImageNtHeaders64;
|
||||
PImageNtHHeaders = PImageNtHeaders64;
|
||||
TImageNtHeaders = TImageNtHeaders64;
|
||||
PImageNtHeaders = PImageNtHeaders64;
|
||||
{$else}
|
||||
IMAGE_NT_HEADERS = IMAGE_NT_HEADERS32;
|
||||
TImageNtHHeaders = TImageNtHeaders32;
|
||||
PImageNtHHeaders = PImageNtHeaders32;
|
||||
TImageNtHeaders = TImageNtHeaders32;
|
||||
PImageNtHeaders = PImageNtHeaders32;
|
||||
{$endif}
|
||||
|
||||
const
|
||||
@ -592,7 +592,274 @@ const
|
||||
IMAGE_SCN_MEM_EXECUTE = $20000000; // Section is executable.
|
||||
IMAGE_SCN_MEM_READ = $40000000; // Section is readable.
|
||||
IMAGE_SCN_MEM_WRITE = $80000000; // Section is writeable.
|
||||
|
||||
//
|
||||
// TLS Chaacteristic Flags
|
||||
//
|
||||
IMAGE_SCN_SCALE_INDEX = $00000001; // Tls index is scaled
|
||||
|
||||
{$packrecords 2}
|
||||
|
||||
//
|
||||
// Symbol format.
|
||||
//
|
||||
type
|
||||
TISName = record
|
||||
case Byte of
|
||||
0: (ShortName: array[0..7] of Char);
|
||||
1: (Name: record
|
||||
Short: DWORD;
|
||||
Long: DWORD;
|
||||
end);
|
||||
2: (LongName: array[0..1] of DWORD) ;
|
||||
end;
|
||||
|
||||
_IMAGE_SYMBOL = record
|
||||
N: TISName;
|
||||
Value: DWORD;
|
||||
SectionNumber: SHORT;
|
||||
_Type: WORD;
|
||||
StorageClass: BYTE;
|
||||
NumberOfAuxSymbols: BYTE;
|
||||
end;
|
||||
IMAGE_SYMBOL = _IMAGE_SYMBOL;
|
||||
TImageSymbol = _IMAGE_SYMBOL;
|
||||
PImageSymbol = ^TImageSymbol;
|
||||
|
||||
const
|
||||
IMAGE_SIZEOF_SYMBOL = 18;
|
||||
|
||||
//
|
||||
// Section values.
|
||||
//
|
||||
// Symbols have a section number of the section in which they are
|
||||
// defined. Otherwise, section numbers have the following meanings:
|
||||
//
|
||||
|
||||
IMAGE_SYM_UNDEFINED = SHORT(0); // Symbol is undefined or is common.
|
||||
IMAGE_SYM_ABSOLUTE = SHORT(-1); // Symbol is an absolute value.
|
||||
IMAGE_SYM_DEBUG = SHORT(-2); // Symbol is a special debug item.
|
||||
IMAGE_SYM_SECTION_MAX = $FEFF; // Values = $FF00-= $FFFF are special
|
||||
|
||||
//
|
||||
// Type (fundamental) values.
|
||||
//
|
||||
|
||||
IMAGE_SYM_TYPE_NULL = $0000; // no type.
|
||||
IMAGE_SYM_TYPE_VOID = $0001; //
|
||||
IMAGE_SYM_TYPE_CHAR = $0002; // type character.
|
||||
IMAGE_SYM_TYPE_SHORT = $0003; // type short integer.
|
||||
IMAGE_SYM_TYPE_INT = $0004; //
|
||||
IMAGE_SYM_TYPE_LONG = $0005; //
|
||||
IMAGE_SYM_TYPE_FLOAT = $0006; //
|
||||
IMAGE_SYM_TYPE_DOUBLE = $0007; //
|
||||
IMAGE_SYM_TYPE_STRUCT = $0008; //
|
||||
IMAGE_SYM_TYPE_UNION = $0009; //
|
||||
IMAGE_SYM_TYPE_ENUM = $000A; // enumeration.
|
||||
IMAGE_SYM_TYPE_MOE = $000B; // member of enumeration.
|
||||
IMAGE_SYM_TYPE_BYTE = $000C; //
|
||||
IMAGE_SYM_TYPE_WORD = $000D; //
|
||||
IMAGE_SYM_TYPE_UINT = $000E; //
|
||||
IMAGE_SYM_TYPE_DWORD = $000F; //
|
||||
IMAGE_SYM_TYPE_PCODE = $8000; //
|
||||
//
|
||||
// Type (derived) values.
|
||||
//
|
||||
|
||||
IMAGE_SYM_DTYPE_NULL = 0; // no derived type.
|
||||
IMAGE_SYM_DTYPE_POINTER = 1; // pointer.
|
||||
IMAGE_SYM_DTYPE_FUNCTION = 2; // function.
|
||||
IMAGE_SYM_DTYPE_ARRAY = 3; // array.
|
||||
|
||||
//
|
||||
// Storage classes.
|
||||
//
|
||||
IMAGE_SYM_CLASS_END_OF_FUNCTION = High(BYTE);
|
||||
IMAGE_SYM_CLASS_NULL = $0000;
|
||||
IMAGE_SYM_CLASS_AUTOMATIC = $0001;
|
||||
IMAGE_SYM_CLASS_EXTERNAL = $0002;
|
||||
IMAGE_SYM_CLASS_STATIC = $0003;
|
||||
IMAGE_SYM_CLASS_REGISTER = $0004;
|
||||
IMAGE_SYM_CLASS_EXTERNAL_DEF = $0005;
|
||||
IMAGE_SYM_CLASS_LABEL = $0006;
|
||||
IMAGE_SYM_CLASS_UNDEFINED_LABEL = $0007;
|
||||
IMAGE_SYM_CLASS_MEMBER_OF_STRUCT = $0008;
|
||||
IMAGE_SYM_CLASS_ARGUMENT = $0009;
|
||||
IMAGE_SYM_CLASS_STRUCT_TAG = $000A;
|
||||
IMAGE_SYM_CLASS_MEMBER_OF_UNION = $000B;
|
||||
IMAGE_SYM_CLASS_UNION_TAG = $000C;
|
||||
IMAGE_SYM_CLASS_TYPE_DEFINITION = $000D;
|
||||
IMAGE_SYM_CLASS_UNDEFINED_STATIC = $000E;
|
||||
IMAGE_SYM_CLASS_ENUM_TAG = $000F;
|
||||
IMAGE_SYM_CLASS_MEMBER_OF_ENUM = $0010;
|
||||
IMAGE_SYM_CLASS_REGISTER_PARAM = $0011;
|
||||
IMAGE_SYM_CLASS_BIT_FIELD = $0012;
|
||||
|
||||
IMAGE_SYM_CLASS_FAR_EXTERNAL = $0044; //
|
||||
|
||||
IMAGE_SYM_CLASS_BLOCK = $0064;
|
||||
IMAGE_SYM_CLASS_FUNCTION = $0065;
|
||||
IMAGE_SYM_CLASS_END_OF_STRUCT = $0066;
|
||||
IMAGE_SYM_CLASS_FILE = $0067;
|
||||
// new
|
||||
IMAGE_SYM_CLASS_SECTION = $0068;
|
||||
IMAGE_SYM_CLASS_WEAK_EXTERNAL = $0069;
|
||||
|
||||
IMAGE_SYM_CLASS_CLR_TOKEN = $006B;
|
||||
|
||||
// type packing constants
|
||||
|
||||
N_BTMASK = $000F;
|
||||
N_TMASK = $0030;
|
||||
N_TMASK1 = $00C0;
|
||||
N_TMASK2 = $00F0;
|
||||
N_BTSHFT = 4;
|
||||
N_TSHIFT = 2;
|
||||
|
||||
// MACROS
|
||||
|
||||
// Basic Type of x
|
||||
function BTYPE(x: Byte): Byte; inline;
|
||||
|
||||
// Is x a pointer?
|
||||
function ISPTR(x: Byte): Boolean; inline;
|
||||
|
||||
// Is x a function?
|
||||
function ISFCN(x: Byte): Boolean; inline;
|
||||
|
||||
// Is x an array?
|
||||
function ISARY(x: Byte): Boolean; inline;
|
||||
|
||||
// Is x a structure, union, or enumeration TAG?
|
||||
function ISTAG(x: Byte): Boolean; inline;
|
||||
|
||||
function INCREF(x: Byte): Byte; inline;
|
||||
|
||||
function DECREF(x: Byte): Byte; inline;
|
||||
|
||||
//
|
||||
// Auxiliary entry format.
|
||||
//
|
||||
type
|
||||
TIASMisc = record
|
||||
case Byte of
|
||||
0: (
|
||||
Linenumber: WORD; // declaration line number
|
||||
Size: WORD; // size of struct, union, or enum
|
||||
);
|
||||
1: (
|
||||
LnSz: record
|
||||
Linenumber: WORD; // declaration line number
|
||||
Size: WORD; // size of struct, union, or enum
|
||||
end;
|
||||
);
|
||||
2: (TotalSize: DWORD);
|
||||
end;
|
||||
|
||||
TIASFcnAry = record
|
||||
case Byte of
|
||||
0: (
|
||||
_Function: record // if ISFCN, tag, or .bb
|
||||
PointerToLinenumber: DWORD;
|
||||
PointerToNextFunction: DWORD;
|
||||
end;
|
||||
);
|
||||
1: (
|
||||
_Array: record // if ISARY, up to 4 dimen.
|
||||
Dimension: array[0..3] of WORD;
|
||||
end;
|
||||
);
|
||||
end;
|
||||
|
||||
_IMAGE_AUX_SYMBOL = record
|
||||
case Byte of
|
||||
0: (
|
||||
Sym: record
|
||||
TagIndex: DWORD; // struct, union, or enum tag index
|
||||
Misc: TIASMisc;
|
||||
FcnAry: TIASFcnAry;
|
||||
TvIndex: WORD; // tv index
|
||||
end;
|
||||
);
|
||||
1: (
|
||||
_File: record
|
||||
Name: array[0..IMAGE_SIZEOF_SYMBOL-1] of BYTE;
|
||||
end;
|
||||
);
|
||||
2: (
|
||||
Section: record
|
||||
Length: DWORD; // section length
|
||||
NumberOfRelocations: WORD; // number of relocation entries
|
||||
NumberOfLinenumbers: WORD; // number of line numbers
|
||||
CheckSum: DWORD; // checksum for communal
|
||||
Number: SHORT; // section number to associate with
|
||||
Selection: BYTE; // communal selection type
|
||||
end;
|
||||
);
|
||||
end;
|
||||
IMAGE_AUX_SYMBOL = _IMAGE_AUX_SYMBOL;
|
||||
TImageAuxSymbol = _IMAGE_AUX_SYMBOL;
|
||||
PImageAuxSymbol = ^TImageAuxSymbol;
|
||||
|
||||
|
||||
const
|
||||
IMAGE_SIZEOF_AUX_SYMBOL = 18;
|
||||
|
||||
type
|
||||
IMAGE_AUX_SYMBOL_TYPE = (
|
||||
IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF = 1
|
||||
);
|
||||
TImageAuxSymbolType = IMAGE_AUX_SYMBOL_TYPE;
|
||||
|
||||
{$packRecords 2}
|
||||
|
||||
type
|
||||
IMAGE_AUX_SYMBOL_TOKEN_DEF = record
|
||||
bAuxType: BYTE; // IMAGE_AUX_SYMBOL_TYPE
|
||||
bReserved: BYTE; // Must be 0
|
||||
SymbolTableIndex: DWORD;
|
||||
rgbReserved: array [0..11] of BYTE; // Must be 0
|
||||
end;
|
||||
TImageAuxSymbolTokenDef = IMAGE_AUX_SYMBOL_TOKEN_DEF;
|
||||
PImageAuxSymbolTokenDef = ^TImageAuxSymbolTokenDef;
|
||||
|
||||
{$packrecords 4}
|
||||
|
||||
implementation
|
||||
|
||||
function BTYPE(x: Byte): Byte; inline;
|
||||
begin
|
||||
Result := x and N_BTMASK;
|
||||
end;
|
||||
|
||||
function ISPTR(x: Byte): Boolean; inline;
|
||||
begin
|
||||
Result := (x and N_TMASK) = (IMAGE_SYM_DTYPE_POINTER shl N_BTSHFT);
|
||||
end;
|
||||
|
||||
function ISFCN(x: Byte): Boolean; inline;
|
||||
begin
|
||||
Result := (x and N_TMASK) = (IMAGE_SYM_DTYPE_FUNCTION shl N_BTSHFT);
|
||||
end;
|
||||
|
||||
function ISARY(x: Byte): Boolean; inline;
|
||||
begin
|
||||
Result := (x and N_TMASK) = (IMAGE_SYM_DTYPE_ARRAY shl N_BTSHFT);
|
||||
end;
|
||||
|
||||
function ISTAG(x: Byte): Boolean; inline;
|
||||
begin
|
||||
Result := (x = IMAGE_SYM_CLASS_STRUCT_TAG) or (x = IMAGE_SYM_CLASS_UNION_TAG) or (x = IMAGE_SYM_CLASS_ENUM_TAG);
|
||||
end;
|
||||
|
||||
function INCREF(x: Byte): Byte; inline;
|
||||
begin
|
||||
Result := ((x and not N_BTMASK) shl N_TSHIFT) or (IMAGE_SYM_DTYPE_POINTER shl N_BTSHFT) or (x and N_BTMASK);
|
||||
end;
|
||||
|
||||
function DECREF(x: Byte): Byte; inline;
|
||||
begin
|
||||
Result := ((x shr N_TSHIFT) and not N_BTMASK) or (x and N_BTMASK);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
241
debugger/windebug/windsymbols.pas
Normal file
241
debugger/windebug/windsymbols.pas
Normal file
@ -0,0 +1,241 @@
|
||||
{ $Id$ }
|
||||
{
|
||||
---------------------------------------------------------------------------
|
||||
windsymbols.pas - Native windows debugger - Symbol loader/resolver
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
This unit contains helper classes for loading and resolving of debug symbols
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
@created(Sat Jun 24th WET 2006)
|
||||
@lastmod($Date$)
|
||||
@author(Marc Weustink <marc@@dommelstein.nl>)
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* This source is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This code is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* General Public License for more details. *
|
||||
* *
|
||||
* A copy of the GNU General Public License is available on the World *
|
||||
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
||||
* obtain it by writing to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
* *
|
||||
***************************************************************************
|
||||
}
|
||||
unit WinDSymbols;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows, Classes, SysUtils, WinDebugger, WinDExtra, WinDPETypes, WinDDwarf;
|
||||
|
||||
|
||||
procedure AddSymbols(AParent: TDbgSymbol; AModule: THandle);
|
||||
|
||||
implementation
|
||||
|
||||
procedure AddSymbols(AParent: TDbgSymbol; AModule: THandle);
|
||||
var
|
||||
ModulePtr: Pointer;
|
||||
Is64: Boolean;
|
||||
Sections: TStringList;
|
||||
|
||||
procedure AddDwarf;
|
||||
procedure Dump(p: PChar; count: Integer);
|
||||
var
|
||||
n: integer;
|
||||
begin
|
||||
for n := 1 to count do
|
||||
begin
|
||||
case p^ of
|
||||
#32..#127: Write(p^, ' ');
|
||||
else
|
||||
Write('#', Ord(p^), ' ');
|
||||
end;
|
||||
Inc(p);
|
||||
end;
|
||||
WriteLN;
|
||||
end;
|
||||
|
||||
function ULEB128toOrdinal(var p: PByte): Integer;
|
||||
var
|
||||
n: Byte;
|
||||
begin
|
||||
Result := 0;
|
||||
n := 0;
|
||||
repeat
|
||||
Result := Result + (p^ and $7F) shl n;
|
||||
Inc(n, 7);
|
||||
Inc(p);
|
||||
until ((p^ and $80) = 0) or (n > 128);
|
||||
end;
|
||||
|
||||
var
|
||||
idx4, idx16: Integer;
|
||||
data4, data16: Pointer;
|
||||
SH: PImageSectionHeader;
|
||||
n: integer;
|
||||
p: Pointer;
|
||||
pc: PChar absolute p;
|
||||
pb: PByte absolute p;
|
||||
pw: PWord absolute p;
|
||||
Name, Value: Cardinal;
|
||||
begin
|
||||
idx4 := Sections.IndexOf('/4');
|
||||
idx16 := Sections.IndexOf('/16');
|
||||
if (idx4 = -1) and (idx16 = -1) then Exit;
|
||||
|
||||
SH := Pointer(Sections.Objects[idx4]);
|
||||
Data4 := ModulePtr + SH^.PointerToRawData;
|
||||
p := Data4;
|
||||
WriteLN('.debug_info');
|
||||
WriteLn(' length: ', PCardinal(p)^);
|
||||
Inc(p, 4);
|
||||
WriteLn(' version: ', PWord(p)^);
|
||||
Inc(p, 2);
|
||||
WriteLn(' abbrev offset: ', PCardinal(p)^);
|
||||
Inc(p, 4);
|
||||
WriteLn(' address size: ', PByte(p)^);
|
||||
Inc(p, 1);
|
||||
|
||||
Write(HexValue(SH^.PointerToRawData, 8, []), ': ');
|
||||
Dump(p, 80);
|
||||
|
||||
SH := Pointer(Sections.Objects[idx16]);
|
||||
Data16 := ModulePtr + SH^.PointerToRawData;
|
||||
p := Data16;
|
||||
WriteLN('.debug_abbrev');
|
||||
while pb^ <> 0 do
|
||||
begin
|
||||
WriteLN(' abbrev: ', Cardinal(ULEB128toOrdinal(pb)));
|
||||
Value := Cardinal(ULEB128toOrdinal(pb));
|
||||
WriteLN(' tag: ', Value, '=', DwarfTagToString(Value));
|
||||
WriteLN(' children:', pb^);
|
||||
inc(pb);
|
||||
for n := 0 to 15 do
|
||||
begin
|
||||
Name := Cardinal(ULEB128toOrdinal(pb));
|
||||
Value := Cardinal(ULEB128toOrdinal(pb));
|
||||
if (name = 0) and (value = 0) then Break;
|
||||
WriteLN(' [', n:4, '] name: ', Name, '=', DwarfAttributeToString(Name), ', value:', Value, '=', DwarfAttributeFormToString(Value));
|
||||
end;
|
||||
if (name = 0) and (value = 0) then Continue;
|
||||
while pw^ <> 0 do Inc(pw);
|
||||
inc(pw);
|
||||
end;
|
||||
|
||||
// Write(HexValue(SH^.PointerToRawData, 8, []), ': ');
|
||||
// Dump(p, 80);
|
||||
end;
|
||||
|
||||
procedure AddStabs;
|
||||
var
|
||||
idx, idxstr: Integer;
|
||||
begin
|
||||
idx := Sections.Indexof('.stab');
|
||||
idxstr := Sections.Indexof('.stabstr');
|
||||
if (idx = -1) and (idxstr = -1) then Exit;
|
||||
end;
|
||||
|
||||
var
|
||||
hMap: THandle;
|
||||
DosHeader: PImageDosHeader;
|
||||
NtHeaders: PImageNtHeaders;
|
||||
SectionHeader: PImageSectionHeader;
|
||||
n: Integer;
|
||||
SectionName: array[0..IMAGE_SIZEOF_SHORT_NAME] of Char;
|
||||
begin
|
||||
hMap := 0;
|
||||
ModulePtr := nil;
|
||||
Sections := nil;
|
||||
try
|
||||
hMap := CreateFileMapping(AModule, nil, PAGE_READONLY{ or SEC_IMAGE}, 0, 0, nil);
|
||||
if hMap = 0
|
||||
then begin
|
||||
Log('AddSymbols: Could not create module mapping');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
ModulePtr := MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
|
||||
if ModulePtr = nil
|
||||
then begin
|
||||
Log('AddSymbols: Could not map view');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
DosHeader := ModulePtr;
|
||||
if (DosHeader^.e_magic <> IMAGE_DOS_SIGNATURE)
|
||||
or (DosHeader^.e_lfanew = 0)
|
||||
then begin
|
||||
Log('AddSymbols: Invalid DOS header');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
NTHeaders := ModulePtr + DosHeader^.e_lfanew;
|
||||
|
||||
if NTHeaders^.Signature <> IMAGE_NT_SIGNATURE
|
||||
then begin
|
||||
Log('AddSymbols: Invalid NT header: %s', [IntToHex(NTHeaders^.Signature, 8)]);
|
||||
Exit;
|
||||
end;
|
||||
|
||||
Is64 := NTHeaders^.OptionalHeader.Magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
|
||||
|
||||
Sections := TStringList.Create;
|
||||
Sections.CaseSensitive := False;
|
||||
Sections.Duplicates := dupIgnore;
|
||||
Sections.Sorted := True;
|
||||
for n := 0 to NtHeaders^.FileHeader.NumberOfSections - 1 do
|
||||
begin
|
||||
SectionHeader := @NTHeaders^.OptionalHeader + NTHeaders^.FileHeader.SizeOfOptionalHeader + SizeOf(SectionHeader^) * n;
|
||||
// make a null terminated name
|
||||
Move(SectionHeader^.Name, SectionName, IMAGE_SIZEOF_SHORT_NAME);
|
||||
SectionName[IMAGE_SIZEOF_SHORT_NAME] := #0;
|
||||
Sections.AddObject(SectionName, TObject(SectionHeader));
|
||||
end;
|
||||
|
||||
AddDwarf;
|
||||
AddStabs;
|
||||
//TODO: AddOther
|
||||
|
||||
|
||||
|
||||
(*
|
||||
with SectionHeader do
|
||||
begin
|
||||
Move(SectionHeader.Name, SectionName, IMAGE_SIZEOF_SHORT_NAME);
|
||||
SectionName[IMAGE_SIZEOF_SHORT_NAME] := #0;
|
||||
WriteLN(' Name: ',SectionName);
|
||||
WriteLN(' Misc.PhysicalAddress: ',FormatAddress(Misc.PhysicalAddress));
|
||||
WriteLN(' Misc.VirtualSize: ',Misc.VirtualSize);
|
||||
WriteLN(' VirtualAddress: ',FormatAddress(VirtualAddress));
|
||||
WriteLN(' SizeOfRawData: ',SizeOfRawData);
|
||||
WriteLN(' PointerToRawData: ',FormatAddress(PointerToRawData));
|
||||
WriteLN(' PointerToRelocations: ',FormatAddress(PointerToRelocations));
|
||||
WriteLN(' PointerToLinenumbers: ',FormatAddress(PointerToLinenumbers));
|
||||
WriteLN(' NumberOfRelocations: ',NumberOfRelocations);
|
||||
WriteLN(' NumberOfLinenumbers: ',NumberOfLinenumbers);
|
||||
Write(' Characteristics: ', IntToHex(Characteristics, 8), ' [');
|
||||
end;
|
||||
*)
|
||||
|
||||
finally
|
||||
UnmapViewOfFile(ModulePtr);
|
||||
CloseHandle(hMap);
|
||||
Sections.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
53
debugger/windebug/windutil.pp
Normal file
53
debugger/windebug/windutil.pp
Normal file
@ -0,0 +1,53 @@
|
||||
{ $Id$ }
|
||||
{
|
||||
---------------------------------------------------------------------------
|
||||
windutil.pp - Native windows debugger - Utilities
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
This unit contains utility functions
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
@created(Mon Apr 10th WET 2006)
|
||||
@lastmod($Date$)
|
||||
@author(Marc Weustink <marc@@dommelstein.nl>)
|
||||
|
||||
***************************************************************************
|
||||
* *
|
||||
* This source is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This code is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* General Public License for more details. *
|
||||
* *
|
||||
* A copy of the GNU General Public License is available on the World *
|
||||
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
||||
* obtain it by writing to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
* *
|
||||
***************************************************************************
|
||||
}
|
||||
unit WinDUtil;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
|
||||
function AlignPtr(Src: Pointer; Alignment: Byte): Pointer;
|
||||
|
||||
implementation
|
||||
|
||||
function AlignPtr(Src: Pointer; Alignment: Byte): Pointer;
|
||||
begin
|
||||
Result := Pointer(((PtrUInt(Src) + Alignment - 1) and not PtrUInt(Alignment - 1)));
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user