VirtualBox

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

Last change on this file since 87829 was 85121, checked in by vboxsync, 4 years ago

iprt/cdefs.h: Refactored the typedef use of DECLCALLBACK as well as DECLCALLBACKMEMBER to wrap the whole expression, similar to the DECLR?CALLBACKMEMBER macros. This allows adding a throw() at the end when compiling with the VC++ compiler to indicate that the callbacks won't throw anything, so we can stop supressing the C5039 warning about passing functions that can potential throw C++ exceptions to extern C code that can't necessarily cope with such (unwind,++). Introduced a few _EX variations that allows specifying different/no calling convention too, as that's handy when dynamically resolving host APIs. Fixed numerous places missing DECLCALLBACK and such. Left two angry @todos regarding use of CreateThread. bugref:9794

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 78.1 KB
Line 
1/* $Id: dbg.h 85121 2020-07-08 19:33:26Z vboxsync $ */
2/** @file
3 * IPRT - Debugging Routines.
4 */
5
6/*
7 * Copyright (C) 2008-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * 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 DECLCALLBACKTYPE(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 DECLCALLBACKTYPE(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, PRTLDRMOD phLdrModIn, uint32_t cbImage, uint32_t cSegs,
1241 PCRTDBGSEGMENT paSegs, 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/** Mach-O: Load the __LINKEDIT segment (@sa RTLDR_O_MACHO_LOAD_LINKEDIT). */
1249#define RTDBGMOD_F_MACHO_LOAD_LINKEDIT RT_BIT_32(1)
1250/** Valid flag mask. */
1251#define RTDBGMOD_F_VALID_MASK UINT32_C(0x00000003)
1252/** @} */
1253
1254
1255/**
1256 * Retains another reference to the module.
1257 *
1258 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1259 *
1260 * @param hDbgMod The module handle.
1261 *
1262 * @remarks Will not take any locks.
1263 */
1264RTDECL(uint32_t) RTDbgModRetain(RTDBGMOD hDbgMod);
1265
1266/**
1267 * Release a reference to the module.
1268 *
1269 * When the reference count reaches zero, the module is destroyed.
1270 *
1271 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1272 *
1273 * @param hDbgMod The module handle. The NIL handle is quietly ignored
1274 * and 0 is returned.
1275 *
1276 * @remarks Will not take any locks.
1277 */
1278RTDECL(uint32_t) RTDbgModRelease(RTDBGMOD hDbgMod);
1279
1280/**
1281 * Removes all content from the debug module (container), optionally only
1282 * leaving segments and image size intact.
1283 *
1284 * This is only possible on container modules, i.e. created by RTDbgModCreate().
1285 *
1286 * @returns IPRT status code.
1287 * @param hDbgMod The module handle.
1288 * @param fLeaveSegments Whether to leave segments (and image size) as is.
1289 */
1290RTDECL(int) RTDbgModRemoveAll(RTDBGMOD hDbgMod, bool fLeaveSegments);
1291
1292/**
1293 * Gets the module name.
1294 *
1295 * @returns Pointer to a read only string containing the name.
1296 *
1297 * @param hDbgMod The module handle.
1298 */
1299RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod);
1300
1301/**
1302 * Gets the name of the debug info file we're using.
1303 *
1304 * @returns Pointer to a read only string containing the filename, NULL if we
1305 * don't use one.
1306 *
1307 * @param hDbgMod The module handle.
1308 */
1309RTDECL(const char *) RTDbgModDebugFile(RTDBGMOD hDbgMod);
1310
1311/**
1312 * Gets the image filename (as specified by the user).
1313 *
1314 * @returns Pointer to a read only string containing the filename.
1315 *
1316 * @param hDbgMod The module handle.
1317 */
1318RTDECL(const char *) RTDbgModImageFile(RTDBGMOD hDbgMod);
1319
1320/**
1321 * Gets the image filename actually used if it differs from RTDbgModImageFile.
1322 *
1323 * @returns Pointer to a read only string containing the filename, NULL if same
1324 * as RTDBgModImageFile.
1325 *
1326 * @param hDbgMod The module handle.
1327 */
1328RTDECL(const char *) RTDbgModImageFileUsed(RTDBGMOD hDbgMod);
1329
1330/**
1331 * Checks if the loading of the debug info has been postponed.
1332 *
1333 * @returns true if postponed, false if not or invalid handle.
1334 * @param hDbgMod The module handle.
1335 */
1336RTDECL(bool) RTDbgModIsDeferred(RTDBGMOD hDbgMod);
1337
1338/**
1339 * Checks if the debug info is exports only.
1340 *
1341 * @returns true if exports only, false if not or invalid handle.
1342 * @param hDbgMod The module handle.
1343 */
1344RTDECL(bool) RTDbgModIsExports(RTDBGMOD hDbgMod);
1345
1346/**
1347 * Converts an image relative address to a segment:offset address.
1348 *
1349 * @returns Segment index on success.
1350 * NIL_RTDBGSEGIDX is returned if the module handle or the RVA are
1351 * invalid.
1352 *
1353 * @param hDbgMod The module handle.
1354 * @param uRva The image relative address to convert.
1355 * @param poffSeg Where to return the segment offset. Optional.
1356 */
1357RTDECL(RTDBGSEGIDX) RTDbgModRvaToSegOff(RTDBGMOD hDbgMod, RTUINTPTR uRva, PRTUINTPTR poffSeg);
1358
1359/**
1360 * Gets the module tag value if any.
1361 *
1362 * @returns The tag. 0 if hDbgMod is invalid.
1363 *
1364 * @param hDbgMod The module handle.
1365 */
1366RTDECL(uint64_t) RTDbgModGetTag(RTDBGMOD hDbgMod);
1367
1368/**
1369 * Tags or untags the module.
1370 *
1371 * @returns IPRT status code.
1372 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1373 *
1374 * @param hDbgMod The module handle.
1375 * @param uTag The tag value. The convention is that 0 is no tag
1376 * and any other value means it's tagged. It's adviced
1377 * to use some kind of unique number like an address
1378 * (global or string cache for instance) to avoid
1379 * collisions with other users
1380 */
1381RTDECL(int) RTDbgModSetTag(RTDBGMOD hDbgMod, uint64_t uTag);
1382
1383
1384/**
1385 * Image size when mapped if segments are mapped adjacently.
1386 *
1387 * For ELF, PE, and Mach-O images this is (usually) a natural query, for LX and
1388 * NE and such it's a bit odder and the answer may not make much sense for them.
1389 *
1390 * @returns Image mapped size.
1391 * RTUINTPTR_MAX is returned if the handle is invalid.
1392 *
1393 * @param hDbgMod The module handle.
1394 */
1395RTDECL(RTUINTPTR) RTDbgModImageSize(RTDBGMOD hDbgMod);
1396
1397/**
1398 * Gets the image format.
1399 *
1400 * @returns Image format.
1401 * @retval RTLDRFMT_INVALID if the handle is invalid or if the format isn't known.
1402 * @param hDbgMod The debug module handle.
1403 * @sa RTLdrGetFormat
1404 */
1405RTDECL(RTLDRFMT) RTDbgModImageGetFormat(RTDBGMOD hDbgMod);
1406
1407/**
1408 * Gets the image architecture.
1409 *
1410 * @returns Image architecture.
1411 * @retval RTLDRARCH_INVALID if the handle is invalid.
1412 * @retval RTLDRARCH_WHATEVER if unknown.
1413 * @param hDbgMod The debug module handle.
1414 * @sa RTLdrGetArch
1415 */
1416RTDECL(RTLDRARCH) RTDbgModImageGetArch(RTDBGMOD hDbgMod);
1417
1418/**
1419 * Generic method for querying image properties.
1420 *
1421 * @returns IPRT status code.
1422 * @retval VERR_NOT_SUPPORTED if the property query isn't supported (either all
1423 * or that specific property). The caller must handle this result.
1424 * @retval VERR_NOT_FOUND the property was not found in the module. The caller
1425 * must also normally deal with this.
1426 * @retval VERR_INVALID_FUNCTION if the function value is wrong.
1427 * @retval VERR_INVALID_PARAMETER if the fixed buffer size is wrong. Correct
1428 * size in @a *pcbRet.
1429 * @retval VERR_BUFFER_OVERFLOW if the function doesn't have a fixed size
1430 * buffer and the buffer isn't big enough. Correct size in @a *pcbRet.
1431 * @retval VERR_INVALID_HANDLE if the handle is invalid.
1432 *
1433 * @param hDbgMod The debug module handle.
1434 * @param enmProp The property to query.
1435 * @param pvBuf Pointer to the input / output buffer. In most cases
1436 * it's only used for returning data.
1437 * @param cbBuf The size of the buffer.
1438 * @param pcbRet Where to return the amount of data returned. On
1439 * buffer size errors, this is set to the correct size.
1440 * Optional.
1441 * @sa RTLdrQueryPropEx
1442 */
1443RTDECL(int) RTDbgModImageQueryProp(RTDBGMOD hDbgMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf, size_t *pcbRet);
1444
1445
1446/**
1447 * Adds a segment to the module. Optional feature.
1448 *
1449 * This method is intended used for manually constructing debug info for a
1450 * module. The main usage is from other debug info interpreters that want to
1451 * avoid writing a debug info database and instead uses the standard container
1452 * behind the scenes.
1453 *
1454 * @returns IPRT status code.
1455 * @retval VERR_NOT_SUPPORTED if this feature isn't support by the debug info
1456 * interpreter. This is a common return code.
1457 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1458 * @retval VERR_DBG_ADDRESS_WRAP if uRva+cb wraps around.
1459 * @retval VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE if pszName is too short or long.
1460 * @retval VERR_INVALID_PARAMETER if fFlags contains undefined flags.
1461 * @retval VERR_DBG_SPECIAL_SEGMENT if *piSeg is a special segment.
1462 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if *piSeg doesn't meet expectations.
1463 *
1464 * @param hDbgMod The module handle.
1465 * @param uRva The image relative address of the segment.
1466 * @param cb The size of the segment.
1467 * @param pszName The segment name. Does not normally need to be
1468 * unique, although this is somewhat up to the
1469 * debug interpreter to decide.
1470 * @param fFlags Segment flags. Reserved for future used, MBZ.
1471 * @param piSeg The segment index or NIL_RTDBGSEGIDX on input.
1472 * The assigned segment index on successful return.
1473 * Optional.
1474 */
1475RTDECL(int) RTDbgModSegmentAdd(RTDBGMOD hDbgMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName,
1476 uint32_t fFlags, PRTDBGSEGIDX piSeg);
1477
1478/**
1479 * Gets the number of segments in the module.
1480 *
1481 * This is can be used to determine the range which can be passed to
1482 * RTDbgModSegmentByIndex and derivates.
1483 *
1484 * @returns The segment relative address.
1485 * NIL_RTDBGSEGIDX if the handle is invalid.
1486 *
1487 * @param hDbgMod The module handle.
1488 */
1489RTDECL(RTDBGSEGIDX) RTDbgModSegmentCount(RTDBGMOD hDbgMod);
1490
1491/**
1492 * Query information about a segment.
1493 *
1494 * This can be used together with RTDbgModSegmentCount to enumerate segments.
1495 * The index starts a 0 and stops one below RTDbgModSegmentCount.
1496 *
1497 * @returns IPRT status code.
1498 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if iSeg is too high.
1499 * @retval VERR_DBG_SPECIAL_SEGMENT if iSeg indicates a special segment.
1500 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1501 *
1502 * @param hDbgMod The module handle.
1503 * @param iSeg The segment index. No special segments.
1504 * @param pSegInfo Where to return the segment info. The
1505 * RTDBGSEGMENT::Address member will be set to
1506 * RTUINTPTR_MAX or the load address used at link time.
1507 */
1508RTDECL(int) RTDbgModSegmentByIndex(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo);
1509
1510/**
1511 * Gets the size of a segment.
1512 *
1513 * This is a just a wrapper around RTDbgModSegmentByIndex.
1514 *
1515 * @returns The segment size.
1516 * RTUINTPTR_MAX is returned if either the handle and segment index are
1517 * invalid.
1518 *
1519 * @param hDbgMod The module handle.
1520 * @param iSeg The segment index. RTDBGSEGIDX_ABS is not allowed.
1521 * If RTDBGSEGIDX_RVA is used, the functions returns
1522 * the same value as RTDbgModImageSize.
1523 */
1524RTDECL(RTUINTPTR) RTDbgModSegmentSize(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
1525
1526/**
1527 * Gets the image relative address of a segment.
1528 *
1529 * This is a just a wrapper around RTDbgModSegmentByIndex.
1530 *
1531 * @returns The segment relative address.
1532 * RTUINTPTR_MAX is returned if either the handle and segment index are
1533 * invalid.
1534 *
1535 * @param hDbgMod The module handle.
1536 * @param iSeg The segment index. No special segment indexes
1537 * allowed (asserted).
1538 */
1539RTDECL(RTUINTPTR) RTDbgModSegmentRva(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
1540
1541
1542/**
1543 * Adds a line number to the module.
1544 *
1545 * @returns IPRT status code.
1546 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
1547 * custom symbols. This is a common place occurrence.
1548 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1549 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1550 * short.
1551 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1552 * it's not inside any of the segments defined by the module.
1553 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1554 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1555 * end of the segment.
1556 * @retval VERR_DBG_ADDRESS_WRAP if off+cb wraps around.
1557 * @retval VERR_INVALID_PARAMETER if the symbol flags sets undefined bits.
1558 * @retval VERR_DBG_DUPLICATE_SYMBOL
1559 * @retval VERR_DBG_ADDRESS_CONFLICT
1560 *
1561 * @param hDbgMod The module handle.
1562 * @param pszSymbol The symbol name.
1563 * @param iSeg The segment index.
1564 * @param off The segment offset.
1565 * @param cb The size of the symbol. Can be zero, although this
1566 * may depend somewhat on the debug interpreter.
1567 * @param fFlags Symbol flags, RTDBGSYMBOLADD_F_XXX.
1568 * @param piOrdinal Where to return the symbol ordinal on success. If
1569 * the interpreter doesn't do ordinals, this will be set to
1570 * UINT32_MAX. Optional.
1571 */
1572RTDECL(int) RTDbgModSymbolAdd(RTDBGMOD hDbgMod, const char *pszSymbol, RTDBGSEGIDX iSeg, RTUINTPTR off,
1573 RTUINTPTR cb, uint32_t fFlags, uint32_t *piOrdinal);
1574
1575/**
1576 * Gets the symbol count.
1577 *
1578 * This can be used together wtih RTDbgModSymbolByOrdinal or
1579 * RTDbgModSymbolByOrdinalA to enumerate all the symbols.
1580 *
1581 * @returns The number of symbols in the module.
1582 * UINT32_MAX is returned if the module handle is invalid or some other
1583 * error occurs.
1584 *
1585 * @param hDbgMod The module handle.
1586 */
1587RTDECL(uint32_t) RTDbgModSymbolCount(RTDBGMOD hDbgMod);
1588
1589/**
1590 * Queries symbol information by ordinal number.
1591 *
1592 * @returns IPRT status code.
1593 * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at the given number.
1594 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1595 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1596 * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
1597 *
1598 * @param hDbgMod The module handle.
1599 * @param iOrdinal The symbol ordinal number. 0-based. The highest
1600 * number is RTDbgModSymbolCount() - 1.
1601 * @param pSymInfo Where to store the symbol information.
1602 */
1603RTDECL(int) RTDbgModSymbolByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo);
1604
1605/**
1606 * Queries symbol information by ordinal number.
1607 *
1608 * @returns IPRT status code.
1609 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1610 * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
1611 * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at the given number.
1612 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1613 *
1614 * @param hDbgMod The module handle.
1615 * @param iOrdinal The symbol ordinal number. 0-based. The highest
1616 * number is RTDbgModSymbolCount() - 1.
1617 * @param ppSymInfo Where to store the pointer to the returned
1618 * symbol information. Always set. Free with
1619 * RTDbgSymbolFree.
1620 */
1621RTDECL(int) RTDbgModSymbolByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL *ppSymInfo);
1622
1623/**
1624 * Queries symbol information by address.
1625 *
1626 * The returned symbol is what the debug info interpreter considers the symbol
1627 * most applicable to the specified address. This usually means a symbol with an
1628 * address equal or lower than the requested.
1629 *
1630 * @returns IPRT status code.
1631 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1632 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1633 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1634 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1635 * it's not inside any of the segments defined by the module.
1636 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1637 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1638 * end of the segment.
1639 * @retval VERR_INVALID_PARAMETER if incorrect flags.
1640 *
1641 * @param hDbgMod The module handle.
1642 * @param iSeg The segment number.
1643 * @param off The offset into the segment.
1644 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
1645 * @param poffDisp Where to store the distance between the
1646 * specified address and the returned symbol.
1647 * Optional.
1648 * @param pSymInfo Where to store the symbol information.
1649 */
1650RTDECL(int) RTDbgModSymbolByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
1651 PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo);
1652
1653/**
1654 * Queries symbol information by address.
1655 *
1656 * The returned symbol is what the debug info interpreter considers the symbol
1657 * most applicable to the specified address. This usually means a symbol with an
1658 * address equal or lower than the requested.
1659 *
1660 * @returns IPRT status code.
1661 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1662 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1663 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1664 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1665 * it's not inside any of the segments defined by the module.
1666 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1667 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1668 * end of the segment.
1669 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1670 * @retval VERR_INVALID_PARAMETER if incorrect flags.
1671 *
1672 * @param hDbgMod The module handle.
1673 * @param iSeg The segment index.
1674 * @param off The offset into the segment.
1675 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
1676 * @param poffDisp Where to store the distance between the
1677 * specified address and the returned symbol. Optional.
1678 * @param ppSymInfo Where to store the pointer to the returned
1679 * symbol information. Always set. Free with
1680 * RTDbgSymbolFree.
1681 */
1682RTDECL(int) RTDbgModSymbolByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
1683 PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymInfo);
1684
1685/**
1686 * Queries symbol information by symbol name.
1687 *
1688 * @returns IPRT status code.
1689 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1690 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1691 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1692 * short.
1693 *
1694 * @param hDbgMod The module handle.
1695 * @param pszSymbol The symbol name.
1696 * @param pSymInfo Where to store the symbol information.
1697 */
1698RTDECL(int) RTDbgModSymbolByName(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL pSymInfo);
1699
1700/**
1701 * Queries symbol information by symbol name.
1702 *
1703 * @returns IPRT status code.
1704 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1705 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1706 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1707 * short.
1708 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1709 *
1710 * @param hDbgMod The module handle.
1711 * @param pszSymbol The symbol name.
1712 * @param ppSymInfo Where to store the pointer to the returned
1713 * symbol information. Always set. Free with
1714 * RTDbgSymbolFree.
1715 */
1716RTDECL(int) RTDbgModSymbolByNameA(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL *ppSymInfo);
1717
1718/**
1719 * Adds a line number to the module.
1720 *
1721 * @returns IPRT status code.
1722 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
1723 * custom symbols. This should be consider a normal response.
1724 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1725 * @retval VERR_DBG_FILE_NAME_OUT_OF_RANGE if the file name is too longer or
1726 * empty.
1727 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1728 * it's not inside any of the segments defined by the module.
1729 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1730 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1731 * end of the segment.
1732 * @retval VERR_INVALID_PARAMETER if the line number flags sets undefined bits.
1733 *
1734 * @param hDbgMod The module handle.
1735 * @param pszFile The file name.
1736 * @param uLineNo The line number.
1737 * @param iSeg The segment index.
1738 * @param off The segment offset.
1739 * @param piOrdinal Where to return the line number ordinal on
1740 * success. If the interpreter doesn't do ordinals,
1741 * this will be set to UINT32_MAX. Optional.
1742 */
1743RTDECL(int) RTDbgModLineAdd(RTDBGMOD hDbgMod, const char *pszFile, uint32_t uLineNo,
1744 RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t *piOrdinal);
1745
1746/**
1747 * Gets the line number count.
1748 *
1749 * This can be used together wtih RTDbgModLineByOrdinal or RTDbgModSymbolByLineA
1750 * to enumerate all the line number information.
1751 *
1752 * @returns The number of line numbers in the module.
1753 * UINT32_MAX is returned if the module handle is invalid or some other
1754 * error occurs.
1755 *
1756 * @param hDbgMod The module handle.
1757 */
1758RTDECL(uint32_t) RTDbgModLineCount(RTDBGMOD hDbgMod);
1759
1760/**
1761 * Queries line number information by ordinal number.
1762 *
1763 * This can be used to enumerate the line numbers for the module. Use
1764 * RTDbgModLineCount() to figure the end of the ordinals.
1765 *
1766 * @returns IPRT status code.
1767 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1768 * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
1769 * ordinal.
1770 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1771
1772 * @param hDbgMod The module handle.
1773 * @param iOrdinal The line number ordinal number.
1774 * @param pLineInfo Where to store the information about the line
1775 * number.
1776 */
1777RTDECL(int) RTDbgModLineByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo);
1778
1779/**
1780 * Queries line number information by ordinal number.
1781 *
1782 * This can be used to enumerate the line numbers for the module. Use
1783 * RTDbgModLineCount() to figure the end of the ordinals.
1784 *
1785 * @returns IPRT status code.
1786 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1787 * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
1788 * ordinal.
1789 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1790 * @retval VERR_NO_MEMORY if RTDbgLineAlloc fails.
1791 *
1792 * @param hDbgMod The module handle.
1793 * @param iOrdinal The line number ordinal number.
1794 * @param ppLineInfo Where to store the pointer to the returned line
1795 * number information. Always set. Free with
1796 * RTDbgLineFree.
1797 */
1798RTDECL(int) RTDbgModLineByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE *ppLineInfo);
1799
1800/**
1801 * Queries line number information by address.
1802 *
1803 * The returned line number is what the debug info interpreter considers the
1804 * one most applicable to the specified address. This usually means a line
1805 * number with an address equal or lower than the requested.
1806 *
1807 * @returns IPRT status code.
1808 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1809 * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
1810 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1811 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1812 * it's not inside any of the segments defined by the module.
1813 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1814 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1815 * end of the segment.
1816 *
1817 * @param hDbgMod The module handle.
1818 * @param iSeg The segment number.
1819 * @param off The offset into the segment.
1820 * @param poffDisp Where to store the distance between the
1821 * specified address and the returned symbol.
1822 * Optional.
1823 * @param pLineInfo Where to store the line number information.
1824 */
1825RTDECL(int) RTDbgModLineByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLineInfo);
1826
1827/**
1828 * Queries line number information by address.
1829 *
1830 * The returned line number is what the debug info interpreter considers the
1831 * one most applicable to the specified address. This usually means a line
1832 * number with an address equal or lower than the requested.
1833 *
1834 * @returns IPRT status code.
1835 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1836 * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
1837 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1838 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1839 * it's not inside any of the segments defined by the module.
1840 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1841 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1842 * end of the segment.
1843 * @retval VERR_NO_MEMORY if RTDbgLineAlloc fails.
1844 *
1845 * @param hDbgMod The module handle.
1846 * @param iSeg The segment number.
1847 * @param off The offset into the segment.
1848 * @param poffDisp Where to store the distance between the
1849 * specified address and the returned symbol.
1850 * Optional.
1851 * @param ppLineInfo Where to store the pointer to the returned line
1852 * number information. Always set. Free with
1853 * RTDbgLineFree.
1854 */
1855RTDECL(int) RTDbgModLineByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE *ppLineInfo);
1856
1857/**
1858 * Try use unwind information to unwind one frame.
1859 *
1860 * @returns IPRT status code. Last informational status from stack reader callback.
1861 * @retval VERR_DBG_NO_UNWIND_INFO if the module contains no unwind information.
1862 * @retval VERR_DBG_UNWIND_INFO_NOT_FOUND if no unwind information was found
1863 * for the location given by iSeg:off.
1864 *
1865 * @param hDbgMod The module handle.
1866 * @param iSeg The segment number of the program counter.
1867 * @param off The offset into @a iSeg. Together with @a iSeg
1868 * this corresponds to the RTDBGUNWINDSTATE::uPc
1869 * value pointed to by @a pState.
1870 * @param pState The unwind state to work.
1871 *
1872 * @sa RTLdrUnwindFrame
1873 */
1874RTDECL(int) RTDbgModUnwindFrame(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTDBGUNWINDSTATE pState);
1875
1876/** @} */
1877# endif /* IN_RING3 */
1878
1879
1880
1881/** @name Kernel Debug Info API
1882 *
1883 * This is a specialized API for obtaining symbols and structure information
1884 * about the running kernel. It is relatively OS specific. Its purpose and
1885 * operation is doesn't map all that well onto RTDbgMod, so a few dedicated
1886 * functions was created for it.
1887 *
1888 * @{ */
1889
1890/** Handle to the kernel debug info. */
1891typedef struct RTDBGKRNLINFOINT *RTDBGKRNLINFO;
1892/** Pointer to a kernel debug info handle. */
1893typedef RTDBGKRNLINFO *PRTDBGKRNLINFO;
1894/** Nil kernel debug info handle. */
1895#define NIL_RTDBGKRNLINFO ((RTDBGKRNLINFO)0)
1896
1897/**
1898 * Opens the kernel debug info.
1899 *
1900 * @returns IPRT status code. Can fail for any number of reasons.
1901 *
1902 * @param phKrnlInfo Where to return the kernel debug info handle on
1903 * success.
1904 * @param fFlags Flags reserved for future use. Must be zero.
1905 */
1906RTR0DECL(int) RTR0DbgKrnlInfoOpen(PRTDBGKRNLINFO phKrnlInfo, uint32_t fFlags);
1907
1908/**
1909 * Retains a reference to the kernel debug info handle.
1910 *
1911 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1912 * @param hKrnlInfo The kernel info handle.
1913 */
1914RTR0DECL(uint32_t) RTR0DbgKrnlInfoRetain(RTDBGKRNLINFO hKrnlInfo);
1915
1916
1917/**
1918 * Releases a reference to the kernel debug info handle, destroying it when the
1919 * counter reaches zero.
1920 *
1921 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1922 * @param hKrnlInfo The kernel info handle. NIL_RTDBGKRNLINFO is
1923 * quietly ignored.
1924 */
1925RTR0DECL(uint32_t) RTR0DbgKrnlInfoRelease(RTDBGKRNLINFO hKrnlInfo);
1926
1927/**
1928 * Queries the offset (in bytes) of a member of a kernel structure.
1929 *
1930 * @returns IPRT status code.
1931 * @retval VINF_SUCCESS and offset at @a poffMember.
1932 * @retval VERR_NOT_FOUND if the structure or the member was not found.
1933 * @retval VERR_INVALID_HANDLE if hKrnlInfo is bad.
1934 * @retval VERR_INVALID_POINTER if any of the pointers are bad.
1935 *
1936 * @param hKrnlInfo The kernel info handle.
1937 * @param pszModule The name of the module to search, pass NULL to
1938 * search the default kernel module(s).
1939 * @param pszStructure The structure name.
1940 * @param pszMember The member name.
1941 * @param poffMember Where to return the offset.
1942 */
1943RTR0DECL(int) RTR0DbgKrnlInfoQueryMember(RTDBGKRNLINFO hKrnlInfo, const char *pszModule, const char *pszStructure,
1944 const char *pszMember, size_t *poffMember);
1945
1946
1947/**
1948 * Queries the value (usually the address) of a kernel symbol.
1949 *
1950 * This may go looking for the symbol in other modules, in which case it will
1951 * always check the kernel symbol table first.
1952 *
1953 * @returns IPRT status code.
1954 * @retval VINF_SUCCESS and value at @a ppvSymbol.
1955 * @retval VERR_SYMBOL_NOT_FOUND
1956 * @retval VERR_INVALID_HANDLE if hKrnlInfo is bad.
1957 * @retval VERR_INVALID_POINTER if any of the pointers are bad.
1958 *
1959 * @param hKrnlInfo The kernel info handle.
1960 * @param pszModule Reserved for future extensions. Pass NULL.
1961 * @param pszSymbol The C name of the symbol.
1962 * @param ppvSymbol Where to return the symbol value, passing NULL is
1963 * OK. This may be modified even on failure, in
1964 * particular, it will be set to NULL when
1965 * VERR_SYMBOL_NOT_FOUND is returned.
1966 *
1967 * @sa RTR0DbgKrnlInfoGetSymbol, RTLdrGetSymbol
1968 */
1969RTR0DECL(int) RTR0DbgKrnlInfoQuerySymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
1970 const char *pszSymbol, void **ppvSymbol);
1971
1972/**
1973 * Wrapper around RTR0DbgKrnlInfoQuerySymbol that returns the symbol.
1974 *
1975 * @return Symbol address if found, NULL if not found or some invalid parameter
1976 * or something.
1977 * @param hKrnlInfo The kernel info handle.
1978 * @param pszModule Reserved for future extensions. Pass NULL.
1979 * @param pszSymbol The C name of the symbol.
1980 * @sa RTR0DbgKrnlInfoQuerySymbol, RTLdrGetSymbol
1981 */
1982RTR0DECL(void *) RTR0DbgKrnlInfoGetSymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule, const char *pszSymbol);
1983
1984/**
1985 * Queries the size (in bytes) of a kernel data type.
1986 *
1987 * @returns IPRT status code.
1988 * @retval VINF_SUCCESS and size at @a pcbType.
1989 * @retval VERR_NOT_FOUND if the type was not found.
1990 * @retval VERR_INVALID_HANDLE if hKrnlInfo is bad.
1991 * @retval VERR_INVALID_POINTER if any of the pointers are bad.
1992 * @retval VERR_WRONG_TYPE if the type was not a valid data type (e.g. a
1993 * function)
1994 *
1995 * @param hKrnlInfo The kernel info handle.
1996 * @param pszModule The name of the module to search, pass NULL to
1997 * search the default kernel module(s).
1998 * @param pszType The type name.
1999 * @param pcbType Where to return the size of the type.
2000 */
2001RTR0DECL(int) RTR0DbgKrnlInfoQuerySize(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
2002 const char *pszType, size_t *pcbType);
2003/** @} */
2004
2005/** @} */
2006
2007RT_C_DECLS_END
2008
2009#endif /* !IPRT_INCLUDED_dbg_h */
2010
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