Porting pice. Bug fixes.

svn path=/trunk/; revision=2533
This commit is contained in:
Eugene Ingerman 2002-01-21 10:03:50 +00:00
parent 656f7cb1f4
commit 88650ed55e
14 changed files with 447 additions and 343 deletions

View file

@ -210,9 +210,15 @@ BOOLEAN ReInstallSWBreakpoint(ULONG ulAddress)
{ {
if(IsAddressValid(p->ulAddress)) if(IsAddressValid(p->ulAddress))
{ {
*(PUCHAR)(p->ulAddress) = 0xCC; BOOLEAN isWriteable;
p->bInstalled = TRUE;
bResult = TRUE; 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 // TODO: must also check if it's a writable page
if(IsAddressValid(ulAddress) ) 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) if((p = FindSwBp(ulAddress))==NULL)
{ {
DPRINT((0,"InstallSWBreakpoint(): %.8X is free\n",ulAddress)); DPRINT((2,"InstallSWBreakpoint(): %.8X is free\n",ulAddress));
if( (p=FindEmptySwBpSlot()) ) if( (p=FindEmptySwBpSlot()) )
{ {
DPRINT((0,"InstallSWBreakpoint(): found empty slot\n")); BOOLEAN isWriteable;
DPRINT((0,"InstallSWBreakpoint(): %x value: %x", ulAddress, *(PUCHAR)ulAddress)); DPRINT((2,"InstallSWBreakpoint(): found empty slot\n"));
DPRINT((2,"InstallSWBreakpoint(): %x value: %x", ulAddress, *(PUCHAR)ulAddress));
p->ucOriginalOpcode = *(PUCHAR)ulAddress; p->ucOriginalOpcode = *(PUCHAR)ulAddress;
*(PUCHAR)ulAddress = 0xCC; //allow writing to page
p->bUsed = TRUE; 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; p->bInstalled = TRUE;
// find next address // find next address
p->ulAddress = ulAddress; p->ulAddress = ulAddress;
@ -337,9 +352,15 @@ void TryToInstallVirtualSWBreakpoints(void)
if(IsAddressValid(ulAddressWithOffset)) if(IsAddressValid(ulAddressWithOffset))
{ {
DPRINT((0,"TryToInstallVirtualSWBreakpoints(): installing...\n")); BOOLEAN isWriteable;
DPRINT((0,"TryToInstallVirtualSWBreakpoints(): installing...\n"));
p->ucOriginalOpcode = *(PUCHAR)ulAddressWithOffset; p->ucOriginalOpcode = *(PUCHAR)ulAddressWithOffset;
//allow writing to page
if( !( isWriteable = IsAddressWriteable(ulAddressWithOffset) ) )
SetAddressWriteable(ulAddressWithOffset,TRUE);
*(PUCHAR)ulAddressWithOffset = 0xCC; *(PUCHAR)ulAddressWithOffset = 0xCC;
if( !isWriteable )
SetAddressWriteable(ulAddressWithOffset,FALSE);
p->bUsed = TRUE; p->bUsed = TRUE;
p->bInstalled = TRUE; p->bInstalled = TRUE;
p->bVirtual = FALSE; p->bVirtual = FALSE;
@ -380,8 +401,13 @@ BOOLEAN RemoveSWBreakpoint(ULONG ulAddress)
{ {
if(IsAddressValid(ulAddress) && p->bInstalled == TRUE && p->bVirtual==FALSE) 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; *(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode;
if( !isWriteable )
SetAddressWriteable(ulAddress,FALSE);
} }
PICE_memset(p,0,sizeof(*p)); PICE_memset(p,0,sizeof(*p));
@ -411,8 +437,13 @@ BOOLEAN DeInstallSWBreakpoint(ULONG ulAddress)
{ {
if(IsAddressValid(ulAddress) && p->bInstalled == TRUE && p->bVirtual==FALSE) if(IsAddressValid(ulAddress) && p->bInstalled == TRUE && p->bVirtual==FALSE)
{ {
BOOLEAN isWriteable;
if( !( isWriteable = IsAddressWriteable(ulAddress) ) )
SetAddressWriteable(ulAddress,TRUE);
// restore original opcode // restore original opcode
*(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode; *(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode;
if( !isWriteable )
SetAddressWriteable(ulAddress,FALSE);
} }
p->bInstalled = FALSE; p->bInstalled = FALSE;
@ -447,7 +478,12 @@ BOOLEAN RemoveAllSWBreakpoints(BOOLEAN bEvenPermanents)
{ {
if(IsAddressValid(p->ulAddress) && p->bVirtual==FALSE) if(IsAddressValid(p->ulAddress) && p->bVirtual==FALSE)
{ {
BOOLEAN isWriteable;
if( !( isWriteable = IsAddressWriteable(p->ulAddress) ) )
SetAddressWriteable(p->ulAddress,TRUE);
*(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode; *(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode;
if( !isWriteable )
SetAddressWriteable(p->ulAddress,FALSE);
bResult = TRUE; bResult = TRUE;
} }
PICE_memset(p,0,sizeof(*p)); PICE_memset(p,0,sizeof(*p));
@ -458,7 +494,12 @@ BOOLEAN RemoveAllSWBreakpoints(BOOLEAN bEvenPermanents)
{ {
if(IsAddressValid(p->ulAddress) && p->bVirtual==FALSE) if(IsAddressValid(p->ulAddress) && p->bVirtual==FALSE)
{ {
BOOLEAN isWriteable;
if( !( isWriteable = IsAddressWriteable(p->ulAddress) ) )
SetAddressWriteable(p->ulAddress,TRUE);
*(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode; *(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode;
if( !isWriteable )
SetAddressWriteable(p->ulAddress,FALSE);
bResult = TRUE; bResult = TRUE;
} }
PICE_memset(p,0,sizeof(*p)); PICE_memset(p,0,sizeof(*p));
@ -583,8 +624,13 @@ void RevirtualizeBreakpointsForModule(PDEBUG_MODULE pMod)
p->bVirtual = TRUE; p->bVirtual = TRUE;
if(IsAddressValid(p->ulAddress) ) 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)); DPRINT((0,"RevirtualizeBreakpointsForModule(): restoring original opcode @ %x\n",p->ulAddress));
*(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode; *(PUCHAR)(p->ulAddress) = p->ucOriginalOpcode;
if( !isWriteable )
SetAddressWriteable(p->ulAddress,FALSE);
} }
else else
{ {

View file

@ -51,6 +51,7 @@ ULONG ulDebugFlags;
char tempDebug[2048]; char tempDebug[2048];
USHORT usDebugPortBase; USHORT usDebugPortBase;
extern BOOLEAN bIsPrintkPatched;
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// FUNCTIONS // FUNCTIONS
//// ////
@ -74,6 +75,7 @@ VOID Pice_dprintf(ULONG DebugLevel, PCHAR DebugMessage, ...)
PICE_vsprintf(tempDebug, DebugMessage, ap); PICE_vsprintf(tempDebug, DebugMessage, ap);
//ei DebugSendString(tempDebug); //ei DebugSendString(tempDebug);
Print(OUTPUT_WINDOW, tempDebug); Print(OUTPUT_WINDOW, tempDebug);
DbgPrint("%s", tempDebug);
restore_flags(ulDebugFlags); restore_flags(ulDebugFlags);
} }
va_end(ap); va_end(ap);
@ -179,10 +181,11 @@ void DebugSetOthers(ULONG Parity, ULONG Bits, ULONG StopBit)
void DebugSetupSerial(ULONG port,ULONG baudrate) void DebugSetupSerial(ULONG port,ULONG baudrate)
{ {
USHORT ports[]={COM1BASE,COM2BASE}; USHORT ports[]={COM1BASE,COM2BASE};
#if 0 //ei temporary
usDebugPortBase = ports[port-1]; usDebugPortBase = ports[port-1];
DebugSetOthers(NO_PARITY,8,1); DebugSetOthers(NO_PARITY,8,1);
DebugSetSpeed(baudrate); DebugSetSpeed(baudrate);
#endif
} }
#endif // DEBUG #endif // DEBUG

View file

@ -48,6 +48,7 @@ PMADDRESS_SPACE mm_init_mm;
ULONG KeyboardIRQL; ULONG KeyboardIRQL;
extern void NewInt31Handler(void);
//************************************************************************* //*************************************************************************
// InitPICE() // InitPICE()
// //
@ -100,7 +101,7 @@ BOOLEAN InitPICE(void)
DPRINT((0,"InitPICE(): trace step 4\n")); DPRINT((0,"InitPICE(): trace step 4\n"));
// print the initial screen template // print the initial screen template
PrintTemplate(); PrintTemplate();
/*
DPRINT((0,"InitPICE(): trace step 5\n")); DPRINT((0,"InitPICE(): trace step 5\n"));
// ask the user if he wants to abort the debugger load // ask the user if he wants to abort the debugger load
if(!CheckLoadAbort()) if(!CheckLoadAbort())
@ -111,7 +112,7 @@ BOOLEAN InitPICE(void)
LEAVE_FUNC(); LEAVE_FUNC();
return FALSE; return FALSE;
} }
*/
DPRINT((0,"InitPICE(): trace step 6\n")); DPRINT((0,"InitPICE(): trace step 6\n"));
// load the file /boot/System.map. // load the file /boot/System.map.
// !!! It must be consistent with the current kernel at all cost!!! // !!! 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")); DPRINT((0,"InitPICE(): trace step 7\n"));
ScanExports("_KernelAddressSpace", &ulAddr); 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)); DPRINT((0,"init_mm %x @ %x\n",&my_init_mm,my_init_mm));
if(!my_init_mm) if(!my_init_mm)
{ {
@ -146,7 +147,7 @@ BOOLEAN InitPICE(void)
DPRINT((0,"InitPICE(): trace step 7.1\n")); DPRINT((0,"InitPICE(): trace step 7.1\n"));
ScanExports("_PsProcessListHead",&ulAddr); ScanExports("_PsProcessListHead",&ulAddr);
pPsProcessListHead = ulAddr; pPsProcessListHead = (LIST_ENTRY*)ulAddr;
DPRINT((0,"pPsProcessListHead @ %X\n",pPsProcessListHead)); DPRINT((0,"pPsProcessListHead @ %X\n",pPsProcessListHead));
if(!pPsProcessListHead) if(!pPsProcessListHead)
{ {
@ -180,7 +181,7 @@ BOOLEAN InitPICE(void)
// the loaded module list // the loaded module list
ScanExports("_NameSpaceRoot", &ulAddr); ScanExports("_NameSpaceRoot", &ulAddr);
pNameSpaceRoot = ulAddr; pNameSpaceRoot = (PDIRECTORY_OBJECT *)ulAddr;
DPRINT((0,"pNameSpaceRoot @ %X\n",pNameSpaceRoot)); DPRINT((0,"pNameSpaceRoot @ %X\n",pNameSpaceRoot));
if(!pNameSpaceRoot) if(!pNameSpaceRoot)
{ {
@ -278,10 +279,11 @@ BOOLEAN InitPICE(void)
InstallGlobalKeyboardHook(); InstallGlobalKeyboardHook();
InstallSyscallHook(); InstallSyscallHook();
InstallInt3Hook(); InstallInt3Hook();
InstallPrintkHook();
InstallDblFltHook(); InstallDblFltHook();
InstallGPFaultHook(); InstallGPFaultHook();
InstallIntEHook(); InstallIntEHook();
//__asm__("int3");
InstallPrintkHook();
DPRINT((0,"InitPICE(): trace step 16\n")); DPRINT((0,"InitPICE(): trace step 16\n"));
if(ulDoInitialBreak) if(ulDoInitialBreak)

View file

@ -47,9 +47,13 @@ Copyright notice:
char tempOutput[1024],tempOutput2[1024]; char tempOutput[1024],tempOutput2[1024];
ULONG ulPrintk=0; //ULONG ulPrintk=0;
ULONG (*ulPrintk) (PANSI_STRING String);
BOOLEAN bInPrintk = FALSE; BOOLEAN bInPrintk = FALSE;
BOOLEAN bIsDebugPrint = FALSE; BOOLEAN bIsDebugPrint = FALSE;
BOOLEAN bIsPrintkPatched = FALSE;
ULONG ulCountTimerEvents = 0; ULONG ulCountTimerEvents = 0;
@ -126,10 +130,20 @@ ULONG CountArgs(LPSTR fmt)
return count; 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() // PrintkCallback()
// //
// called from RealIsr() when processing INT3 placed // called from RealIsr() when processing INT3 placed
// Must not make any calls to KdpPrintString (e.g. by calling DbgPrint).
//************************************************************************* //*************************************************************************
void PrintkCallback(void) void PrintkCallback(void)
{ {
@ -138,55 +152,26 @@ void PrintkCallback(void)
ULONG countArgs,i,len; ULONG countArgs,i,len;
PANSI_STRING temp; PANSI_STRING temp;
DPRINT((2,"In PrintkCallback:1\n"));
bInPrintk = TRUE; bInPrintk = TRUE;
DPRINT((2,"In PrintkCallback:2\n"));
// get the linear address of stack where string resides // get the linear address of stack where string resides
ulAddress = GetLinearAddress(CurrentSS,CurrentESP); ulAddress = GetLinearAddress(CurrentSS,CurrentESP);
if(ulAddress) if(ulAddress)
{ {
DPRINT((2,"In PrintkCallback: ulAddress: %x\n", ulAddress));
if(IsAddressValid(ulAddress+sizeof(char *)) ) if(IsAddressValid(ulAddress+sizeof(char *)) )
{ {
//KdpPrintString has PANSI_STRING as a parameter //KdpPrintString has PANSI_STRING as a parameter
temp = (PANSI_STRING)*(PULONG)(ulAddress+sizeof(char *)); temp = (PANSI_STRING)*(PULONG)(ulAddress+sizeof(char *));
DPRINT((2,"temp: %x\n", temp));
fmt = temp->Buffer; fmt = temp->Buffer;
// validate format string Print(OUTPUT_WINDOW,fmt);
if((len = PICE_strlen(fmt)) ) DPRINT((2,"%s\n", fmt));
{ CurrentEIP = (ULONG)PICE_KdpPrintString;
// 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;i<countArgs;i++)
{
if(!IsRangeValid((ULONG)(args+i*sizeof(ULONG)),sizeof(ULONG)) )
{
PICE_sprintf(tempOutput,"printk(%s): argument #%u is not valid!\n",(LPSTR)fmt,i);
Print(OUTPUT_WINDOW,tempOutput);
bInPrintk = FALSE;
return;
}
}
PICE_vsprintf(tempOutput2, fmt, args);
}
else
{
Print(OUTPUT_WINDOW,"printk(): ARGS are passed in but not valid!\n");
}
}
else
{
PICE_strcpy(tempOutput2, fmt);
}
Print(OUTPUT_WINDOW,tempOutput2);
}
} }
} }
bInPrintk = FALSE; bInPrintk = FALSE;
@ -260,21 +245,23 @@ void RemovePiceRunningTimer(void)
//************************************************************************* //*************************************************************************
void InstallPrintkHook(void) void InstallPrintkHook(void)
{ {
ENTER_FUNC();
ENTER_FUNC();
return;
if( bIsPrintkPatched )
return;
DPRINT((0,"installing PrintString hook\n")); DPRINT((0,"installing PrintString hook\n"));
DPRINT((0,"installing PrintString hook. DISABLED for now!!!!!!!!!!!\n")); ScanExports("_KdpPrintString",(PULONG)&ulPrintk);
/* ei fix later
ScanExports("_KdpPrintString",(PULONG)&ulPrintk);
DPRINT((0,"_KdpPrintString @ %x\n", ulPrintk));
ASSERT( ulPrintk ); // temporary ASSERT( ulPrintk ); // temporary
if(ulPrintk) if(ulPrintk)
{ {
InstallSWBreakpoint(ulPrintk,TRUE,PrintkCallback); bIsPrintkPatched = InstallSWBreakpoint(ulPrintk,TRUE,PrintkCallback);
DPRINT((0,"KdpPrintStringTest breakpoint installed? %d\n", bIsPrintkPatched));
} }
*/ LEAVE_FUNC();
LEAVE_FUNC();
} }
//************************************************************************* //*************************************************************************
@ -285,13 +272,11 @@ void DeInstallPrintkHook(void)
{ {
ENTER_FUNC(); ENTER_FUNC();
DPRINT((0,"enter DeInstallPrintkHook()\n")); DPRINT((0,"enter DeInstallPrintkHook()\n"));
if(bIsPrintkPatched && ulPrintk)
if(ulPrintk)
{ {
// will be done on exit debugger // will be done on exit debugger
DeInstallSWBreakpoint(ulPrintk); if( DeInstallSWBreakpoint(ulPrintk) )
bIsPrintkPatched = FALSE;
} }
LEAVE_FUNC(); LEAVE_FUNC();
} }

View file

@ -15,7 +15,7 @@ Environment:
LINUX 2.2.X LINUX 2.2.X
Kernel mode only Kernel mode only
Author: Author:
Klaus P. Gerlicher Klaus P. Gerlicher
@ -30,7 +30,11 @@ Copyright notice:
--*/ --*/
void InstallPrintkHook(void); void InstallPrintkHook(void);
void DeInstallPrintkHook(void); void DeInstallPrintkHook(void);
extern ULONG ulPrintk;
//extern ULONG ulPrintk;
extern ULONG (*ulPrintk) (PANSI_STRING String);
extern BOOLEAN bInPrintk; extern BOOLEAN bInPrintk;
extern BOOLEAN bIsDebugPrint; extern BOOLEAN bIsDebugPrint;

View file

@ -979,7 +979,7 @@ COMMAND_PROTOTYPE(ShowPageDirs)
PICE_sprintf(tempCmd,"%.8X %.8X %s %s %s (PTE @ %.8X)\n", PICE_sprintf(tempCmd,"%.8X %.8X %s %s %s (PTE @ %.8X)\n",
pArgs->Value[0], pArgs->Value[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->P==1)?"P ":"NP",
pPage->RW?"RW":"R ", pPage->RW?"RW":"R ",
pPage->US?"U":"S", pPage->US?"U":"S",
@ -1313,7 +1313,7 @@ void DisplaySourceFile(LPSTR pSrcLine,LPSTR pSrcEnd,ULONG ulLineNumber,ULONG ulL
LPSTR pTemp; LPSTR pTemp;
ULONG j = ulLineNumber-1; 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 // go to line
while(j--) while(j--)
@ -1411,16 +1411,16 @@ void UnassembleOneLineDown(void)
{ {
ULONG addr,addrorg; ULONG addr,addrorg;
DPRINT((2,"UnassembleOneLineDown()\n")); DPRINT((0,"UnassembleOneLineDown()\n"));
addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset); addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset);
DPRINT((2,"UnassembleOneLineDown(): addr = %.8X\n",addr)); DPRINT((0,"UnassembleOneLineDown(): addr = %.8X\n",addr));
tempCmd[0]=0; tempCmd[0]=0;
Disasm(&addr,tempCmd); Disasm(&addr,tempCmd);
DPRINT((2,"UnassembleOneLineDown(): addr after = %.8X\n",addr)); DPRINT((0,"UnassembleOneLineDown(): addr after = %.8X\n",addr));
ulOldDisasmOffset += (addr - addrorg); ulOldDisasmOffset += (addr - addrorg);
RepaintSource(); RepaintSource();
@ -1434,17 +1434,17 @@ void UnassembleOnePageDown(ULONG page)
{ {
ULONG addr,addrorg,i; ULONG addr,addrorg,i;
DPRINT((2,"UnassembleOnePageDown()\n")); DPRINT((0,"UnassembleOnePageDown()\n"));
addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset); addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset);
DPRINT((2,"UnassembleOnePageDown(): addr = %.8X\n",addr)); DPRINT((0,"UnassembleOnePageDown(): addr = %.8X\n",addr));
tempCmd[0]=0; tempCmd[0]=0;
for(i=0;i<page;i++) for(i=0;i<page;i++)
Disasm(&addr,tempCmd); Disasm(&addr,tempCmd);
DPRINT((2,"UnassembleOnePageDown(): addr after = %.8X\n",addr)); DPRINT((0,"UnassembleOnePageDown(): addr after = %.8X\n",addr));
ulOldDisasmOffset += (addr - addrorg); ulOldDisasmOffset += (addr - addrorg);
RepaintSource(); RepaintSource();
@ -1460,18 +1460,18 @@ void UnassembleOneLineUp(void)
LONG offset; LONG offset;
LPSTR pSymbol; LPSTR pSymbol;
DPRINT((2,"UnassembleOneLineUp()\n")); DPRINT((0,"UnassembleOneLineUp()\n"));
addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset); addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset);
DPRINT((2,"UnassembleOneLineUp(): addrorg = %.8X\n",addr)); DPRINT((0,"UnassembleOneLineUp(): addrorg = %.8X\n",addr));
offset = 1; offset = 1;
if((pSymbol = FindFunctionByAddress(addrorg-offset,&start,&end)) ) if((pSymbol = FindFunctionByAddress(addrorg-offset,&start,&end)) )
{ {
offset = addrorg - start; offset = addrorg - start;
DPRINT((2,"UnassembleOneLineUp(): %s @ offset = %u\n",pSymbol,offset)); DPRINT((0,"UnassembleOneLineUp(): %s @ offset = %u\n",pSymbol,offset));
} }
else else
{ {
@ -1485,12 +1485,12 @@ void UnassembleOneLineUp(void)
addr = addrorg - offset; addr = addrorg - offset;
do do
{ {
DPRINT((2,"UnassembleOneLineUp(): offset = %u addrorg %x addr %x\n",offset,addrorg,addr)); DPRINT((0,"UnassembleOneLineUp(): offset = %u addrorg %x addr %x\n",offset,addrorg,addr));
// disassemble while not reaching current instruction // disassemble while not reaching current instruction
addrbefore = addr; addrbefore = addr;
tempCmd[0]=0; tempCmd[0]=0;
Disasm(&addr,tempCmd); Disasm(&addr,tempCmd);
DPRINT((2,"%.8X: %s\n",addrbefore,tempCmd)); DPRINT((0,"%.8X: %s\n",addrbefore,tempCmd));
}while((addr != addrorg) && (addrbefore < addrorg)); }while((addr != addrorg) && (addrbefore < addrorg));
if((addrorg - addrstart)<=0) if((addrorg - addrstart)<=0)
@ -1498,7 +1498,7 @@ void UnassembleOneLineUp(void)
else else
ulOldDisasmOffset -= (addrorg - addrbefore); ulOldDisasmOffset -= (addrorg - addrbefore);
DPRINT((2,"UnassembleOneLineUp(): new addr = %.4X:%.8X\n",usOldDisasmSegment,ulOldDisasmOffset)); DPRINT((0,"UnassembleOneLineUp(): new addr = %.4X:%.8X\n",usOldDisasmSegment,ulOldDisasmOffset));
RepaintSource(); RepaintSource();
} }
@ -1513,20 +1513,20 @@ void UnassembleOnePageUp(ULONG page)
LONG offset; LONG offset;
LPSTR pSymbol; LPSTR pSymbol;
DPRINT((2,"UnassembleOnePageUp()\n")); DPRINT((0,"UnassembleOnePageUp()\n"));
for(i=0;i<page;i++) for(i=0;i<page;i++)
{ {
addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset); addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset);
DPRINT((2,"UnassembleOnePageUp(): addrorg = %.8X\n",addr)); DPRINT((0,"UnassembleOnePageUp(): addrorg = %.8X\n",addr));
offset = 1; offset = 1;
if((pSymbol = FindFunctionByAddress(addrorg-offset,&start,&end)) ) if((pSymbol = FindFunctionByAddress(addrorg-offset,&start,&end)) )
{ {
offset = addrorg - start; offset = addrorg - start;
DPRINT((2,"UnassembleOnePageUp(): %s @ offset = %u\n",pSymbol,offset)); DPRINT((0,"UnassembleOnePageUp(): %s @ offset = %u\n",pSymbol,offset));
} }
else else
{ {
@ -1539,12 +1539,12 @@ void UnassembleOnePageUp(ULONG page)
addrstart = addrorg; addrstart = addrorg;
do do
{ {
DPRINT((2,"UnassembleOnePageUp(): offset = %u addrorg %x addr %x\n",offset,addrorg,addr)); DPRINT((0,"UnassembleOnePageUp(): offset = %u addrorg %x addr %x\n",offset,addrorg,addr));
addrbefore = addr; addrbefore = addr;
// disassemble while not reaching current instruction // disassemble while not reaching current instruction
tempCmd[0]=0; tempCmd[0]=0;
Disasm(&addr,tempCmd); Disasm(&addr,tempCmd);
DPRINT((2,"%.8X: %s\n",addrbefore,tempCmd)); DPRINT((0,"%.8X: %s\n",addrbefore,tempCmd));
}while((addr != addrorg) && (addrbefore < addrorg)); }while((addr != addrorg) && (addrbefore < addrorg));
if((addrorg - addrstart)<=0) if((addrorg - addrstart)<=0)
@ -1554,7 +1554,7 @@ void UnassembleOnePageUp(ULONG page)
} }
DPRINT((2,"UnassembleOnePageUp(): new addr = %.4X:%.8X\n",usOldDisasmSegment,ulOldDisasmOffset)); DPRINT((0,"UnassembleOnePageUp(): new addr = %.4X:%.8X\n",usOldDisasmSegment,ulOldDisasmOffset));
RepaintSource(); RepaintSource();
} }
@ -1614,7 +1614,7 @@ COMMAND_PROTOTYPE(Unassemble)
return TRUE; return TRUE;
DPRINT((2,"Unassemble(%0.4X:%0.8X)\n",segment,addr)); DPRINT((0,"Unassemble(%0.4X:%0.8X)\n",segment,addr));
// //
// unassemble // unassemble
@ -1652,19 +1652,19 @@ COMMAND_PROTOTYPE(Unassemble)
if(pCurrentMod) if(pCurrentMod)
{ {
ULONG mod_addr; ULONG mod_addr;
DPRINT((2,"Unassemble(): pCurrentMod->name = %S\n",pCurrentMod->name)); DPRINT((0,"Unassemble(): pCurrentMod->name = %S\n",pCurrentMod->name));
mod_addr = (ULONG)pCurrentMod->BaseAddress; mod_addr = (ULONG)pCurrentMod->BaseAddress;
pCurrentSymbols = FindModuleSymbols(mod_addr); 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; ulCurrentlyDisplayedLineNumber = 0;
if(bShowSrc && bForceDisassembly == FALSE && (pSrc = FindSourceLineForAddress(addr,&ulLineNumber,&pSrcStart,&pSrcEnd,&pFilename)) ) 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); PICE_strcpy(szCurrentFile,pFilename);
ulCurrentlyDisplayedLineNumber = ulLineNumber; ulCurrentlyDisplayedLineNumber = ulLineNumber;
@ -1711,7 +1711,7 @@ COMMAND_PROTOTYPE(Unassemble)
else else
{ {
*szCurrentFile = 0; *szCurrentFile = 0;
DPRINT((2,"Couldn't find source for file\n")); DPRINT((0,"Couldn't find source for file\n"));
Home(SOURCE_WINDOW); Home(SOURCE_WINDOW);
// for each line in the disassembly window // for each line in the disassembly window
for(i=0;i<wWindow[SOURCE_WINDOW].cy;i++) for(i=0;i<wWindow[SOURCE_WINDOW].cy;i++)
@ -2476,6 +2476,7 @@ COMMAND_PROTOTYPE(SwitchTables)
CopyWideToAnsi(temp,pMod->name); CopyWideToAnsi(temp,pMod->name);
pCurrentSymbols = (PICE_SYMBOLFILE_HEADER*)pArgs->Value[0]; pCurrentSymbols = (PICE_SYMBOLFILE_HEADER*)pArgs->Value[0];
DPRINT((2,"TableSwitchSym: pCurrentSymbols: %x, Name: %S\n", pCurrentSymbols, pCurrentSymbols->name));
pTempMod = IsModuleLoaded(temp); pTempMod = IsModuleLoaded(temp);
if( pTempMod ) if( pTempMod )
pCurrentMod = pTempMod; pCurrentMod = pTempMod;
@ -2611,8 +2612,10 @@ COMMAND_PROTOTYPE(ShowLocals)
if(pArgs->Count==0) if(pArgs->Count==0)
{ {
p = FindLocalsByAddress(GetLinearAddress(CurrentCS,CurrentEIP)); p = FindLocalsByAddress(GetLinearAddress(CurrentCS,CurrentEIP));
DPRINT((0,"ShowLocals: %x", p));
if(p) if(p)
{ {
DPRINT((0,"ShowLocals: name %s, type_name %s\n", p->name, p->type_name));
while(PICE_strlen(p->name)) while(PICE_strlen(p->name))
{ {
if(!p->bRegister) if(!p->bRegister)

View file

@ -88,18 +88,27 @@ BOOLEAN PiceKbdIsr (
if(isDown) 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 // CTRL pressed
if(ucKey==0x1d) if(ucKey==0x1d)
{ {
bControl=TRUE; 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 // fake a CTRL-D release call
bForward=FALSE; bForward=FALSE;
bEnterNow=TRUE; bEnterNow=TRUE;
bControl=FALSE; 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) else if((ucKey == 66|| ucKey == 68) && bStepping)
{ {

View file

@ -151,11 +151,15 @@ ULONG HandlePageFault(FRAME* ptr)
PLIST_ENTRY current_entry; PLIST_ENTRY current_entry;
MEMORY_AREA* current; MEMORY_AREA* current;
//for some reason stack is corrupted. disable for now.
return 0;
// get linear address of page fault // get linear address of page fault
__asm__("movl %%cr2,%0":"=r" (address)); __asm__("movl %%cr2,%0":"=r" (address));
// current process // current process
tsk = IoGetCurrentProcess(); 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 // there's something terribly wrong if we get a fault in our command handler
if(bInDebuggerShell) if(bInDebuggerShell)
@ -182,35 +186,67 @@ ULONG HandlePageFault(FRAME* ptr)
current = CONTAINING_RECORD(current_entry, current = CONTAINING_RECORD(current_entry,
MEMORY_AREA, MEMORY_AREA,
Entry); 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( (address >= current->BaseAddress) && (address <= current->BaseAddress + current->Length ))
{ {
if(error_code & 2) //page not present
{ if( !(error_code & 1) ){
// area was not writable //check it is in pageable area
if(!(current->Attributes & PAGE_READONLY)) if( current->Type == MEMORY_AREA_SECTION_VIEW_COMMIT ||
{ current->Type == MEMORY_AREA_SECTION_VIEW_RESERVE ||
Print(OUTPUT_WINDOW,"pICE: virtual memory arena is not writeable!\n"); current->Type == MEMORY_AREA_VIRTUAL_MEMORY ||
return 1; current->Type == MEMORY_AREA_PAGED_POOL
} ){
} Print(OUTPUT_WINDOW,"pICE: VMA Pageable Section.\n");
// READ ACCESS return 0; //let the system handle this
else }
{ Print(OUTPUT_WINDOW,"pICE: VMA Page not present in non-pageable Section!\n");
// test EXT bit in error code return 1;
if (error_code & 1) }
{ else{ //access violation
Print(OUTPUT_WINDOW,"pICE: page-level protection fault!\n");
return 1; if( error_code & 4 )
} { //user mode
// if( (ULONG)address >= KERNEL_BASE )
if (!(current->Attributes & PAGE_EXECUTE_READ)) {
{ Print(OUTPUT_WINDOW,"pICE: User mode program trying to access kernel memory!\n");
Print(OUTPUT_WINDOW,"pICE: VMA is not readable!\n"); return 1;
return 1; }
} return 0;
} }
// let the system handle it /*
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; current_entry = current_entry->Flink;
} }
@ -301,7 +337,7 @@ void InstallIntEHook(void)
OldIntEHandler=SetGlobalInt(0x0E,(ULONG)LocalIntEHandler); OldIntEHandler=SetGlobalInt(0x0E,(ULONG)LocalIntEHandler);
} }
UnmaskIrqs(); UnmaskIrqs();
DPRINT((2,"OldIntE @ %x\n", OldIntEHandler));
LEAVE_FUNC(); LEAVE_FUNC();
} }

View file

@ -50,10 +50,10 @@ PUCHAR pScreenBufferSerial;
USHORT usSerialPortBase; USHORT usSerialPortBase;
UCHAR packet[PAGE_SIZE]; UCHAR packet[_PAGE_SIZE];
UCHAR assemble_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; ULONG ulFlushBufferPos = 0;
UCHAR ucLastKeyRead; UCHAR ucLastKeyRead;

View file

@ -323,9 +323,9 @@ void DebuggerShell(void)
CheckRingBuffer(); CheckRingBuffer();
// kill the speakers annoying beep // kill the speakers annoying beep
speaker = inb_p(0x61); speaker = inb_p((PCHAR)0x61);
speaker &= 0xFC; speaker &= 0xFC;
outb_p(speaker,0x61); outb_p(speaker,(PCHAR)0x61);
ProcessBootParams(); ProcessBootParams();
@ -1038,16 +1038,19 @@ void RealIsr(ULONG dwReasonForBreak)
bIrqStateAtBreak = ((CurrentEFL&(1<<9))!=0); 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 // came in because TF flag was set
if(dwReasonForBreak == REASON_SINGLESTEP) if(dwReasonForBreak == REASON_SINGLESTEP)
{ {
ULONG ulAddress,ulAddressCurrent; ULONG ulAddress,ulAddressCurrent;
DPRINT((0,"REASON_SINGLESTEP\n")); DPRINT((2,"REASON_SINGLESTEP\n"));
if(!bSingleStep) if(!bSingleStep)
{ {
DPRINT((0,"no single step requested!\n")); DPRINT((2,"no single step requested!\n"));
dwCallOldInt1Handler = 1; dwCallOldInt1Handler = 1;
goto common_return_point; goto common_return_point;
} }
@ -1060,7 +1063,7 @@ void RealIsr(ULONG dwReasonForBreak)
// simply restart the system. // simply restart the system.
if(NeedToReInstallSWBreakpoints(ulAddress,TRUE) ) if(NeedToReInstallSWBreakpoints(ulAddress,TRUE) )
{ {
DPRINT((0,"reinstalling INT3 @ %.4X:%.8X\n",OldCS,OldEIP)); DPRINT((2,"reinstalling INT3 @ %.4X:%.8X\n",OldCS,OldEIP));
ReInstallSWBreakpoint(ulAddress); ReInstallSWBreakpoint(ulAddress);
@ -1079,7 +1082,7 @@ void RealIsr(ULONG dwReasonForBreak)
} }
LEAVE_FUNC(); LEAVE_FUNC();
DPRINT((0,"-----------------------------------------------------------------\n")); DPRINT((2,"-----------------------------------------------------------------\n"));
return; return;
} }
bPreviousCommandWasGo = FALSE; bPreviousCommandWasGo = FALSE;
@ -1094,7 +1097,7 @@ void RealIsr(ULONG dwReasonForBreak)
ULONG ulLineNumber; ULONG ulLineNumber;
LPSTR pSrc,pFileName; LPSTR pSrc,pFileName;
DPRINT((0,"RealIsr(): stepping through source!\n")); DPRINT((2,"RealIsr(): stepping through source!\n"));
// look up the corresponding source line // look up the corresponding source line
// if there isn't any or the source line number has changed // 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); pSrc = FindSourceLineForAddress(ulAddressCurrent,&ulLineNumber,NULL,NULL,&pFileName);
else pSrc = NULL; 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 we have found a source line there
if(pSrc && ulLineNumber==g_ulLineNumberStart) 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) if(bStepInto)
StepInto(NULL); StepInto(NULL);
@ -1117,7 +1120,7 @@ void RealIsr(ULONG dwReasonForBreak)
bInDebuggerShell = FALSE; bInDebuggerShell = FALSE;
LEAVE_FUNC(); LEAVE_FUNC();
DPRINT((0,"-----------------------------------------------------------------\n")); DPRINT((2,"-----------------------------------------------------------------\n"));
return; return;
} }
bStepThroughSource = FALSE; bStepThroughSource = FALSE;
@ -1130,7 +1133,7 @@ void RealIsr(ULONG dwReasonForBreak)
{ {
ULONG ulReason; ULONG ulReason;
DPRINT((0,"REASON_HARDWARE_BP\n")); DPRINT((2,"REASON_HARDWARE_BP\n"));
// disable HW breakpoints // disable HW breakpoints
__asm__(" __asm__("
@ -1144,7 +1147,7 @@ void RealIsr(ULONG dwReasonForBreak)
:"eax" :"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) // HW breakpoint DR1 (skip: only used in init_module detection)
if(ulReason&0x2) if(ulReason&0x2)
@ -1178,12 +1181,12 @@ void RealIsr(ULONG dwReasonForBreak)
else else
pSrc = NULL; 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 we have found a source line there
if(pSrc && ulLineNumber==g_ulLineNumberStart) 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) if(bStepInto)
StepInto(NULL); StepInto(NULL);
@ -1205,7 +1208,7 @@ void RealIsr(ULONG dwReasonForBreak)
{ {
ULONG ulAddress; ULONG ulAddress;
DPRINT((0,"REASON_INT3\n")); DPRINT((2,"REASON_INT3\n"));
// must subtract one cause INT3s are generated after instructions execution // must subtract one cause INT3s are generated after instructions execution
CurrentEIP--; CurrentEIP--;
@ -1213,26 +1216,26 @@ void RealIsr(ULONG dwReasonForBreak)
// make a flat address // make a flat address
ulAddress = GetLinearAddress(CurrentCS,CurrentEIP); 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 there's a breakpoint installed at current EIP remove it
if(DeInstallSWBreakpoint(ulAddress) ) if(DeInstallSWBreakpoint(ulAddress) )
{ {
PSW_BP p; 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 // if it's permanent (must be Printk() ) skip the DebuggerShell() and
// do a callback // do a callback
if( (p = IsPermanentSWBreakpoint(ulAddress)) ) if( (p = IsPermanentSWBreakpoint(ulAddress)) )
{ {
DPRINT((0,"permanent breakpoint\n")); DPRINT((2,"permanent breakpoint\n"));
OldCS = CurrentCS; OldCS = CurrentCS;
OldEIP = CurrentEIP; OldEIP = CurrentEIP;
bSkipMainLoop = TRUE; bSkipMainLoop = TRUE;
DPRINT((2,"callback at %x\n",p->Callback));
if(p->Callback) if(p->Callback)
p->Callback(); p->Callback();
} }
@ -1256,6 +1259,9 @@ void RealIsr(ULONG dwReasonForBreak)
LPSTR pFind; LPSTR pFind;
PEPROCESS my_current = IoGetCurrentProcess(); 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 // 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 // above TASK_SIZE we assume this to be a hard embedded INT3
/* /*
@ -1316,7 +1322,7 @@ void RealIsr(ULONG dwReasonForBreak)
{ {
LPSTR pSymbolName; LPSTR pSymbolName;
DPRINT((0,"REASON_PAGEFAULT\n")); DPRINT((2,"REASON_PAGEFAULT\n"));
if( ScanExportsByAddress(&pSymbolName,GetLinearAddress(CurrentCS,CurrentEIP)) ) if( ScanExportsByAddress(&pSymbolName,GetLinearAddress(CurrentCS,CurrentEIP)) )
{ {
@ -1335,7 +1341,7 @@ void RealIsr(ULONG dwReasonForBreak)
{ {
LPSTR pSymbolName; LPSTR pSymbolName;
DPRINT((0,"REASON_GPFAULT\n")); DPRINT((2,"REASON_GPFAULT\n"));
if( ScanExportsByAddress(&pSymbolName,GetLinearAddress(CurrentCS,CurrentEIP)) ) if( ScanExportsByAddress(&pSymbolName,GetLinearAddress(CurrentCS,CurrentEIP)) )
{ {
@ -1350,19 +1356,19 @@ void RealIsr(ULONG dwReasonForBreak)
} }
else if(dwReasonForBreak == REASON_CTRLF) else if(dwReasonForBreak == REASON_CTRLF)
{ {
DPRINT((0,"REASON_CTRLF\n")); DPRINT((2,"REASON_CTRLF\n"));
// nothing to do // nothing to do
} }
else if(dwReasonForBreak == REASON_DOUBLE_FAULT) 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); PICE_sprintf(tempShell,"pICE: Breakpoint due to double fault at %.4X:%.8X\n",CurrentCS,CurrentEIP);
Print(OUTPUT_WINDOW,tempShell); Print(OUTPUT_WINDOW,tempShell);
} }
else if(dwReasonForBreak == REASON_INTERNAL_ERROR) 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: Please report this error to klauspg@diamondmm.com!\n");
// Print(OUTPUT_WINDOW,"pICE: !!! SYSTEM HALTED !!!\n"); // Print(OUTPUT_WINDOW,"pICE: !!! SYSTEM HALTED !!!\n");
@ -1370,7 +1376,7 @@ void RealIsr(ULONG dwReasonForBreak)
} }
else 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); PICE_sprintf(tempShell,"pICE: Breakpoint due to unknown reason at %.4X:%.8X (code %x)\n",CurrentCS,CurrentEIP,dwReasonForBreak);
Print(OUTPUT_WINDOW,tempShell); Print(OUTPUT_WINDOW,tempShell);
@ -1380,13 +1386,13 @@ void RealIsr(ULONG dwReasonForBreak)
} }
// we don't single-step yet // we don't single-step yet
DPRINT((0,"RealIsr(): not stepping yet\n")); DPRINT((2,"RealIsr(): not stepping yet\n"));
bSingleStep=FALSE; bSingleStep=FALSE;
// process commands // process commands
if(bSkipMainLoop == FALSE) if(bSkipMainLoop == FALSE)
{ {
DPRINT((0,"RealIsr(): saving registers\n")); DPRINT((2,"RealIsr(): saving registers\n"));
// save the extended regs // save the extended regs
__asm__ __volatile__ __asm__ __volatile__
(" ("
@ -1418,17 +1424,17 @@ void RealIsr(ULONG dwReasonForBreak)
popl %eax" popl %eax"
); );
DPRINT((0,"RealIsr(): adding colon to output()\n")); DPRINT((2,"RealIsr(): adding colon to output()\n"));
Print(OUTPUT_WINDOW,":"); Print(OUTPUT_WINDOW,":");
DPRINT((0,"RealIsr(): calling DebuggerShell()\n")); DPRINT((2,"RealIsr(): calling DebuggerShell()\n"));
DebuggerShell(); DebuggerShell();
} }
// if there was a SW breakpoint at CS:EIP // if there was a SW breakpoint at CS:EIP
if(NeedToReInstallSWBreakpoints(GetLinearAddress(CurrentCS,CurrentEIP),TRUE)) 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 // remember how we restarted last time
bPreviousCommandWasGo = !bSingleStep; bPreviousCommandWasGo = !bSingleStep;
// do a single step to reinstall breakpoint // do a single step to reinstall breakpoint
@ -1449,7 +1455,7 @@ common_return_point:
bInDebuggerShell = FALSE; bInDebuggerShell = FALSE;
LEAVE_FUNC(); LEAVE_FUNC();
DPRINT((0,"-----------------------------------------------------------------\n")); DPRINT((2,"common return-----------------------------------------------------------------\n"));
} }
__asm__(".global NewInt31Handler __asm__(".global NewInt31Handler
@ -1560,7 +1566,7 @@ afterswitch:
// restore EAX // restore EAX
popl %eax popl %eax
// do we need to call old INT1 handler // do we need to call old INT1 handler
.byte 0x2e .byte 0x2e
cmp $0,_dwCallOldInt1Handler cmp $0,_dwCallOldInt1Handler
je do_iret2 je do_iret2
@ -1604,6 +1610,8 @@ do_iret3:
jmp *_OldGPFaultHandler jmp *_OldGPFaultHandler
do_iret: do_iret:
//ei
//int3
iretl "); iretl ");
// //

View file

@ -53,7 +53,7 @@ LOCAL_VARIABLE local_vars[512];
PICE_SYMBOLFILE_HEADER* apSymbols[32]={NULL,}; PICE_SYMBOLFILE_HEADER* apSymbols[32]={NULL,};
ULONG ulNumSymbolsLoaded=0; ULONG ulNumSymbolsLoaded=0;
//ULONG kernel_end=0; ULONG kernel_end=0;
char tempSym[1024]; // temp buffer for output char tempSym[1024]; // temp buffer for output
@ -231,14 +231,13 @@ BOOLEAN ListDriverModules( void )
PICE_wcscpy( pdebug_module_tail->name, pm->BaseName.Buffer); PICE_wcscpy( pdebug_module_tail->name, pm->BaseName.Buffer);
pdebug_module_tail = pdebug_module_tail->next; 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)); kernel_end = (ULONG)pm->Base + pm->Length;
pd=HEADER_TO_BODY(current_obj); }
}
*/ current = current->Flink;
current = current->Flink;
} }
} }
@ -594,104 +593,107 @@ BOOLEAN ScanExportsByAddress(LPSTR *pFind,ULONG ulValue)
ENTER_FUNC(); ENTER_FUNC();
pSymbols = FindModuleSymbols(ulValue); pSymbols = FindModuleSymbols(ulValue);
if(pSymbols && pdebug_module_head) if(BuildModuleList()){
{ if(pSymbols && pdebug_module_head)
PDEBUG_MODULE pdTemp; {
PDEBUG_MODULE pdTemp;
DPRINT((0,"looking up symbols\n")); DPRINT((0,"looking up symbols\n"));
pd = pdebug_module_head; pd = pdebug_module_head;
do do
{ {
ASSERT(pd->size); if(pd->size){
pdTemp = pd;
pdTemp = pd; if(ulValue>=((ULONG)pdTemp->BaseAddress) && ulValue<((ULONG)pdTemp+pdTemp->size))
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?
{ {
DPRINT((0,"ScanExportsByAddress(): pSym = %x is not a valid pointer\n",(ULONG)pSym)); if(PICE_wcsicmp(pdTemp->name,pSymbols->name) == 0)
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 ))
{ {
ULONG ulCurrAddr; DPRINT((0,"ScanExportsByAddress(): found symbols for module %S @ %x \n",pdTemp->name,(ULONG)pSymbols));
PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1);
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)pSym,sizeof(IMAGE_SYMBOL) ) ) //should we actually check all the symbols here?
if(!IsRangeValid((ULONG)pShdrThis,sizeof(IMAGE_SECTION_HEADER)) )
{ {
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; 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) DPRINT((0,"ScanExportsByAddress(): pSym = %x\n",pSym));
{ DPRINT((0,"ScanExportsByAddress(): pStr = %x\n",pStr));
ulAddr = ulCurrAddr; DPRINT((0,"ScanExportsByAddress(): pShdr = %x\n",pShdr));
pFoundSym = pSym;
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 // if haven't found in the symbols try ntoskrnl exports. (note: check that this is needed since we
// already checked ntoskrnl coff symbol table) // already checked ntoskrnl coff symbol table)
if(pExports /*&& ulValue >= TASK_SIZE && ulValue < kernel_end*/) if(pExports && ulValue >= KERNEL_START && ulValue < kernel_end)
{ {
p = pExports; p = pExports;
// while we bound in System.map // while we bound in System.map
@ -1348,7 +1350,7 @@ PLOCAL_VARIABLE FindLocalsByAddress(ULONG addr)
break; break;
case N_LSYM: case N_LSYM:
// if we're in the function we're looking for // 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)); 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); ulTypeNumber = ExtractTypeNumber(pName);
@ -1367,7 +1369,7 @@ PLOCAL_VARIABLE FindLocalsByAddress(ULONG addr)
break; break;
case N_PSYM: case N_PSYM:
// if we're in the function we're looking for // 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)); 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); ulTypeNumber = ExtractTypeNumber(pName);
@ -1384,7 +1386,7 @@ PLOCAL_VARIABLE FindLocalsByAddress(ULONG addr)
break; break;
case N_RSYM: case N_RSYM:
// if we're in the function we're looking for // 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)); 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); ulTypeNumber = ExtractTypeNumber(pName);
@ -1452,14 +1454,16 @@ LPSTR FindSourceLineForAddress(ULONG addr,PULONG pulLineNumber,LPSTR* ppSrcStart
// lookup the functions name and start-end (external symbols) // lookup the functions name and start-end (external symbols)
pFunctionName = FindFunctionByAddress(addr,&start,&end); pFunctionName = FindFunctionByAddress(addr,&start,&end);
DPRINT((2,"FindSourceLineForAddress: %x\n", pFunctionName)); DPRINT((0,"FindSourceLineForAddress: for function: %s\n", pFunctionName));
if(pFunctionName) if(pFunctionName)
{ {
// lookup the modules symbol table (STABS) // lookup the modules symbol table (STABS)
pSymbols = FindModuleSymbols(addr); pSymbols = FindModuleSymbols(addr);
DPRINT((0,"FindSourceLineForAddress: pSymbols %x\n", pSymbols));
if(pSymbols) if(pSymbols)
{ {
DPRINT((0,"FindSourceLineForAddress: pSymbols->ulNumberOfSrcFiles %x\n", pSymbols->ulNumberOfSrcFiles));
// no source files so we don't need to lookup anything // no source files so we don't need to lookup anything
if(!pSymbols->ulNumberOfSrcFiles) if(!pSymbols->ulNumberOfSrcFiles)
return NULL; return NULL;
@ -1514,9 +1518,9 @@ LPSTR FindSourceLineForAddress(ULONG addr,PULONG pulLineNumber,LPSTR* ppSrcStart
// line number // line number
case N_SLINE: case N_SLINE:
// if we're in the function we're looking for // 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) if(bFirstOccurence)
{ {
@ -1638,6 +1642,7 @@ LPSTR FindSourceLineForAddress(ULONG addr,PULONG pulLineNumber,LPSTR* ppSrcStart
} }
} }
} }
DPRINT((0,"FindSourceLineForAddress: exit 1\n"));
return NULL; return NULL;
} }
@ -1768,7 +1773,7 @@ ULONG ListSymbolStartingAt(PDEBUG_MODULE pMod,PICE_SYMBOLFILE_HEADER* pSymbols,U
LPSTR pName; LPSTR pName;
if(((pSym->Type == 0x0) || (pSym->Type == 0x20) ) && 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 )) (pSym->SectionNumber > 0 ))
{ {
PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1); 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 ) ) ) 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; 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(ulNumSymbolsLoaded<DIM(apSymbols)) if(ulNumSymbolsLoaded<DIM(apSymbols))
{ {
hf = PICE_open(tempstr,OF_READ); hf = PICE_open(tempstr,OF_READ);
DPRINT((0,"LoadSymbols: hf: %x, file: %S\n",hf, tempstr)); DPRINT((2,"LoadSymbols: hf: %x, file: %S\n",hf, tempstr));
if(hf) if(hf)
{ {
//mm_segment_t oldfs; //mm_segment_t oldfs;
size_t len; size_t len;
DPRINT((0,"hf = %x\n",hf)); DPRINT((2,"hf = %x\n",hf));
len = PICE_len(hf); len = PICE_len(hf);
DPRINT((0,"file len = %d\n",len)); DPRINT((2,"file len = %d\n",len));
if(len) if(len)
{ {
pSymbols = PICE_malloc(len+1,NONPAGEDPOOL); // maybe make pool setting an option pSymbols = PICE_malloc(len+1,NONPAGEDPOOL); // maybe make pool setting an option
DPRINT((0,"pSymbols = %x\n",pSymbols)); DPRINT((2,"pSymbols = %x\n",pSymbols));
if(pSymbols) if(pSymbols)
{ {
//oldfs = get_fs(); set_fs(KERNEL_DS); //oldfs = get_fs(); set_fs(KERNEL_DS);
if(len == PICE_read(hf,(PVOID)pSymbols,len)) if(len == PICE_read(hf,(PVOID)pSymbols,len))
{ {
DPRINT((0,"LoadSymbols(): success reading symbols!\n")); DPRINT((2,"LoadSymbols(): success reading symbols!\n"));
DPRINT((0,"LoadSymbols(): pSymbols->magic = %X\n",pSymbols->magic)); DPRINT((2,"LoadSymbols(): pSymbols->magic = %X\n",pSymbols->magic));
} }
//set_fs(oldfs); //set_fs(oldfs);
@ -2017,7 +2022,7 @@ PICE_SYMBOLFILE_HEADER* LoadSymbols(LPSTR filename)
} }
else 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)); DPRINT((0,"Load symbols from file %s\n", temp));
pSymbols = LoadSymbols(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) if(pSymbols)
{ {
PICE_SYMBOLFILE_SOURCE* pSrc; PICE_SYMBOLFILE_SOURCE* pSrc;

View file

@ -44,7 +44,7 @@ char tempFlowChanges[256];
//PMADDRESS_SPACE my_init_mm=NULL; //PMADDRESS_SPACE my_init_mm=NULL;
ULONG TwoPagesForPhysMem[2*PAGE_SIZE]; ULONG TwoPagesForPhysMem[2*_PAGE_SIZE];
// scancode to ASCII conversion // scancode to ASCII conversion
typedef struct tagSCANTOASCII typedef struct tagSCANTOASCII
@ -301,13 +301,13 @@ ULONG result=1;
} }
//************************************************************************* //*************************************************************************
// PICE_strcmpi() // PICE_strcmp()
// //
// my version of strcmp() // my version of strcmp()
//************************************************************************* //*************************************************************************
ULONG PICE_strcmp(char* s1,char* s2) ULONG PICE_strcmp(char* s1,char* s2)
{ {
ULONG result=1; ULONG result=1;
while(IsAddressValid((ULONG)s1) && *s1 && // not end of string while(IsAddressValid((ULONG)s1) && *s1 && // not end of string
IsAddressValid((ULONG)s2) && *s2 && // not end of string IsAddressValid((ULONG)s2) && *s2 && // not end of string
@ -323,6 +323,37 @@ ULONG result=1;
return result; 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 PICE_wcsicmp(WCHAR* s1, WCHAR* s2)
{ {
ULONG result=1; ULONG result=1;
@ -366,11 +397,11 @@ char c;
// //
// does a page validity check on every character in th string // does a page validity check on every character in th string
//************************************************************************* //*************************************************************************
USHORT PICE_strlen(char* s) USHORT PICE_strlen(const char* s)
{ {
USHORT i; USHORT i;
for(i=0;IsAddressValid((ULONG)&s[i]) && s[i]!=0 && i<PAGE_SIZE;i++); for(i=0;IsAddressValid((ULONG)&s[i]) && s[i]!=0 && i<_PAGE_SIZE;i++);
if(IsAddressValid((ULONG)&s[i]) && s[i]==0) if(IsAddressValid((ULONG)&s[i]) && s[i]==0)
return i; return i;
@ -437,7 +468,7 @@ BOOLEAN IsAddressValid(ULONG address)
BOOLEAN bResult = FALSE; BOOLEAN bResult = FALSE;
PEPROCESS my_current = IoGetCurrentProcess(); PEPROCESS my_current = IoGetCurrentProcess();
address &= (~(PAGE_SIZE-1)); address &= (~(_PAGE_SIZE-1));
if(my_current) if(my_current)
{ {
@ -477,10 +508,9 @@ BOOLEAN IsAddressWriteable(ULONG address)
{ {
PULONG pPGD; PULONG pPGD;
PULONG pPTE; PULONG pPTE;
BOOLEAN bResult = FALSE;
PEPROCESS my_current = IoGetCurrentProcess(); PEPROCESS my_current = IoGetCurrentProcess();
address &= (~(PAGE_SIZE-1)); //address &= (~(_PAGE_SIZE-1));
if(my_current) if(my_current)
{ {
@ -490,24 +520,26 @@ BOOLEAN IsAddressWriteable(ULONG address)
// not large page // not large page
if(!((*pPGD)&_PAGE_4M)) if(!((*pPGD)&_PAGE_4M))
{ {
bResult |= (*pPGD) & _PAGE_RW; if(!((*pPGD) & _PAGE_RW))
return FALSE;
pPTE = ADDR_TO_PTE(address); pPTE = ADDR_TO_PTE(address);
if(pPTE) if(pPTE)
{ {
if( (*pPTE)&(_PAGE_PRESENT | _PAGE_PSE) ) if( ((*pPTE)&(_PAGE_PRESENT | _PAGE_PSE)) &&
bResult |= (*pPTE) & _PAGE_RW; ((*pPTE) & _PAGE_RW))
return TRUE;
else
return FALSE;
} }
} }
// large page // large page
else else
{ return ((*pPGD) & _PAGE_RW);
bResult |= (*pPGD) & _PAGE_RW;
}
} }
} }
return bResult; return FALSE;
} }
@ -519,11 +551,9 @@ BOOLEAN SetAddressWriteable(ULONG address,BOOLEAN bSet)
{ {
PULONG pPGD; PULONG pPGD;
PULONG pPTE; PULONG pPTE;
BOOLEAN bResult = FALSE;
PEPROCESS my_current = IoGetCurrentProcess(); PEPROCESS my_current = IoGetCurrentProcess();
address &= (~(PAGE_SIZE-1)); //address &= (~(_PAGE_SIZE-1));
if(my_current) if(my_current)
{ {
pPGD = ADDR_TO_PDE(address); pPGD = ADDR_TO_PDE(address);
@ -537,11 +567,14 @@ BOOLEAN SetAddressWriteable(ULONG address,BOOLEAN bSet)
{ {
if( (*pPTE)&(_PAGE_PRESENT | _PAGE_PSE) ) if( (*pPTE)&(_PAGE_PRESENT | _PAGE_PSE) )
{ {
if( bSet ) if( bSet ){
*pPTE |= _PAGE_RW; *pPTE |= _PAGE_RW;
else }
else{
*pPTE &= ~_PAGE_RW; *pPTE &= ~_PAGE_RW;
bResult = TRUE; }
FLUSH_TLB;
return TRUE;
} }
} }
} }
@ -552,12 +585,12 @@ BOOLEAN SetAddressWriteable(ULONG address,BOOLEAN bSet)
*pPGD |= _PAGE_RW; *pPGD |= _PAGE_RW;
else else
*pPGD &= ~_PAGE_RW; *pPGD &= ~_PAGE_RW;
bResult = TRUE; FLUSH_TLB;
return TRUE;
} }
} }
} }
return FALSE;
return bResult;
} }
//************************************************************************* //*************************************************************************
// IsRangeValid() // IsRangeValid()
@ -570,7 +603,7 @@ ULONG i,NumPages,PageNum;
// need to only touch one byte per page // need to only touch one byte per page
// calculate PICE_number of pages to touch // calculate PICE_number of pages to touch
NumPages=(Length+(PAGE_SIZE-1))>>12; NumPages=(Length+(_PAGE_SIZE-1))>>12;
// calculate PICE_number of page // calculate PICE_number of page
PageNum=Addr>>PAGE_SHIFT; PageNum=Addr>>PAGE_SHIFT;
@ -579,7 +612,7 @@ ULONG i,NumPages,PageNum;
for(i=0;i<NumPages;i++) for(i=0;i<NumPages;i++)
{ {
// if any one page is invalid range is invalid // if any one page is invalid range is invalid
if(!IsAddressValid((ULONG)((PageNum+i)*PAGE_SIZE)) ) if(!IsAddressValid((ULONG)((PageNum+i)*_PAGE_SIZE)) )
return FALSE; return FALSE;
} }
@ -1411,7 +1444,7 @@ PULONG FindPteForLinearAddress(ULONG address)
ENTER_FUNC(); ENTER_FUNC();
address &= (~(PAGE_SIZE-1)); address &= (~(_PAGE_SIZE-1));
if(my_current) if(my_current)
{ {
@ -1464,7 +1497,7 @@ void InvalidateLB(void)
//************************************************************************* //*************************************************************************
ULONG ReadPhysMem(ULONG Address,ULONG ulSize) ULONG ReadPhysMem(ULONG Address,ULONG ulSize)
{ {
ULONG Page = ((ULONG)TwoPagesForPhysMem+PAGE_SIZE)&~(PAGE_SIZE-1); ULONG Page = ((ULONG)TwoPagesForPhysMem+_PAGE_SIZE)&~(_PAGE_SIZE-1);
PULONG pPTE; PULONG pPTE;
ULONG temp = 0; ULONG temp = 0;
ULONG oldPTE; ULONG oldPTE;
@ -1478,7 +1511,7 @@ ULONG ReadPhysMem(ULONG Address,ULONG ulSize)
{ {
oldPTE = *pPTE; oldPTE = *pPTE;
DPRINT((0,"ReadPhysMem(): oldPTE = %.8X\n",oldPTE)); DPRINT((0,"ReadPhysMem(): oldPTE = %.8X\n",oldPTE));
temp = (Address & ~(PAGE_SIZE-1)); temp = (Address & ~(_PAGE_SIZE-1));
DPRINT((0,"ReadPhysMem(): page-aligned Address = %.8X\n",temp)); DPRINT((0,"ReadPhysMem(): page-aligned Address = %.8X\n",temp));
*pPTE = temp|0x1; *pPTE = temp|0x1;
DPRINT((0,"ReadPhysMem(): new PTE = %.8X\n",*pPTE)); DPRINT((0,"ReadPhysMem(): new PTE = %.8X\n",*pPTE));
@ -1486,15 +1519,15 @@ ULONG ReadPhysMem(ULONG Address,ULONG ulSize)
switch(ulSize) switch(ulSize)
{ {
case sizeof(UCHAR): // BYTE case sizeof(UCHAR): // BYTE
temp = *(PUCHAR)(Page + (Address & (PAGE_SIZE-1))); temp = *(PUCHAR)(Page + (Address & (_PAGE_SIZE-1)));
temp = (UCHAR)temp; temp = (UCHAR)temp;
break; break;
case sizeof(USHORT): // WORD case sizeof(USHORT): // WORD
temp = *(PUSHORT)(Page + (Address & (PAGE_SIZE-1))); temp = *(PUSHORT)(Page + (Address & (_PAGE_SIZE-1)));
temp = (USHORT)temp; temp = (USHORT)temp;
break; break;
case sizeof(ULONG): // DWORD case sizeof(ULONG): // DWORD
temp = *(PULONG)(Page + (Address & (PAGE_SIZE-1))); temp = *(PULONG)(Page + (Address & (_PAGE_SIZE-1)));
break; break;
} }
*pPTE = oldPTE; *pPTE = oldPTE;
@ -1511,7 +1544,7 @@ ULONG ReadPhysMem(ULONG Address,ULONG ulSize)
//************************************************************************* //*************************************************************************
void WritePhysMem(ULONG Address,ULONG Datum,ULONG ulSize) void WritePhysMem(ULONG Address,ULONG Datum,ULONG ulSize)
{ {
ULONG Page = ((ULONG)TwoPagesForPhysMem+PAGE_SIZE)&~(PAGE_SIZE-1); ULONG Page = ((ULONG)TwoPagesForPhysMem+_PAGE_SIZE)&~(_PAGE_SIZE-1);
PULONG pPTE; PULONG pPTE;
ULONG temp; ULONG temp;
ULONG oldPTE; ULONG oldPTE;
@ -1520,19 +1553,19 @@ void WritePhysMem(ULONG Address,ULONG Datum,ULONG ulSize)
if(pPTE) if(pPTE)
{ {
oldPTE = *pPTE; oldPTE = *pPTE;
temp = (Address & ~(PAGE_SIZE-1)); temp = (Address & ~(_PAGE_SIZE-1));
*pPTE = temp | 0x3; // present and writable *pPTE = temp | 0x3; // present and writable
InvalidateLB(); InvalidateLB();
switch(ulSize) switch(ulSize)
{ {
case sizeof(UCHAR): // BYTE case sizeof(UCHAR): // BYTE
*(PUCHAR)(Page + (Address & (PAGE_SIZE-1))) = (UCHAR)Datum; *(PUCHAR)(Page + (Address & (_PAGE_SIZE-1))) = (UCHAR)Datum;
break; break;
case sizeof(USHORT): // WORD case sizeof(USHORT): // WORD
*(PUSHORT)(Page + (Address & (PAGE_SIZE-1))) = (USHORT)Datum; *(PUSHORT)(Page + (Address & (_PAGE_SIZE-1))) = (USHORT)Datum;
break; break;
case sizeof(ULONG): // DWORD case sizeof(ULONG): // DWORD
*(PULONG)(Page + (Address & (PAGE_SIZE-1))) = Datum; *(PULONG)(Page + (Address & (_PAGE_SIZE-1))) = Datum;
break; break;
} }
*pPTE = oldPTE; *pPTE = oldPTE;
@ -2038,39 +2071,6 @@ ULONG inl(PULONG port)
return READ_PORT_ULONG(port); return READ_PORT_ULONG(port);
} }
#if 0
//*************************************************************************
// GetInitMm()
//
//*************************************************************************
struct mm_struct *GetInitMm(void)
{
#if REAL_LINUX_VERSION_CODE >= 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() // EnablePassThrough()
// //
@ -2186,7 +2186,7 @@ int PICE_close (HANDLE hFile)
{ {
return 0; return 0;
} }
DbgPrint("ZwClose failed:\n"); DPRINT((2,"ZwClose failed:\n"));
return -1; return -1;
} }
@ -2200,7 +2200,7 @@ size_t PICE_len( HANDLE hFile )
if( !NT_SUCCESS( status ) ){ if( !NT_SUCCESS( status ) ){
DPRINT((0,"PICE_len: ZwQueryInformationFile error: %x\n", 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; return (size_t)fs.EndOfFile.u.LowPart;
} }

View file

@ -175,7 +175,7 @@ char *PICE_strrev(char *);
ULONG PICE_strcmp(char* s1,char* s2); ULONG PICE_strcmp(char* s1,char* s2);
ULONG PICE_strcmpi(char* s1,char* s2); ULONG PICE_strcmpi(char* s1,char* s2);
ULONG PICE_strncmpi(char* s1,char* s2,ULONG len); 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); char* PICE_strcat(char* s1,char* s2);
BOOLEAN PICE_isprint(char c); BOOLEAN PICE_isprint(char c);
char* PICE_strcpy(char* s1,char* s2); char* PICE_strcpy(char* s1,char* s2);
@ -240,7 +240,9 @@ void KeyboardFlushKeyboardQueue(void);
#define _PAGE_ACCESSED 0x020 #define _PAGE_ACCESSED 0x020
#define _PAGE_DIRTY 0x040 #define _PAGE_DIRTY 0x040
#define _PAGE_PSE 0x080 #define _PAGE_PSE 0x080
#define _PAGE_4M _PAGE_PSE #define _PAGE_4M _PAGE_PSE
#define _PAGE_SIZE 0x1000
UCHAR AsciiFromScan(UCHAR s); UCHAR AsciiFromScan(UCHAR s);
UCHAR AsciiToScan(UCHAR s); UCHAR AsciiToScan(UCHAR s);

View file

@ -1,3 +1,4 @@
# sample # sample
+vga +vga
\\SystemRoot\symbols\pice.dbg
\\SystemRoot\symbols\ntoskrnl.dbg \\SystemRoot\symbols\ntoskrnl.dbg