From 88650ed55efa1bfdfa0cae06b0c237f2fcf55fb4 Mon Sep 17 00:00:00 2001 From: Eugene Ingerman Date: Mon, 21 Jan 2002 10:03:50 +0000 Subject: [PATCH] Porting pice. Bug fixes. svn path=/trunk/; revision=2533 --- reactos/apps/utils/pice/module/bp.c | 68 +++++-- reactos/apps/utils/pice/module/debug.c | 5 +- reactos/apps/utils/pice/module/init.c | 14 +- reactos/apps/utils/pice/module/output.c | 89 ++++------ reactos/apps/utils/pice/module/output.h | 8 +- reactos/apps/utils/pice/module/parse.c | 55 +++--- reactos/apps/utils/pice/module/patch.c | 13 +- reactos/apps/utils/pice/module/pgflt.c | 92 +++++++--- reactos/apps/utils/pice/module/serial.c | 6 +- reactos/apps/utils/pice/module/shell.c | 72 ++++---- reactos/apps/utils/pice/module/symbols.c | 217 ++++++++++++----------- reactos/apps/utils/pice/module/utils.c | 144 +++++++-------- reactos/apps/utils/pice/module/utils.h | 6 +- reactos/apps/utils/pice/pice.cfg | 1 + 14 files changed, 447 insertions(+), 343 deletions(-) diff --git a/reactos/apps/utils/pice/module/bp.c b/reactos/apps/utils/pice/module/bp.c index 333b51cd234..0eb12281e61 100644 --- a/reactos/apps/utils/pice/module/bp.c +++ b/reactos/apps/utils/pice/module/bp.c @@ -210,9 +210,15 @@ BOOLEAN ReInstallSWBreakpoint(ULONG ulAddress) { if(IsAddressValid(p->ulAddress)) { - *(PUCHAR)(p->ulAddress) = 0xCC; - p->bInstalled = TRUE; - bResult = TRUE; + BOOLEAN isWriteable; + + if( !( isWriteable = IsAddressWriteable(p->ulAddress) ) ) + SetAddressWriteable(p->ulAddress,TRUE); + *(PUCHAR)(p->ulAddress) = 0xCC; + if( !isWriteable ) + SetAddressWriteable(p->ulAddress,FALSE); + p->bInstalled = TRUE; + bResult = TRUE; } } } @@ -239,17 +245,26 @@ BOOLEAN InstallSWBreakpoint(ULONG ulAddress,BOOLEAN bPermanent,void (*SWBreakpoi // TODO: must also check if it's a writable page if(IsAddressValid(ulAddress) ) { - DPRINT((0,"InstallSWBreakpoint(): %.8X is valid, writable? %d\n",ulAddress,IsAddressWriteable(ulAddress))); + DPRINT((2,"InstallSWBreakpoint(): %.8X is valid, writable? %d\n",ulAddress,IsAddressWriteable(ulAddress))); + DPRINT((2,"pde: %x, pte: %x\n", *(ADDR_TO_PDE(ulAddress)), *(ADDR_TO_PTE(ulAddress)))); if((p = FindSwBp(ulAddress))==NULL) { - DPRINT((0,"InstallSWBreakpoint(): %.8X is free\n",ulAddress)); + DPRINT((2,"InstallSWBreakpoint(): %.8X is free\n",ulAddress)); if( (p=FindEmptySwBpSlot()) ) { - DPRINT((0,"InstallSWBreakpoint(): found empty slot\n")); - DPRINT((0,"InstallSWBreakpoint(): %x value: %x", ulAddress, *(PUCHAR)ulAddress)); + BOOLEAN isWriteable; + DPRINT((2,"InstallSWBreakpoint(): found empty slot\n")); + DPRINT((2,"InstallSWBreakpoint(): %x value: %x", ulAddress, *(PUCHAR)ulAddress)); p->ucOriginalOpcode = *(PUCHAR)ulAddress; - *(PUCHAR)ulAddress = 0xCC; - p->bUsed = TRUE; + //allow writing to page + if( !( isWriteable = IsAddressWriteable(ulAddress) ) ) + SetAddressWriteable(ulAddress,TRUE); + DPRINT((2,"writing breakpoint\n")); + *(PUCHAR)ulAddress = 0xCC; + DPRINT((2,"restoring page access\n")); + if( !isWriteable ) + SetAddressWriteable(ulAddress,FALSE); + p->bUsed = TRUE; p->bInstalled = TRUE; // find next address p->ulAddress = ulAddress; @@ -337,9 +352,15 @@ void TryToInstallVirtualSWBreakpoints(void) if(IsAddressValid(ulAddressWithOffset)) { - DPRINT((0,"TryToInstallVirtualSWBreakpoints(): installing...\n")); + BOOLEAN isWriteable; + DPRINT((0,"TryToInstallVirtualSWBreakpoints(): installing...\n")); p->ucOriginalOpcode = *(PUCHAR)ulAddressWithOffset; + //allow writing to page + if( !( isWriteable = IsAddressWriteable(ulAddressWithOffset) ) ) + SetAddressWriteable(ulAddressWithOffset,TRUE); *(PUCHAR)ulAddressWithOffset = 0xCC; + if( !isWriteable ) + SetAddressWriteable(ulAddressWithOffset,FALSE); p->bUsed = TRUE; p->bInstalled = TRUE; p->bVirtual = FALSE; @@ -380,8 +401,13 @@ BOOLEAN RemoveSWBreakpoint(ULONG ulAddress) { if(IsAddressValid(ulAddress) && p->bInstalled == TRUE && p->bVirtual==FALSE) { - // restore original opcode + BOOLEAN isWriteable; + if( !( isWriteable = IsAddressWriteable(ulAddress) ) ) + SetAddressWriteable(ulAddress,TRUE); + // restore original opcode *(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode; + if( !isWriteable ) + SetAddressWriteable(ulAddress,FALSE); } PICE_memset(p,0,sizeof(*p)); @@ -411,8 +437,13 @@ BOOLEAN DeInstallSWBreakpoint(ULONG ulAddress) { if(IsAddressValid(ulAddress) && p->bInstalled == TRUE && p->bVirtual==FALSE) { + BOOLEAN isWriteable; + if( !( isWriteable = IsAddressWriteable(ulAddress) ) ) + SetAddressWriteable(ulAddress,TRUE); // restore original opcode *(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode; + if( !isWriteable ) + SetAddressWriteable(ulAddress,FALSE); } p->bInstalled = FALSE; @@ -447,7 +478,12 @@ BOOLEAN RemoveAllSWBreakpoints(BOOLEAN bEvenPermanents) { if(IsAddressValid(p->ulAddress) && p->bVirtual==FALSE) { + BOOLEAN isWriteable; + if( !( isWriteable = IsAddressWriteable(p->ulAddress) ) ) + SetAddressWriteable(p->ulAddress,TRUE); *(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode; + if( !isWriteable ) + SetAddressWriteable(p->ulAddress,FALSE); bResult = TRUE; } PICE_memset(p,0,sizeof(*p)); @@ -458,7 +494,12 @@ BOOLEAN RemoveAllSWBreakpoints(BOOLEAN bEvenPermanents) { if(IsAddressValid(p->ulAddress) && p->bVirtual==FALSE) { + BOOLEAN isWriteable; + if( !( isWriteable = IsAddressWriteable(p->ulAddress) ) ) + SetAddressWriteable(p->ulAddress,TRUE); *(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode; + if( !isWriteable ) + SetAddressWriteable(p->ulAddress,FALSE); bResult = TRUE; } PICE_memset(p,0,sizeof(*p)); @@ -583,8 +624,13 @@ void RevirtualizeBreakpointsForModule(PDEBUG_MODULE pMod) p->bVirtual = TRUE; if(IsAddressValid(p->ulAddress) ) { + BOOLEAN isWriteable; + if( !( isWriteable = IsAddressWriteable(p->ulAddress) ) ) + SetAddressWriteable(p->ulAddress,TRUE); DPRINT((0,"RevirtualizeBreakpointsForModule(): restoring original opcode @ %x\n",p->ulAddress)); *(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode; + if( !isWriteable ) + SetAddressWriteable(p->ulAddress,FALSE); } else { diff --git a/reactos/apps/utils/pice/module/debug.c b/reactos/apps/utils/pice/module/debug.c index e33e266d0d4..f2eed6208cd 100644 --- a/reactos/apps/utils/pice/module/debug.c +++ b/reactos/apps/utils/pice/module/debug.c @@ -51,6 +51,7 @@ ULONG ulDebugFlags; char tempDebug[2048]; USHORT usDebugPortBase; +extern BOOLEAN bIsPrintkPatched; //////////////////////////////////////////////////// // FUNCTIONS //// @@ -74,6 +75,7 @@ VOID Pice_dprintf(ULONG DebugLevel, PCHAR DebugMessage, ...) PICE_vsprintf(tempDebug, DebugMessage, ap); //ei DebugSendString(tempDebug); Print(OUTPUT_WINDOW, tempDebug); + DbgPrint("%s", tempDebug); restore_flags(ulDebugFlags); } va_end(ap); @@ -179,10 +181,11 @@ void DebugSetOthers(ULONG Parity, ULONG Bits, ULONG StopBit) void DebugSetupSerial(ULONG port,ULONG baudrate) { USHORT ports[]={COM1BASE,COM2BASE}; - +#if 0 //ei temporary usDebugPortBase = ports[port-1]; DebugSetOthers(NO_PARITY,8,1); DebugSetSpeed(baudrate); +#endif } #endif // DEBUG diff --git a/reactos/apps/utils/pice/module/init.c b/reactos/apps/utils/pice/module/init.c index 9e168312ebe..c6136276c45 100644 --- a/reactos/apps/utils/pice/module/init.c +++ b/reactos/apps/utils/pice/module/init.c @@ -48,6 +48,7 @@ PMADDRESS_SPACE mm_init_mm; ULONG KeyboardIRQL; +extern void NewInt31Handler(void); //************************************************************************* // InitPICE() // @@ -100,7 +101,7 @@ BOOLEAN InitPICE(void) DPRINT((0,"InitPICE(): trace step 4\n")); // print the initial screen template PrintTemplate(); - +/* DPRINT((0,"InitPICE(): trace step 5\n")); // ask the user if he wants to abort the debugger load if(!CheckLoadAbort()) @@ -111,7 +112,7 @@ BOOLEAN InitPICE(void) LEAVE_FUNC(); return FALSE; } - +*/ DPRINT((0,"InitPICE(): trace step 6\n")); // load the file /boot/System.map. // !!! It must be consistent with the current kernel at all cost!!! @@ -128,7 +129,7 @@ BOOLEAN InitPICE(void) DPRINT((0,"InitPICE(): trace step 7\n")); ScanExports("_KernelAddressSpace", &ulAddr); - my_init_mm = ulAddr; + my_init_mm = (PEPROCESS) ulAddr; DPRINT((0,"init_mm %x @ %x\n",&my_init_mm,my_init_mm)); if(!my_init_mm) { @@ -146,7 +147,7 @@ BOOLEAN InitPICE(void) DPRINT((0,"InitPICE(): trace step 7.1\n")); ScanExports("_PsProcessListHead",&ulAddr); - pPsProcessListHead = ulAddr; + pPsProcessListHead = (LIST_ENTRY*)ulAddr; DPRINT((0,"pPsProcessListHead @ %X\n",pPsProcessListHead)); if(!pPsProcessListHead) { @@ -180,7 +181,7 @@ BOOLEAN InitPICE(void) // the loaded module list ScanExports("_NameSpaceRoot", &ulAddr); - pNameSpaceRoot = ulAddr; + pNameSpaceRoot = (PDIRECTORY_OBJECT *)ulAddr; DPRINT((0,"pNameSpaceRoot @ %X\n",pNameSpaceRoot)); if(!pNameSpaceRoot) { @@ -278,10 +279,11 @@ BOOLEAN InitPICE(void) InstallGlobalKeyboardHook(); InstallSyscallHook(); InstallInt3Hook(); - InstallPrintkHook(); InstallDblFltHook(); InstallGPFaultHook(); InstallIntEHook(); + //__asm__("int3"); + InstallPrintkHook(); DPRINT((0,"InitPICE(): trace step 16\n")); if(ulDoInitialBreak) diff --git a/reactos/apps/utils/pice/module/output.c b/reactos/apps/utils/pice/module/output.c index 40d2dbeaa71..dba9203e863 100644 --- a/reactos/apps/utils/pice/module/output.c +++ b/reactos/apps/utils/pice/module/output.c @@ -47,9 +47,13 @@ Copyright notice: char tempOutput[1024],tempOutput2[1024]; -ULONG ulPrintk=0; +//ULONG ulPrintk=0; + +ULONG (*ulPrintk) (PANSI_STRING String); + BOOLEAN bInPrintk = FALSE; BOOLEAN bIsDebugPrint = FALSE; +BOOLEAN bIsPrintkPatched = FALSE; ULONG ulCountTimerEvents = 0; @@ -126,10 +130,20 @@ ULONG CountArgs(LPSTR fmt) return count; } +//*********************************************************************************** +// Our replacement of kernel function. +// Must not make any calls to KdpPrintString (e.g. by calling DbgPrint). +//*********************************************************************************** +ULONG PICE_KdpPrintString(PANSI_STRING String) +{ + //dummy function + DPRINT((0,"PICE_KdpPrintString\n\n\n")); +} //************************************************************************* // PrintkCallback() // // called from RealIsr() when processing INT3 placed +// Must not make any calls to KdpPrintString (e.g. by calling DbgPrint). //************************************************************************* void PrintkCallback(void) { @@ -138,55 +152,26 @@ void PrintkCallback(void) ULONG countArgs,i,len; PANSI_STRING temp; + DPRINT((2,"In PrintkCallback:1\n")); + bInPrintk = TRUE; + DPRINT((2,"In PrintkCallback:2\n")); // get the linear address of stack where string resides ulAddress = GetLinearAddress(CurrentSS,CurrentESP); if(ulAddress) { + DPRINT((2,"In PrintkCallback: ulAddress: %x\n", ulAddress)); if(IsAddressValid(ulAddress+sizeof(char *)) ) { //KdpPrintString has PANSI_STRING as a parameter temp = (PANSI_STRING)*(PULONG)(ulAddress+sizeof(char *)); + DPRINT((2,"temp: %x\n", temp)); fmt = temp->Buffer; - // validate format string - if((len = PICE_strlen(fmt)) ) - { - // skip debug prefix if present - if(len>=3 && *fmt=='<' && *(fmt+2)=='>') - fmt += 3; - - if((countArgs = CountArgs(fmt))>0) - { - - args = (LPSTR)(ulAddress+2*sizeof(char *)); - if(IsAddressValid((ULONG)args)) - { - // validate passed in args - for(i=0;iValue[0], - (pPage->PTBase<<12)|(pArgs->Value[0]&(PAGE_SIZE-1)), + (pPage->PTBase<<12)|(pArgs->Value[0]&(_PAGE_SIZE-1)), (pPage->P==1)?"P ":"NP", pPage->RW?"RW":"R ", pPage->US?"U":"S", @@ -1313,7 +1313,7 @@ void DisplaySourceFile(LPSTR pSrcLine,LPSTR pSrcEnd,ULONG ulLineNumber,ULONG ulL LPSTR pTemp; ULONG j = ulLineNumber-1; - DPRINT((2,"DisplaySourceFile(%.8X,%u,%u)\n",pSrcLine,ulLineNumber,ulLineNumberToInvert)); + DPRINT((0,"DisplaySourceFile(%.8X,%u,%u)\n",pSrcLine,ulLineNumber,ulLineNumberToInvert)); // go to line while(j--) @@ -1411,16 +1411,16 @@ void UnassembleOneLineDown(void) { ULONG addr,addrorg; - DPRINT((2,"UnassembleOneLineDown()\n")); + DPRINT((0,"UnassembleOneLineDown()\n")); addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset); - DPRINT((2,"UnassembleOneLineDown(): addr = %.8X\n",addr)); + DPRINT((0,"UnassembleOneLineDown(): addr = %.8X\n",addr)); tempCmd[0]=0; Disasm(&addr,tempCmd); - DPRINT((2,"UnassembleOneLineDown(): addr after = %.8X\n",addr)); + DPRINT((0,"UnassembleOneLineDown(): addr after = %.8X\n",addr)); ulOldDisasmOffset += (addr - addrorg); RepaintSource(); @@ -1434,17 +1434,17 @@ void UnassembleOnePageDown(ULONG page) { ULONG addr,addrorg,i; - DPRINT((2,"UnassembleOnePageDown()\n")); + DPRINT((0,"UnassembleOnePageDown()\n")); addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset); - DPRINT((2,"UnassembleOnePageDown(): addr = %.8X\n",addr)); + DPRINT((0,"UnassembleOnePageDown(): addr = %.8X\n",addr)); tempCmd[0]=0; for(i=0;iname = %S\n",pCurrentMod->name)); + DPRINT((0,"Unassemble(): pCurrentMod->name = %S\n",pCurrentMod->name)); mod_addr = (ULONG)pCurrentMod->BaseAddress; pCurrentSymbols = FindModuleSymbols(mod_addr); - DPRINT((2,"Unassemble(): pCurrentSymbols = %x\n",(ULONG)pCurrentSymbols)); + DPRINT((0,"Unassemble(): pCurrentSymbols = %x\n",(ULONG)pCurrentSymbols)); } - DPRINT((2,"Unassemble(): pCurrentMod = %x, showsrc: %d\n",pCurrentMod, bShowSrc)); + DPRINT((0,"Unassemble(): pCurrentMod = %x, showsrc: %d\n",pCurrentMod, bShowSrc)); ulCurrentlyDisplayedLineNumber = 0; if(bShowSrc && bForceDisassembly == FALSE && (pSrc = FindSourceLineForAddress(addr,&ulLineNumber,&pSrcStart,&pSrcEnd,&pFilename)) ) { - DPRINT((2,"\n\n\nFoundSourceLineForAddress: file: %s line: %d\n", pFilename, ulLineNumber)); + DPRINT((0,"FoundSourceLineForAddress: file: %s line: %d\n", pFilename, ulLineNumber)); PICE_strcpy(szCurrentFile,pFilename); ulCurrentlyDisplayedLineNumber = ulLineNumber; @@ -1711,7 +1711,7 @@ COMMAND_PROTOTYPE(Unassemble) else { *szCurrentFile = 0; - DPRINT((2,"Couldn't find source for file\n")); + DPRINT((0,"Couldn't find source for file\n")); Home(SOURCE_WINDOW); // for each line in the disassembly window for(i=0;iname); pCurrentSymbols = (PICE_SYMBOLFILE_HEADER*)pArgs->Value[0]; + DPRINT((2,"TableSwitchSym: pCurrentSymbols: %x, Name: %S\n", pCurrentSymbols, pCurrentSymbols->name)); pTempMod = IsModuleLoaded(temp); if( pTempMod ) pCurrentMod = pTempMod; @@ -2611,8 +2612,10 @@ COMMAND_PROTOTYPE(ShowLocals) if(pArgs->Count==0) { p = FindLocalsByAddress(GetLinearAddress(CurrentCS,CurrentEIP)); + DPRINT((0,"ShowLocals: %x", p)); if(p) { + DPRINT((0,"ShowLocals: name %s, type_name %s\n", p->name, p->type_name)); while(PICE_strlen(p->name)) { if(!p->bRegister) diff --git a/reactos/apps/utils/pice/module/patch.c b/reactos/apps/utils/pice/module/patch.c index 156946fb664..12357abe386 100644 --- a/reactos/apps/utils/pice/module/patch.c +++ b/reactos/apps/utils/pice/module/patch.c @@ -88,18 +88,27 @@ BOOLEAN PiceKbdIsr ( if(isDown) { - DbgPrint("bControl: %x, ucKey: %x, breakkey: %x\n", bControl, ucKey, AsciiToScan(ucBreakKey)); + DPRINT((2,"bControl: %x, ucKey: %x, breakkey: %x\n", bControl, ucKey, AsciiToScan(ucBreakKey))); // CTRL pressed if(ucKey==0x1d) { bControl=TRUE; } - if(bControl==TRUE && ucKey==AsciiToScan(ucBreakKey)) // CTRL-D + else if(bControl==TRUE && ucKey==AsciiToScan(ucBreakKey)) // CTRL-D { // fake a CTRL-D release call bForward=FALSE; bEnterNow=TRUE; bControl=FALSE; + // simulate an initial break + __asm__(" + pushfl + pushl %cs + pushl $returnpoint + pushl $" STR(REASON_CTRLF) " + jmp NewInt31Handler + returnpoint:"); + } else if((ucKey == 66|| ucKey == 68) && bStepping) { diff --git a/reactos/apps/utils/pice/module/pgflt.c b/reactos/apps/utils/pice/module/pgflt.c index ca750764c49..7012e340c18 100644 --- a/reactos/apps/utils/pice/module/pgflt.c +++ b/reactos/apps/utils/pice/module/pgflt.c @@ -151,11 +151,15 @@ ULONG HandlePageFault(FRAME* ptr) PLIST_ENTRY current_entry; MEMORY_AREA* current; + //for some reason stack is corrupted. disable for now. + return 0; + // get linear address of page fault __asm__("movl %%cr2,%0":"=r" (address)); // current process tsk = IoGetCurrentProcess(); + DPRINT((2,"\nPageFault: Name: %s, bInDebShell: %d, error: %d, addr: %x\n", tsk->ImageFileName, bInDebuggerShell, ptr->error_code, address)); // there's something terribly wrong if we get a fault in our command handler if(bInDebuggerShell) @@ -182,35 +186,67 @@ ULONG HandlePageFault(FRAME* ptr) current = CONTAINING_RECORD(current_entry, MEMORY_AREA, Entry); + DPRINT((2,"address: %x %x - %x Attrib: %x, Type: %x\n", address, current->BaseAddress, current->BaseAddress + current->Length, current->Attributes, current->Type)); + return 0; if( (address >= current->BaseAddress) && (address <= current->BaseAddress + current->Length )) { - if(error_code & 2) - { - // area was not writable - if(!(current->Attributes & PAGE_READONLY)) - { - Print(OUTPUT_WINDOW,"pICE: virtual memory arena is not writeable!\n"); - return 1; - } - } - // READ ACCESS - else - { - // test EXT bit in error code - if (error_code & 1) - { - Print(OUTPUT_WINDOW,"pICE: page-level protection fault!\n"); - return 1; - } - // - if (!(current->Attributes & PAGE_EXECUTE_READ)) - { - Print(OUTPUT_WINDOW,"pICE: VMA is not readable!\n"); - return 1; - } - } - // let the system handle it - return 0; + //page not present + if( !(error_code & 1) ){ + //check it is in pageable area + if( current->Type == MEMORY_AREA_SECTION_VIEW_COMMIT || + current->Type == MEMORY_AREA_SECTION_VIEW_RESERVE || + current->Type == MEMORY_AREA_VIRTUAL_MEMORY || + current->Type == MEMORY_AREA_PAGED_POOL + ){ + Print(OUTPUT_WINDOW,"pICE: VMA Pageable Section.\n"); + return 0; //let the system handle this + } + Print(OUTPUT_WINDOW,"pICE: VMA Page not present in non-pageable Section!\n"); + return 1; + } + else{ //access violation + + if( error_code & 4 ) + { //user mode + if( (ULONG)address >= KERNEL_BASE ) + { + Print(OUTPUT_WINDOW,"pICE: User mode program trying to access kernel memory!\n"); + return 1; + } + return 0; + } + /* + if(error_code & 2) + { + //on write + if(!(current->Attributes & PAGE_READONLY)) + { + Print(OUTPUT_WINDOW,"pICE: virtual memory arena is not writeable!\n"); + return 1; + } + } + // READ ACCESS + else + { + // test EXT bit in error code + if (error_code & 1) + { + Print(OUTPUT_WINDOW,"pICE: page-level protection fault!\n"); + return 1; + } + // + */ + /* + if (!(current->Attributes & PAGE_EXECUTE_READ)) + { + Print(OUTPUT_WINDOW,"pICE: VMA is not readable!\n"); + return 1; + } + */ + + // let the system handle it + return 0; + } } current_entry = current_entry->Flink; } @@ -301,7 +337,7 @@ void InstallIntEHook(void) OldIntEHandler=SetGlobalInt(0x0E,(ULONG)LocalIntEHandler); } UnmaskIrqs(); - + DPRINT((2,"OldIntE @ %x\n", OldIntEHandler)); LEAVE_FUNC(); } diff --git a/reactos/apps/utils/pice/module/serial.c b/reactos/apps/utils/pice/module/serial.c index eeb64ec264d..3998492eae7 100644 --- a/reactos/apps/utils/pice/module/serial.c +++ b/reactos/apps/utils/pice/module/serial.c @@ -50,10 +50,10 @@ PUCHAR pScreenBufferSerial; USHORT usSerialPortBase; -UCHAR packet[PAGE_SIZE]; -UCHAR assemble_packet[PAGE_SIZE]; +UCHAR packet[_PAGE_SIZE]; +UCHAR assemble_packet[_PAGE_SIZE]; -UCHAR flush_buffer[PAGE_SIZE],g_x,g_y; +UCHAR flush_buffer[_PAGE_SIZE],g_x,g_y; ULONG ulFlushBufferPos = 0; UCHAR ucLastKeyRead; diff --git a/reactos/apps/utils/pice/module/shell.c b/reactos/apps/utils/pice/module/shell.c index 3eb344edc47..acb1ea000f8 100644 --- a/reactos/apps/utils/pice/module/shell.c +++ b/reactos/apps/utils/pice/module/shell.c @@ -323,9 +323,9 @@ void DebuggerShell(void) CheckRingBuffer(); // kill the speakers annoying beep - speaker = inb_p(0x61); + speaker = inb_p((PCHAR)0x61); speaker &= 0xFC; - outb_p(speaker,0x61); + outb_p(speaker,(PCHAR)0x61); ProcessBootParams(); @@ -1038,16 +1038,19 @@ void RealIsr(ULONG dwReasonForBreak) bIrqStateAtBreak = ((CurrentEFL&(1<<9))!=0); + DPRINT((2,"\nbInDebuggerShell %x, dwReasonForBreak: %x, bIrqStateAtBreak: %d\n", bInDebuggerShell, dwReasonForBreak, bIrqStateAtBreak)); + DPRINT((2,"CurrentEIP: %x, CurrentESP: %x\n", CurrentEIP, CurrentESP)); + // came in because TF flag was set if(dwReasonForBreak == REASON_SINGLESTEP) { ULONG ulAddress,ulAddressCurrent; - DPRINT((0,"REASON_SINGLESTEP\n")); + DPRINT((2,"REASON_SINGLESTEP\n")); if(!bSingleStep) { - DPRINT((0,"no single step requested!\n")); + DPRINT((2,"no single step requested!\n")); dwCallOldInt1Handler = 1; goto common_return_point; } @@ -1060,7 +1063,7 @@ void RealIsr(ULONG dwReasonForBreak) // simply restart the system. if(NeedToReInstallSWBreakpoints(ulAddress,TRUE) ) { - DPRINT((0,"reinstalling INT3 @ %.4X:%.8X\n",OldCS,OldEIP)); + DPRINT((2,"reinstalling INT3 @ %.4X:%.8X\n",OldCS,OldEIP)); ReInstallSWBreakpoint(ulAddress); @@ -1079,7 +1082,7 @@ void RealIsr(ULONG dwReasonForBreak) } LEAVE_FUNC(); - DPRINT((0,"-----------------------------------------------------------------\n")); + DPRINT((2,"-----------------------------------------------------------------\n")); return; } bPreviousCommandWasGo = FALSE; @@ -1094,7 +1097,7 @@ void RealIsr(ULONG dwReasonForBreak) ULONG ulLineNumber; LPSTR pSrc,pFileName; - DPRINT((0,"RealIsr(): stepping through source!\n")); + DPRINT((2,"RealIsr(): stepping through source!\n")); // look up the corresponding source line // if there isn't any or the source line number has changed @@ -1103,12 +1106,12 @@ void RealIsr(ULONG dwReasonForBreak) pSrc = FindSourceLineForAddress(ulAddressCurrent,&ulLineNumber,NULL,NULL,&pFileName); else pSrc = NULL; - DPRINT((0,"RealIsr(): line #%u pSrc=%x (old line #%u)\n",ulLineNumber,(ULONG)pSrc,g_ulLineNumberStart)); + DPRINT((2,"RealIsr(): line #%u pSrc=%x (old line #%u)\n",ulLineNumber,(ULONG)pSrc,g_ulLineNumberStart)); // if we have found a source line there if(pSrc && ulLineNumber==g_ulLineNumberStart) { - DPRINT((0,"RealIsr(): stepping through line #%u in file = %s!\n",ulLineNumber,pFileName)); + DPRINT((2,"RealIsr(): stepping through line #%u in file = %s!\n",ulLineNumber,pFileName)); if(bStepInto) StepInto(NULL); @@ -1117,7 +1120,7 @@ void RealIsr(ULONG dwReasonForBreak) bInDebuggerShell = FALSE; LEAVE_FUNC(); - DPRINT((0,"-----------------------------------------------------------------\n")); + DPRINT((2,"-----------------------------------------------------------------\n")); return; } bStepThroughSource = FALSE; @@ -1130,7 +1133,7 @@ void RealIsr(ULONG dwReasonForBreak) { ULONG ulReason; - DPRINT((0,"REASON_HARDWARE_BP\n")); + DPRINT((2,"REASON_HARDWARE_BP\n")); // disable HW breakpoints __asm__(" @@ -1144,7 +1147,7 @@ void RealIsr(ULONG dwReasonForBreak) :"eax" ); - DPRINT((0,"REASON_HARDWARE_BP: %x\n",(ulReason&0xF))); + DPRINT((2,"REASON_HARDWARE_BP: %x\n",(ulReason&0xF))); // HW breakpoint DR1 (skip: only used in init_module detection) if(ulReason&0x2) @@ -1178,12 +1181,12 @@ void RealIsr(ULONG dwReasonForBreak) else pSrc = NULL; - DPRINT((0,"RealIsr(): line #%u pSrc=%x (old line #%u) [2]\n",ulLineNumber,(ULONG)pSrc,g_ulLineNumberStart)); + DPRINT((2,"RealIsr(): line #%u pSrc=%x (old line #%u) [2]\n",ulLineNumber,(ULONG)pSrc,g_ulLineNumberStart)); // if we have found a source line there if(pSrc && ulLineNumber==g_ulLineNumberStart) { - DPRINT((0,"RealIsr(): stepping through line #%u in file = %s! [2]\n",ulLineNumber,pFileName)); + DPRINT((2,"RealIsr(): stepping through line #%u in file = %s! [2]\n",ulLineNumber,pFileName)); if(bStepInto) StepInto(NULL); @@ -1205,7 +1208,7 @@ void RealIsr(ULONG dwReasonForBreak) { ULONG ulAddress; - DPRINT((0,"REASON_INT3\n")); + DPRINT((2,"REASON_INT3\n")); // must subtract one cause INT3s are generated after instructions execution CurrentEIP--; @@ -1213,26 +1216,26 @@ void RealIsr(ULONG dwReasonForBreak) // make a flat address ulAddress = GetLinearAddress(CurrentCS,CurrentEIP); - DPRINT((0,"INT3 @ %.8X\n",ulAddress)); + DPRINT((2,"INT3 @ %.8X\n",ulAddress)); // if there's a breakpoint installed at current EIP remove it if(DeInstallSWBreakpoint(ulAddress) ) { PSW_BP p; - DPRINT((0,"INT3 @ %.8X removed\n",ulAddress)); + DPRINT((2,"INT3 @ %.8X removed\n",ulAddress)); // if it's permanent (must be Printk() ) skip the DebuggerShell() and // do a callback if( (p = IsPermanentSWBreakpoint(ulAddress)) ) { - DPRINT((0,"permanent breakpoint\n")); + DPRINT((2,"permanent breakpoint\n")); OldCS = CurrentCS; OldEIP = CurrentEIP; bSkipMainLoop = TRUE; - + DPRINT((2,"callback at %x\n",p->Callback)); if(p->Callback) p->Callback(); } @@ -1256,6 +1259,9 @@ void RealIsr(ULONG dwReasonForBreak) LPSTR pFind; PEPROCESS my_current = IoGetCurrentProcess(); + DPRINT((2,"can't deinstall, somebody else's breakpoint\n")); + + // if no other debugger is running on this process and the address is // above TASK_SIZE we assume this to be a hard embedded INT3 /* @@ -1316,7 +1322,7 @@ void RealIsr(ULONG dwReasonForBreak) { LPSTR pSymbolName; - DPRINT((0,"REASON_PAGEFAULT\n")); + DPRINT((2,"REASON_PAGEFAULT\n")); if( ScanExportsByAddress(&pSymbolName,GetLinearAddress(CurrentCS,CurrentEIP)) ) { @@ -1335,7 +1341,7 @@ void RealIsr(ULONG dwReasonForBreak) { LPSTR pSymbolName; - DPRINT((0,"REASON_GPFAULT\n")); + DPRINT((2,"REASON_GPFAULT\n")); if( ScanExportsByAddress(&pSymbolName,GetLinearAddress(CurrentCS,CurrentEIP)) ) { @@ -1350,19 +1356,19 @@ void RealIsr(ULONG dwReasonForBreak) } else if(dwReasonForBreak == REASON_CTRLF) { - DPRINT((0,"REASON_CTRLF\n")); + DPRINT((2,"REASON_CTRLF\n")); // nothing to do } else if(dwReasonForBreak == REASON_DOUBLE_FAULT) { - DPRINT((0,"REASON_DOUBLE_FAULT\n")); + DPRINT((2,"REASON_DOUBLE_FAULT\n")); PICE_sprintf(tempShell,"pICE: Breakpoint due to double fault at %.4X:%.8X\n",CurrentCS,CurrentEIP); Print(OUTPUT_WINDOW,tempShell); } else if(dwReasonForBreak == REASON_INTERNAL_ERROR) { - DPRINT((0,"REASON_INTERNAL_ERROR\n")); + DPRINT((2,"REASON_INTERNAL_ERROR\n")); Print(OUTPUT_WINDOW,"pICE: Please report this error to klauspg@diamondmm.com!\n"); // Print(OUTPUT_WINDOW,"pICE: !!! SYSTEM HALTED !!!\n"); @@ -1370,7 +1376,7 @@ void RealIsr(ULONG dwReasonForBreak) } else { - DPRINT((0,"REASON_UNKNOWN\n")); + DPRINT((2,"REASON_UNKNOWN\n")); PICE_sprintf(tempShell,"pICE: Breakpoint due to unknown reason at %.4X:%.8X (code %x)\n",CurrentCS,CurrentEIP,dwReasonForBreak); Print(OUTPUT_WINDOW,tempShell); @@ -1380,13 +1386,13 @@ void RealIsr(ULONG dwReasonForBreak) } // we don't single-step yet - DPRINT((0,"RealIsr(): not stepping yet\n")); + DPRINT((2,"RealIsr(): not stepping yet\n")); bSingleStep=FALSE; // process commands if(bSkipMainLoop == FALSE) { - DPRINT((0,"RealIsr(): saving registers\n")); + DPRINT((2,"RealIsr(): saving registers\n")); // save the extended regs __asm__ __volatile__ (" @@ -1418,17 +1424,17 @@ void RealIsr(ULONG dwReasonForBreak) popl %eax" ); - DPRINT((0,"RealIsr(): adding colon to output()\n")); + DPRINT((2,"RealIsr(): adding colon to output()\n")); Print(OUTPUT_WINDOW,":"); - DPRINT((0,"RealIsr(): calling DebuggerShell()\n")); + DPRINT((2,"RealIsr(): calling DebuggerShell()\n")); DebuggerShell(); } // if there was a SW breakpoint at CS:EIP if(NeedToReInstallSWBreakpoints(GetLinearAddress(CurrentCS,CurrentEIP),TRUE)) { - DPRINT((0,"need to reinstall INT3\n")); + DPRINT((2,"need to reinstall INT3\n")); // remember how we restarted last time bPreviousCommandWasGo = !bSingleStep; // do a single step to reinstall breakpoint @@ -1449,7 +1455,7 @@ common_return_point: bInDebuggerShell = FALSE; LEAVE_FUNC(); - DPRINT((0,"-----------------------------------------------------------------\n")); + DPRINT((2,"common return-----------------------------------------------------------------\n")); } __asm__(".global NewInt31Handler @@ -1560,7 +1566,7 @@ afterswitch: // restore EAX popl %eax - // do we need to call old INT1 handler + // do we need to call old INT1 handler .byte 0x2e cmp $0,_dwCallOldInt1Handler je do_iret2 @@ -1604,6 +1610,8 @@ do_iret3: jmp *_OldGPFaultHandler do_iret: + //ei + //int3 iretl "); // diff --git a/reactos/apps/utils/pice/module/symbols.c b/reactos/apps/utils/pice/module/symbols.c index 36daf17780b..ed7fd4cdcf2 100644 --- a/reactos/apps/utils/pice/module/symbols.c +++ b/reactos/apps/utils/pice/module/symbols.c @@ -53,7 +53,7 @@ LOCAL_VARIABLE local_vars[512]; PICE_SYMBOLFILE_HEADER* apSymbols[32]={NULL,}; ULONG ulNumSymbolsLoaded=0; -//ULONG kernel_end=0; +ULONG kernel_end=0; char tempSym[1024]; // temp buffer for output @@ -231,14 +231,13 @@ BOOLEAN ListDriverModules( void ) PICE_wcscpy( pdebug_module_tail->name, pm->BaseName.Buffer); pdebug_module_tail = pdebug_module_tail->next; - /* - if (_wcsicmp(current_obj->Name.Buffer, "Modules")==0) + + if (_wcsicmp(pm->BaseName.Buffer, L"ntoskrnl")==0 && pm) { - DbgPrint("Found it %x\n",HEADER_TO_BODY(current_obj)); - pd=HEADER_TO_BODY(current_obj); - } - */ - current = current->Flink; + kernel_end = (ULONG)pm->Base + pm->Length; + } + + current = current->Flink; } } @@ -594,104 +593,107 @@ BOOLEAN ScanExportsByAddress(LPSTR *pFind,ULONG ulValue) ENTER_FUNC(); pSymbols = FindModuleSymbols(ulValue); - if(pSymbols && pdebug_module_head) - { - PDEBUG_MODULE pdTemp; + if(BuildModuleList()){ + if(pSymbols && pdebug_module_head) + { + PDEBUG_MODULE pdTemp; - DPRINT((0,"looking up symbols\n")); - pd = pdebug_module_head; - do - { - ASSERT(pd->size); + DPRINT((0,"looking up symbols\n")); + pd = pdebug_module_head; + do + { + if(pd->size){ + pdTemp = pd; - pdTemp = pd; - - if(ulValue>=((ULONG)pdTemp->BaseAddress) && ulValue<((ULONG)pdTemp+pdTemp->size)) - { - if(PICE_wcsicmp(pdTemp->name,pSymbols->name) == 0) - { - DPRINT((0,"ScanExportsByAddress(): found symbols for module %S @ %x \n",pdTemp->name,(ULONG)pSymbols)); - - pSym = (PIMAGE_SYMBOL)((ULONG)pSymbols+pSymbols->ulOffsetToGlobals); - pSymEnd = (PIMAGE_SYMBOL)((ULONG)pSym+pSymbols->ulSizeOfGlobals); - pStr = (LPSTR)((ULONG)pSymbols+pSymbols->ulOffsetToGlobalsStrings); - pShdr = (PIMAGE_SECTION_HEADER)((ULONG)pSymbols+pSymbols->ulOffsetToHeaders); - - if(!IsRangeValid((ULONG)pSym,sizeof(IMAGE_SYMBOL) ) ) //should we actually check all the symbols here? + if(ulValue>=((ULONG)pdTemp->BaseAddress) && ulValue<((ULONG)pdTemp+pdTemp->size)) { - DPRINT((0,"ScanExportsByAddress(): pSym = %x is not a valid pointer\n",(ULONG)pSym)); - return FALSE; - } - - DPRINT((0,"ScanExportsByAddress(): pSym = %x\n",pSym)); - DPRINT((0,"ScanExportsByAddress(): pStr = %x\n",pStr)); - DPRINT((0,"ScanExportsByAddress(): pShdr = %x\n",pShdr)); - - DPRINT((0,"ScanExportsByAddress(): %S has %u symbols\n",pSymbols->name,pSymbols->ulSizeOfGlobals/sizeof(IMAGE_SYMBOL))); - - /* go through all the global symbols and find the one with - the largest address which is less than ulValue */ - while(pSym < pSymEnd) - { //it seems only 0x0 and 0x20 are used for type and External or Static storage classes - if(((pSym->Type == 0x0) || (pSym->Type == 0x20) ) && - ((pSym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) || (pSym->StorageClass==IMAGE_SYM_CLASS_STATIC)) && - (pSym->SectionNumber > 0 )) + if(PICE_wcsicmp(pdTemp->name,pSymbols->name) == 0) { - ULONG ulCurrAddr; - PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1); + DPRINT((0,"ScanExportsByAddress(): found symbols for module %S @ %x \n",pdTemp->name,(ULONG)pSymbols)); + pSym = (PIMAGE_SYMBOL)((ULONG)pSymbols+pSymbols->ulOffsetToGlobals); + pSymEnd = (PIMAGE_SYMBOL)((ULONG)pSym+pSymbols->ulSizeOfGlobals); + pStr = (LPSTR)((ULONG)pSymbols+pSymbols->ulOffsetToGlobalsStrings); + pShdr = (PIMAGE_SECTION_HEADER)((ULONG)pSymbols+pSymbols->ulOffsetToHeaders); - DPRINT((0,"ScanExportsByAddress(): pShdr[%x] = %x\n",pSym->SectionNumber,(ULONG)pShdrThis)); - - if(!IsRangeValid((ULONG)pShdrThis,sizeof(IMAGE_SECTION_HEADER)) ) + if(!IsRangeValid((ULONG)pSym,sizeof(IMAGE_SYMBOL) ) ) //should we actually check all the symbols here? { - DPRINT((0,"ScanExportsByAddress(): pElfShdr[%x] = %x is not a valid pointer\n",pSym->SectionNumber,(ULONG)pShdrThis)); + DPRINT((0,"ScanExportsByAddress(): pSym = %x is not a valid pointer\n",(ULONG)pSym)); return FALSE; } - //to get address in the memory we base address of the module and - //add offset of the section and then add offset of the symbol from - //the begining of the section - ulCurrAddr = ((ULONG)pdTemp->BaseAddress+pShdrThis->VirtualAddress+pSym->Value); - DPRINT((0,"ScanExportsByAddress(): CurrAddr [1] = %x\n",ulCurrAddr)); - if(ulCurrAddr<=ulValue && ulCurrAddr>ulAddr) - { - ulAddr = ulCurrAddr; - pFoundSym = pSym; + DPRINT((0,"ScanExportsByAddress(): pSym = %x\n",pSym)); + DPRINT((0,"ScanExportsByAddress(): pStr = %x\n",pStr)); + DPRINT((0,"ScanExportsByAddress(): pShdr = %x\n",pShdr)); + + DPRINT((0,"ScanExportsByAddress(): %S has %u symbols\n",pSymbols->name,pSymbols->ulSizeOfGlobals/sizeof(IMAGE_SYMBOL))); + + /* go through all the global symbols and find the one with + the largest address which is less than ulValue */ + while(pSym < pSymEnd) + { //it seems only 0x0 and 0x20 are used for type and External or Static storage classes + if(((pSym->Type == 0x0) || (pSym->Type == 0x20) ) && + ((pSym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) || (pSym->StorageClass==IMAGE_SYM_CLASS_STATIC)) && + (pSym->SectionNumber > 0 )) + { + ULONG ulCurrAddr; + PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1); + + + DPRINT((0,"ScanExportsByAddress(): pShdr[%x] = %x\n",pSym->SectionNumber,(ULONG)pShdrThis)); + + if(!IsRangeValid((ULONG)pShdrThis,sizeof(IMAGE_SECTION_HEADER)) ) + { + DPRINT((0,"ScanExportsByAddress(): pElfShdr[%x] = %x is not a valid pointer\n",pSym->SectionNumber,(ULONG)pShdrThis)); + return FALSE; + } + //to get address in the memory we base address of the module and + //add offset of the section and then add offset of the symbol from + //the begining of the section + ulCurrAddr = ((ULONG)pdTemp->BaseAddress+pShdrThis->VirtualAddress+pSym->Value); + DPRINT((0,"ScanExportsByAddress(): CurrAddr [1] = %x\n",ulCurrAddr)); + + if(ulCurrAddr<=ulValue && ulCurrAddr>ulAddr) + { + ulAddr = ulCurrAddr; + pFoundSym = pSym; + } + } + //skip the auxiliary symbols and get the next symbol + pSym += pSym->NumberOfAuxSymbols + 1; } + *pFind = temp3; + if(0) + { + PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pFoundSym->SectionNumber-1); + //check that ulValue is below the limit for the section where best match is found + ASSERT(ulValue < ((ULONG)pdTemp->BaseAddress+pShdrThis->SizeOfRawData)); + } + if( pFoundSym->N.Name.Short ){ + pName = pFoundSym->N.ShortName; //name is in the header + PICE_sprintf(temp3,"%S!%.8s",pdTemp->name,pName); //if name is in the header it may be nonzero terminated + } + else{ + ASSERT(pFoundSym->N.Name.Long<=pSymbols->ulSizeOfGlobalsStrings); //sanity check + pName = pStr+pFoundSym->N.Name.Long; + if(!IsAddressValid((ULONG)pName)) + { + DPRINT((0,"ScanExportsByAddress(): pName = %x is not a valid pointer\n",pName)); + return FALSE; + } + PICE_sprintf(temp3,"%S!%s",pdTemp->name,pName); + } + DPRINT((0,"ScanExportsByAddress(): pName = %x\n",(ULONG)pName)); + return TRUE; } - //skip the auxiliary symbols and get the next symbol - pSym += pSym->NumberOfAuxSymbols + 1; } - *pFind = temp3; - { - PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pFoundSym->SectionNumber-1); - //check that ulValue is below the limit for the section where best match is found - ASSERT(ulValue < ((ULONG)pdTemp->BaseAddress+pShdrThis->SizeOfRawData)); - } - if( pFoundSym->N.Name.Short ){ - pName = pFoundSym->N.ShortName; //name is in the header - PICE_sprintf(temp3,"%S!%.8s",pdTemp->name,pName); //if name is in the header it may be nonzero terminated - } - else{ - ASSERT(pFoundSym->N.Name.Long<=pSymbols->ulSizeOfGlobalsStrings); //sanity check - pName = pStr+pFoundSym->N.Name.Long; - if(!IsAddressValid((ULONG)pName)) - { - DPRINT((0,"ScanExportsByAddress(): pName = %x is not a valid pointer\n",pName)); - return FALSE; - } - PICE_sprintf(temp3,"%S!%s",pdTemp->name,pName); - } - DPRINT((0,"ScanExportsByAddress(): pName = %x\n",(ULONG)pName)); - return TRUE; } - } - }while((pd = pd->next)); + }while((pd = pd->next)); + } } // if haven't found in the symbols try ntoskrnl exports. (note: check that this is needed since we // already checked ntoskrnl coff symbol table) - if(pExports /*&& ulValue >= TASK_SIZE && ulValue < kernel_end*/) + if(pExports && ulValue >= KERNEL_START && ulValue < kernel_end) { p = pExports; // while we bound in System.map @@ -1348,7 +1350,7 @@ PLOCAL_VARIABLE FindLocalsByAddress(ULONG addr) break; case N_LSYM: // if we're in the function we're looking for - if(szCurrentFunction[0] && PICE_strcmp(szCurrentFunction,pFunctionName)==0) + if(szCurrentFunction[0] && PICE_fncmp(szCurrentFunction,pFunctionName)==0) { DPRINT((0,"local variable %.8X %.8X %.8X %.8X %.8X %s\n",pStab->n_strx,pStab->n_type,pStab->n_other,pStab->n_desc,pStab->n_value,pName)); ulTypeNumber = ExtractTypeNumber(pName); @@ -1367,7 +1369,7 @@ PLOCAL_VARIABLE FindLocalsByAddress(ULONG addr) break; case N_PSYM: // if we're in the function we're looking for - if(szCurrentFunction[0] && PICE_strcmp(szCurrentFunction,pFunctionName)==0) + if(szCurrentFunction[0] && PICE_fncmp(szCurrentFunction,pFunctionName)==0) { DPRINT((0,"parameter variable %.8X %.8X %.8X %.8X %.8X %s\n",pStab->n_strx,pStab->n_type,pStab->n_other,pStab->n_desc,pStab->n_value,pName)); ulTypeNumber = ExtractTypeNumber(pName); @@ -1384,7 +1386,7 @@ PLOCAL_VARIABLE FindLocalsByAddress(ULONG addr) break; case N_RSYM: // if we're in the function we're looking for - if(szCurrentFunction[0] && PICE_strcmp(szCurrentFunction,pFunctionName)==0) + if(szCurrentFunction[0] && PICE_fncmp(szCurrentFunction,pFunctionName)==0) { DPRINT((0,"local variable %.8X %.8X %.8X %.8X %.8X %s\n",pStab->n_strx,pStab->n_type,pStab->n_other,pStab->n_desc,pStab->n_value,pName)); ulTypeNumber = ExtractTypeNumber(pName); @@ -1452,14 +1454,16 @@ LPSTR FindSourceLineForAddress(ULONG addr,PULONG pulLineNumber,LPSTR* ppSrcStart // lookup the functions name and start-end (external symbols) pFunctionName = FindFunctionByAddress(addr,&start,&end); - DPRINT((2,"FindSourceLineForAddress: %x\n", pFunctionName)); + DPRINT((0,"FindSourceLineForAddress: for function: %s\n", pFunctionName)); if(pFunctionName) { // lookup the modules symbol table (STABS) pSymbols = FindModuleSymbols(addr); + DPRINT((0,"FindSourceLineForAddress: pSymbols %x\n", pSymbols)); if(pSymbols) { + DPRINT((0,"FindSourceLineForAddress: pSymbols->ulNumberOfSrcFiles %x\n", pSymbols->ulNumberOfSrcFiles)); // no source files so we don't need to lookup anything if(!pSymbols->ulNumberOfSrcFiles) return NULL; @@ -1514,9 +1518,9 @@ LPSTR FindSourceLineForAddress(ULONG addr,PULONG pulLineNumber,LPSTR* ppSrcStart // line number case N_SLINE: // if we're in the function we're looking for - if(szCurrentFunction[0] && PICE_strcmp(szCurrentFunction,pFunctionName)==0) + if(szCurrentFunction[0] && PICE_fncmp(szCurrentFunction,pFunctionName)==0) { - //DPRINT((0,"code source line number #%u for addr. %x (function @ %x) ulMinValue = %x ulDelta = %x\n",pStab->n_desc,start+pStab->n_value,start,ulMinValue,(addr-(start+pStab->n_value)))); + DPRINT((0,"code source line number #%u for addr. %x (function @ %x) ulMinValue = %x ulDelta = %x\n",pStab->n_desc,start+pStab->n_value,start,ulMinValue,(addr-(start+pStab->n_value)))); if(bFirstOccurence) { @@ -1638,6 +1642,7 @@ LPSTR FindSourceLineForAddress(ULONG addr,PULONG pulLineNumber,LPSTR* ppSrcStart } } } + DPRINT((0,"FindSourceLineForAddress: exit 1\n")); return NULL; } @@ -1768,7 +1773,7 @@ ULONG ListSymbolStartingAt(PDEBUG_MODULE pMod,PICE_SYMBOLFILE_HEADER* pSymbols,U LPSTR pName; if(((pSym->Type == 0x0) || (pSym->Type == 0x20) ) && - ((pSym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) || (pSym->StorageClass==IMAGE_SYM_CLASS_STATIC)) && + ((pSym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) /*|| (pSym->StorageClass==IMAGE_SYM_CLASS_STATIC)*/) && (pSym->SectionNumber > 0 )) { PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1); @@ -1956,37 +1961,37 @@ PICE_SYMBOLFILE_HEADER* LoadSymbols(LPSTR filename) if( !( conv = PICE_MultiByteToWideChar(CP_ACP, NULL, filename, -1, tempstr, 256 ) ) ) { - DPRINT((0,"Can't convert module name.\n")); + DPRINT((2,"Can't convert module name.\n")); return NULL; } - DPRINT((0,"LoadSymbols: test %S, %s, tempstr %S, conv: %d\n",L"testing", filename, tempstr, conv)); + DPRINT((2,"LoadSymbols: filename %s, tempstr %S, conv: %d\n", filename, tempstr, conv)); if(ulNumSymbolsLoadedmagic = %X\n",pSymbols->magic)); + DPRINT((2,"LoadSymbols(): success reading symbols!\n")); + DPRINT((2,"LoadSymbols(): pSymbols->magic = %X\n",pSymbols->magic)); } //set_fs(oldfs); @@ -2017,7 +2022,7 @@ PICE_SYMBOLFILE_HEADER* LoadSymbols(LPSTR filename) } else { - DPRINT((0,"pICE: could not load symbols for %s...\n",filename)); + DPRINT((2,"pICE: could not load symbols for %s...\n",filename)); } } @@ -2178,7 +2183,7 @@ BOOLEAN LoadSymbolsFromConfig(BOOLEAN bIgnoreBootParams) { DPRINT((0,"Load symbols from file %s\n", temp)); pSymbols = LoadSymbols(temp); - DbgPrint("Load symbols from file %s, pSymbols: %x\n", temp, pSymbols); + DPRINT((2,"Load symbols from file %s, pSymbols: %x\n", temp, pSymbols)); if(pSymbols) { PICE_SYMBOLFILE_SOURCE* pSrc; diff --git a/reactos/apps/utils/pice/module/utils.c b/reactos/apps/utils/pice/module/utils.c index 85114ae8e61..986b90725f9 100644 --- a/reactos/apps/utils/pice/module/utils.c +++ b/reactos/apps/utils/pice/module/utils.c @@ -44,7 +44,7 @@ char tempFlowChanges[256]; //PMADDRESS_SPACE my_init_mm=NULL; -ULONG TwoPagesForPhysMem[2*PAGE_SIZE]; +ULONG TwoPagesForPhysMem[2*_PAGE_SIZE]; // scancode to ASCII conversion typedef struct tagSCANTOASCII @@ -301,13 +301,13 @@ ULONG result=1; } //************************************************************************* -// PICE_strcmpi() +// PICE_strcmp() // // my version of strcmp() //************************************************************************* ULONG PICE_strcmp(char* s1,char* s2) { -ULONG result=1; + ULONG result=1; while(IsAddressValid((ULONG)s1) && *s1 && // not end of string IsAddressValid((ULONG)s2) && *s2 && // not end of string @@ -323,6 +323,37 @@ ULONG result=1; return result; } +//************************************************************************* +// PICE_fncmp() +// +// compare function names ignoring decorations: +// leading '_' or '@" and trailing "@xx" +//************************************************************************* +ULONG PICE_fncmp(char* s1,char* s2) +{ + ULONG result=1; + + if( IsAddressValid((ULONG)s1) && (*s1 == '_' || *s1 == '@')) + s1++; + + if( IsAddressValid((ULONG)s2) && (*s2 == '_' || *s2 == '@')) + s2++; + + while(IsAddressValid((ULONG)s1) && *s1 && // not end of string + IsAddressValid((ULONG)s2) && *s2 ) + { + if( (*s1 != *s2) || *s1=='@' || *s2=='@' ) + break; + s1++; + s2++; + } + // strings same length + if((*s1==0 || *s1=='@') && (*s2==0 || *s2 =='@')){ + result=0; + } + return result; +} + ULONG PICE_wcsicmp(WCHAR* s1, WCHAR* s2) { ULONG result=1; @@ -366,11 +397,11 @@ char c; // // does a page validity check on every character in th string //************************************************************************* -USHORT PICE_strlen(char* s) +USHORT PICE_strlen(const char* s) { USHORT i; - for(i=0;IsAddressValid((ULONG)&s[i]) && s[i]!=0 && i>12; + NumPages=(Length+(_PAGE_SIZE-1))>>12; // calculate PICE_number of page PageNum=Addr>>PAGE_SHIFT; @@ -579,7 +612,7 @@ ULONG i,NumPages,PageNum; for(i=0;i= 0x02020B - ENTER_FUNC(); - /* symbol export of init_mm was added in 2.2.11 */ - LEAVE_FUNC(); - return &init_mm; -#else - // see also Rubini, Linux Device Drivers, page 288 - struct task_struct *pt; - - ENTER_FUNC(); - - for (pt = current->next_task; pt != current; pt = pt->next_task) { - if (pt->pid == 0) { - LEAVE_FUNC(); - return pt->mm; - } - } - - DPRINT((0,"GetInitMm(): failure\n")); - LEAVE_FUNC(); - return NULL; -#endif -} -#endif - //************************************************************************* // EnablePassThrough() // @@ -2186,7 +2186,7 @@ int PICE_close (HANDLE hFile) { return 0; } - DbgPrint("ZwClose failed:\n"); + DPRINT((2,"ZwClose failed:\n")); return -1; } @@ -2200,7 +2200,7 @@ size_t PICE_len( HANDLE hFile ) if( !NT_SUCCESS( status ) ){ DPRINT((0,"PICE_len: ZwQueryInformationFile error: %x\n", status)); } - ASSERT(fs.EndOfFile.u.HighPart == 0); + //ASSERT(fs.EndOfFile.u.HighPart == 0); return (size_t)fs.EndOfFile.u.LowPart; } diff --git a/reactos/apps/utils/pice/module/utils.h b/reactos/apps/utils/pice/module/utils.h index 2f140d26153..42ac2e5b893 100644 --- a/reactos/apps/utils/pice/module/utils.h +++ b/reactos/apps/utils/pice/module/utils.h @@ -175,7 +175,7 @@ char *PICE_strrev(char *); ULONG PICE_strcmp(char* s1,char* s2); ULONG PICE_strcmpi(char* s1,char* s2); ULONG PICE_strncmpi(char* s1,char* s2,ULONG len); -USHORT PICE_strlen(char* s); +USHORT PICE_strlen(const char* s); char* PICE_strcat(char* s1,char* s2); BOOLEAN PICE_isprint(char c); char* PICE_strcpy(char* s1,char* s2); @@ -240,7 +240,9 @@ void KeyboardFlushKeyboardQueue(void); #define _PAGE_ACCESSED 0x020 #define _PAGE_DIRTY 0x040 #define _PAGE_PSE 0x080 -#define _PAGE_4M _PAGE_PSE +#define _PAGE_4M _PAGE_PSE +#define _PAGE_SIZE 0x1000 + UCHAR AsciiFromScan(UCHAR s); UCHAR AsciiToScan(UCHAR s); diff --git a/reactos/apps/utils/pice/pice.cfg b/reactos/apps/utils/pice/pice.cfg index 38a9fab494e..e15cb50eb79 100644 --- a/reactos/apps/utils/pice/pice.cfg +++ b/reactos/apps/utils/pice/pice.cfg @@ -1,3 +1,4 @@ # sample +vga +\\SystemRoot\symbols\pice.dbg \\SystemRoot\symbols\ntoskrnl.dbg