VirtualBox

source: vbox/trunk/src/VBox/Debugger/DBGCBuiltInSymbols.cpp@ 31512

Last change on this file since 31512 was 31510, checked in by vboxsync, 14 years ago

The debugger is back in the OSE.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette