1 | /* $Id: DBGCEmulateCodeView.cpp 35628 2011-01-19 14:58:26Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGC - Debugger Console, CodeView / WinDbg Emulation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*******************************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #define LOG_GROUP LOG_GROUP_DBGC
|
---|
22 | #include <VBox/dbg.h>
|
---|
23 | #include <VBox/vmm/dbgf.h>
|
---|
24 | #include <VBox/vmm/pgm.h>
|
---|
25 | #include <VBox/vmm/cpum.h>
|
---|
26 | #include <VBox/dis.h>
|
---|
27 | #include <VBox/param.h>
|
---|
28 | #include <VBox/err.h>
|
---|
29 | #include <VBox/log.h>
|
---|
30 |
|
---|
31 | #include <iprt/asm.h>
|
---|
32 | #include <iprt/mem.h>
|
---|
33 | #include <iprt/string.h>
|
---|
34 | #include <iprt/assert.h>
|
---|
35 | #include <iprt/ctype.h>
|
---|
36 |
|
---|
37 | #include <stdlib.h>
|
---|
38 | #include <stdio.h>
|
---|
39 |
|
---|
40 | #include "DBGCInternal.h"
|
---|
41 |
|
---|
42 |
|
---|
43 | /*******************************************************************************
|
---|
44 | * Internal Functions *
|
---|
45 | *******************************************************************************/
|
---|
46 | static DECLCALLBACK(int) dbgcCmdBrkAccess(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
47 | static DECLCALLBACK(int) dbgcCmdBrkClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
48 | static DECLCALLBACK(int) dbgcCmdBrkDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
49 | static DECLCALLBACK(int) dbgcCmdBrkEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
50 | static DECLCALLBACK(int) dbgcCmdBrkList(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
51 | static DECLCALLBACK(int) dbgcCmdBrkSet(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
52 | static DECLCALLBACK(int) dbgcCmdBrkREM(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
53 | static DECLCALLBACK(int) dbgcCmdDumpMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
54 | static DECLCALLBACK(int) dbgcCmdDumpDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
55 | static DECLCALLBACK(int) dbgcCmdDumpIDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
56 | static DECLCALLBACK(int) dbgcCmdDumpPageDir(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
57 | static DECLCALLBACK(int) dbgcCmdDumpPageDirBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
58 | static DECLCALLBACK(int) dbgcCmdDumpPageHierarchy(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
59 | static DECLCALLBACK(int) dbgcCmdDumpPageTable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
60 | static DECLCALLBACK(int) dbgcCmdDumpPageTableBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
61 | static DECLCALLBACK(int) dbgcCmdDumpTSS(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
62 | static DECLCALLBACK(int) dbgcCmdEditMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
63 | static DECLCALLBACK(int) dbgcCmdGo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
64 | static DECLCALLBACK(int) dbgcCmdListModules(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
65 | static DECLCALLBACK(int) dbgcCmdListNear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
66 | static DECLCALLBACK(int) dbgcCmdListSource(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
67 | static DECLCALLBACK(int) dbgcCmdMemoryInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
68 | static DECLCALLBACK(int) dbgcCmdReg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
69 | static DECLCALLBACK(int) dbgcCmdRegGuest(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
70 | static DECLCALLBACK(int) dbgcCmdRegHyper(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
71 | static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
72 | static DECLCALLBACK(int) dbgcCmdSearchMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
73 | static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
74 | static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
75 | static DECLCALLBACK(int) dbgcCmdTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
76 | static DECLCALLBACK(int) dbgcCmdUnassemble(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
|
---|
77 |
|
---|
78 |
|
---|
79 | /*******************************************************************************
|
---|
80 | * Global Variables *
|
---|
81 | *******************************************************************************/
|
---|
82 | /** 'ba' arguments. */
|
---|
83 | static const DBGCVARDESC g_aArgBrkAcc[] =
|
---|
84 | {
|
---|
85 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
86 | { 1, 1, DBGCVAR_CAT_STRING, 0, "access", "The access type: x=execute, rw=read/write (alias r), w=write, i=not implemented." },
|
---|
87 | { 1, 1, DBGCVAR_CAT_NUMBER, 0, "size", "The access size: 1, 2, 4, or 8. 'x' access requires 1, and 8 requires amd64 long mode." },
|
---|
88 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
|
---|
89 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
|
---|
90 | { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
|
---|
91 | { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
|
---|
92 | };
|
---|
93 |
|
---|
94 |
|
---|
95 | /** 'bc', 'bd', 'be' arguments. */
|
---|
96 | static const DBGCVARDESC g_aArgBrks[] =
|
---|
97 | {
|
---|
98 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
99 | { 0, ~0, DBGCVAR_CAT_NUMBER, 0, "#bp", "Breakpoint number." },
|
---|
100 | { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All breakpoints." },
|
---|
101 | };
|
---|
102 |
|
---|
103 |
|
---|
104 | /** 'bp' arguments. */
|
---|
105 | static const DBGCVARDESC g_aArgBrkSet[] =
|
---|
106 | {
|
---|
107 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
108 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
|
---|
109 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
|
---|
110 | { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
|
---|
111 | { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
|
---|
112 | };
|
---|
113 |
|
---|
114 |
|
---|
115 | /** 'br' arguments. */
|
---|
116 | static const DBGCVARDESC g_aArgBrkREM[] =
|
---|
117 | {
|
---|
118 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
119 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
|
---|
120 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
|
---|
121 | { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
|
---|
122 | { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
|
---|
123 | };
|
---|
124 |
|
---|
125 |
|
---|
126 | /** 'd?' arguments. */
|
---|
127 | static const DBGCVARDESC g_aArgDumpMem[] =
|
---|
128 | {
|
---|
129 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
130 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start dumping memory." },
|
---|
131 | };
|
---|
132 |
|
---|
133 |
|
---|
134 | /** 'dg', 'dga', 'dl', 'dla' arguments. */
|
---|
135 | static const DBGCVARDESC g_aArgDumpDT[] =
|
---|
136 | {
|
---|
137 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
138 | { 0, ~0, DBGCVAR_CAT_NUMBER, 0, "sel", "Selector or selector range." },
|
---|
139 | { 0, ~0, DBGCVAR_CAT_POINTER, 0, "address", "Far address which selector should be dumped." },
|
---|
140 | };
|
---|
141 |
|
---|
142 |
|
---|
143 | /** 'di', 'dia' arguments. */
|
---|
144 | static const DBGCVARDESC g_aArgDumpIDT[] =
|
---|
145 | {
|
---|
146 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
147 | { 0, ~0, DBGCVAR_CAT_NUMBER, 0, "int", "The interrupt vector or interrupt vector range." },
|
---|
148 | };
|
---|
149 |
|
---|
150 |
|
---|
151 | /** 'dpd*' arguments. */
|
---|
152 | static const DBGCVARDESC g_aArgDumpPD[] =
|
---|
153 | {
|
---|
154 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
155 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "index", "Index into the page directory." },
|
---|
156 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from. Range is applied to the page directory." },
|
---|
157 | };
|
---|
158 |
|
---|
159 |
|
---|
160 | /** 'dpda' arguments. */
|
---|
161 | static const DBGCVARDESC g_aArgDumpPDAddr[] =
|
---|
162 | {
|
---|
163 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
164 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page directory entry to start dumping from." },
|
---|
165 | };
|
---|
166 |
|
---|
167 |
|
---|
168 | /** 'dph*' arguments. */
|
---|
169 | static const DBGCVARDESC g_aArgDumpPH[] =
|
---|
170 | {
|
---|
171 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
172 | { 0, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "Where in the address space to start dumping and for how long (range). The default address/range will be used if omitted." },
|
---|
173 | { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "cr3", "The CR3 value to use. The current CR3 of the context will be used if omitted." },
|
---|
174 | { 0, 1, DBGCVAR_CAT_STRING, DBGCVD_FLAGS_DEP_PREV, "mode", "The paging mode: legacy, pse, pae, long, ept. Append '-np' for nested paging and '-nx' for no-execute. The current mode will be used if omitted." },
|
---|
175 | };
|
---|
176 |
|
---|
177 |
|
---|
178 | /** 'dpt?' arguments. */
|
---|
179 | static const DBGCVARDESC g_aArgDumpPT[] =
|
---|
180 | {
|
---|
181 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
182 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from." },
|
---|
183 | };
|
---|
184 |
|
---|
185 |
|
---|
186 | /** 'dpta' arguments. */
|
---|
187 | static const DBGCVARDESC g_aArgDumpPTAddr[] =
|
---|
188 | {
|
---|
189 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
190 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page table entry to start dumping from." },
|
---|
191 | };
|
---|
192 |
|
---|
193 |
|
---|
194 | /** 'dt' arguments. */
|
---|
195 | static const DBGCVARDESC g_aArgDumpTSS[] =
|
---|
196 | {
|
---|
197 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
198 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "tss", "TSS selector number." },
|
---|
199 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "tss:ign|addr", "TSS address. If the selector is a TSS selector, the offset will be ignored." }
|
---|
200 | };
|
---|
201 |
|
---|
202 |
|
---|
203 | /** 'e?' arguments. */
|
---|
204 | static const DBGCVARDESC g_aArgEditMem[] =
|
---|
205 | {
|
---|
206 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
207 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to write." },
|
---|
208 | { 1, ~0, DBGCVAR_CAT_NUMBER, 0, "value", "Value to write." },
|
---|
209 | };
|
---|
210 |
|
---|
211 |
|
---|
212 | /** 'lm' arguments. */
|
---|
213 | static const DBGCVARDESC g_aArgListMods[] =
|
---|
214 | {
|
---|
215 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
216 | { 0, ~0, DBGCVAR_CAT_STRING, 0, "module", "Module name." },
|
---|
217 | };
|
---|
218 |
|
---|
219 |
|
---|
220 | /** 'ln' arguments. */
|
---|
221 | static const DBGCVARDESC g_aArgListNear[] =
|
---|
222 | {
|
---|
223 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
224 | { 0, ~0, DBGCVAR_CAT_POINTER, 0, "address", "Address of the symbol to look up." },
|
---|
225 | { 0, ~0, DBGCVAR_CAT_SYMBOL, 0, "symbol", "Symbol to lookup." },
|
---|
226 | };
|
---|
227 |
|
---|
228 | /** 'ln' return. */
|
---|
229 | static const DBGCVARDESC g_RetListNear =
|
---|
230 | {
|
---|
231 | 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "The last resolved symbol/address with adjusted range."
|
---|
232 | };
|
---|
233 |
|
---|
234 |
|
---|
235 | /** 'ls' arguments. */
|
---|
236 | static const DBGCVARDESC g_aArgListSource[] =
|
---|
237 | {
|
---|
238 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
239 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start looking for source lines." },
|
---|
240 | };
|
---|
241 |
|
---|
242 |
|
---|
243 | /** 'm' argument. */
|
---|
244 | static const DBGCVARDESC g_aArgMemoryInfo[] =
|
---|
245 | {
|
---|
246 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
247 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Pointer to obtain info about." },
|
---|
248 | };
|
---|
249 |
|
---|
250 |
|
---|
251 | /** 'r' arguments. */
|
---|
252 | static const DBGCVARDESC g_aArgReg[] =
|
---|
253 | {
|
---|
254 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
255 | { 0, 1, DBGCVAR_CAT_SYMBOL, 0, "register", "Register to show or set." },
|
---|
256 | { 0, 1, DBGCVAR_CAT_NUMBER_NO_RANGE, DBGCVD_FLAGS_DEP_PREV, "value", "New register value." },
|
---|
257 | };
|
---|
258 |
|
---|
259 |
|
---|
260 | /** 's' arguments. */
|
---|
261 | static const DBGCVARDESC g_aArgSearchMem[] =
|
---|
262 | {
|
---|
263 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
264 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-b", "Byte string." },
|
---|
265 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-w", "Word string." },
|
---|
266 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-d", "DWord string." },
|
---|
267 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-q", "QWord string." },
|
---|
268 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-a", "ASCII string." },
|
---|
269 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-u", "Unicode string." },
|
---|
270 | { 0, 1, DBGCVAR_CAT_OPTION_NUMBER, 0, "-n <Hits>", "Maximum number of hits." },
|
---|
271 | { 0, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
|
---|
272 | { 0, ~0, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
|
---|
273 | };
|
---|
274 |
|
---|
275 |
|
---|
276 | /** 's?' arguments. */
|
---|
277 | static const DBGCVARDESC g_aArgSearchMemType[] =
|
---|
278 | {
|
---|
279 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
280 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
|
---|
281 | { 1, ~0, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
|
---|
282 | };
|
---|
283 |
|
---|
284 |
|
---|
285 | /** 'u' arguments. */
|
---|
286 | static const DBGCVARDESC g_aArgUnassemble[] =
|
---|
287 | {
|
---|
288 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
289 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start disassembling." },
|
---|
290 | };
|
---|
291 |
|
---|
292 |
|
---|
293 | /** Command descriptors for the CodeView / WinDbg emulation.
|
---|
294 | * The emulation isn't attempting to be identical, only somewhat similar.
|
---|
295 | */
|
---|
296 | const DBGCCMD g_aCmdsCodeView[] =
|
---|
297 | {
|
---|
298 | /* pszCmd, cArgsMin, cArgsMax, paArgDescs, cArgDescs, pResultDesc, fFlags, pfnHandler pszSyntax, ....pszDescription */
|
---|
299 | { "ba", 3, 6, &g_aArgBrkAcc[0], RT_ELEMENTS(g_aArgBrkAcc), NULL, 0, dbgcCmdBrkAccess, "<access> <size> <address> [passes [max passes]] [cmds]",
|
---|
300 | "Sets a data access breakpoint." },
|
---|
301 | { "bc", 1, ~0, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), NULL, 0, dbgcCmdBrkClear, "all | <bp#> [bp# []]", "Enabled a set of breakpoints." },
|
---|
302 | { "bd", 1, ~0, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), NULL, 0, dbgcCmdBrkDisable, "all | <bp#> [bp# []]", "Disables a set of breakpoints." },
|
---|
303 | { "be", 1, ~0, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), NULL, 0, dbgcCmdBrkEnable, "all | <bp#> [bp# []]", "Enabled a set of breakpoints." },
|
---|
304 | { "bl", 0, 0, NULL, 0, NULL, 0, dbgcCmdBrkList, "", "Lists all the breakpoints." },
|
---|
305 | { "bp", 1, 4, &g_aArgBrkSet[0], RT_ELEMENTS(g_aArgBrkSet), NULL, 0, dbgcCmdBrkSet, "<address> [passes [max passes]] [cmds]",
|
---|
306 | "Sets a breakpoint (int 3)." },
|
---|
307 | { "br", 1, 4, &g_aArgBrkREM[0], RT_ELEMENTS(g_aArgBrkREM), NULL, 0, dbgcCmdBrkREM, "<address> [passes [max passes]] [cmds]",
|
---|
308 | "Sets a recompiler specific breakpoint." },
|
---|
309 | { "d", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory using last element size." },
|
---|
310 | { "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
|
---|
311 | { "db", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory in bytes." },
|
---|
312 | { "dd", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory in double words." },
|
---|
313 | { "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
|
---|
314 | { "dg", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), NULL, 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT)." },
|
---|
315 | { "dga", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), NULL, 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT) including not-present entries." },
|
---|
316 | { "di", 0, ~0, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), NULL, 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT)." },
|
---|
317 | { "dia", 0, ~0, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), NULL, 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT) including not-present entries." },
|
---|
318 | { "dl", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), NULL, 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT)." },
|
---|
319 | { "dla", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), NULL, 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT) including not-present entries." },
|
---|
320 | { "dpd", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), NULL, 0, dbgcCmdDumpPageDir, "[addr] [index]", "Dumps page directory entries of the default context." },
|
---|
321 | { "dpda", 0, 1, &g_aArgDumpPDAddr[0],RT_ELEMENTS(g_aArgDumpPDAddr),NULL, 0, dbgcCmdDumpPageDir, "[addr]", "Dumps specified page directory." },
|
---|
322 | { "dpdb", 1, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), NULL, 0, dbgcCmdDumpPageDirBoth, "[addr] [index]", "Dumps page directory entries of the guest and the hypervisor. " },
|
---|
323 | { "dpdg", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), NULL, 0, dbgcCmdDumpPageDir, "[addr] [index]", "Dumps page directory entries of the guest." },
|
---|
324 | { "dpdh", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), NULL, 0, dbgcCmdDumpPageDir, "[addr] [index]", "Dumps page directory entries of the hypervisor. " },
|
---|
325 | { "dph", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), NULL, 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Default context." },
|
---|
326 | { "dphg", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), NULL, 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Guest context." },
|
---|
327 | { "dphh", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), NULL, 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Hypervisor context." },
|
---|
328 | { "dpt", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), NULL, 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the default context." },
|
---|
329 | { "dpta", 1, 1, &g_aArgDumpPTAddr[0],RT_ELEMENTS(g_aArgDumpPTAddr), NULL, 0, dbgcCmdDumpPageTable,"<addr>", "Dumps specified page table." },
|
---|
330 | { "dptb", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), NULL, 0, dbgcCmdDumpPageTableBoth,"<addr>", "Dumps page table entries of the guest and the hypervisor." },
|
---|
331 | { "dptg", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), NULL, 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the guest." },
|
---|
332 | { "dpth", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), NULL, 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the hypervisor." },
|
---|
333 | { "dq", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory in quad words." },
|
---|
334 | { "dt", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), NULL, 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the task state segment (TSS)." },
|
---|
335 | { "dt16", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), NULL, 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 16-bit task state segment (TSS)." },
|
---|
336 | { "dt32", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), NULL, 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 32-bit task state segment (TSS)." },
|
---|
337 | { "dt64", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), NULL, 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 64-bit task state segment (TSS)." },
|
---|
338 | { "dw", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory in words." },
|
---|
339 | /** @todo add 'e', 'ea str', 'eza str', 'eu str' and 'ezu str'. See also
|
---|
340 | * dbgcCmdSearchMem and its dbgcVarsToBytes usage. */
|
---|
341 | { "eb", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), NULL, 0, dbgcCmdEditMem, "<addr> <value>", "Write a 1-byte value to memory." },
|
---|
342 | { "ew", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), NULL, 0, dbgcCmdEditMem, "<addr> <value>", "Write a 2-byte value to memory." },
|
---|
343 | { "ed", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), NULL, 0, dbgcCmdEditMem, "<addr> <value>", "Write a 4-byte value to memory." },
|
---|
344 | { "eq", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), NULL, 0, dbgcCmdEditMem, "<addr> <value>", "Write a 8-byte value to memory." },
|
---|
345 | { "g", 0, 0, NULL, 0, NULL, 0, dbgcCmdGo, "", "Continue execution." },
|
---|
346 | { "k", 0, 0, NULL, 0, NULL, 0, dbgcCmdStack, "", "Callstack." },
|
---|
347 | { "kg", 0, 0, NULL, 0, NULL, 0, dbgcCmdStack, "", "Callstack - guest." },
|
---|
348 | { "kh", 0, 0, NULL, 0, NULL, 0, dbgcCmdStack, "", "Callstack - hypervisor." },
|
---|
349 | { "lm", 0, ~0, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), NULL, 0, dbgcCmdListModules, "[module [..]]", "List modules." },
|
---|
350 | { "lmo", 0, ~0, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), NULL, 0, dbgcCmdListModules, "[module [..]]", "List modules and their segments." },
|
---|
351 | { "ln", 0, ~0, &g_aArgListNear[0], RT_ELEMENTS(g_aArgListNear), &g_RetListNear, 0, dbgcCmdListNear, "[addr/sym [..]]", "List symbols near to the address. Default address is CS:EIP." },
|
---|
352 | { "ls", 0, 1, &g_aArgListSource[0],RT_ELEMENTS(g_aArgListSource),NULL, 0, dbgcCmdListSource, "[addr]", "Source." },
|
---|
353 | { "m", 1, 1, &g_aArgMemoryInfo[0],RT_ELEMENTS(g_aArgMemoryInfo),NULL, 0, dbgcCmdMemoryInfo, "<addr>", "Display information about that piece of memory." },
|
---|
354 | { "r", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), NULL, 0, dbgcCmdReg, "[reg [newval]]", "Show or set register(s) - active reg set." },
|
---|
355 | { "rg", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), NULL, 0, dbgcCmdRegGuest, "[reg [newval]]", "Show or set register(s) - guest reg set." },
|
---|
356 | { "rg32", 0, 0, NULL, 0, NULL, 0, dbgcCmdRegGuest, "", "Show 32-bit guest registers." },
|
---|
357 | { "rg64", 0, 0, NULL, 0, NULL, 0, dbgcCmdRegGuest, "", "Show 64-bit guest registers." },
|
---|
358 | { "rh", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), NULL, 0, dbgcCmdRegHyper, "[reg [newval]]", "Show or set register(s) - hypervisor reg set." },
|
---|
359 | { "rt", 0, 0, NULL, 0, NULL, 0, dbgcCmdRegTerse, "", "Toggles terse / verbose register info." },
|
---|
360 | { "s", 0, ~0, &g_aArgSearchMem[0], RT_ELEMENTS(g_aArgSearchMem), NULL, 0, dbgcCmdSearchMem, "[options] <range> <pattern>", "Continue last search." },
|
---|
361 | { "sa", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an ascii string." },
|
---|
362 | { "sb", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more bytes." },
|
---|
363 | { "sd", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more double words." },
|
---|
364 | { "sq", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more quad words." },
|
---|
365 | { "su", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an unicode string." },
|
---|
366 | { "sw", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more words." },
|
---|
367 | { "t", 0, 0, NULL, 0, NULL, 0, dbgcCmdTrace, "", "Instruction trace (step into)." },
|
---|
368 | { "u", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble),NULL, 0, dbgcCmdUnassemble, "[addr]", "Unassemble." },
|
---|
369 | { "u64", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble),NULL, 0, dbgcCmdUnassemble, "[addr]", "Unassemble 64-bit code." },
|
---|
370 | { "u32", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble),NULL, 0, dbgcCmdUnassemble, "[addr]", "Unassemble 32-bit code." },
|
---|
371 | { "u16", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble),NULL, 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code." },
|
---|
372 | { "uv86", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble),NULL, 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code with v8086/real mode addressing." },
|
---|
373 | };
|
---|
374 |
|
---|
375 | /** The number of commands in the CodeView/WinDbg emulation. */
|
---|
376 | const unsigned g_cCmdsCodeView = RT_ELEMENTS(g_aCmdsCodeView);
|
---|
377 |
|
---|
378 |
|
---|
379 |
|
---|
380 | /**
|
---|
381 | * The 'go' command.
|
---|
382 | *
|
---|
383 | * @returns VBox status.
|
---|
384 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
385 | * @param pCmdHlp Pointer to command helper functions.
|
---|
386 | * @param pVM Pointer to the current VM (if any).
|
---|
387 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
388 | * @param cArgs Number of arguments in the array.
|
---|
389 | */
|
---|
390 | static DECLCALLBACK(int) dbgcCmdGo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
391 | {
|
---|
392 | /*
|
---|
393 | * Check if the VM is halted or not before trying to resume it.
|
---|
394 | */
|
---|
395 | if (!DBGFR3IsHalted(pVM))
|
---|
396 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "warning: The VM is already running...\n");
|
---|
397 | else
|
---|
398 | {
|
---|
399 | int rc = DBGFR3Resume(pVM);
|
---|
400 | if (RT_FAILURE(rc))
|
---|
401 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Executing DBGFR3Resume().");
|
---|
402 | }
|
---|
403 |
|
---|
404 | NOREF(pCmd);
|
---|
405 | NOREF(paArgs);
|
---|
406 | NOREF(cArgs);
|
---|
407 | NOREF(pResult);
|
---|
408 | return 0;
|
---|
409 | }
|
---|
410 |
|
---|
411 |
|
---|
412 | /**
|
---|
413 | * The 'ba' command.
|
---|
414 | *
|
---|
415 | * @returns VBox status.
|
---|
416 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
417 | * @param pCmdHlp Pointer to command helper functions.
|
---|
418 | * @param pVM Pointer to the current VM (if any).
|
---|
419 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
420 | * @param cArgs Number of arguments in the array.
|
---|
421 | */
|
---|
422 | static DECLCALLBACK(int) dbgcCmdBrkAccess(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
|
---|
423 | {
|
---|
424 | /*
|
---|
425 | * Interpret access type.
|
---|
426 | */
|
---|
427 | if ( !strchr("xrwi", paArgs[0].u.pszString[0])
|
---|
428 | || paArgs[0].u.pszString[1])
|
---|
429 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid access type '%s' for '%s'. Valid types are 'e', 'r', 'w' and 'i'.\n",
|
---|
430 | paArgs[0].u.pszString, pCmd->pszCmd);
|
---|
431 | uint8_t fType = 0;
|
---|
432 | switch (paArgs[0].u.pszString[0])
|
---|
433 | {
|
---|
434 | case 'x': fType = X86_DR7_RW_EO; break;
|
---|
435 | case 'r': fType = X86_DR7_RW_RW; break;
|
---|
436 | case 'w': fType = X86_DR7_RW_WO; break;
|
---|
437 | case 'i': fType = X86_DR7_RW_IO; break;
|
---|
438 | }
|
---|
439 |
|
---|
440 | /*
|
---|
441 | * Validate size.
|
---|
442 | */
|
---|
443 | if (fType == X86_DR7_RW_EO && paArgs[1].u.u64Number != 1)
|
---|
444 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid access size %RX64 for '%s'. 'x' access type requires size 1!\n",
|
---|
445 | paArgs[1].u.u64Number, pCmd->pszCmd);
|
---|
446 | switch (paArgs[1].u.u64Number)
|
---|
447 | {
|
---|
448 | case 1:
|
---|
449 | case 2:
|
---|
450 | case 4:
|
---|
451 | break;
|
---|
452 | /*case 8: - later*/
|
---|
453 | default:
|
---|
454 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid access size %RX64 for '%s'. 1, 2 or 4!\n",
|
---|
455 | paArgs[1].u.u64Number, pCmd->pszCmd);
|
---|
456 | }
|
---|
457 | uint8_t cb = (uint8_t)paArgs[1].u.u64Number;
|
---|
458 |
|
---|
459 | /*
|
---|
460 | * Convert the pointer to a DBGF address.
|
---|
461 | */
|
---|
462 | DBGFADDRESS Address;
|
---|
463 | int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[2], &Address);
|
---|
464 | if (RT_FAILURE(rc))
|
---|
465 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Couldn't convert '%DV' to a DBGF address, rc=%Rrc.\n", &paArgs[2], rc);
|
---|
466 |
|
---|
467 | /*
|
---|
468 | * Pick out the optional arguments.
|
---|
469 | */
|
---|
470 | uint64_t iHitTrigger = 0;
|
---|
471 | uint64_t iHitDisable = ~0;
|
---|
472 | const char *pszCmds = NULL;
|
---|
473 | unsigned iArg = 3;
|
---|
474 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
475 | {
|
---|
476 | iHitTrigger = paArgs[iArg].u.u64Number;
|
---|
477 | iArg++;
|
---|
478 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
479 | {
|
---|
480 | iHitDisable = paArgs[iArg].u.u64Number;
|
---|
481 | iArg++;
|
---|
482 | }
|
---|
483 | }
|
---|
484 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
|
---|
485 | {
|
---|
486 | pszCmds = paArgs[iArg].u.pszString;
|
---|
487 | iArg++;
|
---|
488 | }
|
---|
489 |
|
---|
490 | /*
|
---|
491 | * Try set the breakpoint.
|
---|
492 | */
|
---|
493 | RTUINT iBp;
|
---|
494 | rc = DBGFR3BpSetReg(pVM, &Address, iHitTrigger, iHitDisable, fType, cb, &iBp);
|
---|
495 | if (RT_SUCCESS(rc))
|
---|
496 | {
|
---|
497 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
498 | rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
|
---|
499 | if (RT_SUCCESS(rc))
|
---|
500 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Set access breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
501 | if (rc == VERR_DBGC_BP_EXISTS)
|
---|
502 | {
|
---|
503 | rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
|
---|
504 | if (RT_SUCCESS(rc))
|
---|
505 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Updated access breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
506 | }
|
---|
507 | int rc2 = DBGFR3BpClear(pDbgc->pVM, iBp);
|
---|
508 | AssertRC(rc2);
|
---|
509 | }
|
---|
510 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Failed to set access breakpoint at %RGv, rc=%Rrc.\n", Address.FlatPtr, rc);
|
---|
511 | }
|
---|
512 |
|
---|
513 |
|
---|
514 | /**
|
---|
515 | * The 'bc' command.
|
---|
516 | *
|
---|
517 | * @returns VBox status.
|
---|
518 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
519 | * @param pCmdHlp Pointer to command helper functions.
|
---|
520 | * @param pVM Pointer to the current VM (if any).
|
---|
521 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
522 | * @param cArgs Number of arguments in the array.
|
---|
523 | */
|
---|
524 | static DECLCALLBACK(int) dbgcCmdBrkClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
|
---|
525 | {
|
---|
526 | /*
|
---|
527 | * Enumerate the arguments.
|
---|
528 | */
|
---|
529 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
530 | int rc = VINF_SUCCESS;
|
---|
531 | for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
|
---|
532 | {
|
---|
533 | if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
|
---|
534 | {
|
---|
535 | /* one */
|
---|
536 | RTUINT iBp = (RTUINT)paArgs[iArg].u.u64Number;
|
---|
537 | if (iBp != paArgs[iArg].u.u64Number)
|
---|
538 | {
|
---|
539 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Breakpoint id %RX64 is too large!\n", paArgs[iArg].u.u64Number);
|
---|
540 | break;
|
---|
541 | }
|
---|
542 | int rc2 = DBGFR3BpClear(pVM, iBp);
|
---|
543 | if (RT_FAILURE(rc2))
|
---|
544 | rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc2, "DBGFR3BpClear failed for breakpoint %u!\n", iBp);
|
---|
545 | if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
|
---|
546 | dbgcBpDelete(pDbgc, iBp);
|
---|
547 | }
|
---|
548 | else if (!strcmp(paArgs[iArg].u.pszString, "all"))
|
---|
549 | {
|
---|
550 | /* all */
|
---|
551 | PDBGCBP pBp = pDbgc->pFirstBp;
|
---|
552 | while (pBp)
|
---|
553 | {
|
---|
554 | RTUINT iBp = pBp->iBp;
|
---|
555 | pBp = pBp->pNext;
|
---|
556 |
|
---|
557 | int rc2 = DBGFR3BpClear(pVM, iBp);
|
---|
558 | if (RT_FAILURE(rc2))
|
---|
559 | rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc2, "DBGFR3BpClear failed for breakpoint %u!\n", iBp);
|
---|
560 | if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
|
---|
561 | dbgcBpDelete(pDbgc, iBp);
|
---|
562 | }
|
---|
563 | }
|
---|
564 | else
|
---|
565 | {
|
---|
566 | /* invalid parameter */
|
---|
567 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid argument '%s' to '%s'!\n", paArgs[iArg].u.pszString, pCmd->pszCmd);
|
---|
568 | break;
|
---|
569 | }
|
---|
570 | }
|
---|
571 | return rc;
|
---|
572 | }
|
---|
573 |
|
---|
574 |
|
---|
575 | /**
|
---|
576 | * The 'bd' command.
|
---|
577 | *
|
---|
578 | * @returns VBox status.
|
---|
579 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
580 | * @param pCmdHlp Pointer to command helper functions.
|
---|
581 | * @param pVM Pointer to the current VM (if any).
|
---|
582 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
583 | * @param cArgs Number of arguments in the array.
|
---|
584 | */
|
---|
585 | static DECLCALLBACK(int) dbgcCmdBrkDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
|
---|
586 | {
|
---|
587 | /*
|
---|
588 | * Enumerate the arguments.
|
---|
589 | */
|
---|
590 | int rc = VINF_SUCCESS;
|
---|
591 | for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
|
---|
592 | {
|
---|
593 | if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
|
---|
594 | {
|
---|
595 | /* one */
|
---|
596 | RTUINT iBp = (RTUINT)paArgs[iArg].u.u64Number;
|
---|
597 | if (iBp != paArgs[iArg].u.u64Number)
|
---|
598 | {
|
---|
599 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Breakpoint id %RX64 is too large!\n", paArgs[iArg].u.u64Number);
|
---|
600 | break;
|
---|
601 | }
|
---|
602 | rc = DBGFR3BpDisable(pVM, iBp);
|
---|
603 | if (RT_FAILURE(rc))
|
---|
604 | rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3BpDisable failed for breakpoint %u!\n", iBp);
|
---|
605 | }
|
---|
606 | else if (!strcmp(paArgs[iArg].u.pszString, "all"))
|
---|
607 | {
|
---|
608 | /* all */
|
---|
609 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
610 | for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
|
---|
611 | {
|
---|
612 | rc = DBGFR3BpDisable(pVM, pBp->iBp);
|
---|
613 | if (RT_FAILURE(rc))
|
---|
614 | rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3BpDisable failed for breakpoint %u!\n", pBp->iBp);
|
---|
615 | }
|
---|
616 | }
|
---|
617 | else
|
---|
618 | {
|
---|
619 | /* invalid parameter */
|
---|
620 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid argument '%s' to '%s'!\n", paArgs[iArg].u.pszString, pCmd->pszCmd);
|
---|
621 | break;
|
---|
622 | }
|
---|
623 | }
|
---|
624 | return rc;
|
---|
625 | }
|
---|
626 |
|
---|
627 |
|
---|
628 | /**
|
---|
629 | * The 'be' command.
|
---|
630 | *
|
---|
631 | * @returns VBox status.
|
---|
632 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
633 | * @param pCmdHlp Pointer to command helper functions.
|
---|
634 | * @param pVM Pointer to the current VM (if any).
|
---|
635 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
636 | * @param cArgs Number of arguments in the array.
|
---|
637 | */
|
---|
638 | static DECLCALLBACK(int) dbgcCmdBrkEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
|
---|
639 | {
|
---|
640 | /*
|
---|
641 | * Enumerate the arguments.
|
---|
642 | */
|
---|
643 | int rc = VINF_SUCCESS;
|
---|
644 | for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
|
---|
645 | {
|
---|
646 | if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
|
---|
647 | {
|
---|
648 | /* one */
|
---|
649 | RTUINT iBp = (RTUINT)paArgs[iArg].u.u64Number;
|
---|
650 | if (iBp != paArgs[iArg].u.u64Number)
|
---|
651 | {
|
---|
652 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Breakpoint id %RX64 is too large!\n", paArgs[iArg].u.u64Number);
|
---|
653 | break;
|
---|
654 | }
|
---|
655 | rc = DBGFR3BpEnable(pVM, iBp);
|
---|
656 | if (RT_FAILURE(rc))
|
---|
657 | rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3BpEnable failed for breakpoint %u!\n", iBp);
|
---|
658 | }
|
---|
659 | else if (!strcmp(paArgs[iArg].u.pszString, "all"))
|
---|
660 | {
|
---|
661 | /* all */
|
---|
662 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
663 | for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
|
---|
664 | {
|
---|
665 | rc = DBGFR3BpEnable(pVM, pBp->iBp);
|
---|
666 | if (RT_FAILURE(rc))
|
---|
667 | rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3BpEnable failed for breakpoint %u!\n", pBp->iBp);
|
---|
668 | }
|
---|
669 | }
|
---|
670 | else
|
---|
671 | {
|
---|
672 | /* invalid parameter */
|
---|
673 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid argument '%s' to '%s'!\n", paArgs[iArg].u.pszString, pCmd->pszCmd);
|
---|
674 | break;
|
---|
675 | }
|
---|
676 | }
|
---|
677 | return rc;
|
---|
678 | }
|
---|
679 |
|
---|
680 |
|
---|
681 | /**
|
---|
682 | * Breakpoint enumeration callback function.
|
---|
683 | *
|
---|
684 | * @returns VBox status code. Any failure will stop the enumeration.
|
---|
685 | * @param pVM The VM handle.
|
---|
686 | * @param pvUser The user argument.
|
---|
687 | * @param pBp Pointer to the breakpoint information. (readonly)
|
---|
688 | */
|
---|
689 | static DECLCALLBACK(int) dbgcEnumBreakpointsCallback(PVM pVM, void *pvUser, PCDBGFBP pBp)
|
---|
690 | {
|
---|
691 | PDBGC pDbgc = (PDBGC)pvUser;
|
---|
692 | PDBGCBP pDbgcBp = dbgcBpGet(pDbgc, pBp->iBp);
|
---|
693 |
|
---|
694 | /*
|
---|
695 | * BP type and size.
|
---|
696 | */
|
---|
697 | char chType;
|
---|
698 | char cb = 1;
|
---|
699 | switch (pBp->enmType)
|
---|
700 | {
|
---|
701 | case DBGFBPTYPE_INT3:
|
---|
702 | chType = 'p';
|
---|
703 | break;
|
---|
704 | case DBGFBPTYPE_REG:
|
---|
705 | switch (pBp->u.Reg.fType)
|
---|
706 | {
|
---|
707 | case X86_DR7_RW_EO: chType = 'x'; break;
|
---|
708 | case X86_DR7_RW_WO: chType = 'w'; break;
|
---|
709 | case X86_DR7_RW_IO: chType = 'i'; break;
|
---|
710 | case X86_DR7_RW_RW: chType = 'r'; break;
|
---|
711 | default: chType = '?'; break;
|
---|
712 |
|
---|
713 | }
|
---|
714 | cb = pBp->u.Reg.cb;
|
---|
715 | break;
|
---|
716 | case DBGFBPTYPE_REM:
|
---|
717 | chType = 'r';
|
---|
718 | break;
|
---|
719 | default:
|
---|
720 | chType = '?';
|
---|
721 | break;
|
---|
722 | }
|
---|
723 |
|
---|
724 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%2u %c %d %c %RGv %04RX64 (%04RX64 to ",
|
---|
725 | pBp->iBp, pBp->fEnabled ? 'e' : 'd', cb, chType,
|
---|
726 | pBp->GCPtr, pBp->cHits, pBp->iHitTrigger);
|
---|
727 | if (pBp->iHitDisable == ~(uint64_t)0)
|
---|
728 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "~0) ");
|
---|
729 | else
|
---|
730 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%04RX64)");
|
---|
731 |
|
---|
732 | /*
|
---|
733 | * Try resolve the address.
|
---|
734 | */
|
---|
735 | RTDBGSYMBOL Sym;
|
---|
736 | RTINTPTR off;
|
---|
737 | DBGFADDRESS Addr;
|
---|
738 | int rc = DBGFR3AsSymbolByAddr(pVM, pDbgc->hDbgAs, DBGFR3AddrFromFlat(pVM, &Addr, pBp->GCPtr), &off, &Sym, NULL);
|
---|
739 | if (RT_SUCCESS(rc))
|
---|
740 | {
|
---|
741 | if (!off)
|
---|
742 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%s", Sym.szName);
|
---|
743 | else if (off > 0)
|
---|
744 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%s+%RGv", Sym.szName, off);
|
---|
745 | else
|
---|
746 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%s+%RGv", Sym.szName, -off);
|
---|
747 | }
|
---|
748 |
|
---|
749 | /*
|
---|
750 | * The commands.
|
---|
751 | */
|
---|
752 | if (pDbgcBp)
|
---|
753 | {
|
---|
754 | if (pDbgcBp->cchCmd)
|
---|
755 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\n cmds: '%s'\n",
|
---|
756 | pDbgcBp->szCmd);
|
---|
757 | else
|
---|
758 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\n");
|
---|
759 | }
|
---|
760 | else
|
---|
761 | pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, " [unknown bp]\n");
|
---|
762 |
|
---|
763 | return VINF_SUCCESS;
|
---|
764 | }
|
---|
765 |
|
---|
766 |
|
---|
767 | /**
|
---|
768 | * The 'bl' command.
|
---|
769 | *
|
---|
770 | * @returns VBox status.
|
---|
771 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
772 | * @param pCmdHlp Pointer to command helper functions.
|
---|
773 | * @param pVM Pointer to the current VM (if any).
|
---|
774 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
775 | * @param cArgs Number of arguments in the array.
|
---|
776 | */
|
---|
777 | static DECLCALLBACK(int) dbgcCmdBrkList(PCDBGCCMD /*pCmd*/, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR /*paArgs*/, unsigned /*cArgs*/, PDBGCVAR /*pResult*/)
|
---|
778 | {
|
---|
779 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
780 |
|
---|
781 | /*
|
---|
782 | * Enumerate the breakpoints.
|
---|
783 | */
|
---|
784 | int rc = DBGFR3BpEnum(pVM, dbgcEnumBreakpointsCallback, pDbgc);
|
---|
785 | if (RT_FAILURE(rc))
|
---|
786 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3BpEnum failed.\n");
|
---|
787 | return rc;
|
---|
788 | }
|
---|
789 |
|
---|
790 |
|
---|
791 | /**
|
---|
792 | * The 'bp' command.
|
---|
793 | *
|
---|
794 | * @returns VBox status.
|
---|
795 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
796 | * @param pCmdHlp Pointer to command helper functions.
|
---|
797 | * @param pVM Pointer to the current VM (if any).
|
---|
798 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
799 | * @param cArgs Number of arguments in the array.
|
---|
800 | */
|
---|
801 | static DECLCALLBACK(int) dbgcCmdBrkSet(PCDBGCCMD /*pCmd*/, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
|
---|
802 | {
|
---|
803 | /*
|
---|
804 | * Convert the pointer to a DBGF address.
|
---|
805 | */
|
---|
806 | DBGFADDRESS Address;
|
---|
807 | int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
|
---|
808 | if (RT_FAILURE(rc))
|
---|
809 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Couldn't convert '%DV' to a DBGF address, rc=%Rrc.\n", &paArgs[0], rc);
|
---|
810 |
|
---|
811 | /*
|
---|
812 | * Pick out the optional arguments.
|
---|
813 | */
|
---|
814 | uint64_t iHitTrigger = 0;
|
---|
815 | uint64_t iHitDisable = ~0;
|
---|
816 | const char *pszCmds = NULL;
|
---|
817 | unsigned iArg = 1;
|
---|
818 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
819 | {
|
---|
820 | iHitTrigger = paArgs[iArg].u.u64Number;
|
---|
821 | iArg++;
|
---|
822 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
823 | {
|
---|
824 | iHitDisable = paArgs[iArg].u.u64Number;
|
---|
825 | iArg++;
|
---|
826 | }
|
---|
827 | }
|
---|
828 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
|
---|
829 | {
|
---|
830 | pszCmds = paArgs[iArg].u.pszString;
|
---|
831 | iArg++;
|
---|
832 | }
|
---|
833 |
|
---|
834 | /*
|
---|
835 | * Try set the breakpoint.
|
---|
836 | */
|
---|
837 | RTUINT iBp;
|
---|
838 | rc = DBGFR3BpSet(pVM, &Address, iHitTrigger, iHitDisable, &iBp);
|
---|
839 | if (RT_SUCCESS(rc))
|
---|
840 | {
|
---|
841 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
842 | rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
|
---|
843 | if (RT_SUCCESS(rc))
|
---|
844 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Set breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
845 | if (rc == VERR_DBGC_BP_EXISTS)
|
---|
846 | {
|
---|
847 | rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
|
---|
848 | if (RT_SUCCESS(rc))
|
---|
849 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Updated breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
850 | }
|
---|
851 | int rc2 = DBGFR3BpClear(pDbgc->pVM, iBp);
|
---|
852 | AssertRC(rc2);
|
---|
853 | }
|
---|
854 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Failed to set breakpoint at %RGv, rc=%Rrc.\n", Address.FlatPtr, rc);
|
---|
855 | }
|
---|
856 |
|
---|
857 |
|
---|
858 | /**
|
---|
859 | * The 'br' command.
|
---|
860 | *
|
---|
861 | * @returns VBox status.
|
---|
862 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
863 | * @param pCmdHlp Pointer to command helper functions.
|
---|
864 | * @param pVM Pointer to the current VM (if any).
|
---|
865 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
866 | * @param cArgs Number of arguments in the array.
|
---|
867 | */
|
---|
868 | static DECLCALLBACK(int) dbgcCmdBrkREM(PCDBGCCMD /*pCmd*/, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
|
---|
869 | {
|
---|
870 | /*
|
---|
871 | * Convert the pointer to a DBGF address.
|
---|
872 | */
|
---|
873 | DBGFADDRESS Address;
|
---|
874 | int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
|
---|
875 | if (RT_FAILURE(rc))
|
---|
876 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Couldn't convert '%DV' to a DBGF address, rc=%Rrc.\n", &paArgs[0], rc);
|
---|
877 |
|
---|
878 | /*
|
---|
879 | * Pick out the optional arguments.
|
---|
880 | */
|
---|
881 | uint64_t iHitTrigger = 0;
|
---|
882 | uint64_t iHitDisable = ~0;
|
---|
883 | const char *pszCmds = NULL;
|
---|
884 | unsigned iArg = 1;
|
---|
885 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
886 | {
|
---|
887 | iHitTrigger = paArgs[iArg].u.u64Number;
|
---|
888 | iArg++;
|
---|
889 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
890 | {
|
---|
891 | iHitDisable = paArgs[iArg].u.u64Number;
|
---|
892 | iArg++;
|
---|
893 | }
|
---|
894 | }
|
---|
895 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
|
---|
896 | {
|
---|
897 | pszCmds = paArgs[iArg].u.pszString;
|
---|
898 | iArg++;
|
---|
899 | }
|
---|
900 |
|
---|
901 | /*
|
---|
902 | * Try set the breakpoint.
|
---|
903 | */
|
---|
904 | RTUINT iBp;
|
---|
905 | rc = DBGFR3BpSetREM(pVM, &Address, iHitTrigger, iHitDisable, &iBp);
|
---|
906 | if (RT_SUCCESS(rc))
|
---|
907 | {
|
---|
908 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
909 | rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
|
---|
910 | if (RT_SUCCESS(rc))
|
---|
911 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Set REM breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
912 | if (rc == VERR_DBGC_BP_EXISTS)
|
---|
913 | {
|
---|
914 | rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
|
---|
915 | if (RT_SUCCESS(rc))
|
---|
916 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Updated REM breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
917 | }
|
---|
918 | int rc2 = DBGFR3BpClear(pDbgc->pVM, iBp);
|
---|
919 | AssertRC(rc2);
|
---|
920 | }
|
---|
921 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Failed to set REM breakpoint at %RGv, rc=%Rrc.\n", Address.FlatPtr, rc);
|
---|
922 | }
|
---|
923 |
|
---|
924 |
|
---|
925 | /**
|
---|
926 | * The 'u' command.
|
---|
927 | *
|
---|
928 | * @returns VBox status.
|
---|
929 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
930 | * @param pCmdHlp Pointer to command helper functions.
|
---|
931 | * @param pVM Pointer to the current VM (if any).
|
---|
932 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
933 | * @param cArgs Number of arguments in the array.
|
---|
934 | */
|
---|
935 | static DECLCALLBACK(int) dbgcCmdUnassemble(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
936 | {
|
---|
937 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
938 |
|
---|
939 | /*
|
---|
940 | * Validate input.
|
---|
941 | */
|
---|
942 | if ( cArgs > 1
|
---|
943 | || (cArgs == 1 && !DBGCVAR_ISPOINTER(paArgs[0].enmType)))
|
---|
944 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
|
---|
945 | if (!pVM && !cArgs && !DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
|
---|
946 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Don't know where to start disassembling...\n");
|
---|
947 | if (!pVM && cArgs && DBGCVAR_ISGCPOINTER(paArgs[0].enmType))
|
---|
948 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: GC address but no VM.\n");
|
---|
949 |
|
---|
950 | unsigned fFlags = DBGF_DISAS_FLAGS_NO_ADDRESS;
|
---|
951 |
|
---|
952 | /*
|
---|
953 | * Check the desired mode.
|
---|
954 | */
|
---|
955 | switch (pCmd->pszCmd[1])
|
---|
956 | {
|
---|
957 | default: AssertFailed();
|
---|
958 | case '\0': fFlags |= DBGF_DISAS_FLAGS_DEFAULT_MODE; break;
|
---|
959 | case '6': fFlags |= DBGF_DISAS_FLAGS_64BIT_MODE; break;
|
---|
960 | case '3': fFlags |= DBGF_DISAS_FLAGS_32BIT_MODE; break;
|
---|
961 | case '1': fFlags |= DBGF_DISAS_FLAGS_16BIT_MODE; break;
|
---|
962 | case 'v': fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE; break;
|
---|
963 | }
|
---|
964 |
|
---|
965 | /*
|
---|
966 | * Find address.
|
---|
967 | */
|
---|
968 | if (!cArgs)
|
---|
969 | {
|
---|
970 | if (!DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
|
---|
971 | {
|
---|
972 | PVMCPU pVCpu = VMMGetCpuById(pVM, pDbgc->idCpu);
|
---|
973 | if ( pDbgc->fRegCtxGuest
|
---|
974 | && CPUMIsGuestIn64BitCodeEx(CPUMQueryGuestCtxPtr(pVCpu)))
|
---|
975 | {
|
---|
976 | pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
977 | pDbgc->SourcePos.u.GCFlat = CPUMGetGuestRIP(pVCpu);
|
---|
978 | }
|
---|
979 | else
|
---|
980 | {
|
---|
981 | pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FAR;
|
---|
982 | pDbgc->SourcePos.u.GCFar.off = pDbgc->fRegCtxGuest ? CPUMGetGuestEIP(pVCpu) : CPUMGetHyperEIP(pVCpu);
|
---|
983 | pDbgc->SourcePos.u.GCFar.sel = pDbgc->fRegCtxGuest ? CPUMGetGuestCS(pVCpu) : CPUMGetHyperCS(pVCpu);
|
---|
984 | }
|
---|
985 |
|
---|
986 | if (pDbgc->fRegCtxGuest)
|
---|
987 | fFlags |= DBGF_DISAS_FLAGS_CURRENT_GUEST;
|
---|
988 | else
|
---|
989 | fFlags |= DBGF_DISAS_FLAGS_CURRENT_HYPER;
|
---|
990 | }
|
---|
991 | pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
992 | }
|
---|
993 | else
|
---|
994 | pDbgc->DisasmPos = paArgs[0];
|
---|
995 | pDbgc->pLastPos = &pDbgc->DisasmPos;
|
---|
996 |
|
---|
997 | /*
|
---|
998 | * Range.
|
---|
999 | */
|
---|
1000 | switch (pDbgc->DisasmPos.enmRangeType)
|
---|
1001 | {
|
---|
1002 | case DBGCVAR_RANGE_NONE:
|
---|
1003 | pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
1004 | pDbgc->DisasmPos.u64Range = 10;
|
---|
1005 | break;
|
---|
1006 |
|
---|
1007 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
1008 | if (pDbgc->DisasmPos.u64Range > 2048)
|
---|
1009 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Too many lines requested. Max is 2048 lines.\n");
|
---|
1010 | break;
|
---|
1011 |
|
---|
1012 | case DBGCVAR_RANGE_BYTES:
|
---|
1013 | if (pDbgc->DisasmPos.u64Range > 65536)
|
---|
1014 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: The requested range is too big. Max is 64KB.\n");
|
---|
1015 | break;
|
---|
1016 |
|
---|
1017 | default:
|
---|
1018 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: Unknown range type %d.\n", pDbgc->DisasmPos.enmRangeType);
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | /*
|
---|
1022 | * Convert physical and host addresses to guest addresses.
|
---|
1023 | */
|
---|
1024 | int rc;
|
---|
1025 | switch (pDbgc->DisasmPos.enmType)
|
---|
1026 | {
|
---|
1027 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
1028 | case DBGCVAR_TYPE_GC_FAR:
|
---|
1029 | break;
|
---|
1030 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
1031 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
1032 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
1033 | {
|
---|
1034 | DBGCVAR VarTmp;
|
---|
1035 | rc = DBGCCmdHlpEval(pCmdHlp, &VarTmp, "%%(%Dv)", &pDbgc->DisasmPos);
|
---|
1036 | if (RT_FAILURE(rc))
|
---|
1037 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: failed to evaluate '%%(%Dv)' -> %Rrc .\n", &pDbgc->DisasmPos, rc);
|
---|
1038 | pDbgc->DisasmPos = VarTmp;
|
---|
1039 | break;
|
---|
1040 | }
|
---|
1041 | default: AssertFailed(); break;
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | /*
|
---|
1045 | * Print address.
|
---|
1046 | * todo: Change to list near.
|
---|
1047 | */
|
---|
1048 | #if 0
|
---|
1049 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV:\n", &pDbgc->DisasmPos);
|
---|
1050 | if (RT_FAILURE(rc))
|
---|
1051 | return rc;
|
---|
1052 | #endif
|
---|
1053 |
|
---|
1054 | /*
|
---|
1055 | * Do the disassembling.
|
---|
1056 | */
|
---|
1057 | unsigned cTries = 32;
|
---|
1058 | int iRangeLeft = (int)pDbgc->DisasmPos.u64Range;
|
---|
1059 | if (iRangeLeft == 0) /* kludge for 'r'. */
|
---|
1060 | iRangeLeft = -1;
|
---|
1061 | for (;;)
|
---|
1062 | {
|
---|
1063 | /*
|
---|
1064 | * Disassemble the instruction.
|
---|
1065 | */
|
---|
1066 | char szDis[256];
|
---|
1067 | uint32_t cbInstr = 1;
|
---|
1068 | if (pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FLAT)
|
---|
1069 | rc = DBGFR3DisasInstrEx(pVM, pDbgc->idCpu, DBGF_SEL_FLAT, pDbgc->DisasmPos.u.GCFlat, fFlags,
|
---|
1070 | &szDis[0], sizeof(szDis), &cbInstr);
|
---|
1071 | else
|
---|
1072 | rc = DBGFR3DisasInstrEx(pVM, pDbgc->idCpu, pDbgc->DisasmPos.u.GCFar.sel, pDbgc->DisasmPos.u.GCFar.off, fFlags,
|
---|
1073 | &szDis[0], sizeof(szDis), &cbInstr);
|
---|
1074 | if (RT_SUCCESS(rc))
|
---|
1075 | {
|
---|
1076 | /* print it */
|
---|
1077 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%-16DV %s\n", &pDbgc->DisasmPos, &szDis[0]);
|
---|
1078 | if (RT_FAILURE(rc))
|
---|
1079 | return rc;
|
---|
1080 | }
|
---|
1081 | else
|
---|
1082 | {
|
---|
1083 | /* bitch. */
|
---|
1084 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Failed to disassemble instruction, skipping one byte.\n");
|
---|
1085 | if (RT_FAILURE(rc))
|
---|
1086 | return rc;
|
---|
1087 | if (cTries-- > 0)
|
---|
1088 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Too many disassembly failures. Giving up.\n");
|
---|
1089 | cbInstr = 1;
|
---|
1090 | }
|
---|
1091 |
|
---|
1092 | /* advance */
|
---|
1093 | if (iRangeLeft < 0) /* 'r' */
|
---|
1094 | break;
|
---|
1095 | if (pDbgc->DisasmPos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
|
---|
1096 | iRangeLeft--;
|
---|
1097 | else
|
---|
1098 | iRangeLeft -= cbInstr;
|
---|
1099 | rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->DisasmPos, "(%Dv) + %x", &pDbgc->DisasmPos, cbInstr);
|
---|
1100 | if (RT_FAILURE(rc))
|
---|
1101 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->DisasmPos, cbInstr);
|
---|
1102 | if (iRangeLeft <= 0)
|
---|
1103 | break;
|
---|
1104 | fFlags &= ~(DBGF_DISAS_FLAGS_CURRENT_GUEST | DBGF_DISAS_FLAGS_CURRENT_HYPER);
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | NOREF(pCmd); NOREF(pResult);
|
---|
1108 | return 0;
|
---|
1109 | }
|
---|
1110 |
|
---|
1111 |
|
---|
1112 | /**
|
---|
1113 | * The 'ls' command.
|
---|
1114 | *
|
---|
1115 | * @returns VBox status.
|
---|
1116 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1117 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1118 | * @param pVM Pointer to the current VM (if any).
|
---|
1119 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1120 | * @param cArgs Number of arguments in the array.
|
---|
1121 | */
|
---|
1122 | static DECLCALLBACK(int) dbgcCmdListSource(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
1123 | {
|
---|
1124 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1125 |
|
---|
1126 | /*
|
---|
1127 | * Validate input.
|
---|
1128 | */
|
---|
1129 | if ( cArgs > 1
|
---|
1130 | || (cArgs == 1 && !DBGCVAR_ISPOINTER(paArgs[0].enmType)))
|
---|
1131 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
|
---|
1132 | if (!pVM && !cArgs && !DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
|
---|
1133 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Don't know where to start disassembling...\n");
|
---|
1134 | if (!pVM && cArgs && DBGCVAR_ISGCPOINTER(paArgs[0].enmType))
|
---|
1135 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: GC address but no VM.\n");
|
---|
1136 |
|
---|
1137 | /*
|
---|
1138 | * Find address.
|
---|
1139 | */
|
---|
1140 | if (!cArgs)
|
---|
1141 | {
|
---|
1142 | if (!DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
|
---|
1143 | {
|
---|
1144 | PVMCPU pVCpu = VMMGetCpuById(pVM, pDbgc->idCpu);
|
---|
1145 | pDbgc->SourcePos.enmType = DBGCVAR_TYPE_GC_FAR;
|
---|
1146 | pDbgc->SourcePos.u.GCFar.off = pDbgc->fRegCtxGuest ? CPUMGetGuestEIP(pVCpu) : CPUMGetHyperEIP(pVCpu);
|
---|
1147 | pDbgc->SourcePos.u.GCFar.sel = pDbgc->fRegCtxGuest ? CPUMGetGuestCS(pVCpu) : CPUMGetHyperCS(pVCpu);
|
---|
1148 | }
|
---|
1149 | pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
1150 | }
|
---|
1151 | else
|
---|
1152 | pDbgc->SourcePos = paArgs[0];
|
---|
1153 | pDbgc->pLastPos = &pDbgc->SourcePos;
|
---|
1154 |
|
---|
1155 | /*
|
---|
1156 | * Ensure the source address is flat GC.
|
---|
1157 | */
|
---|
1158 | switch (pDbgc->SourcePos.enmType)
|
---|
1159 | {
|
---|
1160 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
1161 | break;
|
---|
1162 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
1163 | case DBGCVAR_TYPE_GC_FAR:
|
---|
1164 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
1165 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
1166 | {
|
---|
1167 | int rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->SourcePos, "%%(%Dv)", &pDbgc->SourcePos);
|
---|
1168 | if (RT_FAILURE(rc))
|
---|
1169 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid address or address type. (rc=%d)\n", rc);
|
---|
1170 | break;
|
---|
1171 | }
|
---|
1172 | default: AssertFailed(); break;
|
---|
1173 | }
|
---|
1174 |
|
---|
1175 | /*
|
---|
1176 | * Range.
|
---|
1177 | */
|
---|
1178 | switch (pDbgc->SourcePos.enmRangeType)
|
---|
1179 | {
|
---|
1180 | case DBGCVAR_RANGE_NONE:
|
---|
1181 | pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
1182 | pDbgc->SourcePos.u64Range = 10;
|
---|
1183 | break;
|
---|
1184 |
|
---|
1185 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
1186 | if (pDbgc->SourcePos.u64Range > 2048)
|
---|
1187 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Too many lines requested. Max is 2048 lines.\n");
|
---|
1188 | break;
|
---|
1189 |
|
---|
1190 | case DBGCVAR_RANGE_BYTES:
|
---|
1191 | if (pDbgc->SourcePos.u64Range > 65536)
|
---|
1192 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: The requested range is too big. Max is 64KB.\n");
|
---|
1193 | break;
|
---|
1194 |
|
---|
1195 | default:
|
---|
1196 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: Unknown range type %d.\n", pDbgc->SourcePos.enmRangeType);
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | /*
|
---|
1200 | * Do the disassembling.
|
---|
1201 | */
|
---|
1202 | bool fFirst = 1;
|
---|
1203 | DBGFLINE LinePrev = { 0, 0, "" };
|
---|
1204 | int iRangeLeft = (int)pDbgc->SourcePos.u64Range;
|
---|
1205 | if (iRangeLeft == 0) /* kludge for 'r'. */
|
---|
1206 | iRangeLeft = -1;
|
---|
1207 | for (;;)
|
---|
1208 | {
|
---|
1209 | /*
|
---|
1210 | * Get line info.
|
---|
1211 | */
|
---|
1212 | DBGFLINE Line;
|
---|
1213 | RTGCINTPTR off;
|
---|
1214 | int rc = DBGFR3LineByAddr(pVM, pDbgc->SourcePos.u.GCFlat, &off, &Line);
|
---|
1215 | if (RT_FAILURE(rc))
|
---|
1216 | return VINF_SUCCESS;
|
---|
1217 |
|
---|
1218 | unsigned cLines = 0;
|
---|
1219 | if (memcmp(&Line, &LinePrev, sizeof(Line)))
|
---|
1220 | {
|
---|
1221 | /*
|
---|
1222 | * Print filenamename
|
---|
1223 | */
|
---|
1224 | if (!fFirst && strcmp(Line.szFilename, LinePrev.szFilename))
|
---|
1225 | fFirst = true;
|
---|
1226 | if (fFirst)
|
---|
1227 | {
|
---|
1228 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "[%s @ %d]\n", Line.szFilename, Line.uLineNo);
|
---|
1229 | if (RT_FAILURE(rc))
|
---|
1230 | return rc;
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 | /*
|
---|
1234 | * Try open the file and read the line.
|
---|
1235 | */
|
---|
1236 | FILE *phFile = fopen(Line.szFilename, "r");
|
---|
1237 | if (phFile)
|
---|
1238 | {
|
---|
1239 | /* Skip ahead to the desired line. */
|
---|
1240 | char szLine[4096];
|
---|
1241 | unsigned cBefore = fFirst ? RT_MIN(2, Line.uLineNo - 1) : Line.uLineNo - LinePrev.uLineNo - 1;
|
---|
1242 | if (cBefore > 7)
|
---|
1243 | cBefore = 0;
|
---|
1244 | unsigned cLeft = Line.uLineNo - cBefore;
|
---|
1245 | while (cLeft > 0)
|
---|
1246 | {
|
---|
1247 | szLine[0] = '\0';
|
---|
1248 | if (!fgets(szLine, sizeof(szLine), phFile))
|
---|
1249 | break;
|
---|
1250 | cLeft--;
|
---|
1251 | }
|
---|
1252 | if (!cLeft)
|
---|
1253 | {
|
---|
1254 | /* print the before lines */
|
---|
1255 | for (;;)
|
---|
1256 | {
|
---|
1257 | size_t cch = strlen(szLine);
|
---|
1258 | while (cch > 0 && (szLine[cch - 1] == '\r' || szLine[cch - 1] == '\n' || RT_C_IS_SPACE(szLine[cch - 1])) )
|
---|
1259 | szLine[--cch] = '\0';
|
---|
1260 | if (cBefore-- <= 0)
|
---|
1261 | break;
|
---|
1262 |
|
---|
1263 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %4d: %s\n", Line.uLineNo - cBefore - 1, szLine);
|
---|
1264 | szLine[0] = '\0';
|
---|
1265 | fgets(szLine, sizeof(szLine), phFile);
|
---|
1266 | cLines++;
|
---|
1267 | }
|
---|
1268 | /* print the actual line */
|
---|
1269 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%08llx %4d: %s\n", Line.Address, Line.uLineNo, szLine);
|
---|
1270 | }
|
---|
1271 | fclose(phFile);
|
---|
1272 | if (RT_FAILURE(rc))
|
---|
1273 | return rc;
|
---|
1274 | fFirst = false;
|
---|
1275 | }
|
---|
1276 | else
|
---|
1277 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Warning: couldn't open source file '%s'\n", Line.szFilename);
|
---|
1278 |
|
---|
1279 | LinePrev = Line;
|
---|
1280 | }
|
---|
1281 |
|
---|
1282 |
|
---|
1283 | /*
|
---|
1284 | * Advance
|
---|
1285 | */
|
---|
1286 | if (iRangeLeft < 0) /* 'r' */
|
---|
1287 | break;
|
---|
1288 | if (pDbgc->SourcePos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
|
---|
1289 | iRangeLeft -= cLines;
|
---|
1290 | else
|
---|
1291 | iRangeLeft -= 1;
|
---|
1292 | rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->SourcePos, "(%Dv) + %x", &pDbgc->SourcePos, 1);
|
---|
1293 | if (RT_FAILURE(rc))
|
---|
1294 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->SourcePos, 1);
|
---|
1295 | if (iRangeLeft <= 0)
|
---|
1296 | break;
|
---|
1297 | }
|
---|
1298 |
|
---|
1299 | NOREF(pCmd); NOREF(pResult);
|
---|
1300 | return 0;
|
---|
1301 | }
|
---|
1302 |
|
---|
1303 |
|
---|
1304 | /**
|
---|
1305 | * The 'r' command.
|
---|
1306 | *
|
---|
1307 | * @returns VBox status.
|
---|
1308 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1309 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1310 | * @param pVM Pointer to the current VM (if any).
|
---|
1311 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1312 | * @param cArgs Number of arguments in the array.
|
---|
1313 | */
|
---|
1314 | static DECLCALLBACK(int) dbgcCmdReg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
1315 | {
|
---|
1316 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1317 | if (!pDbgc->fRegCtxGuest)
|
---|
1318 | return dbgcCmdRegHyper(pCmd, pCmdHlp, pVM, paArgs, cArgs, pResult);
|
---|
1319 | return dbgcCmdRegGuest(pCmd, pCmdHlp, pVM, paArgs, cArgs, pResult);
|
---|
1320 | }
|
---|
1321 |
|
---|
1322 |
|
---|
1323 | /**
|
---|
1324 | * Common worker for the dbgcCmdReg*() commands.
|
---|
1325 | *
|
---|
1326 | * @returns VBox status.
|
---|
1327 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1328 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1329 | * @param pVM Pointer to the current VM (if any).
|
---|
1330 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1331 | * @param cArgs Number of arguments in the array.
|
---|
1332 | * @param pszPrefix The symbol prefix.
|
---|
1333 | */
|
---|
1334 | static DECLCALLBACK(int) dbgcCmdRegCommon(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs,
|
---|
1335 | PDBGCVAR pResult, const char *pszPrefix)
|
---|
1336 | {
|
---|
1337 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1338 | Assert(cArgs == 1 || cArgs == 2); /* cArgs == 0 is handled by the caller */
|
---|
1339 | if ( paArgs[0].enmType != DBGCVAR_TYPE_STRING
|
---|
1340 | && paArgs[0].enmType != DBGCVAR_TYPE_SYMBOL)
|
---|
1341 | return DBGCCmdHlpPrintf(pCmdHlp, "internal error: The parser doesn't do its job properly yet.. Try drop the '@' or/and quote the register name\n");
|
---|
1342 |
|
---|
1343 | /*
|
---|
1344 | * Parse the register name and kind.
|
---|
1345 | */
|
---|
1346 | const char *pszReg = paArgs[0].u.pszString;
|
---|
1347 | if (*pszReg == '@')
|
---|
1348 | pszReg++;
|
---|
1349 | VMCPUID idCpu = pDbgc->idCpu;
|
---|
1350 | if (*pszPrefix)
|
---|
1351 | idCpu |= DBGFREG_HYPER_VMCPUID;
|
---|
1352 | if (*pszReg == '.')
|
---|
1353 | {
|
---|
1354 | pszReg++;
|
---|
1355 | idCpu |= DBGFREG_HYPER_VMCPUID;
|
---|
1356 | }
|
---|
1357 | const char * const pszActualPrefix = idCpu & DBGFREG_HYPER_VMCPUID ? "." : "";
|
---|
1358 |
|
---|
1359 | /*
|
---|
1360 | * Query the register type & value (the setter needs the type).
|
---|
1361 | */
|
---|
1362 | DBGFREGVALTYPE enmType;
|
---|
1363 | DBGFREGVAL Value;
|
---|
1364 | int rc = DBGFR3RegNmQuery(pVM, idCpu, pszReg, &Value, &enmType);
|
---|
1365 | if (RT_FAILURE(rc))
|
---|
1366 | {
|
---|
1367 | if (rc == VERR_DBGF_REGISTER_NOT_FOUND)
|
---|
1368 | return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown register: '%s%s'.\n",
|
---|
1369 | pszActualPrefix, pszReg);
|
---|
1370 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmQuery failed querying '%s%s': %Rrc.\n",
|
---|
1371 | pszActualPrefix, pszReg, rc);
|
---|
1372 | }
|
---|
1373 | if (cArgs == 1)
|
---|
1374 | {
|
---|
1375 | /*
|
---|
1376 | * Show the register.
|
---|
1377 | */
|
---|
1378 | char szValue[160];
|
---|
1379 | rc = DBGFR3RegFormatValue(szValue, sizeof(szValue), &Value, enmType, true /*fSpecial*/);
|
---|
1380 | if (RT_SUCCESS(rc))
|
---|
1381 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%s%s=%s\n", pszActualPrefix, pszReg, szValue);
|
---|
1382 | else
|
---|
1383 | rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegFormatValue failed: %Rrc.\n", rc);
|
---|
1384 | }
|
---|
1385 | else if (cArgs == 2)
|
---|
1386 | {
|
---|
1387 | /*
|
---|
1388 | * Modify the register.
|
---|
1389 | */
|
---|
1390 | if ( paArgs[1].enmType == DBGCVAR_TYPE_STRING
|
---|
1391 | || paArgs[1].enmType == DBGCVAR_TYPE_SYMBOL)
|
---|
1392 | return DBGCCmdHlpPrintf(pCmdHlp, "internal error: The parser doesn't do its job properly on the 2nd argument yet...\n");
|
---|
1393 | if (enmType != DBGFREGVALTYPE_DTR)
|
---|
1394 | {
|
---|
1395 | enmType = DBGFREGVALTYPE_U64;
|
---|
1396 | rc = DBGCCmdHlpVarToNumber(pCmdHlp, &paArgs[1], &Value.u64);
|
---|
1397 | }
|
---|
1398 | else
|
---|
1399 | {
|
---|
1400 | enmType = DBGFREGVALTYPE_DTR;
|
---|
1401 | rc = DBGCCmdHlpVarToNumber(pCmdHlp, &paArgs[1], &Value.dtr.u64Base);
|
---|
1402 | if (RT_SUCCESS(rc) && paArgs[1].enmRangeType != DBGCVAR_RANGE_NONE)
|
---|
1403 | Value.dtr.u32Limit = (uint32_t)paArgs[1].u64Range;
|
---|
1404 | }
|
---|
1405 | if (RT_SUCCESS(rc))
|
---|
1406 | {
|
---|
1407 | rc = DBGFR3RegNmSet(pVM, idCpu, pszReg, &Value, enmType);
|
---|
1408 | if (RT_FAILURE(rc))
|
---|
1409 | rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmSet failed settings '%s%s': %Rrc\n",
|
---|
1410 | pszActualPrefix, pszReg, rc);
|
---|
1411 | }
|
---|
1412 | else
|
---|
1413 | rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegFormatValue failed: %Rrc.\n", rc);
|
---|
1414 | }
|
---|
1415 | else
|
---|
1416 | {
|
---|
1417 | NOREF(pCmd); NOREF(paArgs); NOREF(pResult);
|
---|
1418 | rc = DBGCCmdHlpPrintf(pCmdHlp, "Huh? cArgs=%d Expected 0, 1 or 2!\n", cArgs);
|
---|
1419 | }
|
---|
1420 | return rc;
|
---|
1421 | }
|
---|
1422 |
|
---|
1423 |
|
---|
1424 | /**
|
---|
1425 | * The 'rg', 'rg64' and 'rg32' commands.
|
---|
1426 | *
|
---|
1427 | * @returns VBox status.
|
---|
1428 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1429 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1430 | * @param pVM Pointer to the current VM (if any).
|
---|
1431 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1432 | * @param cArgs Number of arguments in the array.
|
---|
1433 | */
|
---|
1434 | static DECLCALLBACK(int) dbgcCmdRegGuest(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
1435 | {
|
---|
1436 | /*
|
---|
1437 | * Show all registers our selves.
|
---|
1438 | */
|
---|
1439 | if (cArgs == 0)
|
---|
1440 | {
|
---|
1441 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1442 | bool const f64BitMode = !strcmp(pCmd->pszCmd, "rg64")
|
---|
1443 | || ( !strcmp(pCmd->pszCmd, "rg32")
|
---|
1444 | && CPUMIsGuestIn64BitCodeEx(CPUMQueryGuestCtxPtr(VMMGetCpuById(pVM, pDbgc->idCpu))));
|
---|
1445 | char szDisAndRegs[8192];
|
---|
1446 | int rc;
|
---|
1447 |
|
---|
1448 | if (pDbgc->fRegTerse)
|
---|
1449 | {
|
---|
1450 | if (f64BitMode)
|
---|
1451 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu, &szDisAndRegs[0], sizeof(szDisAndRegs),
|
---|
1452 | "u %016VR{rip} L 0\n"
|
---|
1453 | "rax=%016VR{rax} rbx=%016VR{rbx} rcx=%016VR{rcx} rdx=%016VR{rdx}\n"
|
---|
1454 | "rsi=%016VR{rsi} rdi=%016VR{rdi} r8 =%016VR{r8} r9 =%016VR{r9}\n"
|
---|
1455 | "r10=%016VR{r10} r11=%016VR{r11} r12=%016VR{r12} r13=%016VR{r13}\n"
|
---|
1456 | "r14=%016VR{r14} r15=%016VR{r15} %VRF{rflags}\n"
|
---|
1457 | "rip=%016VR{rip} rsp=%016VR{rsp} rbp=%016VR{rbp}\n"
|
---|
1458 | "cs=%04VR{cs} ds=%04VR{ds} es=%04VR{es} fs=%04VR{fs} gs=%04VR{gs} ss=%04VR{ss} rflags=%08VR{rflags}\n");
|
---|
1459 | else
|
---|
1460 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
1461 | "u %04VR{cs}:%08VR{eip} L 0\n"
|
---|
1462 | "eax=%08VR{eax} ebx=%08VR{ebx} ecx=%08VR{ecx} edx=%08VR{edx} esi=%08VR{esi} edi=%08VR{edi}\n"
|
---|
1463 | "eip=%08VR{eip} esp=%08VR{esp} ebp=%08VR{ebp} %VRF{eflags}\n"
|
---|
1464 | "cs=%04VR{cs} ds=%04VR{ds} es=%04VR{es} fs=%04VR{fs} gs=%04VR{gs} ss=%04VR{ss} eflags=%08VR{eflags}\n");
|
---|
1465 | }
|
---|
1466 | else
|
---|
1467 | {
|
---|
1468 | if (f64BitMode)
|
---|
1469 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu, &szDisAndRegs[0], sizeof(szDisAndRegs),
|
---|
1470 | "u %016VR{rip} L 0\n"
|
---|
1471 | "rax=%016VR{rax} rbx=%016VR{rbx} rcx=%016VR{rcx} rdx=%016VR{rdx}\n"
|
---|
1472 | "rsi=%016VR{rsi} rdi=%016VR{rdi} r8 =%016VR{r8} r9 =%016VR{r9}\n"
|
---|
1473 | "r10=%016VR{r10} r11=%016VR{r11} r12=%016VR{r12} r13=%016VR{r13}\n"
|
---|
1474 | "r14=%016VR{r14} r15=%016VR{r15} %VRF{rflags}\n"
|
---|
1475 | "rip=%016VR{rip} rsp=%016VR{rsp} rbp=%016VR{rbp}\n"
|
---|
1476 | "cs={%04VR{cs} base=%016VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} cr0=%016VR{cr0}\n"
|
---|
1477 | "ds={%04VR{ds} base=%016VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} cr2=%016VR{cr2}\n"
|
---|
1478 | "es={%04VR{es} base=%016VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} cr3=%016VR{cr3}\n"
|
---|
1479 | "fs={%04VR{fs} base=%016VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} cr4=%016VR{cr4}\n"
|
---|
1480 | "gs={%04VR{gs} base=%016VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}} cr8=%016VR{cr8}\n"
|
---|
1481 | "ss={%04VR{ss} base=%016VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}}\n"
|
---|
1482 | "dr0=%016VR{dr0} dr1=%016VR{dr1} dr2=%016VR{dr2} dr3=%016VR{dr3}\n"
|
---|
1483 | "dr6=%016VR{dr6} dr7=%016VR{dr7}\n"
|
---|
1484 | "gdtr=%016VR{gdtr_base}:%04VR{gdtr_lim} idtr=%016VR{idtr_base}:%04VR{idtr_lim} rflags=%08VR{rflags}\n"
|
---|
1485 | "ldtr={%04VR{ldtr} base=%016VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%08VR{ldtr_attr}}\n"
|
---|
1486 | "tr ={%04VR{tr} base=%016VR{tr_base} limit=%08VR{tr_lim} flags=%08VR{tr_attr}}\n"
|
---|
1487 | " sysenter={cs=%04VR{sysenter_cs} eip=%08VR{sysenter_eip} esp=%08VR{sysenter_esp}}\n"
|
---|
1488 | " efer=%016VR{efer}\n"
|
---|
1489 | " pat=%016VR{pat}\n"
|
---|
1490 | " sf_mask=%016VR{sf_mask}\n"
|
---|
1491 | "krnl_gs_base=%016VR{krnl_gs_base}\n"
|
---|
1492 | " lstar=%016VR{lstar}\n"
|
---|
1493 | " star=%016VR{star} cstar=%016VR{cstar}\n"
|
---|
1494 | "fcw=%04VR{fcw} fsw=%04VR{fsw} ftw=%04VR{ftw} mxcsr=%04VR{mxcsr} mxcsr_mask=%04VR{mxcsr_mask}\n"
|
---|
1495 | );
|
---|
1496 | else
|
---|
1497 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
1498 | "u %04VR{cs}:%08VR{eip} L 0\n"
|
---|
1499 | "eax=%08VR{eax} ebx=%08VR{ebx} ecx=%08VR{ecx} edx=%08VR{edx} esi=%08VR{esi} edi=%08VR{edi}\n"
|
---|
1500 | "eip=%08VR{eip} esp=%08VR{esp} ebp=%08VR{ebp} %VRF{eflags}\n"
|
---|
1501 | "cs={%04VR{cs} base=%08VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} dr0=%08VR{dr0} dr1=%08VR{dr1}\n"
|
---|
1502 | "ds={%04VR{ds} base=%08VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} dr2=%08VR{dr2} dr3=%08VR{dr3}\n"
|
---|
1503 | "es={%04VR{es} base=%08VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} dr6=%08VR{dr6} dr6=%08VR{dr6}\n"
|
---|
1504 | "fs={%04VR{fs} base=%08VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} cr0=%08VR{cr0} cr2=%08VR{cr0}\n"
|
---|
1505 | "gs={%04VR{gs} base=%08VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}} cr3=%08VR{cr0} cr4=%08VR{cr0}\n"
|
---|
1506 | "ss={%04VR{ss} base=%08VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}} cr8=%08VR{cr8}\n"
|
---|
1507 | "gdtr=%08VR{gdtr_base}:%04VR{gdtr_lim} idtr=%08VR{idtr_base}:%04VR{idtr_lim} eflags=%08VR{eflags}\n"
|
---|
1508 | "ldtr={%04VR{ldtr} base=%08VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%04VR{ldtr_attr}}\n"
|
---|
1509 | "tr ={%04VR{tr} base=%08VR{tr_base} limit=%08VR{tr_lim} flags=%04VR{tr_attr}}\n"
|
---|
1510 | "sysenter={cs=%04VR{sysenter_cs} eip=%08VR{sysenter_eip} esp=%08VR{sysenter_esp}}\n"
|
---|
1511 | "fcw=%04VR{fcw} fsw=%04VR{fsw} ftw=%04VR{ftw} mxcsr=%04VR{mxcsr} mxcsr_mask=%04VR{mxcsr_mask}\n"
|
---|
1512 | );
|
---|
1513 | }
|
---|
1514 | if (RT_FAILURE(rc))
|
---|
1515 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegPrintf failed");
|
---|
1516 | char *pszRegs = strchr(szDisAndRegs, '\n');
|
---|
1517 | *pszRegs++ = '\0';
|
---|
1518 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%s", pszRegs);
|
---|
1519 |
|
---|
1520 | /*
|
---|
1521 | * Disassemble one instruction at cs:[r|e]ip.
|
---|
1522 | */
|
---|
1523 | return pCmdHlp->pfnExec(pCmdHlp, "%s", szDisAndRegs);
|
---|
1524 | }
|
---|
1525 | return dbgcCmdRegCommon(pCmd, pCmdHlp, pVM, paArgs, cArgs, pResult, "");
|
---|
1526 | }
|
---|
1527 |
|
---|
1528 |
|
---|
1529 | /**
|
---|
1530 | * The 'rh' command.
|
---|
1531 | *
|
---|
1532 | * @returns VBox status.
|
---|
1533 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1534 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1535 | * @param pVM Pointer to the current VM (if any).
|
---|
1536 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1537 | * @param cArgs Number of arguments in the array.
|
---|
1538 | */
|
---|
1539 | static DECLCALLBACK(int) dbgcCmdRegHyper(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
1540 | {
|
---|
1541 | /*
|
---|
1542 | * Show all registers our selves.
|
---|
1543 | */
|
---|
1544 | if (cArgs == 0)
|
---|
1545 | {
|
---|
1546 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1547 | char szDisAndRegs[8192];
|
---|
1548 | int rc;
|
---|
1549 |
|
---|
1550 | if (pDbgc->fRegTerse)
|
---|
1551 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu | DBGFREG_HYPER_VMCPUID, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
1552 | "u %VR{cs}:%VR{eip} L 0\n"
|
---|
1553 | ".eax=%08VR{eax} .ebx=%08VR{ebx} .ecx=%08VR{ecx} .edx=%08VR{edx} .esi=%08VR{esi} .edi=%08VR{edi}\n"
|
---|
1554 | ".eip=%08VR{eip} .esp=%08VR{esp} .ebp=%08VR{ebp} .%VRF{eflags}\n"
|
---|
1555 | ".cs=%04VR{cs} .ds=%04VR{ds} .es=%04VR{es} .fs=%04VR{fs} .gs=%04VR{gs} .ss=%04VR{ss} .eflags=%08VR{eflags}\n");
|
---|
1556 | else
|
---|
1557 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu | DBGFREG_HYPER_VMCPUID, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
1558 | "u %04VR{cs}:%08VR{eip} L 0\n"
|
---|
1559 | ".eax=%08VR{eax} .ebx=%08VR{ebx} .ecx=%08VR{ecx} .edx=%08VR{edx} .esi=%08VR{esi} .edi=%08VR{edi}\n"
|
---|
1560 | ".eip=%08VR{eip} .esp=%08VR{esp} .ebp=%08VR{ebp} .%VRF{eflags}\n"
|
---|
1561 | ".cs={%04VR{cs} base=%08VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} .dr0=%08VR{dr0} .dr1=%08VR{dr1}\n"
|
---|
1562 | ".ds={%04VR{ds} base=%08VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} .dr2=%08VR{dr2} .dr3=%08VR{dr3}\n"
|
---|
1563 | ".es={%04VR{es} base=%08VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} .dr6=%08VR{dr6} .dr6=%08VR{dr6}\n"
|
---|
1564 | ".fs={%04VR{fs} base=%08VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} .cr3=%016VR{cr3}\n"
|
---|
1565 | ".gs={%04VR{gs} base=%08VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}}\n"
|
---|
1566 | ".ss={%04VR{ss} base=%08VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}}\n"
|
---|
1567 | ".gdtr=%08VR{gdtr_base}:%04VR{gdtr_lim} .idtr=%08VR{idtr_base}:%04VR{idtr_lim} .eflags=%08VR{eflags}\n"
|
---|
1568 | ".ldtr={%04VR{ldtr} base=%08VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%04VR{ldtr_attr}}\n"
|
---|
1569 | ".tr ={%04VR{tr} base=%08VR{tr_base} limit=%08VR{tr_lim} flags=%04VR{tr_attr}}\n"
|
---|
1570 | );
|
---|
1571 | if (RT_FAILURE(rc))
|
---|
1572 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegPrintf failed");
|
---|
1573 | char *pszRegs = strchr(szDisAndRegs, '\n');
|
---|
1574 | *pszRegs++ = '\0';
|
---|
1575 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%s", pszRegs);
|
---|
1576 |
|
---|
1577 | /*
|
---|
1578 | * Disassemble one instruction at cs:[r|e]ip.
|
---|
1579 | */
|
---|
1580 | return pCmdHlp->pfnExec(pCmdHlp, "%s", szDisAndRegs);
|
---|
1581 | }
|
---|
1582 | return dbgcCmdRegCommon(pCmd, pCmdHlp, pVM, paArgs, cArgs, pResult, ".");
|
---|
1583 | }
|
---|
1584 |
|
---|
1585 |
|
---|
1586 | /**
|
---|
1587 | * The 'rt' command.
|
---|
1588 | *
|
---|
1589 | * @returns VBox status.
|
---|
1590 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1591 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1592 | * @param pVM Pointer to the current VM (if any).
|
---|
1593 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1594 | * @param cArgs Number of arguments in the array.
|
---|
1595 | */
|
---|
1596 | static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
1597 | {
|
---|
1598 | NOREF(pCmd); NOREF(pVM); NOREF(paArgs); NOREF(cArgs); NOREF(pResult);
|
---|
1599 |
|
---|
1600 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1601 | pDbgc->fRegTerse = !pDbgc->fRegTerse;
|
---|
1602 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, pDbgc->fRegTerse ? "info: Terse register info.\n" : "info: Verbose register info.\n");
|
---|
1603 | }
|
---|
1604 |
|
---|
1605 |
|
---|
1606 | /**
|
---|
1607 | * The 't' command.
|
---|
1608 | *
|
---|
1609 | * @returns VBox status.
|
---|
1610 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1611 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1612 | * @param pVM Pointer to the current VM (if any).
|
---|
1613 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1614 | * @param cArgs Number of arguments in the array.
|
---|
1615 | */
|
---|
1616 | static DECLCALLBACK(int) dbgcCmdTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
1617 | {
|
---|
1618 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1619 |
|
---|
1620 | int rc = DBGFR3Step(pVM, pDbgc->idCpu);
|
---|
1621 | if (RT_SUCCESS(rc))
|
---|
1622 | pDbgc->fReady = false;
|
---|
1623 | else
|
---|
1624 | rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "When trying to single step VM %p\n", pDbgc->pVM);
|
---|
1625 |
|
---|
1626 | NOREF(pCmd); NOREF(paArgs); NOREF(cArgs); NOREF(pResult);
|
---|
1627 | return rc;
|
---|
1628 | }
|
---|
1629 |
|
---|
1630 |
|
---|
1631 | /**
|
---|
1632 | * The 'k', 'kg' and 'kh' commands.
|
---|
1633 | *
|
---|
1634 | * @returns VBox status.
|
---|
1635 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1636 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1637 | * @param pVM Pointer to the current VM (if any).
|
---|
1638 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1639 | * @param cArgs Number of arguments in the array.
|
---|
1640 | */
|
---|
1641 | static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
1642 | {
|
---|
1643 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1644 |
|
---|
1645 | /*
|
---|
1646 | * Figure which context we're called for and start walking that stack.
|
---|
1647 | */
|
---|
1648 | int rc;
|
---|
1649 | PCDBGFSTACKFRAME pFirstFrame;
|
---|
1650 | bool const fGuest = pCmd->pszCmd[1] == 'g'
|
---|
1651 | || (!pCmd->pszCmd[1] && pDbgc->fRegCtxGuest);
|
---|
1652 | rc = DBGFR3StackWalkBegin(pVM, pDbgc->idCpu, fGuest ? DBGFCODETYPE_GUEST : DBGFCODETYPE_HYPER, &pFirstFrame);
|
---|
1653 | if (RT_FAILURE(rc))
|
---|
1654 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Failed to begin stack walk, rc=%Rrc\n", rc);
|
---|
1655 |
|
---|
1656 | /*
|
---|
1657 | * Print header.
|
---|
1658 | * 12345678 12345678 0023:87654321 12345678 87654321 12345678 87654321 symbol
|
---|
1659 | */
|
---|
1660 | uint32_t fBitFlags = 0;
|
---|
1661 | for (PCDBGFSTACKFRAME pFrame = pFirstFrame;
|
---|
1662 | pFrame;
|
---|
1663 | pFrame = DBGFR3StackWalkNext(pFrame))
|
---|
1664 | {
|
---|
1665 | uint32_t const fCurBitFlags = pFrame->fFlags & (DBGFSTACKFRAME_FLAGS_16BIT | DBGFSTACKFRAME_FLAGS_32BIT | DBGFSTACKFRAME_FLAGS_64BIT);
|
---|
1666 | if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_16BIT)
|
---|
1667 | {
|
---|
1668 | if (fCurBitFlags != fBitFlags)
|
---|
1669 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "SS:BP Ret SS:BP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
|
---|
1670 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04RX16:%04RX16 %04RX16:%04RX16 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
|
---|
1671 | pFrame->AddrFrame.Sel,
|
---|
1672 | (uint16_t)pFrame->AddrFrame.off,
|
---|
1673 | pFrame->AddrReturnFrame.Sel,
|
---|
1674 | (uint16_t)pFrame->AddrReturnFrame.off,
|
---|
1675 | (uint32_t)pFrame->AddrReturnPC.Sel,
|
---|
1676 | (uint32_t)pFrame->AddrReturnPC.off,
|
---|
1677 | pFrame->Args.au32[0],
|
---|
1678 | pFrame->Args.au32[1],
|
---|
1679 | pFrame->Args.au32[2],
|
---|
1680 | pFrame->Args.au32[3]);
|
---|
1681 | }
|
---|
1682 | else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_32BIT)
|
---|
1683 | {
|
---|
1684 | if (fCurBitFlags != fBitFlags)
|
---|
1685 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
|
---|
1686 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
|
---|
1687 | (uint32_t)pFrame->AddrFrame.off,
|
---|
1688 | (uint32_t)pFrame->AddrReturnFrame.off,
|
---|
1689 | (uint32_t)pFrame->AddrReturnPC.Sel,
|
---|
1690 | (uint32_t)pFrame->AddrReturnPC.off,
|
---|
1691 | pFrame->Args.au32[0],
|
---|
1692 | pFrame->Args.au32[1],
|
---|
1693 | pFrame->Args.au32[2],
|
---|
1694 | pFrame->Args.au32[3]);
|
---|
1695 | }
|
---|
1696 | else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT)
|
---|
1697 | {
|
---|
1698 | if (fCurBitFlags != fBitFlags)
|
---|
1699 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "RBP Ret SS:RBP Ret RIP CS:RIP / Symbol [line]\n");
|
---|
1700 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%016RX64 %04RX16:%016RX64 %016RX64",
|
---|
1701 | (uint64_t)pFrame->AddrFrame.off,
|
---|
1702 | pFrame->AddrReturnFrame.Sel,
|
---|
1703 | (uint64_t)pFrame->AddrReturnFrame.off,
|
---|
1704 | (uint64_t)pFrame->AddrReturnPC.off);
|
---|
1705 | }
|
---|
1706 | if (RT_FAILURE(rc))
|
---|
1707 | break;
|
---|
1708 | if (!pFrame->pSymPC)
|
---|
1709 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL,
|
---|
1710 | fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT
|
---|
1711 | ? " %RTsel:%016RGv"
|
---|
1712 | : fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT
|
---|
1713 | ? " %RTsel:%08RGv"
|
---|
1714 | : " %RTsel:%04RGv"
|
---|
1715 | , pFrame->AddrPC.Sel, pFrame->AddrPC.off);
|
---|
1716 | else
|
---|
1717 | {
|
---|
1718 | RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value; /** @todo this isn't 100% correct for segmented stuff. */
|
---|
1719 | if (offDisp > 0)
|
---|
1720 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %s+%llx", pFrame->pSymPC->szName, (int64_t)offDisp);
|
---|
1721 | else if (offDisp < 0)
|
---|
1722 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %s-%llx", pFrame->pSymPC->szName, -(int64_t)offDisp);
|
---|
1723 | else
|
---|
1724 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %s", pFrame->pSymPC->szName);
|
---|
1725 | }
|
---|
1726 | if (RT_SUCCESS(rc) && pFrame->pLinePC)
|
---|
1727 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
|
---|
1728 | if (RT_SUCCESS(rc))
|
---|
1729 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
|
---|
1730 | if (RT_FAILURE(rc))
|
---|
1731 | break;
|
---|
1732 |
|
---|
1733 | fBitFlags = fCurBitFlags;
|
---|
1734 | }
|
---|
1735 |
|
---|
1736 | DBGFR3StackWalkEnd(pFirstFrame);
|
---|
1737 |
|
---|
1738 | NOREF(paArgs); NOREF(cArgs); NOREF(pResult);
|
---|
1739 | return rc;
|
---|
1740 | }
|
---|
1741 |
|
---|
1742 |
|
---|
1743 | static int dbgcCmdDumpDTWorker64(PDBGCCMDHLP pCmdHlp, PCX86DESC64 pDesc, unsigned iEntry, bool fHyper, bool *pfDblEntry)
|
---|
1744 | {
|
---|
1745 | /* GUEST64 */
|
---|
1746 | int rc;
|
---|
1747 |
|
---|
1748 | const char *pszHyper = fHyper ? " HYPER" : "";
|
---|
1749 | const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
|
---|
1750 | if (pDesc->Gen.u1DescType)
|
---|
1751 | {
|
---|
1752 | static const char * const s_apszTypes[] =
|
---|
1753 | {
|
---|
1754 | "DataRO", /* 0 Read-Only */
|
---|
1755 | "DataRO", /* 1 Read-Only - Accessed */
|
---|
1756 | "DataRW", /* 2 Read/Write */
|
---|
1757 | "DataRW", /* 3 Read/Write - Accessed */
|
---|
1758 | "DownRO", /* 4 Expand-down, Read-Only */
|
---|
1759 | "DownRO", /* 5 Expand-down, Read-Only - Accessed */
|
---|
1760 | "DownRW", /* 6 Expand-down, Read/Write */
|
---|
1761 | "DownRO", /* 7 Expand-down, Read/Write - Accessed */
|
---|
1762 | "CodeEO", /* 8 Execute-Only */
|
---|
1763 | "CodeEO", /* 9 Execute-Only - Accessed */
|
---|
1764 | "CodeER", /* A Execute/Readable */
|
---|
1765 | "CodeER", /* B Execute/Readable - Accessed */
|
---|
1766 | "ConfE0", /* C Conforming, Execute-Only */
|
---|
1767 | "ConfE0", /* D Conforming, Execute-Only - Accessed */
|
---|
1768 | "ConfER", /* E Conforming, Execute/Readable */
|
---|
1769 | "ConfER" /* F Conforming, Execute/Readable - Accessed */
|
---|
1770 | };
|
---|
1771 | const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
|
---|
1772 | const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
|
---|
1773 | const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
|
---|
1774 | uint32_t u32Base = X86DESC_BASE(*pDesc);
|
---|
1775 | uint32_t cbLimit = X86DESC_LIMIT(*pDesc);
|
---|
1776 | if (pDesc->Gen.u1Granularity)
|
---|
1777 | cbLimit <<= PAGE_SHIFT;
|
---|
1778 |
|
---|
1779 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
|
---|
1780 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
|
---|
1781 | pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
|
---|
1782 | pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
|
---|
1783 | }
|
---|
1784 | else
|
---|
1785 | {
|
---|
1786 | static const char * const s_apszTypes[] =
|
---|
1787 | {
|
---|
1788 | "Ill-0 ", /* 0 0000 Reserved (Illegal) */
|
---|
1789 | "Ill-1 ", /* 1 0001 Available 16-bit TSS */
|
---|
1790 | "LDT ", /* 2 0010 LDT */
|
---|
1791 | "Ill-3 ", /* 3 0011 Busy 16-bit TSS */
|
---|
1792 | "Ill-4 ", /* 4 0100 16-bit Call Gate */
|
---|
1793 | "Ill-5 ", /* 5 0101 Task Gate */
|
---|
1794 | "Ill-6 ", /* 6 0110 16-bit Interrupt Gate */
|
---|
1795 | "Ill-7 ", /* 7 0111 16-bit Trap Gate */
|
---|
1796 | "Ill-8 ", /* 8 1000 Reserved (Illegal) */
|
---|
1797 | "Tss64A", /* 9 1001 Available 32-bit TSS */
|
---|
1798 | "Ill-A ", /* A 1010 Reserved (Illegal) */
|
---|
1799 | "Tss64B", /* B 1011 Busy 32-bit TSS */
|
---|
1800 | "Call64", /* C 1100 32-bit Call Gate */
|
---|
1801 | "Ill-D ", /* D 1101 Reserved (Illegal) */
|
---|
1802 | "Int64 ", /* E 1110 32-bit Interrupt Gate */
|
---|
1803 | "Trap64" /* F 1111 32-bit Trap Gate */
|
---|
1804 | };
|
---|
1805 | switch (pDesc->Gen.u4Type)
|
---|
1806 | {
|
---|
1807 | /* raw */
|
---|
1808 | case X86_SEL_TYPE_SYS_UNDEFINED:
|
---|
1809 | case X86_SEL_TYPE_SYS_UNDEFINED2:
|
---|
1810 | case X86_SEL_TYPE_SYS_UNDEFINED4:
|
---|
1811 | case X86_SEL_TYPE_SYS_UNDEFINED3:
|
---|
1812 | case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
|
---|
1813 | case X86_SEL_TYPE_SYS_286_TSS_BUSY:
|
---|
1814 | case X86_SEL_TYPE_SYS_286_CALL_GATE:
|
---|
1815 | case X86_SEL_TYPE_SYS_286_INT_GATE:
|
---|
1816 | case X86_SEL_TYPE_SYS_286_TRAP_GATE:
|
---|
1817 | case X86_SEL_TYPE_SYS_TASK_GATE:
|
---|
1818 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s %.8Rhxs DPL=%d %s%s\n",
|
---|
1819 | iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
|
---|
1820 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
1821 | break;
|
---|
1822 |
|
---|
1823 | case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
|
---|
1824 | case X86_SEL_TYPE_SYS_386_TSS_BUSY:
|
---|
1825 | case X86_SEL_TYPE_SYS_LDT:
|
---|
1826 | {
|
---|
1827 | const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
|
---|
1828 | const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
|
---|
1829 | const char *pszLong = pDesc->Gen.u1Long ? "LONG" : " ";
|
---|
1830 |
|
---|
1831 | uint64_t u32Base = X86DESC64_BASE(*pDesc);
|
---|
1832 | uint32_t cbLimit = X86DESC_LIMIT(*pDesc);
|
---|
1833 |
|
---|
1834 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%016RX64 Lim=%08x DPL=%d %s %s %s %sAVL=%d R=%d%s\n",
|
---|
1835 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
|
---|
1836 | pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszLong, pszBig,
|
---|
1837 | pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
|
---|
1838 | pszHyper);
|
---|
1839 | if (pfDblEntry)
|
---|
1840 | *pfDblEntry = true;
|
---|
1841 | break;
|
---|
1842 | }
|
---|
1843 |
|
---|
1844 | case X86_SEL_TYPE_SYS_386_CALL_GATE:
|
---|
1845 | {
|
---|
1846 | unsigned cParams = pDesc->au8[4] & 0x1f;
|
---|
1847 | const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
|
---|
1848 | RTSEL sel = pDesc->au16[1];
|
---|
1849 | uint64_t off = pDesc->au16[0]
|
---|
1850 | | ((uint64_t)pDesc->au16[3] << 16)
|
---|
1851 | | ((uint64_t)pDesc->Gen.u32BaseHigh3 << 32);
|
---|
1852 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%016RX64 DPL=%d %s %s=%d%s\n",
|
---|
1853 | iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
|
---|
1854 | pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper);
|
---|
1855 | if (pfDblEntry)
|
---|
1856 | *pfDblEntry = true;
|
---|
1857 | break;
|
---|
1858 | }
|
---|
1859 |
|
---|
1860 | case X86_SEL_TYPE_SYS_386_INT_GATE:
|
---|
1861 | case X86_SEL_TYPE_SYS_386_TRAP_GATE:
|
---|
1862 | {
|
---|
1863 | RTSEL sel = pDesc->au16[1];
|
---|
1864 | uint64_t off = pDesc->au16[0]
|
---|
1865 | | ((uint64_t)pDesc->au16[3] << 16)
|
---|
1866 | | ((uint64_t)pDesc->Gen.u32BaseHigh3 << 32);
|
---|
1867 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%016RX64 DPL=%d %s%s\n",
|
---|
1868 | iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
|
---|
1869 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
1870 | if (pfDblEntry)
|
---|
1871 | *pfDblEntry = true;
|
---|
1872 | break;
|
---|
1873 | }
|
---|
1874 |
|
---|
1875 | /* impossible, just it's necessary to keep gcc happy. */
|
---|
1876 | default:
|
---|
1877 | return VINF_SUCCESS;
|
---|
1878 | }
|
---|
1879 | }
|
---|
1880 | return VINF_SUCCESS;
|
---|
1881 | }
|
---|
1882 |
|
---|
1883 |
|
---|
1884 | /**
|
---|
1885 | * Worker function that displays one descriptor entry (GDT, LDT, IDT).
|
---|
1886 | *
|
---|
1887 | * @returns pfnPrintf status code.
|
---|
1888 | * @param pCmdHlp The DBGC command helpers.
|
---|
1889 | * @param pDesc The descriptor to display.
|
---|
1890 | * @param iEntry The descriptor entry number.
|
---|
1891 | * @param fHyper Whether the selector belongs to the hypervisor or not.
|
---|
1892 | */
|
---|
1893 | static int dbgcCmdDumpDTWorker32(PDBGCCMDHLP pCmdHlp, PCX86DESC pDesc, unsigned iEntry, bool fHyper)
|
---|
1894 | {
|
---|
1895 | int rc;
|
---|
1896 |
|
---|
1897 | const char *pszHyper = fHyper ? " HYPER" : "";
|
---|
1898 | const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
|
---|
1899 | if (pDesc->Gen.u1DescType)
|
---|
1900 | {
|
---|
1901 | static const char * const s_apszTypes[] =
|
---|
1902 | {
|
---|
1903 | "DataRO", /* 0 Read-Only */
|
---|
1904 | "DataRO", /* 1 Read-Only - Accessed */
|
---|
1905 | "DataRW", /* 2 Read/Write */
|
---|
1906 | "DataRW", /* 3 Read/Write - Accessed */
|
---|
1907 | "DownRO", /* 4 Expand-down, Read-Only */
|
---|
1908 | "DownRO", /* 5 Expand-down, Read-Only - Accessed */
|
---|
1909 | "DownRW", /* 6 Expand-down, Read/Write */
|
---|
1910 | "DownRO", /* 7 Expand-down, Read/Write - Accessed */
|
---|
1911 | "CodeEO", /* 8 Execute-Only */
|
---|
1912 | "CodeEO", /* 9 Execute-Only - Accessed */
|
---|
1913 | "CodeER", /* A Execute/Readable */
|
---|
1914 | "CodeER", /* B Execute/Readable - Accessed */
|
---|
1915 | "ConfE0", /* C Conforming, Execute-Only */
|
---|
1916 | "ConfE0", /* D Conforming, Execute-Only - Accessed */
|
---|
1917 | "ConfER", /* E Conforming, Execute/Readable */
|
---|
1918 | "ConfER" /* F Conforming, Execute/Readable - Accessed */
|
---|
1919 | };
|
---|
1920 | const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
|
---|
1921 | const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
|
---|
1922 | const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
|
---|
1923 | uint32_t u32Base = pDesc->Gen.u16BaseLow
|
---|
1924 | | ((uint32_t)pDesc->Gen.u8BaseHigh1 << 16)
|
---|
1925 | | ((uint32_t)pDesc->Gen.u8BaseHigh2 << 24);
|
---|
1926 | uint32_t cbLimit = pDesc->Gen.u16LimitLow | (pDesc->Gen.u4LimitHigh << 16);
|
---|
1927 | if (pDesc->Gen.u1Granularity)
|
---|
1928 | cbLimit <<= PAGE_SHIFT;
|
---|
1929 |
|
---|
1930 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
|
---|
1931 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
|
---|
1932 | pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
|
---|
1933 | pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
|
---|
1934 | }
|
---|
1935 | else
|
---|
1936 | {
|
---|
1937 | static const char * const s_apszTypes[] =
|
---|
1938 | {
|
---|
1939 | "Ill-0 ", /* 0 0000 Reserved (Illegal) */
|
---|
1940 | "Tss16A", /* 1 0001 Available 16-bit TSS */
|
---|
1941 | "LDT ", /* 2 0010 LDT */
|
---|
1942 | "Tss16B", /* 3 0011 Busy 16-bit TSS */
|
---|
1943 | "Call16", /* 4 0100 16-bit Call Gate */
|
---|
1944 | "TaskG ", /* 5 0101 Task Gate */
|
---|
1945 | "Int16 ", /* 6 0110 16-bit Interrupt Gate */
|
---|
1946 | "Trap16", /* 7 0111 16-bit Trap Gate */
|
---|
1947 | "Ill-8 ", /* 8 1000 Reserved (Illegal) */
|
---|
1948 | "Tss32A", /* 9 1001 Available 32-bit TSS */
|
---|
1949 | "Ill-A ", /* A 1010 Reserved (Illegal) */
|
---|
1950 | "Tss32B", /* B 1011 Busy 32-bit TSS */
|
---|
1951 | "Call32", /* C 1100 32-bit Call Gate */
|
---|
1952 | "Ill-D ", /* D 1101 Reserved (Illegal) */
|
---|
1953 | "Int32 ", /* E 1110 32-bit Interrupt Gate */
|
---|
1954 | "Trap32" /* F 1111 32-bit Trap Gate */
|
---|
1955 | };
|
---|
1956 | switch (pDesc->Gen.u4Type)
|
---|
1957 | {
|
---|
1958 | /* raw */
|
---|
1959 | case X86_SEL_TYPE_SYS_UNDEFINED:
|
---|
1960 | case X86_SEL_TYPE_SYS_UNDEFINED2:
|
---|
1961 | case X86_SEL_TYPE_SYS_UNDEFINED4:
|
---|
1962 | case X86_SEL_TYPE_SYS_UNDEFINED3:
|
---|
1963 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s %.8Rhxs DPL=%d %s%s\n",
|
---|
1964 | iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
|
---|
1965 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
1966 | break;
|
---|
1967 |
|
---|
1968 | case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
|
---|
1969 | case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
|
---|
1970 | case X86_SEL_TYPE_SYS_286_TSS_BUSY:
|
---|
1971 | case X86_SEL_TYPE_SYS_386_TSS_BUSY:
|
---|
1972 | case X86_SEL_TYPE_SYS_LDT:
|
---|
1973 | {
|
---|
1974 | const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
|
---|
1975 | const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
|
---|
1976 | const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
|
---|
1977 | uint32_t u32Base = pDesc->Gen.u16BaseLow
|
---|
1978 | | ((uint32_t)pDesc->Gen.u8BaseHigh1 << 16)
|
---|
1979 | | ((uint32_t)pDesc->Gen.u8BaseHigh2 << 24);
|
---|
1980 | uint32_t cbLimit = pDesc->Gen.u16LimitLow | (pDesc->Gen.u4LimitHigh << 16);
|
---|
1981 | if (pDesc->Gen.u1Granularity)
|
---|
1982 | cbLimit <<= PAGE_SHIFT;
|
---|
1983 |
|
---|
1984 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d R=%d%s\n",
|
---|
1985 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
|
---|
1986 | pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszGranularity, pszBig,
|
---|
1987 | pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
|
---|
1988 | pszHyper);
|
---|
1989 | break;
|
---|
1990 | }
|
---|
1991 |
|
---|
1992 | case X86_SEL_TYPE_SYS_TASK_GATE:
|
---|
1993 | {
|
---|
1994 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s TSS=%04x DPL=%d %s%s\n",
|
---|
1995 | iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc->au16[1],
|
---|
1996 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
1997 | break;
|
---|
1998 | }
|
---|
1999 |
|
---|
2000 | case X86_SEL_TYPE_SYS_286_CALL_GATE:
|
---|
2001 | case X86_SEL_TYPE_SYS_386_CALL_GATE:
|
---|
2002 | {
|
---|
2003 | unsigned cParams = pDesc->au8[4] & 0x1f;
|
---|
2004 | const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
|
---|
2005 | RTSEL sel = pDesc->au16[1];
|
---|
2006 | uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
|
---|
2007 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%08x DPL=%d %s %s=%d%s\n",
|
---|
2008 | iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
|
---|
2009 | pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper);
|
---|
2010 | break;
|
---|
2011 | }
|
---|
2012 |
|
---|
2013 | case X86_SEL_TYPE_SYS_286_INT_GATE:
|
---|
2014 | case X86_SEL_TYPE_SYS_386_INT_GATE:
|
---|
2015 | case X86_SEL_TYPE_SYS_286_TRAP_GATE:
|
---|
2016 | case X86_SEL_TYPE_SYS_386_TRAP_GATE:
|
---|
2017 | {
|
---|
2018 | RTSEL sel = pDesc->au16[1];
|
---|
2019 | uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
|
---|
2020 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%08x DPL=%d %s%s\n",
|
---|
2021 | iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
|
---|
2022 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
2023 | break;
|
---|
2024 | }
|
---|
2025 |
|
---|
2026 | /* impossible, just it's necessary to keep gcc happy. */
|
---|
2027 | default:
|
---|
2028 | return VINF_SUCCESS;
|
---|
2029 | }
|
---|
2030 | }
|
---|
2031 | return rc;
|
---|
2032 | }
|
---|
2033 |
|
---|
2034 |
|
---|
2035 | /**
|
---|
2036 | * The 'dg', 'dga', 'dl' and 'dla' commands.
|
---|
2037 | *
|
---|
2038 | * @returns VBox status.
|
---|
2039 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2040 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2041 | * @param pVM Pointer to the current VM (if any).
|
---|
2042 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2043 | * @param cArgs Number of arguments in the array.
|
---|
2044 | */
|
---|
2045 | static DECLCALLBACK(int) dbgcCmdDumpDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
2046 | {
|
---|
2047 | /*
|
---|
2048 | * Validate input.
|
---|
2049 | */
|
---|
2050 | if (!pVM)
|
---|
2051 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
2052 |
|
---|
2053 | /*
|
---|
2054 | * Get the CPU mode, check which command variation this is
|
---|
2055 | * and fix a default parameter if needed.
|
---|
2056 | */
|
---|
2057 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2058 | PVMCPU pVCpu = VMMGetCpuById(pVM, pDbgc->idCpu);
|
---|
2059 | CPUMMODE enmMode = CPUMGetGuestMode(pVCpu);
|
---|
2060 | bool fGdt = pCmd->pszCmd[1] == 'g';
|
---|
2061 | bool fAll = pCmd->pszCmd[2] == 'a';
|
---|
2062 | RTSEL SelTable = fGdt ? 0 : X86_SEL_LDT;
|
---|
2063 |
|
---|
2064 | DBGCVAR Var;
|
---|
2065 | if (!cArgs)
|
---|
2066 | {
|
---|
2067 | cArgs = 1;
|
---|
2068 | paArgs = &Var;
|
---|
2069 | Var.enmType = DBGCVAR_TYPE_NUMBER;
|
---|
2070 | Var.u.u64Number = 0;
|
---|
2071 | Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
2072 | Var.u64Range = 1024;
|
---|
2073 | }
|
---|
2074 |
|
---|
2075 | /*
|
---|
2076 | * Process the arguments.
|
---|
2077 | */
|
---|
2078 | for (unsigned i = 0; i < cArgs; i++)
|
---|
2079 | {
|
---|
2080 | /*
|
---|
2081 | * Retrieve the selector value from the argument.
|
---|
2082 | * The parser may confuse pointers and numbers if more than one
|
---|
2083 | * argument is given, that that into account.
|
---|
2084 | */
|
---|
2085 | /* check that what we got makes sense as we don't trust the parser yet. */
|
---|
2086 | if ( paArgs[i].enmType != DBGCVAR_TYPE_NUMBER
|
---|
2087 | && !DBGCVAR_ISPOINTER(paArgs[i].enmType))
|
---|
2088 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: arg #%u isn't of number or pointer type but %d.\n", i, paArgs[i].enmType);
|
---|
2089 | uint64_t u64;
|
---|
2090 | unsigned cSels = 1;
|
---|
2091 | switch (paArgs[i].enmType)
|
---|
2092 | {
|
---|
2093 | case DBGCVAR_TYPE_NUMBER:
|
---|
2094 | u64 = paArgs[i].u.u64Number;
|
---|
2095 | if (paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE)
|
---|
2096 | cSels = RT_MIN(paArgs[i].u64Range, 1024);
|
---|
2097 | break;
|
---|
2098 | case DBGCVAR_TYPE_GC_FAR: u64 = paArgs[i].u.GCFar.sel; break;
|
---|
2099 | case DBGCVAR_TYPE_GC_FLAT: u64 = paArgs[i].u.GCFlat; break;
|
---|
2100 | case DBGCVAR_TYPE_GC_PHYS: u64 = paArgs[i].u.GCPhys; break;
|
---|
2101 | case DBGCVAR_TYPE_HC_FLAT: u64 = (uintptr_t)paArgs[i].u.pvHCFlat; break;
|
---|
2102 | case DBGCVAR_TYPE_HC_PHYS: u64 = paArgs[i].u.HCPhys; break;
|
---|
2103 | default: u64 = _64K; break;
|
---|
2104 | }
|
---|
2105 | if (u64 < _64K)
|
---|
2106 | {
|
---|
2107 | unsigned Sel = (RTSEL)u64;
|
---|
2108 |
|
---|
2109 | /*
|
---|
2110 | * Dump the specified range.
|
---|
2111 | */
|
---|
2112 | bool fSingle = cSels == 1;
|
---|
2113 | while ( cSels-- > 0
|
---|
2114 | && Sel < _64K)
|
---|
2115 | {
|
---|
2116 | DBGFSELINFO SelInfo;
|
---|
2117 | int rc = DBGFR3SelQueryInfo(pVM, pDbgc->idCpu, Sel | SelTable, DBGFSELQI_FLAGS_DT_GUEST, &SelInfo);
|
---|
2118 | if (RT_SUCCESS(rc))
|
---|
2119 | {
|
---|
2120 | if (SelInfo.fFlags & DBGFSELINFO_FLAGS_REAL_MODE)
|
---|
2121 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x RealM Bas=%04x Lim=%04x\n",
|
---|
2122 | Sel, (unsigned)SelInfo.GCPtrBase, (unsigned)SelInfo.cbLimit);
|
---|
2123 | else if ( fAll
|
---|
2124 | || fSingle
|
---|
2125 | || SelInfo.u.Raw.Gen.u1Present)
|
---|
2126 | {
|
---|
2127 | if (enmMode == CPUMMODE_PROTECTED)
|
---|
2128 | rc = dbgcCmdDumpDTWorker32(pCmdHlp, &SelInfo.u.Raw, Sel, !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER));
|
---|
2129 | else
|
---|
2130 | {
|
---|
2131 | bool fDblSkip = false;
|
---|
2132 | rc = dbgcCmdDumpDTWorker64(pCmdHlp, &SelInfo.u.Raw64, Sel, !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER), &fDblSkip);
|
---|
2133 | if (fDblSkip)
|
---|
2134 | Sel += 4;
|
---|
2135 | }
|
---|
2136 | }
|
---|
2137 | }
|
---|
2138 | else
|
---|
2139 | {
|
---|
2140 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %Rrc\n", Sel, rc);
|
---|
2141 | if (!fAll)
|
---|
2142 | return rc;
|
---|
2143 | }
|
---|
2144 | if (RT_FAILURE(rc))
|
---|
2145 | return rc;
|
---|
2146 |
|
---|
2147 | /* next */
|
---|
2148 | Sel += 8;
|
---|
2149 | }
|
---|
2150 | }
|
---|
2151 | else
|
---|
2152 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: %llx is out of bounds\n", u64);
|
---|
2153 | }
|
---|
2154 |
|
---|
2155 | NOREF(pResult);
|
---|
2156 | return VINF_SUCCESS;
|
---|
2157 | }
|
---|
2158 |
|
---|
2159 |
|
---|
2160 | /**
|
---|
2161 | * The 'di' and 'dia' commands.
|
---|
2162 | *
|
---|
2163 | * @returns VBox status.
|
---|
2164 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2165 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2166 | * @param pVM Pointer to the current VM (if any).
|
---|
2167 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2168 | * @param cArgs Number of arguments in the array.
|
---|
2169 | */
|
---|
2170 | static DECLCALLBACK(int) dbgcCmdDumpIDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
2171 | {
|
---|
2172 | /*
|
---|
2173 | * Validate input.
|
---|
2174 | */
|
---|
2175 | if (!pVM)
|
---|
2176 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
2177 |
|
---|
2178 | /*
|
---|
2179 | * Establish some stuff like the current IDTR and CPU mode,
|
---|
2180 | * and fix a default parameter.
|
---|
2181 | */
|
---|
2182 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2183 | PVMCPU pVCpu = VMMGetCpuById(pVM, pDbgc->idCpu);
|
---|
2184 | uint16_t cbLimit;
|
---|
2185 | RTGCUINTPTR GCPtrBase = CPUMGetGuestIDTR(pVCpu, &cbLimit);
|
---|
2186 | CPUMMODE enmMode = CPUMGetGuestMode(pVCpu);
|
---|
2187 | unsigned cbEntry;
|
---|
2188 | switch (enmMode)
|
---|
2189 | {
|
---|
2190 | case CPUMMODE_REAL: cbEntry = sizeof(RTFAR16); break;
|
---|
2191 | case CPUMMODE_PROTECTED: cbEntry = sizeof(X86DESC); break;
|
---|
2192 | case CPUMMODE_LONG: cbEntry = sizeof(X86DESC64); break;
|
---|
2193 | default:
|
---|
2194 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid CPU mode %d.\n", enmMode);
|
---|
2195 | }
|
---|
2196 |
|
---|
2197 | bool fAll = pCmd->pszCmd[2] == 'a';
|
---|
2198 | DBGCVAR Var;
|
---|
2199 | if (!cArgs)
|
---|
2200 | {
|
---|
2201 | cArgs = 1;
|
---|
2202 | paArgs = &Var;
|
---|
2203 | Var.enmType = DBGCVAR_TYPE_NUMBER;
|
---|
2204 | Var.u.u64Number = 0;
|
---|
2205 | Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
2206 | Var.u64Range = 256;
|
---|
2207 | }
|
---|
2208 |
|
---|
2209 | /*
|
---|
2210 | * Process the arguments.
|
---|
2211 | */
|
---|
2212 | for (unsigned i = 0; i < cArgs; i++)
|
---|
2213 | {
|
---|
2214 | /* check that what we got makes sense as we don't trust the parser yet. */
|
---|
2215 | if (paArgs[i].enmType != DBGCVAR_TYPE_NUMBER)
|
---|
2216 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: arg #%u isn't of number type but %d.\n", i, paArgs[i].enmType);
|
---|
2217 | if (paArgs[i].u.u64Number < 256)
|
---|
2218 | {
|
---|
2219 | RTGCUINTPTR iInt = (RTGCUINTPTR)paArgs[i].u.u64Number;
|
---|
2220 | unsigned cInts = paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE
|
---|
2221 | ? paArgs[i].u64Range
|
---|
2222 | : 1;
|
---|
2223 | bool fSingle = cInts == 1;
|
---|
2224 | while ( cInts-- > 0
|
---|
2225 | && iInt < 256)
|
---|
2226 | {
|
---|
2227 | /*
|
---|
2228 | * Try read it.
|
---|
2229 | */
|
---|
2230 | union
|
---|
2231 | {
|
---|
2232 | RTFAR16 Real;
|
---|
2233 | X86DESC Prot;
|
---|
2234 | X86DESC64 Long;
|
---|
2235 | } u;
|
---|
2236 | if (iInt * cbEntry + (cbEntry - 1) > cbLimit)
|
---|
2237 | {
|
---|
2238 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x not within the IDT\n", (unsigned)iInt);
|
---|
2239 | if (!fAll && !fSingle)
|
---|
2240 | return VINF_SUCCESS;
|
---|
2241 | }
|
---|
2242 | DBGCVAR AddrVar;
|
---|
2243 | AddrVar.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
2244 | AddrVar.u.GCFlat = GCPtrBase + iInt * cbEntry;
|
---|
2245 | AddrVar.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
2246 | int rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &u, cbEntry, &AddrVar, NULL);
|
---|
2247 | if (RT_FAILURE(rc))
|
---|
2248 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading IDT entry %#04x.\n", (unsigned)iInt);
|
---|
2249 |
|
---|
2250 | /*
|
---|
2251 | * Display it.
|
---|
2252 | */
|
---|
2253 | switch (enmMode)
|
---|
2254 | {
|
---|
2255 | case CPUMMODE_REAL:
|
---|
2256 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %RTfp16\n", (unsigned)iInt, u.Real);
|
---|
2257 | /** @todo resolve 16:16 IDTE to a symbol */
|
---|
2258 | break;
|
---|
2259 | case CPUMMODE_PROTECTED:
|
---|
2260 | if (fAll || fSingle || u.Prot.Gen.u1Present)
|
---|
2261 | rc = dbgcCmdDumpDTWorker32(pCmdHlp, &u.Prot, iInt, false);
|
---|
2262 | break;
|
---|
2263 | case CPUMMODE_LONG:
|
---|
2264 | if (fAll || fSingle || u.Long.Gen.u1Present)
|
---|
2265 | rc = dbgcCmdDumpDTWorker64(pCmdHlp, &u.Long, iInt, false, NULL);
|
---|
2266 | break;
|
---|
2267 | default: break; /* to shut up gcc */
|
---|
2268 | }
|
---|
2269 | if (RT_FAILURE(rc))
|
---|
2270 | return rc;
|
---|
2271 |
|
---|
2272 | /* next */
|
---|
2273 | iInt++;
|
---|
2274 | }
|
---|
2275 | }
|
---|
2276 | else
|
---|
2277 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: %llx is out of bounds (max 256)\n", paArgs[i].u.u64Number);
|
---|
2278 | }
|
---|
2279 |
|
---|
2280 | NOREF(pResult);
|
---|
2281 | return VINF_SUCCESS;
|
---|
2282 | }
|
---|
2283 |
|
---|
2284 |
|
---|
2285 | /**
|
---|
2286 | * The 'da', 'dq', 'dd', 'dw' and 'db' commands.
|
---|
2287 | *
|
---|
2288 | * @returns VBox status.
|
---|
2289 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2290 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2291 | * @param pVM Pointer to the current VM (if any).
|
---|
2292 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2293 | * @param cArgs Number of arguments in the array.
|
---|
2294 | */
|
---|
2295 | static DECLCALLBACK(int) dbgcCmdDumpMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
2296 | {
|
---|
2297 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2298 |
|
---|
2299 | /*
|
---|
2300 | * Validate input.
|
---|
2301 | */
|
---|
2302 | if ( cArgs > 1
|
---|
2303 | || (cArgs == 1 && !DBGCVAR_ISPOINTER(paArgs[0].enmType)))
|
---|
2304 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
|
---|
2305 | if (!pVM)
|
---|
2306 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
2307 |
|
---|
2308 | /*
|
---|
2309 | * Figure out the element size.
|
---|
2310 | */
|
---|
2311 | unsigned cbElement;
|
---|
2312 | bool fAscii = false;
|
---|
2313 | switch (pCmd->pszCmd[1])
|
---|
2314 | {
|
---|
2315 | default:
|
---|
2316 | case 'b': cbElement = 1; break;
|
---|
2317 | case 'w': cbElement = 2; break;
|
---|
2318 | case 'd': cbElement = 4; break;
|
---|
2319 | case 'q': cbElement = 8; break;
|
---|
2320 | case 'a':
|
---|
2321 | cbElement = 1;
|
---|
2322 | fAscii = true;
|
---|
2323 | break;
|
---|
2324 | case '\0':
|
---|
2325 | fAscii = !!(pDbgc->cbDumpElement & 0x80000000);
|
---|
2326 | cbElement = pDbgc->cbDumpElement & 0x7fffffff;
|
---|
2327 | if (!cbElement)
|
---|
2328 | cbElement = 1;
|
---|
2329 | break;
|
---|
2330 | }
|
---|
2331 |
|
---|
2332 | /*
|
---|
2333 | * Find address.
|
---|
2334 | */
|
---|
2335 | if (!cArgs)
|
---|
2336 | pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
2337 | else
|
---|
2338 | pDbgc->DumpPos = paArgs[0];
|
---|
2339 |
|
---|
2340 | /*
|
---|
2341 | * Range.
|
---|
2342 | */
|
---|
2343 | switch (pDbgc->DumpPos.enmRangeType)
|
---|
2344 | {
|
---|
2345 | case DBGCVAR_RANGE_NONE:
|
---|
2346 | pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
|
---|
2347 | pDbgc->DumpPos.u64Range = 0x60;
|
---|
2348 | break;
|
---|
2349 |
|
---|
2350 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
2351 | if (pDbgc->DumpPos.u64Range > 2048)
|
---|
2352 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Too many elements requested. Max is 2048 elements.\n");
|
---|
2353 | pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
|
---|
2354 | pDbgc->DumpPos.u64Range = (cbElement ? cbElement : 1) * pDbgc->DumpPos.u64Range;
|
---|
2355 | break;
|
---|
2356 |
|
---|
2357 | case DBGCVAR_RANGE_BYTES:
|
---|
2358 | if (pDbgc->DumpPos.u64Range > 65536)
|
---|
2359 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: The requested range is too big. Max is 64KB.\n");
|
---|
2360 | break;
|
---|
2361 |
|
---|
2362 | default:
|
---|
2363 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: Unknown range type %d.\n", pDbgc->DumpPos.enmRangeType);
|
---|
2364 | }
|
---|
2365 |
|
---|
2366 | pDbgc->pLastPos = &pDbgc->DumpPos;
|
---|
2367 |
|
---|
2368 | /*
|
---|
2369 | * Do the dumping.
|
---|
2370 | */
|
---|
2371 | pDbgc->cbDumpElement = cbElement | (fAscii << 31);
|
---|
2372 | int cbLeft = (int)pDbgc->DumpPos.u64Range;
|
---|
2373 | uint8_t u8Prev = '\0';
|
---|
2374 | for (;;)
|
---|
2375 | {
|
---|
2376 | /*
|
---|
2377 | * Read memory.
|
---|
2378 | */
|
---|
2379 | char achBuffer[16];
|
---|
2380 | size_t cbReq = RT_MIN((int)sizeof(achBuffer), cbLeft);
|
---|
2381 | size_t cb = RT_MIN((int)sizeof(achBuffer), cbLeft);
|
---|
2382 | int rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &achBuffer, cbReq, &pDbgc->DumpPos, &cb);
|
---|
2383 | if (RT_FAILURE(rc))
|
---|
2384 | {
|
---|
2385 | if (u8Prev && u8Prev != '\n')
|
---|
2386 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
|
---|
2387 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading memory at %DV.\n", &pDbgc->DumpPos);
|
---|
2388 | }
|
---|
2389 |
|
---|
2390 | /*
|
---|
2391 | * Display it.
|
---|
2392 | */
|
---|
2393 | memset(&achBuffer[cb], 0, sizeof(achBuffer) - cb);
|
---|
2394 | if (!fAscii)
|
---|
2395 | {
|
---|
2396 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV:", &pDbgc->DumpPos);
|
---|
2397 | unsigned i;
|
---|
2398 | for (i = 0; i < cb; i += cbElement)
|
---|
2399 | {
|
---|
2400 | const char *pszSpace = " ";
|
---|
2401 | if (cbElement <= 2 && i == 8 && !fAscii)
|
---|
2402 | pszSpace = "-";
|
---|
2403 | switch (cbElement)
|
---|
2404 | {
|
---|
2405 | case 1: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%02x", pszSpace, *(uint8_t *)&achBuffer[i]); break;
|
---|
2406 | case 2: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%04x", pszSpace, *(uint16_t *)&achBuffer[i]); break;
|
---|
2407 | case 4: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%08x", pszSpace, *(uint32_t *)&achBuffer[i]); break;
|
---|
2408 | case 8: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%016llx", pszSpace, *(uint64_t *)&achBuffer[i]); break;
|
---|
2409 | }
|
---|
2410 | }
|
---|
2411 |
|
---|
2412 | /* chars column */
|
---|
2413 | if (pDbgc->cbDumpElement == 1)
|
---|
2414 | {
|
---|
2415 | while (i++ < sizeof(achBuffer))
|
---|
2416 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, " ");
|
---|
2417 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, " ");
|
---|
2418 | for (i = 0; i < cb; i += cbElement)
|
---|
2419 | {
|
---|
2420 | uint8_t u8 = *(uint8_t *)&achBuffer[i];
|
---|
2421 | if (RT_C_IS_PRINT(u8) && u8 < 127 && u8 >= 32)
|
---|
2422 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%c", u8);
|
---|
2423 | else
|
---|
2424 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, ".");
|
---|
2425 | }
|
---|
2426 | }
|
---|
2427 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
|
---|
2428 | }
|
---|
2429 | else
|
---|
2430 | {
|
---|
2431 | /*
|
---|
2432 | * We print up to the first zero and stop there.
|
---|
2433 | * Only printables + '\t' and '\n' are printed.
|
---|
2434 | */
|
---|
2435 | if (!u8Prev)
|
---|
2436 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV:\n", &pDbgc->DumpPos);
|
---|
2437 | uint8_t u8 = '\0';
|
---|
2438 | unsigned i;
|
---|
2439 | for (i = 0; i < cb; i++)
|
---|
2440 | {
|
---|
2441 | u8Prev = u8;
|
---|
2442 | u8 = *(uint8_t *)&achBuffer[i];
|
---|
2443 | if ( u8 < 127
|
---|
2444 | && ( (RT_C_IS_PRINT(u8) && u8 >= 32)
|
---|
2445 | || u8 == '\t'
|
---|
2446 | || u8 == '\n'))
|
---|
2447 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%c", u8);
|
---|
2448 | else if (!u8)
|
---|
2449 | break;
|
---|
2450 | else
|
---|
2451 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\\x%x", u8);
|
---|
2452 | }
|
---|
2453 | if (u8 == '\0')
|
---|
2454 | cb = cbLeft = i + 1;
|
---|
2455 | if (cbLeft - cb <= 0 && u8Prev != '\n')
|
---|
2456 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
|
---|
2457 | }
|
---|
2458 |
|
---|
2459 | /*
|
---|
2460 | * Advance
|
---|
2461 | */
|
---|
2462 | cbLeft -= (int)cb;
|
---|
2463 | rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->DumpPos, "(%Dv) + %x", &pDbgc->DumpPos, cb);
|
---|
2464 | if (RT_FAILURE(rc))
|
---|
2465 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->DumpPos, cb);
|
---|
2466 | if (cbLeft <= 0)
|
---|
2467 | break;
|
---|
2468 | }
|
---|
2469 |
|
---|
2470 | NOREF(pCmd); NOREF(pResult);
|
---|
2471 | return VINF_SUCCESS;
|
---|
2472 | }
|
---|
2473 |
|
---|
2474 |
|
---|
2475 | /**
|
---|
2476 | * Best guess at which paging mode currently applies to the guest
|
---|
2477 | * paging structures.
|
---|
2478 | *
|
---|
2479 | * This have to come up with a decent answer even when the guest
|
---|
2480 | * is in non-paged protected mode or real mode.
|
---|
2481 | *
|
---|
2482 | * @returns cr3.
|
---|
2483 | * @param pDbgc The DBGC instance.
|
---|
2484 | * @param pfPAE Where to store the page address extension indicator.
|
---|
2485 | * @param pfLME Where to store the long mode enabled indicator.
|
---|
2486 | * @param pfPSE Where to store the page size extension indicator.
|
---|
2487 | * @param pfPGE Where to store the page global enabled indicator.
|
---|
2488 | * @param pfNXE Where to store the no-execution enabled indicator.
|
---|
2489 | */
|
---|
2490 | static RTGCPHYS dbgcGetGuestPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
|
---|
2491 | {
|
---|
2492 | PVMCPU pVCpu = VMMGetCpuById(pDbgc->pVM, pDbgc->idCpu);
|
---|
2493 | RTGCUINTREG cr4 = CPUMGetGuestCR4(pVCpu);
|
---|
2494 | *pfPSE = !!(cr4 & X86_CR4_PSE);
|
---|
2495 | *pfPGE = !!(cr4 & X86_CR4_PGE);
|
---|
2496 | if (cr4 & X86_CR4_PAE)
|
---|
2497 | {
|
---|
2498 | *pfPSE = true;
|
---|
2499 | *pfPAE = true;
|
---|
2500 | }
|
---|
2501 | else
|
---|
2502 | *pfPAE = false;
|
---|
2503 |
|
---|
2504 | *pfLME = CPUMGetGuestMode(pVCpu) == CPUMMODE_LONG;
|
---|
2505 | *pfNXE = false; /* GUEST64 GUESTNX */
|
---|
2506 | return CPUMGetGuestCR3(pVCpu);
|
---|
2507 | }
|
---|
2508 |
|
---|
2509 |
|
---|
2510 | /**
|
---|
2511 | * Determine the shadow paging mode.
|
---|
2512 | *
|
---|
2513 | * @returns cr3.
|
---|
2514 | * @param pDbgc The DBGC instance.
|
---|
2515 | * @param pfPAE Where to store the page address extension indicator.
|
---|
2516 | * @param pfLME Where to store the long mode enabled indicator.
|
---|
2517 | * @param pfPSE Where to store the page size extension indicator.
|
---|
2518 | * @param pfPGE Where to store the page global enabled indicator.
|
---|
2519 | * @param pfNXE Where to store the no-execution enabled indicator.
|
---|
2520 | */
|
---|
2521 | static RTHCPHYS dbgcGetShadowPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
|
---|
2522 | {
|
---|
2523 | PVMCPU pVCpu = VMMGetCpuById(pDbgc->pVM, pDbgc->idCpu);
|
---|
2524 |
|
---|
2525 | *pfPSE = true;
|
---|
2526 | *pfPGE = false;
|
---|
2527 | switch (PGMGetShadowMode(pVCpu))
|
---|
2528 | {
|
---|
2529 | default:
|
---|
2530 | case PGMMODE_32_BIT:
|
---|
2531 | *pfPAE = *pfLME = *pfNXE = false;
|
---|
2532 | break;
|
---|
2533 | case PGMMODE_PAE:
|
---|
2534 | *pfLME = *pfNXE = false;
|
---|
2535 | *pfPAE = true;
|
---|
2536 | break;
|
---|
2537 | case PGMMODE_PAE_NX:
|
---|
2538 | *pfLME = false;
|
---|
2539 | *pfPAE = *pfNXE = true;
|
---|
2540 | break;
|
---|
2541 | case PGMMODE_AMD64:
|
---|
2542 | *pfNXE = false;
|
---|
2543 | *pfPAE = *pfLME = true;
|
---|
2544 | break;
|
---|
2545 | case PGMMODE_AMD64_NX:
|
---|
2546 | *pfPAE = *pfLME = *pfNXE = true;
|
---|
2547 | break;
|
---|
2548 | }
|
---|
2549 | return PGMGetHyperCR3(pVCpu);
|
---|
2550 | }
|
---|
2551 |
|
---|
2552 |
|
---|
2553 | /**
|
---|
2554 | * The 'dpd', 'dpda', 'dpdb', 'dpdg' and 'dpdh' commands.
|
---|
2555 | *
|
---|
2556 | * @returns VBox status.
|
---|
2557 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2558 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2559 | * @param pVM Pointer to the current VM (if any).
|
---|
2560 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2561 | * @param cArgs Number of arguments in the array.
|
---|
2562 | */
|
---|
2563 | static DECLCALLBACK(int) dbgcCmdDumpPageDir(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
2564 | {
|
---|
2565 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2566 |
|
---|
2567 | /*
|
---|
2568 | * Validate input.
|
---|
2569 | */
|
---|
2570 | if ( cArgs > 1
|
---|
2571 | || (cArgs == 1 && pCmd->pszCmd[3] == 'a' && !DBGCVAR_ISPOINTER(paArgs[0].enmType))
|
---|
2572 | || (cArgs == 1 && pCmd->pszCmd[3] != 'a' && !(paArgs[0].enmType == DBGCVAR_TYPE_NUMBER || DBGCVAR_ISPOINTER(paArgs[0].enmType)))
|
---|
2573 | )
|
---|
2574 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
|
---|
2575 | if (!pVM)
|
---|
2576 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
2577 |
|
---|
2578 | /*
|
---|
2579 | * Guest or shadow page directories? Get the paging parameters.
|
---|
2580 | */
|
---|
2581 | bool fGuest = pCmd->pszCmd[3] != 'h';
|
---|
2582 | if (!pCmd->pszCmd[3] || pCmd->pszCmd[3] == 'a')
|
---|
2583 | fGuest = paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
|
---|
2584 | ? pDbgc->fRegCtxGuest
|
---|
2585 | : DBGCVAR_ISGCPOINTER(paArgs[0].enmType);
|
---|
2586 |
|
---|
2587 | bool fPAE, fLME, fPSE, fPGE, fNXE;
|
---|
2588 | uint64_t cr3 = fGuest
|
---|
2589 | ? dbgcGetGuestPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE)
|
---|
2590 | : dbgcGetShadowPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE);
|
---|
2591 | const unsigned cbEntry = fPAE ? sizeof(X86PTEPAE) : sizeof(X86PTE);
|
---|
2592 |
|
---|
2593 | /*
|
---|
2594 | * Setup default argument if none was specified.
|
---|
2595 | * Fix address / index confusion.
|
---|
2596 | */
|
---|
2597 | DBGCVAR VarDefault;
|
---|
2598 | if (!cArgs)
|
---|
2599 | {
|
---|
2600 | if (pCmd->pszCmd[3] == 'a')
|
---|
2601 | {
|
---|
2602 | if (fLME || fPAE)
|
---|
2603 | return DBGCCmdHlpPrintf(pCmdHlp, "Default argument for 'dpda' hasn't been fully implemented yet. Try with an address or use one of the other commands.\n");
|
---|
2604 | if (fGuest)
|
---|
2605 | DBGCVAR_INIT_GC_PHYS(&VarDefault, cr3);
|
---|
2606 | else
|
---|
2607 | DBGCVAR_INIT_HC_PHYS(&VarDefault, cr3);
|
---|
2608 | }
|
---|
2609 | else
|
---|
2610 | DBGCVAR_INIT_GC_FLAT(&VarDefault, 0);
|
---|
2611 | paArgs = &VarDefault;
|
---|
2612 | cArgs = 1;
|
---|
2613 | }
|
---|
2614 | else if (paArgs[0].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
2615 | {
|
---|
2616 | Assert(pCmd->pszCmd[3] != 'a');
|
---|
2617 | VarDefault = paArgs[0];
|
---|
2618 | if (VarDefault.u.u64Number <= 1024)
|
---|
2619 | {
|
---|
2620 | if (fPAE)
|
---|
2621 | return DBGCCmdHlpPrintf(pCmdHlp, "PDE indexing is only implemented for 32-bit paging.\n");
|
---|
2622 | if (VarDefault.u.u64Number >= PAGE_SIZE / cbEntry)
|
---|
2623 | return DBGCCmdHlpPrintf(pCmdHlp, "PDE index is out of range [0..%d].\n", PAGE_SIZE / cbEntry - 1);
|
---|
2624 | VarDefault.u.u64Number <<= X86_PD_SHIFT;
|
---|
2625 | }
|
---|
2626 | VarDefault.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
2627 | paArgs = &VarDefault;
|
---|
2628 | }
|
---|
2629 |
|
---|
2630 | /*
|
---|
2631 | * Locate the PDE to start displaying at.
|
---|
2632 | *
|
---|
2633 | * The 'dpda' command takes the address of a PDE, while the others are guest
|
---|
2634 | * virtual address which PDEs should be displayed. So, 'dpda' is rather simple
|
---|
2635 | * while the others require us to do all the tedious walking thru the paging
|
---|
2636 | * hierarchy to find the intended PDE.
|
---|
2637 | */
|
---|
2638 | unsigned iEntry = ~0U; /* The page directory index. ~0U for 'dpta'. */
|
---|
2639 | DBGCVAR VarGCPtr; /* The GC address corresponding to the current PDE (iEntry != ~0U). */
|
---|
2640 | DBGCVAR VarPDEAddr; /* The address of the current PDE. */
|
---|
2641 | unsigned cEntries; /* The number of entries to display. */
|
---|
2642 | unsigned cEntriesMax; /* The max number of entries to display. */
|
---|
2643 | int rc;
|
---|
2644 | if (pCmd->pszCmd[3] == 'a')
|
---|
2645 | {
|
---|
2646 | VarPDEAddr = paArgs[0];
|
---|
2647 | switch (VarPDEAddr.enmRangeType)
|
---|
2648 | {
|
---|
2649 | case DBGCVAR_RANGE_BYTES: cEntries = VarPDEAddr.u64Range / cbEntry; break;
|
---|
2650 | case DBGCVAR_RANGE_ELEMENTS: cEntries = VarPDEAddr.u64Range; break;
|
---|
2651 | default: cEntries = 10; break;
|
---|
2652 | }
|
---|
2653 | cEntriesMax = PAGE_SIZE / cbEntry;
|
---|
2654 | }
|
---|
2655 | else
|
---|
2656 | {
|
---|
2657 | /*
|
---|
2658 | * Determine the range.
|
---|
2659 | */
|
---|
2660 | switch (paArgs[0].enmRangeType)
|
---|
2661 | {
|
---|
2662 | case DBGCVAR_RANGE_BYTES: cEntries = paArgs[0].u64Range / PAGE_SIZE; break;
|
---|
2663 | case DBGCVAR_RANGE_ELEMENTS: cEntries = paArgs[0].u64Range; break;
|
---|
2664 | default: cEntries = 10; break;
|
---|
2665 | }
|
---|
2666 |
|
---|
2667 | /*
|
---|
2668 | * Normalize the input address, it must be a flat GC address.
|
---|
2669 | */
|
---|
2670 | rc = DBGCCmdHlpEval(pCmdHlp, &VarGCPtr, "%%(%Dv)", &paArgs[0]);
|
---|
2671 | if (RT_FAILURE(rc))
|
---|
2672 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
|
---|
2673 | if (VarGCPtr.enmType == DBGCVAR_TYPE_HC_FLAT)
|
---|
2674 | {
|
---|
2675 | VarGCPtr.u.GCFlat = (uintptr_t)VarGCPtr.u.pvHCFlat;
|
---|
2676 | VarGCPtr.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
2677 | }
|
---|
2678 | if (fPAE)
|
---|
2679 | VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_PAE_SHIFT) - 1);
|
---|
2680 | else
|
---|
2681 | VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_SHIFT) - 1);
|
---|
2682 |
|
---|
2683 | /*
|
---|
2684 | * Do the paging walk until we get to the page directory.
|
---|
2685 | */
|
---|
2686 | DBGCVAR VarCur;
|
---|
2687 | if (fGuest)
|
---|
2688 | DBGCVAR_INIT_GC_PHYS(&VarCur, cr3);
|
---|
2689 | else
|
---|
2690 | DBGCVAR_INIT_HC_PHYS(&VarCur, cr3);
|
---|
2691 | if (fLME)
|
---|
2692 | {
|
---|
2693 | /* Page Map Level 4 Lookup. */
|
---|
2694 | /* Check if it's a valid address first? */
|
---|
2695 | VarCur.u.u64Number &= X86_PTE_PAE_PG_MASK;
|
---|
2696 | VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
|
---|
2697 | X86PML4E Pml4e;
|
---|
2698 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pml4e, sizeof(Pml4e), &VarCur, NULL);
|
---|
2699 | if (RT_FAILURE(rc))
|
---|
2700 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PML4E memory at %DV.\n", &VarCur);
|
---|
2701 | if (!Pml4e.n.u1Present)
|
---|
2702 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
|
---|
2703 |
|
---|
2704 | VarCur.u.u64Number = Pml4e.u & X86_PML4E_PG_MASK;
|
---|
2705 | Assert(fPAE);
|
---|
2706 | }
|
---|
2707 | if (fPAE)
|
---|
2708 | {
|
---|
2709 | /* Page directory pointer table. */
|
---|
2710 | X86PDPE Pdpe;
|
---|
2711 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE) * sizeof(Pdpe);
|
---|
2712 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pdpe, sizeof(Pdpe), &VarCur, NULL);
|
---|
2713 | if (RT_FAILURE(rc))
|
---|
2714 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDPE memory at %DV.\n", &VarCur);
|
---|
2715 | if (!Pdpe.n.u1Present)
|
---|
2716 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory is not present for %Dv.\n", &VarGCPtr);
|
---|
2717 |
|
---|
2718 | iEntry = (VarGCPtr.u.GCFlat >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
2719 | VarPDEAddr = VarCur;
|
---|
2720 | VarPDEAddr.u.u64Number = Pdpe.u & X86_PDPE_PG_MASK;
|
---|
2721 | VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDEPAE);
|
---|
2722 | }
|
---|
2723 | else
|
---|
2724 | {
|
---|
2725 | /* 32-bit legacy - CR3 == page directory. */
|
---|
2726 | iEntry = (VarGCPtr.u.GCFlat >> X86_PD_SHIFT) & X86_PD_MASK;
|
---|
2727 | VarPDEAddr = VarCur;
|
---|
2728 | VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDE);
|
---|
2729 | }
|
---|
2730 | cEntriesMax = (PAGE_SIZE - iEntry) / cbEntry;
|
---|
2731 | iEntry /= cbEntry;
|
---|
2732 | }
|
---|
2733 |
|
---|
2734 | /* adjust cEntries */
|
---|
2735 | cEntries = RT_MAX(1, cEntries);
|
---|
2736 | cEntries = RT_MIN(cEntries, cEntriesMax);
|
---|
2737 |
|
---|
2738 | /*
|
---|
2739 | * The display loop.
|
---|
2740 | */
|
---|
2741 | DBGCCmdHlpPrintf(pCmdHlp, iEntry != ~0U ? "%DV (index %#x):\n" : "%DV:\n",
|
---|
2742 | &VarPDEAddr, iEntry);
|
---|
2743 | do
|
---|
2744 | {
|
---|
2745 | /*
|
---|
2746 | * Read.
|
---|
2747 | */
|
---|
2748 | X86PDEPAE Pde;
|
---|
2749 | Pde.u = 0;
|
---|
2750 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pde, cbEntry, &VarPDEAddr, NULL);
|
---|
2751 | if (RT_FAILURE(rc))
|
---|
2752 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarPDEAddr);
|
---|
2753 |
|
---|
2754 | /*
|
---|
2755 | * Display.
|
---|
2756 | */
|
---|
2757 | if (iEntry != ~0U)
|
---|
2758 | {
|
---|
2759 | DBGCCmdHlpPrintf(pCmdHlp, "%03x %DV: ", iEntry, &VarGCPtr);
|
---|
2760 | iEntry++;
|
---|
2761 | }
|
---|
2762 | if (fPSE && Pde.b.u1Size)
|
---|
2763 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
2764 | fPAE
|
---|
2765 | ? "%016llx big phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
|
---|
2766 | : "%08llx big phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
|
---|
2767 | Pde.u,
|
---|
2768 | Pde.u & X86_PDE_PAE_PG_MASK,
|
---|
2769 | Pde.b.u1Present ? "p " : "np",
|
---|
2770 | Pde.b.u1Write ? "w" : "r",
|
---|
2771 | Pde.b.u1User ? "u" : "s",
|
---|
2772 | Pde.b.u1Accessed ? "a " : "na",
|
---|
2773 | Pde.b.u1Dirty ? "d " : "nd",
|
---|
2774 | Pde.b.u3Available,
|
---|
2775 | Pde.b.u1Global ? (fPGE ? "g" : "G") : " ",
|
---|
2776 | Pde.b.u1WriteThru ? "pwt" : " ",
|
---|
2777 | Pde.b.u1CacheDisable ? "pcd" : " ",
|
---|
2778 | Pde.b.u1PAT ? "pat" : "",
|
---|
2779 | Pde.b.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
|
---|
2780 | else
|
---|
2781 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
2782 | fPAE
|
---|
2783 | ? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s"
|
---|
2784 | : "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s",
|
---|
2785 | Pde.u,
|
---|
2786 | Pde.u & X86_PDE_PAE_PG_MASK,
|
---|
2787 | Pde.n.u1Present ? "p " : "np",
|
---|
2788 | Pde.n.u1Write ? "w" : "r",
|
---|
2789 | Pde.n.u1User ? "u" : "s",
|
---|
2790 | Pde.n.u1Accessed ? "a " : "na",
|
---|
2791 | Pde.u & RT_BIT(6) ? "6 " : " ",
|
---|
2792 | Pde.n.u3Available,
|
---|
2793 | Pde.u & RT_BIT(8) ? "8" : " ",
|
---|
2794 | Pde.n.u1WriteThru ? "pwt" : " ",
|
---|
2795 | Pde.n.u1CacheDisable ? "pcd" : " ",
|
---|
2796 | Pde.u & RT_BIT(7) ? "7" : "",
|
---|
2797 | Pde.n.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
|
---|
2798 | if (Pde.u & UINT64_C(0x7fff000000000000))
|
---|
2799 | DBGCCmdHlpPrintf(pCmdHlp, " weird=%RX64", (Pde.u & UINT64_C(0x7fff000000000000)));
|
---|
2800 | rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
2801 | if (RT_FAILURE(rc))
|
---|
2802 | return rc;
|
---|
2803 |
|
---|
2804 | /*
|
---|
2805 | * Advance.
|
---|
2806 | */
|
---|
2807 | VarPDEAddr.u.u64Number += cbEntry;
|
---|
2808 | if (iEntry != ~0U)
|
---|
2809 | VarGCPtr.u.GCFlat += fPAE ? RT_BIT_32(X86_PD_PAE_SHIFT) : RT_BIT_32(X86_PD_SHIFT);
|
---|
2810 | } while (cEntries-- > 0);
|
---|
2811 |
|
---|
2812 | NOREF(pResult);
|
---|
2813 | return VINF_SUCCESS;
|
---|
2814 | }
|
---|
2815 |
|
---|
2816 |
|
---|
2817 | /**
|
---|
2818 | * The 'dpdb' command.
|
---|
2819 | *
|
---|
2820 | * @returns VBox status.
|
---|
2821 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2822 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2823 | * @param pVM Pointer to the current VM (if any).
|
---|
2824 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2825 | * @param cArgs Number of arguments in the array.
|
---|
2826 | */
|
---|
2827 | static DECLCALLBACK(int) dbgcCmdDumpPageDirBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
2828 | {
|
---|
2829 | if (!pVM)
|
---|
2830 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
2831 | int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dpdg %DV", &paArgs[0]);
|
---|
2832 | int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpdh %DV", &paArgs[0]);
|
---|
2833 | if (RT_FAILURE(rc1))
|
---|
2834 | return rc1;
|
---|
2835 | NOREF(pCmd); NOREF(paArgs); NOREF(cArgs); NOREF(pResult);
|
---|
2836 | return rc2;
|
---|
2837 | }
|
---|
2838 |
|
---|
2839 |
|
---|
2840 | /**
|
---|
2841 | * The 'dph*' commands and main part of 'm'.
|
---|
2842 | *
|
---|
2843 | * @returns VBox status.
|
---|
2844 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2845 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2846 | * @param pVM Pointer to the current VM (if any).
|
---|
2847 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2848 | * @param cArgs Number of arguments in the array.
|
---|
2849 | */
|
---|
2850 | static DECLCALLBACK(int) dbgcCmdDumpPageHierarchy(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
2851 | {
|
---|
2852 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2853 | if (!pVM)
|
---|
2854 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "No VM.\n");
|
---|
2855 |
|
---|
2856 | /*
|
---|
2857 | * Figure the context and base flags.
|
---|
2858 | */
|
---|
2859 | uint32_t fFlags = DBGFPGDMP_FLAGS_PAGE_INFO | DBGFPGDMP_FLAGS_PRINT_CR3;
|
---|
2860 | if (pCmd->pszCmd[0] == 'm')
|
---|
2861 | fFlags |= DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW;
|
---|
2862 | else if (pCmd->pszCmd[3] == '\0')
|
---|
2863 | fFlags |= pDbgc->fRegCtxGuest ? DBGFPGDMP_FLAGS_GUEST : DBGFPGDMP_FLAGS_SHADOW;
|
---|
2864 | else if (pCmd->pszCmd[3] == 'g')
|
---|
2865 | fFlags |= DBGFPGDMP_FLAGS_GUEST;
|
---|
2866 | else if (pCmd->pszCmd[3] == 'h')
|
---|
2867 | fFlags |= DBGFPGDMP_FLAGS_SHADOW;
|
---|
2868 | else
|
---|
2869 | AssertFailed();
|
---|
2870 |
|
---|
2871 | if (pDbgc->cPagingHierarchyDumps == 0)
|
---|
2872 | fFlags |= DBGFPGDMP_FLAGS_HEADER;
|
---|
2873 | pDbgc->cPagingHierarchyDumps = (pDbgc->cPagingHierarchyDumps + 1) % 42;
|
---|
2874 |
|
---|
2875 | /*
|
---|
2876 | * Get the range.
|
---|
2877 | */
|
---|
2878 | PCDBGCVAR pRange = cArgs > 0 ? &paArgs[0] : pDbgc->pLastPos;
|
---|
2879 | RTGCPTR GCPtrFirst = NIL_RTGCPTR;
|
---|
2880 | int rc = DBGCCmdHlpVarToFlatAddr(pCmdHlp, pRange, &GCPtrFirst);
|
---|
2881 | if (RT_FAILURE(rc))
|
---|
2882 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to convert %DV to a flat address: %Rrc", pRange, rc);
|
---|
2883 |
|
---|
2884 | uint64_t cbRange;
|
---|
2885 | rc = DBGCCmdHlpVarGetRange(pCmdHlp, pRange, PAGE_SIZE, PAGE_SIZE * 8, &cbRange);
|
---|
2886 | if (RT_FAILURE(rc))
|
---|
2887 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to obtain the range of %DV: %Rrc", pRange, rc);
|
---|
2888 |
|
---|
2889 | RTGCPTR GCPtrLast = RTGCPTR_MAX - GCPtrFirst;
|
---|
2890 | if (cbRange >= GCPtrLast)
|
---|
2891 | GCPtrLast = RTGCPTR_MAX;
|
---|
2892 | else if (!cbRange)
|
---|
2893 | GCPtrLast = GCPtrFirst;
|
---|
2894 | else
|
---|
2895 | GCPtrLast = GCPtrFirst + cbRange - 1;
|
---|
2896 |
|
---|
2897 | /*
|
---|
2898 | * Do we have a CR3?
|
---|
2899 | */
|
---|
2900 | uint64_t cr3 = 0;
|
---|
2901 | if (cArgs > 1)
|
---|
2902 | {
|
---|
2903 | if ((fFlags & (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW)) == (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW))
|
---|
2904 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "No CR3 or mode arguments when dumping both context, please.");
|
---|
2905 | if (paArgs[1].enmType != DBGCVAR_TYPE_NUMBER)
|
---|
2906 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "The CR3 argument is not a number: %DV", &paArgs[1]);
|
---|
2907 | cr3 = paArgs[1].u.u64Number;
|
---|
2908 | }
|
---|
2909 | else
|
---|
2910 | fFlags |= DBGFPGDMP_FLAGS_CURRENT_CR3;
|
---|
2911 |
|
---|
2912 | /*
|
---|
2913 | * Do we have a mode?
|
---|
2914 | */
|
---|
2915 | if (cArgs > 2)
|
---|
2916 | {
|
---|
2917 | if (paArgs[2].enmType != DBGCVAR_TYPE_STRING)
|
---|
2918 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "The mode argument is not a string: %DV", &paArgs[2]);
|
---|
2919 | static const struct MODETOFLAGS
|
---|
2920 | {
|
---|
2921 | const char *pszName;
|
---|
2922 | uint32_t fFlags;
|
---|
2923 | } s_aModeToFlags[] =
|
---|
2924 | {
|
---|
2925 | { "ept", DBGFPGDMP_FLAGS_EPT },
|
---|
2926 | { "legacy", 0 },
|
---|
2927 | { "legacy-np", DBGFPGDMP_FLAGS_NP },
|
---|
2928 | { "pse", DBGFPGDMP_FLAGS_PSE },
|
---|
2929 | { "pse-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_NP },
|
---|
2930 | { "pae", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE },
|
---|
2931 | { "pae-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NP },
|
---|
2932 | { "pae-nx", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NXE },
|
---|
2933 | { "pae-nx-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NXE | DBGFPGDMP_FLAGS_NP },
|
---|
2934 | { "long", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME },
|
---|
2935 | { "long-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NP },
|
---|
2936 | { "long-nx", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NXE },
|
---|
2937 | { "long-nx-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NXE | DBGFPGDMP_FLAGS_NP }
|
---|
2938 | };
|
---|
2939 | int i = RT_ELEMENTS(s_aModeToFlags);
|
---|
2940 | while (i-- > 0)
|
---|
2941 | if (!strcmp(s_aModeToFlags[i].pszName, paArgs[2].u.pszString))
|
---|
2942 | {
|
---|
2943 | fFlags |= s_aModeToFlags[i].fFlags;
|
---|
2944 | break;
|
---|
2945 | }
|
---|
2946 | if (i < 0)
|
---|
2947 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Unknown mode: \"%s\"", paArgs[2].u.pszString);
|
---|
2948 | }
|
---|
2949 | else
|
---|
2950 | fFlags |= DBGFPGDMP_FLAGS_CURRENT_MODE;
|
---|
2951 |
|
---|
2952 | /*
|
---|
2953 | * Call the worker.
|
---|
2954 | */
|
---|
2955 | rc = DBGFR3PagingDumpEx(pVM, pDbgc->idCpu, fFlags, cr3, GCPtrFirst, GCPtrLast, 99 /*cMaxDepth*/,
|
---|
2956 | DBGCCmdHlpGetDbgfOutputHlp(pCmdHlp));
|
---|
2957 | if (RT_FAILURE(rc))
|
---|
2958 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "DBGFR3PagingDumpEx: %Rrc\n", rc);
|
---|
2959 | return VINF_SUCCESS;
|
---|
2960 | }
|
---|
2961 |
|
---|
2962 |
|
---|
2963 |
|
---|
2964 | /**
|
---|
2965 | * The 'dpg*' commands.
|
---|
2966 | *
|
---|
2967 | * @returns VBox status.
|
---|
2968 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2969 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2970 | * @param pVM Pointer to the current VM (if any).
|
---|
2971 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2972 | * @param cArgs Number of arguments in the array.
|
---|
2973 | */
|
---|
2974 | static DECLCALLBACK(int) dbgcCmdDumpPageTable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
2975 | {
|
---|
2976 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2977 |
|
---|
2978 | /*
|
---|
2979 | * Validate input.
|
---|
2980 | */
|
---|
2981 | if ( cArgs != 1
|
---|
2982 | || (pCmd->pszCmd[3] == 'a' && !DBGCVAR_ISPOINTER(paArgs[0].enmType))
|
---|
2983 | || (pCmd->pszCmd[3] != 'a' && !(paArgs[0].enmType == DBGCVAR_TYPE_NUMBER || DBGCVAR_ISPOINTER(paArgs[0].enmType)))
|
---|
2984 | )
|
---|
2985 | return DBGCCmdHlpPrintf(pCmdHlp, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
|
---|
2986 | if (!pVM)
|
---|
2987 | return DBGCCmdHlpPrintf(pCmdHlp, "error: No VM.\n");
|
---|
2988 |
|
---|
2989 | /*
|
---|
2990 | * Guest or shadow page tables? Get the paging parameters.
|
---|
2991 | */
|
---|
2992 | bool fGuest = pCmd->pszCmd[3] != 'h';
|
---|
2993 | if (!pCmd->pszCmd[3] || pCmd->pszCmd[3] == 'a')
|
---|
2994 | fGuest = paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
|
---|
2995 | ? pDbgc->fRegCtxGuest
|
---|
2996 | : DBGCVAR_ISGCPOINTER(paArgs[0].enmType);
|
---|
2997 |
|
---|
2998 | bool fPAE, fLME, fPSE, fPGE, fNXE;
|
---|
2999 | uint64_t cr3 = fGuest
|
---|
3000 | ? dbgcGetGuestPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE)
|
---|
3001 | : dbgcGetShadowPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE);
|
---|
3002 | const unsigned cbEntry = fPAE ? sizeof(X86PTEPAE) : sizeof(X86PTE);
|
---|
3003 |
|
---|
3004 | /*
|
---|
3005 | * Locate the PTE to start displaying at.
|
---|
3006 | *
|
---|
3007 | * The 'dpta' command takes the address of a PTE, while the others are guest
|
---|
3008 | * virtual address which PTEs should be displayed. So, 'pdta' is rather simple
|
---|
3009 | * while the others require us to do all the tedious walking thru the paging
|
---|
3010 | * hierarchy to find the intended PTE.
|
---|
3011 | */
|
---|
3012 | unsigned iEntry = ~0U; /* The page table index. ~0U for 'dpta'. */
|
---|
3013 | DBGCVAR VarGCPtr; /* The GC address corresponding to the current PTE (iEntry != ~0U). */
|
---|
3014 | DBGCVAR VarPTEAddr; /* The address of the current PTE. */
|
---|
3015 | unsigned cEntries; /* The number of entries to display. */
|
---|
3016 | unsigned cEntriesMax; /* The max number of entries to display. */
|
---|
3017 | int rc;
|
---|
3018 | if (pCmd->pszCmd[3] == 'a')
|
---|
3019 | {
|
---|
3020 | VarPTEAddr = paArgs[0];
|
---|
3021 | switch (VarPTEAddr.enmRangeType)
|
---|
3022 | {
|
---|
3023 | case DBGCVAR_RANGE_BYTES: cEntries = VarPTEAddr.u64Range / cbEntry; break;
|
---|
3024 | case DBGCVAR_RANGE_ELEMENTS: cEntries = VarPTEAddr.u64Range; break;
|
---|
3025 | default: cEntries = 10; break;
|
---|
3026 | }
|
---|
3027 | cEntriesMax = PAGE_SIZE / cbEntry;
|
---|
3028 | }
|
---|
3029 | else
|
---|
3030 | {
|
---|
3031 | /*
|
---|
3032 | * Determine the range.
|
---|
3033 | */
|
---|
3034 | switch (paArgs[0].enmRangeType)
|
---|
3035 | {
|
---|
3036 | case DBGCVAR_RANGE_BYTES: cEntries = paArgs[0].u64Range / PAGE_SIZE; break;
|
---|
3037 | case DBGCVAR_RANGE_ELEMENTS: cEntries = paArgs[0].u64Range; break;
|
---|
3038 | default: cEntries = 10; break;
|
---|
3039 | }
|
---|
3040 |
|
---|
3041 | /*
|
---|
3042 | * Normalize the input address, it must be a flat GC address.
|
---|
3043 | */
|
---|
3044 | rc = DBGCCmdHlpEval(pCmdHlp, &VarGCPtr, "%%(%Dv)", &paArgs[0]);
|
---|
3045 | if (RT_FAILURE(rc))
|
---|
3046 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
|
---|
3047 | if (VarGCPtr.enmType == DBGCVAR_TYPE_HC_FLAT)
|
---|
3048 | {
|
---|
3049 | VarGCPtr.u.GCFlat = (uintptr_t)VarGCPtr.u.pvHCFlat;
|
---|
3050 | VarGCPtr.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
3051 | }
|
---|
3052 | VarGCPtr.u.GCFlat &= ~(RTGCPTR)PAGE_OFFSET_MASK;
|
---|
3053 |
|
---|
3054 | /*
|
---|
3055 | * Do the paging walk until we get to the page table.
|
---|
3056 | */
|
---|
3057 | DBGCVAR VarCur;
|
---|
3058 | if (fGuest)
|
---|
3059 | DBGCVAR_INIT_GC_PHYS(&VarCur, cr3);
|
---|
3060 | else
|
---|
3061 | DBGCVAR_INIT_HC_PHYS(&VarCur, cr3);
|
---|
3062 | if (fLME)
|
---|
3063 | {
|
---|
3064 | /* Page Map Level 4 Lookup. */
|
---|
3065 | /* Check if it's a valid address first? */
|
---|
3066 | VarCur.u.u64Number &= X86_PTE_PAE_PG_MASK;
|
---|
3067 | VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
|
---|
3068 | X86PML4E Pml4e;
|
---|
3069 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pml4e, sizeof(Pml4e), &VarCur, NULL);
|
---|
3070 | if (RT_FAILURE(rc))
|
---|
3071 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PML4E memory at %DV.\n", &VarCur);
|
---|
3072 | if (!Pml4e.n.u1Present)
|
---|
3073 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
|
---|
3074 |
|
---|
3075 | VarCur.u.u64Number = Pml4e.u & X86_PML4E_PG_MASK;
|
---|
3076 | Assert(fPAE);
|
---|
3077 | }
|
---|
3078 | if (fPAE)
|
---|
3079 | {
|
---|
3080 | /* Page directory pointer table. */
|
---|
3081 | X86PDPE Pdpe;
|
---|
3082 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE) * sizeof(Pdpe);
|
---|
3083 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pdpe, sizeof(Pdpe), &VarCur, NULL);
|
---|
3084 | if (RT_FAILURE(rc))
|
---|
3085 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDPE memory at %DV.\n", &VarCur);
|
---|
3086 | if (!Pdpe.n.u1Present)
|
---|
3087 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory is not present for %Dv.\n", &VarGCPtr);
|
---|
3088 |
|
---|
3089 | VarCur.u.u64Number = Pdpe.u & X86_PDPE_PG_MASK;
|
---|
3090 |
|
---|
3091 | /* Page directory (PAE). */
|
---|
3092 | X86PDEPAE Pde;
|
---|
3093 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK) * sizeof(Pde);
|
---|
3094 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pde, sizeof(Pde), &VarCur, NULL);
|
---|
3095 | if (RT_FAILURE(rc))
|
---|
3096 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarCur);
|
---|
3097 | if (!Pde.n.u1Present)
|
---|
3098 | return DBGCCmdHlpPrintf(pCmdHlp, "Page table is not present for %Dv.\n", &VarGCPtr);
|
---|
3099 | if (fPSE && Pde.n.u1Size)
|
---|
3100 | return pCmdHlp->pfnExec(pCmdHlp, "dpd%s %Dv L3", &pCmd->pszCmd[3], &VarGCPtr);
|
---|
3101 |
|
---|
3102 | iEntry = (VarGCPtr.u.GCFlat >> X86_PT_PAE_SHIFT) & X86_PT_PAE_MASK;
|
---|
3103 | VarPTEAddr = VarCur;
|
---|
3104 | VarPTEAddr.u.u64Number = Pde.u & X86_PDE_PAE_PG_MASK;
|
---|
3105 | VarPTEAddr.u.u64Number += iEntry * sizeof(X86PTEPAE);
|
---|
3106 | }
|
---|
3107 | else
|
---|
3108 | {
|
---|
3109 | /* Page directory (legacy). */
|
---|
3110 | X86PDE Pde;
|
---|
3111 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PD_SHIFT) & X86_PD_MASK) * sizeof(Pde);
|
---|
3112 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pde, sizeof(Pde), &VarCur, NULL);
|
---|
3113 | if (RT_FAILURE(rc))
|
---|
3114 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarCur);
|
---|
3115 | if (!Pde.n.u1Present)
|
---|
3116 | return DBGCCmdHlpPrintf(pCmdHlp, "Page table is not present for %Dv.\n", &VarGCPtr);
|
---|
3117 | if (fPSE && Pde.n.u1Size)
|
---|
3118 | return pCmdHlp->pfnExec(pCmdHlp, "dpd%s %Dv L3", &pCmd->pszCmd[3], &VarGCPtr);
|
---|
3119 |
|
---|
3120 | iEntry = (VarGCPtr.u.GCFlat >> X86_PT_SHIFT) & X86_PT_MASK;
|
---|
3121 | VarPTEAddr = VarCur;
|
---|
3122 | VarPTEAddr.u.u64Number = Pde.u & X86_PDE_PG_MASK;
|
---|
3123 | VarPTEAddr.u.u64Number += iEntry * sizeof(X86PTE);
|
---|
3124 | }
|
---|
3125 | cEntriesMax = (PAGE_SIZE - iEntry) / cbEntry;
|
---|
3126 | iEntry /= cbEntry;
|
---|
3127 | }
|
---|
3128 |
|
---|
3129 | /* adjust cEntries */
|
---|
3130 | cEntries = RT_MAX(1, cEntries);
|
---|
3131 | cEntries = RT_MIN(cEntries, cEntriesMax);
|
---|
3132 |
|
---|
3133 | /*
|
---|
3134 | * The display loop.
|
---|
3135 | */
|
---|
3136 | DBGCCmdHlpPrintf(pCmdHlp, iEntry != ~0U ? "%DV (base %DV / index %#x):\n" : "%DV:\n",
|
---|
3137 | &VarPTEAddr, &VarGCPtr, iEntry);
|
---|
3138 | do
|
---|
3139 | {
|
---|
3140 | /*
|
---|
3141 | * Read.
|
---|
3142 | */
|
---|
3143 | X86PTEPAE Pte;
|
---|
3144 | Pte.u = 0;
|
---|
3145 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pte, cbEntry, &VarPTEAddr, NULL);
|
---|
3146 | if (RT_FAILURE(rc))
|
---|
3147 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PTE memory at %DV.\n", &VarPTEAddr);
|
---|
3148 |
|
---|
3149 | /*
|
---|
3150 | * Display.
|
---|
3151 | */
|
---|
3152 | if (iEntry != ~0U)
|
---|
3153 | {
|
---|
3154 | DBGCCmdHlpPrintf(pCmdHlp, "%03x %DV: ", iEntry, &VarGCPtr);
|
---|
3155 | iEntry++;
|
---|
3156 | }
|
---|
3157 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
3158 | fPAE
|
---|
3159 | ? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
|
---|
3160 | : "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
|
---|
3161 | Pte.u,
|
---|
3162 | Pte.u & X86_PTE_PAE_PG_MASK,
|
---|
3163 | Pte.n.u1Present ? "p " : "np",
|
---|
3164 | Pte.n.u1Write ? "w" : "r",
|
---|
3165 | Pte.n.u1User ? "u" : "s",
|
---|
3166 | Pte.n.u1Accessed ? "a " : "na",
|
---|
3167 | Pte.n.u1Dirty ? "d " : "nd",
|
---|
3168 | Pte.n.u3Available,
|
---|
3169 | Pte.n.u1Global ? (fPGE ? "g" : "G") : " ",
|
---|
3170 | Pte.n.u1WriteThru ? "pwt" : " ",
|
---|
3171 | Pte.n.u1CacheDisable ? "pcd" : " ",
|
---|
3172 | Pte.n.u1PAT ? "pat" : " ",
|
---|
3173 | Pte.n.u1NoExecute ? (fNXE ? "nx" : "NX") : " "
|
---|
3174 | );
|
---|
3175 | if (Pte.u & UINT64_C(0x7fff000000000000))
|
---|
3176 | DBGCCmdHlpPrintf(pCmdHlp, " weird=%RX64", (Pte.u & UINT64_C(0x7fff000000000000)));
|
---|
3177 | rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
3178 | if (RT_FAILURE(rc))
|
---|
3179 | return rc;
|
---|
3180 |
|
---|
3181 | /*
|
---|
3182 | * Advance.
|
---|
3183 | */
|
---|
3184 | VarPTEAddr.u.u64Number += cbEntry;
|
---|
3185 | if (iEntry != ~0U)
|
---|
3186 | VarGCPtr.u.GCFlat += PAGE_SIZE;
|
---|
3187 | } while (cEntries-- > 0);
|
---|
3188 |
|
---|
3189 | NOREF(pResult);
|
---|
3190 | return VINF_SUCCESS;
|
---|
3191 | }
|
---|
3192 |
|
---|
3193 |
|
---|
3194 | /**
|
---|
3195 | * The 'dptb' command.
|
---|
3196 | *
|
---|
3197 | * @returns VBox status.
|
---|
3198 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
3199 | * @param pCmdHlp Pointer to command helper functions.
|
---|
3200 | * @param pVM Pointer to the current VM (if any).
|
---|
3201 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
3202 | * @param cArgs Number of arguments in the array.
|
---|
3203 | */
|
---|
3204 | static DECLCALLBACK(int) dbgcCmdDumpPageTableBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
3205 | {
|
---|
3206 | if (!pVM)
|
---|
3207 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
3208 | int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dptg %DV", &paArgs[0]);
|
---|
3209 | int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpth %DV", &paArgs[0]);
|
---|
3210 | if (RT_FAILURE(rc1))
|
---|
3211 | return rc1;
|
---|
3212 | NOREF(pCmd); NOREF(cArgs); NOREF(pResult);
|
---|
3213 | return rc2;
|
---|
3214 | }
|
---|
3215 |
|
---|
3216 |
|
---|
3217 | /**
|
---|
3218 | * The 'dt' command.
|
---|
3219 | *
|
---|
3220 | * @returns VBox status.
|
---|
3221 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
3222 | * @param pCmdHlp Pointer to command helper functions.
|
---|
3223 | * @param pVM Pointer to the current VM (if any).
|
---|
3224 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
3225 | * @param cArgs Number of arguments in the array.
|
---|
3226 | */
|
---|
3227 | static DECLCALLBACK(int) dbgcCmdDumpTSS(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
|
---|
3228 | {
|
---|
3229 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3230 | int rc;
|
---|
3231 |
|
---|
3232 | if (!pVM)
|
---|
3233 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "No VM.\n");
|
---|
3234 | if ( cArgs > 1
|
---|
3235 | || (cArgs == 1 && paArgs[0].enmType == DBGCVAR_TYPE_STRING)
|
---|
3236 | || (cArgs == 1 && paArgs[0].enmType == DBGCVAR_TYPE_SYMBOL))
|
---|
3237 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "internal error: The parser doesn't do its job properly yet...\n");
|
---|
3238 |
|
---|
3239 | /*
|
---|
3240 | * Check if the command indicates the type.
|
---|
3241 | */
|
---|
3242 | enum { kTss16, kTss32, kTss64, kTssToBeDetermined } enmTssType = kTssToBeDetermined;
|
---|
3243 | if (!strcmp(pCmd->pszCmd, "dt16"))
|
---|
3244 | enmTssType = kTss16;
|
---|
3245 | else if (!strcmp(pCmd->pszCmd, "dt32"))
|
---|
3246 | enmTssType = kTss32;
|
---|
3247 | else if (!strcmp(pCmd->pszCmd, "dt64"))
|
---|
3248 | enmTssType = kTss64;
|
---|
3249 |
|
---|
3250 | /*
|
---|
3251 | * We can get a TSS selector (number), a far pointer using a TSS selector, or some kind of TSS pointer.
|
---|
3252 | */
|
---|
3253 | uint32_t SelTss = UINT32_MAX;
|
---|
3254 | DBGCVAR VarTssAddr;
|
---|
3255 | if (cArgs == 0)
|
---|
3256 | {
|
---|
3257 | /** @todo consider querying the hidden bits instead (missing API). */
|
---|
3258 | uint16_t SelTR;
|
---|
3259 | rc = DBGFR3RegCpuQueryU16(pVM, pDbgc->idCpu, DBGFREG_TR, &SelTR);
|
---|
3260 | if (RT_FAILURE(rc))
|
---|
3261 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to query TR, rc=%Rrc\n", rc);
|
---|
3262 | DBGCVAR_INIT_GC_FAR(&VarTssAddr, SelTR, 0);
|
---|
3263 | SelTss = SelTR;
|
---|
3264 | }
|
---|
3265 | else if (paArgs[0].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
3266 | {
|
---|
3267 | if (paArgs[0].u.u64Number < 0xffff)
|
---|
3268 | DBGCVAR_INIT_GC_FAR(&VarTssAddr, (RTSEL)paArgs[0].u.u64Number, 0);
|
---|
3269 | else
|
---|
3270 | {
|
---|
3271 | if (paArgs[0].enmRangeType == DBGCVAR_RANGE_ELEMENTS)
|
---|
3272 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Element count doesn't combine with a TSS address.\n");
|
---|
3273 | DBGCVAR_INIT_GC_FLAT(&VarTssAddr, paArgs[0].u.u64Number);
|
---|
3274 | if (paArgs[0].enmRangeType == DBGCVAR_RANGE_BYTES)
|
---|
3275 | {
|
---|
3276 | VarTssAddr.enmRangeType = paArgs[0].enmRangeType;
|
---|
3277 | VarTssAddr.u64Range = paArgs[0].u64Range;
|
---|
3278 | }
|
---|
3279 | }
|
---|
3280 | }
|
---|
3281 | else
|
---|
3282 | VarTssAddr = paArgs[0];
|
---|
3283 |
|
---|
3284 | /*
|
---|
3285 | * Deal with TSS:ign by means of the GDT.
|
---|
3286 | */
|
---|
3287 | if (VarTssAddr.enmType == DBGCVAR_TYPE_GC_FAR)
|
---|
3288 | {
|
---|
3289 | SelTss = VarTssAddr.u.GCFar.sel;
|
---|
3290 | DBGFSELINFO SelInfo;
|
---|
3291 | rc = DBGFR3SelQueryInfo(pVM, pDbgc->idCpu, VarTssAddr.u.GCFar.sel, DBGFSELQI_FLAGS_DT_GUEST, &SelInfo);
|
---|
3292 | if (RT_FAILURE(rc))
|
---|
3293 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "DBGFR3SelQueryInfo(,%u,%d,,) -> %Rrc.\n",
|
---|
3294 | pDbgc->idCpu, VarTssAddr.u.GCFar.sel, rc);
|
---|
3295 |
|
---|
3296 | if (SelInfo.u.Raw.Gen.u1DescType)
|
---|
3297 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "%04x is not a TSS selector. (!sys)\n", VarTssAddr.u.GCFar.sel);
|
---|
3298 |
|
---|
3299 | switch (SelInfo.u.Raw.Gen.u4Type)
|
---|
3300 | {
|
---|
3301 | case X86_SEL_TYPE_SYS_286_TSS_BUSY:
|
---|
3302 | case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
|
---|
3303 | if (enmTssType == kTssToBeDetermined)
|
---|
3304 | enmTssType = kTss16;
|
---|
3305 | break;
|
---|
3306 |
|
---|
3307 | case X86_SEL_TYPE_SYS_386_TSS_BUSY: /* AMD64 too */
|
---|
3308 | case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
|
---|
3309 | if (enmTssType == kTssToBeDetermined)
|
---|
3310 | enmTssType = SelInfo.fFlags & DBGFSELINFO_FLAGS_LONG_MODE ? kTss64 : kTss32;
|
---|
3311 | break;
|
---|
3312 |
|
---|
3313 | default:
|
---|
3314 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "%04x is not a TSS selector. (type=%x)\n",
|
---|
3315 | VarTssAddr.u.GCFar.sel, SelInfo.u.Raw.Gen.u4Type);
|
---|
3316 | }
|
---|
3317 |
|
---|
3318 | DBGCVAR_INIT_GC_FLAT(&VarTssAddr, SelInfo.GCPtrBase);
|
---|
3319 | DBGCVAR_SET_RANGE(&VarTssAddr, DBGCVAR_RANGE_BYTES, RT_MAX(SelInfo.cbLimit + 1, SelInfo.cbLimit));
|
---|
3320 | }
|
---|
3321 |
|
---|
3322 | /*
|
---|
3323 | * Determine the TSS type if none is currently given.
|
---|
3324 | */
|
---|
3325 | if (enmTssType == kTssToBeDetermined)
|
---|
3326 | {
|
---|
3327 | if ( VarTssAddr.u64Range > 0
|
---|
3328 | && VarTssAddr.u64Range < sizeof(X86TSS32) - 4)
|
---|
3329 | enmTssType = kTss16;
|
---|
3330 | else
|
---|
3331 | {
|
---|
3332 | uint64_t uEfer;
|
---|
3333 | rc = DBGFR3RegCpuQueryU64(pVM, pDbgc->idCpu, DBGFREG_MSR_K6_EFER, &uEfer);
|
---|
3334 | if ( RT_FAILURE(rc)
|
---|
3335 | || !(uEfer & MSR_K6_EFER_LMA) )
|
---|
3336 | enmTssType = kTss32;
|
---|
3337 | else
|
---|
3338 | enmTssType = kTss64;
|
---|
3339 | }
|
---|
3340 | }
|
---|
3341 |
|
---|
3342 | /*
|
---|
3343 | * Figure the min/max sizes.
|
---|
3344 | * ASSUMES max TSS size is 64 KB.
|
---|
3345 | */
|
---|
3346 | uint32_t cbTssMin;
|
---|
3347 | uint32_t cbTssMax;
|
---|
3348 | switch (enmTssType)
|
---|
3349 | {
|
---|
3350 | case kTss16:
|
---|
3351 | cbTssMin = cbTssMax = sizeof(X86TSS16);
|
---|
3352 | break;
|
---|
3353 | case kTss32:
|
---|
3354 | cbTssMin = RT_OFFSETOF(X86TSS32, IntRedirBitmap);
|
---|
3355 | cbTssMax = _64K;
|
---|
3356 | break;
|
---|
3357 | case kTss64:
|
---|
3358 | cbTssMin = RT_OFFSETOF(X86TSS64, IntRedirBitmap);
|
---|
3359 | cbTssMax = _64K;
|
---|
3360 | break;
|
---|
3361 | default:
|
---|
3362 | AssertFailedReturn(VERR_INTERNAL_ERROR);
|
---|
3363 | }
|
---|
3364 | uint32_t cbTss = VarTssAddr.enmRangeType == DBGCVAR_RANGE_BYTES ? (uint32_t)VarTssAddr.u64Range : 0;
|
---|
3365 | if (cbTss == 0)
|
---|
3366 | cbTss = cbTssMin;
|
---|
3367 | else if (cbTss < cbTssMin)
|
---|
3368 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Minimum TSS size is %u bytes, you specified %llu (%llx) bytes.\n",
|
---|
3369 | cbTssMin, VarTssAddr.u64Range, VarTssAddr.u64Range);
|
---|
3370 | else if (cbTss > cbTssMax)
|
---|
3371 | cbTss = cbTssMax;
|
---|
3372 | DBGCVAR_SET_RANGE(&VarTssAddr, DBGCVAR_RANGE_BYTES, cbTss);
|
---|
3373 |
|
---|
3374 | /*
|
---|
3375 | * Read the TSS into a temporary buffer.
|
---|
3376 | */
|
---|
3377 | uint8_t abBuf[_64K];
|
---|
3378 | size_t cbTssRead;
|
---|
3379 | rc = DBGCCmdHlpMemRead(pCmdHlp, pVM, abBuf, cbTss, &VarTssAddr, &cbTssRead);
|
---|
3380 | if (RT_FAILURE(rc))
|
---|
3381 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to read TSS at %Dv: %Rrc\n", &VarTssAddr, rc);
|
---|
3382 | if (cbTssRead < cbTssMin)
|
---|
3383 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to read essential parts of the TSS (read %zu, min %zu).\n",
|
---|
3384 | cbTssRead, cbTssMin);
|
---|
3385 | if (cbTssRead < cbTss)
|
---|
3386 | memset(&abBuf[cbTssRead], 0xff, cbTss - cbTssRead);
|
---|
3387 |
|
---|
3388 |
|
---|
3389 | /*
|
---|
3390 | * Format the TSS.
|
---|
3391 | */
|
---|
3392 | uint16_t offIoBitmap;
|
---|
3393 | switch (enmTssType)
|
---|
3394 | {
|
---|
3395 | case kTss16:
|
---|
3396 | {
|
---|
3397 | PCX86TSS16 pTss = (PCX86TSS16)&abBuf[0];
|
---|
3398 | if (SelTss != UINT32_MAX)
|
---|
3399 | DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS16 at %Dv\n", SelTss, &VarTssAddr);
|
---|
3400 | else
|
---|
3401 | DBGCCmdHlpPrintf(pCmdHlp, "TSS16 at %Dv\n", &VarTssAddr);
|
---|
3402 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
3403 | "ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x\n"
|
---|
3404 | "ip=%04x sp=%04x bp=%04x\n"
|
---|
3405 | "cs=%04x ss=%04x ds=%04x es=%04x flags=%04x\n"
|
---|
3406 | "ss:sp0=%04x:%04x ss:sp1=%04x:%04x ss:sp2=%04x:%04x\n"
|
---|
3407 | "prev=%04x ldtr=%04x\n"
|
---|
3408 | ,
|
---|
3409 | pTss->ax, pTss->bx, pTss->cx, pTss->dx, pTss->si, pTss->di,
|
---|
3410 | pTss->ip, pTss->sp, pTss->bp,
|
---|
3411 | pTss->cs, pTss->ss, pTss->ds, pTss->es, pTss->flags,
|
---|
3412 | pTss->ss0, pTss->sp0, pTss->ss1, pTss->sp1, pTss->ss2, pTss->sp2,
|
---|
3413 | pTss->selPrev, pTss->selLdt);
|
---|
3414 | if (pTss->cs != 0)
|
---|
3415 | pCmdHlp->pfnExec(pCmdHlp, "u %04x:%04x L 0", pTss->cs, pTss->ip);
|
---|
3416 | offIoBitmap = 0;
|
---|
3417 | break;
|
---|
3418 | }
|
---|
3419 |
|
---|
3420 | case kTss32:
|
---|
3421 | {
|
---|
3422 | PCX86TSS32 pTss = (PCX86TSS32)&abBuf[0];
|
---|
3423 | if (SelTss != UINT32_MAX)
|
---|
3424 | DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS32 at %Dv (min=%04x)\n", SelTss, &VarTssAddr, cbTssMin);
|
---|
3425 | else
|
---|
3426 | DBGCCmdHlpPrintf(pCmdHlp, "TSS32 at %Dv (min=%04x)\n", &VarTssAddr, cbTssMin);
|
---|
3427 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
3428 | "eax=%08x bx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n"
|
---|
3429 | "eip=%08x esp=%08x ebp=%08x\n"
|
---|
3430 | "cs=%04x ss=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08x\n"
|
---|
3431 | "ss:esp0=%04x:%08x ss:esp1=%04x:%08x ss:esp2=%04x:%08x\n"
|
---|
3432 | "prev=%04x ldtr=%04x cr3=%08x debug=%u iomap=%04x\n"
|
---|
3433 | ,
|
---|
3434 | pTss->eax, pTss->ebx, pTss->ecx, pTss->edx, pTss->esi, pTss->edi,
|
---|
3435 | pTss->eip, pTss->esp, pTss->ebp,
|
---|
3436 | pTss->cs, pTss->ss, pTss->ds, pTss->es, pTss->fs, pTss->gs, pTss->eflags,
|
---|
3437 | pTss->ss0, pTss->esp0, pTss->ss1, pTss->esp1, pTss->ss2, pTss->esp2,
|
---|
3438 | pTss->selPrev, pTss->selLdt, pTss->cr3, pTss->fDebugTrap, pTss->offIoBitmap);
|
---|
3439 | if (pTss->cs != 0)
|
---|
3440 | pCmdHlp->pfnExec(pCmdHlp, "u %04x:%08x L 0", pTss->cs, pTss->eip);
|
---|
3441 | offIoBitmap = pTss->offIoBitmap;
|
---|
3442 | break;
|
---|
3443 | }
|
---|
3444 |
|
---|
3445 | case kTss64:
|
---|
3446 | {
|
---|
3447 | PCX86TSS64 pTss = (PCX86TSS64)&abBuf[0];
|
---|
3448 | if (SelTss != UINT32_MAX)
|
---|
3449 | DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS64 at %Dv (min=%04x)\n", SelTss, &VarTssAddr, cbTssMin);
|
---|
3450 | else
|
---|
3451 | DBGCCmdHlpPrintf(pCmdHlp, "TSS64 at %Dv (min=%04x)\n", &VarTssAddr, cbTssMin);
|
---|
3452 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
3453 | "rsp0=%016RX16 rsp1=%016RX16 rsp2=%016RX16\n"
|
---|
3454 | "ist1=%016RX16 ist2=%016RX16\n"
|
---|
3455 | "ist3=%016RX16 ist4=%016RX16\n"
|
---|
3456 | "ist5=%016RX16 ist6=%016RX16\n"
|
---|
3457 | "ist7=%016RX16 iomap=%04x\n"
|
---|
3458 | ,
|
---|
3459 | pTss->rsp0, pTss->rsp1, pTss->rsp2,
|
---|
3460 | pTss->ist1, pTss->ist2,
|
---|
3461 | pTss->ist3, pTss->ist4,
|
---|
3462 | pTss->ist5, pTss->ist6,
|
---|
3463 | pTss->ist7, pTss->offIoBitmap);
|
---|
3464 | offIoBitmap = pTss->offIoBitmap;
|
---|
3465 | break;
|
---|
3466 | }
|
---|
3467 |
|
---|
3468 | default:
|
---|
3469 | AssertFailedReturn(VERR_INTERNAL_ERROR);
|
---|
3470 | }
|
---|
3471 |
|
---|
3472 | /*
|
---|
3473 | * Dump the interrupt redirection bitmap.
|
---|
3474 | */
|
---|
3475 | if (enmTssType != kTss16)
|
---|
3476 | {
|
---|
3477 | if ( offIoBitmap > cbTssMin
|
---|
3478 | && offIoBitmap < cbTss) /** @todo check exactly what the edge cases are here. */
|
---|
3479 | {
|
---|
3480 | if (offIoBitmap - cbTssMin >= 32)
|
---|
3481 | {
|
---|
3482 | DBGCCmdHlpPrintf(pCmdHlp, "Interrupt redirection:\n");
|
---|
3483 | uint8_t const *pbIntRedirBitmap = &abBuf[offIoBitmap - 32];
|
---|
3484 | uint32_t iStart = 0;
|
---|
3485 | bool fPrev = ASMBitTest(pbIntRedirBitmap, 0); /* LE/BE issue */
|
---|
3486 | for (uint32_t i = 0; i < 256; i++)
|
---|
3487 | {
|
---|
3488 | bool fThis = ASMBitTest(pbIntRedirBitmap, i);
|
---|
3489 | if (fThis != fPrev)
|
---|
3490 | {
|
---|
3491 | DBGCCmdHlpPrintf(pCmdHlp, "%02x-%02x %s\n", iStart, i - 1, fPrev ? "Protected mode" : "Redirected");
|
---|
3492 | fPrev = fThis;
|
---|
3493 | iStart = i;
|
---|
3494 | }
|
---|
3495 | }
|
---|
3496 | if (iStart != 255)
|
---|
3497 | DBGCCmdHlpPrintf(pCmdHlp, "%02x-%02x %s\n", iStart, 255, fPrev ? "Protected mode" : "Redirected");
|
---|
3498 | }
|
---|
3499 | else
|
---|
3500 | DBGCCmdHlpPrintf(pCmdHlp, "Invalid interrupt redirection bitmap size: %u (%#x), expected 32 bytes.\n",
|
---|
3501 | offIoBitmap - cbTssMin, offIoBitmap - cbTssMin);
|
---|
3502 | }
|
---|
3503 | else if (offIoBitmap > 0)
|
---|
3504 | DBGCCmdHlpPrintf(pCmdHlp, "No interrupt redirection bitmap (-%#x)\n", cbTssMin - offIoBitmap);
|
---|
3505 | else
|
---|
3506 | DBGCCmdHlpPrintf(pCmdHlp, "No interrupt redirection bitmap\n");
|
---|
3507 | }
|
---|
3508 |
|
---|
3509 | /*
|
---|
3510 | * Dump the I/O bitmap if present.
|
---|
3511 | */
|
---|
3512 | if (enmTssType != kTss16)
|
---|
3513 | {
|
---|
3514 | if (offIoBitmap < cbTss)
|
---|
3515 | {
|
---|
3516 | uint32_t cPorts = RT_MIN((cbTss - offIoBitmap) * 8, _64K);
|
---|
3517 | DBGCVAR VarAddr;
|
---|
3518 | DBGCCmdHlpEval(pCmdHlp, &VarAddr, "%DV + %#x", &VarTssAddr, offIoBitmap);
|
---|
3519 | DBGCCmdHlpPrintf(pCmdHlp, "I/O bitmap at %DV - %#x ports:\n", &VarAddr, cPorts);
|
---|
3520 |
|
---|
3521 | uint8_t const *pbIoBitmap = &abBuf[offIoBitmap];
|
---|
3522 | uint32_t iStart = 0;
|
---|
3523 | bool fPrev = ASMBitTest(pbIoBitmap, 0);
|
---|
3524 | uint32_t cLine = 0;
|
---|
3525 | for (uint32_t i = 1; i < cPorts; i++)
|
---|
3526 | {
|
---|
3527 | bool fThis = ASMBitTest(pbIoBitmap, i);
|
---|
3528 | if (fThis != fPrev)
|
---|
3529 | {
|
---|
3530 | cLine++;
|
---|
3531 | DBGCCmdHlpPrintf(pCmdHlp, "%04x-%04x %s%s", iStart, i-1,
|
---|
3532 | fPrev ? "GP" : "OK", (cLine % 6) == 0 ? "\n" : " ");
|
---|
3533 | fPrev = fThis;
|
---|
3534 | iStart = i;
|
---|
3535 | }
|
---|
3536 | }
|
---|
3537 | if (iStart != _64K-1)
|
---|
3538 | DBGCCmdHlpPrintf(pCmdHlp, "%04x-%04x %s\n", iStart, _64K-1, fPrev ? "GP" : "OK");
|
---|
3539 | }
|
---|
3540 | else if (offIoBitmap > 0)
|
---|
3541 | DBGCCmdHlpPrintf(pCmdHlp, "No I/O bitmap (-%#x)\n", cbTssMin - offIoBitmap);
|
---|
3542 | else
|
---|
3543 | DBGCCmdHlpPrintf(pCmdHlp, "No I/O bitmap\n");
|
---|
3544 | }
|
---|
3545 |
|
---|
3546 | return VINF_SUCCESS;
|
---|
3547 | }
|
---|
3548 |
|
---|
3549 |
|
---|
3550 | /**
|
---|
3551 | * The 'm' command.
|
---|
3552 | *
|
---|
3553 | * @returns VBox status.
|
---|
3554 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
3555 | * @param pCmdHlp Pointer to command helper functions.
|
---|
3556 | * @param pVM Pointer to the current VM (if any).
|
---|
3557 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
3558 | * @param cArgs Number of arguments in the array.
|
---|
3559 | */
|
---|
3560 | static DECLCALLBACK(int) dbgcCmdMemoryInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
3561 | {
|
---|
3562 | DBGCCmdHlpPrintf(pCmdHlp, "Address: %DV\n", &paArgs[0]);
|
---|
3563 | if (!pVM)
|
---|
3564 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "No VM.\n");
|
---|
3565 | return dbgcCmdDumpPageHierarchy(pCmd, pCmdHlp, pVM, paArgs, cArgs, pResult);
|
---|
3566 | }
|
---|
3567 |
|
---|
3568 |
|
---|
3569 | /**
|
---|
3570 | * Converts one or more variables into a byte buffer for a
|
---|
3571 | * given unit size.
|
---|
3572 | *
|
---|
3573 | * @returns VBox status codes:
|
---|
3574 | * @retval VERR_TOO_MUCH_DATA if the buffer is too small, bitched.
|
---|
3575 | * @retval VERR_INTERNAL_ERROR on bad variable type, bitched.
|
---|
3576 | * @retval VINF_SUCCESS on success.
|
---|
3577 | *
|
---|
3578 | * @param pvBuf The buffer to convert into.
|
---|
3579 | * @param pcbBuf The buffer size on input. The size of the result on output.
|
---|
3580 | * @param cbUnit The unit size to apply when converting.
|
---|
3581 | * The high bit is used to indicate unicode string.
|
---|
3582 | * @param paVars The array of variables to convert.
|
---|
3583 | * @param cVars The number of variables.
|
---|
3584 | */
|
---|
3585 | int dbgcVarsToBytes(PDBGCCMDHLP pCmdHlp, void *pvBuf, uint32_t *pcbBuf, size_t cbUnit, PCDBGCVAR paVars, unsigned cVars)
|
---|
3586 | {
|
---|
3587 | union
|
---|
3588 | {
|
---|
3589 | uint8_t *pu8;
|
---|
3590 | uint16_t *pu16;
|
---|
3591 | uint32_t *pu32;
|
---|
3592 | uint64_t *pu64;
|
---|
3593 | } u, uEnd;
|
---|
3594 | u.pu8 = (uint8_t *)pvBuf;
|
---|
3595 | uEnd.pu8 = u.pu8 + *pcbBuf;
|
---|
3596 |
|
---|
3597 | unsigned i;
|
---|
3598 | for (i = 0; i < cVars && u.pu8 < uEnd.pu8; i++)
|
---|
3599 | {
|
---|
3600 | switch (paVars[i].enmType)
|
---|
3601 | {
|
---|
3602 | case DBGCVAR_TYPE_GC_FAR:
|
---|
3603 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
3604 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
3605 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
3606 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
3607 | case DBGCVAR_TYPE_NUMBER:
|
---|
3608 | {
|
---|
3609 | uint64_t u64 = paVars[i].u.u64Number;
|
---|
3610 | switch (cbUnit & 0x1f)
|
---|
3611 | {
|
---|
3612 | case 1:
|
---|
3613 | do
|
---|
3614 | {
|
---|
3615 | *u.pu8++ = u64;
|
---|
3616 | u64 >>= 8;
|
---|
3617 | } while (u64);
|
---|
3618 | break;
|
---|
3619 | case 2:
|
---|
3620 | do
|
---|
3621 | {
|
---|
3622 | *u.pu16++ = u64;
|
---|
3623 | u64 >>= 16;
|
---|
3624 | } while (u64);
|
---|
3625 | break;
|
---|
3626 | case 4:
|
---|
3627 | *u.pu32++ = u64;
|
---|
3628 | u64 >>= 32;
|
---|
3629 | if (u64)
|
---|
3630 | *u.pu32++ = u64;
|
---|
3631 | break;
|
---|
3632 | case 8:
|
---|
3633 | *u.pu64++ = u64;
|
---|
3634 | break;
|
---|
3635 | }
|
---|
3636 | break;
|
---|
3637 | }
|
---|
3638 |
|
---|
3639 | case DBGCVAR_TYPE_STRING:
|
---|
3640 | case DBGCVAR_TYPE_SYMBOL:
|
---|
3641 | {
|
---|
3642 | const char *psz = paVars[i].u.pszString;
|
---|
3643 | size_t cbString = strlen(psz);
|
---|
3644 | if (cbUnit & RT_BIT_32(31))
|
---|
3645 | {
|
---|
3646 | /* Explode char to unit. */
|
---|
3647 | if (cbString > (uintptr_t)(uEnd.pu8 - u.pu8) * (cbUnit & 0x1f))
|
---|
3648 | {
|
---|
3649 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
|
---|
3650 | return VERR_TOO_MUCH_DATA;
|
---|
3651 | }
|
---|
3652 | while (*psz)
|
---|
3653 | {
|
---|
3654 | switch (cbUnit & 0x1f)
|
---|
3655 | {
|
---|
3656 | case 1: *u.pu8++ = *psz; break;
|
---|
3657 | case 2: *u.pu16++ = *psz; break;
|
---|
3658 | case 4: *u.pu32++ = *psz; break;
|
---|
3659 | case 8: *u.pu64++ = *psz; break;
|
---|
3660 | }
|
---|
3661 | psz++;
|
---|
3662 | }
|
---|
3663 | }
|
---|
3664 | else
|
---|
3665 | {
|
---|
3666 | /* Raw copy with zero padding if the size isn't aligned. */
|
---|
3667 | if (cbString > (uintptr_t)(uEnd.pu8 - u.pu8))
|
---|
3668 | {
|
---|
3669 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
|
---|
3670 | return VERR_TOO_MUCH_DATA;
|
---|
3671 | }
|
---|
3672 |
|
---|
3673 | size_t cbCopy = cbString & ~(cbUnit - 1);
|
---|
3674 | memcpy(u.pu8, psz, cbCopy);
|
---|
3675 | u.pu8 += cbCopy;
|
---|
3676 | psz += cbCopy;
|
---|
3677 |
|
---|
3678 | size_t cbReminder = cbString & (cbUnit - 1);
|
---|
3679 | if (cbReminder)
|
---|
3680 | {
|
---|
3681 | memcpy(u.pu8, psz, cbString & (cbUnit - 1));
|
---|
3682 | memset(u.pu8 + cbReminder, 0, cbUnit - cbReminder);
|
---|
3683 | u.pu8 += cbUnit;
|
---|
3684 | }
|
---|
3685 | }
|
---|
3686 | break;
|
---|
3687 | }
|
---|
3688 |
|
---|
3689 | default:
|
---|
3690 | *pcbBuf = u.pu8 - (uint8_t *)pvBuf;
|
---|
3691 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INTERNAL_ERROR,
|
---|
3692 | "i=%d enmType=%d\n", i, paVars[i].enmType);
|
---|
3693 | return VERR_INTERNAL_ERROR;
|
---|
3694 | }
|
---|
3695 | }
|
---|
3696 | *pcbBuf = u.pu8 - (uint8_t *)pvBuf;
|
---|
3697 | if (i != cVars)
|
---|
3698 | {
|
---|
3699 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
|
---|
3700 | return VERR_TOO_MUCH_DATA;
|
---|
3701 | }
|
---|
3702 | return VINF_SUCCESS;
|
---|
3703 | }
|
---|
3704 |
|
---|
3705 |
|
---|
3706 | /**
|
---|
3707 | * The 'eb', 'ew', 'ed' and 'eq' commands.
|
---|
3708 | *
|
---|
3709 | * @returns VBox status.
|
---|
3710 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
3711 | * @param pCmdHlp Pointer to command helper functions.
|
---|
3712 | * @param pVM Pointer to the current VM (if any).
|
---|
3713 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
3714 | * @param cArgs Number of arguments in the array.
|
---|
3715 | */
|
---|
3716 | static DECLCALLBACK(int) dbgcCmdEditMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
3717 | {
|
---|
3718 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3719 | unsigned iArg;
|
---|
3720 |
|
---|
3721 | /*
|
---|
3722 | * Validate input.
|
---|
3723 | */
|
---|
3724 | if ( cArgs < 2
|
---|
3725 | || !DBGCVAR_ISPOINTER(paArgs[0].enmType))
|
---|
3726 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "internal error: The parser doesn't do its job properly yet... It might help to use the '%%' operator.\n");
|
---|
3727 | for (iArg = 1; iArg < cArgs; iArg++)
|
---|
3728 | if (paArgs[iArg].enmType != DBGCVAR_TYPE_NUMBER)
|
---|
3729 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "internal error: The parser doesn't do its job properly yet: Arg #%u is not a number.\n", iArg);
|
---|
3730 | if (!pVM)
|
---|
3731 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "error: No VM.\n");
|
---|
3732 |
|
---|
3733 | /*
|
---|
3734 | * Figure out the element size.
|
---|
3735 | */
|
---|
3736 | unsigned cbElement;
|
---|
3737 | switch (pCmd->pszCmd[1])
|
---|
3738 | {
|
---|
3739 | default:
|
---|
3740 | case 'b': cbElement = 1; break;
|
---|
3741 | case 'w': cbElement = 2; break;
|
---|
3742 | case 'd': cbElement = 4; break;
|
---|
3743 | case 'q': cbElement = 8; break;
|
---|
3744 | }
|
---|
3745 |
|
---|
3746 | /*
|
---|
3747 | * Do setting.
|
---|
3748 | */
|
---|
3749 | DBGCVAR Addr = paArgs[0];
|
---|
3750 | for (iArg = 1;;)
|
---|
3751 | {
|
---|
3752 | size_t cbWritten;
|
---|
3753 | int rc = pCmdHlp->pfnMemWrite(pCmdHlp, pVM, &paArgs[iArg].u, cbElement, &Addr, &cbWritten);
|
---|
3754 | if (RT_FAILURE(rc))
|
---|
3755 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Writing memory at %DV.\n", &Addr);
|
---|
3756 | if (cbWritten != cbElement)
|
---|
3757 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Only wrote %u out of %u bytes!\n", cbWritten, cbElement);
|
---|
3758 |
|
---|
3759 | /* advance. */
|
---|
3760 | iArg++;
|
---|
3761 | if (iArg >= cArgs)
|
---|
3762 | break;
|
---|
3763 | rc = DBGCCmdHlpEval(pCmdHlp, &Addr, "%Dv + %#x", &Addr, cbElement);
|
---|
3764 | if (RT_FAILURE(rc))
|
---|
3765 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
|
---|
3766 | }
|
---|
3767 |
|
---|
3768 | NOREF(pResult);
|
---|
3769 | return VINF_SUCCESS;
|
---|
3770 | }
|
---|
3771 |
|
---|
3772 |
|
---|
3773 | /**
|
---|
3774 | * Executes the search.
|
---|
3775 | *
|
---|
3776 | * @returns VBox status code.
|
---|
3777 | * @param pCmdHlp The command helpers.
|
---|
3778 | * @param pVM The VM handle.
|
---|
3779 | * @param pAddress The address to start searching from. (undefined on output)
|
---|
3780 | * @param cbRange The address range to search. Must not wrap.
|
---|
3781 | * @param pabBytes The byte pattern to search for.
|
---|
3782 | * @param cbBytes The size of the pattern.
|
---|
3783 | * @param cbUnit The search unit.
|
---|
3784 | * @param cMaxHits The max number of hits.
|
---|
3785 | * @param pResult Where to store the result if it's a function invocation.
|
---|
3786 | */
|
---|
3787 | static int dbgcCmdWorkerSearchMemDoIt(PDBGCCMDHLP pCmdHlp, PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR cbRange,
|
---|
3788 | const uint8_t *pabBytes, uint32_t cbBytes,
|
---|
3789 | uint32_t cbUnit, uint64_t cMaxHits, PDBGCVAR pResult)
|
---|
3790 | {
|
---|
3791 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3792 |
|
---|
3793 | /*
|
---|
3794 | * Do the search.
|
---|
3795 | */
|
---|
3796 | uint64_t cHits = 0;
|
---|
3797 | for (;;)
|
---|
3798 | {
|
---|
3799 | /* search */
|
---|
3800 | DBGFADDRESS HitAddress;
|
---|
3801 | int rc = DBGFR3MemScan(pVM, pDbgc->idCpu, pAddress, cbRange, 1, pabBytes, cbBytes, &HitAddress);
|
---|
3802 | if (RT_FAILURE(rc))
|
---|
3803 | {
|
---|
3804 | if (rc != VERR_DBGF_MEM_NOT_FOUND)
|
---|
3805 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3MemScan\n");
|
---|
3806 |
|
---|
3807 | /* update the current address so we can save it (later). */
|
---|
3808 | pAddress->off += cbRange;
|
---|
3809 | pAddress->FlatPtr += cbRange;
|
---|
3810 | cbRange = 0;
|
---|
3811 | break;
|
---|
3812 | }
|
---|
3813 |
|
---|
3814 | /* report result */
|
---|
3815 | DBGCVAR VarCur;
|
---|
3816 | dbgcVarInit(&VarCur);
|
---|
3817 | dbgcVarSetDbgfAddr(&VarCur, &HitAddress);
|
---|
3818 | if (!pResult)
|
---|
3819 | pCmdHlp->pfnExec(pCmdHlp, "db %DV LB 10", &VarCur);
|
---|
3820 | else
|
---|
3821 | dbgcVarSetDbgfAddr(pResult, &HitAddress);
|
---|
3822 |
|
---|
3823 | /* advance */
|
---|
3824 | cbRange -= HitAddress.FlatPtr - pAddress->FlatPtr;
|
---|
3825 | *pAddress = HitAddress;
|
---|
3826 | pAddress->FlatPtr += cbBytes;
|
---|
3827 | pAddress->off += cbBytes;
|
---|
3828 | if (cbRange <= cbBytes)
|
---|
3829 | {
|
---|
3830 | cbRange = 0;
|
---|
3831 | break;
|
---|
3832 | }
|
---|
3833 | cbRange -= cbBytes;
|
---|
3834 |
|
---|
3835 | if (++cHits >= cMaxHits)
|
---|
3836 | {
|
---|
3837 | /// @todo save the search.
|
---|
3838 | break;
|
---|
3839 | }
|
---|
3840 | }
|
---|
3841 |
|
---|
3842 | /*
|
---|
3843 | * Save the search so we can resume it...
|
---|
3844 | */
|
---|
3845 | if (pDbgc->abSearch != pabBytes)
|
---|
3846 | {
|
---|
3847 | memcpy(pDbgc->abSearch, pabBytes, cbBytes);
|
---|
3848 | pDbgc->cbSearch = cbBytes;
|
---|
3849 | pDbgc->cbSearchUnit = cbUnit;
|
---|
3850 | }
|
---|
3851 | pDbgc->cMaxSearchHits = cMaxHits;
|
---|
3852 | pDbgc->SearchAddr = *pAddress;
|
---|
3853 | pDbgc->cbSearchRange = cbRange;
|
---|
3854 |
|
---|
3855 | return cHits ? VINF_SUCCESS : VERR_DBGC_COMMAND_FAILED;
|
---|
3856 | }
|
---|
3857 |
|
---|
3858 |
|
---|
3859 | /**
|
---|
3860 | * Resumes the previous search.
|
---|
3861 | *
|
---|
3862 | * @returns VBox status code.
|
---|
3863 | * @param pCmdHlp Pointer to the command helper functions.
|
---|
3864 | * @param pVM Pointer to the current VM (if any).
|
---|
3865 | * @param pResult Where to store the result of a function invocation.
|
---|
3866 | */
|
---|
3867 | static int dbgcCmdWorkerSearchMemResume(PDBGCCMDHLP pCmdHlp, PVM pVM, PDBGCVAR pResult)
|
---|
3868 | {
|
---|
3869 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3870 |
|
---|
3871 | /*
|
---|
3872 | * Make sure there is a previous command.
|
---|
3873 | */
|
---|
3874 | if (!pDbgc->cbSearch)
|
---|
3875 | {
|
---|
3876 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Error: No previous search\n");
|
---|
3877 | return VERR_DBGC_COMMAND_FAILED;
|
---|
3878 | }
|
---|
3879 |
|
---|
3880 | /*
|
---|
3881 | * Make range and address adjustments.
|
---|
3882 | */
|
---|
3883 | DBGFADDRESS Address = pDbgc->SearchAddr;
|
---|
3884 | if (Address.FlatPtr == ~(RTGCUINTPTR)0)
|
---|
3885 | {
|
---|
3886 | Address.FlatPtr -= Address.off;
|
---|
3887 | Address.off = 0;
|
---|
3888 | }
|
---|
3889 |
|
---|
3890 | RTGCUINTPTR cbRange = pDbgc->cbSearchRange;
|
---|
3891 | if (!cbRange)
|
---|
3892 | cbRange = ~(RTGCUINTPTR)0;
|
---|
3893 | if (Address.FlatPtr + cbRange < pDbgc->SearchAddr.FlatPtr)
|
---|
3894 | cbRange = ~(RTGCUINTPTR)0 - pDbgc->SearchAddr.FlatPtr + !!pDbgc->SearchAddr.FlatPtr;
|
---|
3895 |
|
---|
3896 | return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pVM, &Address, cbRange, pDbgc->abSearch, pDbgc->cbSearch,
|
---|
3897 | pDbgc->cbSearchUnit, pDbgc->cMaxSearchHits, pResult);
|
---|
3898 | }
|
---|
3899 |
|
---|
3900 |
|
---|
3901 | /**
|
---|
3902 | * Search memory, worker for the 's' and 's?' functions.
|
---|
3903 | *
|
---|
3904 | * @returns VBox status.
|
---|
3905 | * @param pCmdHlp Pointer to the command helper functions.
|
---|
3906 | * @param pVM Pointer to the current VM (if any).
|
---|
3907 | * @param pAddress Where to start searching. If no range, search till end of address space.
|
---|
3908 | * @param cMaxHits The maximum number of hits.
|
---|
3909 | * @param chType The search type.
|
---|
3910 | * @param paPatArgs The pattern variable array.
|
---|
3911 | * @param cPatArgs Number of pattern variables.
|
---|
3912 | * @param pResult Where to store the result of a function invocation.
|
---|
3913 | */
|
---|
3914 | static int dbgcCmdWorkerSearchMem(PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR pAddress, uint64_t cMaxHits, char chType,
|
---|
3915 | PCDBGCVAR paPatArgs, unsigned cPatArgs, PDBGCVAR pResult)
|
---|
3916 | {
|
---|
3917 | dbgcVarSetGCFlat(pResult, 0);
|
---|
3918 |
|
---|
3919 | /*
|
---|
3920 | * Convert the search pattern into bytes and DBGFR3MemScan can deal with.
|
---|
3921 | */
|
---|
3922 | uint32_t cbUnit;
|
---|
3923 | switch (chType)
|
---|
3924 | {
|
---|
3925 | case 'a':
|
---|
3926 | case 'b': cbUnit = 1; break;
|
---|
3927 | case 'u': cbUnit = 2 | RT_BIT_32(31); break;
|
---|
3928 | case 'w': cbUnit = 2; break;
|
---|
3929 | case 'd': cbUnit = 4; break;
|
---|
3930 | case 'q': cbUnit = 8; break;
|
---|
3931 | default:
|
---|
3932 | return pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "chType=%c\n", chType);
|
---|
3933 | }
|
---|
3934 | uint8_t abBytes[RT_SIZEOFMEMB(DBGC, abSearch)];
|
---|
3935 | uint32_t cbBytes = sizeof(abBytes);
|
---|
3936 | int rc = dbgcVarsToBytes(pCmdHlp, abBytes, &cbBytes, cbUnit, paPatArgs, cPatArgs);
|
---|
3937 | if (RT_FAILURE(rc))
|
---|
3938 | return VERR_DBGC_COMMAND_FAILED;
|
---|
3939 |
|
---|
3940 | /*
|
---|
3941 | * Make DBGF address and fix the range.
|
---|
3942 | */
|
---|
3943 | DBGFADDRESS Address;
|
---|
3944 | rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, pAddress, &Address);
|
---|
3945 | if (RT_FAILURE(rc))
|
---|
3946 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "VarToDbgfAddr(,%Dv,)\n", pAddress);
|
---|
3947 |
|
---|
3948 | RTGCUINTPTR cbRange;
|
---|
3949 | switch (pAddress->enmRangeType)
|
---|
3950 | {
|
---|
3951 | case DBGCVAR_RANGE_BYTES:
|
---|
3952 | cbRange = pAddress->u64Range;
|
---|
3953 | if (cbRange != pAddress->u64Range)
|
---|
3954 | cbRange = ~(RTGCUINTPTR)0;
|
---|
3955 | break;
|
---|
3956 |
|
---|
3957 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
3958 | cbRange = (RTGCUINTPTR)(pAddress->u64Range * cbUnit);
|
---|
3959 | if ( cbRange != pAddress->u64Range * cbUnit
|
---|
3960 | || cbRange < pAddress->u64Range)
|
---|
3961 | cbRange = ~(RTGCUINTPTR)0;
|
---|
3962 | break;
|
---|
3963 |
|
---|
3964 | default:
|
---|
3965 | cbRange = ~(RTGCUINTPTR)0;
|
---|
3966 | break;
|
---|
3967 | }
|
---|
3968 | if (Address.FlatPtr + cbRange < Address.FlatPtr)
|
---|
3969 | cbRange = ~(RTGCUINTPTR)0 - Address.FlatPtr + !!Address.FlatPtr;
|
---|
3970 |
|
---|
3971 | /*
|
---|
3972 | * Ok, do it.
|
---|
3973 | */
|
---|
3974 | return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pVM, &Address, cbRange, abBytes, cbBytes, cbUnit, cMaxHits, pResult);
|
---|
3975 | }
|
---|
3976 |
|
---|
3977 |
|
---|
3978 | /**
|
---|
3979 | * The 's' command.
|
---|
3980 | *
|
---|
3981 | * @returns VBox status.
|
---|
3982 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
3983 | * @param pCmdHlp Pointer to command helper functions.
|
---|
3984 | * @param pVM Pointer to the current VM (if any).
|
---|
3985 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
3986 | * @param cArgs Number of arguments in the array.
|
---|
3987 | */
|
---|
3988 | static DECLCALLBACK(int) dbgcCmdSearchMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
3989 | {
|
---|
3990 | /* check that the parser did what it's supposed to do. */
|
---|
3991 | //if ( cArgs <= 2
|
---|
3992 | // && paArgs[0].enmType != DBGCVAR_TYPE_STRING)
|
---|
3993 | // return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "parser error\n");
|
---|
3994 |
|
---|
3995 | /*
|
---|
3996 | * Repeat previous search?
|
---|
3997 | */
|
---|
3998 | if (cArgs == 0)
|
---|
3999 | return dbgcCmdWorkerSearchMemResume(pCmdHlp, pVM, pResult);
|
---|
4000 |
|
---|
4001 | /*
|
---|
4002 | * Parse arguments.
|
---|
4003 | */
|
---|
4004 |
|
---|
4005 | return -1;
|
---|
4006 | }
|
---|
4007 |
|
---|
4008 |
|
---|
4009 | /**
|
---|
4010 | * The 's?' command.
|
---|
4011 | *
|
---|
4012 | * @returns VBox status.
|
---|
4013 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
4014 | * @param pCmdHlp Pointer to command helper functions.
|
---|
4015 | * @param pVM Pointer to the current VM (if any).
|
---|
4016 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
4017 | * @param cArgs Number of arguments in the array.
|
---|
4018 | */
|
---|
4019 | static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
4020 | {
|
---|
4021 | /* check that the parser did what it's supposed to do. */
|
---|
4022 | if ( cArgs < 2
|
---|
4023 | || !DBGCVAR_ISGCPOINTER(paArgs[0].enmType))
|
---|
4024 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "parser error\n");
|
---|
4025 | return dbgcCmdWorkerSearchMem(pCmdHlp, pVM, &paArgs[0], pResult ? 1 : 25, pCmd->pszCmd[1], paArgs + 1, cArgs - 1, pResult);
|
---|
4026 | }
|
---|
4027 |
|
---|
4028 |
|
---|
4029 | /**
|
---|
4030 | * List near symbol.
|
---|
4031 | *
|
---|
4032 | * @returns VBox status code.
|
---|
4033 | * @param pCmdHlp Pointer to command helper functions.
|
---|
4034 | * @param pVM Pointer to the current VM (if any).
|
---|
4035 | * @param pArg Pointer to the address or symbol to lookup.
|
---|
4036 | */
|
---|
4037 | static int dbgcDoListNear(PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR pArg, PDBGCVAR pResult)
|
---|
4038 | {
|
---|
4039 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
4040 | dbgcVarSetGCFlat(pResult, 0);
|
---|
4041 |
|
---|
4042 | RTDBGSYMBOL Symbol;
|
---|
4043 | int rc;
|
---|
4044 | if (pArg->enmType == DBGCVAR_TYPE_SYMBOL)
|
---|
4045 | {
|
---|
4046 | /*
|
---|
4047 | * Lookup the symbol address.
|
---|
4048 | */
|
---|
4049 | rc = DBGFR3AsSymbolByName(pVM, pDbgc->hDbgAs, pArg->u.pszString, &Symbol, NULL);
|
---|
4050 | if (RT_FAILURE(rc))
|
---|
4051 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3AsSymbolByName(,,%s,)\n", pArg->u.pszString);
|
---|
4052 |
|
---|
4053 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%Rptr %s\n", Symbol.Value, Symbol.szName);
|
---|
4054 | dbgcVarSetGCFlatByteRange(pResult, Symbol.Value, Symbol.cb);
|
---|
4055 | }
|
---|
4056 | else
|
---|
4057 | {
|
---|
4058 | /*
|
---|
4059 | * Convert it to a flat GC address and lookup that address.
|
---|
4060 | */
|
---|
4061 | DBGCVAR AddrVar;
|
---|
4062 | rc = DBGCCmdHlpEval(pCmdHlp, &AddrVar, "%%(%DV)", pArg);
|
---|
4063 | if (RT_FAILURE(rc))
|
---|
4064 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "%%(%DV)\n", pArg);
|
---|
4065 |
|
---|
4066 | dbgcVarSetVar(pResult, &AddrVar);
|
---|
4067 |
|
---|
4068 | RTINTPTR offDisp;
|
---|
4069 | DBGFADDRESS Addr;
|
---|
4070 | rc = DBGFR3AsSymbolByAddr(pVM, pDbgc->hDbgAs, DBGFR3AddrFromFlat(pVM, &Addr, AddrVar.u.GCFlat), &offDisp, &Symbol, NULL);
|
---|
4071 | if (RT_FAILURE(rc))
|
---|
4072 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3ASymbolByAddr(,,%RGv,,)\n", AddrVar.u.GCFlat);
|
---|
4073 |
|
---|
4074 | if (!offDisp)
|
---|
4075 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV %s", &AddrVar, Symbol.szName);
|
---|
4076 | else if (offDisp > 0)
|
---|
4077 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV %s + %RGv", &AddrVar, Symbol.szName, offDisp);
|
---|
4078 | else
|
---|
4079 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV %s - %RGv", &AddrVar, Symbol.szName, -offDisp);
|
---|
4080 | if ((RTGCINTPTR)Symbol.cb > -offDisp)
|
---|
4081 | {
|
---|
4082 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " LB %RGv\n", Symbol.cb + offDisp);
|
---|
4083 | dbgcVarSetByteRange(pResult, Symbol.cb + offDisp);
|
---|
4084 | }
|
---|
4085 | else
|
---|
4086 | {
|
---|
4087 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
|
---|
4088 | dbgcVarSetNoRange(pResult);
|
---|
4089 | }
|
---|
4090 | }
|
---|
4091 |
|
---|
4092 | return rc;
|
---|
4093 | }
|
---|
4094 |
|
---|
4095 |
|
---|
4096 | /**
|
---|
4097 | * The 'ln' (listnear) command.
|
---|
4098 | *
|
---|
4099 | * @returns VBox status.
|
---|
4100 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
4101 | * @param pCmdHlp Pointer to command helper functions.
|
---|
4102 | * @param pVM Pointer to the current VM (if any).
|
---|
4103 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
4104 | * @param cArgs Number of arguments in the array.
|
---|
4105 | */
|
---|
4106 | static DECLCALLBACK(int) dbgcCmdListNear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
4107 | {
|
---|
4108 | dbgcVarSetGCFlat(pResult, 0);
|
---|
4109 | if (!cArgs)
|
---|
4110 | {
|
---|
4111 | /*
|
---|
4112 | * Current cs:eip symbol.
|
---|
4113 | */
|
---|
4114 | DBGCVAR AddrVar;
|
---|
4115 | int rc = DBGCCmdHlpEval(pCmdHlp, &AddrVar, "%%(cs:eip)");
|
---|
4116 | if (RT_FAILURE(rc))
|
---|
4117 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "%%(cs:eip)\n");
|
---|
4118 | return dbgcDoListNear(pCmdHlp, pVM, &AddrVar, pResult);
|
---|
4119 | }
|
---|
4120 |
|
---|
4121 | /** @todo Fix the darn parser, it's resolving symbols specified as arguments before we get in here. */
|
---|
4122 | /*
|
---|
4123 | * Iterate arguments.
|
---|
4124 | */
|
---|
4125 | for (unsigned iArg = 0; iArg < cArgs; iArg++)
|
---|
4126 | {
|
---|
4127 | int rc = dbgcDoListNear(pCmdHlp, pVM, &paArgs[iArg], pResult);
|
---|
4128 | if (RT_FAILURE(rc))
|
---|
4129 | return rc;
|
---|
4130 | }
|
---|
4131 |
|
---|
4132 | NOREF(pCmd); NOREF(pResult);
|
---|
4133 | return VINF_SUCCESS;
|
---|
4134 | }
|
---|
4135 |
|
---|
4136 |
|
---|
4137 | /**
|
---|
4138 | * Matches the module patters against a module name.
|
---|
4139 | *
|
---|
4140 | * @returns true if matching, otherwise false.
|
---|
4141 | * @param pszName The module name.
|
---|
4142 | * @param paArgs The module pattern argument list.
|
---|
4143 | * @param cArgs Number of arguments.
|
---|
4144 | */
|
---|
4145 | static bool dbgcCmdListModuleMatch(const char *pszName, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
4146 | {
|
---|
4147 | for (uint32_t i = 0; i < cArgs; i++)
|
---|
4148 | if (RTStrSimplePatternMatch(paArgs[i].u.pszString, pszName))
|
---|
4149 | return true;
|
---|
4150 | return false;
|
---|
4151 | }
|
---|
4152 |
|
---|
4153 |
|
---|
4154 | /**
|
---|
4155 | * The 'ln' (listnear) command.
|
---|
4156 | *
|
---|
4157 | * @returns VBox status.
|
---|
4158 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
4159 | * @param pCmdHlp Pointer to command helper functions.
|
---|
4160 | * @param pVM Pointer to the current VM (if any).
|
---|
4161 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
4162 | * @param cArgs Number of arguments in the array.
|
---|
4163 | */
|
---|
4164 | static DECLCALLBACK(int) dbgcCmdListModules(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
|
---|
4165 | {
|
---|
4166 | bool const fMappings = pCmd->pszCmd[2] == 'o';
|
---|
4167 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
4168 |
|
---|
4169 | /*
|
---|
4170 | * Iterate the modules in the current address space and print info about
|
---|
4171 | * those matching the input.
|
---|
4172 | */
|
---|
4173 | RTDBGAS hAs = DBGFR3AsResolveAndRetain(pVM, pDbgc->hDbgAs);
|
---|
4174 | uint32_t cMods = RTDbgAsModuleCount(hAs);
|
---|
4175 | for (uint32_t iMod = 0; iMod < cMods; iMod++)
|
---|
4176 | {
|
---|
4177 | RTDBGMOD hMod = RTDbgAsModuleByIndex(hAs, iMod);
|
---|
4178 | if (hMod != NIL_RTDBGMOD)
|
---|
4179 | {
|
---|
4180 | uint32_t const cSegs = RTDbgModSegmentCount(hMod);
|
---|
4181 | const char * const pszName = RTDbgModName(hMod);
|
---|
4182 | if ( cArgs == 0
|
---|
4183 | || dbgcCmdListModuleMatch(pszName, paArgs, cArgs))
|
---|
4184 | {
|
---|
4185 | /*
|
---|
4186 | * Find the mapping with the lower address, preferring a full
|
---|
4187 | * image mapping, for the main line.
|
---|
4188 | */
|
---|
4189 | RTDBGASMAPINFO aMappings[128];
|
---|
4190 | uint32_t cMappings = RT_ELEMENTS(aMappings);
|
---|
4191 | int rc = RTDbgAsModuleQueryMapByIndex(hAs, iMod, &aMappings[0], &cMappings, 0 /*fFlags*/);
|
---|
4192 | if (RT_SUCCESS(rc))
|
---|
4193 | {
|
---|
4194 | bool fFull = false;
|
---|
4195 | RTUINTPTR uMin = RTUINTPTR_MAX;
|
---|
4196 | for (uint32_t iMap = 0; iMap < cMappings; iMap++)
|
---|
4197 | if ( aMappings[iMap].Address < uMin
|
---|
4198 | && ( !fFull
|
---|
4199 | || aMappings[iMap].iSeg == NIL_RTDBGSEGIDX))
|
---|
4200 | uMin = aMappings[iMap].Address;
|
---|
4201 | DBGCCmdHlpPrintf(pCmdHlp, "%RGv %04x %s\n", (RTGCUINTPTR)uMin, cSegs, pszName);
|
---|
4202 |
|
---|
4203 | if (fMappings)
|
---|
4204 | {
|
---|
4205 | /* sort by address first - not very efficient. */
|
---|
4206 | for (uint32_t i = 0; i + 1 < cMappings; i++)
|
---|
4207 | for (uint32_t j = i + 1; j < cMappings; j++)
|
---|
4208 | if (aMappings[j].Address < aMappings[i].Address)
|
---|
4209 | {
|
---|
4210 | RTDBGASMAPINFO Tmp = aMappings[j];
|
---|
4211 | aMappings[j] = aMappings[i];
|
---|
4212 | aMappings[i] = Tmp;
|
---|
4213 | }
|
---|
4214 |
|
---|
4215 | /* print */
|
---|
4216 | for (uint32_t iMap = 0; iMap < cMappings; iMap++)
|
---|
4217 | if (aMappings[iMap].iSeg != NIL_RTDBGSEGIDX)
|
---|
4218 | DBGCCmdHlpPrintf(pCmdHlp, " %RGv %RGv #%02x %s\n",
|
---|
4219 | (RTGCUINTPTR)aMappings[iMap].Address,
|
---|
4220 | (RTGCUINTPTR)RTDbgModSegmentSize(hMod, aMappings[iMap].iSeg),
|
---|
4221 | aMappings[iMap].iSeg,
|
---|
4222 | /** @todo RTDbgModSegmentName(hMod, aMappings[iMap].iSeg)*/ "noname");
|
---|
4223 | else
|
---|
4224 | DBGCCmdHlpPrintf(pCmdHlp, " %RGv %RGv <everything>\n",
|
---|
4225 | (RTGCUINTPTR)aMappings[iMap].Address,
|
---|
4226 | (RTGCUINTPTR)RTDbgModImageSize(hMod));
|
---|
4227 | }
|
---|
4228 | }
|
---|
4229 | else
|
---|
4230 | DBGCCmdHlpPrintf(pCmdHlp, "%.*s %04x %s (rc=%Rrc)\n",
|
---|
4231 | sizeof(RTGCPTR) * 2, "???????????", cSegs, pszName, rc);
|
---|
4232 | /** @todo missing address space API for enumerating the mappings. */
|
---|
4233 | }
|
---|
4234 | RTDbgModRelease(hMod);
|
---|
4235 | }
|
---|
4236 | }
|
---|
4237 | RTDbgAsRelease(hAs);
|
---|
4238 |
|
---|
4239 | NOREF(pCmd); NOREF(pResult);
|
---|
4240 | return VINF_SUCCESS;
|
---|
4241 | }
|
---|