VirtualBox

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

Last change on this file since 78286 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

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