VirtualBox

source: vbox/trunk/src/VBox/Runtime/include/internal/dbgmod.h@ 38547

Last change on this file since 38547 was 38547, checked in by vboxsync, 14 years ago

IPRT: More debug info hacking.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.0 KB
Line 
1/* $Id: dbgmod.h 38547 2011-08-26 12:58:47Z vboxsync $ */
2/** @file
3 * IPRT - Internal Header for RTDbgMod and the associated interpreters.
4 */
5
6/*
7 * Copyright (C) 2008-2011 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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 ___internal_dbgmod_h
28#define ___internal_dbgmod_h
29
30#include <iprt/types.h>
31#include <iprt/critsect.h>
32#include <iprt/ldr.h> /* for PFNRTLDRENUMDBG */
33#include "internal/magics.h"
34
35RT_C_DECLS_BEGIN
36
37/** @addtogroup grp_rt_dbgmod
38 * @internal
39 * @{
40 */
41
42
43/** Pointer to the internal module structure. */
44typedef struct RTDBGMODINT *PRTDBGMODINT;
45
46/**
47 * Virtual method table for executable image interpreters.
48 */
49typedef struct RTDBGMODVTIMG
50{
51 /** Magic number (RTDBGMODVTIMG_MAGIC). */
52 uint32_t u32Magic;
53 /** Reserved. */
54 uint32_t fReserved;
55 /** The name of the interpreter. */
56 const char *pszName;
57
58 /**
59 * Try open the image.
60 *
61 * This combines probing and opening.
62 *
63 * @returns IPRT status code. No informational returns defined.
64 *
65 * @param pMod Pointer to the module that is being opened.
66 *
67 * The RTDBGMOD::pszDbgFile member will point to
68 * the filename of any debug info we're aware of
69 * on input. Also, or alternatively, it is expected
70 * that the interpreter will look for debug info in
71 * the executable image file when present and that it
72 * may ask the image interpreter for this when it's
73 * around.
74 *
75 * Upon successful return the method is expected to
76 * initialize pImgOps and pvImgPriv.
77 */
78 DECLCALLBACKMEMBER(int, pfnTryOpen)(PRTDBGMODINT pMod);
79
80 /**
81 * Close the interpreter, freeing all associated resources.
82 *
83 * The caller sets the pDbgOps and pvDbgPriv RTDBGMOD members
84 * to NULL upon return.
85 *
86 * @param pMod Pointer to the module structure.
87 */
88 DECLCALLBACKMEMBER(int, pfnClose)(PRTDBGMODINT pMod);
89
90 /**
91 * Enumerate the debug info contained in the executable image.
92 *
93 * Identical to RTLdrEnumDbgInfo.
94 *
95 * @returns IPRT status code or whatever pfnCallback returns.
96 *
97 * @param pMod Pointer to the module structure.
98 * @param pfnCallback The callback function. Ignore the module
99 * handle argument!
100 * @param pvUser The user argument.
101 */
102 DECLCALLBACKMEMBER(int, pfnEnumDbgInfo)(PRTDBGMODINT pMod, PFNRTLDRENUMDBG pfnCallback, void *pvUser);
103
104 /**
105 * Enumerate the segments in the executable image.
106 *
107 * Identical to RTLdrEnumSegments.
108 *
109 * @returns IPRT status code or whatever pfnCallback returns.
110 *
111 * @param pMod Pointer to the module structure.
112 * @param pfnCallback The callback function. Ignore the module
113 * handle argument!
114 * @param pvUser The user argument.
115 */
116 DECLCALLBACKMEMBER(int, pfnEnumSegments)(PRTDBGMODINT pMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser);
117
118 /**
119 * Gets the size of the loaded image.
120 *
121 * Identical to RTLdrSize.
122 *
123 * @returns The size in bytes, RTUINTPTR_MAX on failure.
124 *
125 * @param pMod Pointer to the module structure.
126 */
127 DECLCALLBACKMEMBER(RTUINTPTR, pfnImageSize)(PRTDBGMODINT pMod);
128
129 /**
130 * Creates a read-only mapping of a part of the image file.
131 *
132 * @returns IPRT status code and *ppvMap set on success.
133 *
134 * @param pMod Pointer to the module structure.
135 * @param off The offset into the image file.
136 * @param cb The number of bytes to map.
137 * @param ppvMap Where to return the mapping address on success.
138 */
139 DECLCALLBACKMEMBER(int, pfnMapPart)(PRTDBGMODINT pMod, RTFOFF off, size_t cb, void const **ppvMap);
140
141 /**
142 * Unmaps memory previously mapped by pfnMapPart.
143 *
144 * @returns IPRT status code, *ppvMap set to NULL on success.
145 *
146 * @param pMod Pointer to the module structure.
147 * @param cb The size of the mapping.
148 * @param ppvMap The mapping address on input, NULL on
149 * successful return.
150 */
151 DECLCALLBACKMEMBER(int, pfnUnmapPart)(PRTDBGMODINT pMod, size_t cb, void const **ppvMap);
152
153
154 /** For catching initialization errors (RTDBGMODVTIMG_MAGIC). */
155 uint32_t u32EndMagic;
156} RTDBGMODVTIMG;
157/** Pointer to a const RTDBGMODVTIMG. */
158typedef RTDBGMODVTIMG const *PCRTDBGMODVTIMG;
159
160
161/**
162 * Virtual method table for debug info interpreters.
163 */
164typedef struct RTDBGMODVTDBG
165{
166 /** Magic number (RTDBGMODVTDBG_MAGIC). */
167 uint32_t u32Magic;
168 /** Mask of supported debug info types, see grp_rt_dbg_type.
169 * Used to speed up the search for a suitable interpreter. */
170 uint32_t fSupports;
171 /** The name of the interpreter. */
172 const char *pszName;
173
174 /**
175 * Try open the image.
176 *
177 * This combines probing and opening.
178 *
179 * @returns IPRT status code. No informational returns defined.
180 *
181 * @param pMod Pointer to the module that is being opened.
182 *
183 * The RTDBGMOD::pszDbgFile member will point to
184 * the filename of any debug info we're aware of
185 * on input. Also, or alternatively, it is expected
186 * that the interpreter will look for debug info in
187 * the executable image file when present and that it
188 * may ask the image interpreter for this when it's
189 * around.
190 *
191 * Upon successful return the method is expected to
192 * initialize pDbgOps and pvDbgPriv.
193 */
194 DECLCALLBACKMEMBER(int, pfnTryOpen)(PRTDBGMODINT pMod);
195
196 /**
197 * Close the interpreter, freeing all associated resources.
198 *
199 * The caller sets the pDbgOps and pvDbgPriv RTDBGMOD members
200 * to NULL upon return.
201 *
202 * @param pMod Pointer to the module structure.
203 */
204 DECLCALLBACKMEMBER(int, pfnClose)(PRTDBGMODINT pMod);
205
206
207
208 /**
209 * Converts an image relative virtual address address to a segmented address.
210 *
211 * @returns Segment index on success, NIL_RTDBGSEGIDX on failure.
212 * @param pMod Pointer to the module structure.
213 * @param uRva The image relative address to convert.
214 * @param poffSeg Where to return the segment offset. Optional.
215 */
216 DECLCALLBACKMEMBER(RTDBGSEGIDX, pfnRvaToSegOff)(PRTDBGMODINT pMod, RTUINTPTR uRva, PRTUINTPTR poffSeg);
217
218 /**
219 * Image size when mapped if segments are mapped adjacently.
220 *
221 * For ELF, PE, and Mach-O images this is (usually) a natural query, for LX and
222 * NE and such it's a bit odder and the answer may not make much sense for them.
223 *
224 * @returns Image mapped size.
225 * @param pMod Pointer to the module structure.
226 */
227 DECLCALLBACKMEMBER(RTUINTPTR, pfnImageSize)(PRTDBGMODINT pMod);
228
229
230
231 /**
232 * Adds a segment to the module (optional).
233 *
234 * @returns IPRT status code.
235 * @retval VERR_NOT_SUPPORTED if the interpreter doesn't support this feature.
236 * @retval VERR_DBG_SEGMENT_INDEX_CONFLICT if the segment index exists already.
237 *
238 * @param pMod Pointer to the module structure.
239 * @param uRva The segment image relative address.
240 * @param cb The segment size.
241 * @param pszName The segment name.
242 * @param cchName The length of the segment name.
243 * @param fFlags Segment flags.
244 * @param piSeg The segment index or NIL_RTDBGSEGIDX on input.
245 * The assigned segment index on successful return.
246 * Optional.
247 */
248 DECLCALLBACKMEMBER(int, pfnSegmentAdd)(PRTDBGMODINT pMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName, size_t cchName,
249 uint32_t fFlags, PRTDBGSEGIDX piSeg);
250
251 /**
252 * Gets the segment count.
253 *
254 * @returns Number of segments.
255 * @retval NIL_RTDBGSEGIDX if unknown.
256 *
257 * @param pMod Pointer to the module structure.
258 */
259 DECLCALLBACKMEMBER(RTDBGSEGIDX, pfnSegmentCount)(PRTDBGMODINT pMod);
260
261 /**
262 * Gets information about a segment.
263 *
264 * @returns IPRT status code.
265 * @retval VERR_DBG_INVALID_SEGMENT_INDEX if iSeg is too high.
266 *
267 * @param pMod Pointer to the module structure.
268 * @param iSeg The segment.
269 * @param pSegInfo Where to store the segment information.
270 */
271 DECLCALLBACKMEMBER(int, pfnSegmentByIndex)(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo);
272
273
274
275 /**
276 * Adds a symbol to the module (optional).
277 *
278 * @returns IPRT code.
279 * @retval VERR_NOT_SUPPORTED if the interpreter doesn't support this feature.
280 *
281 * @param pMod Pointer to the module structure.
282 * @param pszSymbol The symbol name.
283 * @param cchSymbol The length for the symbol name.
284 * @param iSeg The segment number (0-based). RTDBGMOD_SEG_RVA can be used.
285 * @param off The offset into the segment.
286 * @param cb The area covered by the symbol. 0 is fine.
287 * @param fFlags Flags.
288 * @param piOrdinal Where to return the symbol ordinal on success. If the
289 * interpreter doesn't do ordinals, this will be set to
290 * UINT32_MAX. Optional
291 */
292 DECLCALLBACKMEMBER(int, pfnSymbolAdd)(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
293 uint32_t iSeg, RTUINTPTR off, RTUINTPTR cb, uint32_t fFlags,
294 uint32_t *piOrdinal);
295
296 /**
297 * Gets the number of symbols in the module.
298 *
299 * This is used for figuring out the max value to pass to pfnSymbolByIndex among
300 * other things.
301 *
302 * @returns The number of symbols, UINT32_MAX if not known/supported.
303 *
304 * @param pMod Pointer to the module structure.
305 */
306 DECLCALLBACKMEMBER(uint32_t, pfnSymbolCount)(PRTDBGMODINT pMod);
307
308 /**
309 * Queries symbol information by ordinal number.
310 *
311 * @returns IPRT status code.
312 * @retval VINF_SUCCESS on success, no informational status code.
313 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
314 * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
315 * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at that index.
316 *
317 * @param pMod Pointer to the module structure.
318 * @param iOrdinal The symbol ordinal number.
319 * @param pSymInfo Where to store the symbol information.
320 */
321 DECLCALLBACKMEMBER(int, pfnSymbolByOrdinal)(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo);
322
323 /**
324 * Queries symbol information by symbol name.
325 *
326 * @returns IPRT status code.
327 * @retval VINF_SUCCESS on success, no informational status code.
328 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
329 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
330 *
331 * @param pMod Pointer to the module structure.
332 * @param pszSymbol The symbol name.
333 * @param cchSymbol The length of the symbol name.
334 * @param pSymInfo Where to store the symbol information.
335 */
336 DECLCALLBACKMEMBER(int, pfnSymbolByName)(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol, PRTDBGSYMBOL pSymInfo);
337
338 /**
339 * Queries symbol information by address.
340 *
341 * The returned symbol is what the debug info interpreter considers the symbol
342 * most applicable to the specified address. This usually means a symbol with an
343 * address equal or lower than the requested.
344 *
345 * @returns IPRT status code.
346 * @retval VINF_SUCCESS on success, no informational status code.
347 * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
348 * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
349 *
350 * @param pMod Pointer to the module structure.
351 * @param iSeg The segment number (0-based) or RTDBGSEGIDX_ABS.
352 * @param off The offset into the segment.
353 * @param poffDisp Where to store the distance between the specified address
354 * and the returned symbol. Optional.
355 * @param pSymInfo Where to store the symbol information.
356 */
357 DECLCALLBACKMEMBER(int, pfnSymbolByAddr)(PRTDBGMODINT pMod, uint32_t iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo);
358
359
360
361 /**
362 * Adds a line number to the module (optional).
363 *
364 * @returns IPRT status code.
365 * @retval VERR_NOT_SUPPORTED if the interpreter doesn't support this feature.
366 *
367 * @param pMod Pointer to the module structure.
368 * @param pszFile The filename.
369 * @param cchFile The length of the filename.
370 * @param uLineNo The line number.
371 * @param iSeg The segment number (0-based).
372 * @param off The offset into the segment.
373 * @param piOrdinal Where to return the line number ordinal on success. If
374 * the interpreter doesn't do ordinals, this will be set to
375 * UINT32_MAX. Optional
376 */
377 DECLCALLBACKMEMBER(int, pfnLineAdd)(PRTDBGMODINT pMod, const char *pszFile, size_t cchFile, uint32_t uLineNo,
378 uint32_t iSeg, RTUINTPTR off, uint32_t *piOrdinal);
379
380 /**
381 * Gets the number of line numbers in the module.
382 *
383 * @returns The number or UINT32_MAX if not known/supported.
384 *
385 * @param pMod Pointer to the module structure.
386 */
387 DECLCALLBACKMEMBER(uint32_t, pfnLineCount)(PRTDBGMODINT pMod);
388
389 /**
390 * Queries line number information by ordinal number.
391 *
392 * @returns IPRT status code.
393 * @retval VINF_SUCCESS on success, no informational status code.
394 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
395 * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
396 * ordinal.
397 *
398 * @param pMod Pointer to the module structure.
399 * @param iOrdinal The line number ordinal number.
400 * @param pLineInfo Where to store the information about the line number.
401 */
402 DECLCALLBACKMEMBER(int, pfnLineByOrdinal)(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo);
403
404 /**
405 * Queries line number information by address.
406 *
407 * @returns IPRT status code.
408 * @retval VINF_SUCCESS on success, no informational status code.
409 * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
410 * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
411 *
412 * @param pMod Pointer to the module structure.
413 * @param iSeg The segment number (0-based) or RTDBGSEGIDX_ABS.
414 * @param off The offset into the segment.
415 * @param poffDisp Where to store the distance between the specified address
416 * and the returned line number. Optional.
417 * @param pLineInfo Where to store the information about the closest line
418 * number.
419 */
420 DECLCALLBACKMEMBER(int, pfnLineByAddr)(PRTDBGMODINT pMod, uint32_t iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLineInfo);
421
422
423 /** For catching initialization errors (RTDBGMODVTDBG_MAGIC). */
424 uint32_t u32EndMagic;
425} RTDBGMODVTDBG;
426/** Pointer to a const RTDBGMODVTDBG. */
427typedef RTDBGMODVTDBG const *PCRTDBGMODVTDBG;
428
429
430/**
431 * Debug module structure.
432 */
433typedef struct RTDBGMODINT
434{
435 /** Magic value (RTDBGMOD_MAGIC). */
436 uint32_t u32Magic;
437 /** The number of reference there are to this module.
438 * This is used to perform automatic cleanup and sharing. */
439 uint32_t volatile cRefs;
440 /** The module tag. */
441 uint64_t uTag;
442 /** The module name (short). */
443 char const *pszName;
444 /** The module filename. Can be NULL. */
445 char const *pszImgFile;
446 /** The debug info file (if external). Can be NULL. */
447 char const *pszDbgFile;
448
449 /** Critical section serializing access to the module. */
450 RTCRITSECT CritSect;
451
452 /** The method table for the executable image interpreter. */
453 PCRTDBGMODVTIMG pImgVt;
454 /** Pointer to the private data of the executable image interpreter. */
455 void *pvImgPriv;
456
457 /** The method table for the debug info interpreter. */
458 PCRTDBGMODVTDBG pDbgVt;
459 /** Pointer to the private data of the debug info interpreter. */
460 void *pvDbgPriv;
461
462} RTDBGMODINT;
463/** Pointer to an debug module structure. */
464typedef RTDBGMODINT *PRTDBGMODINT;
465
466
467extern DECLHIDDEN(RTSTRCACHE) g_hDbgModStrCache;
468extern DECLHIDDEN(RTDBGMODVTDBG const) g_rtDbgModVtDbgDwarf;
469extern DECLHIDDEN(RTDBGMODVTDBG const) g_rtDbgModVtDbgNm;
470extern DECLHIDDEN(RTDBGMODVTIMG const) g_rtDbgModVtImgLdr;
471
472int rtDbgModContainerCreate(PRTDBGMODINT pMod, RTUINTPTR cbSeg);
473
474/** @} */
475
476RT_C_DECLS_END
477
478#endif
479
Note: See TracBrowser for help on using the repository browser.

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