VirtualBox

source: vbox/trunk/include/iprt/dbg.h@ 73768

Last change on this file since 73768 was 73761, checked in by vboxsync, 6 years ago

IPRT/Dbg: Added simple stack formatter for the current thread.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 75.8 KB
Line 
1/* $Id: dbg.h 73761 2018-08-19 13:42:25Z vboxsync $ */
2/** @file
3 * IPRT - Debugging Routines.
4 */
5
6/*
7 * Copyright (C) 2008-2017 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___iprt_dbg_h
28#define ___iprt_dbg_h
29
30#include <iprt/types.h>
31#include <iprt/stdarg.h>
32#include <iprt/ldr.h>
33
34RT_C_DECLS_BEGIN
35
36
37/** @defgroup grp_rt_dbg RTDbg - Debugging Routines
38 * @ingroup grp_rt
39 * @{
40 */
41
42
43/** Debug segment index. */
44typedef uint32_t RTDBGSEGIDX;
45/** Pointer to a debug segment index. */
46typedef RTDBGSEGIDX *PRTDBGSEGIDX;
47/** Pointer to a const debug segment index. */
48typedef RTDBGSEGIDX const *PCRTDBGSEGIDX;
49/** NIL debug segment index. */
50#define NIL_RTDBGSEGIDX UINT32_C(0xffffffff)
51/** The last normal segment index. */
52#define RTDBGSEGIDX_LAST UINT32_C(0xffffffef)
53/** Special segment index that indicates that the offset is a relative
54 * virtual address (RVA). I.e. an offset from the start of the module. */
55#define RTDBGSEGIDX_RVA UINT32_C(0xfffffff0)
56/** Special segment index that indicates that the offset is a absolute. */
57#define RTDBGSEGIDX_ABS UINT32_C(0xfffffff1)
58/** The last valid special segment index. */
59#define RTDBGSEGIDX_SPECIAL_LAST RTDBGSEGIDX_ABS
60/** The last valid special segment index. */
61#define RTDBGSEGIDX_SPECIAL_FIRST (RTDBGSEGIDX_LAST + 1U)
62
63
64
65/** @name RTDBGSYMADDR_FLAGS_XXX
66 * Flags used when looking up a symbol by address.
67 * @{ */
68/** Less or equal address. (default) */
69#define RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL UINT32_C(0)
70/** Greater or equal address. */
71#define RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL UINT32_C(1)
72/** Don't consider absolute symbols in deferred modules. */
73#define RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED UINT32_C(2)
74/** Don't search for absolute symbols if it's expensive. */
75#define RTDBGSYMADDR_FLAGS_SKIP_ABS UINT32_C(4)
76/** Mask of valid flags. */
77#define RTDBGSYMADDR_FLAGS_VALID_MASK UINT32_C(7)
78/** @} */
79
80
81/** Max length (including '\\0') of a segment name. */
82#define RTDBG_SEGMENT_NAME_LENGTH (128 - 8 - 8 - 8 - 4 - 4)
83
84/**
85 * Debug module segment.
86 */
87typedef struct RTDBGSEGMENT
88{
89 /** The load address.
90 * RTUINTPTR_MAX if not applicable. */
91 RTUINTPTR Address;
92 /** The image relative virtual address of the segment.
93 * RTUINTPTR_MAX if not applicable. */
94 RTUINTPTR uRva;
95 /** The segment size. */
96 RTUINTPTR cb;
97 /** The segment flags. (reserved) */
98 uint32_t fFlags;
99 /** The segment index. */
100 RTDBGSEGIDX iSeg;
101 /** Symbol name. */
102 char szName[RTDBG_SEGMENT_NAME_LENGTH];
103} RTDBGSEGMENT;
104/** Pointer to a debug module segment. */
105typedef RTDBGSEGMENT *PRTDBGSEGMENT;
106/** Pointer to a const debug module segment. */
107typedef RTDBGSEGMENT const *PCRTDBGSEGMENT;
108
109
110/**
111 * Return type.
112 */
113typedef enum RTDBGRETURNTYPE
114{
115 /** The usual invalid 0 value. */
116 RTDBGRETURNTYPE_INVALID = 0,
117 /** Near 16-bit return. */
118 RTDBGRETURNTYPE_NEAR16,
119 /** Near 32-bit return. */
120 RTDBGRETURNTYPE_NEAR32,
121 /** Near 64-bit return. */
122 RTDBGRETURNTYPE_NEAR64,
123 /** Far 16:16 return. */
124 RTDBGRETURNTYPE_FAR16,
125 /** Far 16:32 return. */
126 RTDBGRETURNTYPE_FAR32,
127 /** Far 16:64 return. */
128 RTDBGRETURNTYPE_FAR64,
129 /** 16-bit iret return (e.g. real or 286 protect mode). */
130 RTDBGRETURNTYPE_IRET16,
131 /** 32-bit iret return. */
132 RTDBGRETURNTYPE_IRET32,
133 /** 32-bit iret return. */
134 RTDBGRETURNTYPE_IRET32_PRIV,
135 /** 32-bit iret return to V86 mode. */
136 RTDBGRETURNTYPE_IRET32_V86,
137 /** @todo 64-bit iret return. */
138 RTDBGRETURNTYPE_IRET64,
139 /** The end of the valid return types. */
140 RTDBGRETURNTYPE_END,
141 /** The usual 32-bit blowup. */
142 RTDBGRETURNTYPE_32BIT_HACK = 0x7fffffff
143} RTDBGRETURNTYPE;
144
145/**
146 * Figures the size of the return state on the stack.
147 *
148 * @returns number of bytes. 0 if invalid parameter.
149 * @param enmRetType The type of return.
150 */
151DECLINLINE(unsigned) RTDbgReturnTypeSize(RTDBGRETURNTYPE enmRetType)
152{
153 switch (enmRetType)
154 {
155 case RTDBGRETURNTYPE_NEAR16: return 2;
156 case RTDBGRETURNTYPE_NEAR32: return 4;
157 case RTDBGRETURNTYPE_NEAR64: return 8;
158 case RTDBGRETURNTYPE_FAR16: return 4;
159 case RTDBGRETURNTYPE_FAR32: return 4;
160 case RTDBGRETURNTYPE_FAR64: return 8;
161 case RTDBGRETURNTYPE_IRET16: return 6;
162 case RTDBGRETURNTYPE_IRET32: return 4*3;
163 case RTDBGRETURNTYPE_IRET32_PRIV: return 4*5;
164 case RTDBGRETURNTYPE_IRET32_V86: return 4*9;
165 case RTDBGRETURNTYPE_IRET64: return 5*8;
166
167 case RTDBGRETURNTYPE_INVALID:
168 case RTDBGRETURNTYPE_END:
169 case RTDBGRETURNTYPE_32BIT_HACK:
170 break;
171 }
172 return 0;
173}
174
175/**
176 * Check if near return.
177 *
178 * @returns true if near, false if far or iret.
179 * @param enmRetType The type of return.
180 */
181DECLINLINE(bool) RTDbgReturnTypeIsNear(RTDBGRETURNTYPE enmRetType)
182{
183 return enmRetType == RTDBGRETURNTYPE_NEAR32
184 || enmRetType == RTDBGRETURNTYPE_NEAR64
185 || enmRetType == RTDBGRETURNTYPE_NEAR16;
186}
187
188
189
190/** Magic value for RTDBGUNWINDSTATE::u32Magic (James Moody). */
191#define RTDBGUNWINDSTATE_MAGIC UINT32_C(0x19250326)
192/** Magic value for RTDBGUNWINDSTATE::u32Magic after use. */
193#define RTDBGUNWINDSTATE_MAGIC_DEAD UINT32_C(0x20101209)
194
195/**
196 * Unwind machine state.
197 */
198typedef struct RTDBGUNWINDSTATE
199{
200 /** Structure magic (RTDBGUNWINDSTATE_MAGIC) */
201 uint32_t u32Magic;
202 /** The state architecture. */
203 RTLDRARCH enmArch;
204
205 /** The program counter register.
206 * amd64/x86: RIP/EIP/IP
207 * sparc: PC
208 * arm32: PC / R15
209 */
210 uint64_t uPc;
211
212 /** Return type. */
213 RTDBGRETURNTYPE enmRetType;
214
215 /** Register state (see enmArch). */
216 union
217 {
218 /** RTLDRARCH_AMD64, RTLDRARCH_X86_32 and RTLDRARCH_X86_16. */
219 struct
220 {
221 /** General purpose registers indexed by X86_GREG_XXX. */
222 uint64_t auRegs[16];
223 /** The frame address. */
224 RTFAR64 FrameAddr;
225 /** Set if we're in real or virtual 8086 mode. */
226 bool fRealOrV86;
227 /** The flags register. */
228 uint64_t uRFlags;
229 /** Trap error code. */
230 uint64_t uErrCd;
231 /** Segment registers (indexed by X86_SREG_XXX). */
232 uint16_t auSegs[6];
233
234 /** Bitmap tracking register we've loaded and which content can possibly be trusted. */
235 union
236 {
237 /** For effective clearing of the bits. */
238 uint32_t fAll;
239 /** Detailed view. */
240 struct
241 {
242 /** Bitmap indicating whether a GPR was loaded (parallel to auRegs). */
243 uint16_t fRegs;
244 /** Bitmap indicating whether a segment register was loaded (parallel to auSegs). */
245 uint8_t fSegs;
246 /** Set if uPc was loaded. */
247 RT_GCC_EXTENSION uint8_t fPc : 1;
248 /** Set if FrameAddr was loaded. */
249 RT_GCC_EXTENSION uint8_t fFrameAddr : 1;
250 /** Set if uRFlags was loaded. */
251 RT_GCC_EXTENSION uint8_t fRFlags : 1;
252 /** Set if uErrCd was loaded. */
253 RT_GCC_EXTENSION uint8_t fErrCd : 1;
254 } s;
255 } Loaded;
256 } x86;
257
258 /** @todo add ARM and others as needed. */
259 } u;
260
261 /**
262 * Stack read callback.
263 *
264 * @returns IPRT status code.
265 * @param pThis Pointer to this structure.
266 * @param uSp The stack pointer address.
267 * @param cbToRead The number of bytes to read.
268 * @param pvDst Where to put the bytes we read.
269 */
270 DECLCALLBACKMEMBER(int, pfnReadStack)(struct RTDBGUNWINDSTATE *pThis, RTUINTPTR uSp, size_t cbToRead, void *pvDst);
271 /** User argument (useful for pfnReadStack). */
272 void *pvUser;
273
274} RTDBGUNWINDSTATE;
275
276/**
277 * Try read a 16-bit value off the stack.
278 *
279 * @returns pfnReadStack result.
280 * @param pThis The unwind state.
281 * @param uSrcAddr The stack address.
282 * @param puDst The read destination.
283 */
284DECLINLINE(int) RTDbgUnwindLoadStackU16(PRTDBGUNWINDSTATE pThis, RTUINTPTR uSrcAddr, uint16_t *puDst)
285{
286 return pThis->pfnReadStack(pThis, uSrcAddr, sizeof(*puDst), puDst);
287}
288
289/**
290 * Try read a 32-bit value off the stack.
291 *
292 * @returns pfnReadStack result.
293 * @param pThis The unwind state.
294 * @param uSrcAddr The stack address.
295 * @param puDst The read destination.
296 */
297DECLINLINE(int) RTDbgUnwindLoadStackU32(PRTDBGUNWINDSTATE pThis, RTUINTPTR uSrcAddr, uint32_t *puDst)
298{
299 return pThis->pfnReadStack(pThis, uSrcAddr, sizeof(*puDst), puDst);
300}
301
302/**
303 * Try read a 64-bit value off the stack.
304 *
305 * @returns pfnReadStack result.
306 * @param pThis The unwind state.
307 * @param uSrcAddr The stack address.
308 * @param puDst The read destination.
309 */
310DECLINLINE(int) RTDbgUnwindLoadStackU64(PRTDBGUNWINDSTATE pThis, RTUINTPTR uSrcAddr, uint64_t *puDst)
311{
312 return pThis->pfnReadStack(pThis, uSrcAddr, sizeof(*puDst), puDst);
313}
314
315
316
317/** Max length (including '\\0') of a symbol name. */
318#define RTDBG_SYMBOL_NAME_LENGTH (512 - 8 - 8 - 8 - 4 - 4 - 8)
319
320/**
321 * Debug symbol.
322 */
323typedef struct RTDBGSYMBOL
324{
325 /** Symbol value (address).
326 * This depends a bit who you ask. It will be the same as offSeg when you
327 * as RTDbgMod, but the mapping address if you ask RTDbgAs. */
328 RTUINTPTR Value;
329 /** Symbol size. */
330 RTUINTPTR cb;
331 /** Offset into the segment specified by iSeg. */
332 RTUINTPTR offSeg;
333 /** Segment number. */
334 RTDBGSEGIDX iSeg;
335 /** Symbol Flags. (reserved). */
336 uint32_t fFlags;
337 /** Symbol ordinal.
338 * This is set to UINT32_MAX if the ordinals aren't supported. */
339 uint32_t iOrdinal;
340 /** Symbol name. */
341 char szName[RTDBG_SYMBOL_NAME_LENGTH];
342} RTDBGSYMBOL;
343/** Pointer to debug symbol. */
344typedef RTDBGSYMBOL *PRTDBGSYMBOL;
345/** Pointer to const debug symbol. */
346typedef const RTDBGSYMBOL *PCRTDBGSYMBOL;
347
348
349/**
350 * Allocate a new symbol structure.
351 *
352 * @returns Pointer to a new structure on success, NULL on failure.
353 */
354RTDECL(PRTDBGSYMBOL) RTDbgSymbolAlloc(void);
355
356/**
357 * Duplicates a symbol structure.
358 *
359 * @returns Pointer to duplicate on success, NULL on failure.
360 *
361 * @param pSymInfo The symbol info to duplicate.
362 */
363RTDECL(PRTDBGSYMBOL) RTDbgSymbolDup(PCRTDBGSYMBOL pSymInfo);
364
365/**
366 * Free a symbol structure previously allocated by a RTDbg method.
367 *
368 * @param pSymInfo The symbol info to free. NULL is ignored.
369 */
370RTDECL(void) RTDbgSymbolFree(PRTDBGSYMBOL pSymInfo);
371
372
373/** Max length (including '\\0') of a debug info file name. */
374#define RTDBG_FILE_NAME_LENGTH (260)
375
376
377/**
378 * Debug line number information.
379 */
380typedef struct RTDBGLINE
381{
382 /** Address.
383 * This depends a bit who you ask. It will be the same as offSeg when you
384 * as RTDbgMod, but the mapping address if you ask RTDbgAs. */
385 RTUINTPTR Address;
386 /** Offset into the segment specified by iSeg. */
387 RTUINTPTR offSeg;
388 /** Segment number. */
389 RTDBGSEGIDX iSeg;
390 /** Line number. */
391 uint32_t uLineNo;
392 /** Symbol ordinal.
393 * This is set to UINT32_MAX if the ordinals aren't supported. */
394 uint32_t iOrdinal;
395 /** Filename. */
396 char szFilename[RTDBG_FILE_NAME_LENGTH];
397} RTDBGLINE;
398/** Pointer to debug line number. */
399typedef RTDBGLINE *PRTDBGLINE;
400/** Pointer to const debug line number. */
401typedef const RTDBGLINE *PCRTDBGLINE;
402
403/**
404 * Allocate a new line number structure.
405 *
406 * @returns Pointer to a new structure on success, NULL on failure.
407 */
408RTDECL(PRTDBGLINE) RTDbgLineAlloc(void);
409
410/**
411 * Duplicates a line number structure.
412 *
413 * @returns Pointer to duplicate on success, NULL on failure.
414 *
415 * @param pLine The line number to duplicate.
416 */
417RTDECL(PRTDBGLINE) RTDbgLineDup(PCRTDBGLINE pLine);
418
419/**
420 * Free a line number structure previously allocated by a RTDbg method.
421 *
422 * @param pLine The line number to free. NULL is ignored.
423 */
424RTDECL(void) RTDbgLineFree(PRTDBGLINE pLine);
425
426
427/**
428 * Dump the stack of the current thread into @a pszStack.
429 *
430 * This could be a little slow as it reads image and debug info again for each call.
431 *
432 * @returns Length of string returned in @a pszStack.
433 * @param pszStack The output buffer.
434 * @param cbStack The size of the output buffer.
435 * @param fFlags Future flags, MBZ.
436 *
437 * @remarks Not present on all systems and contexts.
438 */
439RTDECL(size_t) RTDbgStackDumpSelf(char *pszStack, size_t cbStack, uint32_t fFlags);
440
441
442# ifdef IN_RING3
443
444/** @defgroup grp_rt_dbgcfg RTDbgCfg - Debugging Configuration
445 *
446 * The settings used when loading and processing debug info is kept in a
447 * RTDBGCFG instance since it's generally shared for a whole debugging session
448 * and anyhow would be a major pain to pass as individual parameters to each
449 * call. The debugging config API not only keeps the settings information but
450 * also provide APIs for making use of it, and in some cases, like for instance
451 * symbol severs, retriving and maintaining it.
452 *
453 * @todo Work in progress - APIs are still missing, adding when needed.
454 *
455 * @{
456 */
457
458/** Debugging configuration handle. */
459typedef struct RTDBGCFGINT *RTDBGCFG;
460/** Pointer to a debugging configuration handle. */
461typedef RTDBGCFG *PRTDBGCFG;
462/** NIL debug configuration handle. */
463#define NIL_RTDBGCFG ((RTDBGCFG)0)
464
465/** @name RTDBGCFG_FLAGS_XXX - Debugging configuration flags.
466 * @{ */
467/** Use deferred loading. */
468#define RTDBGCFG_FLAGS_DEFERRED RT_BIT_64(0)
469/** Don't use the symbol server (http). */
470#define RTDBGCFG_FLAGS_NO_SYM_SRV RT_BIT_64(1)
471/** Don't use system search paths.
472 * On windows this means not using _NT_ALT_SYMBOL_PATH, _NT_SYMBOL_PATH,
473 * _NT_SOURCE_PATH, and _NT_EXECUTABLE_PATH.
474 * On other systems the effect has yet to be determined. */
475#define RTDBGCFG_FLAGS_NO_SYSTEM_PATHS RT_BIT_64(2)
476/** Don't search the debug and image paths recursively. */
477#define RTDBGCFG_FLAGS_NO_RECURSIV_SEARCH RT_BIT_64(3)
478/** Don't search the source paths recursively. */
479#define RTDBGCFG_FLAGS_NO_RECURSIV_SRC_SEARCH RT_BIT_64(4)
480/** @} */
481
482/**
483 * Debugging configuration properties.
484 *
485 * The search paths are using the DOS convention of semicolon as separator
486 * character. The the special 'srv' + asterisk syntax known from the windows
487 * debugger search paths are also supported to some extent, as is 'cache' +
488 * asterisk.
489 */
490typedef enum RTDBGCFGPROP
491{
492 /** The customary invalid 0 value. */
493 RTDBGCFGPROP_INVALID = 0,
494 /** RTDBGCFG_FLAGS_XXX.
495 * Env: _FLAGS
496 * The environment variable can be specified as a unsigned value or one or more
497 * mnemonics separated by spaces. */
498 RTDBGCFGPROP_FLAGS,
499 /** List of paths to search for symbol files and images.
500 * Env: _PATH */
501 RTDBGCFGPROP_PATH,
502 /** List of symbol file suffixes (semicolon separated).
503 * Env: _SUFFIXES */
504 RTDBGCFGPROP_SUFFIXES,
505 /** List of paths to search for source files.
506 * Env: _SRC_PATH */
507 RTDBGCFGPROP_SRC_PATH,
508 /** End of valid values. */
509 RTDBGCFGPROP_END,
510 /** The customary 32-bit type hack. */
511 RTDBGCFGPROP_32BIT_HACK = 0x7fffffff
512} RTDBGCFGPROP;
513
514/**
515 * Configuration property change operation.
516 */
517typedef enum RTDBGCFGOP
518{
519 /** Customary invalid 0 value. */
520 RTDBGCFGOP_INVALID = 0,
521 /** Replace the current value with the given one. */
522 RTDBGCFGOP_SET,
523 /** Append the given value to the existing one. For integer values this is
524 * considered a bitwise OR operation. */
525 RTDBGCFGOP_APPEND,
526 /** Prepend the given value to the existing one. For integer values this is
527 * considered a bitwise OR operation. */
528 RTDBGCFGOP_PREPEND,
529 /** Removes the value from the existing one. For interger values the value is
530 * complemented and ANDed with the existing one, clearing all the specified
531 * flags/bits. */
532 RTDBGCFGOP_REMOVE,
533 /** End of valid values. */
534 RTDBGCFGOP_END,
535 /** Customary 32-bit type hack. */
536 RTDBGCFGOP_32BIT_HACK = 0x7fffffff
537} RTDBGCFGOP;
538
539
540
541/**
542 * Initializes a debugging configuration.
543 *
544 * @returns IPRT status code.
545 * @param phDbgCfg Where to return the configuration handle.
546 * @param pszEnvVarPrefix The environment variable prefix. If NULL, the
547 * environment is not consulted.
548 * @param fNativePaths Whether to pick up native paths from the
549 * environment.
550 *
551 * @sa RTDbgCfgChangeString, RTDbgCfgChangeUInt.
552 */
553RTDECL(int) RTDbgCfgCreate(PRTDBGCFG phDbgCfg, const char *pszEnvVarPrefix, bool fNativePaths);
554
555/**
556 * Retains a new reference to a debugging config.
557 *
558 * @returns New reference count.
559 * UINT32_MAX is returned if the handle is invalid (asserted).
560 * @param hDbgCfg The config handle.
561 */
562RTDECL(uint32_t) RTDbgCfgRetain(RTDBGCFG hDbgCfg);
563
564/**
565 * Releases a references to a debugging config.
566 *
567 * @returns New reference count, if 0 the config was freed. UINT32_MAX is
568 * returned if the handle is invalid (asserted).
569 * @param hDbgCfg The config handle.
570 */
571RTDECL(uint32_t) RTDbgCfgRelease(RTDBGCFG hDbgCfg);
572
573/**
574 * Changes a property value by string.
575 *
576 * For string values the string is used more or less as given. For integer
577 * values and flags, it can contains both values (ORed together) or property
578 * specific mnemonics (ORed / ~ANDed).
579 *
580 * @returns IPRT status code.
581 * @retval VERR_DBG_CFG_INVALID_VALUE
582 * @param hDbgCfg The debugging configuration handle.
583 * @param enmProp The property to change.
584 * @param enmOp How to change the property.
585 * @param pszValue The property value to apply.
586 */
587RTDECL(int) RTDbgCfgChangeString(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, RTDBGCFGOP enmOp, const char *pszValue);
588
589/**
590 * Changes a property value by unsigned integer (64-bit).
591 *
592 * This can only be applied to integer and flag properties.
593 *
594 * @returns IPRT status code.
595 * @retval VERR_DBG_CFG_NOT_UINT_PROP
596 * @param hDbgCfg The debugging configuration handle.
597 * @param enmProp The property to change.
598 * @param enmOp How to change the property.
599 * @param uValue The property value to apply.
600 */
601RTDECL(int) RTDbgCfgChangeUInt(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, RTDBGCFGOP enmOp, uint64_t uValue);
602
603/**
604 * Query a property value as string.
605 *
606 * Integer and flags properties are returned as a list of mnemonics if possible,
607 * otherwise as simple hex values.
608 *
609 * @returns IPRT status code.
610 * @retval VERR_BUFFER_OVERFLOW if there isn't sufficient buffer space. Nothing
611 * is written.
612 * @param hDbgCfg The debugging configuration handle.
613 * @param enmProp The property to change.
614 * @param pszValue The output buffer.
615 * @param cbValue The size of the output buffer.
616 */
617RTDECL(int) RTDbgCfgQueryString(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, char *pszValue, size_t cbValue);
618
619/**
620 * Query a property value as unsigned integer (64-bit).
621 *
622 * Only integer and flags properties can be queried this way.
623 *
624 * @returns IPRT status code.
625 * @retval VERR_DBG_CFG_NOT_UINT_PROP
626 * @param hDbgCfg The debugging configuration handle.
627 * @param enmProp The property to change.
628 * @param puValue Where to return the value.
629 */
630RTDECL(int) RTDbgCfgQueryUInt(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, uint64_t *puValue);
631
632/**
633 * Log callback.
634 *
635 * @param hDbgCfg The debug config instance.
636 * @param iLevel The message level.
637 * @param pszMsg The message.
638 * @param pvUser User argument.
639 */
640typedef DECLCALLBACK(void) FNRTDBGCFGLOG(RTDBGCFG hDbgCfg, uint32_t iLevel, const char *pszMsg, void *pvUser);
641/** Pointer to a log callback. */
642typedef FNRTDBGCFGLOG *PFNRTDBGCFGLOG;
643
644/**
645 * Sets the log callback for the configuration.
646 *
647 * This will fail if there is already a log callback present, unless pfnCallback
648 * is NULL.
649 *
650 * @returns IPRT status code.
651 * @param hDbgCfg The debugging configuration handle.
652 * @param pfnCallback The callback function. NULL to unset.
653 * @param pvUser The user argument.
654 */
655RTDECL(int) RTDbgCfgSetLogCallback(RTDBGCFG hDbgCfg, PFNRTDBGCFGLOG pfnCallback, void *pvUser);
656
657/**
658 * Callback used by the RTDbgCfgOpen function to try out a file that was found.
659 *
660 * @returns On statuses other than VINF_CALLBACK_RETURN and
661 * VERR_CALLBACK_RETURN the search will continue till the end of the
662 * list. These status codes will not necessarily be propagated to the
663 * caller in any consistent manner.
664 * @retval VINF_CALLBACK_RETURN if successuflly opened the file and it's time
665 * to return
666 * @retval VERR_CALLBACK_RETURN if we shouldn't stop searching.
667 *
668 * @param hDbgCfg The debugging configuration handle.
669 * @param pszFilename The path to the file that should be tried out.
670 * @param pvUser1 First user parameter.
671 * @param pvUser2 Second user parameter.
672 */
673typedef DECLCALLBACK(int) FNRTDBGCFGOPEN(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2);
674/** Pointer to a open-file callback used to the RTDbgCfgOpen functions. */
675typedef FNRTDBGCFGOPEN *PFNRTDBGCFGOPEN;
676
677
678RTDECL(int) RTDbgCfgOpenPeImage(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t cbImage, uint32_t uTimestamp,
679 PFNRTDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
680RTDECL(int) RTDbgCfgOpenPdb70(RTDBGCFG hDbgCfg, const char *pszFilename, PCRTUUID pUuid, uint32_t uAge,
681 PFNRTDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
682RTDECL(int) RTDbgCfgOpenPdb20(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t cbImage, uint32_t uTimestamp, uint32_t uAge,
683 PFNRTDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
684RTDECL(int) RTDbgCfgOpenDbg(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t cbImage, uint32_t uTimestamp,
685 PFNRTDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
686RTDECL(int) RTDbgCfgOpenDwo(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t uCrc32,
687 PFNRTDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
688RTDECL(int) RTDbgCfgOpenDsymBundle(RTDBGCFG hDbgCfg, const char *pszFilename, PCRTUUID pUuid,
689 PFNRTDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
690RTDECL(int) RTDbgCfgOpenMachOImage(RTDBGCFG hDbgCfg, const char *pszFilename, PCRTUUID pUuid,
691 PFNRTDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
692
693
694/** @name Static symbol cache configuration
695 * @{ */
696/** The cache subdirectory containing the UUID mappings for .dSYM bundles.
697 * The UUID mappings implemented by IPRT are splitting the image/dsym UUID up
698 * into five 4 digit parts that maps to directories and one twelve digit part
699 * that maps to a symbolic link. The symlink points to the file in the
700 * Contents/Resources/DWARF/ directory of the .dSYM bundle for a .dSYM map, and
701 * to the image file (Contents/MacOS/bundlename for bundles) for image map.
702 *
703 * According to available documentation, both lldb and gdb are able to use these
704 * UUID maps to find debug info while debugging. See:
705 * http://lldb.llvm.org/symbols.html
706 */
707#define RTDBG_CACHE_UUID_MAP_DIR_DSYMS "dsym-uuids"
708/** The cache subdirectory containing the UUID mappings for image files. */
709#define RTDBG_CACHE_UUID_MAP_DIR_IMAGES "image-uuids"
710/** Suffix used for the cached .dSYM debug files.
711 * In .dSYM bundles only the .dSYM/Contents/Resources/DWARF/debug-file is
712 * copied into the cache, and in order to not clash with the stripped/rich image
713 * file, the cache tool slaps this suffix onto the name. */
714#define RTDBG_CACHE_DSYM_FILE_SUFFIX ".dwarf"
715/** @} */
716
717# endif /* IN_RING3 */
718
719/** @} */
720
721
722/** @defgroup grp_rt_dbgas RTDbgAs - Debug Address Space
723 * @{
724 */
725
726/**
727 * Creates an empty address space.
728 *
729 * @returns IPRT status code.
730 *
731 * @param phDbgAs Where to store the address space handle on success.
732 * @param FirstAddr The first address in the address space.
733 * @param LastAddr The last address in the address space.
734 * @param pszName The name of the address space.
735 */
736RTDECL(int) RTDbgAsCreate(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszName);
737
738/**
739 * Variant of RTDbgAsCreate that takes a name format string.
740 *
741 * @returns IPRT status code.
742 *
743 * @param phDbgAs Where to store the address space handle on success.
744 * @param FirstAddr The first address in the address space.
745 * @param LastAddr The last address in the address space.
746 * @param pszNameFmt The name format of the address space.
747 * @param va Format arguments.
748 */
749RTDECL(int) RTDbgAsCreateV(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr,
750 const char *pszNameFmt, va_list va) RT_IPRT_FORMAT_ATTR(4, 0);
751
752/**
753 * Variant of RTDbgAsCreate that takes a name format string.
754 *
755 * @returns IPRT status code.
756 *
757 * @param phDbgAs Where to store the address space handle on success.
758 * @param FirstAddr The first address in the address space.
759 * @param LastAddr The last address in the address space.
760 * @param pszNameFmt The name format of the address space.
761 * @param ... Format arguments.
762 */
763RTDECL(int) RTDbgAsCreateF(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr,
764 const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(4, 5);
765
766/**
767 * Retains a reference to the address space.
768 *
769 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
770 *
771 * @param hDbgAs The address space handle.
772 *
773 * @remarks Will not take any locks.
774 */
775RTDECL(uint32_t) RTDbgAsRetain(RTDBGAS hDbgAs);
776
777/**
778 * Release a reference to the address space.
779 *
780 * When the reference count reaches zero, the address space is destroyed.
781 * That means unlinking all the modules it currently contains, potentially
782 * causing some or all of them to be destroyed as they are managed by
783 * reference counting.
784 *
785 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
786 *
787 * @param hDbgAs The address space handle. The NIL handle is quietly
788 * ignored and 0 is returned.
789 *
790 * @remarks Will not take any locks.
791 */
792RTDECL(uint32_t) RTDbgAsRelease(RTDBGAS hDbgAs);
793
794/**
795 * Locks the address space for exclusive access.
796 *
797 * @returns IRPT status code
798 * @param hDbgAs The address space handle.
799 */
800RTDECL(int) RTDbgAsLockExcl(RTDBGAS hDbgAs);
801
802/**
803 * Counters the actions of one RTDbgAsUnlockExcl call.
804 *
805 * @returns IRPT status code
806 * @param hDbgAs The address space handle.
807 */
808RTDECL(int) RTDbgAsUnlockExcl(RTDBGAS hDbgAs);
809
810/**
811 * Gets the name of an address space.
812 *
813 * @returns read only address space name.
814 * NULL if hDbgAs is invalid.
815 *
816 * @param hDbgAs The address space handle.
817 *
818 * @remarks Will not take any locks.
819 */
820RTDECL(const char *) RTDbgAsName(RTDBGAS hDbgAs);
821
822/**
823 * Gets the first address in an address space.
824 *
825 * @returns The address.
826 * 0 if hDbgAs is invalid.
827 *
828 * @param hDbgAs The address space handle.
829 *
830 * @remarks Will not take any locks.
831 */
832RTDECL(RTUINTPTR) RTDbgAsFirstAddr(RTDBGAS hDbgAs);
833
834/**
835 * Gets the last address in an address space.
836 *
837 * @returns The address.
838 * 0 if hDbgAs is invalid.
839 *
840 * @param hDbgAs The address space handle.
841 *
842 * @remarks Will not take any locks.
843 */
844RTDECL(RTUINTPTR) RTDbgAsLastAddr(RTDBGAS hDbgAs);
845
846/**
847 * Gets the number of modules in the address space.
848 *
849 * This can be used together with RTDbgAsModuleByIndex
850 * to enumerate the modules.
851 *
852 * @returns The number of modules.
853 *
854 * @param hDbgAs The address space handle.
855 *
856 * @remarks Will not take any locks.
857 */
858RTDECL(uint32_t) RTDbgAsModuleCount(RTDBGAS hDbgAs);
859
860/** @name Flags for RTDbgAsModuleLink and RTDbgAsModuleLinkSeg
861 * @{ */
862/** Replace all conflicting module.
863 * (The conflicting modules will be removed the address space and their
864 * references released.) */
865#define RTDBGASLINK_FLAGS_REPLACE RT_BIT_32(0)
866/** Mask containing the valid flags. */
867#define RTDBGASLINK_FLAGS_VALID_MASK UINT32_C(0x00000001)
868/** @} */
869
870/**
871 * Links a module into the address space at the give address.
872 *
873 * The size of the mapping is determined using RTDbgModImageSize().
874 *
875 * @returns IPRT status code.
876 * @retval VERR_OUT_OF_RANGE if the specified address will put the module
877 * outside the address space.
878 * @retval VERR_ADDRESS_CONFLICT if the mapping clashes with existing mappings.
879 *
880 * @param hDbgAs The address space handle.
881 * @param hDbgMod The module handle of the module to be linked in.
882 * @param ImageAddr The address to link the module at.
883 * @param fFlags See RTDBGASLINK_FLAGS_*.
884 */
885RTDECL(int) RTDbgAsModuleLink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTUINTPTR ImageAddr, uint32_t fFlags);
886
887/**
888 * Links a segment into the address space at the give address.
889 *
890 * The size of the mapping is determined using RTDbgModSegmentSize().
891 *
892 * @returns IPRT status code.
893 * @retval VERR_OUT_OF_RANGE if the specified address will put the module
894 * outside the address space.
895 * @retval VERR_ADDRESS_CONFLICT if the mapping clashes with existing mappings.
896 *
897 * @param hDbgAs The address space handle.
898 * @param hDbgMod The module handle.
899 * @param iSeg The segment number (0-based) of the segment to be
900 * linked in.
901 * @param SegAddr The address to link the segment at.
902 * @param fFlags See RTDBGASLINK_FLAGS_*.
903 */
904RTDECL(int) RTDbgAsModuleLinkSeg(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR SegAddr, uint32_t fFlags);
905
906/**
907 * Unlinks all the mappings of a module from the address space.
908 *
909 * @returns IPRT status code.
910 * @retval VERR_NOT_FOUND if the module wasn't found.
911 *
912 * @param hDbgAs The address space handle.
913 * @param hDbgMod The module handle of the module to be unlinked.
914 */
915RTDECL(int) RTDbgAsModuleUnlink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod);
916
917/**
918 * Unlinks the mapping at the specified address.
919 *
920 * @returns IPRT status code.
921 * @retval VERR_NOT_FOUND if no module or segment is mapped at that address.
922 *
923 * @param hDbgAs The address space handle.
924 * @param Addr The address within the mapping to be unlinked.
925 */
926RTDECL(int) RTDbgAsModuleUnlinkByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr);
927
928/**
929 * Get a the handle of a module in the address space by is index.
930 *
931 * @returns A retained handle to the specified module. The caller must release
932 * the returned reference.
933 * NIL_RTDBGMOD if invalid index or handle.
934 *
935 * @param hDbgAs The address space handle.
936 * @param iModule The index of the module to get.
937 *
938 * @remarks The module indexes may change after calls to RTDbgAsModuleLink,
939 * RTDbgAsModuleLinkSeg, RTDbgAsModuleUnlink and
940 * RTDbgAsModuleUnlinkByAddr.
941 */
942RTDECL(RTDBGMOD) RTDbgAsModuleByIndex(RTDBGAS hDbgAs, uint32_t iModule);
943
944/**
945 * Queries mapping module information by handle.
946 *
947 * @returns IPRT status code.
948 * @retval VERR_NOT_FOUND if no mapping was found at the specified address.
949 *
950 * @param hDbgAs The address space handle.
951 * @param Addr Address within the mapping of the module or segment.
952 * @param phMod Where to the return the retained module handle.
953 * Optional.
954 * @param pAddr Where to return the base address of the mapping.
955 * Optional.
956 * @param piSeg Where to return the segment index. This is set to
957 * NIL if the entire module is mapped as a single
958 * mapping. Optional.
959 */
960RTDECL(int) RTDbgAsModuleByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTDBGMOD phMod, PRTUINTPTR pAddr, PRTDBGSEGIDX piSeg);
961
962/**
963 * Queries mapping module information by name.
964 *
965 * @returns IPRT status code.
966 * @retval VERR_NOT_FOUND if no mapping was found at the specified address.
967 * @retval VERR_OUT_OF_RANGE if the name index was out of range.
968 *
969 * @param hDbgAs The address space handle.
970 * @param pszName The module name.
971 * @param iName There can be more than one module by the same name
972 * in an address space. This argument indicates which
973 * is meant. (0 based)
974 * @param phMod Where to the return the retained module handle.
975 */
976RTDECL(int) RTDbgAsModuleByName(RTDBGAS hDbgAs, const char *pszName, uint32_t iName, PRTDBGMOD phMod);
977
978/**
979 * Information about a mapping.
980 *
981 * This is used by RTDbgAsModuleGetMapByIndex.
982 */
983typedef struct RTDBGASMAPINFO
984{
985 /** The mapping address. */
986 RTUINTPTR Address;
987 /** The segment mapped there.
988 * This is NIL_RTDBGSEGIDX if the entire module image is mapped here. */
989 RTDBGSEGIDX iSeg;
990} RTDBGASMAPINFO;
991/** Pointer to info about an address space mapping. */
992typedef RTDBGASMAPINFO *PRTDBGASMAPINFO;
993/** Pointer to const info about an address space mapping. */
994typedef RTDBGASMAPINFO const *PCRTDBGASMAPINFO;
995
996/**
997 * Queries mapping information for a module given by index.
998 *
999 * @returns IRPT status code.
1000 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
1001 * @retval VERR_OUT_OF_RANGE if the name index was out of range.
1002 * @retval VINF_BUFFER_OVERFLOW if the array is too small and the returned
1003 * information is incomplete.
1004 *
1005 * @param hDbgAs The address space handle.
1006 * @param iModule The index of the module to get.
1007 * @param paMappings Where to return the mapping information. The buffer
1008 * size is given by *pcMappings.
1009 * @param pcMappings IN: Size of the paMappings array. OUT: The number of
1010 * entries returned.
1011 * @param fFlags Flags for reserved for future use. MBZ.
1012 *
1013 * @remarks See remarks for RTDbgAsModuleByIndex regarding the volatility of the
1014 * iModule parameter.
1015 */
1016RTDECL(int) RTDbgAsModuleQueryMapByIndex(RTDBGAS hDbgAs, uint32_t iModule, PRTDBGASMAPINFO paMappings, uint32_t *pcMappings, uint32_t fFlags);
1017
1018/**
1019 * Adds a symbol to a module in the address space.
1020 *
1021 * @returns IPRT status code. See RTDbgModSymbolAdd for more specific ones.
1022 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
1023 * @retval VERR_NOT_FOUND if no module was found at the specified address.
1024 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
1025 * custom symbols.
1026 *
1027 * @param hDbgAs The address space handle.
1028 * @param pszSymbol The symbol name.
1029 * @param Addr The address of the symbol.
1030 * @param cb The size of the symbol.
1031 * @param fFlags Symbol flags.
1032 * @param piOrdinal Where to return the symbol ordinal on success. If
1033 * the interpreter doesn't do ordinals, this will be set to
1034 * UINT32_MAX. Optional
1035 */
1036RTDECL(int) RTDbgAsSymbolAdd(RTDBGAS hDbgAs, const char *pszSymbol, RTUINTPTR Addr, RTUINTPTR cb, uint32_t fFlags, uint32_t *piOrdinal);
1037
1038/**
1039 * Query a symbol by address.
1040 *
1041 * @returns IPRT status code. See RTDbgModSymbolAddr for more specific ones.
1042 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
1043 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
1044 * @retval VERR_INVALID_PARAMETER if incorrect flags.
1045 *
1046 * @param hDbgAs The address space handle.
1047 * @param Addr The address which closest symbol is requested.
1048 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
1049 * @param poffDisp Where to return the distance between the symbol
1050 * and address. Optional.
1051 * @param pSymbol Where to return the symbol info.
1052 * @param phMod Where to return the module handle. Optional.
1053 */
1054RTDECL(int) RTDbgAsSymbolByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, uint32_t fFlags,
1055 PRTINTPTR poffDisp, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
1056
1057/**
1058 * Query a symbol by address.
1059 *
1060 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
1061 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
1062 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
1063 * @retval VERR_INVALID_PARAMETER if incorrect flags.
1064 *
1065 * @param hDbgAs The address space handle.
1066 * @param Addr The address which closest symbol is requested.
1067 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
1068 * @param poffDisp Where to return the distance between the symbol
1069 * and address. Optional.
1070 * @param ppSymInfo Where to return the pointer to the allocated symbol
1071 * info. Always set. Free with RTDbgSymbolFree.
1072 * @param phMod Where to return the module handle. Optional.
1073 */
1074RTDECL(int) RTDbgAsSymbolByAddrA(RTDBGAS hDbgAs, RTUINTPTR Addr, uint32_t fFlags,
1075 PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymInfo, PRTDBGMOD phMod);
1076
1077/**
1078 * Query a symbol by name.
1079 *
1080 * @returns IPRT status code.
1081 * @retval VERR_SYMBOL_NOT_FOUND if not found.
1082 *
1083 * @param hDbgAs The address space handle.
1084 * @param pszSymbol The symbol name. It is possible to limit the scope
1085 * of the search by prefixing the symbol with a module
1086 * name pattern followed by a bang (!) character.
1087 * RTStrSimplePatternNMatch is used for the matching.
1088 * @param pSymbol Where to return the symbol info.
1089 * @param phMod Where to return the module handle. Optional.
1090 */
1091RTDECL(int) RTDbgAsSymbolByName(RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
1092
1093/**
1094 * Query a symbol by name, allocating the returned symbol structure.
1095 *
1096 * @returns IPRT status code.
1097 * @retval VERR_SYMBOL_NOT_FOUND if not found.
1098 *
1099 * @param hDbgAs The address space handle.
1100 * @param pszSymbol The symbol name. See RTDbgAsSymbolByName for more.
1101 * @param ppSymbol Where to return the pointer to the allocated
1102 * symbol info. Always set. Free with RTDbgSymbolFree.
1103 * @param phMod Where to return the module handle. Optional.
1104 */
1105RTDECL(int) RTDbgAsSymbolByNameA(RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL *ppSymbol, PRTDBGMOD phMod);
1106
1107/**
1108 * Adds a line number to a module in the address space.
1109 *
1110 * @returns IPRT status code. See RTDbgModLineAdd for more specific ones.
1111 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
1112 * @retval VERR_NOT_FOUND if no module was found at the specified address.
1113 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
1114 * custom symbols.
1115 *
1116 * @param hDbgAs The address space handle.
1117 * @param pszFile The file name.
1118 * @param uLineNo The line number.
1119 * @param Addr The address of the symbol.
1120 * @param piOrdinal Where to return the line number ordinal on success.
1121 * If the interpreter doesn't do ordinals, this will be
1122 * set to UINT32_MAX. Optional.
1123 */
1124RTDECL(int) RTDbgAsLineAdd(RTDBGAS hDbgAs, const char *pszFile, uint32_t uLineNo, RTUINTPTR Addr, uint32_t *piOrdinal);
1125
1126/**
1127 * Query a line number by address.
1128 *
1129 * @returns IPRT status code. See RTDbgModLineAddrA for more specific ones.
1130 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
1131 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
1132 *
1133 * @param hDbgAs The address space handle.
1134 * @param Addr The address which closest symbol is requested.
1135 * @param poffDisp Where to return the distance between the line
1136 * number and address.
1137 * @param pLine Where to return the line number information.
1138 * @param phMod Where to return the module handle. Optional.
1139 */
1140RTDECL(int) RTDbgAsLineByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE pLine, PRTDBGMOD phMod);
1141
1142/**
1143 * Query a line number by address.
1144 *
1145 * @returns IPRT status code. See RTDbgModLineAddrA for more specific ones.
1146 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
1147 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
1148 *
1149 * @param hDbgAs The address space handle.
1150 * @param Addr The address which closest symbol is requested.
1151 * @param poffDisp Where to return the distance between the line
1152 * number and address.
1153 * @param ppLine Where to return the pointer to the allocated line
1154 * number info. Always set. Free with RTDbgLineFree.
1155 * @param phMod Where to return the module handle. Optional.
1156 */
1157RTDECL(int) RTDbgAsLineByAddrA(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE *ppLine, PRTDBGMOD phMod);
1158
1159/** @todo Missing some bits here. */
1160
1161/** @} */
1162
1163
1164# ifdef IN_RING3
1165/** @defgroup grp_rt_dbgmod RTDbgMod - Debug Module Interpreter
1166 * @{
1167 */
1168
1169/**
1170 * Creates a module based on the default debug info container.
1171 *
1172 * This can be used to manually load a module and its symbol. The primary user
1173 * group is the debug info interpreters, which use this API to create an
1174 * efficient debug info container behind the scenes and forward all queries to
1175 * it once the info has been loaded.
1176 *
1177 * @returns IPRT status code.
1178 *
1179 * @param phDbgMod Where to return the module handle.
1180 * @param pszName The name of the module (mandatory).
1181 * @param cbSeg The size of initial segment. If zero, segments will
1182 * have to be added manually using RTDbgModSegmentAdd.
1183 * @param fFlags Flags reserved for future extensions, MBZ for now.
1184 */
1185RTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cbSeg, uint32_t fFlags);
1186
1187RTDECL(int) RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName,
1188 RTLDRARCH enmArch, RTDBGCFG hDbgCfg);
1189RTDECL(int) RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR uSubtrahend,
1190 RTDBGCFG hDbgCfg);
1191RTDECL(int) RTDbgModCreateFromPeImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName,
1192 PRTLDRMOD phLdrMod, uint32_t cbImage, uint32_t uTimeDateStamp, RTDBGCFG hDbgCfg);
1193RTDECL(int) RTDbgModCreateFromDbg(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage,
1194 uint32_t uTimeDateStamp, RTDBGCFG hDbgCfg);
1195RTDECL(int) RTDbgModCreateFromPdb(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage,
1196 PCRTUUID pUuid, uint32_t Age, RTDBGCFG hDbgCfg);
1197RTDECL(int) RTDbgModCreateFromDwo(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage,
1198 uint32_t uCrc32, RTDBGCFG hDbgCfg);
1199RTDECL(int) RTDbgModCreateFromMachOImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName,
1200 RTLDRARCH enmArch, uint32_t cbImage, uint32_t cSegs, PCRTDBGSEGMENT paSegs,
1201 PCRTUUID pUuid, RTDBGCFG hDbgCfg, uint32_t fFlags);
1202
1203/** @name Flags for RTDbgModCreate and friends.
1204 * @{ */
1205/** Overrides the hDbgCfg settings and forces an image and/or symbol file
1206 * search. RTDbgModCreate will quietly ignore this flag. */
1207#define RTDBGMOD_F_NOT_DEFERRED RT_BIT_32(0)
1208/** @} */
1209
1210
1211/**
1212 * Retains another reference to the module.
1213 *
1214 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1215 *
1216 * @param hDbgMod The module handle.
1217 *
1218 * @remarks Will not take any locks.
1219 */
1220RTDECL(uint32_t) RTDbgModRetain(RTDBGMOD hDbgMod);
1221
1222/**
1223 * Release a reference to the module.
1224 *
1225 * When the reference count reaches zero, the module is destroyed.
1226 *
1227 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1228 *
1229 * @param hDbgMod The module handle. The NIL handle is quietly ignored
1230 * and 0 is returned.
1231 *
1232 * @remarks Will not take any locks.
1233 */
1234RTDECL(uint32_t) RTDbgModRelease(RTDBGMOD hDbgMod);
1235
1236/**
1237 * Removes all content from the debug module (container), optionally only
1238 * leaving segments and image size intact.
1239 *
1240 * This is only possible on container modules, i.e. created by RTDbgModCreate().
1241 *
1242 * @returns IPRT status code.
1243 * @param hDbgMod The module handle.
1244 * @param fLeaveSegments Whether to leave segments (and image size) as is.
1245 */
1246RTDECL(int) RTDbgModRemoveAll(RTDBGMOD hDbgMod, bool fLeaveSegments);
1247
1248/**
1249 * Gets the module name.
1250 *
1251 * @returns Pointer to a read only string containing the name.
1252 *
1253 * @param hDbgMod The module handle.
1254 */
1255RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod);
1256
1257/**
1258 * Gets the name of the debug info file we're using.
1259 *
1260 * @returns Pointer to a read only string containing the filename, NULL if we
1261 * don't use one.
1262 *
1263 * @param hDbgMod The module handle.
1264 */
1265RTDECL(const char *) RTDbgModDebugFile(RTDBGMOD hDbgMod);
1266
1267/**
1268 * Gets the image filename (as specified by the user).
1269 *
1270 * @returns Pointer to a read only string containing the filename.
1271 *
1272 * @param hDbgMod The module handle.
1273 */
1274RTDECL(const char *) RTDbgModImageFile(RTDBGMOD hDbgMod);
1275
1276/**
1277 * Gets the image filename actually used if it differs from RTDbgModImageFile.
1278 *
1279 * @returns Pointer to a read only string containing the filename, NULL if same
1280 * as RTDBgModImageFile.
1281 *
1282 * @param hDbgMod The module handle.
1283 */
1284RTDECL(const char *) RTDbgModImageFileUsed(RTDBGMOD hDbgMod);
1285
1286/**
1287 * Checks if the loading of the debug info has been postponed.
1288 *
1289 * @returns true if postponed, false if not or invalid handle.
1290 * @param hDbgMod The module handle.
1291 */
1292RTDECL(bool) RTDbgModIsDeferred(RTDBGMOD hDbgMod);
1293
1294/**
1295 * Checks if the debug info is exports only.
1296 *
1297 * @returns true if exports only, false if not or invalid handle.
1298 * @param hDbgMod The module handle.
1299 */
1300RTDECL(bool) RTDbgModIsExports(RTDBGMOD hDbgMod);
1301
1302/**
1303 * Converts an image relative address to a segment:offset address.
1304 *
1305 * @returns Segment index on success.
1306 * NIL_RTDBGSEGIDX is returned if the module handle or the RVA are
1307 * invalid.
1308 *
1309 * @param hDbgMod The module handle.
1310 * @param uRva The image relative address to convert.
1311 * @param poffSeg Where to return the segment offset. Optional.
1312 */
1313RTDECL(RTDBGSEGIDX) RTDbgModRvaToSegOff(RTDBGMOD hDbgMod, RTUINTPTR uRva, PRTUINTPTR poffSeg);
1314
1315/**
1316 * Gets the module tag value if any.
1317 *
1318 * @returns The tag. 0 if hDbgMod is invalid.
1319 *
1320 * @param hDbgMod The module handle.
1321 */
1322RTDECL(uint64_t) RTDbgModGetTag(RTDBGMOD hDbgMod);
1323
1324/**
1325 * Tags or untags the module.
1326 *
1327 * @returns IPRT status code.
1328 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1329 *
1330 * @param hDbgMod The module handle.
1331 * @param uTag The tag value. The convention is that 0 is no tag
1332 * and any other value means it's tagged. It's adviced
1333 * to use some kind of unique number like an address
1334 * (global or string cache for instance) to avoid
1335 * collisions with other users
1336 */
1337RTDECL(int) RTDbgModSetTag(RTDBGMOD hDbgMod, uint64_t uTag);
1338
1339
1340/**
1341 * Image size when mapped if segments are mapped adjacently.
1342 *
1343 * For ELF, PE, and Mach-O images this is (usually) a natural query, for LX and
1344 * NE and such it's a bit odder and the answer may not make much sense for them.
1345 *
1346 * @returns Image mapped size.
1347 * RTUINTPTR_MAX is returned if the handle is invalid.
1348 *
1349 * @param hDbgMod The module handle.
1350 */
1351RTDECL(RTUINTPTR) RTDbgModImageSize(RTDBGMOD hDbgMod);
1352
1353/**
1354 * Gets the image format.
1355 *
1356 * @returns Image format.
1357 * @retval RTLDRFMT_INVALID if the handle is invalid or if the format isn't known.
1358 * @param hDbgMod The debug module handle.
1359 * @sa RTLdrGetFormat
1360 */
1361RTDECL(RTLDRFMT) RTDbgModImageGetFormat(RTDBGMOD hDbgMod);
1362
1363/**
1364 * Gets the image architecture.
1365 *
1366 * @returns Image architecture.
1367 * @retval RTLDRARCH_INVALID if the handle is invalid.
1368 * @retval RTLDRARCH_WHATEVER if unknown.
1369 * @param hDbgMod The debug module handle.
1370 * @sa RTLdrGetArch
1371 */
1372RTDECL(RTLDRARCH) RTDbgModImageGetArch(RTDBGMOD hDbgMod);
1373
1374/**
1375 * Generic method for querying image properties.
1376 *
1377 * @returns IPRT status code.
1378 * @retval VERR_NOT_SUPPORTED if the property query isn't supported (either all
1379 * or that specific property). The caller must handle this result.
1380 * @retval VERR_NOT_FOUND the property was not found in the module. The caller
1381 * must also normally deal with this.
1382 * @retval VERR_INVALID_FUNCTION if the function value is wrong.
1383 * @retval VERR_INVALID_PARAMETER if the fixed buffer size is wrong. Correct
1384 * size in @a *pcbRet.
1385 * @retval VERR_BUFFER_OVERFLOW if the function doesn't have a fixed size
1386 * buffer and the buffer isn't big enough. Correct size in @a *pcbRet.
1387 * @retval VERR_INVALID_HANDLE if the handle is invalid.
1388 *
1389 * @param hDbgMod The debug module handle.
1390 * @param enmProp The property to query.
1391 * @param pvBuf Pointer to the input / output buffer. In most cases
1392 * it's only used for returning data.
1393 * @param cbBuf The size of the buffer.
1394 * @param pcbRet Where to return the amount of data returned. On
1395 * buffer size errors, this is set to the correct size.
1396 * Optional.
1397 * @sa RTLdrQueryPropEx
1398 */
1399RTDECL(int) RTDbgModImageQueryProp(RTDBGMOD hDbgMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf, size_t *pcbRet);
1400
1401
1402/**
1403 * Adds a segment to the module. Optional feature.
1404 *
1405 * This method is intended used for manually constructing debug info for a
1406 * module. The main usage is from other debug info interpreters that want to
1407 * avoid writing a debug info database and instead uses the standard container
1408 * behind the scenes.
1409 *
1410 * @returns IPRT status code.
1411 * @retval VERR_NOT_SUPPORTED if this feature isn't support by the debug info
1412 * interpreter. This is a common return code.
1413 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1414 * @retval VERR_DBG_ADDRESS_WRAP if uRva+cb wraps around.
1415 * @retval VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE if pszName is too short or long.
1416 * @retval VERR_INVALID_PARAMETER if fFlags contains undefined flags.
1417 * @retval VERR_DBG_SPECIAL_SEGMENT if *piSeg is a special segment.
1418 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if *piSeg doesn't meet expectations.
1419 *
1420 * @param hDbgMod The module handle.
1421 * @param uRva The image relative address of the segment.
1422 * @param cb The size of the segment.
1423 * @param pszName The segment name. Does not normally need to be
1424 * unique, although this is somewhat up to the
1425 * debug interpreter to decide.
1426 * @param fFlags Segment flags. Reserved for future used, MBZ.
1427 * @param piSeg The segment index or NIL_RTDBGSEGIDX on input.
1428 * The assigned segment index on successful return.
1429 * Optional.
1430 */
1431RTDECL(int) RTDbgModSegmentAdd(RTDBGMOD hDbgMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName,
1432 uint32_t fFlags, PRTDBGSEGIDX piSeg);
1433
1434/**
1435 * Gets the number of segments in the module.
1436 *
1437 * This is can be used to determine the range which can be passed to
1438 * RTDbgModSegmentByIndex and derivates.
1439 *
1440 * @returns The segment relative address.
1441 * NIL_RTDBGSEGIDX if the handle is invalid.
1442 *
1443 * @param hDbgMod The module handle.
1444 */
1445RTDECL(RTDBGSEGIDX) RTDbgModSegmentCount(RTDBGMOD hDbgMod);
1446
1447/**
1448 * Query information about a segment.
1449 *
1450 * This can be used together with RTDbgModSegmentCount to enumerate segments.
1451 * The index starts a 0 and stops one below RTDbgModSegmentCount.
1452 *
1453 * @returns IPRT status code.
1454 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if iSeg is too high.
1455 * @retval VERR_DBG_SPECIAL_SEGMENT if iSeg indicates a special segment.
1456 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1457 *
1458 * @param hDbgMod The module handle.
1459 * @param iSeg The segment index. No special segments.
1460 * @param pSegInfo Where to return the segment info. The
1461 * RTDBGSEGMENT::Address member will be set to
1462 * RTUINTPTR_MAX or the load address used at link time.
1463 */
1464RTDECL(int) RTDbgModSegmentByIndex(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo);
1465
1466/**
1467 * Gets the size of a segment.
1468 *
1469 * This is a just a wrapper around RTDbgModSegmentByIndex.
1470 *
1471 * @returns The segment size.
1472 * RTUINTPTR_MAX is returned if either the handle and segment index are
1473 * invalid.
1474 *
1475 * @param hDbgMod The module handle.
1476 * @param iSeg The segment index. RTDBGSEGIDX_ABS is not allowed.
1477 * If RTDBGSEGIDX_RVA is used, the functions returns
1478 * the same value as RTDbgModImageSize.
1479 */
1480RTDECL(RTUINTPTR) RTDbgModSegmentSize(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
1481
1482/**
1483 * Gets the image relative address of a segment.
1484 *
1485 * This is a just a wrapper around RTDbgModSegmentByIndex.
1486 *
1487 * @returns The segment relative address.
1488 * RTUINTPTR_MAX is returned if either the handle and segment index are
1489 * invalid.
1490 *
1491 * @param hDbgMod The module handle.
1492 * @param iSeg The segment index. No special segment indexes
1493 * allowed (asserted).
1494 */
1495RTDECL(RTUINTPTR) RTDbgModSegmentRva(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
1496
1497
1498/**
1499 * Adds a line number to the module.
1500 *
1501 * @returns IPRT status code.
1502 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
1503 * custom symbols. This is a common place occurrence.
1504 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1505 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1506 * short.
1507 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1508 * it's not inside any of the segments defined by the module.
1509 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1510 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1511 * end of the segment.
1512 * @retval VERR_DBG_ADDRESS_WRAP if off+cb wraps around.
1513 * @retval VERR_INVALID_PARAMETER if the symbol flags sets undefined bits.
1514 *
1515 * @param hDbgMod The module handle.
1516 * @param pszSymbol The symbol name.
1517 * @param iSeg The segment index.
1518 * @param off The segment offset.
1519 * @param cb The size of the symbol. Can be zero, although this
1520 * may depend somewhat on the debug interpreter.
1521 * @param fFlags Symbol flags. Reserved for the future, MBZ.
1522 * @param piOrdinal Where to return the symbol ordinal on success. If
1523 * the interpreter doesn't do ordinals, this will be set to
1524 * UINT32_MAX. Optional.
1525 */
1526RTDECL(int) RTDbgModSymbolAdd(RTDBGMOD hDbgMod, const char *pszSymbol, RTDBGSEGIDX iSeg, RTUINTPTR off,
1527 RTUINTPTR cb, uint32_t fFlags, uint32_t *piOrdinal);
1528
1529/**
1530 * Gets the symbol count.
1531 *
1532 * This can be used together wtih RTDbgModSymbolByOrdinal or
1533 * RTDbgModSymbolByOrdinalA to enumerate all the symbols.
1534 *
1535 * @returns The number of symbols in the module.
1536 * UINT32_MAX is returned if the module handle is invalid or some other
1537 * error occurs.
1538 *
1539 * @param hDbgMod The module handle.
1540 */
1541RTDECL(uint32_t) RTDbgModSymbolCount(RTDBGMOD hDbgMod);
1542
1543/**
1544 * Queries symbol information by ordinal number.
1545 *
1546 * @returns IPRT status code.
1547 * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at the given number.
1548 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1549 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1550 * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
1551 *
1552 * @param hDbgMod The module handle.
1553 * @param iOrdinal The symbol ordinal number. 0-based. The highest
1554 * number is RTDbgModSymbolCount() - 1.
1555 * @param pSymInfo Where to store the symbol information.
1556 */
1557RTDECL(int) RTDbgModSymbolByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo);
1558
1559/**
1560 * Queries symbol information by ordinal number.
1561 *
1562 * @returns IPRT status code.
1563 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1564 * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
1565 * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at the given number.
1566 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1567 *
1568 * @param hDbgMod The module handle.
1569 * @param iOrdinal The symbol ordinal number. 0-based. The highest
1570 * number is RTDbgModSymbolCount() - 1.
1571 * @param ppSymInfo Where to store the pointer to the returned
1572 * symbol information. Always set. Free with
1573 * RTDbgSymbolFree.
1574 */
1575RTDECL(int) RTDbgModSymbolByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL *ppSymInfo);
1576
1577/**
1578 * Queries symbol information by address.
1579 *
1580 * The returned symbol is what the debug info interpreter considers the symbol
1581 * most applicable to the specified address. This usually means a symbol with an
1582 * address equal or lower than the requested.
1583 *
1584 * @returns IPRT status code.
1585 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1586 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1587 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1588 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1589 * it's not inside any of the segments defined by the module.
1590 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1591 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1592 * end of the segment.
1593 * @retval VERR_INVALID_PARAMETER if incorrect flags.
1594 *
1595 * @param hDbgMod The module handle.
1596 * @param iSeg The segment number.
1597 * @param off The offset into the segment.
1598 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
1599 * @param poffDisp Where to store the distance between the
1600 * specified address and the returned symbol.
1601 * Optional.
1602 * @param pSymInfo Where to store the symbol information.
1603 */
1604RTDECL(int) RTDbgModSymbolByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
1605 PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo);
1606
1607/**
1608 * Queries symbol information by address.
1609 *
1610 * The returned symbol is what the debug info interpreter considers the symbol
1611 * most applicable to the specified address. This usually means a symbol with an
1612 * address equal or lower than the requested.
1613 *
1614 * @returns IPRT status code.
1615 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1616 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1617 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1618 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1619 * it's not inside any of the segments defined by the module.
1620 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1621 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1622 * end of the segment.
1623 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1624 * @retval VERR_INVALID_PARAMETER if incorrect flags.
1625 *
1626 * @param hDbgMod The module handle.
1627 * @param iSeg The segment index.
1628 * @param off The offset into the segment.
1629 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
1630 * @param poffDisp Where to store the distance between the
1631 * specified address and the returned symbol. Optional.
1632 * @param ppSymInfo Where to store the pointer to the returned
1633 * symbol information. Always set. Free with
1634 * RTDbgSymbolFree.
1635 */
1636RTDECL(int) RTDbgModSymbolByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
1637 PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymInfo);
1638
1639/**
1640 * Queries symbol information by symbol name.
1641 *
1642 * @returns IPRT status code.
1643 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1644 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1645 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1646 * short.
1647 *
1648 * @param hDbgMod The module handle.
1649 * @param pszSymbol The symbol name.
1650 * @param pSymInfo Where to store the symbol information.
1651 */
1652RTDECL(int) RTDbgModSymbolByName(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL pSymInfo);
1653
1654/**
1655 * Queries symbol information by symbol name.
1656 *
1657 * @returns IPRT status code.
1658 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1659 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1660 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1661 * short.
1662 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1663 *
1664 * @param hDbgMod The module handle.
1665 * @param pszSymbol The symbol name.
1666 * @param ppSymInfo Where to store the pointer to the returned
1667 * symbol information. Always set. Free with
1668 * RTDbgSymbolFree.
1669 */
1670RTDECL(int) RTDbgModSymbolByNameA(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL *ppSymInfo);
1671
1672/**
1673 * Adds a line number to the module.
1674 *
1675 * @returns IPRT status code.
1676 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
1677 * custom symbols. This should be consider a normal response.
1678 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1679 * @retval VERR_DBG_FILE_NAME_OUT_OF_RANGE if the file name is too longer or
1680 * empty.
1681 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1682 * it's not inside any of the segments defined by the module.
1683 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1684 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1685 * end of the segment.
1686 * @retval VERR_INVALID_PARAMETER if the line number flags sets undefined bits.
1687 *
1688 * @param hDbgMod The module handle.
1689 * @param pszFile The file name.
1690 * @param uLineNo The line number.
1691 * @param iSeg The segment index.
1692 * @param off The segment offset.
1693 * @param piOrdinal Where to return the line number ordinal on
1694 * success. If the interpreter doesn't do ordinals,
1695 * this will be set to UINT32_MAX. Optional.
1696 */
1697RTDECL(int) RTDbgModLineAdd(RTDBGMOD hDbgMod, const char *pszFile, uint32_t uLineNo,
1698 RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t *piOrdinal);
1699
1700/**
1701 * Gets the line number count.
1702 *
1703 * This can be used together wtih RTDbgModLineByOrdinal or RTDbgModSymbolByLineA
1704 * to enumerate all the line number information.
1705 *
1706 * @returns The number of line numbers in the module.
1707 * UINT32_MAX is returned if the module handle is invalid or some other
1708 * error occurs.
1709 *
1710 * @param hDbgMod The module handle.
1711 */
1712RTDECL(uint32_t) RTDbgModLineCount(RTDBGMOD hDbgMod);
1713
1714/**
1715 * Queries line number information by ordinal number.
1716 *
1717 * This can be used to enumerate the line numbers for the module. Use
1718 * RTDbgModLineCount() to figure the end of the ordinals.
1719 *
1720 * @returns IPRT status code.
1721 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1722 * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
1723 * ordinal.
1724 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1725
1726 * @param hDbgMod The module handle.
1727 * @param iOrdinal The line number ordinal number.
1728 * @param pLineInfo Where to store the information about the line
1729 * number.
1730 */
1731RTDECL(int) RTDbgModLineByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo);
1732
1733/**
1734 * Queries line number information by ordinal number.
1735 *
1736 * This can be used to enumerate the line numbers for the module. Use
1737 * RTDbgModLineCount() to figure the end of the ordinals.
1738 *
1739 * @returns IPRT status code.
1740 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1741 * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
1742 * ordinal.
1743 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1744 * @retval VERR_NO_MEMORY if RTDbgLineAlloc fails.
1745 *
1746 * @param hDbgMod The module handle.
1747 * @param iOrdinal The line number ordinal number.
1748 * @param ppLineInfo Where to store the pointer to the returned line
1749 * number information. Always set. Free with
1750 * RTDbgLineFree.
1751 */
1752RTDECL(int) RTDbgModLineByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE *ppLineInfo);
1753
1754/**
1755 * Queries line number information by address.
1756 *
1757 * The returned line number is what the debug info interpreter considers the
1758 * one most applicable to the specified address. This usually means a line
1759 * number with an address equal or lower than the requested.
1760 *
1761 * @returns IPRT status code.
1762 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1763 * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
1764 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1765 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1766 * it's not inside any of the segments defined by the module.
1767 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1768 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1769 * end of the segment.
1770 *
1771 * @param hDbgMod The module handle.
1772 * @param iSeg The segment number.
1773 * @param off The offset into the segment.
1774 * @param poffDisp Where to store the distance between the
1775 * specified address and the returned symbol.
1776 * Optional.
1777 * @param pLineInfo Where to store the line number information.
1778 */
1779RTDECL(int) RTDbgModLineByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLineInfo);
1780
1781/**
1782 * Queries line number information by address.
1783 *
1784 * The returned line number is what the debug info interpreter considers the
1785 * one most applicable to the specified address. This usually means a line
1786 * number with an address equal or lower than the requested.
1787 *
1788 * @returns IPRT status code.
1789 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1790 * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
1791 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1792 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1793 * it's not inside any of the segments defined by the module.
1794 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1795 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1796 * end of the segment.
1797 * @retval VERR_NO_MEMORY if RTDbgLineAlloc fails.
1798 *
1799 * @param hDbgMod The module handle.
1800 * @param iSeg The segment number.
1801 * @param off The offset into the segment.
1802 * @param poffDisp Where to store the distance between the
1803 * specified address and the returned symbol.
1804 * Optional.
1805 * @param ppLineInfo Where to store the pointer to the returned line
1806 * number information. Always set. Free with
1807 * RTDbgLineFree.
1808 */
1809RTDECL(int) RTDbgModLineByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE *ppLineInfo);
1810
1811/**
1812 * Try use unwind information to unwind one frame.
1813 *
1814 * @returns IPRT status code. Last informational status from stack reader callback.
1815 * @retval VERR_DBG_NO_UNWIND_INFO if the module contains no unwind information.
1816 * @retval VERR_DBG_UNWIND_INFO_NOT_FOUND if no unwind information was found
1817 * for the location given by iSeg:off.
1818 *
1819 * @param hDbgMod The module handle.
1820 * @param iSeg The segment number of the program counter.
1821 * @param off The offset into @a iSeg. Together with @a iSeg
1822 * this corresponds to the RTDBGUNWINDSTATE::uPc
1823 * value pointed to by @a pState.
1824 * @param pState The unwind state to work.
1825 *
1826 * @sa RTLdrUnwindFrame
1827 */
1828RTDECL(int) RTDbgModUnwindFrame(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTDBGUNWINDSTATE pState);
1829
1830/** @} */
1831# endif /* IN_RING3 */
1832
1833
1834
1835/** @name Kernel Debug Info API
1836 *
1837 * This is a specialized API for obtaining symbols and structure information
1838 * about the running kernel. It is relatively OS specific. Its purpose and
1839 * operation is doesn't map all that well onto RTDbgMod, so a few dedicated
1840 * functions was created for it.
1841 *
1842 * @{ */
1843
1844/** Handle to the kernel debug info. */
1845typedef struct RTDBGKRNLINFOINT *RTDBGKRNLINFO;
1846/** Pointer to a kernel debug info handle. */
1847typedef RTDBGKRNLINFO *PRTDBGKRNLINFO;
1848/** Nil kernel debug info handle. */
1849#define NIL_RTDBGKRNLINFO ((RTDBGKRNLINFO)0)
1850
1851/**
1852 * Opens the kernel debug info.
1853 *
1854 * @returns IPRT status code. Can fail for any number of reasons.
1855 *
1856 * @param phKrnlInfo Where to return the kernel debug info handle on
1857 * success.
1858 * @param fFlags Flags reserved for future use. Must be zero.
1859 */
1860RTR0DECL(int) RTR0DbgKrnlInfoOpen(PRTDBGKRNLINFO phKrnlInfo, uint32_t fFlags);
1861
1862/**
1863 * Retains a reference to the kernel debug info handle.
1864 *
1865 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1866 * @param hKrnlInfo The kernel info handle.
1867 */
1868RTR0DECL(uint32_t) RTR0DbgKrnlInfoRetain(RTDBGKRNLINFO hKrnlInfo);
1869
1870
1871/**
1872 * Releases a reference to the kernel debug info handle, destroying it when the
1873 * counter reaches zero.
1874 *
1875 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1876 * @param hKrnlInfo The kernel info handle. NIL_RTDBGKRNLINFO is
1877 * quietly ignored.
1878 */
1879RTR0DECL(uint32_t) RTR0DbgKrnlInfoRelease(RTDBGKRNLINFO hKrnlInfo);
1880
1881/**
1882 * Queries the offset (in bytes) of a member of a kernel structure.
1883 *
1884 * @returns IPRT status code.
1885 * @retval VINF_SUCCESS and offset at @a poffMember.
1886 * @retval VERR_NOT_FOUND if the structure or the member was not found.
1887 * @retval VERR_INVALID_HANDLE if hKrnlInfo is bad.
1888 * @retval VERR_INVALID_POINTER if any of the pointers are bad.
1889 *
1890 * @param hKrnlInfo The kernel info handle.
1891 * @param pszModule The name of the module to search, pass NULL to
1892 * search the default kernel module(s).
1893 * @param pszStructure The structure name.
1894 * @param pszMember The member name.
1895 * @param poffMember Where to return the offset.
1896 */
1897RTR0DECL(int) RTR0DbgKrnlInfoQueryMember(RTDBGKRNLINFO hKrnlInfo, const char *pszModule, const char *pszStructure,
1898 const char *pszMember, size_t *poffMember);
1899
1900
1901/**
1902 * Queries the value (usually the address) of a kernel symbol.
1903 *
1904 * This may go looking for the symbol in other modules, in which case it will
1905 * always check the kernel symbol table first.
1906 *
1907 * @returns IPRT status code.
1908 * @retval VINF_SUCCESS and value at @a ppvSymbol.
1909 * @retval VERR_SYMBOL_NOT_FOUND
1910 * @retval VERR_INVALID_HANDLE if hKrnlInfo is bad.
1911 * @retval VERR_INVALID_POINTER if any of the pointers are bad.
1912 *
1913 * @param hKrnlInfo The kernel info handle.
1914 * @param pszModule Reserved for future extensions. Pass NULL.
1915 * @param pszSymbol The C name of the symbol.
1916 * @param ppvSymbol Where to return the symbol value, passing NULL is
1917 * OK. This may be modified even on failure, in
1918 * particular, it will be set to NULL when
1919 * VERR_SYMBOL_NOT_FOUND is returned.
1920 *
1921 * @sa RTR0DbgKrnlInfoGetSymbol, RTLdrGetSymbol
1922 */
1923RTR0DECL(int) RTR0DbgKrnlInfoQuerySymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
1924 const char *pszSymbol, void **ppvSymbol);
1925
1926/**
1927 * Wrapper around RTR0DbgKrnlInfoQuerySymbol that returns the symbol.
1928 *
1929 * @return Symbol address if found, NULL if not found or some invalid parameter
1930 * or something.
1931 * @param hKrnlInfo The kernel info handle.
1932 * @param pszModule Reserved for future extensions. Pass NULL.
1933 * @param pszSymbol The C name of the symbol.
1934 * @sa RTR0DbgKrnlInfoQuerySymbol, RTLdrGetSymbol
1935 */
1936RTR0DECL(void *) RTR0DbgKrnlInfoGetSymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule, const char *pszSymbol);
1937
1938/**
1939 * Queries the size (in bytes) of a kernel data type.
1940 *
1941 * @returns IPRT status code.
1942 * @retval VINF_SUCCESS and size at @a pcbType.
1943 * @retval VERR_NOT_FOUND if the type was not found.
1944 * @retval VERR_INVALID_HANDLE if hKrnlInfo is bad.
1945 * @retval VERR_INVALID_POINTER if any of the pointers are bad.
1946 * @retval VERR_WRONG_TYPE if the type was not a valid data type (e.g. a
1947 * function)
1948 *
1949 * @param hKrnlInfo The kernel info handle.
1950 * @param pszModule The name of the module to search, pass NULL to
1951 * search the default kernel module(s).
1952 * @param pszType The type name.
1953 * @param pcbType Where to return the size of the type.
1954 */
1955RTR0DECL(int) RTR0DbgKrnlInfoQuerySize(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
1956 const char *pszType, size_t *pcbType);
1957/** @} */
1958
1959/** @} */
1960
1961RT_C_DECLS_END
1962
1963#endif
1964
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use