VirtualBox

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

Last change on this file since 106983 was 106364, checked in by vboxsync, 6 weeks ago

include/iprt/dbg.h: Add ARMv8 state for the stack unwinding, bugref:10393

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