1 | /* $Id: DBGFInternal.h 87594 2021-02-03 20:23:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGF - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 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 | #ifndef VMM_INCLUDED_SRC_include_DBGFInternal_h
|
---|
19 | #define VMM_INCLUDED_SRC_include_DBGFInternal_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <VBox/cdefs.h>
|
---|
25 | #ifdef IN_RING3
|
---|
26 | # include <VBox/dis.h>
|
---|
27 | #endif
|
---|
28 | #include <VBox/types.h>
|
---|
29 | #include <iprt/semaphore.h>
|
---|
30 | #include <iprt/critsect.h>
|
---|
31 | #include <iprt/string.h>
|
---|
32 | #include <iprt/avl.h>
|
---|
33 | #include <iprt/dbg.h>
|
---|
34 | #include <iprt/tracelog.h>
|
---|
35 | #include <VBox/vmm/dbgf.h>
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 | /** @defgroup grp_dbgf_int Internals
|
---|
40 | * @ingroup grp_dbgf
|
---|
41 | * @internal
|
---|
42 | * @{
|
---|
43 | */
|
---|
44 |
|
---|
45 | /** The maximum tracer instance (total) size, ring-0/raw-mode capable tracers. */
|
---|
46 | #define DBGF_MAX_TRACER_INSTANCE_SIZE _512M
|
---|
47 | /** The maximum tracers instance (total) size, ring-3 only tracers. */
|
---|
48 | #define DBGF_MAX_TRACER_INSTANCE_SIZE_R3 _1G
|
---|
49 | /** Event ringbuffer header size. */
|
---|
50 | #define DBGF_TRACER_EVT_HDR_SZ (32)
|
---|
51 | /** Event ringbuffer payload size. */
|
---|
52 | #define DBGF_TRACER_EVT_PAYLOAD_SZ (32)
|
---|
53 | /** Event ringbuffer entry size. */
|
---|
54 | #define DBGF_TRACER_EVT_SZ (DBGF_TRACER_EVT_HDR_SZ + DBGF_TRACER_EVT_PAYLOAD_SZ)
|
---|
55 |
|
---|
56 |
|
---|
57 | /** @name Global breakpoint table handling defines.
|
---|
58 | * @{ */
|
---|
59 | /** Maximum number of breakpoint owners supported (power of two). */
|
---|
60 | #define DBGF_BP_OWNER_COUNT_MAX _32K
|
---|
61 | /** Maximum number of breakpoints supported (power of two). */
|
---|
62 | #define DBGF_BP_COUNT_MAX _1M
|
---|
63 | /** Size of a single breakpoint structure in bytes. */
|
---|
64 | #define DBGF_BP_ENTRY_SZ 64
|
---|
65 | /** Number of breakpoints handled in one chunk (power of two). */
|
---|
66 | #define DBGF_BP_COUNT_PER_CHUNK _64K
|
---|
67 | /** Number of chunks required to support all breakpoints. */
|
---|
68 | #define DBGF_BP_CHUNK_COUNT (DBGF_BP_COUNT_MAX / DBGF_BP_COUNT_PER_CHUNK)
|
---|
69 | /** Maximum number of instruction bytes when executing breakpointed instructions. */
|
---|
70 | #define DBGF_BP_INSN_MAX 16
|
---|
71 | /** @} */
|
---|
72 |
|
---|
73 | /** @name L2 lookup table limit defines.
|
---|
74 | * @{ */
|
---|
75 | /** Maximum number of entreis in the L2 lookup table. */
|
---|
76 | #define DBGF_BP_L2_TBL_ENTRY_COUNT_MAX _512K
|
---|
77 | /** Number of L2 entries handled in one chunk. */
|
---|
78 | #define DBGF_BP_L2_TBL_ENTRIES_PER_CHUNK _64K
|
---|
79 | /** Number of chunks required tp support all L2 lookup table entries. */
|
---|
80 | #define DBGF_BP_L2_TBL_CHUNK_COUNT (DBGF_BP_L2_TBL_ENTRY_COUNT_MAX / DBGF_BP_L2_TBL_ENTRIES_PER_CHUNK)
|
---|
81 | /** @} */
|
---|
82 |
|
---|
83 |
|
---|
84 | /*******************************************************************************
|
---|
85 | * Structures and Typedefs *
|
---|
86 | *******************************************************************************/
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Event entry types.
|
---|
90 | */
|
---|
91 | typedef enum DBGFTRACEREVT
|
---|
92 | {
|
---|
93 | /** Invalid type. */
|
---|
94 | DBGFTRACEREVT_INVALID = 0,
|
---|
95 | /** Register event source event. */
|
---|
96 | DBGFTRACEREVT_SRC_REGISTER,
|
---|
97 | /** Deregister event source event. */
|
---|
98 | DBGFTRACEREVT_SRC_DEREGISTER,
|
---|
99 | /** MMIO region create event. */
|
---|
100 | DBGFTRACEREVT_MMIO_REGION_CREATE,
|
---|
101 | /** MMIO map region event. */
|
---|
102 | DBGFTRACEREVT_MMIO_MAP,
|
---|
103 | /** MMIO unmap region event. */
|
---|
104 | DBGFTRACEREVT_MMIO_UNMAP,
|
---|
105 | /** MMIO read event. */
|
---|
106 | DBGFTRACEREVT_MMIO_READ,
|
---|
107 | /** MMIO write event. */
|
---|
108 | DBGFTRACEREVT_MMIO_WRITE,
|
---|
109 | /** MMIO fill event. */
|
---|
110 | DBGFTRACEREVT_MMIO_FILL,
|
---|
111 | /** I/O port region create event. */
|
---|
112 | DBGFTRACEREVT_IOPORT_REGION_CREATE,
|
---|
113 | /** I/O port map event. */
|
---|
114 | DBGFTRACEREVT_IOPORT_MAP,
|
---|
115 | /** I/O port unmap event. */
|
---|
116 | DBGFTRACEREVT_IOPORT_UNMAP,
|
---|
117 | /** I/O port read event. */
|
---|
118 | DBGFTRACEREVT_IOPORT_READ,
|
---|
119 | /** I/O port read string event. */
|
---|
120 | DBGFTRACEREVT_IOPORT_READ_STR,
|
---|
121 | /** I/O port write event. */
|
---|
122 | DBGFTRACEREVT_IOPORT_WRITE,
|
---|
123 | /** I/O port write string event. */
|
---|
124 | DBGFTRACEREVT_IOPORT_WRITE_STR,
|
---|
125 | /** IRQ event. */
|
---|
126 | DBGFTRACEREVT_IRQ,
|
---|
127 | /** I/O APIC MSI event. */
|
---|
128 | DBGFTRACEREVT_IOAPIC_MSI,
|
---|
129 | /** Read from guest physical memory. */
|
---|
130 | DBGFTRACEREVT_GCPHYS_READ,
|
---|
131 | /** Write to guest physical memory. */
|
---|
132 | DBGFTRACEREVT_GCPHYS_WRITE,
|
---|
133 | /** 32bit hack. */
|
---|
134 | DBGFTRACEREVT_32BIT_HACK
|
---|
135 | } DBGFTRACEREVT;
|
---|
136 | /** Pointer to a trace event entry type. */
|
---|
137 | typedef DBGFTRACEREVT *PDBGFTRACEREVT;
|
---|
138 |
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * MMIO region create event.
|
---|
142 | */
|
---|
143 | typedef struct DBGFTRACEREVTMMIOCREATE
|
---|
144 | {
|
---|
145 | /** Unique region handle for the event source. */
|
---|
146 | uint64_t hMmioRegion;
|
---|
147 | /** Size of the region in bytes. */
|
---|
148 | RTGCPHYS cbRegion;
|
---|
149 | /** IOM flags passed to the region. */
|
---|
150 | uint32_t fIomFlags;
|
---|
151 | /** The PCI region for a PCI device. */
|
---|
152 | uint32_t iPciRegion;
|
---|
153 | /** Padding to 32byte. */
|
---|
154 | uint64_t u64Pad0;
|
---|
155 | } DBGFTRACEREVTMMIOCREATE;
|
---|
156 | /** Pointer to a MMIO map event. */
|
---|
157 | typedef DBGFTRACEREVTMMIOCREATE *PDBGFTRACEREVTMMIOCREATE;
|
---|
158 | /** Pointer to a const MMIO map event. */
|
---|
159 | typedef const DBGFTRACEREVTMMIOCREATE *PCDBGFTRACEREVTMMIOCREATE;
|
---|
160 |
|
---|
161 | AssertCompileSize(DBGFTRACEREVTMMIOCREATE, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
162 |
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * MMIO region map event.
|
---|
166 | */
|
---|
167 | typedef struct DBGFTRACEREVTMMIOMAP
|
---|
168 | {
|
---|
169 | /** Unique region handle for the event source. */
|
---|
170 | uint64_t hMmioRegion;
|
---|
171 | /** The base guest physical address of the MMIO region. */
|
---|
172 | RTGCPHYS GCPhysMmioBase;
|
---|
173 | /** Padding to 32byte. */
|
---|
174 | uint64_t au64Pad0[2];
|
---|
175 | } DBGFTRACEREVTMMIOMAP;
|
---|
176 | /** Pointer to a MMIO map event. */
|
---|
177 | typedef DBGFTRACEREVTMMIOMAP *PDBGFTRACEREVTMMIOMAP;
|
---|
178 | /** Pointer to a const MMIO map event. */
|
---|
179 | typedef const DBGFTRACEREVTMMIOMAP *PCDBGFTRACEREVTMMIOMAP;
|
---|
180 |
|
---|
181 | AssertCompileSize(DBGFTRACEREVTMMIOMAP, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
182 |
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * MMIO region unmap event.
|
---|
186 | */
|
---|
187 | typedef struct DBGFTRACEREVTMMIOUNMAP
|
---|
188 | {
|
---|
189 | /** Unique region handle for the event source. */
|
---|
190 | uint64_t hMmioRegion;
|
---|
191 | /** Padding to 32byte. */
|
---|
192 | uint64_t au64Pad0[3];
|
---|
193 | } DBGFTRACEREVTMMIOUNMAP;
|
---|
194 | /** Pointer to a MMIO map event. */
|
---|
195 | typedef DBGFTRACEREVTMMIOUNMAP *PDBGFTRACEREVTMMIOUNMAP;
|
---|
196 | /** Pointer to a const MMIO map event. */
|
---|
197 | typedef const DBGFTRACEREVTMMIOUNMAP *PCDBGFTRACEREVTMMIOUNMAP;
|
---|
198 |
|
---|
199 | AssertCompileSize(DBGFTRACEREVTMMIOUNMAP, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
200 |
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * MMIO event.
|
---|
204 | */
|
---|
205 | typedef struct DBGFTRACEREVTMMIO
|
---|
206 | {
|
---|
207 | /** Unique region handle for the event source. */
|
---|
208 | uint64_t hMmioRegion;
|
---|
209 | /** Offset into the region the access happened. */
|
---|
210 | RTGCPHYS offMmio;
|
---|
211 | /** Number of bytes transfered (the direction is in the event header). */
|
---|
212 | uint64_t cbXfer;
|
---|
213 | /** The value transfered. */
|
---|
214 | uint64_t u64Val;
|
---|
215 | } DBGFTRACEREVTMMIO;
|
---|
216 | /** Pointer to a MMIO event. */
|
---|
217 | typedef DBGFTRACEREVTMMIO *PDBGFTRACEREVTMMIO;
|
---|
218 | /** Pointer to a const MMIO event. */
|
---|
219 | typedef const DBGFTRACEREVTMMIO *PCDBGFTRACEREVTMMIO;
|
---|
220 |
|
---|
221 | AssertCompileSize(DBGFTRACEREVTMMIO, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
222 |
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * MMIO fill event.
|
---|
226 | */
|
---|
227 | typedef struct DBGFTRACEREVTMMIOFILL
|
---|
228 | {
|
---|
229 | /** Unique region handle for the event source. */
|
---|
230 | uint64_t hMmioRegion;
|
---|
231 | /** Offset into the region the access happened. */
|
---|
232 | RTGCPHYS offMmio;
|
---|
233 | /** Item size in bytes. */
|
---|
234 | uint32_t cbItem;
|
---|
235 | /** Amount of items being filled. */
|
---|
236 | uint32_t cItems;
|
---|
237 | /** The fill value. */
|
---|
238 | uint32_t u32Item;
|
---|
239 | /** Padding to 32bytes. */
|
---|
240 | uint32_t u32Pad0;
|
---|
241 | } DBGFTRACEREVTMMIOFILL;
|
---|
242 | /** Pointer to a MMIO event. */
|
---|
243 | typedef DBGFTRACEREVTMMIOFILL *PDBGFTRACEREVTMMIOFILL;
|
---|
244 | /** Pointer to a const MMIO event. */
|
---|
245 | typedef const DBGFTRACEREVTMMIOFILL *PCDBGFTRACEREVTMMIOFILL;
|
---|
246 |
|
---|
247 | AssertCompileSize(DBGFTRACEREVTMMIOFILL, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
248 |
|
---|
249 |
|
---|
250 | /**
|
---|
251 | * I/O port region create event.
|
---|
252 | */
|
---|
253 | typedef struct DBGFTRACEREVTIOPORTCREATE
|
---|
254 | {
|
---|
255 | /** Unique I/O port region handle for the event source. */
|
---|
256 | uint64_t hIoPorts;
|
---|
257 | /** Number of ports. */
|
---|
258 | RTIOPORT cPorts;
|
---|
259 | /** Padding. */
|
---|
260 | uint16_t u16Pad0;
|
---|
261 | /** IOM flags passed to the region. */
|
---|
262 | uint32_t fIomFlags;
|
---|
263 | /** The PCI region for a PCI device. */
|
---|
264 | uint32_t iPciRegion;
|
---|
265 | /** Padding to 32byte. */
|
---|
266 | uint32_t u32Pad0[3];
|
---|
267 | } DBGFTRACEREVTIOPORTCREATE;
|
---|
268 | /** Pointer to a MMIO map event. */
|
---|
269 | typedef DBGFTRACEREVTIOPORTCREATE *PDBGFTRACEREVTIOPORTCREATE;
|
---|
270 | /** Pointer to a const MMIO map event. */
|
---|
271 | typedef const DBGFTRACEREVTIOPORTCREATE *PCDBGFTRACEREVTIOPORTCREATE;
|
---|
272 |
|
---|
273 | AssertCompileSize(DBGFTRACEREVTIOPORTCREATE, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
274 |
|
---|
275 |
|
---|
276 | /**
|
---|
277 | * I/O port region map event.
|
---|
278 | */
|
---|
279 | typedef struct DBGFTRACEREVTIOPORTMAP
|
---|
280 | {
|
---|
281 | /** Unique I/O port region handle for the event source. */
|
---|
282 | uint64_t hIoPorts;
|
---|
283 | /** The base I/O port for the region. */
|
---|
284 | RTIOPORT IoPortBase;
|
---|
285 | /** Padding to 32byte. */
|
---|
286 | uint16_t au16Pad0[11];
|
---|
287 | } DBGFTRACEREVTIOPORTMAP;
|
---|
288 | /** Pointer to a MMIO map event. */
|
---|
289 | typedef DBGFTRACEREVTIOPORTMAP *PDBGFTRACEREVTIOPORTMAP;
|
---|
290 | /** Pointer to a const MMIO map event. */
|
---|
291 | typedef const DBGFTRACEREVTIOPORTMAP *PCDBGFTRACEREVTIOPORTMAP;
|
---|
292 |
|
---|
293 | AssertCompileSize(DBGFTRACEREVTIOPORTMAP, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
294 |
|
---|
295 |
|
---|
296 | /**
|
---|
297 | * MMIO region unmap event.
|
---|
298 | */
|
---|
299 | typedef struct DBGFTRACEREVTIOPORTUNMAP
|
---|
300 | {
|
---|
301 | /** Unique region handle for the event source. */
|
---|
302 | uint64_t hIoPorts;
|
---|
303 | /** Padding to 32byte. */
|
---|
304 | uint64_t au64Pad0[3];
|
---|
305 | } DBGFTRACEREVTIOPORTUNMAP;
|
---|
306 | /** Pointer to a MMIO map event. */
|
---|
307 | typedef DBGFTRACEREVTIOPORTUNMAP *PDBGFTRACEREVTIOPORTUNMAP;
|
---|
308 | /** Pointer to a const MMIO map event. */
|
---|
309 | typedef const DBGFTRACEREVTIOPORTUNMAP *PCDBGFTRACEREVTIOPORTUNMAP;
|
---|
310 |
|
---|
311 | AssertCompileSize(DBGFTRACEREVTIOPORTUNMAP, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
312 |
|
---|
313 |
|
---|
314 | /**
|
---|
315 | * I/O port event.
|
---|
316 | */
|
---|
317 | typedef struct DBGFTRACEREVTIOPORT
|
---|
318 | {
|
---|
319 | /** Unique region handle for the event source. */
|
---|
320 | uint64_t hIoPorts;
|
---|
321 | /** Offset into the I/O port region. */
|
---|
322 | RTIOPORT offPort;
|
---|
323 | /** 8 byte alignment. */
|
---|
324 | uint8_t abPad0[6];
|
---|
325 | /** Number of bytes transfered (the direction is in the event header). */
|
---|
326 | uint64_t cbXfer;
|
---|
327 | /** The value transfered. */
|
---|
328 | uint32_t u32Val;
|
---|
329 | /** Padding to 32bytes. */
|
---|
330 | uint8_t abPad1[4];
|
---|
331 | } DBGFTRACEREVTIOPORT;
|
---|
332 | /** Pointer to a MMIO event. */
|
---|
333 | typedef DBGFTRACEREVTIOPORT *PDBGFTRACEREVTIOPORT;
|
---|
334 | /** Pointer to a const MMIO event. */
|
---|
335 | typedef const DBGFTRACEREVTIOPORT *PCDBGFTRACEREVTIOPORT;
|
---|
336 |
|
---|
337 | AssertCompileSize(DBGFTRACEREVTIOPORT, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
338 |
|
---|
339 |
|
---|
340 | /**
|
---|
341 | * I/O port string event.
|
---|
342 | */
|
---|
343 | typedef struct DBGFTRACEREVTIOPORTSTR
|
---|
344 | {
|
---|
345 | /** Unique region handle for the event source. */
|
---|
346 | uint64_t hIoPorts;
|
---|
347 | /** Item size in bytes. */
|
---|
348 | uint32_t cbItem;
|
---|
349 | /** Number of transfers requested - for writes this gives the amount of valid data following. */
|
---|
350 | uint32_t cTransfersReq;
|
---|
351 | /** Number of transfers done - for reads this gives the amount of valid data following. */
|
---|
352 | uint32_t cTransfersRet;
|
---|
353 | /** Offset into the I/O port region. */
|
---|
354 | RTIOPORT offPort;
|
---|
355 | /** Data being transfered. */
|
---|
356 | uint8_t abData[10];
|
---|
357 | } DBGFTRACEREVTIOPORTSTR;
|
---|
358 | /** Pointer to a MMIO event. */
|
---|
359 | typedef DBGFTRACEREVTIOPORTSTR *PDBGFTRACEREVTIOPORTSTR;
|
---|
360 | /** Pointer to a const MMIO event. */
|
---|
361 | typedef const DBGFTRACEREVTIOPORTSTR *PCDBGFTRACEREVTIOPORTSTR;
|
---|
362 |
|
---|
363 | AssertCompileSize(DBGFTRACEREVTIOPORTSTR, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
364 |
|
---|
365 |
|
---|
366 | /**
|
---|
367 | * IRQ event.
|
---|
368 | */
|
---|
369 | typedef struct DBGFTRACEREVTIRQ
|
---|
370 | {
|
---|
371 | /** The IRQ line. */
|
---|
372 | int32_t iIrq;
|
---|
373 | /** IRQ level flags. */
|
---|
374 | int32_t fIrqLvl;
|
---|
375 | /** Padding to 32bytes. */
|
---|
376 | uint32_t au32Pad0[6];
|
---|
377 | } DBGFTRACEREVTIRQ;
|
---|
378 | /** Pointer to a MMIO event. */
|
---|
379 | typedef DBGFTRACEREVTIRQ *PDBGFTRACEREVTIRQ;
|
---|
380 | /** Pointer to a const MMIO event. */
|
---|
381 | typedef const DBGFTRACEREVTIRQ *PCDBGFTRACEREVTIRQ;
|
---|
382 |
|
---|
383 | AssertCompileSize(DBGFTRACEREVTIRQ, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
384 |
|
---|
385 |
|
---|
386 | /**
|
---|
387 | * I/O APIC MSI event.
|
---|
388 | */
|
---|
389 | typedef struct DBGFTRACEREVTIOAPICMSI
|
---|
390 | {
|
---|
391 | /** The guest physical address being written. */
|
---|
392 | RTGCPHYS GCPhys;
|
---|
393 | /** The value being written. */
|
---|
394 | uint32_t u32Val;
|
---|
395 | /** Padding to 32bytes. */
|
---|
396 | uint32_t au32Pad0[5];
|
---|
397 | } DBGFTRACEREVTIOAPICMSI;
|
---|
398 | /** Pointer to a MMIO event. */
|
---|
399 | typedef DBGFTRACEREVTIOAPICMSI *PDBGFTRACEREVTIOAPICMSI;
|
---|
400 | /** Pointer to a const MMIO event. */
|
---|
401 | typedef const DBGFTRACEREVTIOAPICMSI *PCDBGFTRACEREVTIOAPICMSI;
|
---|
402 |
|
---|
403 | AssertCompileSize(DBGFTRACEREVTIOAPICMSI, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
404 |
|
---|
405 |
|
---|
406 | /**
|
---|
407 | * Guest physical memory transfer.
|
---|
408 | */
|
---|
409 | typedef struct DBGFTRACEREVTGCPHYS
|
---|
410 | {
|
---|
411 | /** Guest physical address of the access. */
|
---|
412 | RTGCPHYS GCPhys;
|
---|
413 | /** Number of bytes transfered (the direction is in the event header).
|
---|
414 | * If the number is small enough to fit into the remaining space of the entry
|
---|
415 | * it is stored here, otherwise it will be stored in the next entry (and following
|
---|
416 | * entries). */
|
---|
417 | uint64_t cbXfer;
|
---|
418 | /** Guest data being transfered. */
|
---|
419 | uint8_t abData[16];
|
---|
420 | } DBGFTRACEREVTGCPHYS;
|
---|
421 | /** Pointer to a guest physical memory transfer event. */
|
---|
422 | typedef DBGFTRACEREVTGCPHYS *PDBGFTRACEREVTGCPHYS;
|
---|
423 | /** Pointer to a const uest physical memory transfer event. */
|
---|
424 | typedef const DBGFTRACEREVTGCPHYS *PCDBGFTRACEREVTGCPHYS;
|
---|
425 |
|
---|
426 | AssertCompileSize(DBGFTRACEREVTGCPHYS, DBGF_TRACER_EVT_PAYLOAD_SZ);
|
---|
427 |
|
---|
428 |
|
---|
429 | /**
|
---|
430 | * A trace event header in the shared ring buffer.
|
---|
431 | */
|
---|
432 | typedef struct DBGFTRACEREVTHDR
|
---|
433 | {
|
---|
434 | /** Event ID. */
|
---|
435 | volatile uint64_t idEvt;
|
---|
436 | /** The previous event ID this one links to,
|
---|
437 | * DBGF_TRACER_EVT_HDR_ID_INVALID if it links to no other event. */
|
---|
438 | uint64_t idEvtPrev;
|
---|
439 | /** Event source. */
|
---|
440 | DBGFTRACEREVTSRC hEvtSrc;
|
---|
441 | /** The event entry type. */
|
---|
442 | DBGFTRACEREVT enmEvt;
|
---|
443 | /** Flags for this event. */
|
---|
444 | uint32_t fFlags;
|
---|
445 | } DBGFTRACEREVTHDR;
|
---|
446 | /** Pointer to a trace event header. */
|
---|
447 | typedef DBGFTRACEREVTHDR *PDBGFTRACEREVTHDR;
|
---|
448 | /** Pointer to a const trace event header. */
|
---|
449 | typedef const DBGFTRACEREVTHDR *PCDBGFTRACEREVTHDR;
|
---|
450 |
|
---|
451 | AssertCompileSize(DBGFTRACEREVTHDR, DBGF_TRACER_EVT_HDR_SZ);
|
---|
452 |
|
---|
453 | /** Invalid event ID, this is always set by the flush thread after processing one entry
|
---|
454 | * so the producers know when they are about to overwrite not yet processed entries in the ring buffer. */
|
---|
455 | #define DBGF_TRACER_EVT_HDR_ID_INVALID UINT64_C(0xffffffffffffffff)
|
---|
456 |
|
---|
457 | /** The event came from R0. */
|
---|
458 | #define DBGF_TRACER_EVT_HDR_F_R0 RT_BIT(0)
|
---|
459 |
|
---|
460 | /** Default event header tracer flags. */
|
---|
461 | #ifdef IN_RING0
|
---|
462 | # define DBGF_TRACER_EVT_HDR_F_DEFAULT DBGF_TRACER_EVT_HDR_F_R0
|
---|
463 | #else
|
---|
464 | # define DBGF_TRACER_EVT_HDR_F_DEFAULT (0)
|
---|
465 | #endif
|
---|
466 |
|
---|
467 |
|
---|
468 | /**
|
---|
469 | * Tracer instance data, shared structure.
|
---|
470 | */
|
---|
471 | typedef struct DBGFTRACERSHARED
|
---|
472 | {
|
---|
473 | /** The global event ID counter, monotonically increasing.
|
---|
474 | * Accessed by all threads causing a trace event. */
|
---|
475 | volatile uint64_t idEvt;
|
---|
476 | /** The SUP event semaphore for poking the flush thread. */
|
---|
477 | SUPSEMEVENT hSupSemEvtFlush;
|
---|
478 | /** Ring buffer size. */
|
---|
479 | size_t cbRingBuf;
|
---|
480 | /** Flag whether there are events in the ring buffer to get processed. */
|
---|
481 | volatile bool fEvtsWaiting;
|
---|
482 | /** Flag whether the flush thread is actively running or was kicked. */
|
---|
483 | volatile bool fFlushThrdActive;
|
---|
484 | /** Padding to a 64byte alignment. */
|
---|
485 | uint8_t abAlignment0[32];
|
---|
486 | } DBGFTRACERSHARED;
|
---|
487 | /** Pointer to the shared tarcer instance data. */
|
---|
488 | typedef DBGFTRACERSHARED *PDBGFTRACERSHARED;
|
---|
489 |
|
---|
490 | AssertCompileSizeAlignment(DBGFTRACERSHARED, 64);
|
---|
491 |
|
---|
492 |
|
---|
493 | /**
|
---|
494 | * Guest memory read/write data aggregation.
|
---|
495 | */
|
---|
496 | typedef struct DBGFTRACERGCPHYSRWAGG
|
---|
497 | {
|
---|
498 | /** The event ID which started the aggregation (used for the group ID when writing out the event). */
|
---|
499 | uint64_t idEvtStart;
|
---|
500 | /** The previous event ID used to link all the chunks together. */
|
---|
501 | uint64_t idEvtPrev;
|
---|
502 | /** Number of bytes being transfered. */
|
---|
503 | size_t cbXfer;
|
---|
504 | /** Amount of data left to aggregate before it can be written. */
|
---|
505 | size_t cbLeft;
|
---|
506 | /** Amount of bytes allocated. */
|
---|
507 | size_t cbBufMax;
|
---|
508 | /** Offset into the buffer to write next. */
|
---|
509 | size_t offBuf;
|
---|
510 | /** Pointer to the allocated buffer. */
|
---|
511 | uint8_t *pbBuf;
|
---|
512 | } DBGFTRACERGCPHYSRWAGG;
|
---|
513 | /** Pointer to a guest memory read/write data aggregation structure. */
|
---|
514 | typedef DBGFTRACERGCPHYSRWAGG *PDBGFTRACERGCPHYSRWAGG;
|
---|
515 |
|
---|
516 |
|
---|
517 | /**
|
---|
518 | * Tracer instance data, ring-3
|
---|
519 | */
|
---|
520 | typedef struct DBGFTRACERINSR3
|
---|
521 | {
|
---|
522 | /** Pointer to the next instance.
|
---|
523 | * (Head is pointed to by PDM::pTracerInstances.) */
|
---|
524 | R3PTRTYPE(struct DBGFTRACERINSR3 *) pNextR3;
|
---|
525 | /** R3 pointer to the VM this instance was created for. */
|
---|
526 | PVMR3 pVMR3;
|
---|
527 | /** Tracer instance number. */
|
---|
528 | uint32_t idTracer;
|
---|
529 | /** Flag whether the tracer has the R0 part enabled. */
|
---|
530 | bool fR0Enabled;
|
---|
531 | /** Flag whether the tracer flush thread should shut down. */
|
---|
532 | volatile bool fShutdown;
|
---|
533 | /** Padding. */
|
---|
534 | bool afPad0[6];
|
---|
535 | /** Next event source ID to return for a source registration. */
|
---|
536 | volatile DBGFTRACEREVTSRC hEvtSrcNext;
|
---|
537 | /** Pointer to the shared tracer instance data. */
|
---|
538 | R3PTRTYPE(PDBGFTRACERSHARED) pSharedR3;
|
---|
539 | /** The I/O thread writing the log from the shared event ringbuffer. */
|
---|
540 | RTTHREAD hThrdFlush;
|
---|
541 | /** Pointer to the start of the ring buffer. */
|
---|
542 | R3PTRTYPE(uint8_t *) pbRingBufR3;
|
---|
543 | /** The last processed event ID. */
|
---|
544 | uint64_t idEvtLast;
|
---|
545 | /** The trace log writer handle. */
|
---|
546 | RTTRACELOGWR hTraceLog;
|
---|
547 | /** Guest memory data aggregation structures to track
|
---|
548 | * currently pending guest memory reads/writes. */
|
---|
549 | DBGFTRACERGCPHYSRWAGG aGstMemRwData[10];
|
---|
550 | } DBGFTRACERINSR3;
|
---|
551 | /** Pointer to a tarcer instance - Ring-3 Ptr. */
|
---|
552 | typedef R3PTRTYPE(DBGFTRACERINSR3 *) PDBGFTRACERINSR3;
|
---|
553 |
|
---|
554 |
|
---|
555 | /**
|
---|
556 | * Private tracer instance data, ring-0
|
---|
557 | */
|
---|
558 | typedef struct DBGFTRACERINSR0
|
---|
559 | {
|
---|
560 | /** Pointer to the VM this instance was created for. */
|
---|
561 | R0PTRTYPE(PGVM) pGVM;
|
---|
562 | /** The tracer instance memory. */
|
---|
563 | RTR0MEMOBJ hMemObj;
|
---|
564 | /** The ring-3 mapping object. */
|
---|
565 | RTR0MEMOBJ hMapObj;
|
---|
566 | /** Pointer to the shared tracer instance data. */
|
---|
567 | R0PTRTYPE(PDBGFTRACERSHARED) pSharedR0;
|
---|
568 | /** Size of the ring buffer in bytes, kept here so R3 can not manipulate the ring buffer
|
---|
569 | * size afterwards to trick R0 into doing something harmful. */
|
---|
570 | size_t cbRingBuf;
|
---|
571 | /** Pointer to the start of the ring buffer. */
|
---|
572 | R0PTRTYPE(uint8_t *) pbRingBufR0;
|
---|
573 | } DBGFTRACERINSR0;
|
---|
574 | /** Pointer to a VM - Ring-0 Ptr. */
|
---|
575 | typedef R0PTRTYPE(DBGFTRACERINSR0 *) PDBGFTRACERINSR0;
|
---|
576 |
|
---|
577 |
|
---|
578 | /**
|
---|
579 | * Private device instance data, raw-mode
|
---|
580 | */
|
---|
581 | typedef struct DBGFTRACERINSRC
|
---|
582 | {
|
---|
583 | /** Pointer to the VM this instance was created for. */
|
---|
584 | RGPTRTYPE(PVM) pVMRC;
|
---|
585 | } DBGFTRACERINSRC;
|
---|
586 |
|
---|
587 |
|
---|
588 | #ifdef IN_RING3
|
---|
589 | DECLHIDDEN(int) dbgfTracerR3EvtPostSingle(PVMCC pVM, PDBGFTRACERINSCC pThisCC, DBGFTRACEREVTSRC hEvtSrc,
|
---|
590 | DBGFTRACEREVT enmTraceEvt, const void *pvEvtDesc, size_t cbEvtDesc,
|
---|
591 | uint64_t *pidEvt);
|
---|
592 | #endif
|
---|
593 |
|
---|
594 | /** VMM Debugger Command. */
|
---|
595 | typedef enum DBGFCMD
|
---|
596 | {
|
---|
597 | /** No command.
|
---|
598 | * This is assigned to the field by the emulation thread after
|
---|
599 | * a command has been completed. */
|
---|
600 | DBGFCMD_NO_COMMAND = 0,
|
---|
601 | /** Halt the VM. */
|
---|
602 | DBGFCMD_HALT,
|
---|
603 | /** Resume execution. */
|
---|
604 | DBGFCMD_GO,
|
---|
605 | /** Single step execution - stepping into calls. */
|
---|
606 | DBGFCMD_SINGLE_STEP
|
---|
607 | } DBGFCMD;
|
---|
608 |
|
---|
609 | /**
|
---|
610 | * VMM Debugger Command.
|
---|
611 | */
|
---|
612 | typedef union DBGFCMDDATA
|
---|
613 | {
|
---|
614 | uint32_t uDummy;
|
---|
615 | } DBGFCMDDATA;
|
---|
616 | /** Pointer to DBGF Command Data. */
|
---|
617 | typedef DBGFCMDDATA *PDBGFCMDDATA;
|
---|
618 |
|
---|
619 | /**
|
---|
620 | * Info type.
|
---|
621 | */
|
---|
622 | typedef enum DBGFINFOTYPE
|
---|
623 | {
|
---|
624 | /** Invalid. */
|
---|
625 | DBGFINFOTYPE_INVALID = 0,
|
---|
626 | /** Device owner. */
|
---|
627 | DBGFINFOTYPE_DEV,
|
---|
628 | /** Driver owner. */
|
---|
629 | DBGFINFOTYPE_DRV,
|
---|
630 | /** Internal owner. */
|
---|
631 | DBGFINFOTYPE_INT,
|
---|
632 | /** External owner. */
|
---|
633 | DBGFINFOTYPE_EXT,
|
---|
634 | /** Device owner. */
|
---|
635 | DBGFINFOTYPE_DEV_ARGV,
|
---|
636 | /** Driver owner. */
|
---|
637 | DBGFINFOTYPE_DRV_ARGV,
|
---|
638 | /** USB device owner. */
|
---|
639 | DBGFINFOTYPE_USB_ARGV,
|
---|
640 | /** Internal owner, argv. */
|
---|
641 | DBGFINFOTYPE_INT_ARGV,
|
---|
642 | /** External owner. */
|
---|
643 | DBGFINFOTYPE_EXT_ARGV
|
---|
644 | } DBGFINFOTYPE;
|
---|
645 |
|
---|
646 |
|
---|
647 | /** Pointer to info structure. */
|
---|
648 | typedef struct DBGFINFO *PDBGFINFO;
|
---|
649 |
|
---|
650 | #ifdef IN_RING3
|
---|
651 | /**
|
---|
652 | * Info structure.
|
---|
653 | */
|
---|
654 | typedef struct DBGFINFO
|
---|
655 | {
|
---|
656 | /** The flags. */
|
---|
657 | uint32_t fFlags;
|
---|
658 | /** Owner type. */
|
---|
659 | DBGFINFOTYPE enmType;
|
---|
660 | /** Per type data. */
|
---|
661 | union
|
---|
662 | {
|
---|
663 | /** DBGFINFOTYPE_DEV */
|
---|
664 | struct
|
---|
665 | {
|
---|
666 | /** Device info handler function. */
|
---|
667 | PFNDBGFHANDLERDEV pfnHandler;
|
---|
668 | /** The device instance. */
|
---|
669 | PPDMDEVINS pDevIns;
|
---|
670 | } Dev;
|
---|
671 |
|
---|
672 | /** DBGFINFOTYPE_DRV */
|
---|
673 | struct
|
---|
674 | {
|
---|
675 | /** Driver info handler function. */
|
---|
676 | PFNDBGFHANDLERDRV pfnHandler;
|
---|
677 | /** The driver instance. */
|
---|
678 | PPDMDRVINS pDrvIns;
|
---|
679 | } Drv;
|
---|
680 |
|
---|
681 | /** DBGFINFOTYPE_INT */
|
---|
682 | struct
|
---|
683 | {
|
---|
684 | /** Internal info handler function. */
|
---|
685 | PFNDBGFHANDLERINT pfnHandler;
|
---|
686 | } Int;
|
---|
687 |
|
---|
688 | /** DBGFINFOTYPE_EXT */
|
---|
689 | struct
|
---|
690 | {
|
---|
691 | /** External info handler function. */
|
---|
692 | PFNDBGFHANDLEREXT pfnHandler;
|
---|
693 | /** The user argument. */
|
---|
694 | void *pvUser;
|
---|
695 | } Ext;
|
---|
696 |
|
---|
697 | /** DBGFINFOTYPE_DEV_ARGV */
|
---|
698 | struct
|
---|
699 | {
|
---|
700 | /** Device info handler function. */
|
---|
701 | PFNDBGFINFOARGVDEV pfnHandler;
|
---|
702 | /** The device instance. */
|
---|
703 | PPDMDEVINS pDevIns;
|
---|
704 | } DevArgv;
|
---|
705 |
|
---|
706 | /** DBGFINFOTYPE_DRV_ARGV */
|
---|
707 | struct
|
---|
708 | {
|
---|
709 | /** Driver info handler function. */
|
---|
710 | PFNDBGFINFOARGVDRV pfnHandler;
|
---|
711 | /** The driver instance. */
|
---|
712 | PPDMDRVINS pDrvIns;
|
---|
713 | } DrvArgv;
|
---|
714 |
|
---|
715 | /** DBGFINFOTYPE_USB_ARGV */
|
---|
716 | struct
|
---|
717 | {
|
---|
718 | /** Driver info handler function. */
|
---|
719 | PFNDBGFINFOARGVUSB pfnHandler;
|
---|
720 | /** The driver instance. */
|
---|
721 | PPDMUSBINS pUsbIns;
|
---|
722 | } UsbArgv;
|
---|
723 |
|
---|
724 | /** DBGFINFOTYPE_INT_ARGV */
|
---|
725 | struct
|
---|
726 | {
|
---|
727 | /** Internal info handler function. */
|
---|
728 | PFNDBGFINFOARGVINT pfnHandler;
|
---|
729 | } IntArgv;
|
---|
730 |
|
---|
731 | /** DBGFINFOTYPE_EXT_ARGV */
|
---|
732 | struct
|
---|
733 | {
|
---|
734 | /** External info handler function. */
|
---|
735 | PFNDBGFINFOARGVEXT pfnHandler;
|
---|
736 | /** The user argument. */
|
---|
737 | void *pvUser;
|
---|
738 | } ExtArgv;
|
---|
739 | } u;
|
---|
740 |
|
---|
741 | /** Pointer to the description. */
|
---|
742 | const char *pszDesc;
|
---|
743 | /** Pointer to the next info structure. */
|
---|
744 | PDBGFINFO pNext;
|
---|
745 | /** The identifier name length. */
|
---|
746 | size_t cchName;
|
---|
747 | /** The identifier name. (Extends 'beyond' the struct as usual.) */
|
---|
748 | char szName[1];
|
---|
749 | } DBGFINFO;
|
---|
750 | #endif /* IN_RING3 */
|
---|
751 |
|
---|
752 |
|
---|
753 | #ifdef IN_RING3
|
---|
754 | /**
|
---|
755 | * Guest OS digger instance.
|
---|
756 | */
|
---|
757 | typedef struct DBGFOS
|
---|
758 | {
|
---|
759 | /** Pointer to the registration record. */
|
---|
760 | PCDBGFOSREG pReg;
|
---|
761 | /** Pointer to the next OS we've registered. */
|
---|
762 | struct DBGFOS *pNext;
|
---|
763 | /** List of EMT interface wrappers. */
|
---|
764 | struct DBGFOSEMTWRAPPER *pWrapperHead;
|
---|
765 | /** The instance data (variable size). */
|
---|
766 | uint8_t abData[16];
|
---|
767 | } DBGFOS;
|
---|
768 | #endif
|
---|
769 | /** Pointer to guest OS digger instance. */
|
---|
770 | typedef struct DBGFOS *PDBGFOS;
|
---|
771 | /** Pointer to const guest OS digger instance. */
|
---|
772 | typedef struct DBGFOS const *PCDBGFOS;
|
---|
773 |
|
---|
774 |
|
---|
775 | /** An invalid breakpoint chunk ID. */
|
---|
776 | #define DBGF_BP_CHUNK_ID_INVALID UINT32_MAX
|
---|
777 | /** Generates a unique breakpoint handle from the given chunk ID and entry inside the chunk. */
|
---|
778 | #define DBGF_BP_HND_CREATE(a_idChunk, a_idEntry) RT_MAKE_U32(a_idEntry, a_idChunk);
|
---|
779 | /** Returns the chunk ID from the given breakpoint handle. */
|
---|
780 | #define DBGF_BP_HND_GET_CHUNK_ID(a_hBp) ((uint32_t)RT_HI_U16(a_hBp))
|
---|
781 | /** Returns the entry index inside a chunk from the given breakpoint handle. */
|
---|
782 | #define DBGF_BP_HND_GET_ENTRY(a_hBp) ((uint32_t)RT_LO_U16(a_hBp))
|
---|
783 |
|
---|
784 |
|
---|
785 | /** @name DBGF int3 L1 lookup table entry types.
|
---|
786 | * @{ */
|
---|
787 | /** No breakpoint handle assigned for this entry - special value which can be used
|
---|
788 | * for comparison with the whole entry. */
|
---|
789 | #define DBGF_BP_INT3_L1_ENTRY_TYPE_NULL UINT32_C(0)
|
---|
790 | /** Direct breakpoint handle. */
|
---|
791 | #define DBGF_BP_INT3_L1_ENTRY_TYPE_BP_HND 1
|
---|
792 | /** Index into the L2 tree denoting the root of a search tree. */
|
---|
793 | #define DBGF_BP_INT3_L1_ENTRY_TYPE_L2_IDX 2
|
---|
794 | /** @} */
|
---|
795 |
|
---|
796 |
|
---|
797 | /** Returns the entry type for the given L1 lookup table entry. */
|
---|
798 | #define DBGF_BP_INT3_L1_ENTRY_GET_TYPE(a_u32Entry) ((a_u32Entry) >> 28)
|
---|
799 | /** Returns a DBGF breakpoint handle from the given L1 lookup table entry,
|
---|
800 | * type needs to be DBGF_BP_INT3_L1_ENTRY_TYPE_BP_HND. */
|
---|
801 | #define DBGF_BP_INT3_L1_ENTRY_GET_BP_HND(a_u32Entry) ((DBGFBP)((a_u32Entry) & UINT32_C(0x0fffffff)))
|
---|
802 | /** Returns a L2 index from the given L1 lookup table entry,
|
---|
803 | * type needs to be DBGF_BP_INT3_L1_ENTRY_TYPE_L2_IDX. */
|
---|
804 | #define DBGF_BP_INT3_L1_ENTRY_GET_L2_IDX(a_u32Entry) ((a_u32Entry) & UINT32_C(0x0fffffff))
|
---|
805 | /** Creates a L1 entry value from the given type and data. */
|
---|
806 | #define DBGF_BP_INT3_L1_ENTRY_CREATE(a_Type, a_u32Data) ((((uint32_t)(a_Type)) << 28) | ((a_u32Data) & UINT32_C(0x0fffffff)))
|
---|
807 | /** Creates a breakpoint handle type L1 lookup entry. */
|
---|
808 | #define DBGF_BP_INT3_L1_ENTRY_CREATE_BP_HND(a_hBp) DBGF_BP_INT3_L1_ENTRY_CREATE(DBGF_BP_INT3_L1_ENTRY_TYPE_BP_HND, a_hBp)
|
---|
809 | /** Creates a L2 index type L1 lookup entry. */
|
---|
810 | #define DBGF_BP_INT3_L1_ENTRY_CREATE_L2_IDX(a_idxL2) DBGF_BP_INT3_L1_ENTRY_CREATE(DBGF_BP_INT3_L1_ENTRY_TYPE_L2_IDX, a_idxL2)
|
---|
811 |
|
---|
812 | /** Extracts the lowest bits from the given GC pointer used as an index into the L1 lookup table. */
|
---|
813 | #define DBGF_BP_INT3_L1_IDX_EXTRACT_FROM_ADDR(a_GCPtr) ((uint16_t)((a_GCPtr) & UINT16_C(0xffff)))
|
---|
814 |
|
---|
815 | /**
|
---|
816 | * The internal breakpoint owner state, shared part.
|
---|
817 | */
|
---|
818 | typedef struct DBGFBPOWNERINT
|
---|
819 | {
|
---|
820 | /** Reference counter indicating how man breakpoints use this owner currently. */
|
---|
821 | volatile uint32_t cRefs;
|
---|
822 | /** Padding. */
|
---|
823 | uint32_t u32Pad0;
|
---|
824 | /** Callback to call when a breakpoint has hit, Ring-3 Ptr. */
|
---|
825 | R3PTRTYPE(PFNDBGFBPHIT) pfnBpHitR3;
|
---|
826 | } DBGFBPOWNERINT;
|
---|
827 | AssertCompileSize(DBGFBPOWNERINT, 16);
|
---|
828 | /** Pointer to an internal breakpoint owner state, shared part. */
|
---|
829 | typedef DBGFBPOWNERINT *PDBGFBPOWNERINT;
|
---|
830 | /** Pointer to a constant internal breakpoint owner state, shared part. */
|
---|
831 | typedef const DBGFBPOWNERINT *PCDBGFBPOWNERINT;
|
---|
832 |
|
---|
833 |
|
---|
834 | /**
|
---|
835 | * The internal breakpoint owner state, Ring-0 part.
|
---|
836 | */
|
---|
837 | typedef struct DBGFBPOWNERINTR0
|
---|
838 | {
|
---|
839 | /** Reference counter indicating how man breakpoints use this owner currently. */
|
---|
840 | volatile uint32_t cRefs;
|
---|
841 | /** Padding. */
|
---|
842 | uint32_t u32Pad0;
|
---|
843 | /** Callback to call when a breakpoint has hit, Ring-0 Ptr. */
|
---|
844 | R0PTRTYPE(PFNDBGFBPHIT) pfnBpHitR0;
|
---|
845 | } DBGFBPOWNERINTR0;
|
---|
846 | AssertCompileSize(DBGFBPOWNERINTR0, 16);
|
---|
847 | /** Pointer to an internal breakpoint owner state, shared part. */
|
---|
848 | typedef DBGFBPOWNERINTR0 *PDBGFBPOWNERINTR0;
|
---|
849 | /** Pointer to a constant internal breakpoint owner state, shared part. */
|
---|
850 | typedef const DBGFBPOWNERINTR0 *PCDBGFBPOWNERINTR0;
|
---|
851 |
|
---|
852 |
|
---|
853 | /**
|
---|
854 | * The internal breakpoint state, shared part.
|
---|
855 | */
|
---|
856 | typedef struct DBGFBPINT
|
---|
857 | {
|
---|
858 | /** The publicly visible part. */
|
---|
859 | DBGFBPPUB Pub;
|
---|
860 | /** The opaque user argument for the owner callback, Ring-3 Ptr. */
|
---|
861 | R3PTRTYPE(void *) pvUserR3;
|
---|
862 | } DBGFBPINT;
|
---|
863 | AssertCompileSize(DBGFBPINT, DBGF_BP_ENTRY_SZ);
|
---|
864 | /** Pointer to an internal breakpoint state. */
|
---|
865 | typedef DBGFBPINT *PDBGFBPINT;
|
---|
866 | /** Pointer to an const internal breakpoint state. */
|
---|
867 | typedef const DBGFBPINT *PCDBGFBPINT;
|
---|
868 |
|
---|
869 |
|
---|
870 | /**
|
---|
871 | * The internal breakpoint state, R0 part.
|
---|
872 | */
|
---|
873 | typedef struct DBGFBPINTR0
|
---|
874 | {
|
---|
875 | /** The owner handle. */
|
---|
876 | DBGFBPOWNER hOwner;
|
---|
877 | /** Flag whether the breakpoint is in use. */
|
---|
878 | bool fInUse;
|
---|
879 | /** Padding to 8 byte alignment. */
|
---|
880 | bool afPad[3];
|
---|
881 | /** Opaque user data for the owner callback, Ring-0 Ptr. */
|
---|
882 | R0PTRTYPE(void *) pvUserR0;
|
---|
883 | } DBGFBPINTR0;
|
---|
884 | AssertCompileMemberAlignment(DBGFBPINTR0, pvUserR0, 8);
|
---|
885 | AssertCompileSize(DBGFBPINTR0, 16);
|
---|
886 | /** Pointer to an internal breakpoint state - Ring-0 Ptr. */
|
---|
887 | typedef R0PTRTYPE(DBGFBPINTR0 *) PDBGFBPINTR0;
|
---|
888 |
|
---|
889 |
|
---|
890 | /**
|
---|
891 | * Hardware breakpoint state.
|
---|
892 | */
|
---|
893 | typedef struct DBGFBPHW
|
---|
894 | {
|
---|
895 | /** The flat GC address of the breakpoint. */
|
---|
896 | RTGCUINTPTR GCPtr;
|
---|
897 | /** The breakpoint handle if active, NIL_DBGFBP if not in use. */
|
---|
898 | volatile DBGFBP hBp;
|
---|
899 | /** The access type (one of the X86_DR7_RW_* value). */
|
---|
900 | uint8_t fType;
|
---|
901 | /** The access size. */
|
---|
902 | uint8_t cb;
|
---|
903 | /** Flag whether the breakpoint is currently enabled. */
|
---|
904 | volatile bool fEnabled;
|
---|
905 | /** Padding. */
|
---|
906 | uint8_t bPad;
|
---|
907 | } DBGFBPHW;
|
---|
908 | AssertCompileSize(DBGFBPHW, 16);
|
---|
909 | /** Pointer to a hardware breakpoint state. */
|
---|
910 | typedef DBGFBPHW *PDBGFBPHW;
|
---|
911 | /** Pointer to a const hardware breakpoint state. */
|
---|
912 | typedef const DBGFBPHW *PCDBGFBPHW;
|
---|
913 |
|
---|
914 |
|
---|
915 | /**
|
---|
916 | * A breakpoint table chunk, ring-3 state.
|
---|
917 | */
|
---|
918 | typedef struct DBGFBPCHUNKR3
|
---|
919 | {
|
---|
920 | /** Pointer to the R3 base of the chunk. */
|
---|
921 | R3PTRTYPE(PDBGFBPINT) pBpBaseR3;
|
---|
922 | /** Bitmap of free/occupied breakpoint entries. */
|
---|
923 | R3PTRTYPE(volatile void *) pbmAlloc;
|
---|
924 | /** Number of free breakpoints in the chunk. */
|
---|
925 | volatile uint32_t cBpsFree;
|
---|
926 | /** The chunk index this tracking structure refers to. */
|
---|
927 | uint32_t idChunk;
|
---|
928 | } DBGFBPCHUNKR3;
|
---|
929 | /** Pointer to a breakpoint table chunk - Ring-3 Ptr. */
|
---|
930 | typedef DBGFBPCHUNKR3 *PDBGFBPCHUNKR3;
|
---|
931 | /** Pointer to a const breakpoint table chunk - Ring-3 Ptr. */
|
---|
932 | typedef const DBGFBPCHUNKR3 *PCDBGFBPCHUNKR3;
|
---|
933 |
|
---|
934 |
|
---|
935 | /**
|
---|
936 | * Breakpoint table chunk, ring-0 state.
|
---|
937 | */
|
---|
938 | typedef struct DBGFBPCHUNKR0
|
---|
939 | {
|
---|
940 | /** The chunks memory. */
|
---|
941 | RTR0MEMOBJ hMemObj;
|
---|
942 | /** The ring-3 mapping object. */
|
---|
943 | RTR0MEMOBJ hMapObj;
|
---|
944 | /** Pointer to the breakpoint entries base. */
|
---|
945 | R0PTRTYPE(PDBGFBPINT) paBpBaseSharedR0;
|
---|
946 | /** Pointer to the Ring-0 only part of the breakpoints. */
|
---|
947 | PDBGFBPINTR0 paBpBaseR0Only;
|
---|
948 | } DBGFBPCHUNKR0;
|
---|
949 | /** Pointer to a breakpoint table chunk - Ring-0 Ptr. */
|
---|
950 | typedef R0PTRTYPE(DBGFBPCHUNKR0 *) PDBGFBPCHUNKR0;
|
---|
951 |
|
---|
952 |
|
---|
953 | /**
|
---|
954 | * L2 lookup table entry.
|
---|
955 | *
|
---|
956 | * @remark The order of the members matters to be able to atomically update
|
---|
957 | * the AVL left/right pointers and depth with a single 64bit atomic write.
|
---|
958 | * @verbatim
|
---|
959 | * 7 6 5 4 3 2 1 0
|
---|
960 | * +--------+--------+--------+--------+--------+--------+--------+--------+
|
---|
961 | * | hBp[15:0] | GCPtrKey[63:16] |
|
---|
962 | * +--------+--------+--------+--------+--------+--------+--------+--------+
|
---|
963 | * | hBp[27:16] | iDepth | idxRight[21:0] | idxLeft[21:0] |
|
---|
964 | * +--------+--------+--------+--------+--------+--------+--------+--------+
|
---|
965 | * \_8 bits_/
|
---|
966 | * @endverbatim
|
---|
967 | */
|
---|
968 | typedef struct DBGFBPL2ENTRY
|
---|
969 | {
|
---|
970 | /** The upper 6 bytes of the breakpoint address and the low 16 bits of the breakpoint handle. */
|
---|
971 | volatile uint64_t u64GCPtrKeyAndBpHnd1;
|
---|
972 | /** Left/right lower index, tree depth and remaining 12 bits of the breakpoint handle. */
|
---|
973 | volatile uint64_t u64LeftRightIdxDepthBpHnd2;
|
---|
974 | } DBGFBPL2ENTRY;
|
---|
975 | AssertCompileSize(DBGFBPL2ENTRY, 16);
|
---|
976 | /** Pointer to a L2 lookup table entry. */
|
---|
977 | typedef DBGFBPL2ENTRY *PDBGFBPL2ENTRY;
|
---|
978 | /** Pointer to a const L2 lookup table entry. */
|
---|
979 | typedef const DBGFBPL2ENTRY *PCDBGFBPL2ENTRY;
|
---|
980 |
|
---|
981 | /** Extracts the part from the given GC pointer used as the key in the L2 binary search tree. */
|
---|
982 | #define DBGF_BP_INT3_L2_KEY_EXTRACT_FROM_ADDR(a_GCPtr) ((uint64_t)((a_GCPtr) >> 16))
|
---|
983 |
|
---|
984 | /** An invalid breakpoint chunk ID. */
|
---|
985 | #define DBGF_BP_L2_IDX_CHUNK_ID_INVALID UINT32_MAX
|
---|
986 | /** Generates a unique breakpoint handle from the given chunk ID and entry inside the chunk. */
|
---|
987 | #define DBGF_BP_L2_IDX_CREATE(a_idChunk, a_idEntry) RT_MAKE_U32(a_idEntry, a_idChunk);
|
---|
988 | /** Returns the chunk ID from the given breakpoint handle. */
|
---|
989 | #define DBGF_BP_L2_IDX_GET_CHUNK_ID(a_idxL2) ((uint32_t)RT_HI_U16(a_idxL2))
|
---|
990 | /** Returns the entry index inside a chunk from the given breakpoint handle. */
|
---|
991 | #define DBGF_BP_L2_IDX_GET_ENTRY(a_idxL2) ((uint32_t)RT_LO_U16(a_idxL2))
|
---|
992 |
|
---|
993 | /** Number of bits for the left/right index pointers. */
|
---|
994 | #define DBGF_BP_L2_ENTRY_LEFT_RIGHT_IDX_BITS 22
|
---|
995 | /** Special index value marking the end of a tree. */
|
---|
996 | #define DBGF_BP_L2_ENTRY_IDX_END UINT32_C(0x3fffff)
|
---|
997 | /** Number of bits to shift the breakpoint handle in the first part. */
|
---|
998 | #define DBGF_BP_L2_ENTRY_BP_1ST_SHIFT 48
|
---|
999 | /** Mask for the first part of the breakpoint handle. */
|
---|
1000 | #define DBGF_BP_L2_ENTRY_BP_1ST_MASK UINT32_C(0x0000ffff)
|
---|
1001 | /** Number of bits to shift the breakpoint handle in the second part. */
|
---|
1002 | #define DBGF_BP_L2_ENTRY_BP_2ND_SHIFT 52
|
---|
1003 | /** Mask for the second part of the breakpoint handle. */
|
---|
1004 | #define DBGF_BP_L2_ENTRY_BP_2ND_MASK UINT32_C(0x0fff0000)
|
---|
1005 | /** Mask for the second part of the breakpoint handle stored in the L2 entry. */
|
---|
1006 | #define DBGF_BP_L2_ENTRY_BP_2ND_L2_ENTRY_MASK UINT64_C(0xfff0000000000000)
|
---|
1007 | /** Number of bits to shift the depth in the second part. */
|
---|
1008 | #define DBGF_BP_L2_ENTRY_DEPTH_SHIFT 44
|
---|
1009 | /** Mask for the depth. */
|
---|
1010 | #define DBGF_BP_L2_ENTRY_DEPTH_MASK UINT8_MAX
|
---|
1011 | /** Number of bits to shift the right L2 index in the second part. */
|
---|
1012 | #define DBGF_BP_L2_ENTRY_RIGHT_IDX_SHIFT 22
|
---|
1013 | /** Number of bits to shift the left L2 index in the second part. */
|
---|
1014 | #define DBGF_BP_L2_ENTRY_LEFT_IDX_SHIFT 0
|
---|
1015 | /** Index mask. */
|
---|
1016 | #define DBGF_BP_L2_ENTRY_LEFT_RIGHT_IDX_MASK (RT_BIT_32(DBGF_BP_L2_ENTRY_LEFT_RIGHT_IDX_BITS) - 1)
|
---|
1017 | /** Left index mask. */
|
---|
1018 | #define DBGF_BP_L2_ENTRY_LEFT_IDX_MASK (DBGF_BP_L2_ENTRY_LEFT_RIGHT_IDX_MASK << DBGF_BP_L2_ENTRY_LEFT_IDX_SHIFT)
|
---|
1019 | /** Right index mask. */
|
---|
1020 | #define DBGF_BP_L2_ENTRY_RIGHT_IDX_MASK (DBGF_BP_L2_ENTRY_LEFT_RIGHT_IDX_MASK << DBGF_BP_L2_ENTRY_RIGHT_IDX_SHIFT)
|
---|
1021 | /** Returns the upper 6 bytes of the GC pointer from the given breakpoint entry. */
|
---|
1022 | #define DBGF_BP_L2_ENTRY_GET_GCPTR(a_u64GCPtrKeyAndBpHnd1) ((a_u64GCPtrKeyAndBpHnd1) & UINT64_C(0x0000ffffffffffff))
|
---|
1023 | /** Returns the breakpoint handle from both L2 entry members. */
|
---|
1024 | #define DBGF_BP_L2_ENTRY_GET_BP_HND(a_u64GCPtrKeyAndBpHnd1, a_u64LeftRightIdxDepthBpHnd2) \
|
---|
1025 | ((DBGFBP)(((a_u64GCPtrKeyAndBpHnd1) >> DBGF_BP_L2_ENTRY_BP_1ST_SHIFT) | (((a_u64LeftRightIdxDepthBpHnd2) >> DBGF_BP_L2_ENTRY_BP_2ND_SHIFT) << 16)))
|
---|
1026 | /** Extracts the depth of the second 64bit L2 entry value. */
|
---|
1027 | #define DBGF_BP_L2_ENTRY_GET_DEPTH(a_u64LeftRightIdxDepthBpHnd2) ((uint8_t)(((a_u64LeftRightIdxDepthBpHnd2) >> DBGF_BP_L2_ENTRY_DEPTH_SHIFT) & DBGF_BP_L2_ENTRY_DEPTH_MASK))
|
---|
1028 | /** Extracts the lower right index value from the L2 entry value. */
|
---|
1029 | #define DBGF_BP_L2_ENTRY_GET_IDX_RIGHT(a_u64LeftRightIdxDepthBpHnd2) \
|
---|
1030 | ((uint32_t)(((a_u64LeftRightIdxDepthBpHnd2) >> 22) & DBGF_BP_L2_ENTRY_LEFT_RIGHT_IDX_MASK))
|
---|
1031 | /** Extracts the lower left index value from the L2 entry value. */
|
---|
1032 | #define DBGF_BP_L2_ENTRY_GET_IDX_LEFT(a_u64LeftRightIdxDepthBpHnd2) \
|
---|
1033 | ((uint32_t)((a_u64LeftRightIdxDepthBpHnd2) & DBGF_BP_L2_ENTRY_LEFT_RIGHT_IDX_MASK))
|
---|
1034 |
|
---|
1035 |
|
---|
1036 | /**
|
---|
1037 | * A breakpoint L2 lookup table chunk, ring-3 state.
|
---|
1038 | */
|
---|
1039 | typedef struct DBGFBPL2TBLCHUNKR3
|
---|
1040 | {
|
---|
1041 | /** Pointer to the R3 base of the chunk. */
|
---|
1042 | R3PTRTYPE(PDBGFBPL2ENTRY) pL2BaseR3;
|
---|
1043 | /** Bitmap of free/occupied breakpoint entries. */
|
---|
1044 | R3PTRTYPE(volatile void *) pbmAlloc;
|
---|
1045 | /** Number of free entries in the chunk. */
|
---|
1046 | volatile uint32_t cFree;
|
---|
1047 | /** The chunk index this tracking structure refers to. */
|
---|
1048 | uint32_t idChunk;
|
---|
1049 | } DBGFBPL2TBLCHUNKR3;
|
---|
1050 | /** Pointer to a breakpoint L2 lookup table chunk - Ring-3 Ptr. */
|
---|
1051 | typedef DBGFBPL2TBLCHUNKR3 *PDBGFBPL2TBLCHUNKR3;
|
---|
1052 | /** Pointer to a const breakpoint L2 lookup table chunk - Ring-3 Ptr. */
|
---|
1053 | typedef const DBGFBPL2TBLCHUNKR3 *PCDBGFBPL2TBLCHUNKR3;
|
---|
1054 |
|
---|
1055 |
|
---|
1056 | /**
|
---|
1057 | * Breakpoint L2 lookup table chunk, ring-0 state.
|
---|
1058 | */
|
---|
1059 | typedef struct DBGFBPL2TBLCHUNKR0
|
---|
1060 | {
|
---|
1061 | /** The chunks memory. */
|
---|
1062 | RTR0MEMOBJ hMemObj;
|
---|
1063 | /** The ring-3 mapping object. */
|
---|
1064 | RTR0MEMOBJ hMapObj;
|
---|
1065 | /** Pointer to the breakpoint entries base. */
|
---|
1066 | R0PTRTYPE(PDBGFBPL2ENTRY) paBpL2TblBaseSharedR0;
|
---|
1067 | } DBGFBPL2TBLCHUNKR0;
|
---|
1068 | /** Pointer to a breakpoint L2 lookup table chunk - Ring-0 Ptr. */
|
---|
1069 | typedef R0PTRTYPE(DBGFBPL2TBLCHUNKR0 *) PDBGFBPL2TBLCHUNKR0;
|
---|
1070 |
|
---|
1071 |
|
---|
1072 |
|
---|
1073 | /**
|
---|
1074 | * DBGF Data (part of VM)
|
---|
1075 | */
|
---|
1076 | typedef struct DBGF
|
---|
1077 | {
|
---|
1078 | /** Bitmap of enabled hardware interrupt breakpoints. */
|
---|
1079 | uint32_t bmHardIntBreakpoints[256 / 32];
|
---|
1080 | /** Bitmap of enabled software interrupt breakpoints. */
|
---|
1081 | uint32_t bmSoftIntBreakpoints[256 / 32];
|
---|
1082 | /** Bitmap of selected events.
|
---|
1083 | * This includes non-selectable events too for simplicity, we maintain the
|
---|
1084 | * state for some of these, as it may come in handy. */
|
---|
1085 | uint64_t bmSelectedEvents[(DBGFEVENT_END + 63) / 64];
|
---|
1086 |
|
---|
1087 | /** Enabled hardware interrupt breakpoints. */
|
---|
1088 | uint32_t cHardIntBreakpoints;
|
---|
1089 | /** Enabled software interrupt breakpoints. */
|
---|
1090 | uint32_t cSoftIntBreakpoints;
|
---|
1091 |
|
---|
1092 | /** The number of selected events. */
|
---|
1093 | uint32_t cSelectedEvents;
|
---|
1094 |
|
---|
1095 | /** The number of enabled hardware breakpoints. */
|
---|
1096 | uint8_t cEnabledHwBreakpoints;
|
---|
1097 | /** The number of enabled hardware I/O breakpoints. */
|
---|
1098 | uint8_t cEnabledHwIoBreakpoints;
|
---|
1099 | uint8_t au8Alignment1[2]; /**< Alignment padding. */
|
---|
1100 | /** The number of enabled INT3 breakpoints. */
|
---|
1101 | uint32_t volatile cEnabledInt3Breakpoints;
|
---|
1102 |
|
---|
1103 | /** Debugger Attached flag.
|
---|
1104 | * Set if a debugger is attached, elsewise it's clear.
|
---|
1105 | */
|
---|
1106 | bool volatile fAttached;
|
---|
1107 |
|
---|
1108 | /** Stepping filtering. */
|
---|
1109 | struct
|
---|
1110 | {
|
---|
1111 | /** The CPU doing the stepping.
|
---|
1112 | * Set to NIL_VMCPUID when filtering is inactive */
|
---|
1113 | VMCPUID idCpu;
|
---|
1114 | /** The specified flags. */
|
---|
1115 | uint32_t fFlags;
|
---|
1116 | /** The effective PC address to stop at, if given. */
|
---|
1117 | RTGCPTR AddrPc;
|
---|
1118 | /** The lowest effective stack address to stop at.
|
---|
1119 | * Together with cbStackPop, this forms a range of effective stack pointer
|
---|
1120 | * addresses that we stop for. */
|
---|
1121 | RTGCPTR AddrStackPop;
|
---|
1122 | /** The size of the stack stop area starting at AddrStackPop. */
|
---|
1123 | RTGCPTR cbStackPop;
|
---|
1124 | /** Maximum number of steps. */
|
---|
1125 | uint32_t cMaxSteps;
|
---|
1126 |
|
---|
1127 | /** Number of steps made thus far. */
|
---|
1128 | uint32_t cSteps;
|
---|
1129 | /** Current call counting balance for step-over handling. */
|
---|
1130 | uint32_t uCallDepth;
|
---|
1131 |
|
---|
1132 | uint32_t u32Padding; /**< Alignment padding. */
|
---|
1133 |
|
---|
1134 | } SteppingFilter;
|
---|
1135 |
|
---|
1136 | uint32_t au32Alignment2[2]; /**< Alignment padding. */
|
---|
1137 |
|
---|
1138 | /** @name Breakpoint handling related state.
|
---|
1139 | * @{ */
|
---|
1140 | /** Array of hardware breakpoints (0..3).
|
---|
1141 | * This is shared among all the CPUs because life is much simpler that way. */
|
---|
1142 | DBGFBPHW aHwBreakpoints[4];
|
---|
1143 | /** @} */
|
---|
1144 |
|
---|
1145 | /**
|
---|
1146 | * Bug check data.
|
---|
1147 | * @note This will not be reset on reset.
|
---|
1148 | */
|
---|
1149 | struct
|
---|
1150 | {
|
---|
1151 | /** The ID of the CPU reporting it. */
|
---|
1152 | VMCPUID idCpu;
|
---|
1153 | /** The event associated with the bug check (gives source).
|
---|
1154 | * This is set to DBGFEVENT_END if no BSOD data here. */
|
---|
1155 | DBGFEVENTTYPE enmEvent;
|
---|
1156 | /** The total reset count at the time (VMGetResetCount). */
|
---|
1157 | uint32_t uResetNo;
|
---|
1158 | /** Explicit padding. */
|
---|
1159 | uint32_t uPadding;
|
---|
1160 | /** When it was reported (TMVirtualGet). */
|
---|
1161 | uint64_t uTimestamp;
|
---|
1162 | /** The bug check number.
|
---|
1163 | * @note This is really just 32-bit wide, see KeBugCheckEx. */
|
---|
1164 | uint64_t uBugCheck;
|
---|
1165 | /** The bug check parameters. */
|
---|
1166 | uint64_t auParameters[4];
|
---|
1167 | } BugCheck;
|
---|
1168 | } DBGF;
|
---|
1169 | AssertCompileMemberAlignment(DBGF, aHwBreakpoints, 8);
|
---|
1170 | AssertCompileMemberAlignment(DBGF, bmHardIntBreakpoints, 8);
|
---|
1171 | /** Pointer to DBGF Data. */
|
---|
1172 | typedef DBGF *PDBGF;
|
---|
1173 |
|
---|
1174 |
|
---|
1175 | /**
|
---|
1176 | * Event state (for DBGFCPU::aEvents).
|
---|
1177 | */
|
---|
1178 | typedef enum DBGFEVENTSTATE
|
---|
1179 | {
|
---|
1180 | /** Invalid event stack entry. */
|
---|
1181 | DBGFEVENTSTATE_INVALID = 0,
|
---|
1182 | /** The current event stack entry. */
|
---|
1183 | DBGFEVENTSTATE_CURRENT,
|
---|
1184 | /** Event that should be ignored but hasn't yet actually been ignored. */
|
---|
1185 | DBGFEVENTSTATE_IGNORE,
|
---|
1186 | /** Event that has been ignored but may be restored to IGNORE should another
|
---|
1187 | * debug event fire before the instruction is completed. */
|
---|
1188 | DBGFEVENTSTATE_RESTORABLE,
|
---|
1189 | /** End of valid events. */
|
---|
1190 | DBGFEVENTSTATE_END,
|
---|
1191 | /** Make sure we've got a 32-bit type. */
|
---|
1192 | DBGFEVENTSTATE_32BIT_HACK = 0x7fffffff
|
---|
1193 | } DBGFEVENTSTATE;
|
---|
1194 |
|
---|
1195 |
|
---|
1196 | /** Converts a DBGFCPU pointer into a VM pointer. */
|
---|
1197 | #define DBGFCPU_2_VM(pDbgfCpu) ((PVM)((uint8_t *)(pDbgfCpu) + (pDbgfCpu)->offVM))
|
---|
1198 |
|
---|
1199 | /**
|
---|
1200 | * The per CPU data for DBGF.
|
---|
1201 | */
|
---|
1202 | typedef struct DBGFCPU
|
---|
1203 | {
|
---|
1204 | /** The offset into the VM structure.
|
---|
1205 | * @see DBGFCPU_2_VM(). */
|
---|
1206 | uint32_t offVM;
|
---|
1207 |
|
---|
1208 | /** Flag whether the to invoke any owner handlers in ring-3 before dropping into the debugger. */
|
---|
1209 | bool fBpInvokeOwnerCallback;
|
---|
1210 | /** Set if we're singlestepping in raw mode.
|
---|
1211 | * This is checked and cleared in the \#DB handler. */
|
---|
1212 | bool fSingleSteppingRaw;
|
---|
1213 | /** Alignment padding. */
|
---|
1214 | bool afPadding[2];
|
---|
1215 | /** Current active breakpoint handle.
|
---|
1216 | * This is NIL_DBGFBP if not active. It is set when a execution engine
|
---|
1217 | * encounters a breakpoint and returns VINF_EM_DBG_BREAKPOINT.
|
---|
1218 | *
|
---|
1219 | * @todo drop this in favor of aEvents! */
|
---|
1220 | DBGFBP hBpActive;
|
---|
1221 |
|
---|
1222 | /** The number of events on the stack (aEvents).
|
---|
1223 | * The pending event is the last one (aEvents[cEvents - 1]), but only when
|
---|
1224 | * enmState is DBGFEVENTSTATE_CURRENT. */
|
---|
1225 | uint32_t cEvents;
|
---|
1226 | /** Events - current, ignoring and ignored.
|
---|
1227 | *
|
---|
1228 | * We maintain a stack of events in order to try avoid ending up in an infinit
|
---|
1229 | * loop when resuming after an event fired. There are cases where we may end
|
---|
1230 | * generating additional events before the instruction can be executed
|
---|
1231 | * successfully. Like for instance an XCHG on MMIO with separate read and write
|
---|
1232 | * breakpoints, or a MOVSB instruction working on breakpointed MMIO as both
|
---|
1233 | * source and destination.
|
---|
1234 | *
|
---|
1235 | * So, when resuming after dropping into the debugger for an event, we convert
|
---|
1236 | * the DBGFEVENTSTATE_CURRENT event into a DBGFEVENTSTATE_IGNORE event, leaving
|
---|
1237 | * cEvents unchanged. If the event is reported again, we will ignore it and
|
---|
1238 | * tell the reporter to continue executing. The event change to the
|
---|
1239 | * DBGFEVENTSTATE_RESTORABLE state.
|
---|
1240 | *
|
---|
1241 | * Currently, the event reporter has to figure out that it is a nested event and
|
---|
1242 | * tell DBGF to restore DBGFEVENTSTATE_RESTORABLE events (and keep
|
---|
1243 | * DBGFEVENTSTATE_IGNORE, should they happen out of order for some weird
|
---|
1244 | * reason).
|
---|
1245 | */
|
---|
1246 | struct
|
---|
1247 | {
|
---|
1248 | /** The event details. */
|
---|
1249 | DBGFEVENT Event;
|
---|
1250 | /** The RIP at which this happend (for validating ignoring). */
|
---|
1251 | uint64_t rip;
|
---|
1252 | /** The event state. */
|
---|
1253 | DBGFEVENTSTATE enmState;
|
---|
1254 | /** Alignment padding. */
|
---|
1255 | uint32_t u32Alignment;
|
---|
1256 | } aEvents[3];
|
---|
1257 | } DBGFCPU;
|
---|
1258 | AssertCompileMemberAlignment(DBGFCPU, aEvents, 8);
|
---|
1259 | AssertCompileMemberSizeAlignment(DBGFCPU, aEvents[0], 8);
|
---|
1260 | /** Pointer to DBGFCPU data. */
|
---|
1261 | typedef DBGFCPU *PDBGFCPU;
|
---|
1262 |
|
---|
1263 | struct DBGFOSEMTWRAPPER;
|
---|
1264 |
|
---|
1265 | /**
|
---|
1266 | * DBGF data kept in the ring-0 GVM.
|
---|
1267 | */
|
---|
1268 | typedef struct DBGFR0PERVM
|
---|
1269 | {
|
---|
1270 | /** Pointer to the tracer instance if enabled. */
|
---|
1271 | R0PTRTYPE(struct DBGFTRACERINSR0 *) pTracerR0;
|
---|
1272 |
|
---|
1273 | /** @name Breakpoint handling related state, Ring-0 only part.
|
---|
1274 | * @{ */
|
---|
1275 | /** The breakpoint owner table memory object. */
|
---|
1276 | RTR0MEMOBJ hMemObjBpOwners;
|
---|
1277 | /** The breakpoint owner table mapping object. */
|
---|
1278 | RTR0MEMOBJ hMapObjBpOwners;
|
---|
1279 | /** Base pointer to the breakpoint owners table. */
|
---|
1280 | R0PTRTYPE(PDBGFBPOWNERINTR0) paBpOwnersR0;
|
---|
1281 |
|
---|
1282 | /** Global breakpoint table chunk array. */
|
---|
1283 | DBGFBPCHUNKR0 aBpChunks[DBGF_BP_CHUNK_COUNT];
|
---|
1284 | /** Breakpoint L2 lookup table chunk array. */
|
---|
1285 | DBGFBPL2TBLCHUNKR0 aBpL2TblChunks[DBGF_BP_L2_TBL_CHUNK_COUNT];
|
---|
1286 | /** The L1 lookup tables memory object. */
|
---|
1287 | RTR0MEMOBJ hMemObjBpLocL1;
|
---|
1288 | /** The L1 lookup tables mapping object. */
|
---|
1289 | RTR0MEMOBJ hMapObjBpLocL1;
|
---|
1290 | /** Base pointer to the L1 locator table. */
|
---|
1291 | R0PTRTYPE(volatile uint32_t *) paBpLocL1R0;
|
---|
1292 | /** Flag whether the breakpoint manager was initialized (on demand). */
|
---|
1293 | bool fInit;
|
---|
1294 | /** @} */
|
---|
1295 | } DBGFR0PERVM;
|
---|
1296 |
|
---|
1297 | /**
|
---|
1298 | * The DBGF data kept in the UVM.
|
---|
1299 | */
|
---|
1300 | typedef struct DBGFUSERPERVM
|
---|
1301 | {
|
---|
1302 | /** The address space database lock. */
|
---|
1303 | RTSEMRW hAsDbLock;
|
---|
1304 | /** The address space handle database. (Protected by hAsDbLock.) */
|
---|
1305 | R3PTRTYPE(AVLPVTREE) AsHandleTree;
|
---|
1306 | /** The address space process id database. (Protected by hAsDbLock.) */
|
---|
1307 | R3PTRTYPE(AVLU32TREE) AsPidTree;
|
---|
1308 | /** The address space name database. (Protected by hAsDbLock.) */
|
---|
1309 | R3PTRTYPE(RTSTRSPACE) AsNameSpace;
|
---|
1310 | /** Special address space aliases. (Protected by hAsDbLock.) */
|
---|
1311 | RTDBGAS volatile ahAsAliases[DBGF_AS_COUNT];
|
---|
1312 | /** For lazily populating the aliased address spaces. */
|
---|
1313 | bool volatile afAsAliasPopuplated[DBGF_AS_COUNT];
|
---|
1314 | /** Alignment padding. */
|
---|
1315 | bool afAlignment1[2];
|
---|
1316 | /** Debug configuration. */
|
---|
1317 | R3PTRTYPE(RTDBGCFG) hDbgCfg;
|
---|
1318 |
|
---|
1319 | /** The register database lock. */
|
---|
1320 | RTSEMRW hRegDbLock;
|
---|
1321 | /** String space for looking up registers. (Protected by hRegDbLock.) */
|
---|
1322 | R3PTRTYPE(RTSTRSPACE) RegSpace;
|
---|
1323 | /** String space holding the register sets. (Protected by hRegDbLock.) */
|
---|
1324 | R3PTRTYPE(RTSTRSPACE) RegSetSpace;
|
---|
1325 | /** The number of registers (aliases, sub-fields and the special CPU
|
---|
1326 | * register aliases (eg AH) are not counted). */
|
---|
1327 | uint32_t cRegs;
|
---|
1328 | /** For early initialization by . */
|
---|
1329 | bool volatile fRegDbInitialized;
|
---|
1330 | /** Alignment padding. */
|
---|
1331 | bool afAlignment2[3];
|
---|
1332 |
|
---|
1333 | /** Critical section protecting the Guest OS Digger data, the info handlers
|
---|
1334 | * and the plugins. These share to give the best possible plugin unload
|
---|
1335 | * race protection. */
|
---|
1336 | RTCRITSECTRW CritSect;
|
---|
1337 | /** Head of the LIFO of loaded DBGF plugins. */
|
---|
1338 | R3PTRTYPE(struct DBGFPLUGIN *) pPlugInHead;
|
---|
1339 | /** The current Guest OS digger. */
|
---|
1340 | R3PTRTYPE(PDBGFOS) pCurOS;
|
---|
1341 | /** The head of the Guest OS digger instances. */
|
---|
1342 | R3PTRTYPE(PDBGFOS) pOSHead;
|
---|
1343 | /** List of registered info handlers. */
|
---|
1344 | R3PTRTYPE(PDBGFINFO) pInfoFirst;
|
---|
1345 |
|
---|
1346 | /** The configured tracer. */
|
---|
1347 | PDBGFTRACERINSR3 pTracerR3;
|
---|
1348 |
|
---|
1349 | /** @name VM -> Debugger event communication.
|
---|
1350 | * @{ */
|
---|
1351 | /** The event semaphore the debugger waits on for new events to arrive. */
|
---|
1352 | RTSEMEVENT hEvtWait;
|
---|
1353 | /** Multi event semaphore the vCPUs wait on in case the debug event ringbuffer is
|
---|
1354 | * full and require growing (done from the thread waiting for events). */
|
---|
1355 | RTSEMEVENTMULTI hEvtRingBufFull;
|
---|
1356 | /** Fast mutex protecting the event ring from concurrent write accesses by multiple vCPUs. */
|
---|
1357 | RTSEMFASTMUTEX hMtxDbgEvtWr;
|
---|
1358 | /** Ringbuffer of events, dynamically allocated based on the number of available vCPUs
|
---|
1359 | * (+ some safety entries). */
|
---|
1360 | PDBGFEVENT paDbgEvts;
|
---|
1361 | /** Number of entries in the event ring buffer. */
|
---|
1362 | uint32_t cDbgEvtMax;
|
---|
1363 | /** Next free entry to write to (vCPU thread). */
|
---|
1364 | volatile uint32_t idxDbgEvtWrite;
|
---|
1365 | /** Next event entry to from (debugger thread). */
|
---|
1366 | volatile uint32_t idxDbgEvtRead;
|
---|
1367 | /** @} */
|
---|
1368 |
|
---|
1369 | /** @name Breakpoint handling related state.
|
---|
1370 | * @{ */
|
---|
1371 | /** Base pointer to the breakpoint owners table. */
|
---|
1372 | R3PTRTYPE(PDBGFBPOWNERINT) paBpOwnersR3;
|
---|
1373 | /** Pointer to the bitmap denoting occupied owner entries. */
|
---|
1374 | R3PTRTYPE(volatile void *) pbmBpOwnersAllocR3;
|
---|
1375 |
|
---|
1376 | /** Global breakpoint table chunk array. */
|
---|
1377 | DBGFBPCHUNKR3 aBpChunks[DBGF_BP_CHUNK_COUNT];
|
---|
1378 | /** Breakpoint L2 lookup table chunk array. */
|
---|
1379 | DBGFBPL2TBLCHUNKR3 aBpL2TblChunks[DBGF_BP_L2_TBL_CHUNK_COUNT];
|
---|
1380 | /** Base pointer to the L1 locator table. */
|
---|
1381 | R3PTRTYPE(volatile uint32_t *) paBpLocL1R3;
|
---|
1382 | /** Fast mutex protecting the L2 table from concurrent write accesses (EMTs
|
---|
1383 | * can still do read accesses without holding it while traversing the trees). */
|
---|
1384 | RTSEMFASTMUTEX hMtxBpL2Wr;
|
---|
1385 | /** @} */
|
---|
1386 |
|
---|
1387 | /** The type database lock. */
|
---|
1388 | RTSEMRW hTypeDbLock;
|
---|
1389 | /** String space for looking up types. (Protected by hTypeDbLock.) */
|
---|
1390 | R3PTRTYPE(RTSTRSPACE) TypeSpace;
|
---|
1391 | /** For early initialization by . */
|
---|
1392 | bool volatile fTypeDbInitialized;
|
---|
1393 | /** Alignment padding. */
|
---|
1394 | bool afAlignment3[3];
|
---|
1395 |
|
---|
1396 | } DBGFUSERPERVM;
|
---|
1397 | typedef DBGFUSERPERVM *PDBGFUSERPERVM;
|
---|
1398 | typedef DBGFUSERPERVM const *PCDBGFUSERPERVM;
|
---|
1399 |
|
---|
1400 | /**
|
---|
1401 | * The per-CPU DBGF data kept in the UVM.
|
---|
1402 | */
|
---|
1403 | typedef struct DBGFUSERPERVMCPU
|
---|
1404 | {
|
---|
1405 | /** The guest register set for this CPU. Can be NULL. */
|
---|
1406 | R3PTRTYPE(struct DBGFREGSET *) pGuestRegSet;
|
---|
1407 | /** The hypervisor register set for this CPU. Can be NULL. */
|
---|
1408 | R3PTRTYPE(struct DBGFREGSET *) pHyperRegSet;
|
---|
1409 |
|
---|
1410 | /** @name Debugger -> vCPU command communication.
|
---|
1411 | * @{ */
|
---|
1412 | /** Flag whether this vCPU is currently stopped waiting in the debugger. */
|
---|
1413 | bool volatile fStopped;
|
---|
1414 | /** The Command to the vCPU.
|
---|
1415 | * Operated in an atomic fashion since the vCPU will poll on this.
|
---|
1416 | * This means that a the command data must be written before this member
|
---|
1417 | * is set. The VMM will reset this member to the no-command state
|
---|
1418 | * when it have processed it.
|
---|
1419 | */
|
---|
1420 | DBGFCMD volatile enmDbgfCmd;
|
---|
1421 | /** The Command data.
|
---|
1422 | * Not all commands take data. */
|
---|
1423 | DBGFCMDDATA DbgfCmdData;
|
---|
1424 | /** @} */
|
---|
1425 |
|
---|
1426 | } DBGFUSERPERVMCPU;
|
---|
1427 |
|
---|
1428 |
|
---|
1429 | #ifdef IN_RING3
|
---|
1430 | int dbgfR3AsInit(PUVM pUVM);
|
---|
1431 | void dbgfR3AsTerm(PUVM pUVM);
|
---|
1432 | void dbgfR3AsRelocate(PUVM pUVM, RTGCUINTPTR offDelta);
|
---|
1433 | DECLHIDDEN(int) dbgfR3BpInit(PUVM pUVM);
|
---|
1434 | DECLHIDDEN(int) dbgfR3BpTerm(PUVM pUVM);
|
---|
1435 | int dbgfR3InfoInit(PUVM pUVM);
|
---|
1436 | int dbgfR3InfoTerm(PUVM pUVM);
|
---|
1437 | int dbgfR3OSInit(PUVM pUVM);
|
---|
1438 | void dbgfR3OSTermPart1(PUVM pUVM);
|
---|
1439 | void dbgfR3OSTermPart2(PUVM pUVM);
|
---|
1440 | int dbgfR3OSStackUnwindAssist(PUVM pUVM, VMCPUID idCpu, PDBGFSTACKFRAME pFrame, PRTDBGUNWINDSTATE pState,
|
---|
1441 | PCCPUMCTX pInitialCtx, RTDBGAS hAs, uint64_t *puScratch);
|
---|
1442 | int dbgfR3RegInit(PUVM pUVM);
|
---|
1443 | void dbgfR3RegTerm(PUVM pUVM);
|
---|
1444 | int dbgfR3TraceInit(PVM pVM);
|
---|
1445 | void dbgfR3TraceRelocate(PVM pVM);
|
---|
1446 | void dbgfR3TraceTerm(PVM pVM);
|
---|
1447 | DECLHIDDEN(int) dbgfR3TypeInit(PUVM pUVM);
|
---|
1448 | DECLHIDDEN(void) dbgfR3TypeTerm(PUVM pUVM);
|
---|
1449 | int dbgfR3PlugInInit(PUVM pUVM);
|
---|
1450 | void dbgfR3PlugInTerm(PUVM pUVM);
|
---|
1451 | int dbgfR3BugCheckInit(PVM pVM);
|
---|
1452 | DECLHIDDEN(int) dbgfR3TracerInit(PVM pVM);
|
---|
1453 | DECLHIDDEN(void) dbgfR3TracerTerm(PVM pVM);
|
---|
1454 |
|
---|
1455 | /**
|
---|
1456 | * DBGF disassembler state (substate of DISSTATE).
|
---|
1457 | */
|
---|
1458 | typedef struct DBGFDISSTATE
|
---|
1459 | {
|
---|
1460 | /** Pointer to the current instruction. */
|
---|
1461 | PCDISOPCODE pCurInstr;
|
---|
1462 | /** Size of the instruction in bytes. */
|
---|
1463 | uint32_t cbInstr;
|
---|
1464 | /** Parameters. */
|
---|
1465 | DISOPPARAM Param1;
|
---|
1466 | DISOPPARAM Param2;
|
---|
1467 | DISOPPARAM Param3;
|
---|
1468 | DISOPPARAM Param4;
|
---|
1469 | } DBGFDISSTATE;
|
---|
1470 | /** Pointer to a DBGF disassembler state. */
|
---|
1471 | typedef DBGFDISSTATE *PDBGFDISSTATE;
|
---|
1472 |
|
---|
1473 | DECLHIDDEN(int) dbgfR3DisasInstrStateEx(PUVM pUVM, VMCPUID idCpu, PDBGFADDRESS pAddr, uint32_t fFlags,
|
---|
1474 | char *pszOutput, uint32_t cbOutput, PDBGFDISSTATE pDisState);
|
---|
1475 |
|
---|
1476 | #endif /* IN_RING3 */
|
---|
1477 |
|
---|
1478 | #ifdef IN_RING0
|
---|
1479 | DECLHIDDEN(void) dbgfR0TracerDestroy(PGVM pGVM, PDBGFTRACERINSR0 pTracer);
|
---|
1480 | DECLHIDDEN(void) dbgfR0BpInit(PGVM pGVM);
|
---|
1481 | DECLHIDDEN(void) dbgfR0BpDestroy(PGVM pGVM);
|
---|
1482 | #endif /* !IN_RING0 */
|
---|
1483 |
|
---|
1484 | /** @} */
|
---|
1485 |
|
---|
1486 | #endif /* !VMM_INCLUDED_SRC_include_DBGFInternal_h */
|
---|