source: trunk/kStuff/include/k/kDbg.h@ 3548

Last change on this file since 3548 was 3541, checked in by bird, 18 years ago

errors and stuff.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.1 KB
Line 
1/* $Id: kDbg.h 3541 2007-08-25 03:46:14Z bird $ */
2/** @file
3 * kDbg - The Debug Info Reader.
4 */
5
6/*
7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with This program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#ifndef ___kDbg_h___
26#define ___kDbg_h___
27
28#include "kDbgBase.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/** @defgroup grp_kDbg Debug Info Reader
35 * @{
36 */
37
38/** The max filename path length used by the debug reader. */
39#define KDBG_PATH_MAX 260
40
41/** The max symbol name length used by the debug reader. */
42#define KDBG_SYMBOL_MAX 384
43
44/** @name Special Segments
45 * @{ */
46/** Relative Virtual Address.
47 * The specified offset is relative to the image base. The image base is the lowest memory
48 * address used by the image when loaded with the address assignments indicated in the image. */
49#define KDBGSEG_RVA (-1)
50/** Absolute segment. The offset isn't relative to anything. */
51#define KDBGSEG_ABS (-2)
52/** @} */
53
54
55/**
56 * Line number details.
57 */
58typedef struct KDBGLINE
59{
60 /** The relative virtual address. */
61 KDBGADDR RVA;
62 /** The offset into the segment. */
63 KDBGADDR offSegment;
64 /** The segment number. */
65 int32_t iSegment;
66 /** The Line number. */
67 uint32_t iLine;
68 /** The length of the filename. */
69 uint16_t cchFile;
70 /** The name of the file this line number relates to. */
71 char szFile[KDBG_PATH_MAX];
72} KDBGLINE;
73/** Pointer to line number details. */
74typedef KDBGLINE *PKDBGLINE;
75/** Pointer to const line number details. */
76typedef const KDBGLINE *PCKDBGLINE;
77/** Pointer to a pointer to line number details. */
78typedef PKDBGLINE *PPKDBGLINE;
79
80/**
81 * Duplicates a line number.
82 *
83 * To save heap space, the returned line number will not own more heap space
84 * than it strictly need to. So, it's not possible to append stuff to the symbol
85 * or anything of that kind.
86 *
87 * @returns Pointer to the duplicate.
88 * This must be freed using RTDbgSymbolFree().
89 * @param pLine The line number to be duplicated.
90 */
91KDBG_DECL(PKDBGLINE) kDbgLineDup(PCKDBGLINE pLine);
92
93/**
94 * Frees a line number obtained from the RTDbg API.
95 *
96 * @returns VINF_SUCCESS on success.
97 * @returns KERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in.
98 *
99 * @param pLine The line number to be freed.
100 */
101KDBG_DECL(int) kDbgLineFree(PKDBGLINE pLine);
102
103
104/** @name Symbol Flags.
105 * @{ */
106/** The symbol is weak. */
107#define KDBGSYM_FLAGS_WEAK UINT32_C(0x00000000)
108/** The symbol is absolute.
109 * (This also indicated by the segment number.) */
110#define KDBGSYM_FLAGS_ABS UINT32_C(0x00000001)
111/** The symbol is exported. */
112#define KDBGSYM_FLAGS_EXPORTED UINT32_C(0x00000002)
113/** The symbol is a function/method/procedure/whatever-executable-code. */
114#define KDBGSYM_FLAGS_CODE UINT32_C(0x00000004)
115/** The symbol is some kind of data. */
116#define KDBGSYM_FLAGS_DATA UINT32_C(0x00000008)
117/** @} */
118
119/**
120 * Symbol details.
121 */
122typedef struct KDBGSYMBOL
123{
124 /** The relative virtual address. */
125 KDBGADDR RVA;
126 /** The symbol size.
127 * This is not a reliable field, it could be a bad guess. Ignore if zero. */
128 KDBGADDR cb;
129 /** The offset into the segment. */
130 KDBGADDR offSegment;
131 /** The segment number. */
132 int32_t iSegment;
133 /** The symbol flags. */
134 uint32_t fFlags;
135/** @todo type info? */
136 /** The length of the symbol name. */
137 uint16_t cchName;
138 /** The symbol name. */
139 char szName[KDBG_SYMBOL_MAX];
140} KDBGSYMBOL;
141/** Pointer to symbol details. */
142typedef KDBGSYMBOL *PKDBGSYMBOL;
143/** Pointer to const symbol details. */
144typedef const KDBGSYMBOL *PCKDBGSYMBOL;
145/** Pointer to a pointer to symbol details. */
146typedef PKDBGSYMBOL *PPKDBGSYMBOL;
147
148/**
149 * Duplicates a symbol.
150 *
151 * To save heap space, the returned symbol will not own more heap space than
152 * it strictly need to. So, it's not possible to append stuff to the symbol
153 * or anything of that kind.
154 *
155 * @returns Pointer to the duplicate.
156 * This must be freed using kDbgSymbolFree().
157 * @param pSymbol The symbol to be freed.
158 */
159KDBG_DECL(PKDBGSYMBOL) kDbgSymbolDup(PCKDBGSYMBOL pSymbol);
160
161/**
162 * Frees a symbol obtained from the kDbg API.
163 *
164 * @returns VINF_SUCCESS on success.
165 * @returns KERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in.
166 *
167 * @param pSymbol The symbol to be freed.
168 */
169KDBG_DECL(int) kDbgSymbolFree(PKDBGSYMBOL pSymbol);
170
171
172/** Pointer to a kDbgHlp file structure (abstract). */
173typedef struct KDBGHLPFILE *PKDBGHLPFILE;
174
175/** A debug module handle. */
176typedef struct KDBGMOD *PKDBGMOD;
177
178/**
179 * The debug module method table.
180 */
181typedef struct KDBGMODOPS
182{
183 /** The name of the reader. */
184 const char *pszName;
185
186 /** Pointer to the next debug module readers.
187 * This is only used for dynamically registered readers. */
188 struct KDBGMODOPS *pNext;
189
190 /**
191 * Tries to open the module.
192 *
193 * @returns 0 on success, KDBG_ERR on failure.
194 * @param pFile The file
195 * @param ppMod Where to store the module that's been opened.
196 * @param off The file offset of the debug info. This is 0 if there isn't
197 * any specfic debug info section and the reader should start
198 * looking for debug info at the start of the file.
199 * @param cb The size of the debug info in the file. INT64_MAX if we don't
200 * know or there isn't any particular debug info section in the file.
201 * @param pLdrMod The associated loader module. This can be NULL.
202 *
203 * @remark This is NULL for the builtin readers.
204 */
205 int (*pfnOpen)(PKDBGMOD *ppMod, PKDBGHLPFILE pFile, KFOFF off, KFOFF cb, struct KLDRMOD *pLdrMod);
206
207 /**
208 * Closes the module.
209 *
210 * This should free all resources associated with the module
211 * except the pMod which is freed by the caller.
212 *
213 * @returns IPRT status code.
214 * @param pMod The module.
215 */
216 int (*pfnClose)(PKDBGMOD pMod);
217
218 /**
219 * Gets a symbol by segment:offset.
220 * This will be approximated to the nearest symbol if there is no exact match.
221 *
222 * @returns 0 on success. KLDR_ERR_* on failure.
223 * @param pMod The module.
224 * @param iSegment The segment this offset is relative to.
225 * The -1 segment is special, it means that the addres is relative to
226 * the image base. The image base is where the first bit of the image
227 * is mapped during load.
228 * @param off The offset into the segment.
229 * @param pSym Where to store the symbol details.
230 */
231 int (*pfnQuerySymbol)(PKDBGMOD pMod, KI32 iSegment, KDBGADDR off, PKDBGSYMBOL pSym);
232
233 /**
234 * Gets a line number entry by segment:offset.
235 * This will be approximated to the nearest line number there is no exact match.
236 *
237 * @returns 0 on success. KLDR_ERR_* on failure.
238 * @param pMod The module.
239 * @param iSegment The segment this offset is relative to.
240 * The -1 segment is special, it means that the addres is relative to
241 * the image base. The image base is where the first bit of the image
242 * is mapped during load.
243 * @param off The offset into the segment.
244 * @param pLine Where to store the line number details.
245 */
246 int (*pfnQueryLine)(PKDBGMOD pMod, KI32 iSegment, KDBGADDR uOffset, PKDBGLINE pLine);
247
248 /** This is just to make sure you've initialized all the fields.
249 * Must be identical to pszName. */
250 const char *pszName2;
251} KDBGMODOPS;
252/** Pointer to a module method table. */
253typedef KDBGMODOPS *PKDBGMODOPS;
254/** Pointer to a const module method table. */
255typedef const KDBGMODOPS *PCKDBGMODOPS;
256
257/**
258 * Register a debug module reader with the kDbgModule component.
259 *
260 * Dynamically registered readers are kept in FIFO order, and external
261 * readers will be tried after the builtin ones.
262 *
263 * @returns 0 on success.
264 * @returns KERR_INVALID_POINTER if pOps is missing bits.
265 * @returns KERR_INVALID_PARAMETER if pOps is already in the list.
266 * @param pOps The reader method table, kDbg takes owner ship of
267 * this. This must be writeable as the pNext pointer
268 * will be update. It must also stick around for as
269 * long as kDbg is in use.
270 */
271KDBG_DECL(int) kDbgModuleRegisterReader(PKDBGMODOPS pOps)
272;
273
274
275
276/**
277 * Internal representation of a debug module.
278 */
279typedef struct KDBGMOD
280{
281 /** Magic value (KDBGMOD_MAGIC). */
282 KI32 u32Magic;
283 /** The handle to the module. (If closed, this is NIL_RTFILE.) */
284 PKDBGHLPFILE pFile;
285 /** Pointer to the method table. */
286 PCKDBGMODOPS pOps;
287} KDBGMOD;
288
289
290/** The magic value for the debug module structure. (Some dead english writer) */
291#define KDBGMOD_MAGIC 0x19200501
292/** The magic value of a dead module structure. */
293#define KDBGMOD_MAGIC_DEAD 0x19991231
294
295
296/**
297 * Opens the debug info for a specified executable module.
298 *
299 * @returns IPRT status code.
300 * @param pszModulePath The path to the executable module.
301 * @param ppDbgMod Where to store the debug module handle.
302 */
303KDBG_DECL(int) kDbgModuleOpen(const char *pszModulePath, PKDBGMOD *ppDbgMod);
304
305/**
306 * Closes the module.
307 *
308 * @returns IPRT status code.
309 * @param pMod The module handle.
310 */
311KDBG_DECL(int) kDbgModuleClose(PKDBGMOD pMod);
312
313/**
314 * Gets a symbol by segment:offset.
315 * This will be approximated to the nearest symbol if there is no exact match.
316 *
317 * @returns IPRT status code.
318 * @param pMod The module.
319 * @param iSegment The segment this offset is relative to.
320 * The -1 segment is special, it means that the addres is relative to
321 * the image base. The image base is where the first bit of the image
322 * is mapped during load.
323 * @param off The offset into the segment.
324 * @param pSym Where to store the symbol details.
325 */
326KDBG_DECL(int) kDbgModuleQuerySymbol(PKDBGMOD pMod, KI32 iSegment, KDBGADDR off, PKDBGSYMBOL pSym);
327
328/**
329 * Gets & allocates a symbol by segment:offset.
330 * This will be approximated to the nearest symbol if there is no exact match.
331 *
332 * @returns IPRT status code.
333 * @param pMod The module.
334 * @param iSegment The segment this offset is relative to.
335 * The -1 segment is special, it means that the addres is relative to
336 * the image base. The image base is where the first bit of the image
337 * is mapped during load.
338 * @param off The offset into the segment.
339 * @param ppSym Where to store the pointer to the symbol info.
340 * Free the returned symbol using kDbgSymbolFree().
341 */
342KDBG_DECL(int) kDbgModuleQuerySymbolA(PKDBGMOD pMod, KI32 iSegment, KDBGADDR off, PPKDBGSYMBOL ppSym);
343
344/**
345 * Gets a line number entry by segment:offset.
346 * This will be approximated to the nearest line number there is no exact match.
347 *
348 * @returns IPRT status code.
349 * @param pMod The module.
350 * @param iSegment The segment this offset is relative to.
351 * The -1 segment is special, it means that the addres is relative to
352 * the image base. The image base is where the first bit of the image
353 * is mapped during load.
354 * @param off The offset into the segment.
355 * @param pLine Where to store the line number details.
356 */
357KDBG_DECL(int) kDbgModuleQueryLine(PKDBGMOD pMod, KI32 iSegment, KDBGADDR off, PKDBGLINE pLine);
358
359/**
360 * Gets & allocates a line number entry by segment:offset.
361 * This will be approximated to the nearest line number there is no exact match.
362 *
363 * @returns IPRT status code.
364 * @param pMod The module.
365 * @param iSegment The segment this offset is relative to.
366 * The -1 segment is special, it means that the addres is relative to
367 * the image base. The image base is where the first bit of the image
368 * is mapped during load.
369 * @param off The offset into the segment.
370 * @param ppLine Where to store the pointer to the line number info.
371 * Free the returned line number using kDbgLineFree().
372 */
373KDBG_DECL(int) kDbgModuleQueryLineA(PKDBGMOD pMod, KI32 iSegment, KDBGADDR off, PPKDBGLINE ppLine);
374
375
376/** @} */
377
378#ifdef __cplusplus
379}
380#endif
381
382#endif
Note: See TracBrowser for help on using the repository browser.