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

Last change on this file since 3551 was 3550, checked in by bird, 18 years ago

made kDbg compile again (not linking yet though).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1/* $Id: kDbg.h 3550 2007-08-26 01:13:35Z 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 ___k_kDbg_h___
26#define ___k_kDbg_h___
27
28#include <k/kDefs.h>
29#include <k/kTypes.h>
30#include <k/kRdr.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/** @defgroup grp_kDbg Debug Info Reader
37 * @{
38 */
39
40/** @def KDBG_DECL
41 * Declares a kDbg function according to build context.
42 * @param type The return type.
43 */
44#if defined(KDBG_BUILDING_DYNAMIC)
45# define KDBG_DECL(type) K_DECL_EXPORT(type)
46#elif defined(KDBG_BUILT_DYNAMIC)
47# define KDBG_DECL(type) K_DECL_IMPORT(type)
48#else
49# define KDBG_DECL(type) type
50#endif
51
52
53/** The kDbg address type. */
54typedef KU64 KDBGADDR;
55/** Pointer to a kDbg address. */
56typedef KDBGADDR *PKDBGADDR;
57/** Pointer to a const kDbg address. */
58typedef const KDBGADDR *PCKDBGADDR;
59/** @def KDBGADDR_PRI
60 * printf format type. */
61#define KDBGADDR_PRI KX64_PRI
62/** @def KDBGADDR_MAX
63 * Max kDbg address value. */
64#define KDBGADDR_MAX KU64_C(0xfffffffffffffffe)
65/** @def KDBGADDR_C
66 * kDbg address constant.
67 * @param c The constant value. */
68#define KDBGADDR_C(c) KU64_C(c)
69/** NIL address. */
70#define NIL_KDBGADDR KU64_MAX
71
72
73/** @name Special Segments
74 * @{ */
75/** Relative Virtual Address.
76 * The specified offset is relative to the image base. The image base is the lowest memory
77 * address used by the image when loaded with the address assignments indicated in the image. */
78#define KDBGSEG_RVA (-1)
79/** Absolute segment. The offset isn't relative to anything. */
80#define KDBGSEG_ABS (-2)
81/** @} */
82
83
84/** The max filename path length used by the debug reader. */
85#define KDBG_PATH_MAX 260
86
87/**
88 * Line number details.
89 */
90typedef struct KDBGLINE
91{
92 /** The relative virtual address. */
93 KDBGADDR RVA;
94 /** The offset into the segment. */
95 KDBGADDR offSegment;
96 /** The segment number. */
97 KI32 iSegment;
98 /** The Line number. */
99 KU32 iLine;
100 /** The actual size of this structure. */
101 KU16 cbSelf;
102 /** The length of the filename. */
103 KU16 cchFile;
104 /** The name of the file this line number relates to. */
105 char szFile[KDBG_PATH_MAX];
106} KDBGLINE;
107/** Pointer to line number details. */
108typedef KDBGLINE *PKDBGLINE;
109/** Pointer to const line number details. */
110typedef const KDBGLINE *PCKDBGLINE;
111/** Pointer to a pointer to line number details. */
112typedef PKDBGLINE *PPKDBGLINE;
113
114/**
115 * Duplicates a line number.
116 *
117 * To save heap space, the returned line number will not own more heap space
118 * than it strictly need to. So, it's not possible to append stuff to the symbol
119 * or anything of that kind.
120 *
121 * @returns Pointer to the duplicate.
122 * This must be freed using RTDbgSymbolFree().
123 * @param pLine The line number to be duplicated.
124 */
125KDBG_DECL(PKDBGLINE) kDbgLineDup(PCKDBGLINE pLine);
126
127/**
128 * Frees a line number obtained from the RTDbg API.
129 *
130 * @returns VINF_SUCCESS on success.
131 * @returns KERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in.
132 *
133 * @param pLine The line number to be freed.
134 */
135KDBG_DECL(int) kDbgLineFree(PKDBGLINE pLine);
136
137
138/** @name Symbol Flags.
139 * @{ */
140/** The symbol is weak. */
141#define KDBGSYM_FLAGS_WEAK KU32_C(0x00000000)
142/** The symbol is absolute.
143 * (This also indicated by the segment number.) */
144#define KDBGSYM_FLAGS_ABS KU32_C(0x00000001)
145/** The symbol is exported. */
146#define KDBGSYM_FLAGS_EXPORTED KU32_C(0x00000002)
147/** The symbol is a function/method/procedure/whatever-executable-code. */
148#define KDBGSYM_FLAGS_CODE KU32_C(0x00000004)
149/** The symbol is some kind of data. */
150#define KDBGSYM_FLAGS_DATA KU32_C(0x00000008)
151/** @} */
152
153/** The max symbol name length used by the debug reader. */
154#define KDBG_SYMBOL_MAX 384
155
156/**
157 * Symbol details.
158 */
159typedef struct KDBGSYMBOL
160{
161 /** The relative virtual address. */
162 KDBGADDR RVA;
163 /** The symbol size.
164 * This is not a reliable field, it could be a bad guess. Ignore if zero. */
165 KDBGADDR cb;
166 /** The offset into the segment. */
167 KDBGADDR offSegment;
168 /** The segment number. */
169 KI32 iSegment;
170 /** The symbol flags. */
171 KU32 fFlags;
172/** @todo type info? */
173 /** The actual size of this structure. */
174 KU16 cbSelf;
175 /** The length of the symbol name. */
176 KU16 cchName;
177 /** The symbol name. */
178 char szName[KDBG_SYMBOL_MAX];
179} KDBGSYMBOL;
180/** Pointer to symbol details. */
181typedef KDBGSYMBOL *PKDBGSYMBOL;
182/** Pointer to const symbol details. */
183typedef const KDBGSYMBOL *PCKDBGSYMBOL;
184/** Pointer to a pointer to symbol details. */
185typedef PKDBGSYMBOL *PPKDBGSYMBOL;
186
187/**
188 * Duplicates a symbol.
189 *
190 * To save heap space, the returned symbol will not own more heap space than
191 * it strictly need to. So, it's not possible to append stuff to the symbol
192 * or anything of that kind.
193 *
194 * @returns Pointer to the duplicate.
195 * This must be freed using kDbgSymbolFree().
196 * @param pSymbol The symbol to be freed.
197 */
198KDBG_DECL(PKDBGSYMBOL) kDbgSymbolDup(PCKDBGSYMBOL pSymbol);
199
200/**
201 * Frees a symbol obtained from the kDbg API.
202 *
203 * @returns VINF_SUCCESS on success.
204 * @returns KERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in.
205 *
206 * @param pSymbol The symbol to be freed.
207 */
208KDBG_DECL(int) kDbgSymbolFree(PKDBGSYMBOL pSymbol);
209
210
211/** Pointer to a debug module. */
212typedef struct KDBGMOD *PKDBGMOD;
213/** Pointer to a debug module pointer. */
214typedef PKDBGMOD *PPKDBGMOD;
215
216
217KDBG_DECL(int) kDbgModuleOpen(PPKDBGMOD ppDbgMod, const char *pszFilename, struct KLDRMOD *pLdrMod);
218KDBG_DECL(int) kDbgModuleOpenFile(PPKDBGMOD ppDbgMod, PKRDR pRdr, struct KLDRMOD *pLdrMod);
219KDBG_DECL(int) kDbgModuleOpenFilePart(PPKDBGMOD ppDbgMod, PKRDR pRdr, KFOFF off, KFOFF cb, struct KLDRMOD *pLdrMod);
220KDBG_DECL(int) kDbgModuleClose(PKDBGMOD pMod);
221KDBG_DECL(int) kDbgModuleQuerySymbol(PKDBGMOD pMod, KI32 iSegment, KDBGADDR off, PKDBGSYMBOL pSym);
222KDBG_DECL(int) kDbgModuleQuerySymbolA(PKDBGMOD pMod, KI32 iSegment, KDBGADDR off, PPKDBGSYMBOL ppSym);
223KDBG_DECL(int) kDbgModuleQueryLine(PKDBGMOD pMod, KI32 iSegment, KDBGADDR off, PKDBGLINE pLine);
224KDBG_DECL(int) kDbgModuleQueryLineA(PKDBGMOD pMod, KI32 iSegment, KDBGADDR off, PPKDBGLINE ppLine);
225
226
227/** @} */
228
229#ifdef __cplusplus
230}
231#endif
232
233#endif
Note: See TracBrowser for help on using the repository browser.