3 Copyright (c) 1998-2001 Klaus P. Gerlicher
11 execution of debugger commands
24 15-Nov-2000: general cleanup of source files
28 This file may be distributed under the terms of the GNU Public License.
32 ////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////
42 ULONG ValueTrue
=1,ValueFalse
=0;
43 ULONG ulLastDisassStartAddress
=0,ulLastDisassEndAddress
=0,ulLastInvertedAddress
=0;
44 USHORT gCurrentSelector
=0;
45 ULONG gCurrentOffset
=0;
46 LONG ulCurrentlyDisplayedLineNumber
=0;
47 USHORT usOldDisasmSegment
= 0;
48 ULONG ulOldDisasmOffset
= 0;
49 static ULONG ulCountForWaitKey
= 0;
51 extern PDEBUG_MODULE pdebug_module_head
;
52 extern PDEBUG_MODULE pdebug_module_tail
;
54 //extern unsigned long sys_call_table[];
56 BOOLEAN (*DisplayMemory
)(PARGS
) = DisplayMemoryDword
;
58 char szCurrentFile
[256]="";
59 PDEBUG_MODULE pCurrentMod
=NULL
;
60 PICE_SYMBOLFILE_HEADER
* pCurrentSymbols
=NULL
;
62 // suppresses passing on of function keys while stepping code
63 BOOLEAN bStepping
= FALSE
;
64 BOOLEAN bInt3Here
= TRUE
;
65 BOOLEAN bInt1Here
= TRUE
;
67 KEYWORDS RegKeyWords
[]={
68 {"eax",&CurrentEAX
,sizeof(ULONG
)},
69 {"ebx",&CurrentEBX
,sizeof(ULONG
)},
70 {"ecx",&CurrentECX
,sizeof(ULONG
)},
71 {"edx",&CurrentEDX
,sizeof(ULONG
)},
72 {"edi",&CurrentEDI
,sizeof(ULONG
)},
73 {"esi",&CurrentESI
,sizeof(ULONG
)},
74 {"ebp",&CurrentEBP
,sizeof(ULONG
)},
75 {"esp",&CurrentESP
,sizeof(ULONG
)},
76 {"eip",&CurrentEIP
,sizeof(ULONG
)},
80 KEYWORDS SelectorRegKeyWords
[]={
81 {"cs",&CurrentCS
,sizeof(USHORT
)},
82 {"ds",&CurrentDS
,sizeof(USHORT
)},
83 {"es",&CurrentES
,sizeof(USHORT
)},
84 {"fs",&CurrentFS
,sizeof(USHORT
)},
85 {"gs",&CurrentGS
,sizeof(USHORT
)},
86 {"ss",&CurrentSS
,sizeof(USHORT
)},
90 KEYWORDS OnOffKeyWords
[]={
91 {"on",&ValueTrue
,sizeof(ULONG
)},
92 {"off",&ValueFalse
,sizeof(ULONG
)},
96 KEYWORDS SpecialKeyWords
[]={
97 {"process",&CurrentProcess
,sizeof(ULONG
)},
101 LPSTR LocalVarRegs
[]=
122 #define COMMAND_HAS_NO_PARAMS (0)
123 #define COMMAND_HAS_PARAMS (1<<0)
124 #define COMMAND_HAS_SWITCHES (1<<1)
126 #define PARAM_CAN_BE_SYMBOLIC (1<<0)
127 #define PARAM_CAN_BE_SEG_OFFSET (1<<1)
128 #define PARAM_CAN_BE_MODULE (1<<2)
129 #define PARAM_CAN_BE_PRNAME (1<<3)
130 #define PARAM_CAN_BE_PID (1<<4)
131 #define PARAM_CAN_BE_SRC_FILE (1<<5)
132 #define PARAM_CAN_BE_NUMERIC (1<<6)
133 #define PARAM_CAN_BE_REG_KEYWORD (1<<7)
134 #define PARAM_CAN_BE_ONOFF_KEYWORD (1<<8)
135 #define PARAM_CAN_BE_SPECIAL_KEYWORD (1<<9)
136 #define PARAM_CAN_BE_ASTERISK (1<<10)
137 #define PARAM_CAN_BE_ONOFF (1<<11)
138 #define PARAM_CAN_BE_VIRTUAL_SYMBOLIC (1<<12)
139 #define PARAM_CAN_BE_SRCLINE (1<<13)
140 #define PARAM_CAN_BE_PARTIAL_SYM_NAME (1<<14)
141 #define PARAM_CAN_BE_ANY_STRING (1<<15)
142 #define PARAM_CAN_BE_DECIMAL (1<<16)
143 #define PARAM_CAN_BE_SIZE_DESC (1<<17)
144 #define PARAM_CAN_BE_LETTER (1<<18)
146 #define COMMAND_GROUP_HELP (0)
147 #define COMMAND_GROUP_FLOW (1)
148 #define COMMAND_GROUP_STRUCT (2)
149 #define COMMAND_GROUP_OS (3)
150 #define COMMAND_GROUP_MEM (4)
151 #define COMMAND_GROUP_BREAKPOINT (5)
152 #define COMMAND_GROUP_WINDOW (6)
153 #define COMMAND_GROUP_DEBUG (7)
154 #define COMMAND_GROUP_INFO (8)
155 #define COMMAND_GROUP_STATE (9)
156 #define COMMAND_GROUP_HELP_ONLY (10)
157 #define COMMAND_GROUP_LAST (11)
159 LPSTR CommandGroups
[]=
174 // table of command handlers
175 CMDTABLE CmdTable
[]={
176 {"gdt",ShowGdt
,"display current global descriptor table" ,0,{0,0,0,0,0},"",COMMAND_GROUP_STRUCT
},
177 {"idt",ShowIdt
,"display current interrupt descriptor table" ,0,{0,0,0,0,0},"",COMMAND_GROUP_STRUCT
},
178 {"x",LeaveIce
,"return to Reactos" ,0,{0,0,0,0,0},"",COMMAND_GROUP_FLOW
},
179 {"t",SingleStep
,"single step one instruction" ,0,{0,0,0,0,0},"",COMMAND_GROUP_FLOW
},
180 {"vma",ShowVirtualMemory
,"displays VMAs" ,0,{0,0,0,0,0},"",COMMAND_GROUP_OS
},
181 {"h",ShowHelp
,"list help on commands" ,0,{0,0,0,0,0},"",COMMAND_GROUP_HELP
},
182 {"page",ShowPageDirs
,"dump page directories" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_NUMERIC
|PARAM_CAN_BE_REG_KEYWORD
,0,0,0,0},"",COMMAND_GROUP_STRUCT
},
183 {"proc",ShowProcesses
,"list all processes" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_PRNAME
|PARAM_CAN_BE_PID
,0,0,0,0},"",COMMAND_GROUP_OS
},
184 {"dd",DisplayMemoryDword
,"display dword memory" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_NUMERIC
|PARAM_CAN_BE_SYMBOLIC
|PARAM_CAN_BE_REG_KEYWORD
,0,0,0,0},"",COMMAND_GROUP_MEM
},
185 {"db",DisplayMemoryByte
,"display byte memory " ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_NUMERIC
|PARAM_CAN_BE_SYMBOLIC
|PARAM_CAN_BE_REG_KEYWORD
,0,0,0,0},"",COMMAND_GROUP_MEM
},
186 {"dpd",DisplayPhysMemDword
,"display dword physical memory" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_NUMERIC
,0,0,0,0},"",COMMAND_GROUP_MEM
},
187 {"u",Unassemble
,"disassemble at address" ,COMMAND_HAS_PARAMS
|COMMAND_HAS_SWITCHES
,{PARAM_CAN_BE_NUMERIC
|PARAM_CAN_BE_SYMBOLIC
|PARAM_CAN_BE_REG_KEYWORD
|PARAM_CAN_BE_SRCLINE
,0,0,0,0},"f",COMMAND_GROUP_MEM
},
188 {"mod",ShowModules
,"displays all modules" ,0,{0,0,0,0,0},"",COMMAND_GROUP_OS
},
189 {"bpx",SetBreakpoint
,"set code breakpoint" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_NUMERIC
|PARAM_CAN_BE_VIRTUAL_SYMBOLIC
|PARAM_CAN_BE_SYMBOLIC
|PARAM_CAN_BE_SRCLINE
|PARAM_CAN_BE_REG_KEYWORD
,0,0,0,0},"",COMMAND_GROUP_BREAKPOINT
},
190 {"bl",ListBreakpoints
,"list breakpoints" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_NUMERIC
,0,0,0,0},"",COMMAND_GROUP_BREAKPOINT
},
191 {"bc",ClearBreakpoints
,"clear breakpoints" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_NUMERIC
|PARAM_CAN_BE_ASTERISK
,0,0,0,0},"",COMMAND_GROUP_BREAKPOINT
},
192 {"ver",Ver
,"display pICE version and state information" ,0,{0,0,0,0,0},"",COMMAND_GROUP_INFO
},
193 {"hboot",Hboot
,"hard boot the system" ,0,{0,0,0,0,0},"",COMMAND_GROUP_FLOW
},
194 {"code",SetCodeDisplay
,"toggle code display" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_ONOFF
,0,0,0,0},"",COMMAND_GROUP_STATE
},
195 {"cpu",ShowCPU
,"display CPU special registers" ,0,{0,0,0,0,0},"",COMMAND_GROUP_STRUCT
},
196 {"stack",WalkStack
,"display call stack" ,0,{0,0,0,0,0},"",COMMAND_GROUP_STRUCT
},
197 {"peek",PeekMemory
,"peek at physical memory" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_SIZE_DESC
,PARAM_CAN_BE_NUMERIC
,0,0,0},"",COMMAND_GROUP_MEM
},
198 {"poke",PokeMemory
,"poke to physical memory" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_SIZE_DESC
,PARAM_CAN_BE_NUMERIC
,PARAM_CAN_BE_NUMERIC
,0,0},"",COMMAND_GROUP_MEM
},
199 {".",UnassembleAtCurrentEip
,"unassemble at current instruction" ,0,{0,0,0,0,0},"",COMMAND_GROUP_MEM
},
200 {"p",StepOver
,"single step over call" ,0,{0,0,0,0,0},"",COMMAND_GROUP_FLOW
},
201 {"i",StepInto
,"single step into call" ,0,{0,0,0,0,0},"",COMMAND_GROUP_FLOW
},
202 {"locals",ShowLocals
,"display local symbols" ,0,{0,0,0,0,0},"",COMMAND_GROUP_MEM
},
203 {"table",SwitchTables
,"display loaded symbol tables" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_MODULE
,0,0,0,0},"",COMMAND_GROUP_DEBUG
},
204 {"file",SwitchFiles
,"display source files in symbol table" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_SRC_FILE
,0,0,0,0},"",COMMAND_GROUP_DEBUG
},
205 {"sym",ShowSymbols
,"list known symbol information" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_PARTIAL_SYM_NAME
,0,0,0,0},"",COMMAND_GROUP_DEBUG
},
206 {"?",EvaluateExpression
,"evaluate an expression" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_ANY_STRING
,0,0,0,0},"",COMMAND_GROUP_DEBUG
},
207 {"src",SetSrcDisplay
,"sets disassembly mode" ,0,{0,0,0,0,0},"",COMMAND_GROUP_DEBUG
},
208 {"wc",SizeCodeWindow
,"change size of code window" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_DECIMAL
,0,0,0,0},"",COMMAND_GROUP_WINDOW
},
209 {"wd",SizeDataWindow
,"change size of data window" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_DECIMAL
,0,0,0,0},"",COMMAND_GROUP_WINDOW
},
210 {"r",SetGetRegisters
,"sets or displays registers" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_REG_KEYWORD
,PARAM_CAN_BE_NUMERIC
,0,0,0},"",COMMAND_GROUP_STRUCT
},
211 {"cls",ClearScreen
,"clear output window" ,0,{0,0,0,0,0},"",COMMAND_GROUP_WINDOW
},
212 {"phys",ShowMappings
,"show all mappings for linear address" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_NUMERIC
,0,0,0,0},"",COMMAND_GROUP_MEM
},
213 {"timers",ShowTimers
,"show all active timers" ,0,{0,0,0,0,0},"",COMMAND_GROUP_OS
},
214 {"pci",ShowPCI
,"show PCI devices" ,COMMAND_HAS_PARAMS
|COMMAND_HAS_SWITCHES
,{PARAM_CAN_BE_DECIMAL
,PARAM_CAN_BE_DECIMAL
,0,0,0},"a",COMMAND_GROUP_INFO
},
215 {"next",NextInstr
,"advance EIP to next instruction" ,0,{0,0,0,0,0},""},
216 {"i3here",I3here
,"catch INT 3s" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_ONOFF
,0,0,0,0},"",COMMAND_GROUP_FLOW
},
217 {"layout",SetKeyboardLayout
,"sets keyboard layout" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_ANY_STRING
,0,0,0,0},"",COMMAND_GROUP_FLOW
},
218 {"syscall",ShowSysCallTable
,"displays syscall (table)" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_DECIMAL
,0,0,0,0},"",COMMAND_GROUP_FLOW
},
219 {"altkey",SetAltKey
,"set alternate break key" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_LETTER
,0,0,0,0},"",COMMAND_GROUP_FLOW
},
220 {"addr",ShowContext
,"show/set address contexts" ,COMMAND_HAS_PARAMS
,{PARAM_CAN_BE_PRNAME
,0,0,0,0},"",COMMAND_GROUP_FLOW
},
221 {"arrow up",NULL
,"" ,0,{0,0,0,0,0},"",COMMAND_GROUP_HELP_ONLY
},
227 char HexDigit
[] = { '0', '1', '2', '3', '4', '5', '6', '7',
228 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
238 {"EFLAGS",&CurrentEFL
},
246 {0,0,0,FALSE
,FALSE
,FALSE
,"",""},
247 {0,0,0,FALSE
,FALSE
,FALSE
,"",""},
248 {0,0,0,FALSE
,FALSE
,FALSE
,"",""},
249 {0,0,0,FALSE
,FALSE
,FALSE
,"",""}
252 BOOLEAN bShowSrc
= TRUE
;
253 BOOLEAN bCodeOn
= FALSE
;
254 BOOLEAN bNeedToFillBuffer
= TRUE
;
256 char *NonSystemSegmentTypes
[]=
262 "Data RO expand-dwon",
263 "Data RO expand-down, accessed",
264 "Data RW expand-dwon",
265 "Data RW expand-down, accessed",
270 "Code EO conforming",
271 "Code EO conforming, accessed",
272 "Code ER conforming",
273 "Code ER conforming, accessed"
276 char *SystemSegmentTypes
[]=
279 "16-bit TSS (available)",
284 "16-bit interrupt gate",
287 "32-bit TSS (available)",
292 "32-bit interrupt gate",
296 ////////////////////////////////////////////////////
300 //*************************************************************************
303 //*************************************************************************
304 void RepaintSource(void)
310 // disassembly from current address
311 PICE_memset(&Args
,0,sizeof(ARGS
));
312 // make unassembler refresh all again
313 ulLastDisassStartAddress
=ulLastDisassEndAddress
=0;
320 //*************************************************************************
323 //*************************************************************************
324 void RepaintDesktop(void)
334 // display data window
335 Args
.Value
[0]=OldSelector
;
336 Args
.Value
[1]=OldOffset
;
338 DisplayMemory(&Args
);
340 // disassembly from current address
341 PICE_memset(&Args
,0,sizeof(ARGS
));
342 // make unassembler refresh all again
343 ulLastDisassStartAddress
=ulLastDisassEndAddress
=0;
347 PrintRingBuffer(wWindow
[OUTPUT_WINDOW
].cy
-1);
348 Print(OUTPUT_WINDOW
,"");
356 //*************************************************************************
359 //*************************************************************************
360 void PutStatusText(LPSTR p
)
364 ClrLine(wWindow
[OUTPUT_WINDOW
].y
-1);
365 PutChar(p
,1,wWindow
[OUTPUT_WINDOW
].y
-1);
370 //*************************************************************************
373 //*************************************************************************
374 BOOLEAN
WaitForKey(void)
378 if(ulCountForWaitKey
== 0)
379 SuspendPrintRingBuffer(TRUE
);
383 if(ulCountForWaitKey
== (wWindow
[OUTPUT_WINDOW
].cy
-1))
385 SuspendPrintRingBuffer(FALSE
);
387 PrintRingBuffer(wWindow
[OUTPUT_WINDOW
].cy
-1);
389 ulCountForWaitKey
= 0;
391 SetBackgroundColor(WHITE
);
392 ClrLine(wWindow
[OUTPUT_WINDOW
].y
+wWindow
[OUTPUT_WINDOW
].cy
);
393 PutChar(" Press any key to continue listing or press ESC to stop... ",1,wWindow
[OUTPUT_WINDOW
].y
+wWindow
[OUTPUT_WINDOW
].cy
);
394 ucKeyPressedWhileIdle
=0;
395 while(!(ucKeyPressedWhileIdle
=GetKeyPolled()))
399 SetBackgroundColor(BLACK
);
400 // if ESCAPE then indicate retreat
401 if(ucKeyPressedWhileIdle
==SCANCODE_ESC
)
405 ucKeyPressedWhileIdle
=0;
412 /////////////////////////////////////////////////////////////
414 /////////////////////////////////////////////////////////////
416 //*************************************************************************
419 //*************************************************************************
420 COMMAND_PROTOTYPE(SingleStep
)
423 LPSTR pSrcStart
,pSrcEnd
,pFilename
;
427 if(FindSourceLineForAddress(GetLinearAddress(CurrentCS
,CurrentEIP
),&ulLineNumber
,&pSrcStart
,&pSrcEnd
,&pFilename
))
429 DPRINT((0,"SingleStep(): stepping into source\n"));
435 CurrentEFL
|=0x100; // set trace flag (TF)
449 //*************************************************************************
453 //*************************************************************************
454 COMMAND_PROTOTYPE(StepOver
)
456 char tempDisasm
[256];
457 ULONG dwBreakAddress
;
459 LPSTR pSrcStart
,pSrcEnd
,pFilename
;
463 DPRINT((0,"StepOver():\n"));
465 // only no arguments supplied
466 // when we have source and current disassembly mod is SOURCE
467 // we have to analyse the code block for the source line
468 if(FindSourceLineForAddress(GetLinearAddress(CurrentCS
,CurrentEIP
),&ulLineNumber
,&pSrcStart
,&pSrcEnd
,&pFilename
))
470 DPRINT((0,"StepOver(): we have source here!\n"));
471 DPRINT((0,"StepOver(): line #%u in file = %s!\n",ulLineNumber
,pFilename
));
473 g_ulLineNumberStart
= ulLineNumber
;
474 bStepThroughSource
= TRUE
;
476 // deinstall the INT3 in kernel's printk()
477 DeInstallPrintkHook();
479 goto proceed_as_normal
;
483 DPRINT((0,"StepOver(): no source here!\n"));
486 // if there is some form of call instruction at EIP we need to find
487 // the return address
488 if(IsCallInstrAtEIP())
490 // get address of next instruction
491 dwBreakAddress
=GetLinearAddress(CurrentCS
,CurrentEIP
);
493 Disasm(&dwBreakAddress
,tempDisasm
);
495 DPRINT((0,"address of break = %.4X:%.8X\n",CurrentCS
,dwBreakAddress
));
497 dwBreakAddress
=GetLinearAddress(CurrentCS
,dwBreakAddress
);
499 DPRINT((0,"linear address of break = %.8X\n",dwBreakAddress
));
501 DPRINT((0,"setting DR0=%.8X\n",dwBreakAddress
));
503 SetHardwareBreakPoint(dwBreakAddress
,0);
506 bNotifyToExit
= TRUE
;
510 DPRINT((0,"no call at breakpoint\n"));
512 CurrentEFL
|=0x100; // set trace flag (TF)
528 //*************************************************************************
532 //*************************************************************************
533 COMMAND_PROTOTYPE(StepInto
)
536 LPSTR pSrcStart
,pSrcEnd
,pFilename
;
540 // only no arguments supplied
541 // when we have source and current disassembly mod is SOURCE
542 // we have to analyse the code block for the source line
543 if(FindSourceLineForAddress(GetLinearAddress(CurrentCS
,CurrentEIP
),&ulLineNumber
,&pSrcStart
,&pSrcEnd
,&pFilename
))
545 DPRINT((0,"StepOver(): we have source here!\n"));
546 DPRINT((0,"StepOver(): line #%u in file = %s!\n",ulLineNumber
,pFilename
));
548 g_ulLineNumberStart
= ulLineNumber
;
549 bStepThroughSource
= TRUE
;
551 // deinstall the INT3 in kernel's printk()
552 DeInstallPrintkHook();
554 goto proceed_as_normal_into
;
558 DPRINT((0,"StepInto(): no source here!\n"));
560 proceed_as_normal_into
:
563 CurrentEFL
|=0x100; // set trace flag (TF)
578 //*************************************************************************
581 //*************************************************************************
582 COMMAND_PROTOTYPE(SetBreakpoint
)
589 if(pArgs
->bNotTranslated
[0]==FALSE
)
593 addr
=pArgs
->Value
[0];
594 addrorg
=gCurrentOffset
;
595 segment
=gCurrentSelector
;
599 addrorg
=addr
=pArgs
->Value
[0];
603 if(InstallSWBreakpoint(GetLinearAddress(segment
,addr
),FALSE
,NULL
) )
605 PICE_sprintf(tempCmd
,"BP #%u set to %.4X:%.8X\n",0,segment
,addr
);
609 PICE_sprintf(tempCmd
,"BP #%u NOT set (either page not valid OR already used)\n",0);
611 Print(OUTPUT_WINDOW
,tempCmd
);
615 if(InstallVirtualSWBreakpoint((LPSTR
)pArgs
->Value
[0],(LPSTR
)pArgs
->Value
[1]) )
617 PICE_sprintf(tempCmd
,"BP #%u virtually set to %s!%s\n",0,(LPSTR
)pArgs
->Value
[0],(LPSTR
)pArgs
->Value
[1]);
621 PICE_sprintf(tempCmd
,"BP #%u NOT set (maybe no symbols loaded)\n",0);
623 Print(OUTPUT_WINDOW
,tempCmd
);
632 //*************************************************************************
635 //*************************************************************************
636 COMMAND_PROTOTYPE(ListBreakpoints
)
646 PICE_sprintf(tempCmd
,"(%u) %s %.4X:%.8X(linear %.8X)\n",i
,Bp
[i
].Active
?"*":" ",Bp
[i
].Segment
,Bp
[i
].Offset
,Bp
[i
].LinearAddress
);
647 Print(OUTPUT_WINDOW
,tempCmd
);
653 //*************************************************************************
654 // ClearBreakpoints()
656 //*************************************************************************
657 COMMAND_PROTOTYPE(ClearBreakpoints
)
661 if(pArgs
->Value
[0]<4)
663 Bp
[pArgs
->Value
[0]].Used
=Bp
[pArgs
->Value
[0]].Active
=FALSE
;
671 RemoveAllSWBreakpoints(FALSE
);
673 for(i
=0;i
<4;i
++)Bp
[i
].Used
=Bp
[i
].Active
=FALSE
;
679 //*************************************************************************
682 //*************************************************************************
683 COMMAND_PROTOTYPE(LeaveIce
)
685 // SetHardwareBreakPoints();
692 //*************************************************************************
695 //*************************************************************************
696 COMMAND_PROTOTYPE(ShowGdt
)
709 PICE_sprintf(tempCmd
,"Address=%.8X Limit=%.4X\n",(gdtr
[1]<<16)|(gdtr
[0]>>16),gdtr
[0]&0xFFFF);
710 Print(OUTPUT_WINDOW
,tempCmd
);
713 // make pointer to GDT
714 pGdt
=(PGDT
)(((ULONG
)(gdtr
[1]<<16))|((ULONG
)(gdtr
[0]>>16)));
717 ULONG limit
=((pGdt
[addr
].Limit_19_16
<<16)|pGdt
[addr
].Limit_15_0
);
719 addr
=pArgs
->Value
[0];
721 if(pGdt
[addr
>>3].Gran
)limit
=(limit
*4096)|0xfff;
723 if(!pGdt
[addr
>>3].DescType
)
724 pVerbose
= SystemSegmentTypes
[pGdt
[addr
>>3].SegType
];
726 pVerbose
= NonSystemSegmentTypes
[pGdt
[addr
>>3].SegType
];
728 PICE_sprintf(tempCmd
,"%.4X %.8X %.8X %s %u %s\n",
730 (pGdt
[addr
>>3].Base_31_24
<<24)|(pGdt
[addr
>>3].Base_23_16
<<16)|(pGdt
[addr
>>3].Base_15_0
),
732 pGdt
[addr
>>3].Present
?" P":"NP",
735 Print(OUTPUT_WINDOW
,tempCmd
);
737 else if(pArgs
->Count
==0)
739 for(i
=0;i
<((gdtr
[0]&0xFFFF)>>3);i
++)
741 ULONG limit
=((pGdt
[i
].Limit_19_16
<<16)|pGdt
[i
].Limit_15_0
);
743 if(!pGdt
[i
].DescType
)
744 pVerbose
= SystemSegmentTypes
[pGdt
[i
].SegType
];
746 pVerbose
= NonSystemSegmentTypes
[pGdt
[i
].SegType
];
748 if(pGdt
[i
].Gran
)limit
=(limit
*4096)|0xfff;
750 PICE_sprintf(tempCmd
,"%.4X %.8X %.8X %s %u %s\n",
752 (pGdt
[i
].Base_31_24
<<24)|(pGdt
[i
].Base_23_16
<<16)|(pGdt
[i
].Base_15_0
),
754 pGdt
[i
].Present
?" P":"NP",
757 Print(OUTPUT_WINDOW
,tempCmd
);
758 if(WaitForKey()==FALSE
)break;
764 //*************************************************************************
767 //*************************************************************************
768 void OutputIdtEntry(PIDT pIdt
,ULONG i
)
774 seg
= (USHORT
)pIdt
[i
].Selector
;
775 offset
= (pIdt
[i
].Offset_31_16
<<16)|(pIdt
[i
].Offset_15_0
);
777 switch(pIdt
[i
].DescType
)
781 PICE_sprintf(tempCmd
,"(%0.4X) %0.4X:%0.8X %u [task]\n",i
,
783 GetLinearAddress((USHORT
)seg
,0),
789 if(ScanExportsByAddress(&pSym
,GetLinearAddress((USHORT
)seg
,offset
)))
791 PICE_sprintf(tempCmd
,"(%0.4X) %0.4X:%0.8X %u [int] (%s)\n",i
,
799 PICE_sprintf(tempCmd
,"(%0.4X) %0.4X:%0.8X %u [int]\n",i
,
808 if(ScanExportsByAddress(&pSym
,GetLinearAddress((USHORT
)seg
,offset
)))
810 PICE_sprintf(tempCmd
,"(%0.4X) %0.4X:%0.8X %u [trap] (%s)\n",i
,
818 PICE_sprintf(tempCmd
,"(%0.4X) %0.4X:%0.8X %u [trap]\n",i
,
825 PICE_sprintf(tempCmd
,"(%0.4X) INVALID\n",i
);
828 Print(OUTPUT_WINDOW
,tempCmd
);
831 //*************************************************************************
834 //*************************************************************************
835 COMMAND_PROTOTYPE(ShowIdt
)
848 PICE_sprintf(tempCmd
,"Address=%.8X Limit=%.4X\n",(idtr
[1]<<16)|(idtr
[0]>>16),idtr
[0]&0xFFFF);
849 Print(OUTPUT_WINDOW
,tempCmd
);
851 // make pointer to GDT
852 pIdt
=(PIDT
)(((ULONG
)(idtr
[1]<<16))|((ULONG
)(idtr
[0]>>16)));
855 addr
=pArgs
->Value
[0];
859 else if(pArgs
->Count
==0)
861 for(i
=0;i
<((idtr
[0]&0xFFFF)>>3);i
++)
863 OutputIdtEntry(pIdt
,i
);
864 if(WaitForKey()==FALSE
)break;
871 //*************************************************************************
874 //*************************************************************************
875 COMMAND_PROTOTYPE(ShowHelp
)
879 PutStatusText("COMMAND KEYWORD DESCRIPTION");
880 for(j
=0;j
<COMMAND_GROUP_LAST
;j
++)
882 PICE_sprintf(tempCmd
,"= %-20s =====================================\n",CommandGroups
[j
]);
883 Print(OUTPUT_WINDOW
,tempCmd
);
886 for(i
=0;CmdTable
[i
].Cmd
!=NULL
;i
++)
888 if(CmdTable
[i
].CommandGroup
== j
)
890 PICE_sprintf(tempCmd
,"%-20s %s\n",CmdTable
[i
].Cmd
,CmdTable
[i
].Help
);
891 Print(OUTPUT_WINDOW
,tempCmd
);
892 if(WaitForKey()==FALSE
)return TRUE
;
899 //*************************************************************************
902 //*************************************************************************
903 COMMAND_PROTOTYPE(ShowPageDirs
)
909 PEPROCESS my_current
= IoGetCurrentProcess();
913 DPRINT((0,"ShowPageDirs(): my_current = %.8X\n",(ULONG
)my_current
));
915 // don't touch if not valid process
918 // no arguments supplied -> show all page directories
921 PutStatusText("Linear Physical Attributes");
922 // there are 1024 page directories each mapping 1024*4k of address space
925 ULONG ulAddress
= i
<<22;
926 // from the mm_struct get pointer to page directory for this address
927 pPGD
= ADDR_TO_PDE(ulAddress
);
928 // create a structurized pointer from PGD
929 pPageDir
= (PPAGEDIR
)pPGD
;
934 PICE_sprintf(tempCmd
,"%.8X-%.8X %.8X %s %s %s\n",
935 ulAddress
, ulAddress
+ 0x400000,
936 (pPageDir
->PTBase
<<12),
937 pPageDir
->P
?"P ":"NP",
938 pPageDir
->RW
?"RW":"R ",
939 pPageDir
->US
?"U":"S");
940 Print(OUTPUT_WINDOW
,tempCmd
);
942 if(WaitForKey()==FALSE
)break;
947 // one arg supplied -> show individual page
948 else if(pArgs
->Count
== 1)
950 pPGD
= ADDR_TO_PDE((ULONG
)pArgs
->Value
[0]);
952 DPRINT((0,"ShowPageDirs(): VA = %.8X\n",pArgs
->Value
[0]));
953 DPRINT((0,"ShowPageDirs(): pPGD = %.8X\n",(ULONG
)pPGD
));
955 if(pPGD
&& ((*pPGD
)&_PAGE_PRESENT
))
960 PPAGEDIR pPage
= (PPAGEDIR
)pPGD
;
962 PutStatusText("Linear Physical Attributes");
964 PICE_sprintf(tempCmd
,"%.8X %.8X %s %s %s (LARGE PAGE PTE @ %.8X)\n",
966 (pPage
->PTBase
<<12)|(pArgs
->Value
[0]&0x7FFFFF),
974 pPTE
= ADDR_TO_PTE(pArgs
->Value
[0]);
975 DPRINT((0,"ShowPageDirs(): pPTE = %.8X\n",(ULONG
)pPTE
));
978 PPAGEDIR pPage
= (PPAGEDIR
)pPTE
;
979 DPRINT((0,"ShowPageDirs(): pPage->PTBase = %.8X\n",(ULONG
)pPage
->PTBase
));
981 PutStatusText("Linear Physical Attributes");
983 PICE_sprintf(tempCmd
,"%.8X %.8X %s %s %s (PTE @ %.8X)\n",
985 (pPage
->PTBase
<<12)|(pArgs
->Value
[0]&(_PAGE_SIZE
-1)),
986 (pPage
->P
==1)?"P ":"NP",
993 Print(OUTPUT_WINDOW
,tempCmd
);
997 PICE_sprintf(tempCmd
,"page at %.8X not present.\n",pArgs
->Value
[0]);
998 Print(OUTPUT_WINDOW
,tempCmd
);
1006 //*************************************************************************
1009 //*************************************************************************
1010 COMMAND_PROTOTYPE(ShowProcesses
)
1012 PEPROCESS my_current
= IoGetCurrentProcess();
1013 PLIST_ENTRY current_entry
;
1014 PEPROCESS currentps
;
1018 current_entry
= pPsProcessListHead
->Flink
;
1020 if( current_entry
){
1022 PutStatusText("NAME TASK PID");
1024 while( current_entry
!= pPsProcessListHead
){
1025 currentps
= CONTAINING_RECORD(current_entry
,
1028 DPRINT((0,"currentps = %x\n",currentps
));
1029 //ei would be nice to mark current process!
1030 PICE_sprintf(tempCmd
,"%-16.16s %-12x %x\n",currentps
->ImageFileName
,
1031 (ULONG
)currentps
,currentps
->UniqueProcessId
);
1032 Print(OUTPUT_WINDOW
,tempCmd
);
1033 if(WaitForKey()==FALSE
)
1035 current_entry
= current_entry
->Flink
;
1042 //*************************************************************************
1043 // DisplayMemoryDword()
1045 //*************************************************************************
1046 COMMAND_PROTOTYPE(DisplayMemoryDword
)
1049 static ULONG addr
=0,addrorg
;
1050 static USHORT segment
;
1055 DPRINT((0,"DisplayMemoryDword()\n"));
1058 segment
=(USHORT
)pArgs
->Value
[0];
1059 if(!segment
)segment
=GLOBAL_DATA_SEGMENT
;
1060 addr
=pArgs
->Value
[1];
1061 OldSelector
= segment
;
1064 addr
=GetLinearAddress(segment
,addr
);
1066 else if(pArgs
->Count
==1)
1069 addr
=pArgs
->Value
[0];
1072 addr
=GetLinearAddress(segment
,addr
);
1074 else if(pArgs
->Count
==0)
1076 addr
+= sizeof(ULONG
)*4*4;
1080 if(ScanExportsByAddress(&pSymbolName
,addr
))
1082 PICE_sprintf(tempCmd
," %s ",pSymbolName
);
1083 SetForegroundColor(COLOR_TEXT
);
1084 SetBackgroundColor(COLOR_CAPTION
);
1085 PutChar(tempCmd
,GLOBAL_SCREEN_WIDTH
-1-PICE_strlen(tempCmd
),wWindow
[DATA_WINDOW
].y
-1);
1089 DisableScroll(DATA_WINDOW
);
1091 if(DisplayMemory
!= DisplayMemoryDword
)
1094 DisplayMemory
= DisplayMemoryDword
;
1099 for(k
=0;k
<wWindow
[DATA_WINDOW
].cy
;k
++) // 4 lines
1101 PICE_sprintf(tempCmd
,"%.4X:%.8X: ",segment
,addrorg
+k
*16);
1103 for(i
=0;i
<4;i
++) // 4 dwords
1107 for(j
=0;j
<4;j
++) // 1 dword = 4 bytes
1109 if(IsAddressValid(addr
+i
*4+j
+k
*16))
1111 PICE_sprintf(temp
,"%.2x",*(PUCHAR
)(addr
+i
*4+j
+k
*16));
1113 PICE_strcat(tempCmd
,temp
);
1117 PICE_strcat(tempCmd
,"??");
1120 PICE_strrev(tempCmd
);
1125 for(j
=0;j
<16;j
++) // 1 dword = 4 bytes
1127 wWindow
[DATA_WINDOW
].usCurX
= GLOBAL_SCREEN_WIDTH
-17;
1128 if(IsAddressValid(addr
+j
+k
*16))
1130 PICE_sprintf(temp
,"%c",PICE_isprint(*(PUCHAR
)(addr
+j
+k
*16))?(*(PUCHAR
)(addr
+j
+k
*16)):'.');
1131 PICE_strcat(tempCmd
,temp
);
1135 PICE_strcat(tempCmd
,"?");
1141 EnableScroll(DATA_WINDOW
);
1146 //*************************************************************************
1147 // DisplayMemoryByte()
1149 //*************************************************************************
1150 COMMAND_PROTOTYPE(DisplayMemoryByte
)
1153 static ULONG addr
=0,addrorg
;
1154 static USHORT segment
;
1160 segment
=(USHORT
)pArgs
->Value
[0];
1161 if(!segment
)segment
=GLOBAL_DATA_SEGMENT
;
1162 addr
=pArgs
->Value
[1];
1163 OldSelector
= segment
;
1166 addr
=GetLinearAddress(segment
,addr
);
1168 else if(pArgs
->Count
==1)
1171 addr
=pArgs
->Value
[0];
1174 addr
=GetLinearAddress(segment
,addr
);
1176 else if(pArgs
->Count
==0)
1178 addr
+= sizeof(ULONG
)*4*4;
1182 if(DisplayMemory
!= DisplayMemoryByte
)
1185 DisplayMemory
= DisplayMemoryByte
;
1190 if(ScanExportsByAddress(&pSymbolName
,addr
))
1192 PICE_sprintf(tempCmd
," %s ",pSymbolName
);
1193 SetForegroundColor(COLOR_TEXT
);
1194 SetBackgroundColor(COLOR_CAPTION
);
1195 PutChar(tempCmd
,GLOBAL_SCREEN_WIDTH
-1-PICE_strlen(tempCmd
),wWindow
[DATA_WINDOW
].y
-1);
1199 DisableScroll(DATA_WINDOW
);
1200 for(k
=0;k
<wWindow
[DATA_WINDOW
].cy
;k
++) // 4 lines
1202 PICE_sprintf(tempCmd
,"%.4X:%.8X: ",segment
,addrorg
+k
*16);
1206 for(j
=0;j
<16;j
++) // 1 dword = 4 bytes
1208 if(IsAddressValid(addr
+j
+k
*16))
1210 PICE_sprintf(temp
,"%.2x ",*(PUCHAR
)(addr
+j
+k
*16));
1211 PICE_strcat(tempCmd
,temp
);
1215 PICE_strcat(tempCmd
,"?? ");
1221 for(j
=0;j
<16;j
++) // 1 dword = 4 bytes
1223 wWindow
[DATA_WINDOW
].usCurX
= GLOBAL_SCREEN_WIDTH
-17;
1224 if(IsAddressValid(addr
+j
+k
*16))
1226 PICE_sprintf(temp
,"%c",PICE_isprint(*(PUCHAR
)(addr
+j
+k
*16))?(*(PUCHAR
)(addr
+j
+k
*16)):'.');
1227 PICE_strcat(tempCmd
,temp
);
1231 PICE_strcat(tempCmd
,"?");
1237 EnableScroll(DATA_WINDOW
);
1242 //*************************************************************************
1243 // DisplayPhysMemDword()
1245 //*************************************************************************
1246 COMMAND_PROTOTYPE(DisplayPhysMemDword
)
1249 static ULONG addr
=0,addrorg
;
1250 static USHORT segment
;
1254 DPRINT((0,"DisplayPhysMemDword()\n"));
1259 addr
=pArgs
->Value
[0];
1262 addr
=GetLinearAddress(segment
,addr
);
1264 else if(pArgs
->Count
==0)
1266 addr
+= sizeof(ULONG
)*4*4;
1270 DisableScroll(DATA_WINDOW
);
1272 if(DisplayMemory
!= DisplayPhysMemDword
)
1275 DisplayMemory
= DisplayPhysMemDword
;
1280 for(k
=0;k
<wWindow
[DATA_WINDOW
].cy
;k
++) // 4 lines
1282 PICE_sprintf(tempCmd
,"PHYS:%.8X: ",addrorg
+k
*16);
1284 for(i
=0;i
<4;i
++) // 4 dwords
1287 PICE_sprintf(tempCmd
," %.8X",ReadPhysMem(addr
+i
*4+k
*16,sizeof(ULONG
)));
1292 for(j
=0;j
<16;j
++) // 1 dword = 4 bytes
1295 wWindow
[DATA_WINDOW
].usCurX
= GLOBAL_SCREEN_WIDTH
-17;
1296 ucData
= ReadPhysMem(addr
+j
+k
*16,sizeof(UCHAR
));
1297 PICE_sprintf(temp
,"%c",PICE_isprint(ucData
)?ucData
:'.');
1298 PICE_strcat(tempCmd
,temp
);
1303 EnableScroll(DATA_WINDOW
);
1309 //*************************************************************************
1310 // DisplaySourceFile()
1312 //*************************************************************************
1313 void DisplaySourceFile(LPSTR pSrcLine
,LPSTR pSrcEnd
,ULONG ulLineNumber
,ULONG ulLineNumberToInvert
)
1317 ULONG j
= ulLineNumber
-1;
1319 DPRINT((0,"DisplaySourceFile(%.8X,%u,%u)\n",pSrcLine
,ulLineNumber
,ulLineNumberToInvert
));
1324 // goto end of current line
1325 while(*pSrcLine
!=0x0a && *pSrcLine
!=0x0d)
1328 // skip over the line end
1329 if(*pSrcLine
== 0x0d)
1331 if(*pSrcLine
== 0x0a)
1335 Clear(SOURCE_WINDOW
);
1336 DisableScroll(SOURCE_WINDOW
);
1337 for(i
=0;i
<wWindow
[SOURCE_WINDOW
].cy
;i
++)
1341 if(pSrcLine
<pSrcEnd
)
1343 PICE_sprintf(tempCmd
,".%.5u ",ulLineNumber
+i
);
1344 pTemp
= tempCmd
+ PICE_strlen(tempCmd
);
1346 while(pSrcLine
<pSrcEnd
&& *pSrcLine
!=0x0a && *pSrcLine
!=0x0d)
1348 if(*pSrcLine
==0x9) // TAB
1358 *pTemp
++ = *pSrcLine
++;
1362 if(pSrcLine
<pSrcEnd
)
1364 // skip over the line end
1365 if(*pSrcLine
== 0x0d)
1367 if(*pSrcLine
== 0x0a)
1374 if(PICE_strlen(tempCmd
)>GLOBAL_SCREEN_WIDTH
-1)
1376 tempCmd
[GLOBAL_SCREEN_WIDTH
-2]='\n';
1377 tempCmd
[GLOBAL_SCREEN_WIDTH
-1]=0;
1380 if( (ulLineNumberToInvert
!=-1) &&
1381 ((int)(ulLineNumberToInvert
-ulLineNumber
)>=0) &&
1382 ((ulLineNumberToInvert
-ulLineNumber
)<wWindow
[SOURCE_WINDOW
].cy
) &&
1383 (i
==(ulLineNumberToInvert
-ulLineNumber
)) )
1385 SetForegroundColor(COLOR_BACKGROUND
);
1386 SetBackgroundColor(COLOR_FOREGROUND
);
1389 Print(SOURCE_WINDOW
,tempCmd
);
1391 if( (ulLineNumberToInvert
!=-1) &&
1392 ((int)(ulLineNumberToInvert
-ulLineNumber
)>=0) &&
1393 ((ulLineNumberToInvert
-ulLineNumber
)<wWindow
[SOURCE_WINDOW
].cy
) &&
1394 (i
==(ulLineNumberToInvert
-ulLineNumber
)) )
1402 Print(SOURCE_WINDOW
,"---- End of source file --------------\n");
1406 EnableScroll(SOURCE_WINDOW
);
1409 //*************************************************************************
1410 // UnassembleOneLineDown()
1412 //*************************************************************************
1413 void UnassembleOneLineDown(void)
1417 DPRINT((0,"UnassembleOneLineDown()\n"));
1419 addrorg
= addr
= GetLinearAddress(usOldDisasmSegment
,ulOldDisasmOffset
);
1421 DPRINT((0,"UnassembleOneLineDown(): addr = %.8X\n",addr
));
1424 Disasm(&addr
,tempCmd
);
1426 DPRINT((0,"UnassembleOneLineDown(): addr after = %.8X\n",addr
));
1428 ulOldDisasmOffset
+= (addr
- addrorg
);
1432 //*************************************************************************
1433 // UnassembleOnePageDown()
1435 //*************************************************************************
1436 void UnassembleOnePageDown(ULONG page
)
1438 ULONG addr
,addrorg
,i
;
1440 DPRINT((0,"UnassembleOnePageDown()\n"));
1442 addrorg
= addr
= GetLinearAddress(usOldDisasmSegment
,ulOldDisasmOffset
);
1444 DPRINT((0,"UnassembleOnePageDown(): addr = %.8X\n",addr
));
1448 Disasm(&addr
,tempCmd
);
1450 DPRINT((0,"UnassembleOnePageDown(): addr after = %.8X\n",addr
));
1452 ulOldDisasmOffset
+= (addr
- addrorg
);
1456 //*************************************************************************
1457 // UnassembleOneLineUp()
1459 //*************************************************************************
1460 void UnassembleOneLineUp(void)
1462 ULONG addr
,addrorg
,addrbefore
,start
,end
,addrstart
;
1466 DPRINT((0,"UnassembleOneLineUp()\n"));
1468 addrorg
= addr
= GetLinearAddress(usOldDisasmSegment
,ulOldDisasmOffset
);
1470 DPRINT((0,"UnassembleOneLineUp(): addrorg = %.8X\n",addr
));
1474 if((pSymbol
= FindFunctionByAddress(addrorg
-offset
,&start
,&end
)) )
1476 offset
= addrorg
- start
;
1477 DPRINT((0,"UnassembleOneLineUp(): %s @ offset = %u\n",pSymbol
,offset
));
1481 // max instruction length is 15 bytes
1485 addrstart
= addrorg
;
1487 // start at current address less offset
1488 addr
= addrorg
- offset
;
1491 DPRINT((0,"UnassembleOneLineUp(): offset = %u addrorg %x addr %x\n",offset
,addrorg
,addr
));
1492 // disassemble while not reaching current instruction
1495 Disasm(&addr
,tempCmd
);
1496 DPRINT((0,"%.8X: %s\n",addrbefore
,tempCmd
));
1497 }while((addr
!= addrorg
) && (addrbefore
< addrorg
));
1499 if((addrorg
- addrstart
)<=0)
1500 ulOldDisasmOffset
--;
1502 ulOldDisasmOffset
-= (addrorg
- addrbefore
);
1504 DPRINT((0,"UnassembleOneLineUp(): new addr = %.4X:%.8X\n",usOldDisasmSegment
,ulOldDisasmOffset
));
1509 //*************************************************************************
1510 // UnassembleOneLineUp()
1512 //*************************************************************************
1513 void UnassembleOnePageUp(ULONG page
)
1515 ULONG addr
,addrorg
,addrbefore
,start
,end
,i
,addrstart
;
1519 DPRINT((0,"UnassembleOnePageUp()\n"));
1523 addrorg
= addr
= GetLinearAddress(usOldDisasmSegment
,ulOldDisasmOffset
);
1525 DPRINT((0,"UnassembleOnePageUp(): addrorg = %.8X\n",addr
));
1529 if((pSymbol
= FindFunctionByAddress(addrorg
-offset
,&start
,&end
)) )
1531 offset
= addrorg
- start
;
1532 DPRINT((0,"UnassembleOnePageUp(): %s @ offset = %u\n",pSymbol
,offset
));
1536 // max instruction length is 15 bytes
1540 // start at current address less offset
1541 addr
= addrorg
- offset
;
1542 addrstart
= addrorg
;
1545 DPRINT((0,"UnassembleOnePageUp(): offset = %u addrorg %x addr %x\n",offset
,addrorg
,addr
));
1547 // disassemble while not reaching current instruction
1549 Disasm(&addr
,tempCmd
);
1550 DPRINT((0,"%.8X: %s\n",addrbefore
,tempCmd
));
1551 }while((addr
!= addrorg
) && (addrbefore
< addrorg
));
1553 if((addrorg
- addrstart
)<=0)
1554 ulOldDisasmOffset
--;
1556 ulOldDisasmOffset
-= (addrorg
- addrbefore
);
1560 DPRINT((0,"UnassembleOnePageUp(): new addr = %.4X:%.8X\n",usOldDisasmSegment
,ulOldDisasmOffset
));
1565 //*************************************************************************
1568 //*************************************************************************
1569 COMMAND_PROTOTYPE(Unassemble
)
1572 ULONG addr
=0,addrorg
,addrstart
,ulLineNumber
;
1576 BOOLEAN bSWBpAtAddr
;
1577 LPSTR pSrc
,pFilename
,pSrcStart
,pSrcEnd
;
1578 BOOLEAN bForceDisassembly
= FALSE
;
1580 DPRINT((0,"Unassemble: CountSwitches: %u, count: %u\n", pArgs
->CountSwitches
, pArgs
->Count
));
1581 if(pArgs
->CountSwitches
>1)
1584 if(pArgs
->CountSwitches
==1)
1586 if(pArgs
->Switch
[0] == 'f')
1587 bForceDisassembly
= TRUE
;
1593 addr
=pArgs
->Value
[1];
1594 segment
=(USHORT
)pArgs
->Value
[0];
1595 addrorg
=addrstart
=addr
;
1596 addr
=GetLinearAddress(segment
,addr
);
1598 usOldDisasmSegment
= segment
;
1599 ulOldDisasmOffset
= addr
;
1601 else if(pArgs
->Count
==1)
1603 addr
=pArgs
->Value
[0];
1605 addrorg
=addrstart
=addr
;
1606 addr
=GetLinearAddress(segment
,addr
);
1608 usOldDisasmSegment
= segment
;
1609 ulOldDisasmOffset
= addr
;
1611 else if(pArgs
->Count
==0)
1613 segment
= usOldDisasmSegment
;
1614 addrorg
=addrstart
=addr
;
1615 addr
= GetLinearAddress(usOldDisasmSegment
,ulOldDisasmOffset
);
1621 DPRINT((0,"Unassemble(%0.4X:%0.8X), lastst: %x, lastend:%x\n",segment
,addr
,ulLastDisassStartAddress
,ulLastDisassEndAddress
));
1626 DisableScroll(SOURCE_WINDOW
);
1628 // if we're inside last disassembly range we only need to move to highlight
1629 if(ulLastDisassStartAddress
&& ulLastDisassEndAddress
&& addr
>=ulLastDisassStartAddress
&&
1630 addr
<ulLastDisassEndAddress
)
1632 addr
=ulLastDisassStartAddress
;
1636 ulLastDisassStartAddress
=ulLastDisassEndAddress
=0;
1639 SetForegroundColor(COLOR_TEXT
);
1640 SetBackgroundColor(COLOR_CAPTION
);
1642 ClrLine(wWindow
[SOURCE_WINDOW
].y
-1);
1646 if(ScanExportsByAddress(&pSymbolName
,addr
))
1648 SetForegroundColor(COLOR_TEXT
);
1649 SetBackgroundColor(COLOR_CAPTION
);
1650 PICE_sprintf(tempCmd
," %s ",pSymbolName
);
1651 PutChar(tempCmd
,GLOBAL_SCREEN_WIDTH
-1-PICE_strlen(tempCmd
),wWindow
[SOURCE_WINDOW
].y
-1);
1655 pCurrentMod
= FindModuleFromAddress(addr
);
1659 DPRINT((0,"Unassemble(): pCurrentMod->name = %S\n",pCurrentMod
->name
));
1660 mod_addr
= (ULONG
)pCurrentMod
->BaseAddress
;
1662 pCurrentSymbols
= FindModuleSymbols(mod_addr
);
1663 DPRINT((0,"Unassemble(): pCurrentSymbols = %x\n",(ULONG
)pCurrentSymbols
));
1665 DPRINT((0,"Unassemble(): pCurrentMod = %x, showsrc: %d\n",pCurrentMod
, bShowSrc
));
1667 ulCurrentlyDisplayedLineNumber
= 0;
1669 if(bShowSrc
&& bForceDisassembly
== FALSE
&& (pSrc
= FindSourceLineForAddress(addr
,&ulLineNumber
,&pSrcStart
,&pSrcEnd
,&pFilename
)) )
1671 DPRINT((0,"FoundSourceLineForAddress: file: %s line: %d\n", pFilename
, ulLineNumber
));
1672 PICE_strcpy(szCurrentFile
,pFilename
);
1674 ulCurrentlyDisplayedLineNumber
= ulLineNumber
;
1676 Clear(SOURCE_WINDOW
);
1678 // display file name
1679 SetForegroundColor(COLOR_TEXT
);
1680 SetBackgroundColor(COLOR_CAPTION
);
1682 if(PICE_strlen(pFilename
)<GLOBAL_SCREEN_WIDTH
/2)
1684 PutChar(pFilename
,1,wWindow
[SOURCE_WINDOW
].y
-1);
1690 p
= strrchr(pFilename
,'/');
1700 PutChar(p
,1,wWindow
[SOURCE_WINDOW
].y
-1);
1705 // display the source
1706 if(ulLineNumber
>(wWindow
[SOURCE_WINDOW
].cy
/2) )
1708 DisplaySourceFile(pSrcStart
,pSrcEnd
,ulLineNumber
-(wWindow
[SOURCE_WINDOW
].cy
/2),ulLineNumber
);
1712 DisplaySourceFile(pSrcStart
,pSrcEnd
,ulLineNumber
,ulLineNumber
);
1718 DPRINT((0,"Couldn't find source for file\n"));
1719 Home(SOURCE_WINDOW
);
1720 // for each line in the disassembly window
1721 for(i
=0;i
<wWindow
[SOURCE_WINDOW
].cy
;i
++)
1723 extern ULONG ulWindowOffset
;
1725 bSWBpAtAddr
= FALSE
;
1726 // if there is a potential SW breakpoint at address
1727 // we might have to put back the original opcode
1728 // in order to disassemble correctly.
1729 if(IsSwBpAtAddress(addr
))
1731 // if INT3 is there, remove it while disassembling
1732 if((bSWBpAtAddr
= IsSwBpAtAddressInstalled(addr
)))
1734 DeInstallSWBreakpoint(addr
);
1738 ClrLine(wWindow
[SOURCE_WINDOW
].y
+i
);
1740 // invert the line that we're about to execute
1741 if(addr
==CurrentEIP
)
1743 SetForegroundColor(COLOR_BACKGROUND
);
1744 SetBackgroundColor(COLOR_FOREGROUND
);
1745 ulLastInvertedAddress
= CurrentEIP
;
1748 // output segment:offset address
1749 PICE_sprintf(tempCmd
,"%0.4X:%0.8X ",segment
,addr
);
1750 Print(SOURCE_WINDOW
,tempCmd
);
1752 // disassemble a line
1757 Disasm(&addr
,&tempCmd
[30]);
1762 Disasm(&addr
,tempCmd
);
1764 addrorg
+=(addr
-addrbefore
);
1766 // want to display opcode bytes
1773 if(j
<addr
-addrbefore
)
1775 if(IsAddressValid(addrbefore
+j
))
1777 tempCmd
[j
*2]=HexDigit
[((*(PUCHAR
)(addrbefore
+j
)&0xF0)>>4)];
1778 tempCmd
[j
*2+1]=HexDigit
[((*(PUCHAR
)(addrbefore
+j
)&0xF))];
1793 PICE_strcat(tempCmd
,"\n");
1797 LONG len
= PICE_strlen(tempCmd
);
1798 if(ulWindowOffset
< len
)
1799 PICE_memcpy(tempCmd
,&tempCmd
[ulWindowOffset
],len
-ulWindowOffset
);
1804 Print(SOURCE_WINDOW
,tempCmd
);
1806 if(addrbefore
==CurrentEIP
)
1811 // if potential SW breakpoint, undo marked text
1812 if(IsSwBpAtAddress(addrbefore
))
1814 HatchLine(wWindow
[SOURCE_WINDOW
].y
+i
);
1817 // if breakpoint was installed before disassembly, put it back
1820 ReInstallSWBreakpoint(addrbefore
);
1825 if(ulLastDisassStartAddress
==0 && ulLastDisassEndAddress
==0)
1827 ulLastDisassStartAddress
=addrstart
;
1828 ulLastDisassEndAddress
=addr
;
1831 if(!IsAddressValid(addrstart
))
1833 ulLastDisassStartAddress
=0;
1834 ulLastDisassEndAddress
=0;
1839 EnableScroll(SOURCE_WINDOW
);
1844 //*************************************************************************
1847 //*************************************************************************
1848 COMMAND_PROTOTYPE(ShowModules
)
1851 DPRINT((0,"ShowModules()\n"));
1853 if(BuildModuleList())
1855 pMod
= pdebug_module_head
;
1860 if(pMod
== pCurrentMod
)
1862 PICE_sprintf(tempCmd
,"%.8X - %.8X *%-32S\n",
1863 (unsigned int)pMod
->BaseAddress
,
1864 (unsigned int) ((unsigned int)pMod
->BaseAddress
+pMod
->size
),pMod
->name
);
1868 PICE_sprintf(tempCmd
,"%.8X - %.8X %-32S\n",
1869 (unsigned int)pMod
->BaseAddress
,
1870 (unsigned int) ((unsigned int)pMod
->BaseAddress
+pMod
->size
),
1874 Print(OUTPUT_WINDOW
,tempCmd
);
1875 if(WaitForKey()==FALSE
)
1877 }while((pMod
= pMod
->next
)!=pdebug_module_tail
);
1882 //*************************************************************************
1885 //*************************************************************************
1886 //ei FIX THIS!!!!!!!!!!!!!!!!!!
1887 LPSTR
DecodeVmFlags(ULONG flags
)
1891 #define VM_READ 0x0001
1892 #define VM_WRITE 0x0002
1893 #define VM_EXEC 0x0004
1894 #define VM_SHARED 0x0008
1896 #define VM_MAYREAD 0x0010
1897 #define VM_MAYWRITE 0x0020
1898 #define VM_MAYEXEC 0x0040
1899 #define VM_MAYSHARE 0x0080
1901 #define VM_GROWSDOWN 0x0100
1902 #define VM_GROWSUP 0x0200
1903 #define VM_SHM 0x0400
1904 #define VM_DENYWRITE 0x0800
1906 #define VM_EXECUTABLE 0x1000
1907 #define VM_LOCKED 0x2000
1908 #define VM_IO 0x4000
1910 #define VM_STACK_FLAGS 0x0177
1912 static LPSTR flags_syms_on
[]={"R","W","X","S","MR","MW","MX","MS","GD","GU","SHM","exe","LOCK","IO",""};
1913 static char temp
[256];
1920 if(flags
== VM_STACK_FLAGS
)
1922 PICE_strcpy(temp
," (STACK)");
1930 PICE_strcat(temp
," ");
1931 PICE_strcat(temp
,flags_syms_on
[i
]);
1940 //*************************************************************************
1941 // ShowVirtualMemory()
1943 //*************************************************************************
1944 COMMAND_PROTOTYPE(ShowVirtualMemory
)
1946 PEPROCESS my_current
= IoGetCurrentProcess();
1947 PLIST_ENTRY current_entry
;
1948 PMADDRESS_SPACE vma
= NULL
;
1949 MEMORY_AREA
* current
;
1952 DPRINT((0,"ShowVirtualMemory()\n"));
1954 vma
= &(my_current
->AddressSpace
);
1959 if(pArgs
->Count
== 0)
1961 PutStatusText("START END LENGTH VMA TYPE ATTR");
1962 current_entry
= vma
->MAreaListHead
.Flink
;
1963 while (current_entry
!= &vma
->MAreaListHead
)
1967 current
= CONTAINING_RECORD(current_entry
,
1970 // find the filename
1971 if(((current
->Type
== MEMORY_AREA_SECTION_VIEW
) ) &&
1972 current
->Data
.SectionData
.Section
->FileObject
)
1974 if(IsAddressValid((ULONG
)current
->Data
.SectionData
.Section
->FileObject
->FileName
.Buffer
) )
1975 PICE_sprintf(filename
,"%.64S",current
->Data
.SectionData
.Section
->FileObject
->FileName
.Buffer
);
1978 PICE_sprintf(tempCmd
,"%.8X %.8X %.8X %.8X %x %x %s\n",
1979 (ULONG
)current
->BaseAddress
,
1980 (ULONG
)current
->BaseAddress
+current
->Length
,
1983 current
->Type
, current
->Attributes
,//DecodeVmFlags(current->Type, current->Attributes),
1985 Print(OUTPUT_WINDOW
,tempCmd
);
1987 if(WaitForKey()==FALSE
)
1989 current_entry
= current_entry
->Flink
;
1992 if( vma
== &(my_current
->AddressSpace
) )
1993 vma
= my_init_mm
; // switch to kernel memory area
1994 else vma
= 0; // if we already did kernel, end loop
1999 //*************************************************************************
2002 //*************************************************************************
2003 COMMAND_PROTOTYPE(Ver
)
2005 //ei add kernel version info??!!
2006 PICE_sprintf(tempCmd
,"pICE: version %u.%u (build %u) for Reactos\n",
2011 Print(OUTPUT_WINDOW
,tempCmd
);
2013 /* PICE_sprintf(tempCmd,"pICE: loaded on %s kernel release %s\n",
2014 system_utsname.sysname,
2015 system_utsname.release);
2017 Print(OUTPUT_WINDOW
,tempCmd
);
2018 Print(OUTPUT_WINDOW
,"pICE: written by Klaus P. Gerlicher and Goran Devic.\n");
2019 Print(OUTPUT_WINDOW
,"pICE: ported to Reactos by Eugene Ingerman.\n");
2024 //*************************************************************************
2027 //*************************************************************************
2028 COMMAND_PROTOTYPE(Hboot
)
2030 // nudge the reset line through keyboard controller
2032 movb $0xFE,%al\n\t \
2038 //*************************************************************************
2041 //*************************************************************************
2042 COMMAND_PROTOTYPE(SetSrcDisplay
)
2048 bShowSrc
=bShowSrc
?FALSE
:TRUE
;
2049 PICE_memset(&Args
,0,sizeof(ARGS
));
2050 // make unassembler refresh all again
2051 ulLastDisassStartAddress
=ulLastDisassEndAddress
=0;
2058 //*************************************************************************
2061 //*************************************************************************
2062 COMMAND_PROTOTYPE(I3here
)
2066 if(pArgs
->Value
[0]==1)
2071 Print(OUTPUT_WINDOW
,"I3HERE is now ON\n");
2074 Print(OUTPUT_WINDOW
,"I3HERE is already ON\n");
2076 else if(pArgs
->Value
[0]==0)
2081 Print(OUTPUT_WINDOW
,"I3HERE is now OFF\n");
2084 Print(OUTPUT_WINDOW
,"I3HERE is already OFF\n");
2087 else if(pArgs
->Count
==0)
2091 Print(OUTPUT_WINDOW
,"I3HERE is ON\n");
2095 Print(OUTPUT_WINDOW
,"I3HERE is OFF\n");
2102 COMMAND_PROTOTYPE(I1here
)
2106 if(pArgs
->Value
[0]==1)
2111 Print(OUTPUT_WINDOW
,"I1HERE is now ON\n");
2114 Print(OUTPUT_WINDOW
,"I1HERE is already ON\n");
2116 else if(pArgs
->Value
[0]==0)
2121 Print(OUTPUT_WINDOW
,"I1HERE is now OFF\n");
2124 Print(OUTPUT_WINDOW
,"I1HERE is already OFF\n");
2127 else if(pArgs
->Count
==0)
2131 Print(OUTPUT_WINDOW
,"I1HERE is ON\n");
2135 Print(OUTPUT_WINDOW
,"I1HERE is OFF\n");
2142 COMMAND_PROTOTYPE(NextInstr
)
2144 static char tempDisasm
[256];
2145 ULONG addr
,addrbefore
;
2147 bNeedToFillBuffer
=FALSE
;
2151 addr
=addrbefore
=GetLinearAddress(CurrentCS
,CurrentEIP
);
2152 DPRINT((0,"addr before %.8X\n",addrbefore
));
2153 Disasm(&addr
,tempDisasm
);
2154 DPRINT((0,"addr after %.8X\n",addr
));
2155 CurrentEIP
=CurrentEIP
+(addr
-addrbefore
);
2156 // display register contents
2159 DPRINT((0,"new CS:EIP %04.x:%.8X\n",CurrentCS
,CurrentEIP
));
2160 PICE_memset(pArgs
,0,sizeof(ARGS
));
2161 // make unassembler refresh all again
2162 ulLastDisassStartAddress
=ulLastDisassEndAddress
=0;
2164 pArgs
->Value
[0]=(ULONG
)CurrentCS
;
2165 pArgs
->Value
[1]=CurrentEIP
;
2168 bNeedToFillBuffer
=TRUE
;
2172 COMMAND_PROTOTYPE(SetGetRegisters
)
2178 // display whole set
2179 for(i
=0;RegKeyWords
[i
].pValue
!=0;i
++)
2181 switch(RegKeyWords
[i
].ulSize
)
2184 PICE_sprintf(tempCmd
,"%s = %.8X\n",RegKeyWords
[i
].KeyWord
,*(PUCHAR
)(RegKeyWords
[i
].pValue
));
2187 PICE_sprintf(tempCmd
,"%s = %.8X\n",RegKeyWords
[i
].KeyWord
,*(PUSHORT
)(RegKeyWords
[i
].pValue
));
2190 PICE_sprintf(tempCmd
,"%s = %.8X\n",RegKeyWords
[i
].KeyWord
,*(PULONG
)(RegKeyWords
[i
].pValue
));
2193 Print(OUTPUT_WINDOW
,tempCmd
);
2194 if(WaitForKey()==FALSE
)break;
2197 else if(pArgs
->Count
==1)
2199 // display selected register
2200 for(i
=0;RegKeyWords
[i
].pValue
!=0;i
++)
2202 if(PICE_strcmpi(pArgs
->pToken
[0],RegKeyWords
[i
].KeyWord
)==0)
2204 switch(RegKeyWords
[i
].ulSize
)
2207 PICE_sprintf(tempCmd
,"%s = %.2X\n",RegKeyWords
[i
].KeyWord
,*(PUCHAR
)(RegKeyWords
[i
].pValue
));
2210 PICE_sprintf(tempCmd
,"%s = %.4X\n",RegKeyWords
[i
].KeyWord
,*(PUSHORT
)(RegKeyWords
[i
].pValue
));
2213 PICE_sprintf(tempCmd
,"%s = %.8X\n",RegKeyWords
[i
].KeyWord
,*(PULONG
)(RegKeyWords
[i
].pValue
));
2216 Print(OUTPUT_WINDOW
,tempCmd
);
2221 else if(pArgs
->Count
==2)
2223 // set selected register to value
2224 for(i
=0;RegKeyWords
[i
].pValue
!=0;i
++)
2226 if(PICE_strcmpi(pArgs
->pToken
[0],RegKeyWords
[i
].KeyWord
)==0)
2228 switch(RegKeyWords
[i
].ulSize
)
2231 *(PUCHAR
)(RegKeyWords
[i
].pValue
)=(UCHAR
)pArgs
->Value
[1];
2234 *(PUSHORT
)(RegKeyWords
[i
].pValue
)=(USHORT
)pArgs
->Value
[1];
2237 *(PULONG
)(RegKeyWords
[i
].pValue
)=(ULONG
)pArgs
->Value
[1];
2249 //*************************************************************************
2252 //*************************************************************************
2253 COMMAND_PROTOTYPE(SetCodeDisplay
)
2259 bCodeOn
=bCodeOn
?FALSE
:TRUE
;
2261 PICE_memset(&Args
,0,sizeof(ARGS
));
2263 // make unassembler refresh all again
2264 ulLastDisassStartAddress
=ulLastDisassEndAddress
=0;
2267 else if(pArgs
->Count
==1)
2269 bCodeOn
=(pArgs
->Value
[0]==0)?FALSE
:TRUE
;
2271 PICE_memset(&Args
,0,sizeof(ARGS
));
2273 // make unassembler refresh all again
2274 ulLastDisassStartAddress
=ulLastDisassEndAddress
=0;
2280 //*************************************************************************
2283 //*************************************************************************
2284 COMMAND_PROTOTYPE(ShowCPU
)
2288 for(i
=0;CPUInfo
[i
].pValue
!=NULL
;i
++)
2290 PICE_sprintf(tempCmd
,"%s = %.8X\n",CPUInfo
[i
].Name
,*(CPUInfo
[i
].pValue
));
2291 Print(OUTPUT_WINDOW
,tempCmd
);
2292 if(WaitForKey()==FALSE
)break;
2297 //*************************************************************************
2300 //*************************************************************************
2301 COMMAND_PROTOTYPE(WalkStack
)
2305 IntelStackWalk(CurrentEIP
,CurrentEBP
,CurrentESP
);
2311 //*************************************************************************
2314 //*************************************************************************
2315 COMMAND_PROTOTYPE(PokeDword
)
2320 ulData
= ReadPhysMem(pArgs
->Value
[1],sizeof(ULONG
));
2321 PICE_sprintf(tempCmd
,"value @ %.8X was %.8X\n",pArgs
->Value
[1],ulData
);
2322 Print(OUTPUT_WINDOW
,tempCmd
);
2325 WritePhysMem(pArgs
->Value
[1],pArgs
->Value
[2],sizeof(ULONG
));
2328 ulData
= ReadPhysMem(pArgs
->Value
[1],sizeof(ULONG
));
2329 PICE_sprintf(tempCmd
,"value @ %.8X = %.8X\n",pArgs
->Value
[1],ulData
);
2330 Print(OUTPUT_WINDOW
,tempCmd
);
2335 //*************************************************************************
2338 //*************************************************************************
2339 COMMAND_PROTOTYPE(PokeMemory
)
2341 DPRINT((0,"PokeMemory()\n"));
2342 DPRINT((0,"PokeMemory(): value[0] = %.8X value[1] = %.8X value[3] = %.8X count = %.8X\n",pArgs
->Value
[0],pArgs
->Value
[1],pArgs
->Value
[2],pArgs
->Count
));
2344 // must be three parameters
2345 if(pArgs
->Count
== 3)
2347 switch(pArgs
->Value
[0])
2350 return PokeDword(pArgs
);
2359 Print(OUTPUT_WINDOW
,"you need to supply a physical address and datum to write!\n");
2366 //*************************************************************************
2369 //*************************************************************************
2370 COMMAND_PROTOTYPE(PeekDword
)
2374 ulData
= ReadPhysMem(pArgs
->Value
[1],sizeof(ULONG
));
2375 PICE_sprintf(tempCmd
,"%.8X\n",ulData
);
2376 Print(OUTPUT_WINDOW
,tempCmd
);
2381 //*************************************************************************
2384 //*************************************************************************
2385 COMMAND_PROTOTYPE(PeekWord
)
2389 usData
= (USHORT
)ReadPhysMem(pArgs
->Value
[1],sizeof(USHORT
));
2390 PICE_sprintf(tempCmd
,"%.4X\n",usData
);
2391 Print(OUTPUT_WINDOW
,tempCmd
);
2396 //*************************************************************************
2399 //*************************************************************************
2400 COMMAND_PROTOTYPE(PeekByte
)
2404 ucData
= (UCHAR
)ReadPhysMem(pArgs
->Value
[1],sizeof(UCHAR
));
2405 PICE_sprintf(tempCmd
,"%.2X\n",ucData
);
2406 Print(OUTPUT_WINDOW
,tempCmd
);
2411 //*************************************************************************
2414 //*************************************************************************
2415 COMMAND_PROTOTYPE(PeekMemory
)
2417 DPRINT((0,"PeekMemory()\n"));
2418 DPRINT((0,"PeekMemory(): value[0] = %.8X value[1] = %.8X count = %.8X\n",pArgs
->Value
[0],pArgs
->Value
[1],pArgs
->Count
));
2420 if(pArgs
->Count
== 2)
2422 switch(pArgs
->Value
[0])
2425 return PeekByte(pArgs
);
2427 return PeekWord(pArgs
);
2429 return PeekDword(pArgs
);
2438 //*************************************************************************
2439 // UnassembleAtCurrentEip()
2441 //*************************************************************************
2442 COMMAND_PROTOTYPE(UnassembleAtCurrentEip
)
2444 PICE_memset(pArgs
,0,sizeof(ARGS
));
2446 pArgs
->Value
[0] = CurrentCS
;
2447 pArgs
->Value
[1] = CurrentEIP
;
2452 //*************************************************************************
2455 //*************************************************************************
2456 COMMAND_PROTOTYPE(SwitchTables
)
2460 DPRINT((0,"SwitchTables()\n"));
2462 // no arguments -> display load symbol tables
2465 for(i
=0;i
<DIM(apSymbols
);i
++)
2469 if(apSymbols
[i
] == pCurrentSymbols
)
2470 PICE_sprintf(tempCmd
,"*%-32S @ %.8X (%5u source files)\n",apSymbols
[i
]->name
,(ULONG
)apSymbols
[i
],apSymbols
[i
]->ulNumberOfSrcFiles
);
2472 PICE_sprintf(tempCmd
," %-32S @ %.8X (%5u source files)\n",apSymbols
[i
]->name
,(ULONG
)apSymbols
[i
],apSymbols
[i
]->ulNumberOfSrcFiles
);
2473 Print(OUTPUT_WINDOW
,tempCmd
);
2474 if(WaitForKey()==FALSE
)break;
2478 // 1 argument -> set new current symbols
2479 else if(pArgs
->Count
== 1)
2481 PDEBUG_MODULE pTempMod
;
2482 char temp
[DEBUG_MODULE_NAME_LEN
];
2484 pCurrentSymbols
= (PICE_SYMBOLFILE_HEADER
*)pArgs
->Value
[0];
2485 CopyWideToAnsi( temp
, pCurrentSymbols
->name
);
2487 DPRINT((0,"TableSwitchSym: pCurrentSymbols: %x, Name: %s\n", pCurrentSymbols
, temp
));
2489 pTempMod
= IsModuleLoaded(temp
);
2491 pCurrentMod
= pTempMod
;
2497 //*************************************************************************
2500 //*************************************************************************
2501 COMMAND_PROTOTYPE(SwitchFiles
)
2503 PICE_SYMBOLFILE_SOURCE
* pSrc
;
2507 DPRINT((0,"SwitchFiles()\n"));
2508 // no arguments -> show files for current symbols
2511 if(pCurrentSymbols
&& pCurrentSymbols
->ulNumberOfSrcFiles
)
2513 LPSTR pCurrentFile
=NULL
;
2515 // find out the current file name
2516 if(*szCurrentFile
!=0)
2518 if((pCurrentFile
= strrchr(szCurrentFile
,'/')) )
2524 pCurrentFile
= szCurrentFile
;
2528 pSrc
= (PICE_SYMBOLFILE_SOURCE
*)((ULONG
)pCurrentSymbols
+ pCurrentSymbols
->ulOffsetToSrcFiles
);
2530 for(i
=0;i
<pCurrentSymbols
->ulNumberOfSrcFiles
;i
++)
2534 if((p
= strrchr(pSrc
->filename
,'/')) )
2536 if(PICE_strcmpi(p
+1,pCurrentFile
)==0)
2537 PICE_sprintf(tempCmd
,"*%-32s @ %.8X\n",p
+1,(ULONG
)pSrc
);
2539 PICE_sprintf(tempCmd
," %-32s @ %.8X\n",p
+1,(ULONG
)pSrc
);
2543 if(PICE_strcmpi(pSrc
->filename
,pCurrentFile
)==0)
2544 PICE_sprintf(tempCmd
,"*%-32s @ %.8X\n",pSrc
->filename
,(ULONG
)pSrc
);
2546 PICE_sprintf(tempCmd
," %-32s @ %.8X\n",pSrc
->filename
,(ULONG
)pSrc
);
2551 if((p
= strrchr(pSrc
->filename
,'/')) )
2553 PICE_sprintf(tempCmd
,"%-32s @ %.8X\n",p
+1,(ULONG
)pSrc
);
2557 PICE_sprintf(tempCmd
,"%-32s @ %.8X\n",pSrc
->filename
,(ULONG
)pSrc
);
2560 Print(OUTPUT_WINDOW
,tempCmd
);
2562 if(WaitForKey()==FALSE
)break;
2563 (LPSTR
)pSrc
+= pSrc
->ulOffsetToNext
;
2567 Print(OUTPUT_WINDOW
,"No source files available!\n");
2569 // 1 argument -> argument is pointer PICE_SYMBOLFILE_SOURCE struct ->
2570 // set current file and show it
2571 else if(pArgs
->Count
== 1)
2573 PICE_SYMBOLFILE_SOURCE
* pSrc
= (PICE_SYMBOLFILE_SOURCE
*)pArgs
->Value
[0];
2574 LPSTR pFilename
= pSrc
->filename
;
2576 ClrLine(wWindow
[SOURCE_WINDOW
].y
-1);
2578 if(PICE_strlen(pFilename
)<GLOBAL_SCREEN_WIDTH
/2)
2580 PutChar(pFilename
,1,wWindow
[SOURCE_WINDOW
].y
-1);
2586 p
= strrchr(pFilename
,'/');
2596 PutChar(p
,1,wWindow
[SOURCE_WINDOW
].y
-1);
2599 // set new current file
2600 PICE_strcpy(szCurrentFile
,pFilename
);
2602 ulCurrentlyDisplayedLineNumber
= 1;
2604 DisplaySourceFile((LPSTR
)pSrc
+sizeof(PICE_SYMBOLFILE_SOURCE
),
2605 (LPSTR
)pSrc
+pSrc
->ulOffsetToNext
,
2613 //*************************************************************************
2616 //*************************************************************************
2617 COMMAND_PROTOTYPE(ShowLocals
)
2623 p
= FindLocalsByAddress(GetLinearAddress(CurrentCS
,CurrentEIP
));
2624 DPRINT((0,"ShowLocals: %x\n", p
));
2627 DPRINT((0,"ShowLocals: name %s, type_name %s\n", p
->name
, p
->type_name
));
2628 while(PICE_strlen(p
->name
))
2632 PICE_sprintf(tempCmd
,"[EBP%.4d / #%u] %x %s %s \n",p
->offset
,p
->line
,p
->value
,p
->type_name
,p
->name
);
2636 PICE_sprintf(tempCmd
,"[%-8s / #%u] %x %s %s #%u\n",LocalVarRegs
[p
->offset
],p
->line
,p
->value
,p
->type_name
,p
->name
);
2638 Print(OUTPUT_WINDOW
,tempCmd
);
2646 //*************************************************************************
2649 //*************************************************************************
2650 COMMAND_PROTOTYPE(ShowSymbols
)
2652 PICE_SYMBOLFILE_HEADER
* pSymbols
;
2654 LPSTR pSearchString
,pName
,pFind
;
2656 // no args -> list full symbols for current module
2659 // have current module ?
2662 DPRINT((0,"ShowSymbols(): full listing of symbols for %S\n",pCurrentMod
->name
));
2663 addr
= (ULONG
)pCurrentMod
->BaseAddress
;
2665 if((pSymbols
= FindModuleSymbols(addr
)) )
2667 PICE_sprintf(tempCmd
,"symbols for module \"%S\"\n",pCurrentMod
->name
);
2668 Print(OUTPUT_WINDOW
,tempCmd
);
2671 while((index
= ListSymbolStartingAt(pCurrentMod
,pSymbols
,index
,tempCmd
)))
2673 Print(OUTPUT_WINDOW
,tempCmd
);
2674 if(WaitForKey()==FALSE
)break;
2680 else if(pArgs
->Count
== 1)
2684 addr
= (ULONG
)pCurrentMod
->BaseAddress
;
2686 if((pSymbols
= FindModuleSymbols(addr
)))
2688 pSearchString
= (LPSTR
)pArgs
->Value
[0];
2690 PICE_sprintf(tempCmd
,"symbols for module \"%S\" (searching for \"%s\")\n",pCurrentMod
->name
,pSearchString
);
2691 Print(OUTPUT_WINDOW
,tempCmd
);
2695 if(*pSearchString
=='*' && pSearchString
[PICE_strlen(pSearchString
)-1]=='*')
2697 pSearchString
[PICE_strlen(pSearchString
)-1] = 0;
2700 while((index
= ListSymbolStartingAt(pCurrentMod
,pSymbols
,index
,tempCmd
)))
2702 pName
= strrchr(tempCmd
,' ');
2704 pFind
= strstr(pName
,pSearchString
);
2707 Print(OUTPUT_WINDOW
,tempCmd
);
2708 if(WaitForKey()==FALSE
)break;
2713 else if(pSearchString
[PICE_strlen(pSearchString
)-1]=='*')
2715 pSearchString
[PICE_strlen(pSearchString
)-1] = 0;
2718 index
= ListSymbolStartingAt(pCurrentMod
,pSymbols
,index
,tempCmd
);
2723 pName
= strrchr(tempCmd
,' ');
2725 pFind
= strstr(pName
,pSearchString
);
2726 if(pFind
&& (((ULONG
)pName
-(ULONG
)pFind
)==0) )
2728 Print(OUTPUT_WINDOW
,tempCmd
);
2729 if(WaitForKey()==FALSE
)break;
2731 }while((index
= ListSymbolStartingAt(pCurrentMod
,pSymbols
,index
,tempCmd
)));
2742 //*************************************************************************
2743 // EvaluateExpression()
2745 //*************************************************************************
2746 COMMAND_PROTOTYPE(EvaluateExpression
)
2748 PICE_SYMBOLFILE_HEADER
* pSymbols
;
2751 if(pArgs
->Count
== 1)
2755 addr
= (ULONG
)pCurrentMod
->BaseAddress
;
2757 if( (pSymbols
= FindModuleSymbols(addr
) ) )
2759 DPRINT((0,"EvaluateExpression: %s\n", (LPSTR
)pArgs
->Value
[0]));
2760 Evaluate(pSymbols
,(LPSTR
)pArgs
->Value
[0]);
2767 //*************************************************************************
2770 //*************************************************************************
2771 COMMAND_PROTOTYPE(SizeCodeWindow
)
2773 ULONG NewHeight
,TotalHeight
;
2775 if(pArgs
->Count
== 1)
2777 NewHeight
= pArgs
->Value
[0];
2779 TotalHeight
= wWindow
[SOURCE_WINDOW
].cy
+
2780 wWindow
[OUTPUT_WINDOW
].cy
;
2782 if(NewHeight
< TotalHeight
)
2784 if(wWindow
[SOURCE_WINDOW
].cy
!= NewHeight
)
2786 wWindow
[SOURCE_WINDOW
].cy
= NewHeight
;
2787 wWindow
[OUTPUT_WINDOW
].y
= wWindow
[SOURCE_WINDOW
].y
+ wWindow
[SOURCE_WINDOW
].cy
+ 1;
2788 wWindow
[OUTPUT_WINDOW
].cy
= TotalHeight
- NewHeight
;
2796 PICE_sprintf(tempCmd
,"code window at position %u has %u lines \n",wWindow
[SOURCE_WINDOW
].y
,wWindow
[SOURCE_WINDOW
].cy
);
2797 Print(OUTPUT_WINDOW
,tempCmd
);
2803 //*************************************************************************
2806 //*************************************************************************
2807 COMMAND_PROTOTYPE(SizeDataWindow
)
2809 ULONG NewHeight
,TotalHeight
;
2813 NewHeight
= pArgs
->Value
[0];
2815 TotalHeight
= wWindow
[DATA_WINDOW
].cy
+
2816 wWindow
[SOURCE_WINDOW
].cy
;
2818 if(NewHeight
< TotalHeight
)
2820 if(wWindow
[DATA_WINDOW
].cy
!= NewHeight
)
2822 wWindow
[DATA_WINDOW
].cy
= NewHeight
;
2823 wWindow
[SOURCE_WINDOW
].y
= wWindow
[DATA_WINDOW
].y
+ wWindow
[DATA_WINDOW
].cy
+ 1;
2824 wWindow
[SOURCE_WINDOW
].cy
= TotalHeight
- NewHeight
;
2832 PICE_sprintf(tempCmd
,"data window has %u lines \n",wWindow
[DATA_WINDOW
].cy
);
2833 Print(OUTPUT_WINDOW
,tempCmd
);
2839 //*************************************************************************
2842 //*************************************************************************
2843 COMMAND_PROTOTYPE(ClearScreen
)
2847 Clear(OUTPUT_WINDOW
);
2853 //*************************************************************************
2856 //*************************************************************************
2857 COMMAND_PROTOTYPE(ShowMappings
)
2867 struct mm_struct
* p
= NULL
;
2868 struct task_struct
* my_current
= (struct task_struct
*)0xFFFFE000;
2870 DPRINT((0,"ShowMappings()\n"));
2872 if(pArgs
->Count
== 1)
2874 // We're in DebuggerShell(), so we live on a different stack
2875 (ULONG
)my_current
&= ulRealStackPtr
;
2877 // in case we have a user context we use it's mm_struct
2882 // no user context -> use kernel's context
2888 // get the requested address from arguments
2889 phys_addr
= pArgs
->Value
[0];
2891 DPRINT((0,"ShowMappings(): p = %X phys_addr = %X\n",(ULONG
)p
,phys_addr
));
2893 // for every page directory
2894 for(ulPageDir
=0;ulPageDir
<1024;ulPageDir
++)
2896 address
= (ulPageDir
<<22);
2898 // get the page directory for the address
2899 pPGD
= pgd_offset(p
,address
);
2900 // if page dir present
2901 if(pPGD
&& pgd_val(*pPGD
)&_PAGE_PRESENT
)
2903 DPRINT((0,"ShowMappings(): page directory present for %x\n",address
));
2905 if(!(pgd_val(*pPGD
)&_PAGE_4M
))
2907 DPRINT((0,"ShowMappings(): page directory for 4k pages\n"));
2908 for(ulPageTable
=0;ulPageTable
<1024;ulPageTable
++)
2910 address
= (ulPageDir
<<22)|(ulPageTable
<<12);
2912 pPMD
= pmd_offset(pPGD
,address
);
2915 pPTE
= pte_offset(pPMD
,address
);
2918 if(*(PULONG
)pPTE
& _PAGE_PRESENT
)
2920 ULONG ulPte
= *(PULONG
)pPTE
& 0xFFFFF000;
2922 if(ulPte
== (phys_addr
& 0xFFFFF000))
2924 PICE_sprintf(tempCmd
,"%.8X\n",address
+(phys_addr
&0xFFF));
2925 Print(OUTPUT_WINDOW
,tempCmd
);
2926 if(WaitForKey()==FALSE
)return TRUE
;
2936 address
= (ulPageDir
<<22);
2937 if((pgd_val(*pPGD
)&0xFFC00000) == (phys_addr
& 0xFFC00000) )
2939 if( ((address
|(phys_addr
&0x7FFFFF))&~TASK_SIZE
) == phys_addr
)
2940 PICE_sprintf(tempCmd
,"%.8X (identity map %.8X+%.8X)\n",address
|(phys_addr
&0x7FFFFF),TASK_SIZE
,phys_addr
);
2942 PICE_sprintf(tempCmd
,"%.8X\n",address
|(phys_addr
&0x7FFFFF));
2943 Print(OUTPUT_WINDOW
,tempCmd
);
2944 if(WaitForKey()==FALSE
)return TRUE
;
2951 PICE_sprintf(tempCmd
,"Not implemented yet!\n");
2952 Print(OUTPUT_WINDOW
,tempCmd
);
2956 //*************************************************************************
2959 //*************************************************************************
2960 COMMAND_PROTOTYPE(ShowTimers
)
2966 //*************************************************************************
2967 // FindPCIVendorName()
2969 //*************************************************************************
2970 LPSTR
FindPCIVendorName(USHORT vendorid
)
2974 for(i
=0;i
<DIM(PCIVendorIDs
);i
++)
2976 if(vendorid
== PCIVendorIDs
[i
].vendorid
)
2977 return PCIVendorIDs
[i
].vendor_name
;
2983 //*************************************************************************
2986 //*************************************************************************
2987 COMMAND_PROTOTYPE(ShowPCI
)
2989 ULONG oldCF8
,data
,bus
,dev
,reg
,i
,ulNumBaseAddresses
,bus_req
=0,dev_req
=0;
2990 PCI_NUMBER pciNumber
;
2991 PCI_COMMON_CONFIG pciConfig
,*ppciConfig
;
2995 BOOLEAN bShowAll
= FALSE
,bUseDev
=TRUE
,bUseBus
=TRUE
;
2998 DPRINT((0,"ShowPCI()\n"));
3000 if(pArgs
->CountSwitches
>1)
3003 if(pArgs
->CountSwitches
==1)
3005 if(pArgs
->Switch
[0] == 'a')
3009 if(pArgs
->Count
< 3)
3011 if(pArgs
->Count
> 0)
3014 bus_req
= pArgs
->Value
[0];
3016 if(pArgs
->Count
> 1)
3019 dev_req
= pArgs
->Value
[1];
3022 // save old config space selector
3023 oldCF8
= inl((PULONG
)0xcf8);
3025 for(bus
=0;bus
<256;bus
++)
3027 for(dev
=0;dev
<32;dev
++)
3029 if(!((bUseDev
|| dev
== dev_req
) &&
3030 (bUseBus
|| bus
== bus_req
) ))
3033 pciNumber
.u
.AsUlong
= 0;
3034 pciNumber
.u
.bits
.dev
= dev
;
3035 pciNumber
.u
.bits
.bus
= bus
;
3036 pciNumber
.u
.bits
.func
= 0;
3037 pciNumber
.u
.bits
.ce
= 1;
3038 outl(pciNumber
.u
.AsUlong
,(PULONG
)0xcf8);
3039 data
= inl((PULONG
)0xcfc);
3041 if(data
!= 0xFFFFFFFF) // valid device
3043 if((pVendorName
= FindPCIVendorName((USHORT
)data
)) )
3045 PICE_sprintf(tempCmd
,"Bus%-8uDev%-8u === %.4X %.4X %s ====\n",bus
,dev
,(USHORT
)data
,(USHORT
)(data
>>16),pVendorName
);
3049 PICE_sprintf(tempCmd
,"Bus%-8uDev%-8u === %.4X %.4X N/A ====\n",bus
,dev
,(USHORT
)data
,(USHORT
)(data
>>16));
3051 Print(OUTPUT_WINDOW
,tempCmd
);
3052 if(WaitForKey()==FALSE
)goto CommonShowPCIExit
;
3054 p
= (PULONG
)&pciConfig
;
3055 for(reg
=0;reg
<sizeof(PCI_COMMON_CONFIG
)/sizeof(ULONG
);reg
++)
3057 pciNumber
.u
.AsUlong
= 0;
3058 pciNumber
.u
.bits
.dev
= dev
;
3059 pciNumber
.u
.bits
.bus
= bus
;
3060 pciNumber
.u
.bits
.func
= 0;
3061 pciNumber
.u
.bits
.reg
= reg
;
3062 pciNumber
.u
.bits
.ce
= 1;
3064 outl(pciNumber
.u
.AsUlong
,(PULONG
)0xcf8);
3065 *p
++ = inl((PULONG
)0xcfc);
3067 PICE_sprintf(tempCmd
,"SubVendorId %.4X SubSystemId %.4X\n",pciConfig
.u
.type0
.SubVendorID
,pciConfig
.u
.type0
.SubSystemID
);
3068 Print(OUTPUT_WINDOW
,tempCmd
);
3069 if(WaitForKey()==FALSE
)goto CommonShowPCIExit
;
3073 for(ulNumBaseAddresses
=0,i
=0;i
<6;i
++)
3075 if(pciConfig
.u
.type0
.BaseAddresses
[i
] != 0)
3076 ulNumBaseAddresses
++;
3078 if(ulNumBaseAddresses
)
3080 Print(OUTPUT_WINDOW
,"BaseAddresses:");
3084 if(pciConfig
.u
.type0
.BaseAddresses
[i
] != 0)
3086 PICE_sprintf(temp
," %u:%.8X",i
,pciConfig
.u
.type0
.BaseAddresses
[i
]);
3087 PICE_strcat(tempCmd
,temp
);
3090 Print(OUTPUT_WINDOW
,tempCmd
);
3091 Print(OUTPUT_WINDOW
,"\n");
3092 if(WaitForKey()==FALSE
)goto CommonShowPCIExit
;
3094 ppciConfig
= &pciConfig
;
3097 SHOW_FIELD_WORD(ppciConfig
,Status
,TRUE
);
3098 SHOW_FIELD_WORD(ppciConfig
,Command
,TRUE
);
3099 SHOW_FIELD_BYTE(ppciConfig
,RevisionID
,TRUE
);
3100 SHOW_FIELD_BYTE(ppciConfig
,ProgIf
,TRUE
);
3101 SHOW_FIELD_BYTE(ppciConfig
,BaseClass
,TRUE
);
3102 SHOW_FIELD_BYTE(ppciConfig
,SubClass
,TRUE
);
3103 SHOW_FIELD_BYTE(ppciConfig
,CacheLineSize
,TRUE
);
3104 SHOW_FIELD_BYTE(ppciConfig
,LatencyTimer
,TRUE
);
3112 // restore old config space selector
3113 outl(oldCF8
,(PULONG
)0xcf8);
3116 else if(pArgs
->Count
== 1)
3123 //*************************************************************************
3124 // SetKeyboardLayout()
3126 //*************************************************************************
3127 COMMAND_PROTOTYPE(SetKeyboardLayout
)
3129 PKEYBOARD_LAYOUT layout
;
3133 layout
= GetKeyboardLayout();
3135 switch(pArgs
->Count
)
3138 PICE_sprintf(tempCmd
,"current layout = %s\n", layout
->name
);
3139 Print(OUTPUT_WINDOW
,tempCmd
);
3142 layout
= SetKeyboardLayoutByName((LPSTR
)pArgs
->Value
[0]);
3143 PICE_sprintf(tempCmd
,"current layout = %s\n", layout
->name
);
3144 Print(OUTPUT_WINDOW
,tempCmd
);
3153 //*************************************************************************
3154 // ShowSysCallTable()
3156 //*************************************************************************
3157 COMMAND_PROTOTYPE(ShowSysCallTable
)
3165 if(pArgs
->Count
== 0)
3167 PICE_sprintf(tempCmd
,"%u system calls\n",190);
3168 Print(OUTPUT_WINDOW
,tempCmd
);
3169 if(WaitForKey()!=FALSE
)
3172 if((pName
= FindFunctionByAddress(sys_call_table
[i
],NULL
,NULL
)) )
3174 PICE_sprintf(tempCmd
,"%-.3u: %.8X (%s)\n",i
,sys_call_table
[i
],pName
);
3178 PICE_sprintf(tempCmd
,"%-.3u: %.8X (%s)\n",i
,sys_call_table
[i
],pName
);
3180 Print(OUTPUT_WINDOW
,tempCmd
);
3181 if(WaitForKey()==FALSE
)
3185 else if(pArgs
->Count
== 1)
3187 i
= pArgs
->Value
[0];
3190 if((pName
= FindFunctionByAddress(sys_call_table
[i
],NULL
,NULL
)) )
3192 PICE_sprintf(tempCmd
,"%-.3u: %.8X (%s)\n",i
,sys_call_table
[i
],pName
);
3196 PICE_sprintf(tempCmd
,"%-.3u: %.8X (%s)\n",i
,sys_call_table
[i
],pName
);
3198 Print(OUTPUT_WINDOW
,tempCmd
);
3204 PICE_sprintf(tempCmd
,"Not implemented yet!\n");
3205 Print(OUTPUT_WINDOW
,tempCmd
);
3209 //*************************************************************************
3212 //*************************************************************************
3213 COMMAND_PROTOTYPE(SetAltKey
)
3215 if(pArgs
->Count
== 1)
3217 ucBreakKey
= (UCHAR
)pArgs
->Value
[0];
3219 PICE_sprintf(tempCmd
,"new break key is CTRL-%c\n",ucBreakKey
);
3220 Print(OUTPUT_WINDOW
,tempCmd
);
3222 else if(pArgs
->Count
== 0)
3224 PICE_sprintf(tempCmd
,"current break key is CTRL-%c\n",ucBreakKey
);
3225 Print(OUTPUT_WINDOW
,tempCmd
);
3232 //*************************************************************************
3235 //*************************************************************************
3236 COMMAND_PROTOTYPE(ShowContext
)
3241 //*************************************************************************
3243 // utility functions for parsing
3245 //*************************************************************************
3248 //*************************************************************************
3251 //*************************************************************************
3252 LPSTR
FindCommand(LPSTR p
)
3258 for(j
=0,i
=0;CmdTable
[i
].Cmd
!=NULL
;i
++)
3260 if(PICE_strncmpi(CmdTable
[i
].Cmd
,p
,PICE_strlen(p
)) == 0 &&
3261 CmdTable
[i
].CommandGroup
!= COMMAND_GROUP_HELP_ONLY
)
3263 if(PICE_strlen(tempCmd
))
3264 PICE_strcat(tempCmd
,", ");
3265 PICE_strcat(tempCmd
,CmdTable
[i
].Cmd
);
3270 if(PICE_strlen(tempCmd
))
3272 SetBackgroundColor(COLOR_CAPTION
);
3273 SetForegroundColor(COLOR_TEXT
);
3274 ClrLine(wWindow
[OUTPUT_WINDOW
].y
+wWindow
[OUTPUT_WINDOW
].cy
);
3275 PutChar(tempCmd
,1,wWindow
[OUTPUT_WINDOW
].y
+wWindow
[OUTPUT_WINDOW
].cy
);
3278 PICE_sprintf(tempCmd
,"%s",CmdTable
[k
].Help
);
3279 PutChar(tempCmd
,40,wWindow
[OUTPUT_WINDOW
].y
+wWindow
[OUTPUT_WINDOW
].cy
);
3280 result
=CmdTable
[k
].Cmd
;
3288 //*************************************************************************
3291 //*************************************************************************
3292 void CompactString(LPSTR p
)
3296 for(i
=1;i
<PICE_strlen(p
);i
++)
3298 if(p
[i
]==' ' && p
[i
-1]==' ')
3300 PICE_strcpy(&p
[i
-1],&p
[i
]);
3306 //*************************************************************************
3309 //*************************************************************************
3310 char* PICE_strtok(char *szInputString
)
3312 static char* szCurrString
;
3319 szCurrString
=szInputString
;
3320 CompactString(szCurrString
);
3323 currlength
=PICE_strlen(szCurrString
);
3329 for(i
=0;i
<currlength
;i
++)
3331 if(szCurrString
[i
]==' ')
3337 szTempString
=szCurrString
;
3338 szCurrString
=szCurrString
+i
+1;
3339 return szTempString
;
3342 //*************************************************************************
3343 // ConvertTokenToHex()
3345 //*************************************************************************
3346 BOOLEAN
ConvertTokenToHex(LPSTR p
,PULONG pValue
)
3352 for(i
=0;i
<8 && p
[i
]!=0 && p
[i
]!=' ' && p
[i
]!=':';i
++)
3354 if(p
[i
]>='0' && p
[i
]<='9')
3357 result
|=(ULONG
)(UCHAR
)(p
[i
]-'0');
3359 else if(p
[i
]>='A' && p
[i
]<='F')
3362 result
|=(ULONG
)(UCHAR
)(p
[i
]-'A'+10);
3364 else if(p
[i
]>='a' && p
[i
]<='f')
3367 result
|=(ULONG
)(UCHAR
)(p
[i
]-'a'+10);
3375 ULONG ulSelector
=result
;
3376 if(ulSelector
>0xFFFF)
3378 for(i
=0;i
<8 && p
[i
]!=0 && p
[i
]!=' ' && p
[i
]!=':';i
++)
3380 if(p
[i
]>='0' && p
[i
]<='9')
3383 result
|=(ULONG
)(UCHAR
)(p
[i
]-'0');
3385 else if(p
[i
]>='A' && p
[i
]<='F')
3388 result
|=(ULONG
)(UCHAR
)(p
[i
]-'A'+10);
3390 else if(p
[i
]>='a' && p
[i
]<='f')
3393 result
|=(ULONG
)(UCHAR
)(p
[i
]-'a'+10);
3398 gCurrentSelector
=(USHORT
)ulSelector
;
3399 gCurrentOffset
=result
;
3400 result
= GetLinearAddress((USHORT
)ulSelector
,result
);
3406 //*************************************************************************
3407 // ConvertTokenToDec()
3409 //*************************************************************************
3410 BOOLEAN
ConvertTokenToDec(LPSTR p
,PULONG pValue
)
3417 if(c
>= '0' && c
<= '9')
3420 result
+= (ULONG
)(c
- '0');
3431 //*************************************************************************
3432 // ConvertTokenToSymbol()
3434 //*************************************************************************
3435 BOOLEAN
ConvertTokenToSymbol(LPSTR pToken
,PULONG pValue
)
3440 PDEBUG_MODULE pModFound
;
3442 DPRINT((0,"ConvertTokenToSymbol()\n"));
3444 PICE_strcpy(temp
,pToken
);
3447 // test for module!symbol string
3448 pEx
= PICE_strchr(p
,'!');
3451 DPRINT((0,"ConvertTokenToSymbol(): module!symbol syntax detected\n"));
3452 // terminate module name
3454 // now we have two pointers
3456 DPRINT((0,"ConvertTokenToSymbol(): module = %s symbol = %s\n",p
,pEx
));
3458 if( pModFound
=IsModuleLoaded(p
) )
3460 if((*pValue
= FindFunctionInModuleByName(pEx
,pModFound
)))
3468 if((*pValue
= FindFunctionInModuleByName(p
,pCurrentMod
)))
3471 return ScanExports(p
,pValue
);
3476 //*************************************************************************
3477 // ConvertTokenToModuleAndName()
3479 //*************************************************************************
3480 BOOLEAN
ConvertTokenToModuleAndName(LPSTR pToken
,PULONG pulModuleName
,PULONG pulFunctionName
)
3485 static char module_name
[128];
3486 static char function_name
[128];
3488 // test for module!symbol string
3489 PICE_strcpy(temp
,pToken
);
3492 DPRINT((0,"ConvertTokenToModuleAndName(%s)\n",p
));
3494 pEx
= PICE_strchr(p
,'!');
3497 DPRINT((0,"ConvertTokenToModuleAndName(): module!symbol syntax detected\n"));
3498 // terminate module name
3500 // now we have two pointers
3502 DPRINT((0,"ConvertTokenToModuleAndName(): module = %s symbol = %s\n",p
,pEx
));
3503 PICE_strcpy(module_name
,p
);
3504 PICE_strcpy(function_name
,pEx
);
3505 *pulModuleName
= (ULONG
)module_name
;
3506 *pulFunctionName
= (ULONG
)function_name
;
3513 //*************************************************************************
3514 // ConvertTokenToModule()
3516 // convert an argument module name to a pointer to the module's symbols
3517 //*************************************************************************
3518 BOOLEAN
ConvertTokenToModule(LPSTR p
,PULONG pValue
)
3521 char temp
[DEBUG_MODULE_NAME_LEN
];
3523 for(i
=0;i
<DIM(apSymbols
);i
++)
3527 CopyWideToAnsi(temp
,apSymbols
[i
]->name
);
3528 if(PICE_strcmpi(p
,temp
)==0)
3530 *pValue
= (ULONG
)apSymbols
[i
];
3536 for(i
=0;i
<DIM(apSymbols
);i
++)
3540 CopyWideToAnsi(temp
,apSymbols
[i
]->name
);
3541 if(PICE_strncmpi(temp
,p
,PICE_strlen(p
))==0)
3543 *pValue
= (ULONG
)apSymbols
[i
];
3552 //*************************************************************************
3553 // ConvertTokenToProcess()
3555 //*************************************************************************
3556 BOOLEAN
ConvertTokenToProcess(LPSTR p
,PULONG pValue
)
3561 //*************************************************************************
3562 // ReplaceKeywordWithValue()
3564 //*************************************************************************
3565 BOOLEAN
ReplaceKeywordWithValue(LPSTR p
,PULONG pValue
,KEYWORDS
* pKeyWords
)
3569 for(i
=0;pKeyWords
[i
].KeyWord
!=NULL
;i
++)
3571 if(PICE_strcmpi(p
,pKeyWords
[i
].KeyWord
)==0)
3573 switch(pKeyWords
[i
].ulSize
)
3575 case sizeof(USHORT
):
3576 *pValue
=(ULONG
)*(PUSHORT
)(pKeyWords
[i
].pValue
);
3579 *pValue
=*(PULONG
)(pKeyWords
[i
].pValue
);
3588 //*************************************************************************
3589 // ConvertTokenToKeyword()
3591 //*************************************************************************
3592 BOOLEAN
ConvertTokenToKeyword(LPSTR p
,PULONG pValue
)
3597 DPRINT((0,"ConvertTokenToKeyword()\n"));
3598 count
=StrLenUpToWhiteChar(p
," ");
3599 PICE_strncpy(Name
,p
,count
);
3601 if(ReplaceKeywordWithValue(Name
,pValue
,RegKeyWords
))
3603 DPRINT((0,"ConvertTokenToKeyword(): success\n"));
3609 //*************************************************************************
3610 // ConvertTokenToSpecialKeyword()
3612 //*************************************************************************
3613 BOOLEAN
ConvertTokenToSpecialKeyword(LPSTR p
,PULONG pValue
)
3618 count
=StrLenUpToWhiteChar(p
," ");
3619 PICE_strncpy(Name
,p
,count
);
3621 if(ReplaceKeywordWithValue(Name
,pValue
,SpecialKeyWords
))
3628 //*************************************************************************
3629 // ConvertTokenToOnOff()
3631 //*************************************************************************
3632 BOOLEAN
ConvertTokenToOnOff(LPSTR p
,PULONG pValue
)
3637 count
=StrLenUpToWhiteChar(p
," ");
3638 PICE_strncpy(Name
,p
,count
);
3640 if(ReplaceKeywordWithValue(Name
,pValue
,OnOffKeyWords
))
3647 //*************************************************************************
3648 // ConvertSizeToKeyword()
3650 //*************************************************************************
3651 BOOLEAN
ConvertSizeToKeyword(LPSTR p
,PULONG pValue
)
3655 count
=StrLenUpToWhiteChar(p
," ");
3689 //*************************************************************************
3690 // ConvertTokenToSrcFile()
3692 //*************************************************************************
3693 BOOLEAN
ConvertTokenToSrcFile(LPSTR p
,PULONG pValue
)
3695 PICE_SYMBOLFILE_SOURCE
* pSrc
;
3696 LPSTR pFilename
,pFilenameSrc
;
3699 DPRINT((0,"ConvertTokenToSrcFile(%s)\n",p
));
3701 if(pCurrentSymbols
&& pCurrentSymbols
->ulNumberOfSrcFiles
)
3703 DPRINT((0,"ConvertTokenToSrcFile(): current symbols for %S\n",pCurrentSymbols
->name
));
3705 pSrc
= (PICE_SYMBOLFILE_SOURCE
*)((ULONG
)pCurrentSymbols
+ pCurrentSymbols
->ulOffsetToSrcFiles
);
3707 for(i
=0;i
<pCurrentSymbols
->ulNumberOfSrcFiles
;i
++)
3709 pFilename
= strrchr(pSrc
->filename
,'/');
3711 pFilename
= pSrc
->filename
;
3715 pFilenameSrc
= strrchr(p
,'/');
3721 DPRINT((0,"ConvertTokenToSrcFile(): %s\n",pFilename
));
3723 if(PICE_strcmpi(pFilename
,pFilenameSrc
) == 0)
3725 DPRINT((0,"ConvertTokenToSrcFile(): found %s\n",pFilename
));
3727 *pValue
= (ULONG
)pSrc
;
3732 (LPSTR
)pSrc
+= pSrc
->ulOffsetToNext
;
3735 pSrc
= (PICE_SYMBOLFILE_SOURCE
*)((ULONG
)pCurrentSymbols
+ pCurrentSymbols
->ulOffsetToSrcFiles
);
3737 // if not found now do a lookup for partials
3738 for(i
=0;i
<pCurrentSymbols
->ulNumberOfSrcFiles
;i
++)
3740 pFilename
= strrchr(pSrc
->filename
,'/');
3742 pFilename
= pSrc
->filename
;
3746 DPRINT((0,"ConvertTokenToSrcFile(): %s\n",pFilename
));
3748 if(PICE_strncmpi(pFilename
,p
,PICE_strlen(p
)) == 0)
3750 DPRINT((0,"ConvertTokenToSrcFile(): found %s\n",pFilename
));
3752 *pValue
= (ULONG
)pSrc
;
3757 (LPSTR
)pSrc
+= pSrc
->ulOffsetToNext
;
3764 //*************************************************************************
3765 // ConvertTokenToLineNumber()
3767 //*************************************************************************
3768 BOOLEAN
ConvertTokenToLineNumber(LPSTR p
,PULONG pValue
)
3772 DPRINT((0,"ConvertTokenToLineNumber()\n"));
3775 ulDecimal
= ExtractNumber(p
);
3776 DPRINT((0,"ConvertTokenToLineNumber(): ulDecimal = %u\n",ulDecimal
));
3779 DPRINT((0,"ConvertTokenToLineNumber(): current file = %s\n",szCurrentFile
));
3780 if(pCurrentMod
&& PICE_strlen(szCurrentFile
))
3782 DPRINT((0,"ConvertTokenToLineNumber(): current file %S\n",pCurrentMod
->name
));
3783 if(FindAddressForSourceLine(ulDecimal
,szCurrentFile
,pCurrentMod
,pValue
))
3785 DPRINT((0,"ConvertTokenToLineNumber(): value = %x\n",*pValue
));
3796 //*************************************************************************
3799 //*************************************************************************
3800 BOOLEAN
IsWhiteChar(char c
,LPSTR WhiteChars
)
3802 USHORT lenWhiteChar
= PICE_strlen(WhiteChars
);
3804 for(i
=0;i
<lenWhiteChar
;i
++)
3806 if(c
== WhiteChars
[i
])
3812 //*************************************************************************
3813 // StrLenUpToWhiteChar()
3815 //*************************************************************************
3816 ULONG
StrLenUpToWhiteChar(LPSTR p
,LPSTR WhiteChars
)
3820 for(i
=0;p
[i
]!=0 && !IsWhiteChar(p
[i
],WhiteChars
);i
++);
3826 // command line parser
3828 void Parse(LPSTR pCmdLine
,BOOLEAN bInvokedByFkey
)
3831 BOOLEAN result
=FALSE
;
3834 CMDTABLE
*pCurrentCommand
=NULL
;
3836 ulCountForWaitKey
= 0;
3840 ClrLine(wWindow
[OUTPUT_WINDOW
].y
+wWindow
[OUTPUT_WINDOW
].usCurY
);
3843 PICE_memset(&Arguments
,0,sizeof(ARGS
));
3845 for(j
=0,i
=0;CmdTable
[i
].Cmd
!=NULL
;i
++)
3847 if(PICE_strncmpi(CmdTable
[i
].Cmd
,pCmdLine
,PICE_strlen(CmdTable
[i
].Cmd
))==0 &&
3848 PICE_strlen(CmdTable
[i
].Cmd
)==StrLenUpToWhiteChar(pCmdLine
," ") &&
3849 CmdTable
[i
].CommandGroup
!= COMMAND_GROUP_HELP_ONLY
)
3851 pCurrentCommand
=&CmdTable
[i
];
3855 if(pCurrentCommand
==NULL
)
3857 Print(OUTPUT_WINDOW
," <-- command not found\n");
3858 Print(OUTPUT_WINDOW
,":");
3859 goto CommonParseReturnPoint
;
3862 pToken
= PICE_strtok( pCmdLine
);
3863 // get the args and convert them into numbers
3868 pToken
=PICE_strtok( NULL
);
3869 DPRINT((0,"pToken = %s\n",pToken
));
3872 if(*pToken
== '-' && PICE_strlen(pToken
)==2)
3874 DPRINT((0,"might be a switch\n"));
3875 if(pCurrentCommand
->Flags
& COMMAND_HAS_SWITCHES
)
3877 // token starts with '-' and is 2 chars long
3879 if(PICE_strchr(pCurrentCommand
->pszRecognizedSwitches
,*(pToken
+1)) )
3881 DPRINT((0,"is a switch!\n"));
3882 Arguments
.Switch
[j
++]=*(pToken
+1);
3885 // not a valid switch
3888 PICE_sprintf(tempCmd
," <-- %s is not a valid switch\n",pToken
);
3889 Print(OUTPUT_WINDOW
,tempCmd
);
3890 Print(OUTPUT_WINDOW
,":");
3891 goto CommonParseReturnPoint
;
3896 PICE_sprintf(tempCmd
," <-- %s can't have any switches\n",pCurrentCommand
->Cmd
);
3897 Print(OUTPUT_WINDOW
,tempCmd
);
3898 Print(OUTPUT_WINDOW
,":");
3899 goto CommonParseReturnPoint
;
3903 if(pCurrentCommand
->Flags
& COMMAND_HAS_PARAMS
)
3905 if(!pCurrentCommand
->ParamFlags
[i
])
3907 PICE_sprintf(tempCmd
," <-- %s can't have more than %u parameters\n",pCurrentCommand
->Cmd
,i
);
3908 Print(OUTPUT_WINDOW
,tempCmd
);
3909 Print(OUTPUT_WINDOW
,":");
3910 goto CommonParseReturnPoint
;
3912 DPRINT((0,"Parse(): PARAM_CAN_BE_SRCLINE\n"));
3913 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_SRCLINE
)
3915 if(ConvertTokenToLineNumber(pToken
,&Arguments
.Value
[i
]))
3922 PICE_sprintf(tempCmd
," <-- no line number %s found\n",pToken
);
3923 Print(OUTPUT_WINDOW
,tempCmd
);
3924 Print(OUTPUT_WINDOW
,":");
3925 goto CommonParseReturnPoint
;
3928 DPRINT((0,"Parse(): PARAM_CAN_BE_NUMERIC\n"));
3929 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_NUMERIC
)
3931 if(ConvertTokenToHex(pToken
,&Arguments
.Value
[i
]))
3937 DPRINT((0,"Parse(): PARAM_CAN_BE_DECIMAL\n"));
3938 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_DECIMAL
)
3940 if(ConvertTokenToDec(pToken
,&Arguments
.Value
[i
]))
3946 DPRINT((0,"Parse(): PARAM_CAN_BE_REG_KEYWORD\n"));
3947 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_REG_KEYWORD
)
3949 if(ConvertTokenToKeyword(pToken
,&Arguments
.Value
[i
]))
3951 Arguments
.pToken
[i
] = pToken
;
3956 DPRINT((0,"Parse(): PARAM_CAN_BE_SYMBOLIC\n"));
3957 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_SYMBOLIC
)
3959 if(ConvertTokenToSymbol(pToken
,&Arguments
.Value
[i
]))
3965 DPRINT((0,"Parse(): PARAM_CAN_BE_VIRTUAL_SYMBOLIC\n"));
3966 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_VIRTUAL_SYMBOLIC
)
3968 DPRINT((0,"might be a virtual modname!symbol syntax!\n"));
3969 if(ConvertTokenToModuleAndName(pToken
,&Arguments
.Value
[i
],&Arguments
.Value
[i
+1]))
3971 Arguments
.bNotTranslated
[i
]=TRUE
;
3972 Arguments
.bNotTranslated
[i
+1]=TRUE
;
3977 DPRINT((0,"Parse(): PARAM_CAN_BE_MODULE\n"));
3978 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_MODULE
)
3980 if(ConvertTokenToModule(pToken
,&Arguments
.Value
[i
]))
3986 DPRINT((0,"Parse(): PARAM_CAN_BE_PRNAME\n"));
3987 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_PRNAME
)
3989 if(ConvertTokenToProcess(pToken
,&Arguments
.Value
[i
]))
3995 DPRINT((0,"Parse(): PARAM_CAN_BE_SRC_FILE\n"));
3996 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_SRC_FILE
)
3998 if(ConvertTokenToSrcFile(pToken
,&Arguments
.Value
[i
]))
4004 DPRINT((0,"Parse(): PARAM_CAN_BE_ASTERISK\n"));
4005 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_ASTERISK
)
4007 if(PICE_strlen(pToken
)==1 && pToken
[0]=='*')
4009 Arguments
.Value
[i
]=-1;
4014 DPRINT((0,"Parse(): PARAM_CAN_BE_LETTER\n"));
4015 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_LETTER
)
4017 if(PICE_strlen(pToken
)==1 && PICE_isprint(pToken
[0]))
4019 Arguments
.Value
[i
]=(ULONG
)pToken
[0];
4024 DPRINT((0,"Parse(): PARAM_CAN_BE_ONOFF\n"));
4025 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_ONOFF
)
4027 if(ConvertTokenToOnOff(pToken
,&Arguments
.Value
[i
]))
4033 DPRINT((0,"Parse(): PARAM_CAN_BE_PARTIAL_SYM_NAME\n"));
4034 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_PARTIAL_SYM_NAME
)
4036 Arguments
.Value
[i
] = (ULONG
)pToken
;
4040 DPRINT((0,"Parse(): PARAM_CAN_BE_ANY_STRING\n"));
4041 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_ANY_STRING
)
4043 Arguments
.Value
[i
] = (ULONG
)pToken
;
4047 DPRINT((0,"Parse(): PARAM_CAN_BE_SIZE_DESC\n"));
4048 if(pCurrentCommand
->ParamFlags
[i
] & PARAM_CAN_BE_SIZE_DESC
)
4050 if(ConvertSizeToKeyword(pToken
,&Arguments
.Value
[i
]))
4052 Arguments
.pToken
[i
] = pToken
;
4057 PICE_sprintf(tempCmd
," <-- syntax error in parameter %u!\n",i
);
4058 Print(OUTPUT_WINDOW
,tempCmd
);
4059 Print(OUTPUT_WINDOW
,":");
4060 goto CommonParseReturnPoint
;
4064 PICE_sprintf(tempCmd
," <-- %s has no parameters\n",pCurrentCommand
->Cmd
);
4065 Print(OUTPUT_WINDOW
,tempCmd
);
4066 Print(OUTPUT_WINDOW
,":");
4067 goto CommonParseReturnPoint
;
4072 }while(pToken
&& i
<MAX_ARGS
);
4075 Arguments
.CountSwitches
=j
;
4079 DPRINT((0,"Parse(): command %s switches %u\n",pCurrentCommand
->Cmd
,Arguments
.CountSwitches
));
4083 DPRINT((0,"Parse(): adding new line\n"));
4084 Print(OUTPUT_WINDOW
,"\n");
4087 // call the command handler
4088 result
=pCurrentCommand
->Handler(&Arguments
);
4090 if(result
&& !bInvokedByFkey
&& pCurrentCommand
->Handler
!=LeaveIce
&& pCurrentCommand
->Handler
!=SingleStep
)
4092 DPRINT((0,"Parse(): adding colon\n"));
4093 Print(OUTPUT_WINDOW
,":");
4097 CommonParseReturnPoint
:
4098 SuspendPrintRingBuffer(FALSE
);
4099 PrintRingBuffer(wWindow
[OUTPUT_WINDOW
].cy
-1);