source: trunk/kProfile/dbg.h@ 3526

Last change on this file since 3526 was 3524, checked in by bird, 18 years ago

kProfile Mark II. Some early/old code.

File size: 8.7 KB
Line 
1/* $Id: $ */
2/** @file
3 *
4 * kProfile Mark 2 - Debug Info Reader.
5 *
6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net.de>
7 *
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
26#ifndef __iprt_dbg_h__
27#define __iprt_dbg_h__
28
29#include <iprt/types.h>
30
31__BEGIN_DECLS
32
33/** @defgroup grp_rt_dbg Debug Info Reader
34 * @addtogroup grp_rt
35 * @{
36 */
37
38/** The max filename path length used by the debug reader. */
39#define RTDBG_PATH_MAX 260
40
41/** The max symbol name length used by the debug reader. */
42#define RTDBG_SYMBOL_MAX 384
43
44
45/** @name Special Segments
46 * @{ */
47/** Relative Virtual Address.
48 * The specified offset is relative to the image base. The image base is the lowest memory
49 * address used by the image when loaded with the address assignments indicated in the image. */
50#define RTDBGSEG_RVA (-1)
51/** Absolute segment. The offset isn't relative to anything. */
52#define RTDBGSEG_ABS (-2)
53/** @} */
54
55
56/**
57 * Line number details.
58 */
59typedef struct RTDBGLINE
60{
61 /** The relative virtual address. */
62 RTUINTPTR RVA;
63 /** The offset into the segment. */
64 RTUINTPTR offSegment;
65 /** The segment number. */
66 int32_t iSegment;
67 /** The Line number. */
68 uint32_t iLine;
69 /** The length of the filename. */
70 uint16_t cchFile;
71 /** The name of the file this line number relates to. */
72 char szFile[RTDBG_PATH_MAX];
73} RTDBGLINE;
74/** Pointer to line number details. */
75typedef RTDBGLINE *PRTDBGLINE;
76/** Pointer to const line number details. */
77typedef const RTDBGLINE *PCRTDBGLINE;
78/** Pointer to a pointer to line number details. */
79typedef PRTDBGLINE *PPRTDBGLINE;
80
81/**
82 * Duplicates a line number.
83 *
84 * To save heap space, the returned line number will not own more heap space
85 * than it strictly need to. So, it's not possible to append stuff to the symbol
86 * or anything of that kind.
87 *
88 * @returns Pointer to the duplicate.
89 * This must be freed using RTDbgSymbolFree().
90 * @param pLine The line number to be duplicated.
91 */
92RTDECL(PRTDBGLINE) RTDbgLineDup(PCRTDBGLINE pLine);
93
94/**
95 * Frees a line number obtained from the RTDbg API.
96 *
97 * @returns VINF_SUCCESS on success.
98 * @returns VERR_INVALID_POINTER if a NULL pointer or an !VALID_PTR() is passed in.
99 *
100 * @param pLine The line number to be freed.
101 */
102RTDECL(int) RTDbgLineFree(PRTDBGLINE pLine);
103
104
105/** @name Symbol Flags.
106 * @{ */
107/** The symbol is weak. */
108#define RTDBGSYM_FLAGS_WEAK BIT(0)
109/** The symbol is absolute.
110 * (This also indicated by the segment number.) */
111#define RTDBGSYM_FLAGS_ABS BIT(1)
112/** The symbol is exported. */
113#define RTDBGSYM_FLAGS_EXPORTED BIT(2)
114/** The symbol is a function/method/procedure/whatever-executable-code. */
115#define RTDBGSYM_FLAGS_CODE BIT(3)
116/** The symbol is some kind of data. */
117#define RTDBGSYM_FLAGS_DATA BIT(4)
118/** @} */
119
120/**
121 * Symbol details.
122 */
123typedef struct RTDBGSYMBOL
124{
125 /** The relative virtual address. */
126 RTUINTPTR RVA;
127 /** The symbol size.
128 * This is not a reliable field, it could be a bad guess. Ignore if zero. */
129 RTUINTPTR cb;
130 /** The offset into the segment. */
131 RTUINTPTR offSegment;
132 /** The segment number. */
133 int32_t iSegment;
134 /** The symbol flags. */
135 uint32_t fFlags;
136/** @todo type info? */
137 /** The length of the symbol name. */
138 uint16_t cchName;
139 /** The symbol name. */
140 char szName[RTDBG_SYMBOL_MAX];
141} RTDBGSYMBOL;
142/** Pointer to symbol details. */
143typedef RTDBGSYMBOL *PRTDBGSYMBOL;
144/** Pointer to const symbol details. */
145typedef const RTDBGSYMBOL *PCRTDBGSYMBOL;
146/** Pointer to a pointer to symbol details. */
147typedef PRTDBGSYMBOL *PPRTDBGSYMBOL;
148
149
150/**
151 * Duplicates a symbol.
152 *
153 * To save heap space, the returned symbol will not own more heap space than
154 * it strictly need to. So, it's not possible to append stuff to the symbol
155 * or anything of that kind.
156 *
157 * @returns Pointer to the duplicate.
158 * This must be freed using RTDbgSymbolFree().
159 * @param pSymbol The symbol to be freed.
160 */
161RTDECL(PRTDBGSYMBOL) RTDbgSymbolDup(PCRTDBGSYMBOL pSymbol);
162
163/**
164 * Frees a symbol obtained from the RTDbg API.
165 *
166 * @returns VINF_SUCCESS on success.
167 * @returns VERR_INVALID_POINTER if a NULL pointer or an !VALID_PTR() is passed in.
168 *
169 * @param pSymbol The symbol to be freed.
170 */
171RTDECL(int) RTDbgSymbolFree(PRTDBGSYMBOL pSymbol);
172
173
174
175/** A debug module handle. */
176typedef struct RTDBGMOD *PRTDBGMOD;
177
178/**
179 * Opens the debug info for a specified executable module.
180 *
181 * @returns IPRT status code.
182 * @param pszModulePath The path to the executable module.
183 * @param ppDbgMod Where to store the debug module handle.
184 */
185RTDECL(int) RTDbgModuleOpen(const char *pszModulePath, PRTDBGMOD *ppDbgMod);
186
187/**
188 * Closes the module.
189 *
190 * @returns IPRT status code.
191 * @param pMod The module handle.
192 */
193RTDECL(int) RTDbgModuleClose(PRTDBGMOD pMod);
194
195/**
196 * Gets a symbol by segment:offset.
197 * This will be approximated to the nearest symbol if there is no exact match.
198 *
199 * @returns IPRT status code.
200 * @param pMod The module.
201 * @param iSegment The segment this offset is relative to.
202 * The -1 segment is special, it means that the addres is relative to
203 * the image base. The image base is where the first bit of the image
204 * is mapped during load.
205 * @param off The offset into the segment.
206 * @param pSym Where to store the symbol details.
207 */
208RTDECL(int) RTDbgModuleQuerySymbol(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGSYMBOL pSym);
209
210/**
211 * Gets & allocates a symbol by segment:offset.
212 * This will be approximated to the nearest symbol if there is no exact match.
213 *
214 * @returns IPRT status code.
215 * @param pMod The module.
216 * @param iSegment The segment this offset is relative to.
217 * The -1 segment is special, it means that the addres is relative to
218 * the image base. The image base is where the first bit of the image
219 * is mapped during load.
220 * @param off The offset into the segment.
221 * @param ppSym Where to store the pointer to the symbol info.
222 * Free the returned symbol using RTDbgSymbolFree().
223 */
224RTDECL(int) RTDbgModuleQuerySymbolA(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PPRTDBGSYMBOL ppSym);
225
226/**
227 * Gets a line number entry by segment:offset.
228 * This will be approximated to the nearest line number there is no exact match.
229 *
230 * @returns IPRT status code.
231 * @param pMod The module.
232 * @param iSegment The segment this offset is relative to.
233 * The -1 segment is special, it means that the addres is relative to
234 * the image base. The image base is where the first bit of the image
235 * is mapped during load.
236 * @param off The offset into the segment.
237 * @param pLine Where to store the line number details.
238 */
239RTDECL(int) RTDbgModuleQueryLine(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGLINE pLine);
240
241/**
242 * Gets & allocates a line number entry by segment:offset.
243 * This will be approximated to the nearest line number there is no exact match.
244 *
245 * @returns IPRT status code.
246 * @param pMod The module.
247 * @param iSegment The segment this offset is relative to.
248 * The -1 segment is special, it means that the addres is relative to
249 * the image base. The image base is where the first bit of the image
250 * is mapped during load.
251 * @param off The offset into the segment.
252 * @param ppLine Where to store the pointer to the line number info.
253 * Free the returned line number using RTDbgLineFree().
254 */
255RTDECL(int) RTDbgModuleQueryLineA(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PPRTDBGLINE ppLine);
256
257
258__END_DECLS
259
260/** @} */
261
262#endif
Note: See TracBrowser for help on using the repository browser.