VirtualBox

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

Last change on this file since 21258 was 21110, checked in by vboxsync, 16 years ago

RTDbg: Some adjustments and fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.3 KB
Line 
1/* $Id: dbg.h 21110 2009-07-01 01:02:58Z vboxsync $ */
2/** @file
3 * IPRT - Debugging Routines.
4 */
5
6/*
7 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#ifndef ___iprt_dbg_h
32#define ___iprt_dbg_h
33
34#include <iprt/types.h>
35#include <iprt/stdarg.h>
36
37RT_C_DECLS_BEGIN
38
39/** @defgroup grp_rt_dbg RTDbg - Debugging Routines
40 * @ingroup grp_rt
41 * @{
42 */
43
44
45/** Debug segment index. */
46typedef uint32_t RTDBGSEGIDX;
47/** Pointer to a debug segment index. */
48typedef RTDBGSEGIDX *PRTDBGSEGIDX;
49/** Pointer to a const debug segment index. */
50typedef RTDBGSEGIDX const *PCRTDBGSEGIDX;
51/** NIL debug segment index. */
52#define NIL_RTDBGSEGIDX UINT32_C(0xffffffff)
53/** The last normal segment index. */
54#define RTDBGSEGIDX_LAST UINT32_C(0xffffffef)
55/** Special segment index that indicates that the offset is a relative
56 * virtual address (RVA). I.e. an offset from the start of the module. */
57#define RTDBGSEGIDX_RVA UINT32_C(0xfffffff0)
58/** Special segment index that indicates that the offset is a absolute. */
59#define RTDBGSEGIDX_ABS UINT32_C(0xfffffff1)
60/** The last valid special segment index. */
61#define RTDBGSEGIDX_SPECIAL_LAST RTDBGSEGIDX_ABS
62/** The last valid special segment index. */
63#define RTDBGSEGIDX_SPECIAL_FIRST (RTDBGSEGIDX_LAST + 1U)
64
65
66/** Max length (including '\\0') of a segment name. */
67#define RTDBG_SEGMENT_NAME_LENGTH (128 - 8 - 8 - 8 - 4 - 4)
68
69/**
70 * Debug module segment.
71 */
72typedef struct RTDBGSEGMENT
73{
74 /** The load address.
75 * RTUINTPTR_MAX if not applicable. */
76 RTUINTPTR Address;
77 /** The image relative virtual address of the segment.
78 * RTUINTPTR_MAX if not applicable. */
79 RTUINTPTR uRva;
80 /** The segment size. */
81 RTUINTPTR cb;
82 /** The segment flags. (reserved) */
83 uint32_t fFlags;
84 /** The segment index. */
85 RTDBGSEGIDX iSeg;
86 /** Symbol name. */
87 char szName[RTDBG_SEGMENT_NAME_LENGTH];
88} RTDBGSEGMENT;
89/** Pointer to a debug module segment. */
90typedef RTDBGSEGMENT *PRTDBGSEGMENT;
91/** Pointer to a const debug module segment. */
92typedef RTDBGSEGMENT const *PCRTDBGSEGMENT;
93
94
95
96/** Max length (including '\\0') of a symbol name. */
97#define RTDBG_SYMBOL_NAME_LENGTH (384 - 8 - 8 - 8 - 4 - 4 - 8)
98
99/**
100 * Debug symbol.
101 */
102typedef struct RTDBGSYMBOL
103{
104 /** Symbol value (address).
105 * This depends a bit who you ask. It will be the same as offSeg when you
106 * as RTDbgMod, but the mapping address if you ask RTDbgAs. */
107 RTUINTPTR Value;
108 /** Symbol size. */
109 RTUINTPTR cb;
110 /** Offset into the segment specified by iSeg. */
111 RTUINTPTR offSeg;
112 /** Segment number. */
113 RTDBGSEGIDX iSeg;
114 /** Symbol Flags. (reserved). */
115 uint32_t fFlags;
116 /** Symbol ordinal.
117 * This is set to UINT32_MAX if the ordinals aren't supported. */
118 uint32_t iOrdinal;
119 /** Symbol name. */
120 char szName[RTDBG_SYMBOL_NAME_LENGTH];
121} RTDBGSYMBOL;
122/** Pointer to debug symbol. */
123typedef RTDBGSYMBOL *PRTDBGSYMBOL;
124/** Pointer to const debug symbol. */
125typedef const RTDBGSYMBOL *PCRTDBGSYMBOL;
126
127/**
128 * Allocate a new symbol structure.
129 *
130 * @returns Pointer to a new structure on success, NULL on failure.
131 */
132RTDECL(PRTDBGSYMBOL) RTDbgSymbolAlloc(void);
133
134/**
135 * Duplicates a symbol structure.
136 *
137 * @returns Pointer to duplicate on success, NULL on failure.
138 *
139 * @param pSymInfo The symbol info to duplicate.
140 */
141RTDECL(PRTDBGSYMBOL) RTDbgSymbolDup(PCRTDBGSYMBOL pSymInfo);
142
143/**
144 * Free a symbol structure previously allocated by a RTDbg method.
145 *
146 * @param pSymInfo The symbol info to free. NULL is ignored.
147 */
148RTDECL(void) RTDbgSymbolFree(PRTDBGSYMBOL pSymInfo);
149
150
151/** Max length (including '\\0') of a debug info file name. */
152#define RTDBG_FILE_NAME_LENGTH (260)
153
154
155/**
156 * Debug line number information.
157 */
158typedef struct RTDBGLINE
159{
160 /** Address.
161 * This depends a bit who you ask. It will be the same as offSeg when you
162 * as RTDbgMod, but the mapping address if you ask RTDbgAs. */
163 RTUINTPTR Address;
164 /** Offset into the segment specified by iSeg. */
165 RTUINTPTR offSeg;
166 /** Segment number. */
167 RTDBGSEGIDX iSeg;
168 /** Line number. */
169 uint32_t uLineNo;
170 /** Symbol ordinal.
171 * This is set to UINT32_MAX if the ordinals aren't supported. */
172 uint32_t iOrdinal;
173 /** Filename. */
174 char szFilename[RTDBG_FILE_NAME_LENGTH];
175} RTDBGLINE;
176/** Pointer to debug line number. */
177typedef RTDBGLINE *PRTDBGLINE;
178/** Pointer to const debug line number. */
179typedef const RTDBGLINE *PCRTDBGLINE;
180
181/**
182 * Allocate a new line number structure.
183 *
184 * @returns Pointer to a new structure on success, NULL on failure.
185 */
186RTDECL(PRTDBGLINE) RTDbgLineAlloc(void);
187
188/**
189 * Duplicates a line number structure.
190 *
191 * @returns Pointer to duplicate on success, NULL on failure.
192 *
193 * @param pLine The line number to duplicate.
194 */
195RTDECL(PRTDBGLINE) RTDbgLineDup(PCRTDBGLINE pLine);
196
197/**
198 * Free a line number structure previously allocated by a RTDbg method.
199 *
200 * @param pLine The line number to free. NULL is ignored.
201 */
202RTDECL(void) RTDbgLineFree(PRTDBGLINE pLine);
203
204
205/** @defgroup grp_rt_dbgas RTDbgAs - Debug Address Space
206 * @{
207 */
208
209/**
210 * Creates an empty address space.
211 *
212 * @returns IPRT status code.
213 *
214 * @param phDbgAs Where to store the address space handle on success.
215 * @param FirstAddr The first address in the address space.
216 * @param LastAddr The last address in the address space.
217 * @param pszName The name of the address space.
218 */
219RTDECL(int) RTDbgAsCreate(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszName);
220
221/**
222 * Variant of RTDbgAsCreate that takes a name format string.
223 *
224 * @returns IPRT status code.
225 *
226 * @param phDbgAs Where to store the address space handle on success.
227 * @param FirstAddr The first address in the address space.
228 * @param LastAddr The last address in the address space.
229 * @param pszNameFmt The name format of the address space.
230 * @param va Format arguments.
231 */
232RTDECL(int) RTDbgAsCreateV(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszNameFmt, va_list va);
233
234/**
235 * Variant of RTDbgAsCreate that takes a name format string.
236 *
237 * @returns IPRT status code.
238 *
239 * @param phDbgAs Where to store the address space handle on success.
240 * @param FirstAddr The first address in the address space.
241 * @param LastAddr The last address in the address space.
242 * @param pszNameFmt The name format of the address space.
243 * @param ... Format arguments.
244 */
245RTDECL(int) RTDbgAsCreateF(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszNameFmt, ...);
246
247/**
248 * Retains a reference to the address space.
249 *
250 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
251 *
252 * @param hDbgAs The address space handle.
253 *
254 * @remarks Will not take any locks.
255 */
256RTDECL(uint32_t) RTDbgAsRetain(RTDBGAS hDbgAs);
257
258/**
259 * Release a reference to the address space.
260 *
261 * When the reference count reaches zero, the address space is destroyed.
262 * That means unlinking all the modules it currently contains, potentially
263 * causing some or all of them to be destroyed as they are managed by
264 * reference counting.
265 *
266 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
267 *
268 * @param hDbgAs The address space handle. The NIL handle is quietly
269 * ignored and 0 is returned.
270 *
271 * @remarks Will not take any locks.
272 */
273RTDECL(uint32_t) RTDbgAsRelease(RTDBGAS hDbgAs);
274
275/**
276 * Gets the name of an address space.
277 *
278 * @returns read only address space name.
279 * NULL if hDbgAs is invalid.
280 *
281 * @param hDbgAs The address space handle.
282 *
283 * @remarks Will not take any locks.
284 */
285RTDECL(const char *) RTDbgAsName(RTDBGAS hDbgAs);
286
287/**
288 * Gets the first address in an address space.
289 *
290 * @returns The address.
291 * 0 if hDbgAs is invalid.
292 *
293 * @param hDbgAs The address space handle.
294 *
295 * @remarks Will not take any locks.
296 */
297RTDECL(RTUINTPTR) RTDbgAsFirstAddr(RTDBGAS hDbgAs);
298
299/**
300 * Gets the last address in an address space.
301 *
302 * @returns The address.
303 * 0 if hDbgAs is invalid.
304 *
305 * @param hDbgAs The address space handle.
306 *
307 * @remarks Will not take any locks.
308 */
309RTDECL(RTUINTPTR) RTDbgAsLastAddr(RTDBGAS hDbgAs);
310
311/**
312 * Gets the number of modules in the address space.
313 *
314 * This can be used together with RTDbgAsModuleByIndex
315 * to enumerate the modules.
316 *
317 * @returns The number of modules.
318 *
319 * @param hDbgAs The address space handle.
320 *
321 * @remarks Will not take any locks.
322 */
323RTDECL(uint32_t) RTDbgAsModuleCount(RTDBGAS hDbgAs);
324
325/** @name Flags for RTDbgAsModuleLink and RTDbgAsModuleLinkSeg
326 * @{ */
327/** Replace all conflicting module.
328 * (The conflicting modules will be removed the address space and their
329 * references released.) */
330#define RTDBGASLINK_FLAGS_REPLACE RT_BIT_32(0)
331/** Mask containing the valid flags. */
332#define RTDBGASLINK_FLAGS_VALID_MASK UINT32_C(0x00000001)
333/** @} */
334
335/**
336 * Links a module into the address space at the give address.
337 *
338 * The size of the mapping is determined using RTDbgModImageSize().
339 *
340 * @returns IPRT status code.
341 * @retval VERR_OUT_OF_RANGE if the specified address will put the module
342 * outside the address space.
343 * @retval VERR_ADDRESS_CONFLICT if the mapping clashes with existing mappings.
344 *
345 * @param hDbgAs The address space handle.
346 * @param hDbgMod The module handle of the module to be linked in.
347 * @param ImageAddr The address to link the module at.
348 * @param fFlags See RTDBGASLINK_FLAGS_*.
349 */
350RTDECL(int) RTDbgAsModuleLink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTUINTPTR ImageAddr, uint32_t fFlags);
351
352/**
353 * Links a segment into the address space at the give address.
354 *
355 * The size of the mapping is determined using RTDbgModSegmentSize().
356 *
357 * @returns IPRT status code.
358 * @retval VERR_OUT_OF_RANGE if the specified address will put the module
359 * outside the address space.
360 * @retval VERR_ADDRESS_CONFLICT if the mapping clashes with existing mappings.
361 *
362 * @param hDbgAs The address space handle.
363 * @param hDbgMod The module handle.
364 * @param iSeg The segment number (0-based) of the segment to be
365 * linked in.
366 * @param SegAddr The address to link the segment at.
367 * @param fFlags See RTDBGASLINK_FLAGS_*.
368 */
369RTDECL(int) RTDbgAsModuleLinkSeg(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR SegAddr, uint32_t fFlags);
370
371/**
372 * Unlinks all the mappings of a module from the address space.
373 *
374 * @returns IPRT status code.
375 * @retval VERR_NOT_FOUND if the module wasn't found.
376 *
377 * @param hDbgAs The address space handle.
378 * @param hDbgMod The module handle of the module to be unlinked.
379 */
380RTDECL(int) RTDbgAsModuleUnlink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod);
381
382/**
383 * Unlinks the mapping at the specified address.
384 *
385 * @returns IPRT status code.
386 * @retval VERR_NOT_FOUND if no module or segment is mapped at that address.
387 *
388 * @param hDbgAs The address space handle.
389 * @param Addr The address within the mapping to be unlinked.
390 */
391RTDECL(int) RTDbgAsModuleUnlinkByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr);
392
393/**
394 * Get a the handle of a module in the address space by is index.
395 *
396 * @returns A retained handle to the specified module. The caller must release
397 * the returned reference.
398 * NIL_RTDBGMOD if invalid index or handle.
399 *
400 * @param hDbgAs The address space handle.
401 * @param iModule The index of the module to get.
402 *
403 * @remarks The module indexes may change after calls to RTDbgAsModuleLink,
404 * RTDbgAsModuleLinkSeg, RTDbgAsModuleUnlink and
405 * RTDbgAsModuleUnlinkByAddr.
406 */
407RTDECL(RTDBGMOD) RTDbgAsModuleByIndex(RTDBGAS hDbgAs, uint32_t iModule);
408
409/**
410 * Queries mapping module information by handle.
411 *
412 * @returns IPRT status code.
413 * @retval VERR_NOT_FOUND if no mapping was found at the specified address.
414 *
415 * @param hDbgAs The address space handle.
416 * @param Addr Address within the mapping of the module or segment.
417 * @param phMod Where to the return the retained module handle.
418 * Optional.
419 * @param pAddr Where to return the base address of the mapping.
420 * Optional.
421 * @param piSeg Where to return the segment index. This is set to
422 * NIL if the entire module is mapped as a single
423 * mapping. Optional.
424 */
425RTDECL(int) RTDbgAsModuleByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTDBGMOD phMod, PRTUINTPTR pAddr, PRTDBGSEGIDX piSeg);
426
427/**
428 * Queries mapping module information by name.
429 *
430 * @returns IPRT status code.
431 * @retval VERR_NOT_FOUND if no mapping was found at the specified address.
432 * @retval VERR_OUT_OF_RANGE if the name index was out of range.
433 *
434 * @param hDbgAs The address space handle.
435 * @param pszName The module name.
436 * @param iName There can be more than one module by the same name
437 * in an address space. This argument indicates which
438 * is ment. (0 based)
439 * @param phMod Where to the return the retained module handle.
440 */
441RTDECL(int) RTDbgAsModuleByName(RTDBGAS hDbgAs, const char *pszName, uint32_t iName, PRTDBGMOD phMod);
442
443/**
444 * Adds a symbol to a module in the address space.
445 *
446 * @returns IPRT status code. See RTDbgModSymbolAdd for more specific ones.
447 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
448 * @retval VERR_NOT_FOUND if no module was found at the specified address.
449 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
450 * custom symbols.
451 *
452 * @param hDbgAs The address space handle.
453 * @param pszSymbol The symbol name.
454 * @param Addr The address of the symbol.
455 * @param cb The size of the symbol.
456 * @param fFlags Symbol flags.
457 * @param piOrdinal Where to return the symbol ordinal on success. If
458 * the interpreter doesn't do ordinals, this will be set to
459 * UINT32_MAX. Optional
460 */
461RTDECL(int) RTDbgAsSymbolAdd(RTDBGAS hDbgAs, const char *pszSymbol, RTUINTPTR Addr, RTUINTPTR cb, uint32_t fFlags, uint32_t *piOrdinal);
462
463/**
464 * Query a symbol by address.
465 *
466 * @returns IPRT status code. See RTDbgModSymbolAddr for more specific ones.
467 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
468 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
469 *
470 * @param hDbgAs The address space handle.
471 * @param Addr The address which closest symbol is requested.
472 * @param poffDisp Where to return the distance between the symbol
473 * and address. Optional.
474 * @param pSymInfo Where to return the symbol info.
475 * @param phMod Where to return the module handle. Optional.
476 */
477RTDECL(int) RTDbgAsSymbolByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo, PRTDBGMOD phMod);
478
479/**
480 * Query a symbol by address.
481 *
482 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
483 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
484 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
485 *
486 * @param hDbgAs The address space handle.
487 * @param Addr The address which closest symbol is requested.
488 * @param poffDisp Where to return the distance between the symbol
489 * and address. Optional.
490 * @param ppSymInfo Where to return the pointer to the allocated symbol
491 * info. Always set. Free with RTDbgSymbolFree.
492 * @param phMod Where to return the module handle. Optional.
493 */
494RTDECL(int) RTDbgAsSymbolByAddrA(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymInfo, PRTDBGMOD phMod);
495
496/**
497 * Query a symbol by name.
498 *
499 * @returns IPRT status code.
500 * @retval VERR_SYMBOL_NOT_FOUND if not found.
501 *
502 * @param hDbgAs The address space handle.
503 * @param pszSymbol The symbol name. It is possible to limit the scope
504 * of the search by prefixing the symbol with a module
505 * name pattern followed by a bang (!) character.
506 * RTStrSimplePatternNMatch is used for the matching.
507 * @param pSymbol Where to return the symbol info.
508 * @param phMod Where to return the module handle. Optional.
509 */
510RTDECL(int) RTDbgAsSymbolByName(RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL pSymbol, PRTDBGMOD phMod);
511
512/**
513 * Query a symbol by name, allocating the returned symbol structure.
514 *
515 * @returns IPRT status code.
516 * @retval VERR_SYMBOL_NOT_FOUND if not found.
517 *
518 * @param hDbgAs The address space handle.
519 * @param pszSymbol The symbol name. See RTDbgAsSymbolByName for more.
520 * @param ppSymbol Where to return the pointer to the allocated
521 * symbol info. Always set. Free with RTDbgSymbolFree.
522 * @param phMod Where to return the module handle. Optional.
523 */
524RTDECL(int) RTDbgAsSymbolByNameA(RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL *ppSymbol, PRTDBGMOD phMod);
525
526/**
527 * Query a line number by address.
528 *
529 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
530 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
531 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
532 *
533 * @param hDbgAs The address space handle.
534 * @param Addr The address which closest symbol is requested.
535 * @param poffDisp Where to return the distance between the line
536 * number and address.
537 * @param pLine Where to return the line number information.
538 */
539RTDECL(int) RTDbgAs(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE pLine);
540
541/**
542 * Adds a line number to a module in the address space.
543 *
544 * @returns IPRT status code. See RTDbgModSymbolAdd for more specific ones.
545 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
546 * @retval VERR_NOT_FOUND if no module was found at the specified address.
547 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
548 * custom symbols.
549 *
550 * @param hDbgAs The address space handle.
551 * @param pszFile The file name.
552 * @param uLineNo The line number.
553 * @param Addr The address of the symbol.
554 * @param piOrdinal Where to return the line number ordinal on success.
555 * If the interpreter doesn't do ordinals, this will be
556 * set to UINT32_MAX. Optional.
557 */
558RTDECL(int) RTDbgAsLineAdd(RTDBGAS hDbgAs, const char *pszFile, uint32_t uLineNo, RTUINTPTR Addr, uint32_t *piOrdinal);
559
560/**
561 * Query a line number by address.
562 *
563 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
564 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
565 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
566 *
567 * @param hDbgAs The address space handle.
568 * @param Addr The address which closest symbol is requested.
569 * @param poffDisp Where to return the distance between the line
570 * number and address.
571 * @param ppLine Where to return the pointer to the allocated line
572 * number info. Always set. Free with RTDbgLineFree.
573 */
574RTDECL(int) RTDbgAsLineByAddrA(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE *ppLine);
575
576/** @todo Missing some bits here. */
577
578/** @} */
579
580
581/** @defgroup grp_rt_dbgmod RTDbgMod - Debug Module Interpreter
582 * @{
583 */
584
585/**
586 * Creates a module based on the default debug info container.
587 *
588 * This can be used to manually load a module and its symbol. The primary user
589 * group is the debug info interpreters, which use this API to create an
590 * efficient debug info container behind the scenes and forward all queries to
591 * it once the info has been loaded.
592 *
593 * @returns IPRT status code.
594 *
595 * @param phDbgMod Where to return the module handle.
596 * @param pszName The name of the module (mandatory).
597 * @param cbSeg The size of initial segment. If zero, segments will
598 * have to be added manually using RTDbgModSegmentAdd.
599 * @param fFlags Flags reserved for future extensions, MBZ for now.
600 */
601RTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cbSeg, uint32_t fFlags);
602
603RTDECL(int) RTDbgModCreateDeferred(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR cb, uint32_t fFlags);
604RTDECL(int) RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t fFlags);
605RTDECL(int) RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR uSubtrahend, uint32_t fFlags);
606
607
608/**
609 * Retains another reference to the module.
610 *
611 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
612 *
613 * @param hDbgMod The module handle.
614 *
615 * @remarks Will not take any locks.
616 */
617RTDECL(uint32_t) RTDbgModRetain(RTDBGMOD hDbgMod);
618
619/**
620 * Release a reference to the module.
621 *
622 * When the reference count reaches zero, the module is destroyed.
623 *
624 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
625 *
626 * @param hDbgMod The module handle. The NIL handle is quietly ignored
627 * and 0 is returned.
628 *
629 * @remarks Will not take any locks.
630 */
631RTDECL(uint32_t) RTDbgModRelease(RTDBGMOD hDbgMod);
632
633/**
634 * Gets the module name.
635 *
636 * @returns Pointer to a read only string containing the name.
637 *
638 * @param hDbgMod The module handle.
639 */
640RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod);
641
642/**
643 * Converts an image relative address to a segment:offset address.
644 *
645 * @returns Segment index on success.
646 * NIL_RTDBGSEGIDX is returned if the module handle or the RVA are
647 * invalid.
648 *
649 * @param hDbgMod The module handle.
650 * @param uRva The image relative address to convert.
651 * @param poffSeg Where to return the segment offset. Optional.
652 */
653RTDECL(RTDBGSEGIDX) RTDbgModRvaToSegOff(RTDBGMOD hDbgMod, RTUINTPTR uRva, PRTUINTPTR poffSeg);
654
655/**
656 * Image size when mapped if segments are mapped adjecently.
657 *
658 * For ELF, PE, and Mach-O images this is (usually) a natural query, for LX and
659 * NE and such it's a bit odder and the answer may not make much sense for them.
660 *
661 * @returns Image mapped size.
662 * RTUINTPTR_MAX is returned if the handle is invalid.
663 *
664 * @param hDbgMod The module handle.
665 */
666RTDECL(RTUINTPTR) RTDbgModImageSize(RTDBGMOD hDbgMod);
667
668
669/**
670 * Adds a segment to the module. Optional feature.
671 *
672 * This method is intended used for manually constructing debug info for a
673 * module. The main usage is from other debug info interpreters that want to
674 * avoid writing a debug info database and instead uses the standard container
675 * behind the scenes.
676 *
677 * @returns IPRT status code.
678 * @retval VERR_NOT_SUPPORTED if this feature isn't support by the debug info
679 * interpreter. This is a common return code.
680 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
681 * @retval VERR_DBG_ADDRESS_WRAP if uRva+cb wraps around.
682 * @retval VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE if pszName is too short or long.
683 * @retval VERR_INVALID_PARAMETER if fFlags contains undefined flags.
684 * @retval VERR_DBG_SPECIAL_SEGMENT if *piSeg is a special segment.
685 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if *piSeg doesn't meet expectations.
686 *
687 * @param hDbgMod The module handle.
688 * @param uRva The image relative address of the segment.
689 * @param cb The size of the segment.
690 * @param pszName The segment name. Does not normally need to be
691 * unique, although this is somewhat up to the
692 * debug interpreter to decide.
693 * @param fFlags Segment flags. Reserved for future used, MBZ.
694 * @param piSeg The segment index or NIL_RTDBGSEGIDX on input.
695 * The assigned segment index on successful return.
696 * Optional.
697 */
698RTDECL(int) RTDbgModSegmentAdd(RTDBGMOD hDbgMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName,
699 uint32_t fFlags, PRTDBGSEGIDX piSeg);
700
701/**
702 * Gets the number of segments in the module.
703 *
704 * This is can be used to determin the range which can be passed to
705 * RTDbgModSegmentByIndex and derivates.
706 *
707 * @returns The segment relative address.
708 * NIL_RTDBGSEGIDX if the handle is invalid.
709 *
710 * @param hDbgMod The module handle.
711 */
712RTDECL(RTDBGSEGIDX) RTDbgModSegmentCount(RTDBGMOD hDbgMod);
713
714/**
715 * Query information about a segment.
716 *
717 * This can be used together with RTDbgModSegmentCount to enumerate segments.
718 * The index starts a 0 and stops one below RTDbgModSegmentCount.
719 *
720 * @returns IPRT status code.
721 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if iSeg is too high.
722 * @retval VERR_DBG_SPECIAL_SEGMENT if iSeg indicates a special segment.
723 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
724 *
725 * @param hDbgMod The module handle.
726 * @param iSeg The segment index. No special segments.
727 * @param pSegInfo Where to return the segment info. The
728 * RTDBGSEGMENT::Address member will be set to
729 * RTUINTPTR_MAX or the load address used at link time.
730 */
731RTDECL(int) RTDbgModSegmentByIndex(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo);
732
733/**
734 * Gets the size of a segment.
735 *
736 * This is a just a wrapper around RTDbgModSegmentByIndex.
737 *
738 * @returns The segment size.
739 * RTUINTPTR_MAX is returned if either the handle and segment index are
740 * invalid.
741 *
742 * @param hDbgMod The module handle.
743 * @param iSeg The segment index. RTDBGSEGIDX_ABS is not allowed.
744 * If RTDBGSEGIDX_RVA is used, the functions returns
745 * the same value as RTDbgModImageSize.
746 */
747RTDECL(RTUINTPTR) RTDbgModSegmentSize(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
748
749/**
750 * Gets the image relative address of a segment.
751 *
752 * This is a just a wrapper around RTDbgModSegmentByIndex.
753 *
754 * @returns The segment relative address.
755 * RTUINTPTR_MAX is returned if either the handle and segment index are
756 * invalid.
757 *
758 * @param hDbgMod The module handle.
759 * @param iSeg The segment index. No special segment indexes
760 * allowed (asserted).
761 */
762RTDECL(RTUINTPTR) RTDbgModSegmentRva(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
763
764
765/**
766 * Adds a line number to the module.
767 *
768 * @returns IPRT status code.
769 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
770 * custom symbols. This is a common place occurance.
771 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
772 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
773 * short.
774 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
775 * it's not inside any of the segments defined by the module.
776 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
777 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
778 * end of the segment.
779 * @retval VERR_DBG_ADDRESS_WRAP if off+cb wraps around.
780 * @retval VERR_INVALID_PARAMETER if the symbol flags sets undefined bits.
781 *
782 * @param hDbgMod The module handle.
783 * @param pszSymbol The symbol name.
784 * @param iSeg The segment index.
785 * @param off The segment offset.
786 * @param cb The size of the symbol. Can be zero, although this
787 * may depend somewhat on the debug interpreter.
788 * @param fFlags Symbol flags. Reserved for the future, MBZ.
789 * @param piOrdinal Where to return the symbol ordinal on success. If
790 * the interpreter doesn't do ordinals, this will be set to
791 * UINT32_MAX. Optional.
792 */
793RTDECL(int) RTDbgModSymbolAdd(RTDBGMOD hDbgMod, const char *pszSymbol, RTDBGSEGIDX iSeg, RTUINTPTR off,
794 RTUINTPTR cb, uint32_t fFlags, uint32_t *piOrdinal);
795
796/**
797 * Gets the symbol count.
798 *
799 * This can be used together wtih RTDbgModSymbolByOrdinal or
800 * RTDbgModSymbolByOrdinalA to enumerate all the symbols.
801 *
802 * @returns The number of symbols in the module.
803 * UINT32_MAX is returned if the module handle is invalid or some other
804 * error occurs.
805 *
806 * @param hDbgMod The module handle.
807 */
808RTDECL(uint32_t) RTDbgModSymbolCount(RTDBGMOD hDbgMod);
809
810/**
811 * Queries symbol information by ordinal number.
812 *
813 * @returns IPRT status code.
814 * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at the given number.
815 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
816 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
817 * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
818 *
819 * @param hDbgMod The module handle.
820 * @param iOrdinal The symbol ordinal number. 0-based. The highest
821 * number is RTDbgModSymbolCount() - 1.
822 * @param pSymInfo Where to store the symbol information.
823 */
824RTDECL(int) RTDbgModSymbolByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo);
825
826/**
827 * Queries symbol information by ordinal number.
828 *
829 * @returns IPRT status code.
830 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
831 * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
832 * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at the given number.
833 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
834 *
835 * @param hDbgMod The module handle.
836 * @param iOrdinal The symbol ordinal number. 0-based. The highest
837 * number is RTDbgModSymbolCount() - 1.
838 * @param ppSymInfo Where to store the pointer to the returned
839 * symbol information. Always set. Free with
840 * RTDbgSymbolFree.
841 */
842RTDECL(int) RTDbgModSymbolByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL *ppSymInfo);
843
844/**
845 * Queries symbol information by address.
846 *
847 * The returned symbol is what the debug info interpreter consideres the symbol
848 * most applicable to the specified address. This usually means a symbol with an
849 * address equal or lower than the requested.
850 *
851 * @returns IPRT status code.
852 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
853 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
854 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
855 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
856 * it's not inside any of the segments defined by the module.
857 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
858 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
859 * end of the segment.
860 *
861 * @param hDbgMod The module handle.
862 * @param iSeg The segment number.
863 * @param off The offset into the segment.
864 * @param poffDisp Where to store the distance between the
865 * specified address and the returned symbol.
866 * Optional.
867 * @param pSymInfo Where to store the symbol information.
868 */
869RTDECL(int) RTDbgModSymbolByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo);
870
871/**
872 * Queries symbol information by address.
873 *
874 * The returned symbol is what the debug info interpreter consideres the symbol
875 * most applicable to the specified address. This usually means a symbol with an
876 * address equal or lower than the requested.
877 *
878 * @returns IPRT status code.
879 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
880 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
881 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
882 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
883 * it's not inside any of the segments defined by the module.
884 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
885 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
886 * end of the segment.
887 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
888 *
889 * @param hDbgMod The module handle.
890 * @param iSeg The segment index.
891 * @param off The offset into the segment.
892 * @param poffDisp Where to store the distance between the
893 * specified address and the returned symbol. Optional.
894 * @param ppSymInfo Where to store the pointer to the returned
895 * symbol information. Always set. Free with
896 * RTDbgSymbolFree.
897 */
898RTDECL(int) RTDbgModSymbolByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymInfo);
899
900/**
901 * Queries symbol information by symbol name.
902 *
903 * @returns IPRT status code.
904 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
905 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
906 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
907 * short.
908 *
909 * @param hDbgMod The module handle.
910 * @param pszSymbol The symbol name.
911 * @param pSymInfo Where to store the symbol information.
912 */
913RTDECL(int) RTDbgModSymbolByName(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL pSymInfo);
914
915/**
916 * Queries symbol information by symbol name.
917 *
918 * @returns IPRT status code.
919 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
920 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
921 * @retval VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE if the symbol name is too long or
922 * short.
923 * @retval VERR_NO_MEMORY if RTDbgSymbolAlloc fails.
924 *
925 * @param hDbgMod The module handle.
926 * @param pszSymbol The symbol name.
927 * @param ppSymInfo Where to store the pointer to the returned
928 * symbol information. Always set. Free with
929 * RTDbgSymbolFree.
930 */
931RTDECL(int) RTDbgModSymbolByNameA(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL *ppSymInfo);
932
933/**
934 * Adds a line number to the module.
935 *
936 * @returns IPRT status code.
937 * @retval VERR_NOT_SUPPORTED if the module interpret doesn't support adding
938 * custom symbols. This should be consider a normal response.
939 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
940 * @retval VERR_DBG_FILE_NAME_OUT_OF_RANGE if the file name is too longer or
941 * empty.
942 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
943 * it's not inside any of the segments defined by the module.
944 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
945 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
946 * end of the segment.
947 * @retval VERR_INVALID_PARAMETER if the line number flags sets undefined bits.
948 *
949 * @param hDbgMod The module handle.
950 * @param pszFile The file name.
951 * @param uLineNo The line number.
952 * @param iSeg The segment index.
953 * @param off The segment offset.
954 * @param piOrdinal Where to return the line number ordinal on
955 * success. If the interpreter doesn't do ordinals,
956 * this will be set to UINT32_MAX. Optional.
957 */
958RTDECL(int) RTDbgModLineAdd(RTDBGMOD hDbgMod, const char *pszFile, uint32_t uLineNo,
959 RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t *piOrdinal);
960
961/**
962 * Gets the line number count.
963 *
964 * This can be used together wtih RTDbgModLineByOrdinal or RTDbgModSymbolByLineA
965 * to enumerate all the line number information.
966 *
967 * @returns The number of line numbers in the module.
968 * UINT32_MAX is returned if the module handle is invalid or some other
969 * error occurs.
970 *
971 * @param hDbgMod The module handle.
972 */
973RTDECL(uint32_t) RTDbgModLineCount(RTDBGMOD hDbgMod);
974
975/**
976 * Queries line number information by ordinal number.
977 *
978 * This can be used to enumerate the line numbers for the module. Use
979 * RTDbgModLineCount() to figure the end of the ordinals.
980 *
981 * @returns IPRT status code.
982 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
983 * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
984 * ordinal.
985 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
986
987 * @param hDbgMod The module handle.
988 * @param iOrdinal The line number ordinal number.
989 * @param pLineInfo Where to store the information about the line
990 * number.
991 */
992RTDECL(int) RTDbgModLineByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo);
993
994/**
995 * Queries line number information by ordinal number.
996 *
997 * This can be used to enumerate the line numbers for the module. Use
998 * RTDbgModLineCount() to figure the end of the ordinals.
999 *
1000 * @returns IPRT status code.
1001 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1002 * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
1003 * ordinal.
1004 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1005 * @retval VERR_NO_MEMORY if RTDbgLineAlloc fails.
1006 *
1007 * @param hDbgMod The module handle.
1008 * @param iOrdinal The line number ordinal number.
1009 * @param ppLineInfo Where to store the pointer to the returned line
1010 * number information. Always set. Free with
1011 * RTDbgLineFree.
1012 */
1013RTDECL(int) RTDbgModLineByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE *ppLineInfo);
1014
1015/**
1016 * Queries line number information by address.
1017 *
1018 * The returned line number is what the debug info interpreter consideres the
1019 * one most applicable to the specified address. This usually means a line
1020 * number with an address equal or lower than the requested.
1021 *
1022 * @returns IPRT status code.
1023 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1024 * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
1025 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1026 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1027 * it's not inside any of the segments defined by the module.
1028 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1029 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1030 * end of the segment.
1031 *
1032 * @param hDbgMod The module handle.
1033 * @param iSeg The segment number.
1034 * @param off The offset into the segment.
1035 * @param poffDisp Where to store the distance between the
1036 * specified address and the returned symbol.
1037 * Optional.
1038 * @param pSymInfo Where to store the symbol information.
1039 */
1040RTDECL(int) RTDbgModLineByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLineInfo);
1041
1042/**
1043 * Queries line number information by address.
1044 *
1045 * The returned line number is what the debug info interpreter consideres the
1046 * one most applicable to the specified address. This usually means a line
1047 * number with an address equal or lower than the requested.
1048 *
1049 * @returns IPRT status code.
1050 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
1051 * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
1052 * @retval VERR_INVALID_HANDLE if hDbgMod is invalid.
1053 * @retval VERR_DBG_INVALID_RVA if an image relative address is specified and
1054 * it's not inside any of the segments defined by the module.
1055 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if the segment index isn't valid.
1056 * @retval VERR_DBG_INVALID_SEGMENT_OFFSET if the segment offset is beyond the
1057 * end of the segment.
1058 * @retval VERR_NO_MEMORY if RTDbgLineAlloc fails.
1059 *
1060 * @param hDbgMod The module handle.
1061 * @param iSeg The segment number.
1062 * @param off The offset into the segment.
1063 * @param poffDisp Where to store the distance between the
1064 * specified address and the returned symbol.
1065 * Optional.
1066 * @param ppLineInfo Where to store the pointer to the returned line
1067 * number information. Always set. Free with
1068 * RTDbgLineFree.
1069 */
1070RTDECL(int) RTDbgModLineByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE *ppLineInfo);
1071/** @} */
1072
1073/** @} */
1074
1075RT_C_DECLS_END
1076
1077#endif
1078
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