Author: akhaldi
Date: Wed Dec 15 23:37:54 2010
New Revision: 50033
URL:
http://svn.reactos.org/svn/reactos?rev=50033&view=rev
Log:
[CMAKE]
- Arty: Add usermode addresses translation support. WIP.
Modified:
branches/cmake-bringup/lib/rossym/delete.c
branches/cmake-bringup/lib/rossym/dwarf.h
branches/cmake-bringup/lib/rossym/dwarfinfo.c
branches/cmake-bringup/lib/rossym/dwarfopen.c
branches/cmake-bringup/lib/rossym/dwarfpc.c
branches/cmake-bringup/lib/rossym/fromfile.c
branches/cmake-bringup/lib/rossym/initum.c
branches/cmake-bringup/lib/rossym/pe.c
branches/cmake-bringup/lib/rossym/zwfile.c
branches/cmake-bringup/ntoskrnl/kdbg/kdb_symbols.c
Modified: branches/cmake-bringup/lib/rossym/delete.c
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/lib/rossym/delete…
==============================================================================
--- branches/cmake-bringup/lib/rossym/delete.c [iso-8859-1] (original)
+++ branches/cmake-bringup/lib/rossym/delete.c [iso-8859-1] Wed Dec 15 23:37:54 2010
@@ -22,11 +22,6 @@
VOID
RosSymDelete(PROSSYM_INFO RosSymInfo)
{
- int i;
- for (i = 0; i < RosSymInfo->pe->nsections; i++) {
- RtlFreeAnsiString(ANSI_NAME_STRING(&RosSymInfo->pe->sect[i]));
- }
- RosSymFreeMem(RosSymInfo->pe->sect);
dwarfclose(RosSymInfo);
}
Modified: branches/cmake-bringup/lib/rossym/dwarf.h
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/lib/rossym/dwarf.…
==============================================================================
--- branches/cmake-bringup/lib/rossym/dwarf.h [iso-8859-1] (original)
+++ branches/cmake-bringup/lib/rossym/dwarf.h [iso-8859-1] Wed Dec 15 23:37:54 2010
@@ -252,7 +252,7 @@
uchar framebase;
uchar friend;
uchar highpc;
- uchar entrypc;
+ uchar entrypc;
uchar identifiercase;
uchar import;
uchar inlined;
@@ -315,7 +315,7 @@
DwarfVal framebase;
ulong friend;
ulong highpc;
- ulong entrypc;
+ ulong entrypc;
ulong identifiercase;
ulong import;
ulong inlined;
Modified: branches/cmake-bringup/lib/rossym/dwarfinfo.c
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/lib/rossym/dwarfi…
==============================================================================
--- branches/cmake-bringup/lib/rossym/dwarfinfo.c [iso-8859-1] (original)
+++ branches/cmake-bringup/lib/rossym/dwarfinfo.c [iso-8859-1] Wed Dec 15 23:37:54 2010
@@ -366,7 +366,7 @@
{ DwarfAttrFrameBase, OFFSET(framebase), TBlock|TConstant },
{ DwarfAttrFriend, OFFSET(friend), TReference },
{ DwarfAttrHighpc, OFFSET(highpc), TAddress },
- { DwarfAttrEntrypc, OFFSET(entrypc), TAddress },
+ { DwarfAttrEntrypc, OFFSET(entrypc), TAddress },
{ DwarfAttrIdentifierCase, OFFSET(identifiercase), TConstant },
{ DwarfAttrImport, OFFSET(import), TReference },
{ DwarfAttrInline, OFFSET(inlined), TConstant },
Modified: branches/cmake-bringup/lib/rossym/dwarfopen.c
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/lib/rossym/dwarfo…
==============================================================================
--- branches/cmake-bringup/lib/rossym/dwarfopen.c [iso-8859-1] (original)
+++ branches/cmake-bringup/lib/rossym/dwarfopen.c [iso-8859-1] Wed Dec 15 23:37:54 2010
@@ -40,6 +40,7 @@
return d;
err:
+ DPRINT("Failed to open dwarf\n");
free(d->abbrev.data);
free(d->aranges.data);
free(d->frame.data);
Modified: branches/cmake-bringup/lib/rossym/dwarfpc.c
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/lib/rossym/dwarfp…
==============================================================================
--- branches/cmake-bringup/lib/rossym/dwarfpc.c [iso-8859-1] (original)
+++ branches/cmake-bringup/lib/rossym/dwarfpc.c [iso-8859-1] Wed Dec 15 23:37:54 2010
@@ -50,7 +50,7 @@
{
uchar *prog, *opcount, *end, *dirs;
ulong off, unit, len, vers, x, start, lastline;
- int i, first, op, a, l, quantum, isstmt, linebase, linerange, opcodebase, nf;
+ int i, first, firstline, op, a, l, quantum, isstmt, linebase, linerange, opcodebase,
nf;
char *files, *s;
DwarfBuf b;
DwarfSym sym;
@@ -150,6 +150,7 @@
if(trace) werrstr("program @ %lu ... %.*H opbase = %d\n", b.p -
d->line.data, b.ep-b.p, b.p, opcodebase);
first = 1;
while(b.p != nil){
+ firstline = 0;
op = dwarfget1(&b);
if(trace) werrstr("\tline %lu, addr 0x%x, op %d %.10H", cur.line, cur.addr,
op, b.p);
if(op >= opcodebase){
@@ -162,12 +163,16 @@
if(first){
if(cur.addr > pc){
werrstr("found wrong line mapping 0x%x for pc 0x%x", cur.addr, pc);
- goto out;
+ /* This is an overzealous check. gcc can produce discontiguous ranges
+ and reorder statements, so it's possible for a future line to start
+ ahead of pc and still find a matching one. */
+ /*goto out;*/
+ firstline = 1;
}
first = 0;
start = cur.addr;
}
- if(cur.addr > pc)
+ if(cur.addr > pc && !firstline)
break;
if(b.p == nil){
werrstr("buffer underflow in line mapping");
Modified: branches/cmake-bringup/lib/rossym/fromfile.c
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/lib/rossym/fromfi…
==============================================================================
--- branches/cmake-bringup/lib/rossym/fromfile.c [iso-8859-1] (original)
+++ branches/cmake-bringup/lib/rossym/fromfile.c [iso-8859-1] Wed Dec 15 23:37:54 2010
@@ -20,6 +20,8 @@
#define NDEBUG
#include <debug.h>
+extern NTSTATUS RosSymStatus;
+
BOOLEAN
RosSymCreateFromFile(PVOID FileContext, PROSSYM_INFO *RosSymInfo)
{
@@ -30,10 +32,14 @@
unsigned SymbolTable, NumSymbols;
/* Load DOS header */
- DPRINT("About to read file\n");
+ if (! RosSymSeekFile(FileContext, 0))
+ {
+ DPRINT1("Could not rewind file\n");
+ return FALSE;
+ }
if (! RosSymReadFile(FileContext, &DosHeader, sizeof(IMAGE_DOS_HEADER)))
{
- DPRINT1("Failed to read DOS header\n");
+ DPRINT1("Failed to read DOS header %x\n", RosSymStatus);
return FALSE;
}
if (! ROSSYM_IS_VALID_DOS_HEADER(&DosHeader))
@@ -70,6 +76,7 @@
DPRINT1("Failed seeking to section headers\n");
return FALSE;
}
+ DPRINT("Alloc section headers\n");
SectionHeaders = RosSymAllocMem(NtHeaders.FileHeader.NumberOfSections
* sizeof(IMAGE_SECTION_HEADER));
if (NULL == SectionHeaders)
@@ -178,7 +185,9 @@
pe->imagebase = pe->loadbase = NtHeaders.OptionalHeader.ImageBase;
pe->imagesize = NtHeaders.OptionalHeader.SizeOfImage;
pe->loadsection = loaddisksection;
+ DPRINT("do dwarfopen\n");
*RosSymInfo = dwarfopen(pe);
+ DPRINT("done %x\n", *RosSymInfo);
return TRUE;
Modified: branches/cmake-bringup/lib/rossym/initum.c
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/lib/rossym/initum…
==============================================================================
--- branches/cmake-bringup/lib/rossym/initum.c [iso-8859-1] (original)
+++ branches/cmake-bringup/lib/rossym/initum.c [iso-8859-1] Wed Dec 15 23:37:54 2010
@@ -7,9 +7,12 @@
* PROGRAMMERS: Ge van Geldorp (gvg(a)reactos.com)
*/
+#define WIN32_NO_STATUS
#include <windows.h>
#include <reactos/rossym.h>
#include "rossympriv.h"
+#define NTOS_MODE_USER
+#include <ndk/ntndk.h>
#define NDEBUG
#include <debug.h>
@@ -17,13 +20,13 @@
static PVOID
RosSymAllocMemUM(ULONG_PTR Size)
{
- return HeapAlloc(GetProcessHeap(), 0, Size);
+ return RtlAllocateHeap(RtlGetProcessHeap(), 0, Size);
}
static VOID
RosSymFreeMemUM(PVOID Area)
{
- HeapFree(GetProcessHeap(), 0, Area);
+ RtlFreeHeap(RtlGetProcessHeap(), 0, Area);
}
VOID
Modified: branches/cmake-bringup/lib/rossym/pe.c
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/lib/rossym/pe.c?r…
==============================================================================
--- branches/cmake-bringup/lib/rossym/pe.c [iso-8859-1] (original)
+++ branches/cmake-bringup/lib/rossym/pe.c [iso-8859-1] Wed Dec 15 23:37:54 2010
@@ -111,6 +111,10 @@
for (i = 0; i < pe->nsections; i++) {
RtlFreeAnsiString(ANSI_NAME_STRING(&pe->sect[i]));
}
+ for (i = 0; i < pe->nsymbols; i++) {
+ free(pe->symtab[i].name);
+ }
+ free(pe->symtab);
free(pe->sect);
free(pe);
}
Modified: branches/cmake-bringup/lib/rossym/zwfile.c
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/lib/rossym/zwfile…
==============================================================================
--- branches/cmake-bringup/lib/rossym/zwfile.c [iso-8859-1] (original)
+++ branches/cmake-bringup/lib/rossym/zwfile.c [iso-8859-1] Wed Dec 15 23:37:54 2010
@@ -15,38 +15,40 @@
#define NDEBUG
#include <debug.h>
+NTSTATUS RosSymStatus;
+
BOOLEAN
RosSymZwReadFile(PVOID FileContext, PVOID Buffer, ULONG Size)
{
- NTSTATUS Status;
+ //NTSTATUS Status;
IO_STATUS_BLOCK IoStatusBlock;
- Status = ZwReadFile(*((HANDLE *) FileContext),
+ RosSymStatus = ZwReadFile(*((HANDLE *) FileContext),
0, 0, 0,
&IoStatusBlock,
Buffer,
Size,
0, 0);
- return NT_SUCCESS(Status) && IoStatusBlock.Information == Size;
+ return NT_SUCCESS(RosSymStatus) && IoStatusBlock.Information == Size;
}
BOOLEAN
RosSymZwSeekFile(PVOID FileContext, ULONG_PTR Position)
{
- NTSTATUS Status;
+ //NTSTATUS Status;
IO_STATUS_BLOCK IoStatusBlock;
FILE_POSITION_INFORMATION NewPosition;
NewPosition.CurrentByteOffset.u.HighPart = 0;
NewPosition.CurrentByteOffset.u.LowPart = Position;
- Status = ZwSetInformationFile(*((HANDLE *) FileContext),
+ RosSymStatus = ZwSetInformationFile(*((HANDLE *) FileContext),
&IoStatusBlock,
(PVOID) &NewPosition,
sizeof(FILE_POSITION_INFORMATION),
FilePositionInformation);
- return NT_SUCCESS(Status);
+ return NT_SUCCESS(RosSymStatus);
}
/* EOF */
Modified: branches/cmake-bringup/ntoskrnl/kdbg/kdb_symbols.c
URL:
http://svn.reactos.org/svn/reactos/branches/cmake-bringup/ntoskrnl/kdbg/kdb…
==============================================================================
--- branches/cmake-bringup/ntoskrnl/kdbg/kdb_symbols.c [iso-8859-1] (original)
+++ branches/cmake-bringup/ntoskrnl/kdbg/kdb_symbols.c [iso-8859-1] Wed Dec 15 23:37:54
2010
@@ -29,6 +29,8 @@
static BOOLEAN LoadSymbols;
static LIST_ENTRY SymbolFileListHead;
static KSPIN_LOCK SymbolFileListLock;
+static PROSSYM_INFO KdbpRosSymInfo;
+static ULONG_PTR KdbpImageBase;
BOOLEAN KdbpSymbolsInitialized = FALSE;
/* FUNCTIONS ****************************************************************/
@@ -124,7 +126,13 @@
KdbSymPrintAddress(
IN PVOID Address)
{
+ PMEMORY_AREA MemoryArea = NULL;
+ HANDLE FileHandle = NULL;
+ PROS_SECTION_OBJECT SectionObject;
PLDR_DATA_TABLE_ENTRY LdrEntry;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK IoStatusBlock;
+ UNICODE_STRING ModuleFileName;
ULONG_PTR RelativeAddress;
NTSTATUS Status;
ULONG LineNumber;
@@ -144,11 +152,79 @@
{
DbgPrint("<%wZ:%x (%s:%d (%s))>",
&LdrEntry->BaseDllName, RelativeAddress, FileName, LineNumber,
FunctionName);
- }
- else
- {
- DbgPrint("<%wZ:%x>", &LdrEntry->BaseDllName,
RelativeAddress);
- }
+ return TRUE;
+ }
+ else if (Address < MmSystemRangeStart)
+ {
+ MemoryArea = MmLocateMemoryAreaByAddress(&PsGetCurrentProcess()->Vm, Address);
+ if (!MemoryArea || MemoryArea->Type != MEMORY_AREA_SECTION_VIEW)
+ {
+ goto end;
+ }
+ SectionObject = MemoryArea->Data.SectionData.Section;
+ if (!(SectionObject->AllocationAttributes & SEC_IMAGE)) goto end;
+ if (SectionObject->ImageSection->ImageBase != KdbpImageBase)
+ {
+ if (KdbpRosSymInfo)
+ {
+ RosSymDelete(KdbpRosSymInfo);
+ KdbpRosSymInfo = NULL;
+ }
+
+ Status = MmGetFileNameForAddress(Address, &ModuleFileName);
+ if (!NT_SUCCESS(Status))
+ goto end;
+
+ InitializeObjectAttributes
+ (&ObjectAttributes,
+ &ModuleFileName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+
+ if (!NT_SUCCESS
+ (ZwOpenFile
+ (&FileHandle,
+ FILE_READ_ACCESS,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ FILE_SHARE_READ,
+ FILE_SYNCHRONOUS_IO_NONALERT)))
+ {
+ goto end;
+ }
+
+ if (!RosSymCreateFromFile(&FileHandle, &KdbpRosSymInfo))
+ {
+ KdbpRosSymInfo = NULL;
+ }
+
+ ZwClose(FileHandle);
+ KdbpImageBase = SectionObject->ImageSection->ImageBase;
+ }
+
+ if (KdbpRosSymInfo)
+ {
+ RelativeAddress = (ULONG_PTR)Address - KdbpImageBase;
+ Status = KdbSymGetAddressInformation
+ (KdbpRosSymInfo,
+ RelativeAddress,
+ &LineNumber,
+ FileName,
+ FunctionName);
+ if (NT_SUCCESS(Status))
+ {
+ DbgPrint
+ ("<%wZ:%x (%s:%d (%s))>",
+ &SectionObject->FileObject->FileName,
+ RelativeAddress, FileName, LineNumber, FunctionName);
+ return TRUE;
+ }
+ }
+ }
+
+end:
+ DbgPrint("<%wZ:%x>", &LdrEntry->BaseDllName, RelativeAddress);
return TRUE;
}
@@ -208,8 +284,6 @@
PLIST_ENTRY CurrentEntry;
KIRQL Irql;
- DPRINT("Looking for cached symbol file %wZ\n", FileName);
-
KeAcquireSpinLock(&SymbolFileListLock, &Irql);
CurrentEntry = SymbolFileListHead.Flink;
@@ -217,7 +291,6 @@
{
Current = CONTAINING_RECORD(CurrentEntry, IMAGE_SYMBOL_INFO_CACHE, ListEntry);
- DPRINT("Current->FileName %wZ FileName %wZ\n",
&Current->FileName, FileName);
if (RtlEqualUnicodeString(&Current->FileName, FileName, TRUE))
{
Current->RefCount++;
@@ -311,7 +384,6 @@
}
KeReleaseSpinLock(&SymbolFileListLock, Irql);
- DPRINT1("Warning: Removing unknown symbol file: RosSymInfo = %p\n",
RosSymInfo);
}
/*! \brief Loads a symbol file.
@@ -411,7 +483,6 @@
LdrEntry->DllBase,
(PVOID)(LdrEntry->SizeOfImage + (ULONG_PTR)LdrEntry->DllBase),
LdrEntry->PatchInformation);
-
}
VOID