VirtualBox

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

Last change on this file since 20554 was 20513, checked in by vboxsync, 16 years ago

OSE header fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.1 KB
Line 
1/* $Id: dbg.h 20513 2009-06-12 13:03:42Z 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
61/** Max length (including '\\0') of a symbol name. */
62#define RTDBG_SYMBOL_NAME_LENGTH (512 - 8 - 4 - 4 - 4)
63
64/**
65 * Debug symbol.
66 */
67typedef struct RTDBGSYMBOL
68{
69 /** Symbol value (address). */
70 RTUINTPTR Value;
71 /** Segment number when applicable or NIL_RTDBGSEGIDX. */
72 RTDBGSEGIDX iSeg;
73 /** Symbol size. */
74 uint32_t cb;
75 /** Symbol Flags. (reserved). */
76 uint32_t fFlags;
77 /** Symbol name. */
78 char szName[RTDBG_SYMBOL_NAME_LENGTH];
79} RTDBGSYMBOL;
80/** Pointer to debug symbol. */
81typedef RTDBGSYMBOL *PRTDBGSYMBOL;
82/** Pointer to const debug symbol. */
83typedef const RTDBGSYMBOL *PCRTDBGSYMBOL;
84
85RTDECL(PRTDBGSYMBOL) RTDbgSymbolAlloc(void);
86RTDECL(PRTDBGSYMBOL) RTDbgSymbolDup(PCRTDBGSYMBOL pSymbol);
87RTDECL(void) RTDbgSymbolFree(PRTDBGSYMBOL pSymbol);
88
89
90/**
91 * Debug line number information.
92 */
93typedef struct RTDBGLINE
94{
95 /** Address. */
96 RTUINTPTR Address;
97 /** Segment number when applicable or NIL_RTDBGSEGIDX. */
98 RTDBGSEGIDX iSeg;
99 /** Line number. */
100 uint32_t uLineNo;
101 /** Filename. */
102 char szFilename[260];
103} RTDBGLINE;
104/** Pointer to debug line number. */
105typedef RTDBGLINE *PRTDBGLINE;
106/** Pointer to const debug line number. */
107typedef const RTDBGLINE *PCRTDBGLINE;
108
109RTDECL(PRTDBGLINE) RTDbgLineAlloc(void);
110RTDECL(PRTDBGLINE) RTDbgLineDup(PCRTDBGLINE pLine);
111RTDECL(void) RTDbgLineFree(PRTDBGLINE pLine);
112
113
114/** @defgroup grp_rt_dbgas RTDbgAs - Debug Address Space
115 * @{
116 */
117
118/**
119 * Creates an empty address space.
120 *
121 * @returns IPRT status code.
122 *
123 * @param phDbgAs Where to store the address space handle on success.
124 * @param FirstAddr The first address in the address space.
125 * @param LastAddr The last address in the address space.
126 * @param pszName The name of the address space.
127 */
128RTDECL(int) RTDbgAsCreate(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszName);
129
130/**
131 * Variant of RTDbgAsCreate that takes a name format string.
132 *
133 * @returns IPRT status code.
134 *
135 * @param phDbgAs Where to store the address space handle on success.
136 * @param FirstAddr The first address in the address space.
137 * @param LastAddr The last address in the address space.
138 * @param pszNameFmt The name format of the address space.
139 * @param va Format arguments.
140 */
141RTDECL(int) RTDbgAsCreateV(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszNameFmt, va_list va);
142
143/**
144 * Variant of RTDbgAsCreate that takes a name format string.
145 *
146 * @returns IPRT status code.
147 *
148 * @param phDbgAs Where to store the address space handle on success.
149 * @param FirstAddr The first address in the address space.
150 * @param LastAddr The last address in the address space.
151 * @param pszNameFmt The name format of the address space.
152 * @param ... Format arguments.
153 */
154RTDECL(int) RTDbgAsCreateF(PRTDBGAS phDbgAs, RTUINTPTR FirstAddr, RTUINTPTR LastAddr, const char *pszNameFmt, ...);
155
156/**
157 * Retains a reference to the address space.
158 *
159 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
160 *
161 * @param hDbgAs The address space handle.
162 *
163 * @remarks Will not take any locks.
164 */
165RTDECL(uint32_t) RTDbgAsRetain(RTDBGAS hDbgAs);
166
167/**
168 * Release a reference to the address space.
169 *
170 * When the reference count reaches zero, the address space is destroyed.
171 * That means unlinking all the modules it currently contains, potentially
172 * causing some or all of them to be destroyed as they are managed by
173 * reference counting.
174 *
175 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
176 *
177 * @param hDbgAs The address space handle. The NIL handle is quietly
178 * ignored and 0 is returned.
179 *
180 * @remarks Will not take any locks.
181 */
182RTDECL(uint32_t) RTDbgAsRelease(RTDBGAS hDbgAs);
183
184/**
185 * Gets the name of an address space.
186 *
187 * @returns read only address space name.
188 * NULL if hDbgAs is invalid.
189 *
190 * @param hDbgAs The address space handle.
191 *
192 * @remarks Will not take any locks.
193 */
194RTDECL(const char *) RTDbgAsName(RTDBGAS hDbgAs);
195
196/**
197 * Gets the first address in an address space.
198 *
199 * @returns The address.
200 * 0 if hDbgAs is invalid.
201 *
202 * @param hDbgAs The address space handle.
203 *
204 * @remarks Will not take any locks.
205 */
206RTDECL(RTUINTPTR) RTDbgAsFirstAddr(RTDBGAS hDbgAs);
207
208/**
209 * Gets the last address in an address space.
210 *
211 * @returns The address.
212 * 0 if hDbgAs is invalid.
213 *
214 * @param hDbgAs The address space handle.
215 *
216 * @remarks Will not take any locks.
217 */
218RTDECL(RTUINTPTR) RTDbgAsLastAddr(RTDBGAS hDbgAs);
219
220/**
221 * Gets the number of modules in the address space.
222 *
223 * This can be used together with RTDbgAsModuleByIndex
224 * to enumerate the modules.
225 *
226 * @returns The number of modules.
227 *
228 * @param hDbgAs The address space handle.
229 *
230 * @remarks Will not take any locks.
231 */
232RTDECL(uint32_t) RTDbgAsModuleCount(RTDBGAS hDbgAs);
233
234/** @name Flags for RTDbgAsModuleLink and RTDbgAsModuleLinkSeg
235 * @{ */
236/** Replace all conflicting module.
237 * (The conflicting modules will be removed the address space and their
238 * references released.) */
239#define RTDBGASLINK_FLAGS_REPLACE RT_BIT_32(0)
240/** Mask containing the valid flags. */
241#define RTDBGASLINK_FLAGS_VALID_MASK UINT32_C(0x00000001)
242/** @} */
243
244/**
245 * Links a module into the address space at the give address.
246 *
247 * The size of the mapping is determined using RTDbgModImageSize().
248 *
249 * @returns IPRT status code.
250 * @retval VERR_OUT_OF_RANGE if the specified address will put the module
251 * outside the address space.
252 * @retval VERR_ADDRESS_CONFLICT if the mapping clashes with existing mappings.
253 *
254 * @param hDbgAs The address space handle.
255 * @param hDbgMod The module handle of the module to be linked in.
256 * @param ImageAddr The address to link the module at.
257 * @param fFlags See RTDBGASLINK_FLAGS_*.
258 */
259RTDECL(int) RTDbgAsModuleLink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTUINTPTR ImageAddr, uint32_t fFlags);
260
261/**
262 * Links a segment into the address space at the give address.
263 *
264 * The size of the mapping is determined using RTDbgModSegmentSize().
265 *
266 * @returns IPRT status code.
267 * @retval VERR_OUT_OF_RANGE if the specified address will put the module
268 * outside the address space.
269 * @retval VERR_ADDRESS_CONFLICT if the mapping clashes with existing mappings.
270 *
271 * @param hDbgAs The address space handle.
272 * @param hDbgMod The module handle.
273 * @param iSeg The segment number (0-based) of the segment to be
274 * linked in.
275 * @param SegAddr The address to link the segment at.
276 * @param fFlags See RTDBGASLINK_FLAGS_*.
277 */
278RTDECL(int) RTDbgAsModuleLinkSeg(RTDBGAS hDbgAs, RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR SegAddr, uint32_t fFlags);
279
280/**
281 * Unlinks all the mappings of a module from the address space.
282 *
283 * @returns IPRT status code.
284 * @retval VERR_NOT_FOUND if the module wasn't found.
285 *
286 * @param hDbgAs The address space handle.
287 * @param hDbgMod The module handle of the module to be unlinked.
288 */
289RTDECL(int) RTDbgAsModuleUnlink(RTDBGAS hDbgAs, RTDBGMOD hDbgMod);
290
291/**
292 * Unlinks the mapping at the specified address.
293 *
294 * @returns IPRT status code.
295 * @retval VERR_NOT_FOUND if no module or segment is mapped at that address.
296 *
297 * @param hDbgAs The address space handle.
298 * @param Addr The address within the mapping to be unlinked.
299 */
300RTDECL(int) RTDbgAsModuleUnlinkByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr);
301
302/**
303 * Get a the handle of a module in the address space by is index.
304 *
305 * @returns A retained handle to the specified module. The caller must release
306 * the returned reference.
307 * NIL_RTDBGMOD if invalid index or handle.
308 *
309 * @param hDbgAs The address space handle.
310 * @param iModule The index of the module to get.
311 *
312 * @remarks The module indexes may change after calls to RTDbgAsModuleLink,
313 * RTDbgAsModuleLinkSeg, RTDbgAsModuleUnlink and
314 * RTDbgAsModuleUnlinkByAddr.
315 */
316RTDECL(RTDBGMOD) RTDbgAsModuleByIndex(RTDBGAS hDbgAs, uint32_t iModule);
317
318/**
319 * Queries mapping module information by handle.
320 *
321 * @returns IPRT status code.
322 * @retval VERR_NOT_FOUND if no mapping was found at the specified address.
323 *
324 * @param hDbgAs The address space handle.
325 * @param Addr Address within the mapping of the module or segment.
326 * @param phMod Where to the return the retained module handle.
327 * Optional.
328 * @param pAddr Where to return the base address of the mapping.
329 * Optional.
330 * @param piSeg Where to return the segment index. This is set to
331 * NIL if the entire module is mapped as a single
332 * mapping. Optional.
333 */
334RTDECL(int) RTDbgAsModuleByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTDBGMOD phMod, PRTUINTPTR pAddr, PRTDBGSEGIDX piSeg);
335
336/**
337 * Queries mapping module information by name.
338 *
339 * @returns IPRT status code.
340 * @retval VERR_NOT_FOUND if no mapping was found at the specified address.
341 * @retval VERR_OUT_OF_RANGE if the name index was out of range.
342 *
343 * @param hDbgAs The address space handle.
344 * @param pszName The module name.
345 * @param iName There can be more than one module by the same name
346 * in an address space. This argument indicates which
347 * is ment. (0 based)
348 * @param phMod Where to the return the retained module handle.
349 */
350RTDECL(int) RTDbgAsModuleByName(RTDBGAS hDbgAs, const char *pszName, uint32_t iName, PRTDBGMOD phMod);
351
352/**
353 * Adds a symbol to a module in the address space.
354 *
355 * @returns IPRT status code. See RTDbgModSymbolAdd for more specific ones.
356 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
357 * @retval VERR_NOT_FOUND if no module was found at the specified address.
358 *
359 * @param hDbgAs The address space handle.
360 * @param pszSymbol The symbol name.
361 * @param Addr The address of the symbol.
362 * @param cb The size of the symbol.
363 */
364RTDECL(int) RTDbgAsSymbolAdd(RTDBGAS hDbgAs, const char *pszSymbol, RTUINTPTR Addr, uint32_t cb);
365
366/**
367 * Query a symbol by address.
368 *
369 * @returns IPRT status code. See RTDbgModSymbolAddr for more specific ones.
370 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
371 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
372 *
373 * @param hDbgAs The address space handle.
374 * @param Addr The address which closest symbol is requested.
375 * @param poffDisp Where to return the distance between the symbol
376 * and address. Optional.
377 * @param pSymbol Where to return the symbol info.
378 */
379RTDECL(int) RTDbgAsSymbolByAddr(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGSYMBOL pSymbol);
380
381/**
382 * Query a symbol by address.
383 *
384 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
385 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
386 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
387 *
388 * @param hDbgAs The address space handle.
389 * @param Addr The address which closest symbol is requested.
390 * @param poffDisp Where to return the distance between the symbol
391 * and address. Optional.
392 * @param ppSymbol Where to return the pointer to the allocated
393 * symbol info. Always set. Free with RTDbgSymbolFree.
394 */
395RTDECL(int) RTDbgAsSymbolByAddrA(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymbol);
396
397/**
398 * Query a symbol by name.
399 *
400 * @returns IPRT status code.
401 * @retval VERR_SYMBOL_NOT_FOUND if not found.
402 *
403 * @param hDbgAs The address space handle.
404 * @param pszSymbol The symbol name.
405 * @param pSymbol Where to return the symbol info.
406 */
407RTDECL(int) RTDbgAsSymbolByName(RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL pSymbol);
408
409/**
410 * Query a symbol by name.
411 *
412 * @returns IPRT status code.
413 * @retval VERR_SYMBOL_NOT_FOUND if not found.
414 *
415 * @param hDbgAs The address space handle.
416 * @param pszSymbol The symbol name.
417 * @param ppSymbol Where to return the pointer to the allocated
418 * symbol info. Always set. Free with RTDbgSymbolFree.
419 */
420RTDECL(int) RTDbgAsSymbolByNameA(RTDBGAS hDbgAs, const char *pszSymbol, PRTDBGSYMBOL *ppSymbol);
421
422/**
423 * Query a line number by address.
424 *
425 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
426 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
427 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
428 *
429 * @param hDbgAs The address space handle.
430 * @param Addr The address which closest symbol is requested.
431 * @param poffDisp Where to return the distance between the line
432 * number and address.
433 * @param pLine Where to return the line number information.
434 */
435RTDECL(int) RTDbgAs(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE pLine);
436
437/**
438 * Query a line number by address.
439 *
440 * @returns IPRT status code. See RTDbgModSymbolAddrA for more specific ones.
441 * @retval VERR_INVALID_HANDLE if hDbgAs is invalid.
442 * @retval VERR_NOT_FOUND if the address couldn't be mapped to a module.
443 *
444 * @param hDbgAs The address space handle.
445 * @param Addr The address which closest symbol is requested.
446 * @param poffDisp Where to return the distance between the line
447 * number and address.
448 * @param ppLine Where to return the pointer to the allocated line
449 * number info. Always set. Free with RTDbgLineFree.
450 */
451RTDECL(int) RTDbgAsLineByAddrA(RTDBGAS hDbgAs, RTUINTPTR Addr, PRTINTPTR poffDisp, PRTDBGLINE *ppLine);
452
453/** @todo Missing some bits here. */
454
455/** @} */
456
457
458/** @defgroup grp_rt_dbgmod RTDbgMod - Debug Module Interpreter
459 * @{
460 */
461RTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cb, uint32_t fFlags);
462RTDECL(int) RTDbgModCreateDeferred(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR cb, uint32_t fFlags);
463RTDECL(int) RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, uint32_t fFlags);
464RTDECL(int) RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTUINTPTR uSubtrahend, uint32_t fFlags);
465RTDECL(uint32_t) RTDbgModRetain(RTDBGMOD hDbgMod);
466RTDECL(uint32_t) RTDbgModRelease(RTDBGMOD hDbgMod);
467RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod);
468RTDECL(RTUINTPTR) RTDbgModImageSize(RTDBGMOD hDbgMod);
469RTDECL(RTUINTPTR) RTDbgModSegmentSize(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg);
470RTDECL(RTDBGSEGIDX) RTDbgModSegmentCount(RTDBGMOD hDbgMod);
471
472RTDECL(int) RTDbgModSymbolAdd(RTDBGMOD hDbgMod, const char *pszSymbol, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t cb);
473RTDECL(uint32_t) RTDbgModSymbolCount(RTDBGMOD hDbgMod);
474RTDECL(int) RTDbgModSymbolByIndex(RTDBGMOD hDbgMod, uint32_t iSymbol, PRTDBGSYMBOL pSymbol);
475RTDECL(int) RTDbgModSymbolByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGSYMBOL pSymbol);
476RTDECL(int) RTDbgModSymbolByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymbol);
477RTDECL(int) RTDbgModSymbolByName(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL pSymbol);
478RTDECL(int) RTDbgModSymbolByNameA(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL *ppSymbol);
479
480RTDECL(int) RTDbgModLineByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLine);
481RTDECL(int) RTDbgModLineByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE *ppLine);
482/** @} */
483
484/** @} */
485
486RT_C_DECLS_END
487
488#endif
489
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