| [3528] | 1 | /* $Id: kDbg.h 3530 2007-08-20 03:42:03Z 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
 | 
|---|
 | 31 | extern "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   kDbg Status codes
 | 
|---|
 | 45 |  * (Success is indicated by the value 0.)
 | 
|---|
 | 46 |  * @{ */
 | 
|---|
 | 47 | #define KDBG_ERR_BASE                                   430000
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | /** An API was given an invalid parameter. */
 | 
|---|
 | 50 | #define KDBG_ERR_INVALID_PARAMETER                      (KDBG_ERR_BASE + 0)
 | 
|---|
 | 51 | /** A pointer argument is not valid. */
 | 
|---|
 | 52 | #define KDBG_ERR_INVALID_POINTER                        (KDBG_ERR_BASE + 1)
 | 
|---|
 | 53 | /** A handle argument is not valid. */
 | 
|---|
 | 54 | #define KDBG_ERR_INVALID_HANDLE                         (KDBG_ERR_BASE + 2)
 | 
|---|
 | 55 | /** A parameter is out of range. */
 | 
|---|
 | 56 | #define KDBG_ERR_OUT_OF_RANGE                           (KDBG_ERR_BASE + 3)
 | 
|---|
 | 57 | /** Out of memory. */
 | 
|---|
 | 58 | #define KDBG_ERR_NO_MEMORY                              (KDBG_ERR_BASE + 4)
 | 
|---|
 | 59 | /** The specified file was not found. */
 | 
|---|
 | 60 | #define KDBG_ERR_FILE_NOT_FOUND                         (KDBG_ERR_BASE + 5)
 | 
|---|
| [3530] | 61 | /** Hit some unimplemented functionality - feel free to implement it :-) . */
 | 
|---|
 | 62 | #define KDBG_ERR_NOT_IMPLEMENTED                        (KDBG_ERR_BASE + 6)
 | 
|---|
| [3528] | 63 | /** Generic error. */
 | 
|---|
 | 64 | #define KDBG_ERR_GENERAL_FAILURE                        (KDBG_ERR_BASE + 9)
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | /** The (module) format isn't known to use. */
 | 
|---|
 | 67 | #define KDBG_ERR_UNKOWN_FORMAT                          (KDBG_ERR_BASE + 10)
 | 
|---|
 | 68 | /** The (module) format isn't supported by this kDbg build. */
 | 
|---|
 | 69 | #define KDBG_ERR_FORMAT_NOT_SUPPORTED                   (KDBG_ERR_BASE + 11)
 | 
|---|
 | 70 | /** A specified address or an address found in the debug info is invalid. */
 | 
|---|
 | 71 | #define KDBG_ERR_INVALID_ADDRESS                        (KDBG_ERR_BASE + 12)
 | 
|---|
| [3529] | 72 | /** The dbghelp.dll is too old or something like that. */
 | 
|---|
 | 73 | #define KDBG_ERR_DBGHLP_VERSION_MISMATCH                (KDBG_ERR_BASE + 13)
 | 
|---|
 | 74 | /** Invalid executable format. */
 | 
|---|
 | 75 | #define KDBG_ERR_BAD_EXE_FORMAT                         (KDBG_ERR_BASE + 14)
 | 
|---|
| [3528] | 76 | 
 | 
|---|
 | 77 | /** @} */
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 | 
 | 
|---|
 | 80 | /** @name   Special Segments
 | 
|---|
 | 81 |  * @{ */
 | 
|---|
 | 82 | /** Relative Virtual Address.
 | 
|---|
 | 83 |  * The specified offset is relative to the image base. The image base is the lowest memory
 | 
|---|
 | 84 |  * address used by the image when loaded with the address assignments indicated in the image. */
 | 
|---|
 | 85 | #define KDBGSEG_RVA (-1)
 | 
|---|
 | 86 | /** Absolute segment. The offset isn't relative to anything. */
 | 
|---|
 | 87 | #define KDBGSEG_ABS (-2)
 | 
|---|
 | 88 | /** @} */
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 | /**
 | 
|---|
 | 92 |  * Line number details.
 | 
|---|
 | 93 |  */
 | 
|---|
 | 94 | typedef struct KDBGLINE
 | 
|---|
 | 95 | {
 | 
|---|
 | 96 |     /** The relative virtual address. */
 | 
|---|
 | 97 |     KDBGADDR    RVA;
 | 
|---|
 | 98 |     /** The offset into the segment. */
 | 
|---|
 | 99 |     KDBGADDR    offSegment;
 | 
|---|
 | 100 |     /** The segment number. */
 | 
|---|
 | 101 |     int32_t     iSegment;
 | 
|---|
 | 102 |     /** The Line number. */
 | 
|---|
 | 103 |     uint32_t    iLine;
 | 
|---|
 | 104 |     /** The length of the filename. */
 | 
|---|
 | 105 |     uint16_t    cchFile;
 | 
|---|
 | 106 |     /** The name of the file this line number relates to. */
 | 
|---|
 | 107 |     char        szFile[KDBG_PATH_MAX];
 | 
|---|
 | 108 | } KDBGLINE;
 | 
|---|
 | 109 | /** Pointer to line number details. */
 | 
|---|
 | 110 | typedef KDBGLINE *PKDBGLINE;
 | 
|---|
 | 111 | /** Pointer to const line number details. */
 | 
|---|
 | 112 | typedef const KDBGLINE *PCKDBGLINE;
 | 
|---|
 | 113 | /** Pointer to a pointer to line number details. */
 | 
|---|
 | 114 | typedef PKDBGLINE *PPKDBGLINE;
 | 
|---|
 | 115 | 
 | 
|---|
 | 116 | /**
 | 
|---|
 | 117 |  * Duplicates a line number.
 | 
|---|
 | 118 |  *
 | 
|---|
 | 119 |  * To save heap space, the returned line number will not own more heap space
 | 
|---|
 | 120 |  * than it strictly need to. So, it's not possible to append stuff to the symbol
 | 
|---|
 | 121 |  * or anything of that kind.
 | 
|---|
 | 122 |  *
 | 
|---|
 | 123 |  * @returns Pointer to the duplicate.
 | 
|---|
 | 124 |  *          This must be freed using RTDbgSymbolFree().
 | 
|---|
 | 125 |  * @param   pLine       The line number to be duplicated.
 | 
|---|
 | 126 |  */
 | 
|---|
 | 127 | KDBG_DECL(PKDBGLINE) kDbgLineDup(PCKDBGLINE pLine);
 | 
|---|
 | 128 | 
 | 
|---|
 | 129 | /**
 | 
|---|
 | 130 |  * Frees a line number obtained from the RTDbg API.
 | 
|---|
 | 131 |  *
 | 
|---|
 | 132 |  * @returns VINF_SUCCESS on success.
 | 
|---|
 | 133 |  * @returns KDBG_ERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in.
 | 
|---|
 | 134 |  *
 | 
|---|
 | 135 |  * @param   pLine       The line number to be freed.
 | 
|---|
 | 136 |  */
 | 
|---|
 | 137 | KDBG_DECL(int) kDbgLineFree(PKDBGLINE pLine);
 | 
|---|
 | 138 | 
 | 
|---|
 | 139 | 
 | 
|---|
 | 140 | /** @name Symbol Flags.
 | 
|---|
 | 141 |  * @{ */
 | 
|---|
 | 142 | /** The symbol is weak. */
 | 
|---|
 | 143 | #define KDBGSYM_FLAGS_WEAK      UINT32_C(0x00000000)
 | 
|---|
 | 144 | /** The symbol is absolute.
 | 
|---|
 | 145 |  * (This also indicated by the segment number.) */
 | 
|---|
 | 146 | #define KDBGSYM_FLAGS_ABS       UINT32_C(0x00000001)
 | 
|---|
 | 147 | /** The symbol is exported. */
 | 
|---|
 | 148 | #define KDBGSYM_FLAGS_EXPORTED  UINT32_C(0x00000002)
 | 
|---|
 | 149 | /** The symbol is a function/method/procedure/whatever-executable-code. */
 | 
|---|
 | 150 | #define KDBGSYM_FLAGS_CODE      UINT32_C(0x00000004)
 | 
|---|
 | 151 | /** The symbol is some kind of data. */
 | 
|---|
 | 152 | #define KDBGSYM_FLAGS_DATA      UINT32_C(0x00000008)
 | 
|---|
 | 153 | /** @} */
 | 
|---|
 | 154 | 
 | 
|---|
 | 155 | /**
 | 
|---|
 | 156 |  * Symbol details.
 | 
|---|
 | 157 |  */
 | 
|---|
 | 158 | typedef struct KDBGSYMBOL
 | 
|---|
 | 159 | {
 | 
|---|
 | 160 |     /** The relative virtual address. */
 | 
|---|
 | 161 |     KDBGADDR    RVA;
 | 
|---|
 | 162 |     /** The symbol size.
 | 
|---|
 | 163 |      * This is not a reliable field, it could be a bad guess. Ignore if zero. */
 | 
|---|
 | 164 |     KDBGADDR    cb;
 | 
|---|
 | 165 |     /** The offset into the segment. */
 | 
|---|
 | 166 |     KDBGADDR    offSegment;
 | 
|---|
 | 167 |     /** The segment number. */
 | 
|---|
 | 168 |     int32_t     iSegment;
 | 
|---|
 | 169 |     /** The symbol flags. */
 | 
|---|
 | 170 |     uint32_t    fFlags;
 | 
|---|
 | 171 | /** @todo type info? */
 | 
|---|
 | 172 |     /** The length of the symbol name. */
 | 
|---|
 | 173 |     uint16_t    cchName;
 | 
|---|
 | 174 |     /** The symbol name. */
 | 
|---|
 | 175 |     char        szName[KDBG_SYMBOL_MAX];
 | 
|---|
 | 176 | } KDBGSYMBOL;
 | 
|---|
 | 177 | /** Pointer to symbol details. */
 | 
|---|
 | 178 | typedef KDBGSYMBOL *PKDBGSYMBOL;
 | 
|---|
 | 179 | /** Pointer to const symbol details. */
 | 
|---|
 | 180 | typedef const KDBGSYMBOL *PCKDBGSYMBOL;
 | 
|---|
 | 181 | /** Pointer to a pointer to symbol details. */
 | 
|---|
 | 182 | typedef PKDBGSYMBOL *PPKDBGSYMBOL;
 | 
|---|
 | 183 | 
 | 
|---|
 | 184 | /**
 | 
|---|
 | 185 |  * Duplicates a symbol.
 | 
|---|
 | 186 |  *
 | 
|---|
 | 187 |  * To save heap space, the returned symbol will not own more heap space than
 | 
|---|
 | 188 |  * it strictly need to. So, it's not possible to append stuff to the symbol
 | 
|---|
 | 189 |  * or anything of that kind.
 | 
|---|
 | 190 |  *
 | 
|---|
 | 191 |  * @returns Pointer to the duplicate.
 | 
|---|
 | 192 |  *          This must be freed using kDbgSymbolFree().
 | 
|---|
 | 193 |  * @param   pSymbol     The symbol to be freed.
 | 
|---|
 | 194 |  */
 | 
|---|
 | 195 | KDBG_DECL(PKDBGSYMBOL) kDbgSymbolDup(PCKDBGSYMBOL pSymbol);
 | 
|---|
 | 196 | 
 | 
|---|
 | 197 | /**
 | 
|---|
 | 198 |  * Frees a symbol obtained from the kDbg API.
 | 
|---|
 | 199 |  *
 | 
|---|
 | 200 |  * @returns VINF_SUCCESS on success.
 | 
|---|
 | 201 |  * @returns KDBG_ERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in.
 | 
|---|
 | 202 |  *
 | 
|---|
 | 203 |  * @param   pSymbol     The symbol to be freed.
 | 
|---|
 | 204 |  */
 | 
|---|
 | 205 | KDBG_DECL(int) kDbgSymbolFree(PKDBGSYMBOL pSymbol);
 | 
|---|
 | 206 | 
 | 
|---|
 | 207 | 
 | 
|---|
 | 208 | 
 | 
|---|
 | 209 | /** A debug module handle. */
 | 
|---|
 | 210 | typedef struct KDBGMOD *PKDBGMOD;
 | 
|---|
 | 211 | 
 | 
|---|
 | 212 | /**
 | 
|---|
 | 213 |  * Opens the debug info for a specified executable module.
 | 
|---|
 | 214 |  *
 | 
|---|
 | 215 |  * @returns IPRT status code.
 | 
|---|
 | 216 |  * @param   pszModulePath       The path to the executable module.
 | 
|---|
 | 217 |  * @param   ppDbgMod            Where to store the debug module handle.
 | 
|---|
 | 218 |  */
 | 
|---|
 | 219 | KDBG_DECL(int) kDbgModuleOpen(const char *pszModulePath, PKDBGMOD *ppDbgMod);
 | 
|---|
 | 220 | 
 | 
|---|
 | 221 | /**
 | 
|---|
 | 222 |  * Closes the module.
 | 
|---|
 | 223 |  *
 | 
|---|
 | 224 |  * @returns IPRT status code.
 | 
|---|
 | 225 |  * @param   pMod        The module handle.
 | 
|---|
 | 226 |  */
 | 
|---|
 | 227 | KDBG_DECL(int) kDbgModuleClose(PKDBGMOD pMod);
 | 
|---|
 | 228 | 
 | 
|---|
 | 229 | /**
 | 
|---|
 | 230 |  * Gets a symbol by segment:offset.
 | 
|---|
 | 231 |  * This will be approximated to the nearest symbol if there is no exact match.
 | 
|---|
 | 232 |  *
 | 
|---|
 | 233 |  * @returns IPRT status code.
 | 
|---|
 | 234 |  * @param   pMod        The module.
 | 
|---|
 | 235 |  * @param   iSegment    The segment this offset is relative to.
 | 
|---|
 | 236 |  *                      The -1 segment is special, it means that the addres is relative to
 | 
|---|
 | 237 |  *                      the image base. The image base is where the first bit of the image
 | 
|---|
 | 238 |  *                      is mapped during load.
 | 
|---|
 | 239 |  * @param   off         The offset into the segment.
 | 
|---|
 | 240 |  * @param   pSym        Where to store the symbol details.
 | 
|---|
 | 241 |  */
 | 
|---|
 | 242 | KDBG_DECL(int) kDbgModuleQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym);
 | 
|---|
 | 243 | 
 | 
|---|
 | 244 | /**
 | 
|---|
 | 245 |  * Gets & allocates a symbol by segment:offset.
 | 
|---|
 | 246 |  * This will be approximated to the nearest symbol if there is no exact match.
 | 
|---|
 | 247 |  *
 | 
|---|
 | 248 |  * @returns IPRT status code.
 | 
|---|
 | 249 |  * @param   pMod        The module.
 | 
|---|
 | 250 |  * @param   iSegment    The segment this offset is relative to.
 | 
|---|
 | 251 |  *                      The -1 segment is special, it means that the addres is relative to
 | 
|---|
 | 252 |  *                      the image base. The image base is where the first bit of the image
 | 
|---|
 | 253 |  *                      is mapped during load.
 | 
|---|
 | 254 |  * @param   off         The offset into the segment.
 | 
|---|
 | 255 |  * @param   ppSym       Where to store the pointer to the symbol info.
 | 
|---|
 | 256 |  *                      Free the returned symbol using kDbgSymbolFree().
 | 
|---|
 | 257 |  */
 | 
|---|
 | 258 | KDBG_DECL(int) kDbgModuleQuerySymbolA(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PPKDBGSYMBOL ppSym);
 | 
|---|
 | 259 | 
 | 
|---|
 | 260 | /**
 | 
|---|
 | 261 |  * Gets a line number entry by segment:offset.
 | 
|---|
 | 262 |  * This will be approximated to the nearest line number there is no exact match.
 | 
|---|
 | 263 |  *
 | 
|---|
 | 264 |  * @returns IPRT status code.
 | 
|---|
 | 265 |  * @param   pMod        The module.
 | 
|---|
 | 266 |  * @param   iSegment    The segment this offset is relative to.
 | 
|---|
 | 267 |  *                      The -1 segment is special, it means that the addres is relative to
 | 
|---|
 | 268 |  *                      the image base. The image base is where the first bit of the image
 | 
|---|
 | 269 |  *                      is mapped during load.
 | 
|---|
 | 270 |  * @param   off         The offset into the segment.
 | 
|---|
 | 271 |  * @param   pLine       Where to store the line number details.
 | 
|---|
 | 272 |  */
 | 
|---|
 | 273 | KDBG_DECL(int) kDbgModuleQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine);
 | 
|---|
 | 274 | 
 | 
|---|
 | 275 | /**
 | 
|---|
 | 276 |  * Gets & allocates a line number entry by segment:offset.
 | 
|---|
 | 277 |  * This will be approximated to the nearest line number there is no exact match.
 | 
|---|
 | 278 |  *
 | 
|---|
 | 279 |  * @returns IPRT status code.
 | 
|---|
 | 280 |  * @param   pMod        The module.
 | 
|---|
 | 281 |  * @param   iSegment    The segment this offset is relative to.
 | 
|---|
 | 282 |  *                      The -1 segment is special, it means that the addres is relative to
 | 
|---|
 | 283 |  *                      the image base. The image base is where the first bit of the image
 | 
|---|
 | 284 |  *                      is mapped during load.
 | 
|---|
 | 285 |  * @param   off         The offset into the segment.
 | 
|---|
 | 286 |  * @param   ppLine      Where to store the pointer to the line number info.
 | 
|---|
 | 287 |  *                      Free the returned line number using kDbgLineFree().
 | 
|---|
 | 288 |  */
 | 
|---|
 | 289 | KDBG_DECL(int) kDbgModuleQueryLineA(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PPKDBGLINE ppLine);
 | 
|---|
 | 290 | 
 | 
|---|
 | 291 | 
 | 
|---|
 | 292 | /** @} */
 | 
|---|
 | 293 | 
 | 
|---|
 | 294 | #ifdef __cplusplus
 | 
|---|
 | 295 | }
 | 
|---|
 | 296 | #endif
 | 
|---|
 | 297 | 
 | 
|---|
 | 298 | #endif
 | 
|---|