diff --git a/reactos/apps/utils/pice/loader/main.c b/reactos/apps/utils/pice/loader/main.c index 5b04ab74842..889440a9bd2 100644 --- a/reactos/apps/utils/pice/loader/main.c +++ b/reactos/apps/utils/pice/loader/main.c @@ -86,7 +86,7 @@ void process_stabs( SymbolFileHeader.magic = PICE_MAGIC; strcpy(temp,pExeName); pSlash = strrchr(temp,'\\'); - pDot = strrchr(temp,'.'); + pDot = strchr(temp,'.'); if(pDot) { *pDot = 0; @@ -371,7 +371,7 @@ int process_pe(char* filename,int file,void* p,int len) strcpy(szSymName,filename); //printf("LOADER: file name = %s\n",szSymName); - if((pDot = strrchr(szSymName,'.'))) + if((pDot = strchr(szSymName,'.'))) { *pDot = 0; strcat(pDot,".dbg"); diff --git a/reactos/apps/utils/pice/module/bp.c b/reactos/apps/utils/pice/module/bp.c index cb886133a42..333b51cd234 100644 --- a/reactos/apps/utils/pice/module/bp.c +++ b/reactos/apps/utils/pice/module/bp.c @@ -239,14 +239,14 @@ 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\n",ulAddress)); + DPRINT((0,"InstallSWBreakpoint(): %.8X is valid, writable? %d\n",ulAddress,IsAddressWriteable(ulAddress))); if((p = FindSwBp(ulAddress))==NULL) { DPRINT((0,"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)); p->ucOriginalOpcode = *(PUCHAR)ulAddress; *(PUCHAR)ulAddress = 0xCC; p->bUsed = TRUE; diff --git a/reactos/apps/utils/pice/module/debug.c b/reactos/apps/utils/pice/module/debug.c index bdac8dd2e43..e33e266d0d4 100644 --- a/reactos/apps/utils/pice/module/debug.c +++ b/reactos/apps/utils/pice/module/debug.c @@ -67,13 +67,13 @@ VOID Pice_dprintf(ULONG DebugLevel, PCHAR DebugMessage, ...) va_list ap; va_start(ap, DebugMessage); - if (DebugLevel <= lDebugLevel) + if (/*DebugLevel <= lDebugLevel*/ DebugLevel == 2) { save_flags(ulDebugFlags); cli(); PICE_vsprintf(tempDebug, DebugMessage, ap); //ei DebugSendString(tempDebug); - DbgPrint("%s", tempDebug); + Print(OUTPUT_WINDOW, tempDebug); restore_flags(ulDebugFlags); } va_end(ap); diff --git a/reactos/apps/utils/pice/module/hardware.c b/reactos/apps/utils/pice/module/hardware.c index 58c884574aa..0a067fd5a5b 100644 --- a/reactos/apps/utils/pice/module/hardware.c +++ b/reactos/apps/utils/pice/module/hardware.c @@ -798,7 +798,7 @@ void Print(USHORT Window,LPSTR p) { ULONG i; - DPRINT((5,"%s",p)); + DPRINT((11,"%s",p)); //ENTER_FUNC(); if(!bConsoleIsInitialized) diff --git a/reactos/apps/utils/pice/module/output.c b/reactos/apps/utils/pice/module/output.c index f86b58ab0bc..40d2dbeaa71 100644 --- a/reactos/apps/utils/pice/module/output.c +++ b/reactos/apps/utils/pice/module/output.c @@ -262,7 +262,8 @@ void InstallPrintkHook(void) { ENTER_FUNC(); DPRINT((0,"installing PrintString hook\n")); - + DPRINT((0,"installing PrintString hook. DISABLED for now!!!!!!!!!!!\n")); +/* ei fix later ScanExports("_KdpPrintString",(PULONG)&ulPrintk); ASSERT( ulPrintk ); // temporary @@ -271,6 +272,7 @@ void InstallPrintkHook(void) { InstallSWBreakpoint(ulPrintk,TRUE,PrintkCallback); } +*/ LEAVE_FUNC(); } diff --git a/reactos/apps/utils/pice/module/parse.c b/reactos/apps/utils/pice/module/parse.c index dfdf59f34c2..04e5a8b70f9 100644 --- a/reactos/apps/utils/pice/module/parse.c +++ b/reactos/apps/utils/pice/module/parse.c @@ -1313,7 +1313,7 @@ void DisplaySourceFile(LPSTR pSrcLine,LPSTR pSrcEnd,ULONG ulLineNumber,ULONG ulL LPSTR pTemp; ULONG j = ulLineNumber-1; - DPRINT((0,"DisplaySourceFile(%.8X,%u,%u)\n",pSrcLine,ulLineNumber,ulLineNumberToInvert)); + DPRINT((2,"DisplaySourceFile(%.8X,%u,%u)\n",pSrcLine,ulLineNumber,ulLineNumberToInvert)); // go to line while(j--) @@ -1411,16 +1411,16 @@ void UnassembleOneLineDown(void) { ULONG addr,addrorg; - DPRINT((0,"UnassembleOneLineDown()\n")); + DPRINT((2,"UnassembleOneLineDown()\n")); addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset); - DPRINT((0,"UnassembleOneLineDown(): addr = %.8X\n",addr)); + DPRINT((2,"UnassembleOneLineDown(): addr = %.8X\n",addr)); tempCmd[0]=0; Disasm(&addr,tempCmd); - DPRINT((0,"UnassembleOneLineDown(): addr after = %.8X\n",addr)); + DPRINT((2,"UnassembleOneLineDown(): addr after = %.8X\n",addr)); ulOldDisasmOffset += (addr - addrorg); RepaintSource(); @@ -1434,17 +1434,17 @@ void UnassembleOnePageDown(ULONG page) { ULONG addr,addrorg,i; - DPRINT((0,"UnassembleOnePageDown()\n")); + DPRINT((2,"UnassembleOnePageDown()\n")); addrorg = addr = GetLinearAddress(usOldDisasmSegment,ulOldDisasmOffset); - DPRINT((0,"UnassembleOnePageDown(): addr = %.8X\n",addr)); + DPRINT((2,"UnassembleOnePageDown(): addr = %.8X\n",addr)); tempCmd[0]=0; for(i=0;iname = %S\n",pCurrentMod->name)); + DPRINT((2,"Unassemble(): pCurrentMod->name = %S\n",pCurrentMod->name)); mod_addr = (ULONG)pCurrentMod->BaseAddress; pCurrentSymbols = FindModuleSymbols(mod_addr); - DPRINT((0,"Unassemble(): pCurrentSymbols = %x\n",(ULONG)pCurrentSymbols)); + DPRINT((2,"Unassemble(): pCurrentSymbols = %x\n",(ULONG)pCurrentSymbols)); } - DPRINT((0,"Unassemble(): pCurrentMod = %x\n",pCurrentMod)); + DPRINT((2,"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)); PICE_strcpy(szCurrentFile,pFilename); ulCurrentlyDisplayedLineNumber = ulLineNumber; @@ -1710,7 +1711,7 @@ COMMAND_PROTOTYPE(Unassemble) else { *szCurrentFile = 0; - + DPRINT((2,"Couldn't find source for file\n")); Home(SOURCE_WINDOW); // for each line in the disassembly window for(i=0;iSectionNumber > 0 )) { ULONG ulCurrAddr; - PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + pSym->SectionNumber; + PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1); DPRINT((0,"ScanExportsByAddress(): pShdr[%x] = %x\n",pSym->SectionNumber,(ULONG)pShdrThis)); @@ -665,11 +665,11 @@ BOOLEAN ScanExportsByAddress(LPSTR *pFind,ULONG ulValue) } *pFind = temp3; { - PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + pFoundSym->SectionNumber; + 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) ){ + 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 } @@ -715,14 +715,14 @@ BOOLEAN ScanExportsByAddress(LPSTR *pFind,ULONG ulValue) } // increment pointer to next line p = pStartOfLine; - while(*p!=0 && *p!=0x0a)p++; + while(*p!=0 && *p!=0x0a && *p!=0x0d)p++; p++; } if(bResult) { int i; // copy symbol name to temp string - for(i=0;pSymbolName[i]!=0 && pSymbolName[i]!=0x0a;i++) + for(i=0;pSymbolName[i]!=0 && pSymbolName[i]!=0x0a && pSymbolName[i]!=0x0d;i++) temp[i] = pSymbolName[i]; temp[i] = 0; // decide if we need to append an offset @@ -754,7 +754,7 @@ LPSTR FindFunctionByAddress(ULONG ulValue,PULONG pulstart,PULONG pulend) LPSTR pName; pSymbols = FindModuleSymbols(ulValue); - DPRINT((0,"FindFunctionByAddress(): symbols @ %x\n",(ULONG)pSymbols)); + DPRINT((0,"FindFunctionByAddress(): symbols for %S @ %x \n",pSymbols->name,(ULONG)pSymbols)); if(pSymbols && pdebug_module_head) { DPRINT((0,"looking up symbol\n")); @@ -768,7 +768,7 @@ LPSTR FindFunctionByAddress(ULONG ulValue,PULONG pulstart,PULONG pulend) start = (ULONG)pdTemp->BaseAddress; end = start+pdTemp->size; - DPRINT((0,"FindFunctionByAddress(): is it %S for %x\n",(ULONG)pdTemp->name,ulValue)); + DPRINT((0,"FindFunctionByAddress(): ulValue %x\n",ulValue)); if(ulValue>=start && ulValue0 - if(( (pSym->Type == 0x20) && (pSym->StorageClass==IMAGE_SYM_CLASS_STATIC) && + if(( (pSym->Type == 0x20) && (pSym->StorageClass==IMAGE_SYM_CLASS_EXTERNAL) && (pSym->SectionNumber > 0 ))) { ULONG ulCurrAddr; - PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + pSym->SectionNumber; + PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1); DPRINT((0,"FindFunctionByAddress(): pShdr[%x] = %x\n",pSym->SectionNumber,(ULONG)pShdrThis)); @@ -811,17 +811,19 @@ LPSTR FindFunctionByAddress(ULONG ulValue,PULONG pulstart,PULONG pulend) //the begining of the section ulCurrAddr = ((ULONG)pdTemp->BaseAddress+pShdrThis->VirtualAddress+pSym->Value); DPRINT((0,"FindFunctionByAddress(): CurrAddr [1] = %x\n",ulCurrAddr)); + DPRINT((0,"%x ", ulCurrAddr)); if(ulCurrAddr<=ulValue && ulCurrAddr>start) { start = ulCurrAddr; pFoundSym = pSym; + //DPRINT((0,"FindFunctionByAddress(): CANDIDATE for start %x\n",start)); } else if(ulCurrAddr>=ulValue && ulCurrAddrNumberOfAuxSymbols + 1; @@ -834,7 +836,7 @@ LPSTR FindFunctionByAddress(ULONG ulValue,PULONG pulstart,PULONG pulend) if(pulend){ //just in case there is more than one code section - PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + pFoundSym->SectionNumber; + PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pFoundSym->SectionNumber-1); if( end > (ULONG)pdTemp->BaseAddress+pShdrThis->SizeOfRawData ){ DPRINT((0,"Hmm: end=%d, end of section: %d\n", end, (ULONG)pdTemp->BaseAddress+pShdrThis->SizeOfRawData)); end = (ULONG)pdTemp->BaseAddress+pShdrThis->SizeOfRawData; @@ -842,7 +844,7 @@ LPSTR FindFunctionByAddress(ULONG ulValue,PULONG pulstart,PULONG pulend) *pulend = end; } - if( !(pFoundSym->N.Name.Short) ){ + if(pFoundSym->N.Name.Short){ //name is in the header. it's not zero terminated. have to copy. PICE_sprintf(temp4,"%.8s", pFoundSym->N.ShortName); pName = temp4; @@ -954,17 +956,17 @@ ULONG FindFunctionInModuleByName(LPSTR szFunctionname, PDEBUG_MODULE pd) while( pSym < pSymEnd ) { //symbol is a function is it's type is 0x20, storage class is external and section>0 - if(( (pSym->Type == 0x20) && (pSym->StorageClass==IMAGE_SYM_CLASS_STATIC) && + if(( (pSym->Type == 0x20) && (pSym->StorageClass==IMAGE_SYM_CLASS_EXTERNAL) && (pSym->SectionNumber > 0 ))) { ULONG start; LPSTR pName; - PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + pSym->SectionNumber; + PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1); DPRINT((0,"FindFunctionInModuleByName(): %s @ %x\n",pName,start)); start = ((ULONG)pd->BaseAddress+pShdrThis->VirtualAddress+pSym->Value); - if( !(pSym->N.Name.Short) ){ //if name is stored in the structure + if(pSym->N.Name.Short){ //if name is stored in the structure //name may be not zero terminated but 8 characters max if((PICE_strncmpi(pName,szFunctionname, 8) == 0) && start) { @@ -1450,6 +1452,8 @@ 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)); + if(pFunctionName) { // lookup the modules symbol table (STABS) @@ -1767,7 +1771,7 @@ ULONG ListSymbolStartingAt(PDEBUG_MODULE pMod,PICE_SYMBOLFILE_HEADER* pSymbols,U ((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; + PIMAGE_SECTION_HEADER pShdrThis = (PIMAGE_SECTION_HEADER)pShdr + (pSym->SectionNumber-1); ULONG section_flags; ULONG start; @@ -1784,7 +1788,7 @@ ULONG ListSymbolStartingAt(PDEBUG_MODULE pMod,PICE_SYMBOLFILE_HEADER* pSymbols,U //the begining of the section start = ((ULONG)pMod->BaseAddress+pShdrThis->VirtualAddress+pSym->Value); - if( !(pSym->N.Name.Short) ){ + if(pSym->N.Name.Short){ //name is in the header. it's not zero terminated. have to copy. PICE_sprintf(pOutput,"%.8X (%s) %.8s\n",start,(section_flags&IMAGE_SCN_CNT_CODE)?"TEXT":"DATA",pSym->N.ShortName); } @@ -1946,19 +1950,21 @@ PICE_SYMBOLFILE_HEADER* LoadSymbols(LPSTR filename) { HANDLE hf; PICE_SYMBOLFILE_HEADER* pSymbols=NULL; - WCHAR tempstr[DEBUG_MODULE_NAME_LEN]; - + WCHAR tempstr[256]; + int conv; ENTER_FUNC(); - if( !PICE_MultiByteToWideChar(CP_ACP, NULL, filename, -1, tempstr, DEBUG_MODULE_NAME_LEN ) ) + if( !( conv = PICE_MultiByteToWideChar(CP_ACP, NULL, filename, -1, tempstr, 256 ) ) ) { DPRINT((0,"Can't convert module name.\n")); return NULL; } + DPRINT((0,"LoadSymbols: test %S, %s, tempstr %S, conv: %d\n",L"testing", filename, tempstr, conv)); if(ulNumSymbolsLoaded (unsigned int)precision) + len = precision; + + if (!(flags & NUM_LEFT)) + while (len < field_width--) + *str++ = ' '; + for (i = 0; i < len; ++i) + *str++ = *s++; + while (len < field_width--) + *str++ = ' '; + } else { + /* print unicode string */ + sw = va_arg(args, wchar_t *); + if (sw == NULL) + sw = L""; + + len = wcslen (sw); + if ((unsigned int)len > (unsigned int)precision) + len = precision; + + if (!(flags & NUM_LEFT)) + while (len < field_width--) + *str++ = ' '; + for (i = 0; i < len; ++i) + *str++ = (unsigned char)(*sw++); + while (len < field_width--) + *str++ = ' '; + } + continue; + case 'p': if (field_width == -1) { field_width = 2*sizeof(void *); @@ -2102,6 +2141,9 @@ HANDLE PICE_open (LPCWSTR lpPathName, int iReadWrite) HANDLE hfile; NTSTATUS status; + + DPRINT((0,"PICE_open: %S\n", lpPathName)); + if ( (iReadWrite & OF_READWRITE ) == OF_READWRITE ) dwAccessMask = GENERIC_READ | GENERIC_WRITE; else if ( (iReadWrite & OF_READ ) == OF_READ ) @@ -2127,13 +2169,11 @@ HANDLE PICE_open (LPCWSTR lpPathName, int iReadWrite) NULL, NULL); - status = NtOpenFile( &hfile, dwAccessMask, &ObjectAttributes, NULL, dwShareMode, 0); //BUG BUG check status!!! - DbgPrint("PICE_open: handle: %x, status: %x", hfile, status); if( !NT_SUCCESS( status ) ){ DPRINT((0,"PICE_open: NtOpenFile error: %x\n", status)); } @@ -2157,6 +2197,9 @@ size_t PICE_len( HANDLE hFile ) NTSTATUS status; status = ZwQueryInformationFile( hFile, &iosb, &fs, sizeof fs, FileStandardInformation ); + if( !NT_SUCCESS( status ) ){ + DPRINT((0,"PICE_len: ZwQueryInformationFile error: %x\n", status)); + } ASSERT(fs.EndOfFile.u.HighPart == 0); return (size_t)fs.EndOfFile.u.LowPart; } @@ -2194,12 +2237,12 @@ PICE_MultiByteToWideChar ( && (CP_MACCP != CodePage) && (CP_OEMCP != CodePage)) /* --- FLAGS --- */ - || (dwFlags ^ ( MB_PRECOMPOSED + /*|| (dwFlags ^ ( MB_PRECOMPOSED | MB_COMPOSITE | MB_ERR_INVALID_CHARS | MB_USEGLYPHCHARS ) - ) + )*/ /* --- INPUT BUFFER --- */ || (NULL == lpMultiByteStr) ) @@ -2234,7 +2277,7 @@ PICE_MultiByteToWideChar ( */ if (cchWideChar < InStringLength) { - DPRINT((0,"ERROR_INSUFFICIENT_BUFFER\n")); + DPRINT((0,"ERROR_INSUFFICIENT_BUFFER: cchWideChar: %d, InStringLength: %d\n", cchWideChar, InStringLength)); return 0; } /* @@ -2246,7 +2289,7 @@ PICE_MultiByteToWideChar ( ((*r) && (cchConverted < cchWideChar)); - r++, + r++, w++, cchConverted++ ) { diff --git a/reactos/apps/utils/pice/module/vga.c b/reactos/apps/utils/pice/module/vga.c index cc24d9af054..62101db5d56 100644 --- a/reactos/apps/utils/pice/module/vga.c +++ b/reactos/apps/utils/pice/module/vga.c @@ -52,6 +52,7 @@ Copyright notice: // GLOBALS //// // used for HERCUELS text and VGA text mode +/* WINDOW wWindowVga[4]= { {1,3,1,0,FALSE}, @@ -59,6 +60,15 @@ WINDOW wWindowVga[4]= {10,9,1,0,FALSE}, {20,4,1,0,FALSE} }; +*/ + +WINDOW wWindowVga[4]= +{ + {1,3,1,0,FALSE}, + {5,7,1,0,FALSE}, + {14,15,1,0,FALSE}, + {30,14,1,0,FALSE} +}; // 25 line text mode UCHAR MGATable25[]={97,80,82,15,25, 6,25,25, 2,13,11,12, 0, 0, 0, 0}; @@ -389,7 +399,7 @@ BOOLEAN ConsoleInitVga(void) SetWindowGeometry(wWindowVga); GLOBAL_SCREEN_WIDTH = 80; - GLOBAL_SCREEN_HEIGHT = 25; + GLOBAL_SCREEN_HEIGHT = 45; attr.u.Asuchar = 0x07; diff --git a/reactos/apps/utils/pice/readme.txt b/reactos/apps/utils/pice/readme.txt new file mode 100644 index 00000000000..64958184c79 --- /dev/null +++ b/reactos/apps/utils/pice/readme.txt @@ -0,0 +1,42 @@ +This is some preliminary information on using PICE. I am planning to write +a detailed manual later. + +BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA + + PICE for Reactos is in early beta stage of development. It still has many bugs. + +BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA-BETA + + +PICE is a kernel debugger that was ported for Reactos (the original Linux +project by Klaus P. Gerlicher and Goran Devic may be found here: +http://pice.sourceforge.net). + +Installation and use: + +1. PICE is loaded like a regular device driver. The only limitation - it must +be loaded before keyboard.sys driver. You should add: + + LdrLoadAutoConfigDriver( L"pice.sys" ); + +in ntoskrnl/ldr/loader.c after the line loading keyboard driver. + +2. You should copy pice.cfg and ntoskrnl.sym to \SystemRoot\symbols directory +of Reactos. + +3. If you want to add symbolic information you should use loader.exe to +create .dbg file from the unstrippped version of exe or driver: +For example: +pice\loader\loader.exe -t ntoskrnl.nostrip.exe + +After that copy .dbg file to \SystemRoot\symbols and add a line to pice.cfg: +\\SystemRoot\symbols\ntoskrnl.dbg. + +Pice will load the symbols during boot. For large .dbg files it may take a +while (ntoskrnl.dbg is ~3Mb). You may find that loading time under bochs is +quite slow, although otherwise performance should be fine. + +Enjoy, +Eugene + +