Changeset 3528


Ignore:
Timestamp:
Aug 20, 2007, 4:43:13 AM (18 years ago)
Author:
bird
Message:

Some refactoring and OS abstraction by instroducing kDbgHlp.

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$
    22## @file
     3# kDbg - The Debug Info Reader.
    34#
    4 # kProfiler Mark 2
     5
    56#
    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>
    88#
    99# This file is part of kLIBC.
     
    2828include $(PATH_KBUILD)/header.kmk
    2929
    30 #LIBRARIES   = kPrf2GC kPrf2R0
    31 DLLS        = kPrf2
    32 PROGRAMS    = kPrf2Read
    33 
     30#
     31# kDbg - The profiler module.
     32#
     33DLLS += kDbg
     34kDbg_TEMPLATE = kStuffDLL
     35kDbg_DEFS = KDBG_BUILDING KDBG_RESIDES_IN_DLL
     36kDbg_INCS = ../kLdr
     37kDbg_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
    3446
    3547#
    36 # Our template.
     48# kDbgStatic - The profiler module.
    3749#
    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
     50LIBRARIES += kDbgStatic
     51kDbgStatic_TEMPLATE = kStuffLIB
     52kDbgStatic_DEFS = KDBG_BUILDING
     53kDbgStatic_INCS = ../kLdr
     54kDbgStatic_SOURCES = $(kDbg_SOURCES)
    4555
    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
     60kDbgDump_TEMPLATE = kStuffEXE
     61kDbgDump_SOURCES = kDbgDump.cpp
     62kDbgDump_LIBS = $(TARGET_kDbgStatic)
    16463
    16564# Generate the rules
    16665include $(PATH_KBUILD)/footer.kmk
    16766
    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.o
    174 
    175 READ := $(wildcard *read*.cpp.h *read*.h.h)
    176 $(READ:.h=.o) $(READ:.h=.obj) : kPrf2Read.o
    177 
  • trunk/kDbg/kDbg.h

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
    r3524 r3528  
    1 /* $Id: $ */
     1/* $Id$ */
    22/** @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>
    88 *
    99 * This program is free software; you can redistribute it and/or modify
     
    2323 */
    2424
    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
     31extern "C" {
     32#endif
     33
     34/** @defgroup grp_kDbg      Debug Info Reader
    3535 * @{
    3636 */
    3737
    3838/** The max filename path length used by the debug reader. */
    39 #define RTDBG_PATH_MAX      260
     39#define KDBG_PATH_MAX       260
    4040
    4141/** 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/** @} */
    4372
    4473
     
    4877 * The specified offset is relative to the image base. The image base is the lowest memory
    4978 * 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)
    5180/** Absolute segment. The offset isn't relative to anything. */
    52 #define RTDBGSEG_ABS (-2)
     81#define KDBGSEG_ABS (-2)
    5382/** @} */
    5483
     
    5786 * Line number details.
    5887 */
    59 typedef struct RTDBGLINE
     88typedef struct KDBGLINE
    6089{
    6190    /** The relative virtual address. */
    62     RTUINTPTR   RVA;
     91    KDBGADDR    RVA;
    6392    /** The offset into the segment. */
    64     RTUINTPTR   offSegment;
     93    KDBGADDR    offSegment;
    6594    /** The segment number. */
    6695    int32_t     iSegment;
     
    7099    uint16_t    cchFile;
    71100    /** 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;
    74103/** Pointer to line number details. */
    75 typedef RTDBGLINE *PRTDBGLINE;
     104typedef KDBGLINE *PKDBGLINE;
    76105/** Pointer to const line number details. */
    77 typedef const RTDBGLINE *PCRTDBGLINE;
     106typedef const KDBGLINE *PCKDBGLINE;
    78107/** Pointer to a pointer to line number details. */
    79 typedef PRTDBGLINE *PPRTDBGLINE;
     108typedef PKDBGLINE *PPKDBGLINE;
    80109
    81110/**
     
    90119 * @param   pLine       The line number to be duplicated.
    91120 */
    92 RTDECL(PRTDBGLINE) RTDbgLineDup(PCRTDBGLINE pLine);
     121KDBG_DECL(PKDBGLINE) kDbgLineDup(PCKDBGLINE pLine);
    93122
    94123/**
     
    96125 *
    97126 * @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.
    99128 *
    100129 * @param   pLine       The line number to be freed.
    101130 */
    102 RTDECL(int) RTDbgLineFree(PRTDBGLINE pLine);
     131KDBG_DECL(int) kDbgLineFree(PKDBGLINE pLine);
    103132
    104133
     
    106135 * @{ */
    107136/** The symbol is weak. */
    108 #define RTDBGSYM_FLAGS_WEAK     BIT(0)
     137#define KDBGSYM_FLAGS_WEAK      UINT32_C(0x00000000)
    109138/** The symbol is absolute.
    110139 * (This also indicated by the segment number.) */
    111 #define RTDBGSYM_FLAGS_ABS      BIT(1)
     140#define KDBGSYM_FLAGS_ABS       UINT32_C(0x00000001)
    112141/** The symbol is exported. */
    113 #define RTDBGSYM_FLAGS_EXPORTED BIT(2)
     142#define KDBGSYM_FLAGS_EXPORTED  UINT32_C(0x00000002)
    114143/** 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)
    116145/** The symbol is some kind of data. */
    117 #define RTDBGSYM_FLAGS_DATA     BIT(4)
     146#define KDBGSYM_FLAGS_DATA      UINT32_C(0x00000008)
    118147/** @} */
    119148
     
    121150 * Symbol details.
    122151 */
    123 typedef struct RTDBGSYMBOL
     152typedef struct KDBGSYMBOL
    124153{
    125154    /** The relative virtual address. */
    126     RTUINTPTR   RVA;
     155    KDBGADDR    RVA;
    127156    /** The symbol size.
    128157     * This is not a reliable field, it could be a bad guess. Ignore if zero. */
    129     RTUINTPTR   cb;
     158    KDBGADDR    cb;
    130159    /** The offset into the segment. */
    131     RTUINTPTR   offSegment;
     160    KDBGADDR    offSegment;
    132161    /** The segment number. */
    133162    int32_t     iSegment;
     
    138167    uint16_t    cchName;
    139168    /** The symbol name. */
    140     char        szName[RTDBG_SYMBOL_MAX];
    141 } RTDBGSYMBOL;
     169    char        szName[KDBG_SYMBOL_MAX];
     170} KDBGSYMBOL;
    142171/** Pointer to symbol details. */
    143 typedef RTDBGSYMBOL *PRTDBGSYMBOL;
     172typedef KDBGSYMBOL *PKDBGSYMBOL;
    144173/** Pointer to const symbol details. */
    145 typedef const RTDBGSYMBOL *PCRTDBGSYMBOL;
     174typedef const KDBGSYMBOL *PCKDBGSYMBOL;
    146175/** Pointer to a pointer to symbol details. */
    147 typedef PRTDBGSYMBOL *PPRTDBGSYMBOL;
    148 
     176typedef PKDBGSYMBOL *PPKDBGSYMBOL;
    149177
    150178/**
     
    156184 *
    157185 * @returns Pointer to the duplicate.
    158  *          This must be freed using RTDbgSymbolFree().
     186 *          This must be freed using kDbgSymbolFree().
    159187 * @param   pSymbol     The symbol to be freed.
    160188 */
    161 RTDECL(PRTDBGSYMBOL) RTDbgSymbolDup(PCRTDBGSYMBOL pSymbol);
    162 
    163 /**
    164  * Frees a symbol obtained from the RTDbg API.
     189KDBG_DECL(PKDBGSYMBOL) kDbgSymbolDup(PCKDBGSYMBOL pSymbol);
     190
     191/**
     192 * Frees a symbol obtained from the kDbg API.
    165193 *
    166194 * @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.
    168196 *
    169197 * @param   pSymbol     The symbol to be freed.
    170198 */
    171 RTDECL(int) RTDbgSymbolFree(PRTDBGSYMBOL pSymbol);
     199KDBG_DECL(int) kDbgSymbolFree(PKDBGSYMBOL pSymbol);
    172200
    173201
    174202
    175203/** A debug module handle. */
    176 typedef struct RTDBGMOD *PRTDBGMOD;
     204typedef struct KDBGMOD *PKDBGMOD;
    177205
    178206/**
     
    183211 * @param   ppDbgMod            Where to store the debug module handle.
    184212 */
    185 RTDECL(int) RTDbgModuleOpen(const char *pszModulePath, PRTDBGMOD *ppDbgMod);
     213KDBG_DECL(int) kDbgModuleOpen(const char *pszModulePath, PKDBGMOD *ppDbgMod);
    186214
    187215/**
     
    191219 * @param   pMod        The module handle.
    192220 */
    193 RTDECL(int) RTDbgModuleClose(PRTDBGMOD pMod);
     221KDBG_DECL(int) kDbgModuleClose(PKDBGMOD pMod);
    194222
    195223/**
     
    206234 * @param   pSym        Where to store the symbol details.
    207235 */
    208 RTDECL(int) RTDbgModuleQuerySymbol(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGSYMBOL pSym);
     236KDBG_DECL(int) kDbgModuleQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym);
    209237
    210238/**
     
    220248 * @param   off         The offset into the segment.
    221249 * @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 */
     252KDBG_DECL(int) kDbgModuleQuerySymbolA(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PPKDBGSYMBOL ppSym);
    225253
    226254/**
     
    237265 * @param   pLine       Where to store the line number details.
    238266 */
    239 RTDECL(int) RTDbgModuleQueryLine(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGLINE pLine);
     267KDBG_DECL(int) kDbgModuleQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine);
    240268
    241269/**
     
    251279 * @param   off         The offset into the segment.
    252280 * @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 */
     283KDBG_DECL(int) kDbgModuleQueryLineA(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PPKDBGLINE ppLine);
     284
     285
     286/** @} */
     287
     288#ifdef __cplusplus
     289}
    262290#endif
     291
     292#endif
  • trunk/kDbg/kDbgBase.h

    • Property svn:eol-style set to native
    r3526 r3528  
    11/* $Id$ */
    22/** @file
    3  *
    43 * kDbg - The Debug Info Reader, Base Definitions and Typedefs.
    5  *
     4 */
     5
     6/*
    67 * Copyright (c) 2006-2007 knut st. osmundsen <bird@anduin.net>
    78 *
     
    7879
    7980
     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. */
     133typedef uint64_t KDBGADDR;
     134/** Pointer to a kLdr address. */
     135typedef KDBGADDR *PKDBGADDR;
     136/** Pointer to a const kLdr address. */
     137typedef 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
    80151/** Get the minimum of two values. */
    81152#define KDBG_MIN(a, b)              ((a) <= (b) ? (a) : (b))
     
    89160#define KDBG_ALIGN_P(pv, align)     ( (void *)( ((uintptr_t)(pv) + ((align) - 1)) & ~(uintptr_t)((align) - 1) ) )
    90161/** Align a size_t value. */
    91 #define KDBG_ALIGN_ADDR(val, align) ( ((val) + ((align) - 1)) & ~(KLDRADDR)((align) - 1) )
     162#define KDBG_ALIGN_ADDR(val, align) ( ((val) + ((align) - 1)) & ~(KDBGADDR)((align) - 1) )
    92163/** Number of elements in an array. */
    93164#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 )
    94168
    95169
  • trunk/kDbg/kDbgInternal.h

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
    r3524 r3528  
    1 /* $Id: $ */
     1/* $Id$ */
    22/** @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>
    88 *
    99 * This program is free software; you can redistribute it and/or modify
     
    2323 */
    2424
    25 #ifndef __internal_DBGInternal_h__
    26 #define __internal_DBGInternal_h__
     25#ifndef ___kDbgInternal_h___
     26#define ___kDbgInternal_h___
    2727
    28 #include "dbg.h"
     28#include "kDbgBase.h"
     29#include "kDbgHlp.h"
     30#include "kDbg.h"
    2931
    30 __BEGIN_DECLS
     32#ifdef __cplusplus
     33extern "C" {
     34#endif
    3135
    3236
     
    3438 * The debug module method table.
    3539 */
    36 typedef struct RTDBGMODOPS
     40typedef struct KDBGMODOPS
    3741{
    3842    /** The name of the reader. */
     
    4852     * @param   pMod        The module.
    4953     */
    50     DECLCALLBACKMEMBER(int, pfnClose)(PRTDBGMOD pMod);
     54    int (*pfnClose)(PKDBGMOD pMod);
    5155
    5256    /**
     
    6367     * @param   pSym        Where to store the symbol details.
    6468     */
    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);
    6670
    6771    /**
     
    7882     * @param   pLine       Where to store the line number details.
    7983     */
    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);
    8185
    82 } RTDBGMODOPS;
     86} KDBGMODOPS;
    8387/** Pointer to a module method table. */
    84 typedef RTDBGMODOPS *PRTDBGMODOPS;
     88typedef KDBGMODOPS *PKDBGMODOPS;
    8589/** Pointer to a const module method table. */
    86 typedef const RTDBGMODOPS *PCRTDBGMODOPS;
     90typedef const KDBGMODOPS *PCKDBGMODOPS;
    8791
    8892
     
    9094 * Internal representation of a debug module.
    9195 */
    92 typedef struct RTDBGMOD
     96typedef struct KDBGMOD
    9397{
    94     /** Magic value (RTDBGMOD_MAGIC). */
     98    /** Magic value (KDBGMOD_MAGIC). */
    9599    uint32_t        u32Magic;
    96100    /** The handle to the module. (If closed, this is NIL_RTFILE.) */
    97     RTFILE          File;
     101    PKDBGHLPFILE    pFile;
    98102    /** Pointer to the method table. */
    99     PCRTDBGMODOPS   pOps;
    100 } RTDBGMOD;
     103    PCKDBGMODOPS    pOps;
     104} KDBGMOD;
    101105
    102106
    103 /** The magic value for the debug module structure. (Some english writer) */
    104 #define RTDBGMOD_MAGIC      0x00000000
     107/** The magic value for the debug module structure. (Some dead english writer) */
     108#define KDBGMOD_MAGIC      0x00000000
    105109/** The magic value of a dead module structure. */
    106 #define RTDBGMOD_MAGIC_DEAD 0x00000000
     110#define KDBGMOD_MAGIC_DEAD 0x00000001
    107111
    108112
    109 int rtDbgModPEOpen(RTFILE File, RTFOFF offHdr, const char *pszModulePath, PRTDBGMOD *ppDbgMod);
     113int kdbgModPEOpen(PKDBGHLPFILE pFile, KDBGADDR offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod);
    110114
    111 
    112 __END_DECLS
     115#ifdef __cplusplus
     116}
    113117#endif
    114118
     119#endif
     120
  • trunk/kDbg/kDbgLine.cpp

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
    r3526 r3528  
    1 /* $Id: $ */
     1/* $Id$ */
    22/** @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>
    88 *
    99 * This file is part of kLIBC.
     
    2929*   Header Files                                                               *
    3030*******************************************************************************/
    31 #include <iprt/err.h>
    32 #include <iprt/assert.h>
    33 #include <iprt/alloc.h>
     31#include "kDbg.h"
     32#include "kDbgInternal.h"
    3433
    35 #include "dbg.h"
    36 #include "kDbgBase.h"
    3734
    3835
     
    4542 *
    4643 * @returns Pointer to the duplicate.
    47  *          This must be freed using RTDbgSymbolFree().
     44 *          This must be freed using kDbgSymbolFree().
    4845 * @param   pLine       The line number to be duplicated.
    4946 */
    50 RTDECL(PRTDBGLINE) RTDbgLineDup(PCRTDBGLINE pLine)
     47KDBG_DECL(PKDBGLINE) kDbgLineDup(PCKDBGLINE pLine)
    5148{
    52     AssertMsgReturn(VALID_PTR(pLine), ("%p\n", pLine), NULL);
    53     size_t cb = KDBG_OFFSETOF(RTDBGLINE, szFile[pLine->cchFile + 1]);
    54     return (PRTDBGLINE)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);
    5552}
    5653
     
    5956 * Frees a line number obtained from the RTDbg API.
    6057 *
    61  * @returns VINF_SUCCESS on 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.
    6360 *
    6461 * @param   pLine       The line number to be freed.
    6562 */
    66 RTDECL(int) RTDbgLineFree(PRTDBGLINE pLine)
     63KDBG_DECL(int) kDbgLineFree(PKDBGLINE pLine)
    6764{
    6865    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);
    7168
    72     RTMemFree(pLine);
    73     return VINF_SUCCESS;
     69    kDbgHlpFree(pLine);
     70    return 0;
    7471}
    7572
  • trunk/kDbg/kDbgModPE-generic.cpp

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
    r3526 r3528  
    1 /* $Id: $ */
     1/* $Id$ */
    22/** @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>
    88 *
    99 * This file is part of kLIBC.
     
    2525 */
    2626
    27 
    2827/*******************************************************************************
    2928*   Header Files                                                               *
    3029*******************************************************************************/
    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>
    4333
    4434
     
    4939 * A dbghelp based PE debug reader.
    5040 */
    51 typedef struct RTDBGMODPE
     41typedef struct KDBGMODPE
    5242{
    5343    /** The common module core. */
    54     RTDBGMOD    Core;
     44    KDBGMOD     Core;
    5545    /** The image size. */
    5646    uint32_t    cbImage;
     
    5949    /** The section headers (variable size). The first section is the
    6050     * implicit header section.*/
    61     IMAGE_SECTION_HEADER    aSections[1];
    62 } RTDBGMODPE, *PRTDBGMODPE;
     51    IMAGE_SECTION_HEADER aSections[1];
     52} KDBGMODPE, *PKDBGMODPE;
    6353
    6454
     
    7363 * @param   puRVA       Where to store the RVA on success.
    7464 */
    75 static int rtDbgModPeSegOffToRVA(PRTDBGMODPE pModPe, int32_t iSegment, RTUINTPTR off, uint32_t *puRVA)
     65static int rtDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
    7666{
    7767    if (iSegment >= 0)
    7868    {
    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);
    8474        *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);
    9282        *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);
    9686}
    9787
     
    10797 * @param   poff        Where to store the segment offset.
    10898 */
    109 static int rtDbgModPeRVAToSegOff(PRTDBGMODPE 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);
     99static 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);
    113103    for (int32_t iSegment = 0; iSegment < pModPe->cSections; iSegment++)
    114104    {
     
    119109            *poff = off;
    120110            *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::pfnQueryLine
    130  */
    131 static DECLCALLBACK(int) rtDbgModPEQueryLine(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGLINE pLine)
    132 {
    133     PRTDBGMODPE 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 */
     121static DECLCALLBACK(int) rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
     122{
     123    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
    134124
    135125    /*
     
    138128    uint32_t uRVA;
    139129    int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
    140     if (RT_SUCCESS(rc))
     130    if (!rc)
    141131    {
    142132#if 0
     
    146136        if (g_pfnSymGetLineFromAddr64(pModPe->hSymInst, pModPe->ImageBase + uRVA, &off, &Line))
    147137        {
    148             pLine->RVA = (RTUINTPTR)(Line.Address - pModPe->ImageBase);
     138            pLine->RVA = (KDBGADDR)(Line.Address - pModPe->ImageBase);
    149139            rc = rtDbgModPeRVAToSegOff(pModPe, pLine->RVA, &pLine->iSegment, &pLine->offSegment);
    150140            pLine->iLine = Line.LineNumber;
     
    167157
    168158/**
    169  * @copydoc RTDBGMODOPS::pfnQuerySymbol
    170  */
    171 static DECLCALLBACK(int) rtDbgModPEQuerySymbol(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGSYMBOL pSym)
    172 {
    173     PRTDBGMODPE pModPe = (PRTDBGMODPE)pMod;
     159 * @copydoc KDBGMODOPS::pfnQuerySymbol
     160 */
     161static DECLCALLBACK(int) rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
     162{
     163    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
    174164
    175165    /*
     
    178168    uint32_t uRVA;
    179169    int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
    180     if (RT_SUCCESS(rc))
     170    if (!rc)
    181171    {
    182172#if 0
     
    194184            pSym->fFlags = 0;
    195185            if (Buf.Sym.Flags & SYMFLAG_FUNCTION)
    196                 pSym->fFlags |= RTDBGSYM_FLAGS_CODE;
     186                pSym->fFlags |= KDBGSYM_FLAGS_CODE;
    197187            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.*/
    199189            else
    200                 pSym->fFlags |= RTDBGSYM_FLAGS_DATA;
     190                pSym->fFlags |= KDBGSYM_FLAGS_DATA;
    201191            if (Buf.Sym.Flags & SYMFLAG_EXPORT)
    202                 pSym->fFlags |= RTDBGSYM_FLAGS_EXPORTED;
     192                pSym->fFlags |= KDBGSYM_FLAGS_EXPORTED;
    203193            if ((Buf.Sym.Flags & (SYMFLAG_VALUEPRESENT | SYMFLAG_CONSTANT)) == (SYMFLAG_VALUEPRESENT | SYMFLAG_CONSTANT))
    204194            {
    205195                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;
    208198            }
    209199            else
    210200            {
    211                 pSym->RVA        = (RTUINTPTR)(Buf.Sym.Address - pModPe->ImageBase);
     201                pSym->RVA        = (KDBGADDR)(Buf.Sym.Address - pModPe->ImageBase);
    212202                rc = rtDbgModPeRVAToSegOff(pModPe, pSym->RVA, &pSym->iSegment, &pSym->offSegment);
    213203            }
     
    231221
    232222/**
    233  * @copydoc RTDBGMODOPS::pfnClose
    234  */
    235 static DECLCALLBACK(int) rtDbgModPEClose(PRTDBGMOD pMod)
    236 {
    237     PRTDBGMODPE pModPe = (PRTDBGMODPE)pMod;
     223 * @copydoc KDBGMODOPS::pfnClose
     224 */
     225static DECLCALLBACK(int) rtDbgModPEClose(PKDBGMOD pMod)
     226{
     227    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
    238228
    239229    //if (g_pfnSymCleanup(pModPe->hSymInst))
    240     //    return VINF_SUCCESS;
     230    //    return 0;
    241231    //
    242232    //DWORD Err = GetLastError();
     
    251241 * Methods for a PE module.
    252242 */
    253 static const RTDBGMODOPS g_rtDbgModPEOps =
     243static const KDBGMODOPS g_rtDbgModPEOps =
    254244{
    255245    "PE (dbghelp)",
     
    271261 *
    272262 */
    273 int rtDbgModPEOpen(RTFILE File, RTFOFF offHdr, const char *pszModulePath, PRTDBGMOD *ppDbgMod)
     263int kdbgModPEOpen(RTFILE File, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
    274264{
    275265    /*
     
    277267     */
    278268    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);
    280270    AssertRCReturn(rc, rc);
    281271
    282272    uint32_t cbImage;
    283273    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),
    285275                          &cbImage, sizeof(cbImage), NULL);
    286276    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),
    288278                          &cbImage, sizeof(cbImage), NULL);
    289279    else
     
    294284     * Allocate the module and read/construct the section headers.
    295285     */
    296     PRTDBGMODPE 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;
    299289    pModPe->Core.pOps       = &g_rtDbgModPEOps;
    300290    pModPe->Core.File       = File;
    301291    pModPe->cbImage         = cbImage;
    302292    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,
    304294                      &pModPe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections, NULL);
    305     if (RT_SUCCESS(rc))
     295    if (!rc)
    306296    {
    307297        PIMAGE_SECTION_HEADER pSH = &pModPe->aSections[0];
     
    382372        AssertRC(rc);
    383373
    384     RTMemFree(pModPe);
     374    kDbgHlpFree(pModPe);
    385375    return rc;
    386376}
  • trunk/kDbg/kDbgModPE-win.cpp

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
    r3526 r3528  
    1 /* $Id: $ */
     1/* $Id$ */
    22/** @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>
    88 *
    99 * This file is part of kLIBC.
     
    3333#include <DbgHelp.h>
    3434
    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
    4837
    4938/*******************************************************************************
     
    7362 * A dbghelp based PE debug reader.
    7463 */
    75 typedef struct RTDBGMODPE
     64typedef struct KDBGMODPE
    7665{
    7766    /** The common module core. */
    78     RTDBGMOD    Core;
     67    KDBGMOD    Core;
    7968    /** The image base. */
    8069    DWORD64     ImageBase;
     
    8877     * implicit header section.*/
    8978    IMAGE_SECTION_HEADER    aSections[1];
    90 } RTDBGMODPE, *PRTDBGMODPE;
     79} KDBGMODPE, *PKDBGMODPE;
    9180
    9281
     
    10190 * @param   puRVA       Where to store the RVA on success.
    10291 */
    103 static int rtDbgModPeSegOffToRVA(PRTDBGMODPE pModPe, int32_t iSegment, RTUINTPTR off, uint32_t *puRVA)
     92static int rtDbgModPeSegOffToRVA(PKDBGMODPE pModPe, int32_t iSegment, KDBGADDR off, uint32_t *puRVA)
    10493{
    10594    if (iSegment >= 0)
    10695    {
    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);
    112101        *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);
    120109        *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);
    124113}
    125114
     
    135124 * @param   poff        Where to store the segment offset.
    136125 */
    137 static int rtDbgModPeRVAToSegOff(PRTDBGMODPE 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);
     126static 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);
    141130    for (int32_t iSegment = 0; iSegment < pModPe->cSections; iSegment++)
    142131    {
     
    147136            *poff = off;
    148137            *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::pfnQueryLine
    158  */
    159 static DECLCALLBACK(int) rtDbgModPEQueryLine(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGLINE pLine)
    160 {
    161     PRTDBGMODPE 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 */
     148static DECLCALLBACK(int) rtDbgModPEQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine)
     149{
     150    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
    162151
    163152    /*
     
    166155    uint32_t uRVA;
    167156    int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
    168     if (RT_SUCCESS(rc))
     157    if (!rc)
    169158    {
    170159        DWORD64 off;
     
    173162        if (g_pfnSymGetLineFromAddr64(pModPe->hSymInst, pModPe->ImageBase + uRVA, &off, &Line))
    174163        {
    175             pLine->RVA = (RTUINTPTR)(Line.Address - pModPe->ImageBase);
     164            pLine->RVA = (KDBGADDR)(Line.Address - pModPe->ImageBase);
    176165            rc = rtDbgModPeRVAToSegOff(pModPe, pLine->RVA, &pLine->iSegment, &pLine->offSegment);
    177166            pLine->iLine = Line.LineNumber;
     
    192181
    193182/**
    194  * @copydoc RTDBGMODOPS::pfnQuerySymbol
    195  */
    196 static DECLCALLBACK(int) rtDbgModPEQuerySymbol(PRTDBGMOD pMod, int32_t iSegment, RTUINTPTR off, PRTDBGSYMBOL pSym)
    197 {
    198     PRTDBGMODPE pModPe = (PRTDBGMODPE)pMod;
     183 * @copydoc KDBGMODOPS::pfnQuerySymbol
     184 */
     185static DECLCALLBACK(int) rtDbgModPEQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym)
     186{
     187    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
    199188
    200189    /*
     
    203192    uint32_t uRVA;
    204193    int rc = rtDbgModPeSegOffToRVA(pModPe, iSegment, off, &uRVA);
    205     if (RT_SUCCESS(rc))
     194    if (!rc)
    206195    {
    207196        DWORD64 off;
     
    209198        {
    210199            SYMBOL_INFO Sym;
    211             char        achBuffer[sizeof(SYMBOL_INFO) + RTDBG_SYMBOL_MAX];
     200            char        achBuffer[sizeof(SYMBOL_INFO) + KDBG_SYMBOL_MAX];
    212201        } Buf;
    213202        Buf.Sym.SizeOfStruct = sizeof(SYMBOL_INFO);
    214         Buf.Sym.MaxNameLen = RTDBG_SYMBOL_MAX;
     203        Buf.Sym.MaxNameLen = KDBG_SYMBOL_MAX;
    215204        if (g_pfnSymFromAddr(pModPe->hSymInst, pModPe->ImageBase + uRVA, &off, &Buf.Sym))
    216205        {
     
    218207            pSym->fFlags = 0;
    219208            if (Buf.Sym.Flags & SYMFLAG_FUNCTION)
    220                 pSym->fFlags |= RTDBGSYM_FLAGS_CODE;
     209                pSym->fFlags |= KDBGSYM_FLAGS_CODE;
    221210            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.*/
    223212            else
    224                 pSym->fFlags |= RTDBGSYM_FLAGS_DATA;
     213                pSym->fFlags |= KDBGSYM_FLAGS_DATA;
    225214            if (Buf.Sym.Flags & SYMFLAG_EXPORT)
    226                 pSym->fFlags |= RTDBGSYM_FLAGS_EXPORTED;
     215                pSym->fFlags |= KDBGSYM_FLAGS_EXPORTED;
    227216            if ((Buf.Sym.Flags & (SYMFLAG_VALUEPRESENT | SYMFLAG_CONSTANT)) == (SYMFLAG_VALUEPRESENT | SYMFLAG_CONSTANT))
    228217            {
    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;
    232221            }
    233222            else
    234223            {
    235                 pSym->RVA        = (RTUINTPTR)(Buf.Sym.Address - pModPe->ImageBase);
     224                pSym->RVA        = (KDBGADDR)(Buf.Sym.Address - pModPe->ImageBase);
    236225                rc = rtDbgModPeRVAToSegOff(pModPe, pSym->RVA, &pSym->iSegment, &pSym->offSegment);
    237226            }
     
    253242
    254243/**
    255  * @copydoc RTDBGMODOPS::pfnClose
    256  */
    257 static DECLCALLBACK(int) rtDbgModPEClose(PRTDBGMOD pMod)
    258 {
    259     PRTDBGMODPE pModPe = (PRTDBGMODPE)pMod;
     244 * @copydoc KDBGMODOPS::pfnClose
     245 */
     246static DECLCALLBACK(int) rtDbgModPEClose(PKDBGMOD pMod)
     247{
     248    PKDBGMODPE pModPe = (PKDBGMODPE)pMod;
    260249
    261250    if (g_pfnSymCleanup(pModPe->hSymInst))
    262         return VINF_SUCCESS;
     251        return 0;
    263252
    264253    DWORD Err = GetLastError();
     
    272261 * Methods for a PE module.
    273262 */
    274 static const RTDBGMODOPS g_rtDbgModPEOps =
     263static const KDBGMODOPS g_rtDbgModPEOps =
    275264{
    276265    "PE (dbghelp)",
     
    310299                }
    311300                if (pFileInfo->dwFileVersionMS >= 0x60004)
    312                     rc = VINF_SUCCESS;
     301                    rc = 0;
    313302                else
    314303                    rc = VERR_VERSION_MISMATCH;
     
    355344        strcat(strrchr(pszPath, '\\'), s_szDbgHelp);
    356345        int rc2 = rtDbgModPETryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS);
    357         if (RT_SUCCESS(rc))
     346        if (!rc)
    358347            return rc2;
    359348        if (rc != VERR_VERSION_MISMATCH)
     
    442431{
    443432    if (g_hDbgHelp)
    444         return VINF_SUCCESS;
     433        return 0;
    445434
    446435    /* primitive locking - make some useful API for this kind of spinning! */
     
    452441    {
    453442        ASMAtomicXchgU32(&s_u32Lock, 0);
    454         return VINF_SUCCESS;
     443        return 0;
    455444    }
    456445
     
    460449    char szPath[260];
    461450    int rc = rtDbgModPEFindDbgHelp(szPath, sizeof(szPath));
    462     if (RT_FAILURE(rc))
     451    if (rc)
    463452    {
    464453        ASMAtomicXchgU32(&s_u32Lock, 0);
     
    520509                *s_aFunctions[i].ppfn = pfn;
    521510            }
    522             if (RT_SUCCESS(rc))
     511            if (!rc)
    523512            {
    524513                ASMAtomicXchgSize(&g_hDbgHelp, hmod);
    525514                ASMAtomicXchgU32(&s_u32Lock, 0);
    526                 return VINF_SUCCESS;
     515                return 0;
    527516            }
    528517        }
     
    556545 *
    557546 */
    558 int rtDbgModPEOpen(RTFILE File, RTFOFF offHdr, const char *pszModulePath, PRTDBGMOD *ppDbgMod)
     547int kdbgModPEOpen(RTFILE File, int64_t offHdr, const char *pszModulePath, PKDBGMOD *ppDbgMod)
    559548{
    560549    /*
     
    562551     */
    563552    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);
    565554    AssertRCReturn(rc, rc);
    566555
    567556    uint32_t cbImage;
    568557    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),
    570559                          &cbImage, sizeof(cbImage), NULL);
    571560    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),
    573562                          &cbImage, sizeof(cbImage), NULL);
    574563    else
     
    580569     */
    581570    rc = rtDbgModPELoadDbgHelp();
    582     if (RT_FAILURE(rc))
     571    if (rc)
    583572        return rc;
    584573
     
    586575     * Allocate the module and read/construct the section headers.
    587576     */
    588     PRTDBGMODPE 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;
    591580    pModPe->Core.pOps       = &g_rtDbgModPEOps;
    592581    pModPe->Core.File       = File;
    593582    pModPe->cbImage         = cbImage;
    594583    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,
    596585                      &pModPe->aSections[1], sizeof(pModPe->aSections[0]) * FHdr.NumberOfSections, NULL);
    597     if (RT_SUCCESS(rc))
     586    if (!rc)
    598587    {
    599588        PIMAGE_SECTION_HEADER pSH = &pModPe->aSections[0];
     
    671660        AssertRC(rc);
    672661
    673     RTMemFree(pModPe);
     662    kDbgHlpFree(pModPe);
    674663    return rc;
    675664}
  • trunk/kDbg/kDbgModule.cpp

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
    r3526 r3528  
    1 /* $Id: $ */
     1/* $Id$ */
    22/** @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, Module API.
     4 */
     5
     6/*
     7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net>
    88 *
    99 * This file is part of kLIBC.
     
    2929*   Header Files                                                               *
    3030*******************************************************************************/
    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
    4234#include <kLdrModMZ.h>
    4335#include <kLdrModPE.h>
     
    5244 * @param   ppDbgMod            Where to store the debug module handle.
    5345 */
    54 RTDECL(int) RTDbgModuleOpen(const char *pszModulePath, PRTDBGMOD *ppDbgMod)
     46KDBG_DECL(int) kDbgModuleOpen(const char *pszModulePath, PKDBGMOD *ppDbgMod)
    5547{
    5648    /*
    5749     * Validate input.
    5850     */
    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);
    6254    *ppDbgMod = NULL;
    6355
     
    6557     * The file and try figure out the format.
    6658     */
    67     RTFILE File;
    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)
    7062        return rc;
    7163
    72     RTFOFF offHdr = 0;
     64    int64_t offHdr = 0;
    7365    union
    7466    {
     
    7769        uint8_t     ab[16];
    7870    } Buf;
    79     rc = RTFileRead(File, &Buf, sizeof(Buf), NULL);
    80     if (    RT_SUCCESS(rc)
     71    rc = kDbgHlpRead(pFile, &Buf, sizeof(Buf));
     72    if (    !rc
    8173        &&  Buf.au16[0] == IMAGE_DOS_SIGNATURE)
    8274    {
    8375        /* new header? */
    8476        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)
    8779        {
    8880            offHdr = offNewHeader;
    89             rc = RTFileReadAt(File, offNewHeader, &Buf, sizeof(Buf), NULL);
     81            rc = kDbgHlpReadAt(pFile, offNewHeader, &Buf, sizeof(Buf));
    9082        }
    9183    }
    92     if (RT_SUCCESS(rc))
     84    if (!rc)
    9385    {
    9486        if (Buf.au16[0] == IMAGE_DOS_SIGNATURE)
    95             rc = VERR_NOT_SUPPORTED;
     87            rc = KDBG_ERR_FORMAT_NOT_SUPPORTED;
    9688#ifdef IMAGE_NE_SIGNATURE
    9789        else if (Buf.au16[0] == IMAGE_NE_SIGNATURE)
    98             rc = VERR_NOT_SUPPORTED;
     90            rc = KDBG_ERR_FORMAT_NOT_SUPPORTED;
    9991#endif
    10092#ifdef IMAGE_LX_SIGNATURE
    10193        else if (Buf.au16[0] == IMAGE_LX_SIGNATURE)
    102             rc = VERR_NOT_SUPPORTED;
     94            rc = KDBG_ERR_FORMAT_NOT_SUPPORTED;
    10395#endif
    10496#ifdef IMAGE_LE_SIGNATURE
    10597        else if (Buf.au16[0] == IMAGE_LE_SIGNATURE)
    106             rc = VERR_NOT_SUPPORTED;
     98            rc = KDBG_ERR_FORMAT_NOT_SUPPORTED;
    10799#endif
    108100#ifdef IMAGE_ELF_SIGNATURE
    109101        else if (Buf.au32[0] == IMAGE_ELF_SIGNATURE)
    110             rc = VERR_NOT_SUPPORTED;
     102            rc = KDBG_ERR_FORMAT_NOT_SUPPORTED;
    111103#endif
    112104#ifdef IMAGE_NT_SIGNATURE
    113105        else if (Buf.au32[0] == IMAGE_NT_SIGNATURE)
    114             rc = rtDbgModPEOpen(File, offHdr, pszModulePath, ppDbgMod);
     106            rc = kdbgModPEOpen(pFile, offHdr, pszModulePath, ppDbgMod);
    115107#endif
    116108        /** @todo there are a number of text file formats too which I want to support. */
    117109        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);
    124115    return rc;
    125116}
     
    133124 * @param   pMod        The debug module handle.
    134125 */
    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);
     126KDBG_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);
    140131    return true;
    141132}
     
    148139 * @param   pMod        The module handle.
    149140 */
    150 RTDECL(int) RTDbgModuleClose(PRTDBGMOD pMod)
    151 {
    152     if (!rtDbgModIsValid(pMod))
    153         return VERR_INVALID_PARAMETER;
     141KDBG_DECL(int) kDbgModuleClose(PKDBGMOD pMod)
     142{
     143    if (!kdbgModIsValid(pMod))
     144        return KDBG_ERR_INVALID_PARAMETER;
    154145
    155146    int rc = pMod->pOps->pfnClose(pMod);
    156     if (RT_SUCCESS(rc))
    157         RTMemFree(pMod);
     147    if (!rc)
     148        kDbgHlpFree(pMod);
    158149    return rc;
    159150}
     
    173164 * @param   pSym        Where to store the symbol details.
    174165 */
    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);
     166KDBG_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);
    180171
    181172    return pMod->pOps->pfnQuerySymbol(pMod, iSegment, off, pSym);
     
    195186 * @param   off         The offset into the segment.
    196187 * @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 */
     190KDBG_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);
    208199        if (!*ppSym)
    209             rc = VERR_NO_MEMORY;
     200            rc = KDBG_ERR_NO_MEMORY;
    210201    }
    211202    else
     
    228219 * @param   pLine       Where to store the line number details.
    229220 */
    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);
     221KDBG_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);
    235226
    236227    return pMod->pOps->pfnQueryLine(pMod, iSegment, off, pLine);
     
    250241 * @param   off         The offset into the segment.
    251242 * @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 */
     245KDBG_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);
    263254        if (!*ppLine)
    264             rc = VERR_NO_MEMORY;
     255            rc = KDBG_ERR_NO_MEMORY;
    265256    }
    266257    else
  • trunk/kDbg/kDbgSymbol.cpp

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
    r3526 r3528  
    1 /* $Id: $ */
     1/* $Id$ */
    22/** @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>
    88 *
    99 * This file is part of kLIBC.
     
    2929*   Header Files                                                               *
    3030*******************************************************************************/
    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"
    3733
    3834
     
    4541 *
    4642 * @returns Pointer to the duplicate.
    47  *          This must be freed using RTDbgSymbolFree().
     43 *          This must be freed using kDbgSymbolFree().
    4844 * @param   pSymbol     The symbol to be duplicated.
    4945 */
    50 RTDECL(PRTDBGSYMBOL) RTDbgSymbolDup(PCRTDBGSYMBOL pSymbol)
     46KDBG_DECL(PKDBGSYMBOL) kDbgSymbolDup(PCKDBGSYMBOL pSymbol)
    5147{
    52     AssertMsgReturn(VALID_PTR(pSymbol), ("%p\n", pSymbol), NULL);
    53     size_t cb = KDBG_OFFSETOF(RTDBGSYMBOL, szName[pSymbol->cchName + 1]);
    54     return (PRTDBGSYMBOL)RTMemDup(pSymbol, cb);
     48    kDbgAssertPtrReturn(pSymbol, NULL);
     49    size_t cb = KDBG_OFFSETOF(KDBGSYMBOL, szName[pSymbol->cchName + 1]);
     50    return (PKDBGSYMBOL)kDbgHlpAllocDup(pSymbol, cb);
    5551}
    5652
     
    5955 * Frees a symbol obtained from the RTDbg API.
    6056 *
    61  * @returns VINF_SUCCESS on 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.
    6359 *
    6460 * @param   pSymbol     The symbol to be freed.
    6561 */
    66 RTDECL(int) RTDbgSymbolFree(PRTDBGSYMBOL pSymbol)
     62KDBG_DECL(int) kDbgSymbolFree(PKDBGSYMBOL pSymbol)
    6763{
    6864    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);
    7167
    72     RTMemFree(pSymbol);
    73     return VINF_SUCCESS;
     68    kDbgHlpFree(pSymbol);
     69    return 0;
    7470}
    7571
Note: See TracChangeset for help on using the changeset viewer.