VirtualBox

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

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

More NT4 debugging. Getting closer to working state...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 61.0 KB
Line 
1/* $Id: dbg.h 46101 2013-05-15 15:36:43Z 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 * @param fNativePaths Whether to pick up native paths from the
321 * environment.
322 *
323 * @sa RTDbgCfgChangeString, RTDbgCfgChangeUInt.
324 */
325RTDECL(int) RTDbgCfgCreate(PRTDBGCFG phDbgCfg, const char *pszEnvVarPrefix, bool fNativePaths);
326
327/**
328 * Retains a new reference to a debugging config.
329 *
330 * @returns New reference count.
331 * UINT32_MAX is returned if the handle is invalid (asserted).
332 * @param hDbgCfg The config handle.
333 */
334RTDECL(uint32_t) RTDbgCfgRetain(RTDBGCFG hDbgCfg);
335
336/**
337 * Releases a references to a debugging config.
338 *
339 * @returns New reference count, if 0 the config was freed. UINT32_MAX is
340 * returned if the handle is invalid (asserted).
341 * @param hDbgCfg The config handle.
342 */
343RTDECL(uint32_t) RTDbgCfgRelease(RTDBGCFG hDbgCfg);
344
345/**
346 * Changes a property value by string.
347 *
348 * For string values the string is used more or less as given. For integer
349 * values and flags, it can contains both values (ORed together) or property
350 * specific mnemonics (ORed / ~ANDed).
351 *
352 * @returns IPRT status code.
353 * @retval VERR_DBG_CFG_INVALID_VALUE
354 * @param hDbgCfg The debugging configuration handle.
355 * @param enmProp The property to change.
356 * @param enmOp How to change the property.
357 * @param pszValue The property value to apply.
358 */
359RTDECL(int) RTDbgCfgChangeString(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, RTDBGCFGOP enmOp, const char *pszValue);
360
361/**
362 * Changes a property value by unsigned integer (64-bit).
363 *
364 * This can only be applied to integer and flag properties.
365 *
366 * @returns IPRT status code.
367 * @retval VERR_DBG_CFG_NOT_UINT_PROP
368 * @param hDbgCfg The debugging configuration handle.
369 * @param enmProp The property to change.
370 * @param enmOp How to change the property.
371 * @param uValue The property value to apply.
372 */
373RTDECL(int) RTDbgCfgChangeUInt(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, RTDBGCFGOP enmOp, uint64_t uValue);
374
375/**
376 * Query a property value as string.
377 *
378 * Integer and flags properties are returned as a list of mnemonics if possible,
379 * otherwise as simple hex values.
380 *
381 * @returns IPRT status code.
382 * @retval VERR_BUFFER_OVERFLOW if there isn't sufficient buffer space. Nothing
383 * is written.
384 * @param hDbgCfg The debugging configuration handle.
385 * @param enmProp The property to change.
386 * @param pszValue The output buffer.
387 * @param cbValue The size of the output buffer.
388 */
389RTDECL(int) RTDbgCfgQueryString(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, char *pszValue, size_t cbValue);
390
391/**
392 * Query a property value as unsigned integer (64-bit).
393 *
394 * Only integer and flags properties can be queried this way.
395 *
396 * @returns IPRT status code.
397 * @retval VERR_DBG_CFG_NOT_UINT_PROP
398 * @param hDbgCfg The debugging configuration handle.
399 * @param enmProp The property to change.
400 * @param puValue Where to return the value.
401 */
402RTDECL(int) RTDbgCfgQueryUInt(RTDBGCFG hDbgCfg, RTDBGCFGPROP enmProp, uint64_t *puValue);
403
404/**
405 * Log callback.
406 *
407 * @param hDbgCfg The debug config instance.
408 * @param iLevel The message level.
409 * @param pszMsg The message.
410 * @param pvUser User argument.
411 */
412typedef DECLCALLBACK(void) FNRTDBGCFGLOG(RTDBGCFG hDbgCfg, uint32_t iLevel, const char *pszMsg, void *pvUser);
413/** Pointer to a log callback. */
414typedef FNRTDBGCFGLOG *PFNRTDBGCFGLOG;
415
416/**
417 * Sets the log callback for the configuration.
418 *
419 * This will fail if there is already a log callback present, unless pfnCallback
420 * is NULL.
421 *
422 * @returns IPRT status code.
423 * @param hDbgCfg The debugging configuration handle.
424 * @param pfnCallback The callback function. NULL to unset.
425 * @param pvUser The user argument.
426 */
427RTDECL(int) RTDbgCfgSetLogCallback(RTDBGCFG hDbgCfg, PFNRTDBGCFGLOG pfnCallback, void *pvUser);
428
429/**
430 * Callback used by the RTDbgCfgOpen function to try out a file that was found.
431 *
432 * @returns On statuses other than VINF_CALLBACK_RETURN and
433 * VERR_CALLBACK_RETURN the search will continue till the end of the
434 * list. These status codes will not necessarily be propagated to the
435 * caller in any consistent manner.
436 * @retval VINF_CALLBACK_RETURN if successuflly opened the file and it's time
437 * to return
438 * @retval VERR_CALLBACK_RETURN if we shouldn't stop searching.
439 *
440 * @param hDbgCfg The debugging configuration handle.
441 * @param pszFilename The path to the file that should be tried out.
442 * @param pvUser1 First user parameter.
443 * @param pvUser2 Second user parameter.
444 */
445typedef DECLCALLBACK(int) FNDBGCFGOPEN(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2);
446/** Pointer to a open-file callback used to the RTDbgCfgOpen functions. */
447typedef FNDBGCFGOPEN *PFNDBGCFGOPEN;
448
449
450RTDECL(int) RTDbgCfgOpenPeImage(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t cbImage, uint32_t uTimestamp,
451 PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
452RTDECL(int) RTDbgCfgOpenPdb70(RTDBGCFG hDbgCfg, const char *pszFilename, PCRTUUID pUuid, uint32_t uAge,
453 PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
454RTDECL(int) RTDbgCfgOpenPdb20(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t cbImage, uint32_t uTimestamp, uint32_t uAge,
455 PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
456RTDECL(int) RTDbgCfgOpenDbg(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t cbImage, uint32_t uTimestamp,
457 PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
458RTDECL(int) RTDbgCfgOpenDwo(RTDBGCFG hDbgCfg, const char *pszFilename, uint32_t uCrc32,
459 PFNDBGCFGOPEN pfnCallback, void *pvUser1, void *pvUser2);
460
461
462/** @} */
463
464
465/** @defgroup grp_rt_dbgas RTDbgAs - Debug Address Space
466 * @{
467 */
468
469/**
470 * Creates an empty address space.
471 *
472 * @returns IPRT status code.
473 *
474 * @param phDbgAs Where to store the address space handle on success.
475 * @param FirstAddr The first address in the address space.
476 * @param LastAddr The last address in the address space.
477 * @param pszName The name of the address space.
478 */
479RTDECL(int) RTDbgAsCreate(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszName);
480
481/**
482 * Variant of RTDbgAsCreate that takes a name format string.
483 *
484 * @returns IPRT status code.
485 *
486 * @param phDbgAs Where to store the address space handle on success.
487 * @param FirstAddr The first address in the address space.
488 * @param LastAddr The last address in the address space.
489 * @param pszNameFmt The name format of the address space.
490 * @param va Format arguments.
491 */
492RTDECL(int) RTDbgAsCreateV(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszNameFmt, va_list va);
493
494/**
495 * Variant of RTDbgAsCreate that takes a name format string.
496 *
497 * @returns IPRT status code.
498 *
499 * @param phDbgAs Where to store the address space handle on success.
500 * @param FirstAddr The first address in the address space.
501 * @param LastAddr The last address in the address space.
502 * @param pszNameFmt The name format of the address space.
503 * @param ... Format arguments.
504 */
505RTDECL(int) RTDbgAsCreateF(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszNameFmt, ...);
506
507/**
508 * Retains a reference to the address space.
509 *
510 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
511 *
512 * @param hDbgAs The address space handle.
513 *
514 * @remarks Will not take any locks.
515 */
516RTDECL(uint32_t) RTDbgAsRetain(RTDBGAS hDbgAs);
517
518/**
519 * Release a reference to the address space.
520 *
521 * When the reference count reaches zero, the address space is destroyed.
522 * That means unlinking all the modules it currently contains, potentially
523 * causing some or all of them to be destroyed as they are managed by
524 * reference counting.
525 *
526 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
527 *
528 * @param hDbgAs The address space handle. The NIL handle is quietly
529 * ignored and 0 is returned.
530 *
531 * @remarks Will not take any locks.
532 */
533RTDECL(uint32_t) RTDbgAsRelease(RTDBGAS hDbgAs);
534
535/**
536 * Gets the name of an address space.
537 *
538 * @returns read only address space name.
539 * NULL if hDbgAs is invalid.
540 *
541 * @param hDbgAs The address space handle.
542 *
543 * @remarks Will not take any locks.
544 */
545RTDECL(const char *) RTDbgAsName(RTDBGAS hDbgAs);
546
547/**
548 * Gets the first address in an address space.
549 *
550 * @returns The address.
551 * 0 if hDbgAs is invalid.
552 *
553 * @param hDbgAs The address space handle.
554 *
555 * @remarks Will not take any locks.
556 */
557RTDECL(RTUINTPTR) RTDbgAsFirstAddr(RTDBGAS hDbgAs);
558
559/**
560 * Gets the last address in an address space.
561 *
562 * @returns The address.
563 * 0 if hDbgAs is invalid.
564 *
565 * @param hDbgAs The address space handle.
566 *
567 * @remarks Will not take any locks.
568 */
569RTDECL(RTUINTPTR) RTDbgAsLastAddr(RTDBGAS hDbgAs);
570
571/**
572 * Gets the number of modules in the address space.
573 *
574 * This can be used together with RTDbgAsModuleByIndex
575 * to enumerate the modules.
576 *
577 * @returns The number of modules.
578 *
579 * @param hDbgAs The address space handle.
580 *
581 * @remarks Will not take any locks.
582 */
583RTDECL(uint32_t) RTDbgAsModuleCount(RTDBGAS hDbgAs);
584
585/** @name Flags for RTDbgAsModuleLink and RTDbgAsModuleLinkSeg
586 * @{ */
587/** Replace all conflicting module.
588 * (The conflicting modules will be removed the address space and their
589 * references released.) */
590#define RTDBGASLINK_FLAGS_REPLACE RT_BIT_32(0)
591/** Mask containing the valid flags. */
592#define RTDBGASLINK_FLAGS_VALID_MASK UINT32_C(0x00000001)
593/** @} */
594
595/**
596 * Links a module into the address space at the give address.
597 *
598 * The size of the mapping is determined using RTDbgModImageSize().
599 *
600 * @returns IPRT status code.
601 * @retval VERR_OUT_OF_RANGE if the specified address will put the module
602 * outside the address space.
603 * @retval VERR_ADDRESS_CONFLICT if the mapping clashes with existing mappings.
604 *
605 * @param hDbgAs The address space handle.
606 * @param hDbgMod The module handle of the module to be linked in.
607 * @param ImageAddr The address to link the module at.
608 * @param fFlags See RTDBGASLINK_FLAGS_*.
609 */
610RTDECL(int) RTDbgAsModuleLink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTUINTPTR ImageAddr, uint32_t fFlags);
611
612/**
613 * Links a segment into the address space at the give address.
614 *
615 * The size of the mapping is determined using RTDbgModSegmentSize().
616 *
617 * @returns IPRT status code.
618 * @retval VERR_OUT_OF_RANGE if the specified address will put the module
619 * outside the address space.
620 * @retval VERR_ADDRESS_CONFLICT if the mapping clashes with existing mappings.
621 *
622 * @param hDbgAs The address space handle.
623 * @param hDbgMod The module handle.
624 * @param iSeg The segment number (0-based) of the segment to be
625 * linked in.
626 * @param SegAddr The address to link the segment at.
627 * @param fFlags See RTDBGASLINK_FLAGS_*.
628 */
629RTDECL(int) RTDbgAsModuleLinkSeg(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR SegAddr, uint32_t fFlags);
630
631/**
632 * Unlinks all the mappings of a module from the address space.
633 *
634 * @returns IPRT status code.
635 * @retval VERR_NOT_FOUND if the module wasn't found.
636 *
637 * @param hDbgAs The address space handle.
638 * @param hDbgMod The module handle of the module to be unlinked.
639 */
640RTDECL(int) RTDbgAsModuleUnlink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod);
641
642/**
643 * Unlinks the mapping at the specified address.
644 *
645 * @returns IPRT status code.
646 * @retval VERR_NOT_FOUND if no module or segment is mapped at that address.
647 *
648 * @param hDbgAs The address space handle.
649 * @param Addr The address within the mapping to be unlinked.
650 */
651RTDECL(int) RTDbgAsModuleUnlinkByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr);
652
653/**
654 * Get a the handle of a module in the address space by is index.
655 *
656 * @returns A retained handle to the specified module. The caller must release
657 * the returned reference.
658 * NIL_RTDBGMOD if invalid index or handle.
659 *
660 * @param hDbgAs The address space handle.
661 * @param iModule The index of the module to get.
662 *
663 * @remarks The module indexes may change after calls to RTDbgAsModuleLink,
664 * RTDbgAsModuleLinkSeg, RTDbgAsModuleUnlink and
665 * RTDbgAsModuleUnlinkByAddr.
666 */
667RTDECL(RTDBGMOD) RTDbgAsModuleByIndex(RTDBGAS hDbgAs, uint32_t iModule);
668
669/**
670 * Queries mapping module information by handle.
671 *
672 * @returns IPRT status code.
673 * @retval VERR_NOT_FOUND if no mapping was found at the specified address.
674 *
675 * @param hDbgAs The address space handle.
676 * @param Addr Address within the mapping of the module or segment.
677 * @param phMod Where to the return the retained module handle.
678 * Optional.
679 * @param pAddr Where to return the base address of the mapping.
680 * Optional.
681 * @param piSeg Where to return the segment index. This is set to
682 * NIL if the entire module is mapped as a single
683 * mapping. Optional.
684 */
685RTDECL(int) RTDbgAsModuleByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTDBGMOD phMod, PRTUINTPTR pAddr, PRTDBGSEGIDX piSeg);
686
687/**
688 * Queries mapping module information by name.
689 *
690 * @returns IPRT status code.
691 * @retval VERR_NOT_FOUND if no mapping was found at the specified address.
692 * @retval VERR_OUT_OF_RANGE if the name index was out of range.
693 *
694 * @param hDbgAs The address space handle.
695 * @param pszName The module name.
696 * @param iName There can be more than one module by the same name
697 * in an address space. This argument indicates which
698 * is meant. (0 based)
699 * @param phMod Where to the return the retained module handle.
700 */
701RTDECL(int) RTDbgAsModuleByName(RTDBGAS hDbgAs, const char *pszName, uint32_t iName, PRTDBGMOD phMod);
702
703/**
704 * Information about a mapping.
705 *
706 * This is used by RTDbgAsModuleGetMapByIndex.
707 */
708typedef struct RTDBGASMAPINFO
709{
710 /** The mapping address. */
711 RTUINTPTR Address;
712 /** The segment mapped there.
713 * This is NIL_RTDBGSEGIDX if the entire module image is mapped here. */
714 RTDBGSEGIDX iSeg;
715} RTDBGASMAPINFO;
716/** Pointer to info about an address space mapping. */
717typedef RTDBGASMAPINFO *PRTDBGASMAPINFO;
718/** Pointer to const info about an address space mapping. */
719typedef RTDBGASMAPINFO const *PCRTDBGASMAPINFO;
720
721/**
722 * Queries mapping information for a module given by index.
723 *
724 * @returns IRPT status code.
725 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
726 * @retval VERR_OUT_OF_RANGE if the name index was out of range.
727 * @retval VINF_BUFFER_OVERFLOW if the array is too small and the returned
728 * information is incomplete.
729 *
730 * @param hDbgAs The address space handle.
731 * @param iModule The index of the module to get.
732 * @param paMappings Where to return the mapping information. The buffer
733 * size is given by *pcMappings.
734 * @param pcMappings IN: Size of the paMappings array. OUT: The number of
735 * entries returned.
736 * @param fFlags Flags for reserved for future use. MBZ.
737 *
738 * @remarks See remarks for RTDbgAsModuleByIndex regarding the volatility of the
739 * iModule parameter.
740 */
741RTDECL(int) RTDbgAsModuleQueryMapByIndex(RTDBGAS hDbgAs, uint32_t iModule, PRTDBGASMAPINFO paMappings, uint32_t *pcMappings, uint32_t fFlags);
742
743/**
744 * Adds a symbol to a module in the address space.
745 *
746 * @returns IPRT status code. See RTDbgModSymbolAdd for more specific ones.
747 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
748 * @retval VERR_NOT_FOUND if no module was found at the specified address.
749 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
750 * custom symbols.
751 *
752 * @param hDbgAs The address space handle.
753 * @param pszSymbol The symbol name.
754 * @param Addr The address of the symbol.
755 * @param cb The size of the symbol.
756 * @param fFlags Symbol flags.
757 * @param piOrdinal Where to return the symbol ordinal on success. If
758 * the interpreter doesn't do ordinals, this will be set to
759 * UINT32_MAX. Optional
760 */
761RTDECL(int) RTDbgAsSymbolAdd(RTDBGAS hDbgAs, const char *pszSymbol, RTUINTPTR Addr, RTUINTPTR cb, uint32_t fFlags, uint32_t *piOrdinal);
762
763/**
764 * Query a symbol by address.
765 *
766 * @returns IPRT status code. See RTDbgModSymbolAddr for more specific ones.
767 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
768 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
769 * @retval VERR_INVALID_PARAMETER if incorrect flags.
770 *
771 * @param hDbgAs The address space handle.
772 * @param Addr The address which closest symbol is requested.
773 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
774 * @param poffDisp Where to return the distance between the symbol
775 * and address. Optional.
776 * @param pSymbol Where to return the symbol info.
777 * @param phMod Where to return the module handle. Optional.
778 */
779RTDECL(int) RTDbgAsSymbolByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, uint32_t fFlags,
780 PRTINTPTR poffDisp, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
781
782/**
783 * Query a symbol by address.
784 *
785 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
786 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
787 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
788 * @retval VERR_INVALID_PARAMETER if incorrect flags.
789 *
790 * @param hDbgAs The address space handle.
791 * @param Addr The address which closest symbol is requested.
792 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
793 * @param poffDisp Where to return the distance between the symbol
794 * and address. Optional.
795 * @param ppSymInfo Where to return the pointer to the allocated symbol
796 * info. Always set. Free with RTDbgSymbolFree.
797 * @param phMod Where to return the module handle. Optional.
798 */
799RTDECL(int) RTDbgAsSymbolByAddrA(RTDBGAS hDbgAs, RTUINTPTR Addr, uint32_t fFlags,
800 PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymInfo, PRTDBGMOD phMod);
801
802/**
803 * Query a symbol by name.
804 *
805 * @returns IPRT status code.
806 * @retval VERR_SYMBOL_NOT_FOUND if not found.
807 *
808 * @param hDbgAs The address space handle.
809 * @param pszSymbol The symbol name. It is possible to limit the scope
810 * of the search by prefixing the symbol with a module
811 * name pattern followed by a bang (!) character.
812 * RTStrSimplePatternNMatch is used for the matching.
813 * @param pSymbol Where to return the symbol info.
814 * @param phMod Where to return the module handle. Optional.
815 */
816RTDECL(int) RTDbgAsSymbolByName(RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
817
818/**
819 * Query a symbol by name, allocating the returned symbol structure.
820 *
821 * @returns IPRT status code.
822 * @retval VERR_SYMBOL_NOT_FOUND if not found.
823 *
824 * @param hDbgAs The address space handle.
825 * @param pszSymbol The symbol name. See RTDbgAsSymbolByName for more.
826 * @param ppSymbol Where to return the pointer to the allocated
827 * symbol info. Always set. Free with RTDbgSymbolFree.
828 * @param phMod Where to return the module handle. Optional.
829 */
830RTDECL(int) RTDbgAsSymbolByNameA(RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL *ppSymbol, PRTDBGMOD phMod);
831
832/**
833 * Query a line number by address.
834 *
835 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
836 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
837 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
838 *
839 * @param hDbgAs The address space handle.
840 * @param Addr The address which closest symbol is requested.
841 * @param poffDisp Where to return the distance between the line
842 * number and address.
843 * @param pLine Where to return the line number information.
844 */
845RTDECL(int) RTDbgAs(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE pLine);
846
847/**
848 * Adds a line number to a module in the address space.
849 *
850 * @returns IPRT status code. See RTDbgModSymbolAdd for more specific ones.
851 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
852 * @retval VERR_NOT_FOUND if no module was found at the specified address.
853 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
854 * custom symbols.
855 *
856 * @param hDbgAs The address space handle.
857 * @param pszFile The file name.
858 * @param uLineNo The line number.
859 * @param Addr The address of the symbol.
860 * @param piOrdinal Where to return the line number ordinal on success.
861 * If the interpreter doesn't do ordinals, this will be
862 * set to UINT32_MAX. Optional.
863 */
864RTDECL(int) RTDbgAsLineAdd(RTDBGAS hDbgAs, const char *pszFile, uint32_t uLineNo, RTUINTPTR Addr, uint32_t *piOrdinal);
865
866
867/**
868 * Query a line number by address.
869 *
870 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
871 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
872 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
873 *
874 * @param hDbgAs The address space handle.
875 * @param Addr The address which closest symbol is requested.
876 * @param poffDisp Where to return the distance between the line
877 * number and address.
878 * @param pLine Where to return the line number information.
879 */
880RTDECL(int) RTDbgAsLineByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE pLine);
881
882/**
883 * Query a line number by address.
884 *
885 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
886 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
887 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
888 *
889 * @param hDbgAs The address space handle.
890 * @param Addr The address which closest symbol is requested.
891 * @param poffDisp Where to return the distance between the line
892 * number and address.
893 * @param ppLine Where to return the pointer to the allocated line
894 * number info. Always set. Free with RTDbgLineFree.
895 */
896RTDECL(int) RTDbgAsLineByAddrA(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE *ppLine);
897
898/** @todo Missing some bits here. */
899
900/** @} */
901
902
903/** @defgroup grp_rt_dbgmod RTDbgMod - Debug Module Interpreter
904 * @{
905 */
906
907/**
908 * Creates a module based on the default debug info container.
909 *
910 * This can be used to manually load a module and its symbol. The primary user
911 * group is the debug info interpreters, which use this API to create an
912 * efficient debug info container behind the scenes and forward all queries to
913 * it once the info has been loaded.
914 *
915 * @returns IPRT status code.
916 *
917 * @param phDbgMod Where to return the module handle.
918 * @param pszName The name of the module (mandatory).
919 * @param cbSeg The size of initial segment. If zero, segments will
920 * have to be added manually using RTDbgModSegmentAdd.
921 * @param fFlags Flags reserved for future extensions, MBZ for now.
922 */
923RTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cbSeg, uint32_t fFlags);
924
925RTDECL(int) RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName,
926 RTDBGCFG hDbgCfg);
927RTDECL(int) RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR uSubtrahend,
928 RTDBGCFG hDbgCfg);
929RTDECL(int) RTDbgModCreateFromPeImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTLDRMOD hLdrMod,
930 uint32_t cbImage, uint32_t uTimeDateStamp, RTDBGCFG hDbgCfg);
931RTDECL(int) RTDbgModCreateFromDbg(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage,
932 uint32_t uTimeDateStamp, RTDBGCFG hDbgCfg);
933RTDECL(int) RTDbgModCreateFromPdb(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage,
934 PCRTUUID pUuid, uint32_t Age, RTDBGCFG hDbgCfg);
935RTDECL(int) RTDbgModCreateFromDwo(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t cbImage,
936 uint32_t uCrc32, RTDBGCFG hDbgCfg);
937
938
939/**
940 * Retains another reference to the module.
941 *
942 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
943 *
944 * @param hDbgMod The module handle.
945 *
946 * @remarks Will not take any locks.
947 */
948RTDECL(uint32_t) RTDbgModRetain(RTDBGMOD hDbgMod);
949
950/**
951 * Release a reference to the module.
952 *
953 * When the reference count reaches zero, the module is destroyed.
954 *
955 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
956 *
957 * @param hDbgMod The module handle. The NIL handle is quietly ignored
958 * and 0 is returned.
959 *
960 * @remarks Will not take any locks.
961 */
962RTDECL(uint32_t) RTDbgModRelease(RTDBGMOD hDbgMod);
963
964/**
965 * Gets the module name.
966 *
967 * @returns Pointer to a read only string containing the name.
968 *
969 * @param hDbgMod The module handle.
970 */
971RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod);
972
973/**
974 * Gets the name of the debug info file we're using.
975 *
976 * @returns Pointer to a read only string containing the filename, NULL if we
977 * don't use one.
978 *
979 * @param hDbgMod The module handle.
980 */
981RTDECL(const char *) RTDbgModDebugFile(RTDBGMOD hDbgMod);
982
983/**
984 * Gets the image filename (as specified by the user).
985 *
986 * @returns Pointer to a read only string containing the filename.
987 *
988 * @param hDbgMod The module handle.
989 */
990RTDECL(const char *) RTDbgModImageFile(RTDBGMOD hDbgMod);
991
992/**
993 * Gets the image filename actually used if it differs from RTDbgModImageFile.
994 *
995 * @returns Pointer to a read only string containing the filename, NULL if same
996 * as RTDBgModImageFile.
997 *
998 * @param hDbgMod The module handle.
999 */
1000RTDECL(const char *) RTDbgModImageFileUsed(RTDBGMOD hDbgMod);
1001
1002/**
1003 * Converts an image relative address to a segment:offset address.
1004 *
1005 * @returns Segment index on success.
1006 * NIL_RTDBGSEGIDX is returned if the module handle or the RVA are
1007 * invalid.
1008 *
1009 * @param hDbgMod The module handle.
1010 * @param uRva The image relative address to convert.
1011 * @param poffSeg Where to return the segment offset. Optional.
1012 */
1013RTDECL(RTDBGSEGIDX) RTDbgModRvaToSegOff(RTDBGMOD hDbgMod, RTUINTPTR uRva, PRTUINTPTR poffSeg);
1014
1015/**
1016 * Image size when mapped if segments are mapped adjacently.
1017 *
1018 * For ELF, PE, and Mach-O images this is (usually) a natural query, for LX and
1019 * NE and such it's a bit odder and the answer may not make much sense for them.
1020 *
1021 * @returns Image mapped size.
1022 * RTUINTPTR_MAX is returned if the handle is invalid.
1023 *
1024 * @param hDbgMod The module handle.
1025 */
1026RTDECL(RTUINTPTR) RTDbgModImageSize(RTDBGMOD hDbgMod);
1027
1028/**
1029 * Gets the module tag value if any.
1030 *
1031 * @returns The tag. 0 if hDbgMod is invalid.
1032 *
1033 * @param hDbgMod The module handle.
1034 */
1035RTDECL(uint64_t) RTDbgModGetTag(RTDBGMOD hDbgMod);
1036
1037/**
1038 * Tags or untags the module.
1039 *
1040 * @returns IPRT status code.
1041 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1042 *
1043 * @param hDbgMod The module handle.
1044 * @param uTag The tag value. The convention is that 0 is no tag
1045 * and any other value means it's tagged. It's adviced
1046 * to use some kind of unique number like an address
1047 * (global or string cache for instance) to avoid
1048 * collisions with other users
1049 */
1050RTDECL(int) RTDbgModSetTag(RTDBGMOD hDbgMod, uint64_t uTag);
1051
1052
1053/**
1054 * Adds a segment to the module. Optional feature.
1055 *
1056 * This method is intended used for manually constructing debug info for a
1057 * module. The main usage is from other debug info interpreters that want to
1058 * avoid writing a debug info database and instead uses the standard container
1059 * behind the scenes.
1060 *
1061 * @returns IPRT status code.
1062 * @retval VERR_NOT_SUPPORTED if this feature isn't support by the debug info
1063 * interpreter. This is a common return code.
1064 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1065 * @retval VERR_DBG_ADDRESS_WRAP if uRva+cb wraps around.
1066 * @retval VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE if pszName is too short or long.
1067 * @retval VERR_INVALID_PARAMETER if fFlags contains undefined flags.
1068 * @retval VERR_DBG_SPECIAL_SEGMENT if *piSeg is a special segment.
1069 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if *piSeg doesn't meet expectations.
1070 *
1071 * @param hDbgMod The module handle.
1072 * @param uRva The image relative address of the segment.
1073 * @param cb The size of the segment.
1074 * @param pszName The segment name. Does not normally need to be
1075 * unique, although this is somewhat up to the
1076 * debug interpreter to decide.
1077 * @param fFlags Segment flags. Reserved for future used, MBZ.
1078 * @param piSeg The segment index or NIL_RTDBGSEGIDX on input.
1079 * The assigned segment index on successful return.
1080 * Optional.
1081 */
1082RTDECL(int) RTDbgModSegmentAdd(RTDBGMOD hDbgMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName,
1083 uint32_t fFlags, PRTDBGSEGIDX piSeg);
1084
1085/**
1086 * Gets the number of segments in the module.
1087 *
1088 * This is can be used to determine the range which can be passed to
1089 * RTDbgModSegmentByIndex and derivates.
1090 *
1091 * @returns The segment relative address.
1092 * NIL_RTDBGSEGIDX if the handle is invalid.
1093 *
1094 * @param hDbgMod The module handle.
1095 */
1096RTDECL(RTDBGSEGIDX) RTDbgModSegmentCount(RTDBGMOD hDbgMod);
1097
1098/**
1099 * Query information about a segment.
1100 *
1101 * This can be used together with RTDbgModSegmentCount to enumerate segments.
1102 * The index starts a 0 and stops one below RTDbgModSegmentCount.
1103 *
1104 * @returns IPRT status code.
1105 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if iSeg is too high.
1106 * @retval VERR_DBG_SPECIAL_SEGMENT if iSeg indicates a special segment.
1107 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1108 *
1109 * @param hDbgMod The module handle.
1110 * @param iSeg The segment index. No special segments.
1111 * @param pSegInfo Where to return the segment info. The
1112 * RTDBGSEGMENT::Address member will be set to
1113 * RTUINTPTR_MAX or the load address used at link time.
1114 */
1115RTDECL(int) RTDbgModSegmentByIndex(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo);
1116
1117/**
1118 * Gets the size of a segment.
1119 *
1120 * This is a just a wrapper around RTDbgModSegmentByIndex.
1121 *
1122 * @returns The segment size.
1123 * RTUINTPTR_MAX is returned if either the handle and segment index are
1124 * invalid.
1125 *
1126 * @param hDbgMod The module handle.
1127 * @param iSeg The segment index. RTDBGSEGIDX_ABS is not allowed.
1128 * If RTDBGSEGIDX_RVA is used, the functions returns
1129 * the same value as RTDbgModImageSize.
1130 */
1131RTDECL(RTUINTPTR) RTDbgModSegmentSize(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
1132
1133/**
1134 * Gets the image relative address of a segment.
1135 *
1136 * This is a just a wrapper around RTDbgModSegmentByIndex.
1137 *
1138 * @returns The segment relative address.
1139 * RTUINTPTR_MAX is returned if either the handle and segment index are
1140 * invalid.
1141 *
1142 * @param hDbgMod The module handle.
1143 * @param iSeg The segment index. No special segment indexes
1144 * allowed (asserted).
1145 */
1146RTDECL(RTUINTPTR) RTDbgModSegmentRva(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
1147
1148
1149/**
1150 * Adds a line number to the module.
1151 *
1152 * @returns IPRT status code.
1153 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
1154 * custom symbols. This is a common place occurrence.
1155 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1156 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1157 * short.
1158 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1159 * it's not inside any of the segments defined by the module.
1160 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1161 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1162 * end of the segment.
1163 * @retval VERR_DBG_ADDRESS_WRAP if off+cb wraps around.
1164 * @retval VERR_INVALID_PARAMETER if the symbol flags sets undefined bits.
1165 *
1166 * @param hDbgMod The module handle.
1167 * @param pszSymbol The symbol name.
1168 * @param iSeg The segment index.
1169 * @param off The segment offset.
1170 * @param cb The size of the symbol. Can be zero, although this
1171 * may depend somewhat on the debug interpreter.
1172 * @param fFlags Symbol flags. Reserved for the future, MBZ.
1173 * @param piOrdinal Where to return the symbol ordinal on success. If
1174 * the interpreter doesn't do ordinals, this will be set to
1175 * UINT32_MAX. Optional.
1176 */
1177RTDECL(int) RTDbgModSymbolAdd(RTDBGMOD hDbgMod, const char *pszSymbol, RTDBGSEGIDX iSeg, RTUINTPTR off,
1178 RTUINTPTR cb, uint32_t fFlags, uint32_t *piOrdinal);
1179
1180/**
1181 * Gets the symbol count.
1182 *
1183 * This can be used together wtih RTDbgModSymbolByOrdinal or
1184 * RTDbgModSymbolByOrdinalA to enumerate all the symbols.
1185 *
1186 * @returns The number of symbols in the module.
1187 * UINT32_MAX is returned if the module handle is invalid or some other
1188 * error occurs.
1189 *
1190 * @param hDbgMod The module handle.
1191 */
1192RTDECL(uint32_t) RTDbgModSymbolCount(RTDBGMOD hDbgMod);
1193
1194/**
1195 * Queries symbol information by ordinal number.
1196 *
1197 * @returns IPRT status code.
1198 * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at the given number.
1199 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1200 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1201 * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
1202 *
1203 * @param hDbgMod The module handle.
1204 * @param iOrdinal The symbol ordinal number. 0-based. The highest
1205 * number is RTDbgModSymbolCount() - 1.
1206 * @param pSymInfo Where to store the symbol information.
1207 */
1208RTDECL(int) RTDbgModSymbolByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo);
1209
1210/**
1211 * Queries symbol information by ordinal number.
1212 *
1213 * @returns IPRT status code.
1214 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1215 * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
1216 * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at the given number.
1217 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1218 *
1219 * @param hDbgMod The module handle.
1220 * @param iOrdinal The symbol ordinal number. 0-based. The highest
1221 * number is RTDbgModSymbolCount() - 1.
1222 * @param ppSymInfo Where to store the pointer to the returned
1223 * symbol information. Always set. Free with
1224 * RTDbgSymbolFree.
1225 */
1226RTDECL(int) RTDbgModSymbolByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL *ppSymInfo);
1227
1228/**
1229 * Queries symbol information by address.
1230 *
1231 * The returned symbol is what the debug info interpreter considers the symbol
1232 * most applicable to the specified address. This usually means a symbol with an
1233 * address equal or lower than the requested.
1234 *
1235 * @returns IPRT status code.
1236 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1237 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1238 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1239 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1240 * it's not inside any of the segments defined by the module.
1241 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1242 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1243 * end of the segment.
1244 * @retval VERR_INVALID_PARAMETER if incorrect flags.
1245 *
1246 * @param hDbgMod The module handle.
1247 * @param iSeg The segment number.
1248 * @param off The offset into the segment.
1249 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
1250 * @param poffDisp Where to store the distance between the
1251 * specified address and the returned symbol.
1252 * Optional.
1253 * @param pSymInfo Where to store the symbol information.
1254 */
1255RTDECL(int) RTDbgModSymbolByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
1256 PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo);
1257
1258/**
1259 * Queries symbol information by address.
1260 *
1261 * The returned symbol is what the debug info interpreter considers the symbol
1262 * most applicable to the specified address. This usually means a symbol with an
1263 * address equal or lower than the requested.
1264 *
1265 * @returns IPRT status code.
1266 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1267 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1268 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1269 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1270 * it's not inside any of the segments defined by the module.
1271 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1272 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1273 * end of the segment.
1274 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1275 * @retval VERR_INVALID_PARAMETER if incorrect flags.
1276 *
1277 * @param hDbgMod The module handle.
1278 * @param iSeg The segment index.
1279 * @param off The offset into the segment.
1280 * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
1281 * @param poffDisp Where to store the distance between the
1282 * specified address and the returned symbol. Optional.
1283 * @param ppSymInfo Where to store the pointer to the returned
1284 * symbol information. Always set. Free with
1285 * RTDbgSymbolFree.
1286 */
1287RTDECL(int) RTDbgModSymbolByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
1288 PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymInfo);
1289
1290/**
1291 * Queries symbol information by symbol name.
1292 *
1293 * @returns IPRT status code.
1294 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1295 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1296 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1297 * short.
1298 *
1299 * @param hDbgMod The module handle.
1300 * @param pszSymbol The symbol name.
1301 * @param pSymInfo Where to store the symbol information.
1302 */
1303RTDECL(int) RTDbgModSymbolByName(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL pSymInfo);
1304
1305/**
1306 * Queries symbol information by symbol name.
1307 *
1308 * @returns IPRT status code.
1309 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
1310 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
1311 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
1312 * short.
1313 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
1314 *
1315 * @param hDbgMod The module handle.
1316 * @param pszSymbol The symbol name.
1317 * @param ppSymInfo Where to store the pointer to the returned
1318 * symbol information. Always set. Free with
1319 * RTDbgSymbolFree.
1320 */
1321RTDECL(int) RTDbgModSymbolByNameA(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL *ppSymInfo);
1322
1323/**
1324 * Adds a line number to the module.
1325 *
1326 * @returns IPRT status code.
1327 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
1328 * custom symbols. This should be consider a normal response.
1329 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1330 * @retval VERR_DBG_FILE_NAME_OUT_OF_RANGE if the file name is too longer or
1331 * empty.
1332 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1333 * it's not inside any of the segments defined by the module.
1334 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1335 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1336 * end of the segment.
1337 * @retval VERR_INVALID_PARAMETER if the line number flags sets undefined bits.
1338 *
1339 * @param hDbgMod The module handle.
1340 * @param pszFile The file name.
1341 * @param uLineNo The line number.
1342 * @param iSeg The segment index.
1343 * @param off The segment offset.
1344 * @param piOrdinal Where to return the line number ordinal on
1345 * success. If the interpreter doesn't do ordinals,
1346 * this will be set to UINT32_MAX. Optional.
1347 */
1348RTDECL(int) RTDbgModLineAdd(RTDBGMOD hDbgMod, const char *pszFile, uint32_t uLineNo,
1349 RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t *piOrdinal);
1350
1351/**
1352 * Gets the line number count.
1353 *
1354 * This can be used together wtih RTDbgModLineByOrdinal or RTDbgModSymbolByLineA
1355 * to enumerate all the line number information.
1356 *
1357 * @returns The number of line numbers in the module.
1358 * UINT32_MAX is returned if the module handle is invalid or some other
1359 * error occurs.
1360 *
1361 * @param hDbgMod The module handle.
1362 */
1363RTDECL(uint32_t) RTDbgModLineCount(RTDBGMOD hDbgMod);
1364
1365/**
1366 * Queries line number information by ordinal number.
1367 *
1368 * This can be used to enumerate the line numbers for the module. Use
1369 * RTDbgModLineCount() to figure the end of the ordinals.
1370 *
1371 * @returns IPRT status code.
1372 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1373 * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
1374 * ordinal.
1375 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1376
1377 * @param hDbgMod The module handle.
1378 * @param iOrdinal The line number ordinal number.
1379 * @param pLineInfo Where to store the information about the line
1380 * number.
1381 */
1382RTDECL(int) RTDbgModLineByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo);
1383
1384/**
1385 * Queries line number information by ordinal number.
1386 *
1387 * This can be used to enumerate the line numbers for the module. Use
1388 * RTDbgModLineCount() to figure the end of the ordinals.
1389 *
1390 * @returns IPRT status code.
1391 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1392 * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
1393 * ordinal.
1394 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1395 * @retval VERR_NO_MEMORY if RTDbgLineAlloc fails.
1396 *
1397 * @param hDbgMod The module handle.
1398 * @param iOrdinal The line number ordinal number.
1399 * @param ppLineInfo Where to store the pointer to the returned line
1400 * number information. Always set. Free with
1401 * RTDbgLineFree.
1402 */
1403RTDECL(int) RTDbgModLineByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE *ppLineInfo);
1404
1405/**
1406 * Queries line number information by address.
1407 *
1408 * The returned line number is what the debug info interpreter considers the
1409 * one most applicable to the specified address. This usually means a line
1410 * number with an address equal or lower than the requested.
1411 *
1412 * @returns IPRT status code.
1413 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1414 * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
1415 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1416 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1417 * it's not inside any of the segments defined by the module.
1418 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1419 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1420 * end of the segment.
1421 *
1422 * @param hDbgMod The module handle.
1423 * @param iSeg The segment number.
1424 * @param off The offset into the segment.
1425 * @param poffDisp Where to store the distance between the
1426 * specified address and the returned symbol.
1427 * Optional.
1428 * @param pLineInfo Where to store the line number information.
1429 */
1430RTDECL(int) RTDbgModLineByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLineInfo);
1431
1432/**
1433 * Queries line number information by address.
1434 *
1435 * The returned line number is what the debug info interpreter considers the
1436 * one most applicable to the specified address. This usually means a line
1437 * number with an address equal or lower than the requested.
1438 *
1439 * @returns IPRT status code.
1440 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1441 * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
1442 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1443 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1444 * it's not inside any of the segments defined by the module.
1445 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1446 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1447 * end of the segment.
1448 * @retval VERR_NO_MEMORY if RTDbgLineAlloc fails.
1449 *
1450 * @param hDbgMod The module handle.
1451 * @param iSeg The segment number.
1452 * @param off The offset into the segment.
1453 * @param poffDisp Where to store the distance between the
1454 * specified address and the returned symbol.
1455 * Optional.
1456 * @param ppLineInfo Where to store the pointer to the returned line
1457 * number information. Always set. Free with
1458 * RTDbgLineFree.
1459 */
1460RTDECL(int) RTDbgModLineByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE *ppLineInfo);
1461/** @} */
1462
1463# endif /* IN_RING3 */
1464
1465
1466/** @name Kernel Debug Info API
1467 *
1468 * This is a specialized API for obtaining symbols and structure information
1469 * about the running kernel. It is relatively OS specific. Its purpose and
1470 * operation is doesn't map all that well onto RTDbgMod, so a few dedicated
1471 * functions was created for it.
1472 *
1473 * @{ */
1474
1475/** Handle to the kernel debug info. */
1476typedef struct RTDBGKRNLINFOINT *RTDBGKRNLINFO;
1477/** Pointer to a kernel debug info handle. */
1478typedef RTDBGKRNLINFO *PRTDBGKRNLINFO;
1479/** Nil kernel debug info handle. */
1480#define NIL_RTDBGKRNLINFO ((RTDBGKRNLINFO)0)
1481
1482/**
1483 * Opens the kernel debug info.
1484 *
1485 * @returns IPRT status code. Can fail for any number of reasons.
1486 *
1487 * @param phKrnlInfo Where to return the kernel debug info handle on
1488 * success.
1489 * @param fFlags Flags reserved for future use. Must be zero.
1490 */
1491RTR0DECL(int) RTR0DbgKrnlInfoOpen(PRTDBGKRNLINFO phKrnlInfo, uint32_t fFlags);
1492
1493/**
1494 * Retains a reference to the kernel debug info handle.
1495 *
1496 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1497 * @param hKrnlInfo The kernel info handle.
1498 */
1499RTR0DECL(uint32_t) RTR0DbgKrnlInfoRetain(RTDBGKRNLINFO hKrnlInfo);
1500
1501
1502/**
1503 * Releases a reference to the kernel debug info handle, destroying it when the
1504 * counter reaches zero.
1505 *
1506 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
1507 * @param hKrnlInfo The kernel info handle. NIL_RTDBGKRNLINFO is
1508 * quietly ignored.
1509 */
1510RTR0DECL(uint32_t) RTR0DbgKrnlInfoRelease(RTDBGKRNLINFO hKrnlInfo);
1511
1512/**
1513 * Queries the offset (in bytes) of a member of a kernel structure.
1514 *
1515 * @returns IPRT status code.
1516 * @retval VINF_SUCCESS and offset at @a poffMember.
1517 * @retval VERR_NOT_FOUND if the structure or the member was not found.
1518 * @retval VERR_INVALID_HANDLE if hKrnlInfo is bad.
1519 * @retval VERR_INVALID_POINTER if any of the pointers are bad.
1520 *
1521 * @param hKrnlInfo The kernel info handle.
1522 * @param pszStructure The structure name.
1523 * @param pszMember The member name.
1524 * @param poffMember Where to return the offset.
1525 */
1526RTR0DECL(int) RTR0DbgKrnlInfoQueryMember(RTDBGKRNLINFO hKrnlInfo, const char *pszStructure,
1527 const char *pszMember, size_t *poffMember);
1528
1529
1530/**
1531 * Queries the value (usually the address) of a kernel symbol.
1532 *
1533 * This may go looking for the symbol in other modules, in which case it will
1534 * always check the kernel symbol table first.
1535 *
1536 * @returns IPRT status code.
1537 * @retval VINF_SUCCESS and value at @a ppvSymbol.
1538 * @retval VERR_SYMBOL_NOT_FOUND
1539 * @retval VERR_INVALID_HANDLE if hKrnlInfo is bad.
1540 * @retval VERR_INVALID_POINTER if any of the pointers are bad.
1541 *
1542 * @param hKrnlInfo The kernel info handle.
1543 * @param pszModule Reserved for future extensions. Pass NULL.
1544 * @param pszSymbol The C name of the symbol.
1545 * @param ppvSymbol Where to return the symbol value, passing NULL is
1546 * OK. This may be modified even on failure, in
1547 * particular, it will be set to NULL when
1548 * VERR_SYMBOL_NOT_FOUND is returned.
1549 *
1550 * @sa RTLdrGetSymbol.
1551 */
1552RTR0DECL(int) RTR0DbgKrnlInfoQuerySymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
1553 const char *pszSymbol, void **ppvSymbol);
1554/** @} */
1555
1556/** @} */
1557
1558RT_C_DECLS_END
1559
1560#endif
1561
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