VirtualBox

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

Last change on this file since 46025 was 46025, checked in by vboxsync, 12 years ago

RTDbgCfg: Directory and cache searching code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 59.2 KB
Line 
1/* $Id: dbg.h 46025 2013-05-13 15:36:27Z vboxsync $ */
2/** @file
3 * IPRT - Debugging Routines.
4 */
5
6/*
7 * Copyright (C) 2008-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___iprt_dbg_h
28#define ___iprt_dbg_h
29
30#include <iprt/types.h>
31#include <iprt/stdarg.h>
32
33RT_C_DECLS_BEGIN
34
35# ifdef IN_RING3
36
37/** @defgroup grp_rt_dbg RTDbg - Debugging Routines
38 * @ingroup grp_rt
39 * @{
40 */
41
42
43/** Debug segment index. */
44typedef uint32_t RTDBGSEGIDX;
45/** Pointer to a debug segment index. */
46typedef RTDBGSEGIDX *PRTDBGSEGIDX;
47/** Pointer to a const debug segment index. */
48typedef RTDBGSEGIDX const *PCRTDBGSEGIDX;
49/** NIL debug segment index. */
50#define NIL_RTDBGSEGIDX UINT32_C(0xffffffff)
51/** The last normal segment index. */
52#define RTDBGSEGIDX_LAST UINT32_C(0xffffffef)
53/** Special segment index that indicates that the offset is a relative
54 * virtual address (RVA). I.e. an offset from the start of the module. */
55#define RTDBGSEGIDX_RVA UINT32_C(0xfffffff0)
56/** Special segment index that indicates that the offset is a absolute. */
57#define RTDBGSEGIDX_ABS UINT32_C(0xfffffff1)
58/** The last valid special segment index. */
59#define RTDBGSEGIDX_SPECIAL_LAST RTDBGSEGIDX_ABS
60/** The last valid special segment index. */
61#define RTDBGSEGIDX_SPECIAL_FIRST (RTDBGSEGIDX_LAST + 1U)
62
63
64
65/** @name RTDBGSYMADDR_FLAGS_XXX
66 * Flags used when looking up a symbol by address.
67 * @{ */
68/** Less or equal address. (default) */
69#define RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL UINT32_C(0)
70/** Greater or equal address. */
71#define RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL UINT32_C(1)
72/** Mask of valid flags. */
73#define RTDBGSYMADDR_FLAGS_VALID_MASK UINT32_C(1)
74/** @} */
75
76
77/** Max length (including '\\0') of a segment name. */
78#define RTDBG_SEGMENT_NAME_LENGTH (128 - 8 - 8 - 8 - 4 - 4)
79
80/**
81 * Debug module segment.
82 */
83typedef struct RTDBGSEGMENT
84{
85 /** The load address.
86 * RTUINTPTR_MAX if not applicable. */
87 RTUINTPTR Address;
88 /** The image relative virtual address of the segment.
89 * RTUINTPTR_MAX if not applicable. */
90 RTUINTPTR uRva;
91 /** The segment size. */
92 RTUINTPTR cb;
93 /** The segment flags. (reserved) */
94 uint32_t fFlags;
95 /** The segment index. */
96 RTDBGSEGIDX iSeg;
97 /** Symbol name. */
98 char szName[RTDBG_SEGMENT_NAME_LENGTH];
99} RTDBGSEGMENT;
100/** Pointer to a debug module segment. */
101typedef RTDBGSEGMENT *PRTDBGSEGMENT;
102/** Pointer to a const debug module segment. */
103typedef RTDBGSEGMENT const *PCRTDBGSEGMENT;
104
105
106
107/** Max length (including '\\0') of a symbol name. */
108#define RTDBG_SYMBOL_NAME_LENGTH (384 - 8 - 8 - 8 - 4 - 4 - 8)
109
110/**
111 * Debug symbol.
112 */
113typedef struct RTDBGSYMBOL
114{
115 /** Symbol value (address).
116 * This depends a bit who you ask. It will be the same as offSeg when you
117 * as RTDbgMod, but the mapping address if you ask RTDbgAs. */
118 RTUINTPTR Value;
119 /** Symbol size. */
120 RTUINTPTR cb;
121 /** Offset into the segment specified by iSeg. */
122 RTUINTPTR offSeg;
123 /** Segment number. */
124 RTDBGSEGIDX iSeg;
125 /** Symbol Flags. (reserved). */
126 uint32_t fFlags;
127 /** Symbol ordinal.
128 * This is set to UINT32_MAX if the ordinals aren't supported. */
129 uint32_t iOrdinal;
130 /** Symbol name. */
131 char szName[RTDBG_SYMBOL_NAME_LENGTH];
132} RTDBGSYMBOL;
133/** Pointer to debug symbol. */
134typedef RTDBGSYMBOL *PRTDBGSYMBOL;
135/** Pointer to const debug symbol. */
136typedef const RTDBGSYMBOL *PCRTDBGSYMBOL;
137
138/**
139 * Allocate a new symbol structure.
140 *
141 * @returns Pointer to a new structure on success, NULL on failure.
142 */
143RTDECL(PRTDBGSYMBOL) RTDbgSymbolAlloc(void);
144
145/**
146 * Duplicates a symbol structure.
147 *
148 * @returns Pointer to duplicate on success, NULL on failure.
149 *
150 * @param pSymInfo The symbol info to duplicate.
151 */
152RTDECL(PRTDBGSYMBOL) RTDbgSymbolDup(PCRTDBGSYMBOL pSymInfo);
153
154/**
155 * Free a symbol structure previously allocated by a RTDbg method.
156 *
157 * @param pSymInfo The symbol info to free. NULL is ignored.
158 */
159RTDECL(void) RTDbgSymbolFree(PRTDBGSYMBOL pSymInfo);
160
161
162/** Max length (including '\\0') of a debug info file name. */
163#define RTDBG_FILE_NAME_LENGTH (260)
164
165
166/**
167 * Debug line number information.
168 */
169typedef struct RTDBGLINE
170{
171 /** Address.
172 * This depends a bit who you ask. It will be the same as offSeg when you
173 * as RTDbgMod, but the mapping address if you ask RTDbgAs. */
174 RTUINTPTR Address;
175 /** Offset into the segment specified by iSeg. */
176 RTUINTPTR offSeg;
177 /** Segment number. */
178 RTDBGSEGIDX iSeg;
179 /** Line number. */
180 uint32_t uLineNo;
181 /** Symbol ordinal.
182 * This is set to UINT32_MAX if the ordinals aren't supported. */
183 uint32_t iOrdinal;
184 /** Filename. */
185 char szFilename[RTDBG_FILE_NAME_LENGTH];
186} RTDBGLINE;
187/** Pointer to debug line number. */
188typedef RTDBGLINE *PRTDBGLINE;
189/** Pointer to const debug line number. */
190typedef const RTDBGLINE *PCRTDBGLINE;
191
192/**
193 * Allocate a new line number structure.
194 *
195 * @returns Pointer to a new structure on success, NULL on failure.
196 */
197RTDECL(PRTDBGLINE) RTDbgLineAlloc(void);
198
199/**
200 * Duplicates a line number structure.
201 *
202 * @returns Pointer to duplicate on success, NULL on failure.
203 *
204 * @param pLine The line number to duplicate.
205 */
206RTDECL(PRTDBGLINE) RTDbgLineDup(PCRTDBGLINE pLine);
207
208/**
209 * Free a line number structure previously allocated by a RTDbg method.
210 *
211 * @param pLine The line number to free. NULL is ignored.
212 */
213RTDECL(void) RTDbgLineFree(PRTDBGLINE pLine);
214
215
216/** @defgroup grp_rt_dbgcfg RTDbgCfg - Debugging Configuration
217 *
218 * The settings used when loading and processing debug info is kept in a
219 * RTDBGCFG instance since it's generally shared for a whole debugging session
220 * and anyhow would be a major pain to pass as individual parameters to each
221 * call. The debugging config API not only keeps the settings information but
222 * also provide APIs for making use of it, and in some cases, like for instance
223 * symbol severs, retriving and maintaining it.
224 *
225 * @todo Work in progress - APIs are still missing, adding when needed.
226 *
227 * @{
228 */
229
230/** Debugging configuration handle. */
231typedef struct RTDBGCFGINT *RTDBGCFG;
232/** Pointer to a debugging configuration handle. */
233typedef RTDBGCFG *PRTDBGCFG;
234/** NIL debug configuration handle. */
235#define NIL_RTDBGCFG ((RTDBGCFG)0)
236
237/** @name RTDBGCFG_FLAGS_XXX - Debugging configuration flags.
238 * @{ */
239/** Use deferred loading. */
240#define RTDBGCFG_FLAGS_DEFERRED RT_BIT_64(0)
241/** Don't use the symbol server (http). */
242#define RTDBGCFG_FLAGS_NO_SYM_SRV RT_BIT_64(1)
243/** Don't use system search paths.
244 * On windows this means not using _NT_ALT_SYMBOL_PATH, _NT_SYMBOL_PATH,
245 * _NT_SOURCE_PATH, and _NT_EXECUTABLE_PATH.
246 * On other systems the effect has yet to be determined. */
247#define RTDBGCFG_FLAGS_NO_SYSTEM_PATHS RT_BIT_64(2)
248/** Don't search the debug and image paths recursively. */
249#define RTDBGCFG_FLAGS_NO_RECURSIV_SEARCH RT_BIT_64(3)
250/** Don't search the source paths recursively. */
251#define RTDBGCFG_FLAGS_NO_RECURSIV_SRC_SEARCH RT_BIT_64(4)
252/** @} */
253
254/**
255 * Debugging configuration properties.
256 *
257 * The search paths are using the DOS convention of semicolon as separator
258 * character. The the special 'srv' + asterisk syntax known from the windows
259 * debugger search paths are also supported to some extent, as is 'cache' +
260 * asterisk.
261 */
262typedef enum RTDBGCFGPROP
263{
264 /** The customary invalid 0 value. */
265 RTDBGCFGPROP_INVALID = 0,
266 /** RTDBGCFG_FLAGS_XXX.
267 * Env: _FLAGS
268 * The environment variable can be specified as a unsigned value or one or more
269 * mnemonics separated by spaces. */
270 RTDBGCFGPROP_FLAGS,
271 /** List of paths to search for symbol files and images.
272 * Env: _PATH */
273 RTDBGCFGPROP_PATH,
274 /** List of symbol file suffixes (semicolon separated).
275 * Env: _SUFFIXES */
276 RTDBGCFGPROP_SUFFIXES,
277 /** List of paths to search for source files.
278 * Env: _SRC_PATH */
279 RTDBGCFGPROP_SRC_PATH,
280 /** End of valid values. */
281 RTDBGCFGPROP_END,
282 /** The customary 32-bit type hack. */
283 RTDBGCFGPROP_32BIT_HACK = 0x7fffffff
284} RTDBGCFGPROP;
285
286/**
287 * Configuration property change operation.
288 */
289typedef enum RTDBGCFGOP
290{
291 /** Customary invalid 0 value. */
292 RTDBGCFGOP_INVALID = 0,
293 /** Replace the current value with the given one. */
294 RTDBGCFGOP_SET,
295 /** Append the given value to the existing one. For integer values this is
296 * considered a bitwise OR operation. */
297 RTDBGCFGOP_APPEND,
298 /** Prepend the given value to the existing one. For integer values this is
299 * considered a bitwise OR operation. */
300 RTDBGCFGOP_PREPEND,
301 /** Removes the value from the existing one. For interger values the value is
302 * complemented and ANDed with the existing one, clearing all the specified
303 * flags/bits. */
304 RTDBGCFGOP_REMOVE,
305 /** End of valid values. */
306 RTDBGCFGOP_END,
307 /** Customary 32-bit type hack. */
308 RTDBGCFGOP_32BIT_HACK = 0x7fffffff
309} RTDBGCFGOP;
310
311
312
313/**
314 * Initializes a debugging configuration.
315 *
316 * @returns IPRT status code.
317 * @param phDbgCfg Where to return the configuration handle.
318 * @param pszEnvVarPrefix The environment variable prefix. If NULL, the
319 * environment is not consulted.
320 *
321 * @sa RTDbgCfgChangeString, RTDbgCfgChangeUInt.
322 */
323RTDECL(int) RTDbgCfgCreate(PRTDBGCFG phDbgCfg, const char *pszEnvVarPrefix);
324
325/**
326 * Retains a new reference to a debugging config.
327 *
328 * @returns New reference count.
329 * UINT32_MAX is returned if the handle is invalid (asserted).
330 * @param hDbgCfg The config handle.
331 */
332RTDECL(uint32_t) RTDbgCfgRetain(RTDBGCFG hDbgCfg);
333
334/**
335 * Releases a references to a debugging config.
336 *
337 * @returns New reference count, if 0 the config was freed. UINT32_MAX is
338 * returned if the handle is invalid (asserted).
339 * @param hDbgCfg The config handle.
340 */
341RTDECL(uint32_t) RTDbgCfgRelease(RTDBGCFG hDbgCfg);
342
343/**
344 * Changes a property value by string.
345 *
346 * For string values the string is used more or less as given. For integer
347 * values and flags, it can contains both values (ORed together) or property
348 * specific mnemonics (ORed / ~ANDed).
349 *
350 * @returns IPRT status code.
351 * @retval VERR_DBG_CFG_INVALID_VALUE
352 * @param hDbgCfg The debugging configuration handle.
353 * @param enmProp The property to change.
354 * @param enmOp How to change the property.
355 * @param pszValue The property value to apply.
356 */
357RTDECL(int) RTDbgCfgChangeString(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, RTDBGCFGOP enmOp, const char *pszValue);
358
359/**
360 * Changes a property value by unsigned integer (64-bit).
361 *
362 * This can only be applied to integer and flag properties.
363 *
364 * @returns IPRT status code.
365 * @retval VERR_DBG_CFG_NOT_UINT_PROP
366 * @param hDbgCfg The debugging configuration handle.
367 * @param enmProp The property to change.
368 * @param enmOp How to change the property.
369 * @param uValue The property value to apply.
370 */
371RTDECL(int) RTDbgCfgChangeUInt(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, RTDBGCFGOP enmOp, uint64_t uValue);
372
373/**
374 * Query a property value as string.
375 *
376 * Integer and flags properties are returned as a list of mnemonics if possible,
377 * otherwise as simple hex values.
378 *
379 * @returns IPRT status code.
380 * @retval VERR_BUFFER_OVERFLOW if there isn't sufficient buffer space. Nothing
381 * is written.
382 * @param hDbgCfg The debugging configuration handle.
383 * @param enmProp The property to change.
384 * @param pszValue The output buffer.
385 * @param cbValue The size of the output buffer.
386 */
387RTDECL(int) RTDbgCfgQueryString(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, char *pszValue, size_t cbValue);
388
389/**
390 * Query a property value as unsigned integer (64-bit).
391 *
392 * Only integer and flags properties can be queried this way.
393 *
394 * @returns IPRT status code.
395 * @retval VERR_DBG_CFG_NOT_UINT_PROP
396 * @param hDbgCfg The debugging configuration handle.
397 * @param enmProp The property to change.
398 * @param puValue Where to return the value.
399 */
400RTDECL(int) RTDbgCfgQueryUInt(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, uint64_t *puValue);
401
402
403/**
404 * Callback used by the RTDbgCfgOpen function to try out a file that was found.
405 *
406 * @returns On statuses other than VINF_CALLBACK_RETURN and
407 * VERR_CALLBACK_RETURN the search will continue till the end of the
408 * list. These status codes will not necessarily be propagated to the
409 * caller in any consistent manner.
410 * @retval VINF_CALLBACK_RETURN if successuflly opened the file and it's time
411 * to return
412 * @retval VERR_CALLBACK_RETURN if we shouldn't stop searching.
413 *
414 * @param hDbgCfg The debugging configuration handle.
415 * @param pszFilename The path to the file that should be tried out.
416 * @param pvUser1 First user parameter.
417 * @param pvUser2 Second user parameter.
418 */
419typedef DECLCALLBACK(int) FNDBGCFGOPEN(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2);
420/** Pointer to a open-file callback used to the RTDbgCfgOpen functions. */
421typedef FNDBGCFGOPEN *PFNDBGCFGOPEN;
422
423
424RTDECL(int) RTDbgCfgOpenPeImage(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t cbImage, uint32_t uTimestamp,
425 PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
426RTDECL(int) RTDbgCfgOpenPdb70(RTDBGCFG hDbgCfg, const char *pszFilename, PCRTUUID pUuid, uint32_t uAge,
427 PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
428RTDECL(int) RTDbgCfgOpenPdb20(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t cbImage, uint32_t uTimestamp, uint32_t uAge,
429 PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
430RTDECL(int) RTDbgCfgOpenDbg(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t cbImage, uint32_t uTimestamp,
431 PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
432RTDECL(int) RTDbgCfgOpenDwo(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t uCrc32,
433 PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
434/** @} */
435
436
437/** @defgroup grp_rt_dbgas RTDbgAs - Debug Address Space
438 * @{
439 */
440
441/**
442 * Creates an empty address space.
443 *
444 * @returns IPRT status code.
445 *
446 * @param phDbgAs Where to store the address space handle on success.
447 * @param FirstAddr The first address in the address space.
448 * @param LastAddr The last address in the address space.
449 * @param pszName The name of the address space.
450 */
451RTDECL(int) RTDbgAsCreate(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszName);
452
453/**
454 * Variant of RTDbgAsCreate that takes a name format string.
455 *
456 * @returns IPRT status code.
457 *
458 * @param phDbgAs Where to store the address space handle on success.
459 * @param FirstAddr The first address in the address space.
460 * @param LastAddr The last address in the address space.
461 * @param pszNameFmt The name format of the address space.
462 * @param va Format arguments.
463 */
464RTDECL(int) RTDbgAsCreateV(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszNameFmt, va_list va);
465
466/**
467 * Variant of RTDbgAsCreate that takes a name format string.
468 *
469 * @returns IPRT status code.
470 *
471 * @param phDbgAs Where to store the address space handle on success.
472 * @param FirstAddr The first address in the address space.
473 * @param LastAddr The last address in the address space.
474 * @param pszNameFmt The name format of the address space.
475 * @param ... Format arguments.
476 */
477RTDECL(int) RTDbgAsCreateF(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszNameFmt, ...);
478
479/**
480 * Retains a reference to the address space.
481 *
482 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
483 *
484 * @param hDbgAs The address space handle.
485 *
486 * @remarks Will not take any locks.
487 */
488RTDECL(uint32_t) RTDbgAsRetain(RTDBGAS hDbgAs);
489
490/**
491 * Release a reference to the address space.
492 *
493 * When the reference count reaches zero, the address space is destroyed.
494 * That means unlinking all the modules it currently contains, potentially
495 * causing some or all of them to be destroyed as they are managed by
496 * reference counting.
497 *
498 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
499 *
500 * @param hDbgAs The address space handle. The NIL handle is quietly
501 * ignored and 0 is returned.
502 *
503 * @remarks Will not take any locks.
504 */
505RTDECL(uint32_t) RTDbgAsRelease(RTDBGAS hDbgAs);
506
507/**
508 * Gets the name of an address space.
509 *
510 * @returns read only address space name.
511 * NULL if hDbgAs is invalid.
512 *
513 * @param hDbgAs The address space handle.
514 *
515 * @remarks Will not take any locks.
516 */
517RTDECL(const char *) RTDbgAsName(RTDBGAS hDbgAs);
518
519/**
520 * Gets the first address in an address space.
521 *
522 * @returns The address.
523 * 0 if hDbgAs is invalid.
524 *
525 * @param hDbgAs The address space handle.
526 *
527 * @remarks Will not take any locks.
528 */
529RTDECL(RTUINTPTR) RTDbgAsFirstAddr(RTDBGAS hDbgAs);
530
531/**
532 * Gets the last address in an address space.
533 *
534 * @returns The address.
535 * 0 if hDbgAs is invalid.
536 *
537 * @param hDbgAs The address space handle.
538 *
539 * @remarks Will not take any locks.
540 */
541RTDECL(RTUINTPTR) RTDbgAsLastAddr(RTDBGAS hDbgAs);
542
543/**
544 * Gets the number of modules in the address space.
545 *
546 * This can be used together with RTDbgAsModuleByIndex
547 * to enumerate the modules.
548 *
549 * @returns The number of modules.
550 *
551 * @param hDbgAs The address space handle.
552 *
553 * @remarks Will not take any locks.
554 */
555RTDECL(uint32_t) RTDbgAsModuleCount(RTDBGAS hDbgAs);
556
557/** @name Flags for RTDbgAsModuleLink and RTDbgAsModuleLinkSeg
558 * @{ */
559/** Replace all conflicting module.
560 * (The conflicting modules will be removed the address space and their
561 * references released.) */
562#define RTDBGASLINK_FLAGS_REPLACE RT_BIT_32(0)
563/** Mask containing the valid flags. */
564#define RTDBGASLINK_FLAGS_VALID_MASK UINT32_C(0x00000001)
565/** @} */
566
567/**
568 * Links a module into the address space at the give address.
569 *
570 * The size of the mapping is determined using RTDbgModImageSize().
571 *
572 * @returns IPRT status code.
573 * @retval VERR_OUT_OF_RANGE if the specified address will put the module
574 * outside the address space.
575 * @retval VERR_ADDRESS_CONFLICT if the mapping clashes with existing mappings.
576 *
577 * @param hDbgAs The address space handle.
578 * @param hDbgMod The module handle of the module to be linked in.
579 * @param ImageAddr The address to link the module at.
580 * @param fFlags See RTDBGASLINK_FLAGS_*.
581 */
582RTDECL(int) RTDbgAsModuleLink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTUINTPTR ImageAddr, uint32_t fFlags);
583
584/**
585 * Links a segment into the address space at the give address.
586 *
587 * The size of the mapping is determined using RTDbgModSegmentSize().
588 *
589 * @returns IPRT status code.
590 * @retval VERR_OUT_OF_RANGE if the specified address will put the module
591 * outside the address space.
592 * @retval VERR_ADDRESS_CONFLICT if the mapping clashes with existing mappings.
593 *
594 * @param hDbgAs The address space handle.
595 * @param hDbgMod The module handle.
596 * @param iSeg The segment number (0-based) of the segment to be
597 * linked in.
598 * @param SegAddr The address to link the segment at.
599 * @param fFlags See RTDBGASLINK_FLAGS_*.
600 */
601RTDECL(int) RTDbgAsModuleLinkSeg(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR SegAddr, uint32_t fFlags);
602
603/**
604 * Unlinks all the mappings of a module from the address space.
605 *
606 * @returns IPRT status code.
607 * @retval VERR_NOT_FOUND if the module wasn't found.
608 *
609 * @param hDbgAs The address space handle.
610 * @param hDbgMod The module handle of the module to be unlinked.
611 */
612RTDECL(int) RTDbgAsModuleUnlink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod);
613
614/**
615 * Unlinks the mapping at the specified address.
616 *
617 * @returns IPRT status code.
618 * @retval VERR_NOT_FOUND if no module or segment is mapped at that address.
619 *
620 * @param hDbgAs The address space handle.
621 * @param Addr The address within the mapping to be unlinked.
622 */
623RTDECL(int) RTDbgAsModuleUnlinkByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr);
624
625/**
626 * Get a the handle of a module in the address space by is index.
627 *
628 * @returns A retained handle to the specified module. The caller must release
629 * the returned reference.
630 * NIL_RTDBGMOD if invalid index or handle.
631 *
632 * @param hDbgAs The address space handle.
633 * @param iModule The index of the module to get.
634 *
635 * @remarks The module indexes may change after calls to RTDbgAsModuleLink,
636 * RTDbgAsModuleLinkSeg, RTDbgAsModuleUnlink and
637 * RTDbgAsModuleUnlinkByAddr.
638 */
639RTDECL(RTDBGMOD) RTDbgAsModuleByIndex(RTDBGAS hDbgAs, uint32_t iModule);
640
641/**
642 * Queries mapping module information by handle.
643 *
644 * @returns IPRT status code.
645 * @retval VERR_NOT_FOUND if no mapping was found at the specified address.
646 *
647 * @param hDbgAs The address space handle.
648 * @param Addr Address within the mapping of the module or segment.
649 * @param phMod Where to the return the retained module handle.
650 * Optional.
651 * @param pAddr Where to return the base address of the mapping.
652 * Optional.
653 * @param piSeg Where to return the segment index. This is set to
654 * NIL if the entire module is mapped as a single
655 * mapping. Optional.
656 */
657RTDECL(int) RTDbgAsModuleByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTDBGMOD phMod, PRTUINTPTR pAddr, PRTDBGSEGIDX piSeg);
658
659/**
660 * Queries mapping module information by name.
661 *
662 * @returns IPRT status code.
663 * @retval VERR_NOT_FOUND if no mapping was found at the specified address.
664 * @retval VERR_OUT_OF_RANGE if the name index was out of range.
665 *
666 * @param hDbgAs The address space handle.
667 * @param pszName The module name.
668 * @param iName There can be more than one module by the same name
669 * in an address space. This argument indicates which
670 * is meant. (0 based)
671 * @param phMod Where to the return the retained module handle.
672 */
673RTDECL(int) RTDbgAsModuleByName(RTDBGAS hDbgAs, const char *pszName, uint32_t iName, PRTDBGMOD phMod);
674
675/**
676 * Information about a mapping.
677 *
678 * This is used by RTDbgAsModuleGetMapByIndex.
679 */
680typedef struct RTDBGASMAPINFO
681{
682 /** The mapping address. */
683 RTUINTPTR Address;
684 /** The segment mapped there.
685 * This is NIL_RTDBGSEGIDX if the entire module image is mapped here. */
686 RTDBGSEGIDX iSeg;
687} RTDBGASMAPINFO;
688/** Pointer to info about an address space mapping. */
689typedef RTDBGASMAPINFO *PRTDBGASMAPINFO;
690/** Pointer to const info about an address space mapping. */
691typedef RTDBGASMAPINFO const *PCRTDBGASMAPINFO;
692
693/**
694 * Queries mapping information for a module given by index.
695 *
696 * @returns IRPT status code.
697 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
698 * @retval VERR_OUT_OF_RANGE if the name index was out of range.
699 * @retval VINF_BUFFER_OVERFLOW if the array is too small and the returned
700 * information is incomplete.
701 *
702 * @param hDbgAs The address space handle.
703 * @param iModule The index of the module to get.
704 * @param paMappings Where to return the mapping information. The buffer
705 * size is given by *pcMappings.
706 * @param pcMappings IN: Size of the paMappings array. OUT: The number of
707 * entries returned.
708 * @param fFlags Flags for reserved for future use. MBZ.
709 *
710 * @remarks See remarks for RTDbgAsModuleByIndex regarding the volatility of the
711 * iModule parameter.
712 */
713RTDECL(int) RTDbgAsModuleQueryMapByIndex(RTDBGAS hDbgAs, uint32_t iModule, PRTDBGASMAPINFO paMappings, uint32_t *pcMappings, uint32_t fFlags);
714
715/**
716 * Adds a symbol to a module in the address space.
717 *
718 * @returns IPRT status code. See RTDbgModSymbolAdd for more specific ones.
719 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
720 * @retval VERR_NOT_FOUND if no module was found at the specified address.
721 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
722 * custom symbols.
723 *
724 * @param hDbgAs The address space handle.
725 * @param pszSymbol The symbol name.
726 * @param Addr The address of the symbol.
727 * @param cb The size of the symbol.
728 * @param fFlags Symbol flags.
729 * @param piOrdinal Where to return the symbol ordinal on success. If
730 * the interpreter doesn't do ordinals, this will be set to
731 * UINT32_MAX. Optional
732 */
733RTDECL(int) RTDbgAsSymbolAdd(RTDBGAS hDbgAs, const char *pszSymbol, RTUINTPTR Addr, RTUINTPTR cb, uint32_t fFlags, uint32_t *piOrdinal);
734
735/**
736 * Query a symbol by address.
737 *
738 * @returns IPRT status code. See RTDbgModSymbolAddr for more specific ones.
739 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
740 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
741 * @retval VERR_INVALID_PARAMETER if incorrect flags.
742 *
743 * @param hDbgAs The address space handle.
744 * @param Addr The address which closest symbol is requested.
745 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
746 * @param poffDisp Where to return the distance between the symbol
747 * and address. Optional.
748 * @param pSymbol Where to return the symbol info.
749 * @param phMod Where to return the module handle. Optional.
750 */
751RTDECL(int) RTDbgAsSymbolByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, uint32_t fFlags,
752 PRTINTPTR poffDisp, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
753
754/**
755 * Query a symbol by address.
756 *
757 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
758 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
759 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
760 * @retval VERR_INVALID_PARAMETER if incorrect flags.
761 *
762 * @param hDbgAs The address space handle.
763 * @param Addr The address which closest symbol is requested.
764 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
765 * @param poffDisp Where to return the distance between the symbol
766 * and address. Optional.
767 * @param ppSymInfo Where to return the pointer to the allocated symbol
768 * info. Always set. Free with RTDbgSymbolFree.
769 * @param phMod Where to return the module handle. Optional.
770 */
771RTDECL(int) RTDbgAsSymbolByAddrA(RTDBGAS hDbgAs, RTUINTPTR Addr, uint32_t fFlags,
772 PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymInfo, PRTDBGMOD phMod);
773
774/**
775 * Query a symbol by name.
776 *
777 * @returns IPRT status code.
778 * @retval VERR_SYMBOL_NOT_FOUND if not found.
779 *
780 * @param hDbgAs The address space handle.
781 * @param pszSymbol The symbol name. It is possible to limit the scope
782 * of the search by prefixing the symbol with a module
783 * name pattern followed by a bang (!) character.
784 * RTStrSimplePatternNMatch is used for the matching.
785 * @param pSymbol Where to return the symbol info.
786 * @param phMod Where to return the module handle. Optional.
787 */
788RTDECL(int) RTDbgAsSymbolByName(RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
789
790/**
791 * Query a symbol by name, allocating the returned symbol structure.
792 *
793 * @returns IPRT status code.
794 * @retval VERR_SYMBOL_NOT_FOUND if not found.
795 *
796 * @param hDbgAs The address space handle.
797 * @param pszSymbol The symbol name. See RTDbgAsSymbolByName for more.
798 * @param ppSymbol Where to return the pointer to the allocated
799 * symbol info. Always set. Free with RTDbgSymbolFree.
800 * @param phMod Where to return the module handle. Optional.
801 */
802RTDECL(int) RTDbgAsSymbolByNameA(RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL *ppSymbol, PRTDBGMOD phMod);
803
804/**
805 * Query a line number by address.
806 *
807 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
808 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
809 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
810 *
811 * @param hDbgAs The address space handle.
812 * @param Addr The address which closest symbol is requested.
813 * @param poffDisp Where to return the distance between the line
814 * number and address.
815 * @param pLine Where to return the line number information.
816 */
817RTDECL(int) RTDbgAs(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE pLine);
818
819/**
820 * Adds a line number to a module in the address space.
821 *
822 * @returns IPRT status code. See RTDbgModSymbolAdd for more specific ones.
823 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
824 * @retval VERR_NOT_FOUND if no module was found at the specified address.
825 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
826 * custom symbols.
827 *
828 * @param hDbgAs The address space handle.
829 * @param pszFile The file name.
830 * @param uLineNo The line number.
831 * @param Addr The address of the symbol.
832 * @param piOrdinal Where to return the line number ordinal on success.
833 * If the interpreter doesn't do ordinals, this will be
834 * set to UINT32_MAX. Optional.
835 */
836RTDECL(int) RTDbgAsLineAdd(RTDBGAS hDbgAs, const char *pszFile, uint32_t uLineNo, RTUINTPTR Addr, uint32_t *piOrdinal);
837
838
839/**
840 * Query a line number by address.
841 *
842 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
843 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
844 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
845 *
846 * @param hDbgAs The address space handle.
847 * @param Addr The address which closest symbol is requested.
848 * @param poffDisp Where to return the distance between the line
849 * number and address.
850 * @param pLine Where to return the line number information.
851 */
852RTDECL(int) RTDbgAsLineByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE pLine);
853
854/**
855 * Query a line number by address.
856 *
857 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
858 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
859 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
860 *
861 * @param hDbgAs The address space handle.
862 * @param Addr The address which closest symbol is requested.
863 * @param poffDisp Where to return the distance between the line
864 * number and address.
865 * @param ppLine Where to return the pointer to the allocated line
866 * number info. Always set. Free with RTDbgLineFree.
867 */
868RTDECL(int) RTDbgAsLineByAddrA(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE *ppLine);
869
870/** @todo Missing some bits here. */
871
872/** @} */
873
874
875/** @defgroup grp_rt_dbgmod RTDbgMod - Debug Module Interpreter
876 * @{
877 */
878
879/**
880 * Creates a module based on the default debug info container.
881 *
882 * This can be used to manually load a module and its symbol. The primary user
883 * group is the debug info interpreters, which use this API to create an
884 * efficient debug info container behind the scenes and forward all queries to
885 * it once the info has been loaded.
886 *
887 * @returns IPRT status code.
888 *
889 * @param phDbgMod Where to return the module handle.
890 * @param pszName The name of the module (mandatory).
891 * @param cbSeg The size of initial segment. If zero, segments will
892 * have to be added manually using RTDbgModSegmentAdd.
893 * @param fFlags Flags reserved for future extensions, MBZ for now.
894 */
895RTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cbSeg, uint32_t fFlags);
896
897RTDECL(int) RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName,
898 RTDBGCFG hDbgCfg);
899RTDECL(int) RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR uSubtrahend,
900 RTDBGCFG hDbgCfg);
901RTDECL(int) RTDbgModCreateFromPeImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage,
902 uint32_t uTimeDateStamp, RTDBGCFG hDbgCfg);
903RTDECL(int) RTDbgModCreateFromDbg(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage,
904 uint32_t uTimeDateStamp, RTDBGCFG hDbgCfg);
905RTDECL(int) RTDbgModCreateFromPdb(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage,
906 PCRTUUID pUuid, uint32_t Age, RTDBGCFG hDbgCfg);
907RTDECL(int) RTDbgModCreateFromDwo(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage,
908 uint32_t uCrc32, RTDBGCFG hDbgCfg);
909
910
911/**
912 * Retains another reference to the module.
913 *
914 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
915 *
916 * @param hDbgMod The module handle.
917 *
918 * @remarks Will not take any locks.
919 */
920RTDECL(uint32_t) RTDbgModRetain(RTDBGMOD hDbgMod);
921
922/**
923 * Release a reference to the module.
924 *
925 * When the reference count reaches zero, the module is destroyed.
926 *
927 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
928 *
929 * @param hDbgMod The module handle. The NIL handle is quietly ignored
930 * and 0 is returned.
931 *
932 * @remarks Will not take any locks.
933 */
934RTDECL(uint32_t) RTDbgModRelease(RTDBGMOD hDbgMod);
935
936/**
937 * Gets the module name.
938 *
939 * @returns Pointer to a read only string containing the name.
940 *
941 * @param hDbgMod The module handle.
942 */
943RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod);
944
945/**
946 * Converts an image relative address to a segment:offset address.
947 *
948 * @returns Segment index on success.
949 * NIL_RTDBGSEGIDX is returned if the module handle or the RVA are
950 * invalid.
951 *
952 * @param hDbgMod The module handle.
953 * @param uRva The image relative address to convert.
954 * @param poffSeg Where to return the segment offset. Optional.
955 */
956RTDECL(RTDBGSEGIDX) RTDbgModRvaToSegOff(RTDBGMOD hDbgMod, RTUINTPTR uRva, PRTUINTPTR poffSeg);
957
958/**
959 * Image size when mapped if segments are mapped adjacently.
960 *
961 * For ELF, PE, and Mach-O images this is (usually) a natural query, for LX and
962 * NE and such it's a bit odder and the answer may not make much sense for them.
963 *
964 * @returns Image mapped size.
965 * RTUINTPTR_MAX is returned if the handle is invalid.
966 *
967 * @param hDbgMod The module handle.
968 */
969RTDECL(RTUINTPTR) RTDbgModImageSize(RTDBGMOD hDbgMod);
970
971/**
972 * Gets the module tag value if any.
973 *
974 * @returns The tag. 0 if hDbgMod is invalid.
975 *
976 * @param hDbgMod The module handle.
977 */
978RTDECL(uint64_t) RTDbgModGetTag(RTDBGMOD hDbgMod);
979
980/**
981 * Tags or untags the module.
982 *
983 * @returns IPRT status code.
984 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
985 *
986 * @param hDbgMod The module handle.
987 * @param uTag The tag value. The convention is that 0 is no tag
988 * and any other value means it's tagged. It's adviced
989 * to use some kind of unique number like an address
990 * (global or string cache for instance) to avoid
991 * collisions with other users
992 */
993RTDECL(int) RTDbgModSetTag(RTDBGMOD hDbgMod, uint64_t uTag);
994
995
996/**
997 * Adds a segment to the module. Optional feature.
998 *
999 * This method is intended used for manually constructing debug info for a
1000 * module. The main usage is from other debug info interpreters that want to
1001 * avoid writing a debug info database and instead uses the standard container
1002 * behind the scenes.
1003 *
1004 * @returns IPRT status code.
1005 * @retval VERR_NOT_SUPPORTED if this feature isn't support by the debug info
1006 * interpreter. This is a common return code.
1007 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1008 * @retval VERR_DBG_ADDRESS_WRAP if uRva+cb wraps around.
1009 * @retval VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE if pszName is too short or long.
1010 * @retval VERR_INVALID_PARAMETER if fFlags contains undefined flags.
1011 * @retval VERR_DBG_SPECIAL_SEGMENT if *piSeg is a special segment.
1012 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if *piSeg doesn't meet expectations.
1013 *
1014 * @param hDbgMod The module handle.
1015 * @param uRva The image relative address of the segment.
1016 * @param cb The size of the segment.
1017 * @param pszName The segment name. Does not normally need to be
1018 * unique, although this is somewhat up to the
1019 * debug interpreter to decide.
1020 * @param fFlags Segment flags. Reserved for future used, MBZ.
1021 * @param piSeg The segment index or NIL_RTDBGSEGIDX on input.
1022 * The assigned segment index on successful return.
1023 * Optional.
1024 */
1025RTDECL(int) RTDbgModSegmentAdd(RTDBGMOD hDbgMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName,
1026 uint32_t fFlags, PRTDBGSEGIDX piSeg);
1027
1028/**
1029 * Gets the number of segments in the module.
1030 *
1031 * This is can be used to determine the range which can be passed to
1032 * RTDbgModSegmentByIndex and derivates.
1033 *
1034 * @returns The segment relative address.
1035 * NIL_RTDBGSEGIDX if the handle is invalid.
1036 *
1037 * @param hDbgMod The module handle.
1038 */
1039RTDECL(RTDBGSEGIDX) RTDbgModSegmentCount(RTDBGMOD hDbgMod);
1040
1041/**
1042 * Query information about a segment.
1043 *
1044 * This can be used together with RTDbgModSegmentCount to enumerate segments.
1045 * The index starts a 0 and stops one below RTDbgModSegmentCount.
1046 *
1047 * @returns IPRT status code.
1048 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if iSeg is too high.
1049 * @retval VERR_DBG_SPECIAL_SEGMENT if iSeg indicates a special segment.
1050 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1051 *
1052 * @param hDbgMod The module handle.
1053 * @param iSeg The segment index. No special segments.
1054 * @param pSegInfo Where to return the segment info. The
1055 * RTDBGSEGMENT::Address member will be set to
1056 * RTUINTPTR_MAX or the load address used at link time.
1057 */
1058RTDECL(int) RTDbgModSegmentByIndex(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo);
1059
1060/**
1061 * Gets the size of a segment.
1062 *
1063 * This is a just a wrapper around RTDbgModSegmentByIndex.
1064 *
1065 * @returns The segment size.
1066 * RTUINTPTR_MAX is returned if either the handle and segment index are
1067 * invalid.
1068 *
1069 * @param hDbgMod The module handle.
1070 * @param iSeg The segment index. RTDBGSEGIDX_ABS is not allowed.
1071 * If RTDBGSEGIDX_RVA is used, the functions returns
1072 * the same value as RTDbgModImageSize.
1073 */
1074RTDECL(RTUINTPTR) RTDbgModSegmentSize(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
1075
1076/**
1077 * Gets the image relative address of a segment.
1078 *
1079 * This is a just a wrapper around RTDbgModSegmentByIndex.
1080 *
1081 * @returns The segment relative address.
1082 * RTUINTPTR_MAX is returned if either the handle and segment index are
1083 * invalid.
1084 *
1085 * @param hDbgMod The module handle.
1086 * @param iSeg The segment index. No special segment indexes
1087 * allowed (asserted).
1088 */
1089RTDECL(RTUINTPTR) RTDbgModSegmentRva(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
1090
1091
1092/**
1093 * Adds a line number to the module.
1094 *
1095 * @returns IPRT status code.
1096 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
1097 * custom symbols. This is a common place occurrence.
1098 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1099 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1100 * short.
1101 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1102 * it's not inside any of the segments defined by the module.
1103 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1104 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1105 * end of the segment.
1106 * @retval VERR_DBG_ADDRESS_WRAP if off+cb wraps around.
1107 * @retval VERR_INVALID_PARAMETER if the symbol flags sets undefined bits.
1108 *
1109 * @param hDbgMod The module handle.
1110 * @param pszSymbol The symbol name.
1111 * @param iSeg The segment index.
1112 * @param off The segment offset.
1113 * @param cb The size of the symbol. Can be zero, although this
1114 * may depend somewhat on the debug interpreter.
1115 * @param fFlags Symbol flags. Reserved for the future, MBZ.
1116 * @param piOrdinal Where to return the symbol ordinal on success. If
1117 * the interpreter doesn't do ordinals, this will be set to
1118 * UINT32_MAX. Optional.
1119 */
1120RTDECL(int) RTDbgModSymbolAdd(RTDBGMOD hDbgMod, const char *pszSymbol, RTDBGSEGIDX iSeg, RTUINTPTR off,
1121 RTUINTPTR cb, uint32_t fFlags, uint32_t *piOrdinal);
1122
1123/**
1124 * Gets the symbol count.
1125 *
1126 * This can be used together wtih RTDbgModSymbolByOrdinal or
1127 * RTDbgModSymbolByOrdinalA to enumerate all the symbols.
1128 *
1129 * @returns The number of symbols in the module.
1130 * UINT32_MAX is returned if the module handle is invalid or some other
1131 * error occurs.
1132 *
1133 * @param hDbgMod The module handle.
1134 */
1135RTDECL(uint32_t) RTDbgModSymbolCount(RTDBGMOD hDbgMod);
1136
1137/**
1138 * Queries symbol information by ordinal number.
1139 *
1140 * @returns IPRT status code.
1141 * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at the given number.
1142 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1143 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1144 * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
1145 *
1146 * @param hDbgMod The module handle.
1147 * @param iOrdinal The symbol ordinal number. 0-based. The highest
1148 * number is RTDbgModSymbolCount() - 1.
1149 * @param pSymInfo Where to store the symbol information.
1150 */
1151RTDECL(int) RTDbgModSymbolByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo);
1152
1153/**
1154 * Queries symbol information by ordinal number.
1155 *
1156 * @returns IPRT status code.
1157 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1158 * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
1159 * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at the given number.
1160 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1161 *
1162 * @param hDbgMod The module handle.
1163 * @param iOrdinal The symbol ordinal number. 0-based. The highest
1164 * number is RTDbgModSymbolCount() - 1.
1165 * @param ppSymInfo Where to store the pointer to the returned
1166 * symbol information. Always set. Free with
1167 * RTDbgSymbolFree.
1168 */
1169RTDECL(int) RTDbgModSymbolByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL *ppSymInfo);
1170
1171/**
1172 * Queries symbol information by address.
1173 *
1174 * The returned symbol is what the debug info interpreter considers the symbol
1175 * most applicable to the specified address. This usually means a symbol with an
1176 * address equal or lower than the requested.
1177 *
1178 * @returns IPRT status code.
1179 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1180 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1181 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1182 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1183 * it's not inside any of the segments defined by the module.
1184 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1185 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1186 * end of the segment.
1187 * @retval VERR_INVALID_PARAMETER if incorrect flags.
1188 *
1189 * @param hDbgMod The module handle.
1190 * @param iSeg The segment number.
1191 * @param off The offset into the segment.
1192 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
1193 * @param poffDisp Where to store the distance between the
1194 * specified address and the returned symbol.
1195 * Optional.
1196 * @param pSymInfo Where to store the symbol information.
1197 */
1198RTDECL(int) RTDbgModSymbolByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
1199 PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo);
1200
1201/**
1202 * Queries symbol information by address.
1203 *
1204 * The returned symbol is what the debug info interpreter considers the symbol
1205 * most applicable to the specified address. This usually means a symbol with an
1206 * address equal or lower than the requested.
1207 *
1208 * @returns IPRT status code.
1209 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1210 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1211 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1212 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1213 * it's not inside any of the segments defined by the module.
1214 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1215 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1216 * end of the segment.
1217 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1218 * @retval VERR_INVALID_PARAMETER if incorrect flags.
1219 *
1220 * @param hDbgMod The module handle.
1221 * @param iSeg The segment index.
1222 * @param off The offset into the segment.
1223 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
1224 * @param poffDisp Where to store the distance between the
1225 * specified address and the returned symbol. Optional.
1226 * @param ppSymInfo Where to store the pointer to the returned
1227 * symbol information. Always set. Free with
1228 * RTDbgSymbolFree.
1229 */
1230RTDECL(int) RTDbgModSymbolByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
1231 PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymInfo);
1232
1233/**
1234 * Queries symbol information by symbol name.
1235 *
1236 * @returns IPRT status code.
1237 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1238 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1239 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1240 * short.
1241 *
1242 * @param hDbgMod The module handle.
1243 * @param pszSymbol The symbol name.
1244 * @param pSymInfo Where to store the symbol information.
1245 */
1246RTDECL(int) RTDbgModSymbolByName(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL pSymInfo);
1247
1248/**
1249 * Queries symbol information by symbol name.
1250 *
1251 * @returns IPRT status code.
1252 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1253 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1254 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1255 * short.
1256 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1257 *
1258 * @param hDbgMod The module handle.
1259 * @param pszSymbol The symbol name.
1260 * @param ppSymInfo Where to store the pointer to the returned
1261 * symbol information. Always set. Free with
1262 * RTDbgSymbolFree.
1263 */
1264RTDECL(int) RTDbgModSymbolByNameA(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL *ppSymInfo);
1265
1266/**
1267 * Adds a line number to the module.
1268 *
1269 * @returns IPRT status code.
1270 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
1271 * custom symbols. This should be consider a normal response.
1272 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1273 * @retval VERR_DBG_FILE_NAME_OUT_OF_RANGE if the file name is too longer or
1274 * empty.
1275 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1276 * it's not inside any of the segments defined by the module.
1277 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1278 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1279 * end of the segment.
1280 * @retval VERR_INVALID_PARAMETER if the line number flags sets undefined bits.
1281 *
1282 * @param hDbgMod The module handle.
1283 * @param pszFile The file name.
1284 * @param uLineNo The line number.
1285 * @param iSeg The segment index.
1286 * @param off The segment offset.
1287 * @param piOrdinal Where to return the line number ordinal on
1288 * success. If the interpreter doesn't do ordinals,
1289 * this will be set to UINT32_MAX. Optional.
1290 */
1291RTDECL(int) RTDbgModLineAdd(RTDBGMOD hDbgMod, const char *pszFile, uint32_t uLineNo,
1292 RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t *piOrdinal);
1293
1294/**
1295 * Gets the line number count.
1296 *
1297 * This can be used together wtih RTDbgModLineByOrdinal or RTDbgModSymbolByLineA
1298 * to enumerate all the line number information.
1299 *
1300 * @returns The number of line numbers in the module.
1301 * UINT32_MAX is returned if the module handle is invalid or some other
1302 * error occurs.
1303 *
1304 * @param hDbgMod The module handle.
1305 */
1306RTDECL(uint32_t) RTDbgModLineCount(RTDBGMOD hDbgMod);
1307
1308/**
1309 * Queries line number information by ordinal number.
1310 *
1311 * This can be used to enumerate the line numbers for the module. Use
1312 * RTDbgModLineCount() to figure the end of the ordinals.
1313 *
1314 * @returns IPRT status code.
1315 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1316 * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
1317 * ordinal.
1318 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1319
1320 * @param hDbgMod The module handle.
1321 * @param iOrdinal The line number ordinal number.
1322 * @param pLineInfo Where to store the information about the line
1323 * number.
1324 */
1325RTDECL(int) RTDbgModLineByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo);
1326
1327/**
1328 * Queries line number information by ordinal number.
1329 *
1330 * This can be used to enumerate the line numbers for the module. Use
1331 * RTDbgModLineCount() to figure the end of the ordinals.
1332 *
1333 * @returns IPRT status code.
1334 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1335 * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
1336 * ordinal.
1337 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1338 * @retval VERR_NO_MEMORY if RTDbgLineAlloc fails.
1339 *
1340 * @param hDbgMod The module handle.
1341 * @param iOrdinal The line number ordinal number.
1342 * @param ppLineInfo Where to store the pointer to the returned line
1343 * number information. Always set. Free with
1344 * RTDbgLineFree.
1345 */
1346RTDECL(int) RTDbgModLineByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE *ppLineInfo);
1347
1348/**
1349 * Queries line number information by address.
1350 *
1351 * The returned line number is what the debug info interpreter considers the
1352 * one most applicable to the specified address. This usually means a line
1353 * number with an address equal or lower than the requested.
1354 *
1355 * @returns IPRT status code.
1356 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1357 * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
1358 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1359 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1360 * it's not inside any of the segments defined by the module.
1361 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1362 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1363 * end of the segment.
1364 *
1365 * @param hDbgMod The module handle.
1366 * @param iSeg The segment number.
1367 * @param off The offset into the segment.
1368 * @param poffDisp Where to store the distance between the
1369 * specified address and the returned symbol.
1370 * Optional.
1371 * @param pLineInfo Where to store the line number information.
1372 */
1373RTDECL(int) RTDbgModLineByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLineInfo);
1374
1375/**
1376 * Queries line number information by address.
1377 *
1378 * The returned line number is what the debug info interpreter considers the
1379 * one most applicable to the specified address. This usually means a line
1380 * number with an address equal or lower than the requested.
1381 *
1382 * @returns IPRT status code.
1383 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1384 * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
1385 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1386 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1387 * it's not inside any of the segments defined by the module.
1388 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1389 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1390 * end of the segment.
1391 * @retval VERR_NO_MEMORY if RTDbgLineAlloc fails.
1392 *
1393 * @param hDbgMod The module handle.
1394 * @param iSeg The segment number.
1395 * @param off The offset into the segment.
1396 * @param poffDisp Where to store the distance between the
1397 * specified address and the returned symbol.
1398 * Optional.
1399 * @param ppLineInfo Where to store the pointer to the returned line
1400 * number information. Always set. Free with
1401 * RTDbgLineFree.
1402 */
1403RTDECL(int) RTDbgModLineByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE *ppLineInfo);
1404/** @} */
1405
1406# endif /* IN_RING3 */
1407
1408
1409/** @name Kernel Debug Info API
1410 *
1411 * This is a specialized API for obtaining symbols and structure information
1412 * about the running kernel. It is relatively OS specific. Its purpose and
1413 * operation is doesn't map all that well onto RTDbgMod, so a few dedicated
1414 * functions was created for it.
1415 *
1416 * @{ */
1417
1418/** Handle to the kernel debug info. */
1419typedef struct RTDBGKRNLINFOINT *RTDBGKRNLINFO;
1420/** Pointer to a kernel debug info handle. */
1421typedef RTDBGKRNLINFO *PRTDBGKRNLINFO;
1422/** Nil kernel debug info handle. */
1423#define NIL_RTDBGKRNLINFO ((RTDBGKRNLINFO)0)
1424
1425/**
1426 * Opens the kernel debug info.
1427 *
1428 * @returns IPRT status code. Can fail for any number of reasons.
1429 *
1430 * @param phKrnlInfo Where to return the kernel debug info handle on
1431 * success.
1432 * @param fFlags Flags reserved for future use. Must be zero.
1433 */
1434RTR0DECL(int) RTR0DbgKrnlInfoOpen(PRTDBGKRNLINFO phKrnlInfo, uint32_t fFlags);
1435
1436/**
1437 * Retains a reference to the kernel debug info handle.
1438 *
1439 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1440 * @param hKrnlInfo The kernel info handle.
1441 */
1442RTR0DECL(uint32_t) RTR0DbgKrnlInfoRetain(RTDBGKRNLINFO hKrnlInfo);
1443
1444
1445/**
1446 * Releases a reference to the kernel debug info handle, destroying it when the
1447 * counter reaches zero.
1448 *
1449 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1450 * @param hKrnlInfo The kernel info handle. NIL_RTDBGKRNLINFO is
1451 * quietly ignored.
1452 */
1453RTR0DECL(uint32_t) RTR0DbgKrnlInfoRelease(RTDBGKRNLINFO hKrnlInfo);
1454
1455/**
1456 * Queries the offset (in bytes) of a member of a kernel structure.
1457 *
1458 * @returns IPRT status code.
1459 * @retval VINF_SUCCESS and offset at @a poffMember.
1460 * @retval VERR_NOT_FOUND if the structure or the member was not found.
1461 * @retval VERR_INVALID_HANDLE if hKrnlInfo is bad.
1462 * @retval VERR_INVALID_POINTER if any of the pointers are bad.
1463 *
1464 * @param hKrnlInfo The kernel info handle.
1465 * @param pszStructure The structure name.
1466 * @param pszMember The member name.
1467 * @param poffMember Where to return the offset.
1468 */
1469RTR0DECL(int) RTR0DbgKrnlInfoQueryMember(RTDBGKRNLINFO hKrnlInfo, const char *pszStructure,
1470 const char *pszMember, size_t *poffMember);
1471
1472
1473/**
1474 * Queries the value (usually the address) of a kernel symbol.
1475 *
1476 * This may go looking for the symbol in other modules, in which case it will
1477 * always check the kernel symbol table first.
1478 *
1479 * @returns IPRT status code.
1480 * @retval VINF_SUCCESS and value at @a ppvSymbol.
1481 * @retval VERR_SYMBOL_NOT_FOUND
1482 * @retval VERR_INVALID_HANDLE if hKrnlInfo is bad.
1483 * @retval VERR_INVALID_POINTER if any of the pointers are bad.
1484 *
1485 * @param hKrnlInfo The kernel info handle.
1486 * @param pszModule Reserved for future extensions. Pass NULL.
1487 * @param pszSymbol The C name of the symbol.
1488 * @param ppvSymbol Where to return the symbol value, passing NULL is
1489 * OK. This may be modified even on failure, in
1490 * particular, it will be set to NULL when
1491 * VERR_SYMBOL_NOT_FOUND is returned.
1492 *
1493 * @sa RTLdrGetSymbol.
1494 */
1495RTR0DECL(int) RTR0DbgKrnlInfoQuerySymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
1496 const char *pszSymbol, void **ppvSymbol);
1497/** @} */
1498
1499/** @} */
1500
1501RT_C_DECLS_END
1502
1503#endif
1504
Note: See TracBrowser for help on using the repository browser.

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