1 | /** $Id: DBGCBuiltInSymbols.cpp 9270 2008-05-31 14:53:45Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGC - Debugger Console, Built-In Symbols.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*******************************************************************************
|
---|
23 | * Header Files *
|
---|
24 | *******************************************************************************/
|
---|
25 | #define LOG_GROUP LOG_GROUP_DBGC
|
---|
26 | #include <VBox/dbg.h>
|
---|
27 | #include <VBox/dbgf.h>
|
---|
28 | #include <VBox/vm.h>
|
---|
29 | #include <VBox/vmm.h>
|
---|
30 | #include <VBox/mm.h>
|
---|
31 | #include <VBox/pgm.h>
|
---|
32 | #include <VBox/selm.h>
|
---|
33 | #include <VBox/dis.h>
|
---|
34 | #include <VBox/param.h>
|
---|
35 | #include <VBox/err.h>
|
---|
36 | #include <VBox/log.h>
|
---|
37 |
|
---|
38 | #include <iprt/alloc.h>
|
---|
39 | #include <iprt/alloca.h>
|
---|
40 | #include <iprt/string.h>
|
---|
41 | #include <iprt/assert.h>
|
---|
42 | #include <iprt/ctype.h>
|
---|
43 |
|
---|
44 | #include <stdlib.h>
|
---|
45 | #include <stdio.h>
|
---|
46 |
|
---|
47 | #include "DBGCInternal.h"
|
---|
48 |
|
---|
49 |
|
---|
50 | /*******************************************************************************
|
---|
51 | * Internal Functions *
|
---|
52 | *******************************************************************************/
|
---|
53 | static DECLCALLBACK(int) dbgcSymGetReg(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, DBGCVARTYPE enmType, PDBGCVAR pResult);
|
---|
54 | static DECLCALLBACK(int) dbgcSymSetReg(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, PCDBGCVAR pValue);
|
---|
55 |
|
---|
56 |
|
---|
57 | /*******************************************************************************
|
---|
58 | * Global Variables *
|
---|
59 | *******************************************************************************/
|
---|
60 | /** Register symbol uUser value.
|
---|
61 | * @{
|
---|
62 | */
|
---|
63 | /** If set the register set is the hypervisor and not the guest one. */
|
---|
64 | #define SYMREG_FLAGS_HYPER RT_BIT(20)
|
---|
65 | /** If set a far conversion of the value will use the high 16 bit for the selector.
|
---|
66 | * If clear the low 16 bit will be used. */
|
---|
67 | #define SYMREG_FLAGS_HIGH_SEL RT_BIT(21)
|
---|
68 | /** The shift value to calc the size of a register symbol from the uUser value. */
|
---|
69 | #define SYMREG_SIZE_SHIFT (24)
|
---|
70 | /** Get the offset */
|
---|
71 | #define SYMREG_OFFSET(uUser) (uUser & ((1 << 20) - 1))
|
---|
72 | /** Get the size. */
|
---|
73 | #define SYMREG_SIZE(uUser) ((uUser >> SYMREG_SIZE_SHIFT) & 0xff)
|
---|
74 | /** 1 byte. */
|
---|
75 | #define SYMREG_SIZE_1 ( 1 << SYMREG_SIZE_SHIFT)
|
---|
76 | /** 2 byte. */
|
---|
77 | #define SYMREG_SIZE_2 ( 2 << SYMREG_SIZE_SHIFT)
|
---|
78 | /** 4 byte. */
|
---|
79 | #define SYMREG_SIZE_4 ( 4 << SYMREG_SIZE_SHIFT)
|
---|
80 | /** 6 byte. */
|
---|
81 | #define SYMREG_SIZE_6 ( 6 << SYMREG_SIZE_SHIFT)
|
---|
82 | /** 8 byte. */
|
---|
83 | #define SYMREG_SIZE_8 ( 8 << SYMREG_SIZE_SHIFT)
|
---|
84 | /** 12 byte. */
|
---|
85 | #define SYMREG_SIZE_12 (12 << SYMREG_SIZE_SHIFT)
|
---|
86 | /** 16 byte. */
|
---|
87 | #define SYMREG_SIZE_16 (16 << SYMREG_SIZE_SHIFT)
|
---|
88 | /** @} */
|
---|
89 |
|
---|
90 | /** Builtin Symbols.
|
---|
91 | * ASSUMES little endian register representation!
|
---|
92 | */
|
---|
93 | static const DBGCSYM g_aSyms[] =
|
---|
94 | {
|
---|
95 | { "eax", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eax) | SYMREG_SIZE_4 },
|
---|
96 | { "ax", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eax) | SYMREG_SIZE_2 },
|
---|
97 | { "al", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eax) | SYMREG_SIZE_1 },
|
---|
98 | { "ah", dbgcSymGetReg, dbgcSymSetReg, (offsetof(CPUMCTX, eax) + 1)| SYMREG_SIZE_1 },
|
---|
99 |
|
---|
100 | { "ebx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ebx) | SYMREG_SIZE_4 },
|
---|
101 | { "bx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ebx) | SYMREG_SIZE_2 },
|
---|
102 | { "bl", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ebx) | SYMREG_SIZE_1 },
|
---|
103 | { "bh", dbgcSymGetReg, dbgcSymSetReg, (offsetof(CPUMCTX, ebx) + 1)| SYMREG_SIZE_1 },
|
---|
104 |
|
---|
105 | { "ecx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ecx) | SYMREG_SIZE_4 },
|
---|
106 | { "cx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ecx) | SYMREG_SIZE_2 },
|
---|
107 | { "cl", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ecx) | SYMREG_SIZE_1 },
|
---|
108 | { "ch", dbgcSymGetReg, dbgcSymSetReg, (offsetof(CPUMCTX, ecx) + 1)| SYMREG_SIZE_1 },
|
---|
109 |
|
---|
110 | { "edx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, edx) | SYMREG_SIZE_4 },
|
---|
111 | { "dx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, edx) | SYMREG_SIZE_2 },
|
---|
112 | { "dl", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, edx) | SYMREG_SIZE_1 },
|
---|
113 | { "dh", dbgcSymGetReg, dbgcSymSetReg, (offsetof(CPUMCTX, edx) + 1)| SYMREG_SIZE_1 },
|
---|
114 |
|
---|
115 | { "edi", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, edi) | SYMREG_SIZE_4 },
|
---|
116 | { "di", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, edi) | SYMREG_SIZE_2 },
|
---|
117 |
|
---|
118 | { "esi", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, esi) | SYMREG_SIZE_4 },
|
---|
119 | { "si", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, esi) | SYMREG_SIZE_2 },
|
---|
120 |
|
---|
121 | { "ebp", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ebp) | SYMREG_SIZE_4 },
|
---|
122 | { "bp", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ebp) | SYMREG_SIZE_2 },
|
---|
123 |
|
---|
124 | { "esp", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, esp) | SYMREG_SIZE_4 },
|
---|
125 | { "sp", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, esp) | SYMREG_SIZE_2 },
|
---|
126 |
|
---|
127 | { "eip", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eip) | SYMREG_SIZE_4 },
|
---|
128 | { "ip", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eip) | SYMREG_SIZE_2 },
|
---|
129 |
|
---|
130 | { "efl", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eflags) | SYMREG_SIZE_4 },
|
---|
131 | { "eflags", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eflags) | SYMREG_SIZE_4 },
|
---|
132 | { "fl", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eflags) | SYMREG_SIZE_2 },
|
---|
133 | { "flags", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eflags) | SYMREG_SIZE_2 },
|
---|
134 |
|
---|
135 | { "cs", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, cs) | SYMREG_SIZE_2 },
|
---|
136 | { "ds", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ds) | SYMREG_SIZE_2 },
|
---|
137 | { "es", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, es) | SYMREG_SIZE_2 },
|
---|
138 | { "fs", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, fs) | SYMREG_SIZE_2 },
|
---|
139 | { "gs", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, gs) | SYMREG_SIZE_2 },
|
---|
140 | { "ss", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ss) | SYMREG_SIZE_2 },
|
---|
141 |
|
---|
142 | { "cr0", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, cr0) | SYMREG_SIZE_4 },
|
---|
143 | { "cr2", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, cr2) | SYMREG_SIZE_4 },
|
---|
144 | { "cr3", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, cr3) | SYMREG_SIZE_4 },
|
---|
145 | { "cr4", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, cr4) | SYMREG_SIZE_4 },
|
---|
146 |
|
---|
147 | { "tr", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, tr) | SYMREG_SIZE_2 },
|
---|
148 | { "ldtr", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ldtr) | SYMREG_SIZE_2 },
|
---|
149 |
|
---|
150 | { "gdtr", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, gdtr) | SYMREG_SIZE_6 },
|
---|
151 | { "gdtr.limit", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, gdtr.cbGdt)| SYMREG_SIZE_2 },
|
---|
152 | { "gdtr.base", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, gdtr.pGdt)| SYMREG_SIZE_4 },
|
---|
153 |
|
---|
154 | { "idtr", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, idtr) | SYMREG_SIZE_6 },
|
---|
155 | { "idtr.limit", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, idtr.cbIdt)| SYMREG_SIZE_2 },
|
---|
156 | { "idtr.base", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, idtr.pIdt)| SYMREG_SIZE_4 },
|
---|
157 |
|
---|
158 | /* hypervisor */
|
---|
159 |
|
---|
160 | {".eax", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eax) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
161 | {".ax", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eax) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
162 | {".al", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eax) | SYMREG_SIZE_1 | SYMREG_FLAGS_HYPER },
|
---|
163 | {".ah", dbgcSymGetReg, dbgcSymSetReg, (offsetof(CPUMCTX, eax) + 1)| SYMREG_SIZE_1 | SYMREG_FLAGS_HYPER },
|
---|
164 |
|
---|
165 | {".ebx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ebx) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
166 | {".bx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ebx) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
167 | {".bl", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ebx) | SYMREG_SIZE_1 | SYMREG_FLAGS_HYPER },
|
---|
168 | {".bh", dbgcSymGetReg, dbgcSymSetReg, (offsetof(CPUMCTX, ebx) + 1)| SYMREG_SIZE_1 | SYMREG_FLAGS_HYPER },
|
---|
169 |
|
---|
170 | {".ecx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ecx) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
171 | {".cx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ecx) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
172 | {".cl", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ecx) | SYMREG_SIZE_1 | SYMREG_FLAGS_HYPER },
|
---|
173 | {".ch", dbgcSymGetReg, dbgcSymSetReg, (offsetof(CPUMCTX, ecx) + 1)| SYMREG_SIZE_1 | SYMREG_FLAGS_HYPER },
|
---|
174 |
|
---|
175 | {".edx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, edx) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
176 | {".dx", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, edx) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
177 | {".dl", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, edx) | SYMREG_SIZE_1 | SYMREG_FLAGS_HYPER },
|
---|
178 | {".dh", dbgcSymGetReg, dbgcSymSetReg, (offsetof(CPUMCTX, edx) + 1)| SYMREG_SIZE_1 | SYMREG_FLAGS_HYPER },
|
---|
179 |
|
---|
180 | {".edi", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, edi) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
181 | {".di", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, edi) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
182 |
|
---|
183 | {".esi", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, esi) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
184 | {".si", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, esi) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
185 |
|
---|
186 | {".ebp", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ebp) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
187 | {".bp", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ebp) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
188 |
|
---|
189 | {".esp", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, esp) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
190 | {".sp", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, esp) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
191 |
|
---|
192 | {".eip", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eip) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
193 | {".ip", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eip) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
194 |
|
---|
195 | {".efl", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eflags) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
196 | {".eflags", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eflags) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
197 | {".fl", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eflags) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
198 | {".flags", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, eflags) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
199 |
|
---|
200 | {".cs", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, cs) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
201 | {".ds", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ds) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
202 | {".es", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, es) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
203 | {".fs", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, fs) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
204 | {".gs", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, gs) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
205 | {".ss", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ss) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
206 |
|
---|
207 | {".cr0", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, cr0) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
208 | {".cr2", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, cr2) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
209 | {".cr3", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, cr3) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
210 | {".cr4", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, cr4) | SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
211 |
|
---|
212 | {".tr", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, tr) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
213 | {".ldtr", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, ldtr) | SYMREG_SIZE_2 | SYMREG_FLAGS_HYPER },
|
---|
214 |
|
---|
215 | {".gdtr", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, gdtr) | SYMREG_SIZE_6 | SYMREG_FLAGS_HYPER },
|
---|
216 | {".gdtr.limit", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, gdtr.cbGdt)| SYMREG_SIZE_2| SYMREG_FLAGS_HYPER },
|
---|
217 | {".gdtr.base", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, gdtr.pGdt)| SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
218 |
|
---|
219 | {".idtr", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, idtr) | SYMREG_SIZE_6 | SYMREG_FLAGS_HYPER },
|
---|
220 | {".idtr.limit", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, idtr.cbIdt)| SYMREG_SIZE_2| SYMREG_FLAGS_HYPER },
|
---|
221 | {".idtr.base", dbgcSymGetReg, dbgcSymSetReg, offsetof(CPUMCTX, idtr.pIdt)| SYMREG_SIZE_4 | SYMREG_FLAGS_HYPER },
|
---|
222 |
|
---|
223 | };
|
---|
224 |
|
---|
225 |
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Get builtin register symbol.
|
---|
229 | *
|
---|
230 | * The uUser is special for these symbol descriptors. See the SYMREG_* \#defines.
|
---|
231 | *
|
---|
232 | * @returns 0 on success.
|
---|
233 | * @returns VBox evaluation / parsing error code on failure.
|
---|
234 | * The caller does the bitching.
|
---|
235 | * @param pSymDesc Pointer to the symbol descriptor.
|
---|
236 | * @param pCmdHlp Pointer to the command callback structure.
|
---|
237 | * @param enmType The result type.
|
---|
238 | * @param pResult Where to store the result.
|
---|
239 | */
|
---|
240 | static DECLCALLBACK(int) dbgcSymGetReg(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, DBGCVARTYPE enmType, PDBGCVAR pResult)
|
---|
241 | {
|
---|
242 | LogFlow(("dbgcSymSetReg: pSymDesc->pszName=%d\n", pSymDesc->pszName));
|
---|
243 |
|
---|
244 | /*
|
---|
245 | * pVM is required.
|
---|
246 | */
|
---|
247 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
248 | Assert(pDbgc->pVM);
|
---|
249 |
|
---|
250 | /*
|
---|
251 | * Get the right CPU context.
|
---|
252 | */
|
---|
253 | PCPUMCTX pCtx;
|
---|
254 | int rc;
|
---|
255 | if (!(pSymDesc->uUser & SYMREG_FLAGS_HYPER))
|
---|
256 | rc = CPUMQueryGuestCtxPtr(pDbgc->pVM, &pCtx);
|
---|
257 | else
|
---|
258 | rc = CPUMQueryHyperCtxPtr(pDbgc->pVM, &pCtx);
|
---|
259 | if (VBOX_FAILURE(rc))
|
---|
260 | return rc;
|
---|
261 |
|
---|
262 | /*
|
---|
263 | * Get the value.
|
---|
264 | */
|
---|
265 | void *pvValue = (char *)pCtx + SYMREG_OFFSET(pSymDesc->uUser);
|
---|
266 | uint64_t u64;
|
---|
267 | switch (SYMREG_SIZE(pSymDesc->uUser))
|
---|
268 | {
|
---|
269 | case 1: u64 = *(uint8_t *)pvValue; break;
|
---|
270 | case 2: u64 = *(uint16_t *)pvValue; break;
|
---|
271 | case 4: u64 = *(uint32_t *)pvValue; break;
|
---|
272 | case 6: u64 = *(uint32_t *)pvValue | ((uint64_t)*(uint16_t *)((char *)pvValue + sizeof(uint32_t)) << 32); break;
|
---|
273 | case 8: u64 = *(uint64_t *)pvValue; break;
|
---|
274 | default:
|
---|
275 | return VERR_PARSE_NOT_IMPLEMENTED;
|
---|
276 | }
|
---|
277 |
|
---|
278 | /*
|
---|
279 | * Construct the desired result.
|
---|
280 | */
|
---|
281 | if (enmType == DBGCVAR_TYPE_ANY)
|
---|
282 | enmType = DBGCVAR_TYPE_NUMBER;
|
---|
283 | pResult->pDesc = NULL;
|
---|
284 | pResult->pNext = NULL;
|
---|
285 | pResult->enmType = enmType;
|
---|
286 | pResult->enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
287 | pResult->u64Range = 0;
|
---|
288 |
|
---|
289 | switch (enmType)
|
---|
290 | {
|
---|
291 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
292 | pResult->u.GCFlat = (RTGCPTR)u64;
|
---|
293 | break;
|
---|
294 |
|
---|
295 | case DBGCVAR_TYPE_GC_FAR:
|
---|
296 | switch (SYMREG_SIZE(pSymDesc->uUser))
|
---|
297 | {
|
---|
298 | case 4:
|
---|
299 | if (!(pSymDesc->uUser & SYMREG_FLAGS_HIGH_SEL))
|
---|
300 | {
|
---|
301 | pResult->u.GCFar.off = (uint16_t)u64;
|
---|
302 | pResult->u.GCFar.sel = (uint16_t)(u64 >> 16);
|
---|
303 | }
|
---|
304 | else
|
---|
305 | {
|
---|
306 | pResult->u.GCFar.sel = (uint16_t)u64;
|
---|
307 | pResult->u.GCFar.off = (uint16_t)(u64 >> 16);
|
---|
308 | }
|
---|
309 | break;
|
---|
310 | case 6:
|
---|
311 | if (!(pSymDesc->uUser & SYMREG_FLAGS_HIGH_SEL))
|
---|
312 | {
|
---|
313 | pResult->u.GCFar.off = (uint32_t)u64;
|
---|
314 | pResult->u.GCFar.sel = (uint16_t)(u64 >> 32);
|
---|
315 | }
|
---|
316 | else
|
---|
317 | {
|
---|
318 | pResult->u.GCFar.sel = (uint32_t)u64;
|
---|
319 | pResult->u.GCFar.off = (uint16_t)(u64 >> 32);
|
---|
320 | }
|
---|
321 | break;
|
---|
322 |
|
---|
323 | default:
|
---|
324 | return VERR_PARSE_BAD_RESULT_TYPE;
|
---|
325 | }
|
---|
326 | break;
|
---|
327 |
|
---|
328 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
329 | pResult->u.GCPhys = (RTGCPHYS)u64;
|
---|
330 | break;
|
---|
331 |
|
---|
332 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
333 | pResult->u.pvHCFlat = (void *)(uintptr_t)u64;
|
---|
334 | break;
|
---|
335 |
|
---|
336 | case DBGCVAR_TYPE_HC_FAR:
|
---|
337 | switch (SYMREG_SIZE(pSymDesc->uUser))
|
---|
338 | {
|
---|
339 | case 4:
|
---|
340 | if (!(pSymDesc->uUser & SYMREG_FLAGS_HIGH_SEL))
|
---|
341 | {
|
---|
342 | pResult->u.HCFar.off = (uint16_t)u64;
|
---|
343 | pResult->u.HCFar.sel = (uint16_t)(u64 >> 16);
|
---|
344 | }
|
---|
345 | else
|
---|
346 | {
|
---|
347 | pResult->u.HCFar.sel = (uint16_t)u64;
|
---|
348 | pResult->u.HCFar.off = (uint16_t)(u64 >> 16);
|
---|
349 | }
|
---|
350 | break;
|
---|
351 | case 6:
|
---|
352 | if (!(pSymDesc->uUser & SYMREG_FLAGS_HIGH_SEL))
|
---|
353 | {
|
---|
354 | pResult->u.HCFar.off = (uint32_t)u64;
|
---|
355 | pResult->u.HCFar.sel = (uint16_t)(u64 >> 32);
|
---|
356 | }
|
---|
357 | else
|
---|
358 | {
|
---|
359 | pResult->u.HCFar.sel = (uint32_t)u64;
|
---|
360 | pResult->u.HCFar.off = (uint16_t)(u64 >> 32);
|
---|
361 | }
|
---|
362 | break;
|
---|
363 |
|
---|
364 | default:
|
---|
365 | return VERR_PARSE_BAD_RESULT_TYPE;
|
---|
366 | }
|
---|
367 | break;
|
---|
368 |
|
---|
369 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
370 | pResult->u.GCPhys = (RTGCPHYS)u64;
|
---|
371 | break;
|
---|
372 |
|
---|
373 | case DBGCVAR_TYPE_NUMBER:
|
---|
374 | pResult->u.u64Number = u64;
|
---|
375 | break;
|
---|
376 |
|
---|
377 | case DBGCVAR_TYPE_STRING:
|
---|
378 | case DBGCVAR_TYPE_UNKNOWN:
|
---|
379 | default:
|
---|
380 | return VERR_PARSE_BAD_RESULT_TYPE;
|
---|
381 |
|
---|
382 | }
|
---|
383 |
|
---|
384 | return 0;
|
---|
385 | }
|
---|
386 |
|
---|
387 |
|
---|
388 | /**
|
---|
389 | * Set builtin register symbol.
|
---|
390 | *
|
---|
391 | * The uUser is special for these symbol descriptors. See the SYMREG_* #defines.
|
---|
392 | *
|
---|
393 | * @returns 0 on success.
|
---|
394 | * @returns VBox evaluation / parsing error code on failure.
|
---|
395 | * The caller does the bitching.
|
---|
396 | * @param pSymDesc Pointer to the symbol descriptor.
|
---|
397 | * @param pCmdHlp Pointer to the command callback structure.
|
---|
398 | * @param pValue The value to assign the symbol.
|
---|
399 | */
|
---|
400 | static DECLCALLBACK(int) dbgcSymSetReg(PCDBGCSYM pSymDesc, PDBGCCMDHLP pCmdHlp, PCDBGCVAR pValue)
|
---|
401 | {
|
---|
402 | LogFlow(("dbgcSymSetReg: pSymDesc->pszName=%d\n", pSymDesc->pszName));
|
---|
403 |
|
---|
404 | /*
|
---|
405 | * pVM is required.
|
---|
406 | */
|
---|
407 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
408 | Assert(pDbgc->pVM);
|
---|
409 |
|
---|
410 | /*
|
---|
411 | * Get the right CPU context.
|
---|
412 | */
|
---|
413 | PCPUMCTX pCtx;
|
---|
414 | int rc;
|
---|
415 | if (!(pSymDesc->uUser & SYMREG_FLAGS_HYPER))
|
---|
416 | rc = CPUMQueryGuestCtxPtr(pDbgc->pVM, &pCtx);
|
---|
417 | else
|
---|
418 | rc = CPUMQueryHyperCtxPtr(pDbgc->pVM, &pCtx);
|
---|
419 | if (VBOX_FAILURE(rc))
|
---|
420 | return rc;
|
---|
421 |
|
---|
422 | /*
|
---|
423 | * Check the new value.
|
---|
424 | */
|
---|
425 | if (pValue->enmType != DBGCVAR_TYPE_NUMBER)
|
---|
426 | return VERR_PARSE_ARGUMENT_TYPE_MISMATCH;
|
---|
427 |
|
---|
428 | /*
|
---|
429 | * Set the value.
|
---|
430 | */
|
---|
431 | void *pvValue = (char *)pCtx + SYMREG_OFFSET(pSymDesc->uUser);
|
---|
432 | switch (SYMREG_SIZE(pSymDesc->uUser))
|
---|
433 | {
|
---|
434 | case 1:
|
---|
435 | *(uint8_t *)pvValue = (uint8_t)pValue->u.u64Number;
|
---|
436 | break;
|
---|
437 | case 2:
|
---|
438 | *(uint16_t *)pvValue = (uint16_t)pValue->u.u64Number;
|
---|
439 | break;
|
---|
440 | case 4:
|
---|
441 | *(uint32_t *)pvValue = (uint32_t)pValue->u.u64Number;
|
---|
442 | break;
|
---|
443 | case 6:
|
---|
444 | *(uint32_t *)pvValue = (uint32_t)pValue->u.u64Number;
|
---|
445 | ((uint16_t *)pvValue)[3] = (uint16_t)(pValue->u.u64Number >> 32);
|
---|
446 | break;
|
---|
447 | case 8:
|
---|
448 | *(uint64_t *)pvValue = pValue->u.u64Number;
|
---|
449 | break;
|
---|
450 | default:
|
---|
451 | return VERR_PARSE_NOT_IMPLEMENTED;
|
---|
452 | }
|
---|
453 |
|
---|
454 | return VINF_SUCCESS;
|
---|
455 | }
|
---|
456 |
|
---|
457 |
|
---|
458 | /**
|
---|
459 | * Finds a builtin symbol.
|
---|
460 | * @returns Pointer to symbol descriptor on success.
|
---|
461 | * @returns NULL on failure.
|
---|
462 | * @param pDbgc The debug console instance.
|
---|
463 | * @param pszSymbol The symbol name.
|
---|
464 | */
|
---|
465 | PCDBGCSYM dbgcLookupRegisterSymbol(PDBGC pDbgc, const char *pszSymbol)
|
---|
466 | {
|
---|
467 | for (unsigned iSym = 0; iSym < ELEMENTS(g_aSyms); iSym++)
|
---|
468 | if (!strcmp(pszSymbol, g_aSyms[iSym].pszName))
|
---|
469 | return &g_aSyms[iSym];
|
---|
470 |
|
---|
471 | /** @todo externally registered symbols. */
|
---|
472 | NOREF(pDbgc);
|
---|
473 | return NULL;
|
---|
474 | }
|
---|
475 |
|
---|