Changeset 3528
- Timestamp:
- Aug 20, 2007, 4:43:13 AM (18 years ago)
- Location:
- trunk/kDbg
- Files:
-
- 2 added
- 9 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/kDbg/Makefile.kmk
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
r3526 r3528 1 # $Id :$1 # $Id$ 2 2 ## @file 3 # kDbg - The Debug Info Reader. 3 4 # 4 # kProfiler Mark 2 5 5 6 # 6 # Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net.de> 7 # 7 # Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 8 # 9 9 # This file is part of kLIBC. … … 28 28 include $(PATH_KBUILD)/header.kmk 29 29 30 #LIBRARIES = kPrf2GC kPrf2R0 31 DLLS = kPrf2 32 PROGRAMS = kPrf2Read 33 30 # 31 # kDbg - The profiler module. 32 # 33 DLLS += kDbg 34 kDbg_TEMPLATE = kStuffDLL 35 kDbg_DEFS = KDBG_BUILDING KDBG_RESIDES_IN_DLL 36 kDbg_INCS = ../kLdr 37 kDbg_SOURCES := \ 38 kDbgModule.cpp \ 39 kDbgModPE-$(if $(eq $(BUILD_TARGET),win),win,generic).cpp \ 40 \ 41 kDbgLine.cpp \ 42 \ 43 kDbgSymbol.cpp \ 44 \ 45 kDbgHlpCrt.cpp 34 46 35 47 # 36 # Our template.48 # kDbgStatic - The profiler module. 37 49 # 38 TEMPLATE_kPrf2 = kProfiler Template 39 TEMPLATE_kPrf2_TOOL = GCC3 40 TEMPLATE_kPrf2_TOOL.os2 = GCC3OMF 41 TEMPLATE_kPrf2_TOOL.win.x86 = VCC70 42 TEMPLATE_kPrf2_TOOL.win.amd64 = VCC80AMD64 43 TEMPLATE_kPrf2_ASTOOL = YASM 44 TEMPLATE_kPrf2_ASTOOL.os2 = NASM 50 LIBRARIES += kDbgStatic 51 kDbgStatic_TEMPLATE = kStuffLIB 52 kDbgStatic_DEFS = KDBG_BUILDING 53 kDbgStatic_INCS = ../kLdr 54 kDbgStatic_SOURCES = $(kDbg_SOURCES) 45 55 46 TEMPLATE_kPrf2_SDKS.win = WINPSDK 47 48 TEMPLATE_kPrf2_DEFS.freebsd = KPRF_OS_FREEBSD 49 TEMPLATE_kPrf2_DEFS.linux = KPRF_OS_LINUX 50 TEMPLATE_kPrf2_DEFS.os2 = KPRF_OS_OS2 51 TEMPLATE_kPrf2_DEFS.win = KPRF_OS_WINDOWS 52 53 TEMPLATE_kPrf2_CXXFLAGS.freebsd = -g 54 TEMPLATE_kPrf2_CXXFLAGS.linux = -g 55 TEMPLATE_kPrf2_CXXFLAGS.os2 = -g 56 TEMPLATE_kPrf2_CXXFLAGS.win = -Zi -Zl -MD -W3 -GF -GR- 57 ifneq ($(BUILD_TYPE),debug) 58 TEMPLATE_kPrf2_CXXFLAGS.freebsd+= -O3 59 TEMPLATE_kPrf2_CXXFLAGS.linux += -O3 60 TEMPLATE_kPrf2_CXXFLAGS.os2 += -O3 61 TEMPLATE_kPrf2_CXXFLAGS.win += -O2xtg -Oi -Ob2 62 endif 63 64 TEMPLATE_kPrf2_ASFLAGS.freebsd = -f elf 65 TEMPLATE_kPrf2_ASFLAGS.linux = -f elf 66 TEMPLATE_kPrf2_ASFLAGS.os2 = -f omf 67 TEMPLATE_kPrf2_ASFLAGS.win.x86 = -f win32 -g cv8 68 TEMPLATE_kPrf2_ASFLAGS.win.amd64 = -f win64 -g cv8 69 70 #TEMPLATE_kPrf2_INCS.win = \ 71 # $(PATH_DEV)/x86.win32/vcc70/include \ 72 # $(PATH_DEV)/x86.win32/sdk200209/include 73 74 TEMPLATE_kPrf2_LDFLAGS.freebsd = -g 75 TEMPLATE_kPrf2_LDFLAGS.linux = -g 76 TEMPLATE_kPrf2_LDFLAGS.os2 = -g 77 TEMPLATE_kPrf2_LDFLAGS.win = /DEBUG 78 79 TEMPLATE_kPrf2_LIBS.freebsd = 80 TEMPLATE_kPrf2_LIBS.linux = 81 TEMPLATE_kPrf2_LIBS.os2 = 82 TEMPLATE_kPrf2_LIBS.win = \ 83 $(PATH_SDK_WINPSDK_LIB)/psapi.Lib 84 TEMPLATE_kPrf2_LIBS.win.x86 = \ 85 $(PATH_TOOL_VCC70_LIB)/msvcrt.lib \ 86 $(PATH_TOOL_VCC70_LIB)/msvcprt.lib \ 87 $(PATH_TOOL_VCC70_LIB)/oldnames.lib 88 89 90 # 91 # kPrf2 - The profiler module. 92 # 93 kPrf2_TEMPLATE = kPrf2 94 kPrf2_DEFS.x86 = KPRF_BITS=32 95 kPrf2_DEFS.amd64 = KPRF_BITS=64 96 97 kPrf2_SOURCES = \ 98 kProfileR3.cpp 99 # kProfileGC.cpp 100 # kProfileR0.cpp 101 102 kPrf2_SOURCES.win = \ 103 dllmain-win.cpp \ 104 prf$(BUILD_TARGET_ARCH)msc.asm \ 105 kPrf2-win-$(BUILD_TARGET_ARCH).def 106 prfx86msc.asm_DEFS.win.x86 = \ 107 KPRF_ENTER=_KPrfEnter \ 108 KPRF_LEAVE=_KPrfLeave 109 110 111 112 # 113 # kPrf2Read - The read & producer of statistics. 114 # 115 kPrf2Read_TEMPLATE = kPrf2 116 kPrf2Read_SOURCES = \ 117 kPrf2Read.cpp 118 119 # kDbg stuff 120 KDBG_ROOT ?= $(PATH_CURRENT)/../kProfile 121 kPrf2Read_INCS += $(KDBG_ROOT) 122 kPrf2Read_SOURCES += \ 123 dbgmodule.cpp \ 124 dbgline.cpp \ 125 dbgsymbol.cpp 126 ifeq ($(BUILD_TARGET),win) 127 kPrf2Read_SOURCES.win += dbgModPE-win.cpp 128 else 129 kPrf2Read_SOURCES += dbgModPE-generic.cpp 130 endif 131 132 # kLdr stuff 133 KLDR_ROOT ?= $(PATH_CURRENT)/../kLdr 134 kPrf2Read_INCS += $(KLDR_ROOT) 135 136 # IPRT stuff 137 VBOX_ROOT ?= y:/coding/vbox/svn/trunk 138 kPrf2Read_INCS += $(VBOX_ROOT)/include 139 kPrf2Read_DEFS += IN_RING3 IN_RT_R3 KDBG_USE_IPRT KCOMMON_ALREADY_INCLUDED_STD_TYPES 140 ifeq ($(BUILD_TARGET),win) 141 kPrf2Read_LIBS = \ 142 $(VBOX_ROOT)/out/$(BUILD_TARGET).$(BUILD_TARGET_ARCH)/$(BUILD_TYPE)/lib/VBoxRT$(SUFF_LIB) 143 else 144 kPrf2Read_LIBS = \ 145 $(VBOX_ROOT)/out/$(BUILD_TARGET).$(BUILD_TARGET_ARCH)/$(BUILD_TYPE)/bin/VBoxRT$(SUFF_DLL) 146 endif 147 148 149 # 150 # A simple testcase. 151 # 152 PROGRAMS.win.x86 += tst 153 tst_TOOL = VCC70 154 tst_SDKS = WINPSDK 155 tst_CFLAGS = -GH -Gh -Zi -Zl -GR- -GX- -GF- -MD -W3 -wd4244 156 tst_SOURCES = tst.c 157 tst.c_CFLAGS = -Od 158 tst_LDFLAGS = /DEBUG 159 tst_LIBS = \ 160 $(PATH_TOOL_VCC70_LIB)/msvcrt.lib \ 161 $(PATH_TOOL_VCC70_LIB)/msvcprt.lib \ 162 $(PATH_TOOL_VCC70_LIB)/oldnames.lib \ 163 $(PATH_kPrf2)/kPrf2.lib 56 ## 57 ## kDbgDump - Test program which dumps whatever is thrown at it. 58 ## 59 #PROGRAMS += kDbgDump 60 kDbgDump_TEMPLATE = kStuffEXE 61 kDbgDump_SOURCES = kDbgDump.cpp 62 kDbgDump_LIBS = $(TARGET_kDbgStatic) 164 63 165 64 # Generate the rules 166 65 include $(PATH_KBUILD)/footer.kmk 167 66 168 169 #170 # Aliases for .cpp.h files so we can more easily do syntax checking from the editor.171 #172 CORE := $(wildcard *core*.cpp.h *core*.h.h)173 $(CORE:.h=.o) $(CORE:.h=.obj) : kProfileR3.o174 175 READ := $(wildcard *read*.cpp.h *read*.h.h)176 $(READ:.h=.o) $(READ:.h=.obj) : kPrf2Read.o177 -
Property svn:eol-style
set to
-
trunk/kDbg/kDbg.h
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
r3524 r3528 1 /* $Id :$ */1 /* $Id$ */ 2 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 * 3 * kDbg - The Debug Info Reader. 4 */ 5 6 /* 7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 8 * 9 9 * This program is free software; you can redistribute it and/or modify … … 23 23 */ 24 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 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 35 * @{ 36 36 */ 37 37 38 38 /** The max filename path length used by the debug reader. */ 39 #define RTDBG_PATH_MAX26039 #define KDBG_PATH_MAX 260 40 40 41 41 /** The max symbol name length used by the debug reader. */ 42 #define RTDBG_SYMBOL_MAX 384 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) 61 /** Generic error. */ 62 #define KDBG_ERR_GENERAL_FAILURE (KDBG_ERR_BASE + 9) 63 64 /** The (module) format isn't known to use. */ 65 #define KDBG_ERR_UNKOWN_FORMAT (KDBG_ERR_BASE + 10) 66 /** The (module) format isn't supported by this kDbg build. */ 67 #define KDBG_ERR_FORMAT_NOT_SUPPORTED (KDBG_ERR_BASE + 11) 68 /** A specified address or an address found in the debug info is invalid. */ 69 #define KDBG_ERR_INVALID_ADDRESS (KDBG_ERR_BASE + 12) 70 71 /** @} */ 43 72 44 73 … … 48 77 * The specified offset is relative to the image base. The image base is the lowest memory 49 78 * address used by the image when loaded with the address assignments indicated in the image. */ 50 #define RTDBGSEG_RVA (-1)79 #define KDBGSEG_RVA (-1) 51 80 /** Absolute segment. The offset isn't relative to anything. */ 52 #define RTDBGSEG_ABS (-2)81 #define KDBGSEG_ABS (-2) 53 82 /** @} */ 54 83 … … 57 86 * Line number details. 58 87 */ 59 typedef struct RTDBGLINE88 typedef struct KDBGLINE 60 89 { 61 90 /** The relative virtual address. */ 62 RTUINTPTRRVA;91 KDBGADDR RVA; 63 92 /** The offset into the segment. */ 64 RTUINTPTRoffSegment;93 KDBGADDR offSegment; 65 94 /** The segment number. */ 66 95 int32_t iSegment; … … 70 99 uint16_t cchFile; 71 100 /** The name of the file this line number relates to. */ 72 char szFile[ RTDBG_PATH_MAX];73 } RTDBGLINE;101 char szFile[KDBG_PATH_MAX]; 102 } KDBGLINE; 74 103 /** Pointer to line number details. */ 75 typedef RTDBGLINE *PRTDBGLINE;104 typedef KDBGLINE *PKDBGLINE; 76 105 /** Pointer to const line number details. */ 77 typedef const RTDBGLINE *PCRTDBGLINE;106 typedef const KDBGLINE *PCKDBGLINE; 78 107 /** Pointer to a pointer to line number details. */ 79 typedef P RTDBGLINE *PPRTDBGLINE;108 typedef PKDBGLINE *PPKDBGLINE; 80 109 81 110 /** … … 90 119 * @param pLine The line number to be duplicated. 91 120 */ 92 RTDECL(PRTDBGLINE) RTDbgLineDup(PCRTDBGLINE pLine);121 KDBG_DECL(PKDBGLINE) kDbgLineDup(PCKDBGLINE pLine); 93 122 94 123 /** … … 96 125 * 97 126 * @returns VINF_SUCCESS on success. 98 * @returns VERR_INVALID_POINTER if a NULL pointer or an !VALID_PTR() is passed in.127 * @returns KDBG_ERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in. 99 128 * 100 129 * @param pLine The line number to be freed. 101 130 */ 102 RTDECL(int) RTDbgLineFree(PRTDBGLINE pLine);131 KDBG_DECL(int) kDbgLineFree(PKDBGLINE pLine); 103 132 104 133 … … 106 135 * @{ */ 107 136 /** The symbol is weak. */ 108 #define RTDBGSYM_FLAGS_WEAK BIT(0)137 #define KDBGSYM_FLAGS_WEAK UINT32_C(0x00000000) 109 138 /** The symbol is absolute. 110 139 * (This also indicated by the segment number.) */ 111 #define RTDBGSYM_FLAGS_ABS BIT(1)140 #define KDBGSYM_FLAGS_ABS UINT32_C(0x00000001) 112 141 /** The symbol is exported. */ 113 #define RTDBGSYM_FLAGS_EXPORTED BIT(2)142 #define KDBGSYM_FLAGS_EXPORTED UINT32_C(0x00000002) 114 143 /** The symbol is a function/method/procedure/whatever-executable-code. */ 115 #define RTDBGSYM_FLAGS_CODE BIT(3)144 #define KDBGSYM_FLAGS_CODE UINT32_C(0x00000004) 116 145 /** The symbol is some kind of data. */ 117 #define RTDBGSYM_FLAGS_DATA BIT(4)146 #define KDBGSYM_FLAGS_DATA UINT32_C(0x00000008) 118 147 /** @} */ 119 148 … … 121 150 * Symbol details. 122 151 */ 123 typedef struct RTDBGSYMBOL152 typedef struct KDBGSYMBOL 124 153 { 125 154 /** The relative virtual address. */ 126 RTUINTPTRRVA;155 KDBGADDR RVA; 127 156 /** The symbol size. 128 157 * This is not a reliable field, it could be a bad guess. Ignore if zero. */ 129 RTUINTPTRcb;158 KDBGADDR cb; 130 159 /** The offset into the segment. */ 131 RTUINTPTRoffSegment;160 KDBGADDR offSegment; 132 161 /** The segment number. */ 133 162 int32_t iSegment; … … 138 167 uint16_t cchName; 139 168 /** The symbol name. */ 140 char szName[ RTDBG_SYMBOL_MAX];141 } RTDBGSYMBOL;169 char szName[KDBG_SYMBOL_MAX]; 170 } KDBGSYMBOL; 142 171 /** Pointer to symbol details. */ 143 typedef RTDBGSYMBOL *PRTDBGSYMBOL;172 typedef KDBGSYMBOL *PKDBGSYMBOL; 144 173 /** Pointer to const symbol details. */ 145 typedef const RTDBGSYMBOL *PCRTDBGSYMBOL;174 typedef const KDBGSYMBOL *PCKDBGSYMBOL; 146 175 /** Pointer to a pointer to symbol details. */ 147 typedef PRTDBGSYMBOL *PPRTDBGSYMBOL; 148 176 typedef PKDBGSYMBOL *PPKDBGSYMBOL; 149 177 150 178 /** … … 156 184 * 157 185 * @returns Pointer to the duplicate. 158 * This must be freed using RTDbgSymbolFree().186 * This must be freed using kDbgSymbolFree(). 159 187 * @param pSymbol The symbol to be freed. 160 188 */ 161 RTDECL(PRTDBGSYMBOL) RTDbgSymbolDup(PCRTDBGSYMBOL pSymbol);162 163 /** 164 * Frees a symbol obtained from the RTDbg API.189 KDBG_DECL(PKDBGSYMBOL) kDbgSymbolDup(PCKDBGSYMBOL pSymbol); 190 191 /** 192 * Frees a symbol obtained from the kDbg API. 165 193 * 166 194 * @returns VINF_SUCCESS on success. 167 * @returns VERR_INVALID_POINTER if a NULL pointer or an !VALID_PTR() is passed in.195 * @returns KDBG_ERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in. 168 196 * 169 197 * @param pSymbol The symbol to be freed. 170 198 */ 171 RTDECL(int) RTDbgSymbolFree(PRTDBGSYMBOL pSymbol);199 KDBG_DECL(int) kDbgSymbolFree(PKDBGSYMBOL pSymbol); 172 200 173 201 174 202 175 203 /** A debug module handle. */ 176 typedef struct RTDBGMOD *PRTDBGMOD;204 typedef struct KDBGMOD *PKDBGMOD; 177 205 178 206 /** … … 183 211 * @param ppDbgMod Where to store the debug module handle. 184 212 */ 185 RTDECL(int) RTDbgModuleOpen(const char *pszModulePath, PRTDBGMOD *ppDbgMod);213 KDBG_DECL(int) kDbgModuleOpen(const char *pszModulePath, PKDBGMOD *ppDbgMod); 186 214 187 215 /** … … 191 219 * @param pMod The module handle. 192 220 */ 193 RTDECL(int) RTDbgModuleClose(PRTDBGMOD pMod);221 KDBG_DECL(int) kDbgModuleClose(PKDBGMOD pMod); 194 222 195 223 /** … … 206 234 * @param pSym Where to store the symbol details. 207 235 */ 208 RTDECL(int) RTDbgModuleQuerySymbol(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGSYMBOL pSym);236 KDBG_DECL(int) kDbgModuleQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym); 209 237 210 238 /** … … 220 248 * @param off The offset into the segment. 221 249 * @param ppSym Where to store the pointer to the symbol info. 222 * Free the returned symbol using RTDbgSymbolFree().223 */ 224 RTDECL(int) RTDbgModuleQuerySymbolA(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PPRTDBGSYMBOL ppSym);250 * Free the returned symbol using kDbgSymbolFree(). 251 */ 252 KDBG_DECL(int) kDbgModuleQuerySymbolA(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PPKDBGSYMBOL ppSym); 225 253 226 254 /** … … 237 265 * @param pLine Where to store the line number details. 238 266 */ 239 RTDECL(int) RTDbgModuleQueryLine(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGLINE pLine);267 KDBG_DECL(int) kDbgModuleQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine); 240 268 241 269 /** … … 251 279 * @param off The offset into the segment. 252 280 * @param ppLine Where to store the pointer to the line number info. 253 * Free the returned line number using RTDbgLineFree().254 */ 255 RTDECL(int) RTDbgModuleQueryLineA(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PPRTDBGLINE ppLine);256 257 258 __END_DECLS 259 260 /** @} */ 261 281 * Free the returned line number using kDbgLineFree(). 282 */ 283 KDBG_DECL(int) kDbgModuleQueryLineA(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PPKDBGLINE ppLine); 284 285 286 /** @} */ 287 288 #ifdef __cplusplus 289 } 262 290 #endif 291 292 #endif -
Property svn:eol-style
set to
-
trunk/kDbg/kDbgBase.h
-
Property svn:eol-style
set to
native
r3526 r3528 1 1 /* $Id$ */ 2 2 /** @file 3 *4 3 * kDbg - The Debug Info Reader, Base Definitions and Typedefs. 5 * 4 */ 5 6 /* 6 7 * Copyright (c) 2006-2007 knut st. osmundsen <bird@anduin.net> 7 8 * … … 78 79 79 80 81 /** @def KDBG_CALL 82 * The calling convention used by the kDbg functions. */ 83 #if defined(_MSC_VER) || defined(__OS2__) 84 # define KDBG_CALL __cdecl 85 #else 86 # define KDBG_CALL 87 #endif 88 89 #ifdef __DOXYGEN__ 90 /** @def KDBG_BUILDING 91 * Define KDBG_BUILDING to indicate that kDbg is being built. 92 */ 93 # define KDBG_BUILDING 94 /** @def KDBG_RESIDES_IN_DLL 95 * Define KDBG_RESIDES_IN_DLL to indicate that kDbg resides in a DLL. 96 */ 97 # define KDBG_RESIDES_IN_DLL 98 #endif 99 100 /** @def KDBG_DECL 101 * Macro for defining public functions. */ 102 #if defined(KDBG_RESIDES_IN_DLL) \ 103 && (defined(_MSC_VER) || defined(__OS2__)) 104 # ifdef KDBG_BUILDING 105 # define KDBG_DECL(type) __declspec(dllexport) type 106 # else 107 # define KDBG_DECL(type) __declspec(dllimport) type 108 # endif 109 #else 110 # define KDBG_DECL(type) type 111 #endif 112 113 /** @def KDBG_INLINE 114 * Macro for defining an inline function. */ 115 #ifdef __cplusplus 116 # if defined(__GNUC__) 117 # define KDBG_INLINE(type) static inline type 118 # else 119 # define KDBG_INLINE(type) inline type 120 # endif 121 #else 122 # if defined(__GNUC__) 123 # define KDBG_INLINE(type) static __inline__ type 124 # elif defined(_MSC_VER) 125 # define KDBG_INLINE(type) _inline type 126 # else 127 # error "Port me" 128 # endif 129 #endif 130 131 132 /** The kDbg address type. */ 133 typedef uint64_t KDBGADDR; 134 /** Pointer to a kLdr address. */ 135 typedef KDBGADDR *PKDBGADDR; 136 /** Pointer to a const kLdr address. */ 137 typedef const KDBGADDR *PCKDBGADDR; 138 139 /** NIL address. */ 140 #define NIL_KDBGADDR (~(uint64_t)0) 141 142 /** @def PRI_KDBGADDR 143 * printf format type. */ 144 #ifdef _MSC_VER 145 # define PRI_KDBGADDR "I64x" 146 #else 147 # define PRI_KDBGADDR "llx" 148 #endif 149 150 80 151 /** Get the minimum of two values. */ 81 152 #define KDBG_MIN(a, b) ((a) <= (b) ? (a) : (b)) … … 89 160 #define KDBG_ALIGN_P(pv, align) ( (void *)( ((uintptr_t)(pv) + ((align) - 1)) & ~(uintptr_t)((align) - 1) ) ) 90 161 /** Align a size_t value. */ 91 #define KDBG_ALIGN_ADDR(val, align) ( ((val) + ((align) - 1)) & ~(K LDRADDR)((align) - 1) )162 #define KDBG_ALIGN_ADDR(val, align) ( ((val) + ((align) - 1)) & ~(KDBGADDR)((align) - 1) ) 92 163 /** Number of elements in an array. */ 93 164 #define KDBG_ELEMENTS(a) ( sizeof(a) / sizeof((a)[0]) ) 165 /** @def KDBG_VALID_PTR 166 * Checks if the specified pointer is a valid address or not. */ 167 #define KDBG_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U ) 94 168 95 169 -
Property svn:eol-style
set to
-
trunk/kDbg/kDbgInternal.h
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
r3524 r3528 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 * 4 * kProfile Mark 2 - Debug Info Reader, Internal Header.5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net.de> 7 * 3 * kDbg - The Debug Info Reader, Internal Header. 4 */ 5 6 /* 7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 8 * 9 9 * This program is free software; you can redistribute it and/or modify … … 23 23 */ 24 24 25 #ifndef __ internal_DBGInternal_h__26 #define __ internal_DBGInternal_h__25 #ifndef ___kDbgInternal_h___ 26 #define ___kDbgInternal_h___ 27 27 28 #include "dbg.h" 28 #include "kDbgBase.h" 29 #include "kDbgHlp.h" 30 #include "kDbg.h" 29 31 30 __BEGIN_DECLS 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 31 35 32 36 … … 34 38 * The debug module method table. 35 39 */ 36 typedef struct RTDBGMODOPS40 typedef struct KDBGMODOPS 37 41 { 38 42 /** The name of the reader. */ … … 48 52 * @param pMod The module. 49 53 */ 50 DECLCALLBACKMEMBER(int, pfnClose)(PRTDBGMOD pMod);54 int (*pfnClose)(PKDBGMOD pMod); 51 55 52 56 /** … … 63 67 * @param pSym Where to store the symbol details. 64 68 */ 65 DECLCALLBACKMEMBER(int, pfnQuerySymbol)(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGSYMBOL pSym);69 int (*pfnQuerySymbol)(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym); 66 70 67 71 /** … … 78 82 * @param pLine Where to store the line number details. 79 83 */ 80 DECLCALLBACKMEMBER(int, pfnQueryLine)(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR uOffset, PRTDBGLINE pLine);84 int (*pfnQueryLine)(PKDBGMOD pMod, int32_t iSegment, KDBGADDR uOffset, PKDBGLINE pLine); 81 85 82 } RTDBGMODOPS;86 } KDBGMODOPS; 83 87 /** Pointer to a module method table. */ 84 typedef RTDBGMODOPS *PRTDBGMODOPS;88 typedef KDBGMODOPS *PKDBGMODOPS; 85 89 /** Pointer to a const module method table. */ 86 typedef const RTDBGMODOPS *PCRTDBGMODOPS;90 typedef const KDBGMODOPS *PCKDBGMODOPS; 87 91 88 92 … … 90 94 * Internal representation of a debug module. 91 95 */ 92 typedef struct RTDBGMOD96 typedef struct KDBGMOD 93 97 { 94 /** Magic value ( RTDBGMOD_MAGIC). */98 /** Magic value (KDBGMOD_MAGIC). */ 95 99 uint32_t u32Magic; 96 100 /** The handle to the module. (If closed, this is NIL_RTFILE.) */ 97 RTFILEFile;101 PKDBGHLPFILE pFile; 98 102 /** Pointer to the method table. */ 99 PC RTDBGMODOPSpOps;100 } RTDBGMOD;103 PCKDBGMODOPS pOps; 104 } KDBGMOD; 101 105 102 106 103 /** The magic value for the debug module structure. (Some english writer) */104 #define RTDBGMOD_MAGIC 0x00000000107 /** The magic value for the debug module structure. (Some dead english writer) */ 108 #define KDBGMOD_MAGIC 0x00000000 105 109 /** The magic value of a dead module structure. */ 106 #define RTDBGMOD_MAGIC_DEAD 0x00000000110 #define KDBGMOD_MAGIC_DEAD 0x00000001 107 111 108 112 109 int rtDbgModPEOpen(RTFILE File, RTFOFF offHdr, const char *pszModulePath, PRTDBGMOD *ppDbgMod);113 int kdbgModPEOpen(PKDBGHLPFILE pFile, KDBGADDR offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod); 110 114 111 112 __END_DECLS 115 #ifdef __cplusplus 116 } 113 117 #endif 114 118 119 #endif 120 -
Property svn:eol-style
set to
-
trunk/kDbg/kDbgLine.cpp
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
r3526 r3528 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 * 4 * kProfile Mark 2 - Debug Info Line Number.5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net.de> 7 * 3 * kDbg - The Debug Info Read, Line Numbers. 4 */ 5 6 /* 7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 8 * 9 9 * This file is part of kLIBC. … … 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #include <iprt/err.h> 32 #include <iprt/assert.h> 33 #include <iprt/alloc.h> 31 #include "kDbg.h" 32 #include "kDbgInternal.h" 34 33 35 #include "dbg.h"36 #include "kDbgBase.h"37 34 38 35 … … 45 42 * 46 43 * @returns Pointer to the duplicate. 47 * This must be freed using RTDbgSymbolFree().44 * This must be freed using kDbgSymbolFree(). 48 45 * @param pLine The line number to be duplicated. 49 46 */ 50 RTDECL(PRTDBGLINE) RTDbgLineDup(PCRTDBGLINE pLine)47 KDBG_DECL(PKDBGLINE) kDbgLineDup(PCKDBGLINE pLine) 51 48 { 52 AssertMsgReturn(VALID_PTR(pLine), ("%p\n", pLine), NULL);53 size_t cb = KDBG_OFFSETOF( RTDBGLINE, szFile[pLine->cchFile + 1]);54 return (P RTDBGLINE)RTMemDup(pLine, cb);49 kDbgAssertMsgReturn(KDBG_VALID_PTR(pLine), ("%p\n", pLine), NULL); 50 size_t cb = KDBG_OFFSETOF(KDBGLINE, szFile[pLine->cchFile + 1]); 51 return (PKDBGLINE)kDbgHlpAllocDup(pLine, cb); 55 52 } 56 53 … … 59 56 * Frees a line number obtained from the RTDbg API. 60 57 * 61 * @returns VINF_SUCCESSon success.62 * @returns VERR_INVALID_POINTER if a NULL pointer or an !VALID_PTR() is passed in.58 * @returns 0 on success. 59 * @returns KDBG_ERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in. 63 60 * 64 61 * @param pLine The line number to be freed. 65 62 */ 66 RTDECL(int) RTDbgLineFree(PRTDBGLINE pLine)63 KDBG_DECL(int) kDbgLineFree(PKDBGLINE pLine) 67 64 { 68 65 if (!pLine) 69 return VERR_INVALID_POINTER;70 AssertMsgReturn(VALID_PTR(pLine), ("%p\n", pLine), VERR_INVALID_POINTER);66 return KDBG_ERR_INVALID_POINTER; 67 kDbgAssertMsgReturn(KDBG_VALID_PTR(pLine), ("%p\n", pLine), KDBG_ERR_INVALID_POINTER); 71 68 72 RTMemFree(pLine);73 return VINF_SUCCESS;69 kDbgHlpFree(pLine); 70 return 0; 74 71 } 75 72 -
Property svn:eol-style
set to
-
trunk/kDbg/kDbgModPE-generic.cpp
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
r3526 r3528 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 * 4 * kProfile Mark 2 - Debug Info Reader, DbgHelp Base Reader.5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net.de> 7 * 3 * kDbg - The Debug Info Reader, PE Module (Generic). 4 */ 5 6 /* 7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 8 * 9 9 * This file is part of kLIBC. … … 25 25 */ 26 26 27 28 27 /******************************************************************************* 29 28 * Header Files * 30 29 *******************************************************************************/ 31 #include <iprt/file.h> 32 #include <iprt/string.h> 33 #include <iprt/alloc.h> 34 #include <iprt/assert.h> 35 #include <iprt/asm.h> 36 #include <iprt/err.h> 37 #include <iprt/thread.h> 38 #include <iprt/alloca.h> 39 #include "kDbgBase.h" 40 #include "DBGInternal.h" 41 #include "kLdrModPE.h" 42 30 #include "kDbg.h" 31 #include "kDbgInternal.h" 32 #include <kLdrModPE.h> 43 33 44 34 … … 49 39 * A dbghelp based PE debug reader. 50 40 */ 51 typedef struct RTDBGMODPE41 typedef struct KDBGMODPE 52 42 { 53 43 /** The common module core. */ 54 RTDBGMODCore;44 KDBGMOD Core; 55 45 /** The image size. */ 56 46 uint32_t cbImage; … … 59 49 /** The section headers (variable size). The first section is the 60 50 * implicit header section.*/ 61 IMAGE_SECTION_HEADER 62 } RTDBGMODPE, *PRTDBGMODPE;51 IMAGE_SECTION_HEADER aSections[1]; 52 } KDBGMODPE, *PKDBGMODPE; 63 53 64 54 … … 73 63 * @param puRVA Where to store the RVA on success. 74 64 */ 75 static int rtDbgModPeSegOffToRVA(P RTDBGMODPE pModPe, int32_t iSegment, RTUINTPTR off, uint32_t *puRVA)65 static int rtDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA) 76 66 { 77 67 if (iSegment >= 0) 78 68 { 79 AssertMsgReturn(iSegment < pModPe->cSections, ("iSegment=%RX32 cSections=%RX32\n", iSegment, pModPe->cSections),80 VERR_DBGMOD_INVALID_ADDRESS);81 AssertMsgReturn(off < pModPe->aSections[iSegment].Misc.VirtualSize,82 ("off= %RTptr VirtualSize=%RX32\n", off, pModPe->aSections[iSegment].Misc.VirtualSize),83 VERR_DBGMOD_INVALID_ADDRESS);69 kDbgAssertMsgReturn(iSegment < pModPe->cSections, ("iSegment=%x cSections=%x\n", iSegment, pModPe->cSections), 70 KDBG_ERR_INVALID_ADDRESS); 71 kDbgAssertMsgReturn(off < pModPe->aSections[iSegment].Misc.VirtualSize, 72 ("off=" PRI_KDBGADDR " VirtualSize=%x\n", off, pModPe->aSections[iSegment].Misc.VirtualSize), 73 KDBG_ERR_INVALID_ADDRESS); 84 74 *puRVA = pModPe->aSections[iSegment].VirtualAddress + off; 85 return VINF_SUCCESS;86 } 87 88 if (iSegment == RTDBGSEG_RVA)89 { 90 AssertMsgReturn(off < pModPe->cbImage, ("off=%RTptr, cbImage=%RX32\n", off, pModPe->cbImage),91 VERR_DBGMOD_INVALID_ADDRESS);75 return 0; 76 } 77 78 if (iSegment == KDBGSEG_RVA) 79 { 80 kDbgAssertMsgReturn(off < pModPe->cbImage, ("off=" PRI_KDBGADDR ", cbImage=%x\n", off, pModPe->cbImage), 81 KDBG_ERR_INVALID_ADDRESS); 92 82 *puRVA = off; 93 return VINF_SUCCESS;94 } 95 AssertMsgFailedReturn(("iSegment=%RI32\n", iSegment), VERR_DBGMOD_INVALID_ADDRESS);83 return 0; 84 } 85 AssertMsgFailedReturn(("iSegment=%RI32\n", iSegment), KDBG_ERR_INVALID_ADDRESS); 96 86 } 97 87 … … 107 97 * @param poff Where to store the segment offset. 108 98 */ 109 static int rtDbgModPeRVAToSegOff(P RTDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, RTUINTPTR *poff)110 { 111 AssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%RX32, cbImage=%RX32\n", uRVA, pModPe->cbImage),112 VERR_DBGMOD_INVALID_ADDRESS);99 static int rtDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff) 100 { 101 kDbgAssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage), 102 KDBG_ERR_INVALID_ADDRESS); 113 103 for (int32_t iSegment = 0; iSegment < pModPe->cSections; iSegment++) 114 104 { … … 119 109 *poff = off; 120 110 *piSegment = iSegment; 121 return VINF_SUCCESS;122 } 123 } 124 AssertMsgFailedReturn(("uRVA=% RX32\n", uRVA), VERR_DBGMOD_INVALID_ADDRESS);125 } 126 127 128 /** 129 * @copydoc RTDBGMODOPS::pfnQueryLine130 */ 131 static DECLCALLBACK(int) rtDbgModPEQueryLine(P RTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGLINE pLine)132 { 133 P RTDBGMODPE pModPe = (PRTDBGMODPE)pMod;111 return 0; 112 } 113 } 114 AssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS); 115 } 116 117 118 /** 119 * @copydoc KDBGMODOPS::pfnQueryLine 120 */ 121 static DECLCALLBACK(int) rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine) 122 { 123 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; 134 124 135 125 /* … … 138 128 uint32_t uRVA; 139 129 int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA); 140 if ( RT_SUCCESS(rc))130 if (!rc) 141 131 { 142 132 #if 0 … … 146 136 if (g_pfnSymGetLineFromAddr64(pModPe->hSymInst, pModPe->ImageBase + uRVA, &off, &Line)) 147 137 { 148 pLine->RVA = ( RTUINTPTR)(Line.Address - pModPe->ImageBase);138 pLine->RVA = (KDBGADDR)(Line.Address - pModPe->ImageBase); 149 139 rc = rtDbgModPeRVAToSegOff(pModPe, pLine->RVA, &pLine->iSegment, &pLine->offSegment); 150 140 pLine->iLine = Line.LineNumber; … … 167 157 168 158 /** 169 * @copydoc RTDBGMODOPS::pfnQuerySymbol170 */ 171 static DECLCALLBACK(int) rtDbgModPEQuerySymbol(P RTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGSYMBOL pSym)172 { 173 P RTDBGMODPE pModPe = (PRTDBGMODPE)pMod;159 * @copydoc KDBGMODOPS::pfnQuerySymbol 160 */ 161 static DECLCALLBACK(int) rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym) 162 { 163 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; 174 164 175 165 /* … … 178 168 uint32_t uRVA; 179 169 int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA); 180 if ( RT_SUCCESS(rc))170 if (!rc) 181 171 { 182 172 #if 0 … … 194 184 pSym->fFlags = 0; 195 185 if (Buf.Sym.Flags & SYMFLAG_FUNCTION) 196 pSym->fFlags |= RTDBGSYM_FLAGS_CODE;186 pSym->fFlags |= KDBGSYM_FLAGS_CODE; 197 187 else if (Buf.Sym.Flags & SYMFLAG_CONSTANT) 198 pSym->fFlags |= RTDBGSYM_FLAGS_ABS; /** @todo SYMFLAG_CONSTANT must be tested - documentation is too brief to say what is really meant here.*/188 pSym->fFlags |= KDBGSYM_FLAGS_ABS; /** @todo SYMFLAG_CONSTANT must be tested - documentation is too brief to say what is really meant here.*/ 199 189 else 200 pSym->fFlags |= RTDBGSYM_FLAGS_DATA;190 pSym->fFlags |= KDBGSYM_FLAGS_DATA; 201 191 if (Buf.Sym.Flags & SYMFLAG_EXPORT) 202 pSym->fFlags |= RTDBGSYM_FLAGS_EXPORTED;192 pSym->fFlags |= KDBGSYM_FLAGS_EXPORTED; 203 193 if ((Buf.Sym.Flags & (SYMFLAG_VALUEPRESENT | SYMFLAG_CONSTANT)) == (SYMFLAG_VALUEPRESENT | SYMFLAG_CONSTANT)) 204 194 { 205 195 pSym->iSegment = RTDBGSEG_ABS; 206 pSym->offSegment = ( RTUINTPTR)Buf.Sym.Value;207 pSym->RVA = ( RTUINTPTR)Buf.Sym.Value;196 pSym->offSegment = (KDBGADDR)Buf.Sym.Value; 197 pSym->RVA = (KDBGADDR)Buf.Sym.Value; 208 198 } 209 199 else 210 200 { 211 pSym->RVA = ( RTUINTPTR)(Buf.Sym.Address - pModPe->ImageBase);201 pSym->RVA = (KDBGADDR)(Buf.Sym.Address - pModPe->ImageBase); 212 202 rc = rtDbgModPeRVAToSegOff(pModPe, pSym->RVA, &pSym->iSegment, &pSym->offSegment); 213 203 } … … 231 221 232 222 /** 233 * @copydoc RTDBGMODOPS::pfnClose234 */ 235 static DECLCALLBACK(int) rtDbgModPEClose(P RTDBGMOD pMod)236 { 237 P RTDBGMODPE pModPe = (PRTDBGMODPE)pMod;223 * @copydoc KDBGMODOPS::pfnClose 224 */ 225 static DECLCALLBACK(int) rtDbgModPEClose(PKDBGMOD pMod) 226 { 227 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; 238 228 239 229 //if (g_pfnSymCleanup(pModPe->hSymInst)) 240 // return VINF_SUCCESS;230 // return 0; 241 231 // 242 232 //DWORD Err = GetLastError(); … … 251 241 * Methods for a PE module. 252 242 */ 253 static const RTDBGMODOPS g_rtDbgModPEOps =243 static const KDBGMODOPS g_rtDbgModPEOps = 254 244 { 255 245 "PE (dbghelp)", … … 271 261 * 272 262 */ 273 int rtDbgModPEOpen(RTFILE File, RTFOFF offHdr, const char *pszModulePath, PRTDBGMOD *ppDbgMod)263 int kdbgModPEOpen(RTFILE File, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod) 274 264 { 275 265 /* … … 277 267 */ 278 268 IMAGE_FILE_HEADER FHdr; 279 int rc = RTFileReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader), &FHdr, sizeof(FHdr), NULL);269 int rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader), &FHdr, sizeof(FHdr), NULL); 280 270 AssertRCReturn(rc, rc); 281 271 282 272 uint32_t cbImage; 283 273 if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER32)) 284 rc = RTFileReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage),274 rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage), 285 275 &cbImage, sizeof(cbImage), NULL); 286 276 else if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER64)) 287 rc = RTFileReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage),277 rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage), 288 278 &cbImage, sizeof(cbImage), NULL); 289 279 else … … 294 284 * Allocate the module and read/construct the section headers. 295 285 */ 296 P RTDBGMODPE pModPe = (PRTDBGMODPE)RTMemAlloc(KDBG_OFFSETOF(RTDBGMODPE, aSections[FHdr.NumberOfSections + 2]));297 AssertReturn(pModPe, VERR_NO_MEMORY);298 pModPe->Core.u32Magic = RTDBGMOD_MAGIC;286 PKDBGMODPE pModPe = (PKDBGMODPE)RTMemAlloc(KDBG_OFFSETOF(KDBGMODPE, aSections[FHdr.NumberOfSections + 2])); 287 AssertReturn(pModPe, KDBG_ERR_NO_MEMORY); 288 pModPe->Core.u32Magic = KDBGMOD_MAGIC; 299 289 pModPe->Core.pOps = &g_rtDbgModPEOps; 300 290 pModPe->Core.File = File; 301 291 pModPe->cbImage = cbImage; 302 292 pModPe->cSections = 1 + FHdr.NumberOfSections; 303 rc = RTFileReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader,293 rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader, 304 294 &pModPe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections, NULL); 305 if ( RT_SUCCESS(rc))295 if (!rc) 306 296 { 307 297 PIMAGE_SECTION_HEADER pSH = &pModPe->aSections[0]; … … 382 372 AssertRC(rc); 383 373 384 RTMemFree(pModPe);374 kDbgHlpFree(pModPe); 385 375 return rc; 386 376 } -
Property svn:eol-style
set to
-
trunk/kDbg/kDbgModPE-win.cpp
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
r3526 r3528 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 * 4 * kProfile Mark 2 - Debug Info Reader, DbgHelp Base Reader.5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net.de> 7 * 3 * kDbg - The Debug Info Reader, DbgHelp Based Reader. 4 */ 5 6 /* 7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 8 * 9 9 * This file is part of kLIBC. … … 33 33 #include <DbgHelp.h> 34 34 35 #include <iprt/file.h> 36 #include <iprt/string.h> 37 #include <iprt/alloc.h> 38 #include <iprt/assert.h> 39 #include <iprt/asm.h> 40 #include <iprt/err.h> 41 #include <iprt/thread.h> 42 #include <iprt/alloca.h> 43 #include "kDbgBase.h" 44 #include "DBGInternal.h" 45 46 47 //#include "internal/ldrPE.h" 35 #include "kDbgInternal.h" 36 48 37 49 38 /******************************************************************************* … … 73 62 * A dbghelp based PE debug reader. 74 63 */ 75 typedef struct RTDBGMODPE64 typedef struct KDBGMODPE 76 65 { 77 66 /** The common module core. */ 78 RTDBGMOD Core;67 KDBGMOD Core; 79 68 /** The image base. */ 80 69 DWORD64 ImageBase; … … 88 77 * implicit header section.*/ 89 78 IMAGE_SECTION_HEADER aSections[1]; 90 } RTDBGMODPE, *PRTDBGMODPE;79 } KDBGMODPE, *PKDBGMODPE; 91 80 92 81 … … 101 90 * @param puRVA Where to store the RVA on success. 102 91 */ 103 static int rtDbgModPeSegOffToRVA(P RTDBGMODPE pModPe, int32_t iSegment, RTUINTPTR off, uint32_t *puRVA)92 static int rtDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA) 104 93 { 105 94 if (iSegment >= 0) 106 95 { 107 AssertMsgReturn(iSegment < pModPe->cSections, ("iSegment=%RX32 cSections=%RX32\n", iSegment, pModPe->cSections),108 VERR_DBGMOD_INVALID_ADDRESS);109 AssertMsgReturn(off < pModPe->aSections[iSegment].Misc.VirtualSize,110 ("off=%RTptr VirtualSize=%RX32\n", off, pModPe->aSections[iSegment].Misc.VirtualSize),111 VERR_DBGMOD_INVALID_ADDRESS);96 kDbgAssertMsgReturn(iSegment < pModPe->cSections, ("iSegment=%x cSections=%x\n", iSegment, pModPe->cSections), 97 KDBG_ERR_INVALID_ADDRESS); 98 kDbgAssertMsgReturn(off < pModPe->aSections[iSegment].Misc.VirtualSize, 99 ("off=" PRI_KDBGADDR " VirtualSize=%x\n", off, pModPe->aSections[iSegment].Misc.VirtualSize), 100 KDBG_ERR_INVALID_ADDRESS); 112 101 *puRVA = pModPe->aSections[iSegment].VirtualAddress + off; 113 return VINF_SUCCESS;114 } 115 116 if (iSegment == RTDBGSEG_RVA)117 { 118 AssertMsgReturn(off < pModPe->cbImage, ("off=%RTptr, cbImage=%RX32\n", off, pModPe->cbImage),119 VERR_DBGMOD_INVALID_ADDRESS);102 return 0; 103 } 104 105 if (iSegment == KDBGSEG_RVA) 106 { 107 kDbgAssertMsgReturn(off < pModPe->cbImage, ("off=" PRI_KDBGADDR ", cbImage=%x\n", off, pModPe->cbImage), 108 KDBG_ERR_INVALID_ADDRESS); 120 109 *puRVA = off; 121 return VINF_SUCCESS;122 } 123 AssertMsgFailedReturn(("iSegment=%RI32\n", iSegment), VERR_DBGMOD_INVALID_ADDRESS);110 return 0; 111 } 112 AssertMsgFailedReturn(("iSegment=%RI32\n", iSegment), KDBG_ERR_INVALID_ADDRESS); 124 113 } 125 114 … … 135 124 * @param poff Where to store the segment offset. 136 125 */ 137 static int rtDbgModPeRVAToSegOff(P RTDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, RTUINTPTR *poff)138 { 139 AssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%RX32, cbImage=%RX32\n", uRVA, pModPe->cbImage),140 VERR_DBGMOD_INVALID_ADDRESS);126 static int rtDbgModPeRVAToSegOff(PKDBGMODPE pModPe, uint32_t uRVA, int32_t *piSegment, KDBGADDR *poff) 127 { 128 kDbgAssertMsgReturn(uRVA < pModPe->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModPe->cbImage), 129 KDBG_ERR_INVALID_ADDRESS); 141 130 for (int32_t iSegment = 0; iSegment < pModPe->cSections; iSegment++) 142 131 { … … 147 136 *poff = off; 148 137 *piSegment = iSegment; 149 return VINF_SUCCESS;150 } 151 } 152 AssertMsgFailedReturn(("uRVA=% RX32\n", uRVA), VERR_DBGMOD_INVALID_ADDRESS);153 } 154 155 156 /** 157 * @copydoc RTDBGMODOPS::pfnQueryLine158 */ 159 static DECLCALLBACK(int) rtDbgModPEQueryLine(P RTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGLINE pLine)160 { 161 P RTDBGMODPE pModPe = (PRTDBGMODPE)pMod;138 return 0; 139 } 140 } 141 AssertMsgFailedReturn(("uRVA=%x\n", uRVA), KDBG_ERR_INVALID_ADDRESS); 142 } 143 144 145 /** 146 * @copydoc KDBGMODOPS::pfnQueryLine 147 */ 148 static DECLCALLBACK(int) rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine) 149 { 150 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; 162 151 163 152 /* … … 166 155 uint32_t uRVA; 167 156 int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA); 168 if ( RT_SUCCESS(rc))157 if (!rc) 169 158 { 170 159 DWORD64 off; … … 173 162 if (g_pfnSymGetLineFromAddr64(pModPe->hSymInst, pModPe->ImageBase + uRVA, &off, &Line)) 174 163 { 175 pLine->RVA = ( RTUINTPTR)(Line.Address - pModPe->ImageBase);164 pLine->RVA = (KDBGADDR)(Line.Address - pModPe->ImageBase); 176 165 rc = rtDbgModPeRVAToSegOff(pModPe, pLine->RVA, &pLine->iSegment, &pLine->offSegment); 177 166 pLine->iLine = Line.LineNumber; … … 192 181 193 182 /** 194 * @copydoc RTDBGMODOPS::pfnQuerySymbol195 */ 196 static DECLCALLBACK(int) rtDbgModPEQuerySymbol(P RTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGSYMBOL pSym)197 { 198 P RTDBGMODPE pModPe = (PRTDBGMODPE)pMod;183 * @copydoc KDBGMODOPS::pfnQuerySymbol 184 */ 185 static DECLCALLBACK(int) rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym) 186 { 187 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; 199 188 200 189 /* … … 203 192 uint32_t uRVA; 204 193 int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA); 205 if ( RT_SUCCESS(rc))194 if (!rc) 206 195 { 207 196 DWORD64 off; … … 209 198 { 210 199 SYMBOL_INFO Sym; 211 char achBuffer[sizeof(SYMBOL_INFO) + RTDBG_SYMBOL_MAX];200 char achBuffer[sizeof(SYMBOL_INFO) + KDBG_SYMBOL_MAX]; 212 201 } Buf; 213 202 Buf.Sym.SizeOfStruct = sizeof(SYMBOL_INFO); 214 Buf.Sym.MaxNameLen = RTDBG_SYMBOL_MAX;203 Buf.Sym.MaxNameLen = KDBG_SYMBOL_MAX; 215 204 if (g_pfnSymFromAddr(pModPe->hSymInst, pModPe->ImageBase + uRVA, &off, &Buf.Sym)) 216 205 { … … 218 207 pSym->fFlags = 0; 219 208 if (Buf.Sym.Flags & SYMFLAG_FUNCTION) 220 pSym->fFlags |= RTDBGSYM_FLAGS_CODE;209 pSym->fFlags |= KDBGSYM_FLAGS_CODE; 221 210 else if (Buf.Sym.Flags & SYMFLAG_CONSTANT) 222 pSym->fFlags |= RTDBGSYM_FLAGS_ABS; /** @todo SYMFLAG_CONSTANT must be tested - documentation is too brief to say what is really meant here.*/211 pSym->fFlags |= KDBGSYM_FLAGS_ABS; /** @todo SYMFLAG_CONSTANT must be tested - documentation is too brief to say what is really meant here.*/ 223 212 else 224 pSym->fFlags |= RTDBGSYM_FLAGS_DATA;213 pSym->fFlags |= KDBGSYM_FLAGS_DATA; 225 214 if (Buf.Sym.Flags & SYMFLAG_EXPORT) 226 pSym->fFlags |= RTDBGSYM_FLAGS_EXPORTED;215 pSym->fFlags |= KDBGSYM_FLAGS_EXPORTED; 227 216 if ((Buf.Sym.Flags & (SYMFLAG_VALUEPRESENT | SYMFLAG_CONSTANT)) == (SYMFLAG_VALUEPRESENT | SYMFLAG_CONSTANT)) 228 217 { 229 pSym->iSegment = RTDBGSEG_ABS;230 pSym->offSegment = ( RTUINTPTR)Buf.Sym.Value;231 pSym->RVA = ( RTUINTPTR)Buf.Sym.Value;218 pSym->iSegment = KDBGSEG_ABS; 219 pSym->offSegment = (KDBGADDR)Buf.Sym.Value; 220 pSym->RVA = (KDBGADDR)Buf.Sym.Value; 232 221 } 233 222 else 234 223 { 235 pSym->RVA = ( RTUINTPTR)(Buf.Sym.Address - pModPe->ImageBase);224 pSym->RVA = (KDBGADDR)(Buf.Sym.Address - pModPe->ImageBase); 236 225 rc = rtDbgModPeRVAToSegOff(pModPe, pSym->RVA, &pSym->iSegment, &pSym->offSegment); 237 226 } … … 253 242 254 243 /** 255 * @copydoc RTDBGMODOPS::pfnClose256 */ 257 static DECLCALLBACK(int) rtDbgModPEClose(P RTDBGMOD pMod)258 { 259 P RTDBGMODPE pModPe = (PRTDBGMODPE)pMod;244 * @copydoc KDBGMODOPS::pfnClose 245 */ 246 static DECLCALLBACK(int) rtDbgModPEClose(PKDBGMOD pMod) 247 { 248 PKDBGMODPE pModPe = (PKDBGMODPE)pMod; 260 249 261 250 if (g_pfnSymCleanup(pModPe->hSymInst)) 262 return VINF_SUCCESS;251 return 0; 263 252 264 253 DWORD Err = GetLastError(); … … 272 261 * Methods for a PE module. 273 262 */ 274 static const RTDBGMODOPS g_rtDbgModPEOps =263 static const KDBGMODOPS g_rtDbgModPEOps = 275 264 { 276 265 "PE (dbghelp)", … … 310 299 } 311 300 if (pFileInfo->dwFileVersionMS >= 0x60004) 312 rc = VINF_SUCCESS;301 rc = 0; 313 302 else 314 303 rc = VERR_VERSION_MISMATCH; … … 355 344 strcat(strrchr(pszPath, '\\'), s_szDbgHelp); 356 345 int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 357 if ( RT_SUCCESS(rc))346 if (!rc) 358 347 return rc2; 359 348 if (rc != VERR_VERSION_MISMATCH) … … 442 431 { 443 432 if (g_hDbgHelp) 444 return VINF_SUCCESS;433 return 0; 445 434 446 435 /* primitive locking - make some useful API for this kind of spinning! */ … … 452 441 { 453 442 ASMAtomicXchgU32(&s_u32Lock, 0); 454 return VINF_SUCCESS;443 return 0; 455 444 } 456 445 … … 460 449 char szPath[260]; 461 450 int rc = rtDbgModPEFindDbgHelp(szPath, sizeof(szPath)); 462 if ( RT_FAILURE(rc))451 if (rc) 463 452 { 464 453 ASMAtomicXchgU32(&s_u32Lock, 0); … … 520 509 *s_aFunctions[i].ppfn = pfn; 521 510 } 522 if ( RT_SUCCESS(rc))511 if (!rc) 523 512 { 524 513 ASMAtomicXchgSize(&g_hDbgHelp, hmod); 525 514 ASMAtomicXchgU32(&s_u32Lock, 0); 526 return VINF_SUCCESS;515 return 0; 527 516 } 528 517 } … … 556 545 * 557 546 */ 558 int rtDbgModPEOpen(RTFILE File, RTFOFF offHdr, const char *pszModulePath, PRTDBGMOD *ppDbgMod)547 int kdbgModPEOpen(RTFILE File, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod) 559 548 { 560 549 /* … … 562 551 */ 563 552 IMAGE_FILE_HEADER FHdr; 564 int rc = RTFileReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader), &FHdr, sizeof(FHdr), NULL);553 int rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader), &FHdr, sizeof(FHdr), NULL); 565 554 AssertRCReturn(rc, rc); 566 555 567 556 uint32_t cbImage; 568 557 if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER32)) 569 rc = RTFileReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage),558 rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage), 570 559 &cbImage, sizeof(cbImage), NULL); 571 560 else if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER64)) 572 rc = RTFileReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage),561 rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage), 573 562 &cbImage, sizeof(cbImage), NULL); 574 563 else … … 580 569 */ 581 570 rc = rtDbgModPELoadDbgHelp(); 582 if ( RT_FAILURE(rc))571 if (rc) 583 572 return rc; 584 573 … … 586 575 * Allocate the module and read/construct the section headers. 587 576 */ 588 P RTDBGMODPE pModPe = (PRTDBGMODPE)RTMemAlloc(KDBG_OFFSETOF(RTDBGMODPE, aSections[FHdr.NumberOfSections + 2]));589 AssertReturn(pModPe, VERR_NO_MEMORY);590 pModPe->Core.u32Magic = RTDBGMOD_MAGIC;577 PKDBGMODPE pModPe = (PKDBGMODPE)RTMemAlloc(KDBG_OFFSETOF(KDBGMODPE, aSections[FHdr.NumberOfSections + 2])); 578 AssertReturn(pModPe, KDBG_ERR_NO_MEMORY); 579 pModPe->Core.u32Magic = KDBGMOD_MAGIC; 591 580 pModPe->Core.pOps = &g_rtDbgModPEOps; 592 581 pModPe->Core.File = File; 593 582 pModPe->cbImage = cbImage; 594 583 pModPe->cSections = 1 + FHdr.NumberOfSections; 595 rc = RTFileReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader,584 rc = kDbgHlpReadAt(File, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader, 596 585 &pModPe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections, NULL); 597 if ( RT_SUCCESS(rc))586 if (!rc) 598 587 { 599 588 PIMAGE_SECTION_HEADER pSH = &pModPe->aSections[0]; … … 671 660 AssertRC(rc); 672 661 673 RTMemFree(pModPe);662 kDbgHlpFree(pModPe); 674 663 return rc; 675 664 } -
Property svn:eol-style
set to
-
trunk/kDbg/kDbgModule.cpp
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
r3526 r3528 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 * 4 * kProfile Mark 2 - Debug Info Reader5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net.de> 7 * 3 * kDbg - The Debug Info Reader, Module API. 4 */ 5 6 /* 7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 8 * 9 9 * This file is part of kLIBC. … … 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #ifdef KDBG_USE_IPRT 32 # include <iprt/file.h> 33 # include <iprt/string.h> 34 # include <iprt/err.h> 35 # include <iprt/assert.h> 36 # include <iprt/alloc.h> 37 #else 38 #endif 39 40 #include "kDbgBase.h" 41 #include "DBGInternal.h" 31 #include "kDbg.h" 32 #include "kDbgInternal.h" 33 42 34 #include <kLdrModMZ.h> 43 35 #include <kLdrModPE.h> … … 52 44 * @param ppDbgMod Where to store the debug module handle. 53 45 */ 54 RTDECL(int) RTDbgModuleOpen(const char *pszModulePath, PRTDBGMOD *ppDbgMod)46 KDBG_DECL(int) kDbgModuleOpen(const char *pszModulePath, PKDBGMOD *ppDbgMod) 55 47 { 56 48 /* 57 49 * Validate input. 58 50 */ 59 AssertMsgReturn(VALID_PTR(pszModulePath), ("%p\n", pszModulePath), VERR_INVALID_POINTER);60 AssertMsgReturn(*pszModulePath, ("%p\n", pszModulePath), VERR_INVALID_PARAMETER);61 AssertMsgReturn(VALID_PTR(ppDbgMod), ("%p\n", ppDbgMod), VERR_INVALID_POINTER);51 kDbgAssertPtrReturn(pszModulePath, KDBG_ERR_INVALID_POINTER); 52 kDbgAssertMsgReturn(*pszModulePath, ("%p\n", pszModulePath), KDBG_ERR_INVALID_PARAMETER); 53 kDbgAssertPtrReturn(ppDbgMod, KDBG_ERR_INVALID_POINTER); 62 54 *ppDbgMod = NULL; 63 55 … … 65 57 * The file and try figure out the format. 66 58 */ 67 RTFILEFile;68 int rc = RTFileOpen(&File, pszModulePath, RTFILE_O_READ | RTFILE_O_DENY_WRITE | RTFILE_O_OPEN);69 if ( RT_FAILURE(rc))59 PKDBGHLPFILE pFile; 60 int rc = kDbgHlpOpenRO(pszModulePath, &pFile); 61 if (rc) 70 62 return rc; 71 63 72 RTFOFFoffHdr = 0;64 int64_t offHdr = 0; 73 65 union 74 66 { … … 77 69 uint8_t ab[16]; 78 70 } Buf; 79 rc = RTFileRead(File, &Buf, sizeof(Buf), NULL);80 if ( RT_SUCCESS(rc)71 rc = kDbgHlpRead(pFile, &Buf, sizeof(Buf)); 72 if ( !rc 81 73 && Buf.au16[0] == IMAGE_DOS_SIGNATURE) 82 74 { 83 75 /* new header? */ 84 76 uint32_t offNewHeader; 85 rc = RTFileReadAt(File, KDBG_OFFSETOF(IMAGE_DOS_HEADER, e_lfanew), &offNewHeader, sizeof(offNewHeader), NULL);86 if ( RT_SUCCESS(rc)&& offNewHeader)77 rc = kDbgHlpReadAt(pFile, KDBG_OFFSETOF(IMAGE_DOS_HEADER, e_lfanew), &offNewHeader, sizeof(offNewHeader)); 78 if (!rc && offNewHeader) 87 79 { 88 80 offHdr = offNewHeader; 89 rc = RTFileReadAt(File, offNewHeader, &Buf, sizeof(Buf), NULL);81 rc = kDbgHlpReadAt(pFile, offNewHeader, &Buf, sizeof(Buf)); 90 82 } 91 83 } 92 if ( RT_SUCCESS(rc))84 if (!rc) 93 85 { 94 86 if (Buf.au16[0] == IMAGE_DOS_SIGNATURE) 95 rc = VERR_NOT_SUPPORTED;87 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 96 88 #ifdef IMAGE_NE_SIGNATURE 97 89 else if (Buf.au16[0] == IMAGE_NE_SIGNATURE) 98 rc = VERR_NOT_SUPPORTED;90 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 99 91 #endif 100 92 #ifdef IMAGE_LX_SIGNATURE 101 93 else if (Buf.au16[0] == IMAGE_LX_SIGNATURE) 102 rc = VERR_NOT_SUPPORTED;94 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 103 95 #endif 104 96 #ifdef IMAGE_LE_SIGNATURE 105 97 else if (Buf.au16[0] == IMAGE_LE_SIGNATURE) 106 rc = VERR_NOT_SUPPORTED;98 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 107 99 #endif 108 100 #ifdef IMAGE_ELF_SIGNATURE 109 101 else if (Buf.au32[0] == IMAGE_ELF_SIGNATURE) 110 rc = VERR_NOT_SUPPORTED;102 rc = KDBG_ERR_FORMAT_NOT_SUPPORTED; 111 103 #endif 112 104 #ifdef IMAGE_NT_SIGNATURE 113 105 else if (Buf.au32[0] == IMAGE_NT_SIGNATURE) 114 rc = rtDbgModPEOpen(File, offHdr, pszModulePath, ppDbgMod);106 rc = kdbgModPEOpen(pFile, offHdr, pszModulePath, ppDbgMod); 115 107 #endif 116 108 /** @todo there are a number of text file formats too which I want to support. */ 117 109 else 118 rc = VERR_NOT_SUPPORTED; 119 120 } 121 122 if (RT_FAILURE(rc)) 123 RTFileClose(File); 110 rc = KDBG_ERR_UNKOWN_FORMAT; 111 } 112 113 if (rc) 114 kDbgHlpClose(pFile); 124 115 return rc; 125 116 } … … 133 124 * @param pMod The debug module handle. 134 125 */ 135 DECLINLINE(bool) rtDbgModIsValid(PRTDBGMOD pMod)136 { 137 AssertMsgReturn(VALID_PTR(pMod), ("%p", pMod), false);138 AssertMsgReturn(pMod->u32Magic == RTDBGMOD_MAGIC, ("%RX32", pMod->u32Magic), false);139 AssertMsgReturn(VALID_PTR(pMod->pOps), ("%p", pMod->pOps), false);126 KDBG_INLINE(bool) kdbgModIsValid(PKDBGMOD pMod) 127 { 128 kDbgAssertPtrReturn(pMod, false); 129 kDbgAssertMsgReturn(pMod->u32Magic == KDBGMOD_MAGIC, ("%#x", pMod->u32Magic), false); 130 kDbgAssertPtrReturn(pMod->pOps, false); 140 131 return true; 141 132 } … … 148 139 * @param pMod The module handle. 149 140 */ 150 RTDECL(int) RTDbgModuleClose(PRTDBGMOD pMod)151 { 152 if (! rtDbgModIsValid(pMod))153 return VERR_INVALID_PARAMETER;141 KDBG_DECL(int) kDbgModuleClose(PKDBGMOD pMod) 142 { 143 if (!kdbgModIsValid(pMod)) 144 return KDBG_ERR_INVALID_PARAMETER; 154 145 155 146 int rc = pMod->pOps->pfnClose(pMod); 156 if ( RT_SUCCESS(rc))157 RTMemFree(pMod);147 if (!rc) 148 kDbgHlpFree(pMod); 158 149 return rc; 159 150 } … … 173 164 * @param pSym Where to store the symbol details. 174 165 */ 175 RTDECL(int) RTDbgModuleQuerySymbol(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGSYMBOL pSym)176 { 177 if (! rtDbgModIsValid(pMod))178 return VERR_INVALID_PARAMETER;179 AssertMsgReturn(VALID_PTR(pSym), ("%p", pSym), VERR_INVALID_POINTER);166 KDBG_DECL(int) kDbgModuleQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym) 167 { 168 if (!kdbgModIsValid(pMod)) 169 return KDBG_ERR_INVALID_PARAMETER; 170 kDbgAssertPtrReturn(pSym, KDBG_ERR_INVALID_POINTER); 180 171 181 172 return pMod->pOps->pfnQuerySymbol(pMod, iSegment, off, pSym); … … 195 186 * @param off The offset into the segment. 196 187 * @param ppSym Where to store the pointer to the symbol info. 197 * Free the returned symbol using RTDbgSymbolFree().198 */ 199 RTDECL(int) RTDbgModuleQuerySymbolA(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PPRTDBGSYMBOL ppSym)200 { 201 AssertMsgReturn(VALID_PTR(ppSym), ("%p\n", ppSym), VERR_INVALID_POINTER);202 203 RTDBGSYMBOL Sym;204 int rc = RTDbgModuleQuerySymbol(pMod, iSegment, off, &Sym);205 if ( RT_SUCCESS(rc))206 { 207 *ppSym = RTDbgSymbolDup(&Sym);188 * Free the returned symbol using kDbgSymbolFree(). 189 */ 190 KDBG_DECL(int) kDbgModuleQuerySymbolA(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PPKDBGSYMBOL ppSym) 191 { 192 kDbgAssertPtrReturn(ppSym, KDBG_ERR_INVALID_POINTER); 193 194 KDBGSYMBOL Sym; 195 int rc = kDbgModuleQuerySymbol(pMod, iSegment, off, &Sym); 196 if (!rc) 197 { 198 *ppSym = kDbgSymbolDup(&Sym); 208 199 if (!*ppSym) 209 rc = VERR_NO_MEMORY;200 rc = KDBG_ERR_NO_MEMORY; 210 201 } 211 202 else … … 228 219 * @param pLine Where to store the line number details. 229 220 */ 230 RTDECL(int) RTDbgModuleQueryLine(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGLINE pLine)231 { 232 if (! rtDbgModIsValid(pMod))233 return VERR_INVALID_PARAMETER;234 AssertMsgReturn(VALID_PTR(pLine), ("%p", pLine), VERR_INVALID_POINTER);221 KDBG_DECL(int) kDbgModuleQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine) 222 { 223 if (!kdbgModIsValid(pMod)) 224 return KDBG_ERR_INVALID_PARAMETER; 225 kDbgAssertPtrReturn(pLine, KDBG_ERR_INVALID_POINTER); 235 226 236 227 return pMod->pOps->pfnQueryLine(pMod, iSegment, off, pLine); … … 250 241 * @param off The offset into the segment. 251 242 * @param ppLine Where to store the pointer to the line number info. 252 * Free the returned line number using RTDbgLineFree().253 */ 254 RTDECL(int) RTDbgModuleQueryLineA(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PPRTDBGLINE ppLine)255 { 256 AssertMsgReturn(VALID_PTR(ppLine), ("%p\n", ppLine), VERR_INVALID_POINTER);257 258 RTDBGLINE Line;259 int rc = RTDbgModuleQueryLine(pMod, iSegment, off, &Line);260 if ( RT_SUCCESS(rc))261 { 262 *ppLine = RTDbgLineDup(&Line);243 * Free the returned line number using kDbgLineFree(). 244 */ 245 KDBG_DECL(int) kDbgModuleQueryLineA(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PPKDBGLINE ppLine) 246 { 247 kDbgAssertPtrReturn(ppLine, KDBG_ERR_INVALID_POINTER); 248 249 KDBGLINE Line; 250 int rc = kDbgModuleQueryLine(pMod, iSegment, off, &Line); 251 if (!rc) 252 { 253 *ppLine = kDbgLineDup(&Line); 263 254 if (!*ppLine) 264 rc = VERR_NO_MEMORY;255 rc = KDBG_ERR_NO_MEMORY; 265 256 } 266 257 else -
Property svn:eol-style
set to
-
trunk/kDbg/kDbgSymbol.cpp
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
r3526 r3528 1 /* $Id :$ */1 /* $Id$ */ 2 2 /** @file 3 * 4 * kProfile Mark 2 - Debug Info Symbol.5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-src-spam@anduin.net.de> 7 * 3 * kDbg - The Debug Info Reader, Symbols. 4 */ 5 6 /* 7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 8 * 9 9 * This file is part of kLIBC. … … 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #include <iprt/err.h> 32 #include <iprt/assert.h> 33 #include <iprt/alloc.h> 34 35 #include "kDbgBase.h" 36 #include "dbg.h" 31 #include "kDbg.h" 32 #include "kDbgInternal.h" 37 33 38 34 … … 45 41 * 46 42 * @returns Pointer to the duplicate. 47 * This must be freed using RTDbgSymbolFree().43 * This must be freed using kDbgSymbolFree(). 48 44 * @param pSymbol The symbol to be duplicated. 49 45 */ 50 RTDECL(PRTDBGSYMBOL) RTDbgSymbolDup(PCRTDBGSYMBOL pSymbol)46 KDBG_DECL(PKDBGSYMBOL) kDbgSymbolDup(PCKDBGSYMBOL pSymbol) 51 47 { 52 AssertMsgReturn(VALID_PTR(pSymbol), ("%p\n", pSymbol), NULL);53 size_t cb = KDBG_OFFSETOF( RTDBGSYMBOL, szName[pSymbol->cchName + 1]);54 return (P RTDBGSYMBOL)RTMemDup(pSymbol, cb);48 kDbgAssertPtrReturn(pSymbol, NULL); 49 size_t cb = KDBG_OFFSETOF(KDBGSYMBOL, szName[pSymbol->cchName + 1]); 50 return (PKDBGSYMBOL)kDbgHlpAllocDup(pSymbol, cb); 55 51 } 56 52 … … 59 55 * Frees a symbol obtained from the RTDbg API. 60 56 * 61 * @returns VINF_SUCCESSon success.62 * @returns VERR_INVALID_POINTER if a NULL pointer or an !VALID_PTR() is passed in.57 * @returns 0 on success. 58 * @returns KDBG_ERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in. 63 59 * 64 60 * @param pSymbol The symbol to be freed. 65 61 */ 66 RTDECL(int) RTDbgSymbolFree(PRTDBGSYMBOL pSymbol)62 KDBG_DECL(int) kDbgSymbolFree(PKDBGSYMBOL pSymbol) 67 63 { 68 64 if (!pSymbol) 69 return VERR_INVALID_POINTER;70 AssertMsgReturn(VALID_PTR(pSymbol), ("%p\n", pSymbol), VERR_INVALID_POINTER);65 return KDBG_ERR_INVALID_POINTER; 66 kDbgAssertPtrReturn(pSymbol, KDBG_ERR_INVALID_POINTER); 71 67 72 RTMemFree(pSymbol);73 return VINF_SUCCESS;68 kDbgHlpFree(pSymbol); 69 return 0; 74 70 } 75 71 -
Property svn:eol-style
set to
Note:
See TracChangeset
for help on using the changeset viewer.