VirtualBox

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

Last change on this file since 75155 was 74980, checked in by vboxsync, 6 years ago

IPRT/dbg: Added a few flags to RTDbg[Mod|As]SymbolAdd to deal with conflicts.

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

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