VirtualBox

source: vbox/trunk/src/VBox/VMM/include/DBGFInternal.h@ 86699

Last change on this file since 86699 was 86699, checked in by vboxsync, 5 years ago

VMM/DBGF: Updates to the new breakpoint manager, implement global breakpoint table chunk allocation and register breakpoints which should work again, bugref:9837

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

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