Changeset 3550 for trunk/kStuff/kDbg
- Timestamp:
- Aug 26, 2007, 3:13:35 AM (18 years ago)
- Location:
- trunk/kStuff/kDbg
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kStuff/kDbg/Makefile.kmk
r3537 r3550 31 31 # kDbg - The profiler module. 32 32 # 33 DLLS += kDbg 33 #DLLS += kDbg - disabled for now. 34 34 kDbg_TEMPLATE = kStuffDLL 35 35 kDbg_DEFS = KDBG_BUILDING KDBG_RESIDES_IN_DLL … … 37 37 kDbg_SOURCES := \ 38 38 kDbgModule.cpp \ 39 kDbgModPE.cpp \40 \41 39 kDbgLine.cpp \ 42 \ 43 kDbgSymbol.cpp \ 44 \ 45 kDbgHlpCrt.cpp 40 kDbgSymbol.cpp 46 41 47 42 kDbg_SOURCES += \ … … 66 61 kDbgDump_LIBS = \ 67 62 $(TARGET_kDbgStatic) \ 68 $(TARGET_kDbgStatic:kDbgStatic=kLdrStatic) 63 $(subst kDbg,kLdr,$(TARGET_kDbgStatic)) \ 64 $(subst kDbg,kRdr,$(TARGET_kDbgStatic)) 69 65 70 66 # Generate the rules -
trunk/kStuff/kDbg/kDbgDump.cpp
r3537 r3550 28 28 * Header Files * 29 29 *******************************************************************************/ 30 #include "kDbg.h"30 #include <k/kDbg.h> 31 31 #include <string.h> 32 32 #include <stdio.h> … … 53 53 { 54 54 PKDBGMOD pDbgMod; 55 int rc = kDbgModuleOpen( pszFile, &pDbgMod);55 int rc = kDbgModuleOpen(&pDbgMod, pszFile, NULL); 56 56 if (rc) 57 57 { -
trunk/kStuff/kDbg/kDbgInternal.h
r3541 r3550 26 26 #define ___kDbgInternal_h___ 27 27 28 #include <k/kDbg.h> 29 #include "kDbgHlp.h" 28 #include <k/kHlpAssert.h> 29 #include <k/kMagics.h> 30 #include <k/kErrors.h> 31 #include <k/kDbgAll.h> 32 33 34 /** @defgroup grp_kDbgInternal Internal 35 * @internal 36 * @addtogroup grp_kDbg 37 * @{ 38 */ 39 40 /** @def KDBG_STRICT 41 * If defined the kDbg assertions and other runtime checks will be enabled. */ 42 #ifdef K_ALL_STRICT 43 # undef KDBG_STRICT 44 # define KDBG_STRICT 45 #endif 46 47 /** @name Our Assert macros 48 * @{ */ 49 #ifdef KDBG_STRICT 50 # define kDbgAssert(expr) kHlpAssert(expr) 51 # define kDbgAssertReturn(expr, rcRet) kHlpAssertReturn(expr, rcRet) 52 # define kDbgAssertReturnVoid(expr) kHlpAssertReturnVoid(expr) 53 # define kDbgAssertMsg(expr, msg) kHlpAssertMsg(expr, msg) 54 # define kDbgAssertMsgReturn(expr, msg, rcRet) kHlpAssertMsgReturn(expr, msg, rcRet) 55 # define kDbgAssertMsgReturnVoid(expr, msg) kHlpAssertMsgReturnVoid(expr, msg) 56 #else /* !KDBG_STRICT */ 57 # define kDbgAssert(expr) do { } while (0) 58 # define kDbgAssertReturn(expr, rcRet) do { if (!(expr)) return (rcRet); } while (0) 59 # define kDbgAssertMsg(expr, msg) do { } while (0) 60 # define kDbgAssertMsgReturn(expr, msg, rcRet) do { if (!(expr)) return (rcRet); } while (0) 61 #endif /* !KDBG_STRICT */ 62 63 #define kDbgAssertPtr(ptr) kDbgAssertMsg(K_VALID_PTR(ptr), ("%s = %p\n", #ptr, (ptr))) 64 #define kDbgAssertPtrReturn(ptr, rcRet) kDbgAssertMsgReturn(K_VALID_PTR(ptr), ("%s = %p -> %d\n", #ptr, (ptr), (rcRet)), (rcRet)) 65 #define kDbgAssertPtrReturnVoid(ptr) kDbgAssertMsgReturnVoid(K_VALID_PTR(ptr), ("%s = %p -> %d\n", #ptr, (ptr), (rcRet))) 66 #define kDbgAssertPtrNull(ptr) kDbgAssertMsg(!(ptr) || K_VALID_PTR(ptr), ("%s = %p\n", #ptr, (ptr))) 67 #define kDbgAssertPtrNullReturn(ptr, rcRet) kDbgAssertMsgReturn(!(ptr) || K_VALID_PTR(ptr), ("%s = %p -> %d\n", #ptr, (ptr), (rcRet)), (rcRet)) 68 #define kDbgAssertPtrNullReturnVoid(ptr) kDbgAssertMsgReturnVoid(!(ptr) || K_VALID_PTR(ptr), ("%s = %p -> %d\n", #ptr, (ptr), (rcRet))) 69 #define kDbgAssertRC(rc) kDbgAssertMsg((rc) == 0, ("%s = %d\n", #rc, (rc))) 70 #define kDbgAssertRCReturn(rc, rcRet) kDbgAssertMsgReturn((rc) == 0, ("%s = %d -> %d\n", #rc, (rc), (rcRet)), (rcRet)) 71 #define kDbgAssertRCReturnVoid(rc) kDbgAssertMsgReturnVoid((rc) == 0, ("%s = %d -> %d\n", #rc, (rc), (rcRet))) 72 #define kDbgAssertFailed() kDbgAssert(0) 73 #define kDbgAssertFailedReturn(rcRet) kDbgAssertReturn(0, (rcRet)) 74 #define kDbgAssertFailedReturnVoid() kDbgAssertReturnVoid(0) 75 #define kDbgAssertMsgFailed(msg) kDbgAssertMsg(0, msg) 76 #define kDbgAssertMsgFailedReturn(msg, rcRet) kDbgAssertMsgReturn(0, msg, (rcRet)) 77 #define kDbgAssertMsgFailedReturnVoid(msg) kDbgAssertMsgReturnVoid(0, msg) 78 /** @} */ 79 80 /** Return / crash validation of a reader argument. */ 81 #define KDBGMOD_VALIDATE_EX(pDbgMod, rc) \ 82 do { \ 83 kDbgAssertPtrReturn((pDbgMod), (rc)); \ 84 kDbgAssertReturn((pDbgMod)->u32Magic == KDBGMOD_MAGIC, (rc)); \ 85 kDbgAssertReturn((pDbgMod)->pOps != NULL, (rc)); \ 86 } while (0) 87 88 /** Return / crash validation of a reader argument. */ 89 #define KDBGMOD_VALIDATE(pDbgMod) \ 90 do { \ 91 kDbgAssertPtrReturn((pDbgMod), KERR_INVALID_POINTER); \ 92 kDbgAssertReturn((pDbgMod)->u32Magic == KDBGMOD_MAGIC, KERR_INVALID_HANDLE); \ 93 kDbgAssertReturn((pDbgMod)->pOps != NULL, KERR_INVALID_HANDLE); \ 94 } while (0) 95 96 /** Return / crash validation of a reader argument. */ 97 #define KDBGMOD_VALIDATE_VOID(pDbgMod) \ 98 do { \ 99 kDbgAssertPtrReturnVoid((pDbgMod)); \ 100 kDbgAssertReturnVoid((pDbgMod)->u32Magic == KDBGMOD_MAGIC); \ 101 kDbgAssertReturnVoid((pDbgMod)->pOps != NULL); \ 102 } while (0) 103 30 104 31 105 #ifdef __cplusplus … … 52 126 #endif 53 127 128 /** @} */ 129 54 130 #endif 55 131 -
trunk/kStuff/kDbg/kDbgLine.cpp
r3541 r3550 7 7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 8 * 9 * This file is part of k LIBC.9 * This file is part of kStuff. 10 10 * 11 * k LIBC is free software; you can redistribute it and/or modify12 * it under the terms of the GNU General Public License as published by13 * the Free Software Foundation; either version 2 of the License, or14 * (at your option) any later version.11 * kStuff is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Lesser General Public 13 * License as published by the Free Software Foundation; either 14 * version 2.1 of the License, or (at your option) any later version. 15 15 * 16 * k LIBCis distributed in the hope that it will be useful,16 * kStuff is distributed in the hope that it will be useful, 17 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNUGeneral Public License for more details.18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Lesser General Public License for more details. 20 20 * 21 * You should have received a copy of the GNU General Public License22 * along with kLIBC; if not, write to the Free Software23 * Foundation, Inc., 5 9 Temple Place, Suite 330, Boston, MA 02111-1307USA21 * You should have received a copy of the GNU Lesser General Public 22 * License along with kStuff; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 24 * 25 25 */ 26 27 26 28 27 /******************************************************************************* 29 28 * Header Files * 30 29 *******************************************************************************/ 31 #include "kDbg.h"32 30 #include "kDbgInternal.h" 33 31 #include <k/kHlpAlloc.h> 34 32 35 33 … … 47 45 KDBG_DECL(PKDBGLINE) kDbgLineDup(PCKDBGLINE pLine) 48 46 { 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); 47 kDbgAssertPtrReturn(pLine, NULL); 48 KSIZE cb = K_OFFSETOF(KDBGLINE, szFile[pLine->cchFile + 1]); 49 PKDBGLINE pNewLine = (PKDBGLINE)kHlpDup(pLine, cb); 50 if (pNewLine) 51 pNewLine->cbSelf = cb; 52 return pNewLine; 52 53 } 53 54 54 55 55 56 /** 56 * Frees a line number obtained from the RTDbg API.57 * Frees a line number obtained from the kDbg API. 57 58 * 58 59 * @returns 0 on success. 59 * @returns KERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in.60 * @returns KERR_INVALID_POINTER if pLine isn't a valid pointer. 60 61 * 61 * @param pLine The line number to be freed. 62 * @param pLine The line number to be freed. The null pointer is ignored. 62 63 */ 63 64 KDBG_DECL(int) kDbgLineFree(PKDBGLINE pLine) 64 65 { 65 if (!pLine) 66 return KERR_INVALID_POINTER; 67 kDbgAssertMsgReturn(KDBG_VALID_PTR(pLine), ("%p\n", pLine), KERR_INVALID_POINTER); 68 69 kDbgHlpFree(pLine); 66 if (pLine) 67 { 68 kDbgAssertPtrReturn(pLine, KERR_INVALID_POINTER); 69 pLine->cbSelf = 0; 70 kHlpFree(pLine); 71 } 70 72 return 0; 71 73 } -
trunk/kStuff/kDbg/kDbgModWinDbgHelp.cpp
r3541 r3550 32 32 #define _IMAGEHLP64 33 33 #include <DbgHelp.h> 34 #include <malloc.h> /* alloca */35 34 36 35 #include "kDbgInternal.h" 36 #include <k/kHlpAlloc.h> 37 #include <k/kHlpString.h> 37 38 38 39 … … 72 73 HANDLE hSymInst; 73 74 /** The image size. */ 74 uint32_tcbImage;75 KU32 cbImage; 75 76 /** The number of sections. (We've added the implicit header section.) */ 76 int32_tcSections;77 KI32 cSections; 77 78 /** The section headers (variable size). The first section is the 78 79 * implicit header section.*/ … … 107 108 * @param puRVA Where to store the RVA on success. 108 109 */ 109 static int kdbgModDHSegOffToRVA(PKDBGMODDBGHELP pModDH, int32_t iSegment, KDBGADDR off, uint32_t*puRVA)110 static int kdbgModDHSegOffToRVA(PKDBGMODDBGHELP pModDH, KI32 iSegment, KDBGADDR off, KU32 *puRVA) 110 111 { 111 112 if (iSegment >= 0) … … 116 117 ("off=" PRI_KDBGADDR " VirtualSize=%x\n", off, pModDH->aSections[iSegment].Misc.VirtualSize), 117 118 KDBG_ERR_INVALID_ADDRESS); 118 *puRVA = pModDH->aSections[iSegment].VirtualAddress + ( uint32_t)off;119 *puRVA = pModDH->aSections[iSegment].VirtualAddress + (KU32)off; 119 120 return 0; 120 121 } … … 124 125 kDbgAssertMsgReturn(off < pModDH->cbImage, ("off=" PRI_KDBGADDR ", cbImage=%x\n", off, pModDH->cbImage), 125 126 KDBG_ERR_INVALID_ADDRESS); 126 *puRVA = ( uint32_t)off;127 *puRVA = (KU32)off; 127 128 return 0; 128 129 } … … 141 142 * @param poff Where to store the segment offset. 142 143 */ 143 static int kdbgModDHRVAToSegOff(PKDBGMODDBGHELP pModDH, uint32_t uRVA, int32_t*piSegment, KDBGADDR *poff)144 static int kdbgModDHRVAToSegOff(PKDBGMODDBGHELP pModDH, KU32 uRVA, KI32 *piSegment, KDBGADDR *poff) 144 145 { 145 146 kDbgAssertMsgReturn(uRVA < pModDH->cbImage, ("uRVA=%x, cbImage=%x\n", uRVA, pModDH->cbImage), 146 147 KDBG_ERR_INVALID_ADDRESS); 147 for ( int32_tiSegment = 0; iSegment < pModDH->cSections; iSegment++)148 for (KI32 iSegment = 0; iSegment < pModDH->cSections; iSegment++) 148 149 { 149 150 /** @todo should probably be less strict about address in the alignment gaps. */ 150 uint32_toff = uRVA - pModDH->aSections[iSegment].VirtualAddress;151 KU32 off = uRVA - pModDH->aSections[iSegment].VirtualAddress; 151 152 if (off < pModDH->aSections[iSegment].Misc.VirtualSize) 152 153 { … … 163 164 * @copydoc KDBGMODOPS::pfnQueryLine 164 165 */ 165 static int kdbgModDHQueryLine(PKDBGMOD pMod, int32_tiSegment, KDBGADDR off, PKDBGLINE pLine)166 static int kdbgModDHQueryLine(PKDBGMOD pMod, KI32 iSegment, KDBGADDR off, PKDBGLINE pLine) 166 167 { 167 168 PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)pMod; … … 170 171 * Translate the address to an RVA. 171 172 */ 172 uint32_tuRVA;173 KU32 uRVA; 173 174 int rc = kdbgModDHSegOffToRVA(pModDH, iSegment, off, &uRVA); 174 175 if (!rc) … … 180 181 { 181 182 pLine->RVA = (KDBGADDR)(Line.Address - pModDH->ImageBase); 182 rc = kdbgModDHRVAToSegOff(pModDH, ( uint32_t)pLine->RVA, &pLine->iSegment, &pLine->offSegment);183 rc = kdbgModDHRVAToSegOff(pModDH, (KU32)pLine->RVA, &pLine->iSegment, &pLine->offSegment); 183 184 pLine->iLine = Line.LineNumber; 184 size_t cchFile = strlen(Line.FileName);185 KSIZE cchFile = kHlpStrLen(Line.FileName); 185 186 pLine->cchFile = cchFile < sizeof(pLine->szFile) 186 ? ( uint16_t)cchFile187 : ( uint16_t)sizeof(pLine->szFile) - 1;188 memcpy(pLine->szFile, Line.FileName, pLine->cchFile);187 ? (KU16)cchFile 188 : (KU16)sizeof(pLine->szFile) - 1; 189 kHlpMemCopy(pLine->szFile, Line.FileName, pLine->cchFile); 189 190 pLine->szFile[pLine->cchFile] = '\0'; 190 191 } … … 202 203 * @copydoc KDBGMODOPS::pfnQuerySymbol 203 204 */ 204 static int kdbgModDHQuerySymbol(PKDBGMOD pMod, int32_tiSegment, KDBGADDR off, PKDBGSYMBOL pSym)205 static int kdbgModDHQuerySymbol(PKDBGMOD pMod, KI32 iSegment, KDBGADDR off, PKDBGSYMBOL pSym) 205 206 { 206 207 PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)pMod; … … 209 210 * Translate the address to an RVA. 210 211 */ 211 uint32_tuRVA;212 KU32 uRVA; 212 213 int rc = kdbgModDHSegOffToRVA(pModDH, iSegment, off, &uRVA); 213 214 if (!rc) … … 242 243 { 243 244 pSym->RVA = (KDBGADDR)(Buf.Sym.Address - pModDH->ImageBase); 244 rc = kdbgModDHRVAToSegOff(pModDH, ( uint32_t)pSym->RVA, &pSym->iSegment, &pSym->offSegment);245 rc = kdbgModDHRVAToSegOff(pModDH, (KU32)pSym->RVA, &pSym->iSegment, &pSym->offSegment); 245 246 } 246 pSym->cchName = ( uint16_t)Buf.Sym.NameLen;247 pSym->cchName = (KU16)Buf.Sym.NameLen; 247 248 if (pSym->cchName >= sizeof(pSym->szName)) 248 249 pSym->cchName = sizeof(pSym->szName) - 1; 249 memcpy(pSym->szName, Buf.Sym.Name, Buf.Sym.NameLen);250 kHlpMemCopy(pSym->szName, Buf.Sym.Name, Buf.Sym.NameLen); 250 251 pSym->szName[Buf.Sym.NameLen] = '\0'; 251 252 } … … 272 273 DWORD Err = GetLastError(); 273 274 int rc = kdbgModDHConvWinError(Err); 274 kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=% Rrc\n", Err, rc));275 kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=%d\n", Err, rc)); 275 276 return rc; 276 277 } … … 278 279 279 280 /** 280 * Methods for a PE module.281 */282 static const KDBGMODOPS g_kdbgModDHOps =283 {284 "PE (dbghelp)",285 kdbgModDHClose,286 kdbgModDHQuerySymbol,287 kdbgModDHQueryLine288 };289 290 291 /**292 281 * Checks if the specified dbghelp.dll is usable. 293 282 * … … 296 285 * @param pszPath the path to the dbghelp.dll. 297 286 */ 298 static int kdbgModDHTryDbgHelp(const char *pszPath, uint32_t *pu32FileVersionMS, uint32_t*pu32FileVersionLS)287 static int kdbgModDHTryDbgHelp(const char *pszPath, KU32 *pu32FileVersionMS, KU32 *pu32FileVersionLS) 299 288 { 300 289 int rc; … … 337 326 * Find the dbghelp.dll 338 327 */ 339 static int kdbgModDHFindDbgHelp(char *pszPath, size_tcchPath)328 static int kdbgModDHFindDbgHelp(char *pszPath, KSIZE cchPath) 340 329 { 341 330 /* 342 331 * Try the current directory. 343 332 */ 344 uint32_tFileVersionMS = 0;345 uint32_tFileVersionLS = 0;333 KU32 FileVersionMS = 0; 334 KU32 FileVersionLS = 0; 346 335 int rc = KERR_GENERAL_FAILURE; 347 336 static char s_szDbgHelp[] = "\\dbghelp.dll"; … … 361 350 if (GetModuleFileName(NULL, pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1))) 362 351 { 363 strcat(strrchr(pszPath, '\\'), s_szDbgHelp);352 kHlpStrCat(kHlpStrRChr(pszPath, '\\'), s_szDbgHelp); 364 353 int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 365 354 if (!rc) … … 374 363 if (GetSystemDirectory(pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1))) 375 364 { 376 strcat(pszPath, s_szDbgHelp);365 kHlpStrCat(pszPath, s_szDbgHelp); 377 366 int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 378 367 if (!rc2) … … 387 376 if (GetWindowsDirectory(pszPath, (DWORD)(cchPath - sizeof(s_szDbgHelp) + 1))) 388 377 { 389 strcat(pszPath, s_szDbgHelp);378 kHlpStrCat(pszPath, s_szDbgHelp); 390 379 int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 391 380 if (!rc2) … … 407 396 { 408 397 /* find the end of the path. */ 409 char *pszEnd = strchr(psz, ';');398 char *pszEnd = kHlpStrChr(psz, ';'); 410 399 if (!pszEnd) 411 pszEnd = strchr(psz, '\0');400 pszEnd = kHlpStrChr(psz, '\0'); 412 401 if (pszEnd != psz) 413 402 { 414 403 /* construct filename and try it out */ 415 memcpy(pszPath, psz, pszEnd - psz);416 memcpy(&pszPath[pszEnd - psz], s_szDbgHelp, sizeof(s_szDbgHelp));404 kHlpMemCopy(pszPath, psz, pszEnd - psz); 405 kHlpMemCopy(&pszPath[pszEnd - psz], s_szDbgHelp, sizeof(s_szDbgHelp)); 417 406 int rc2 = kdbgModDHTryDbgHelp(pszPath, &FileVersionMS, &FileVersionLS); 418 407 if (!rc2) … … 453 442 454 443 /* primitive locking - make some useful API for this kind of spinning! */ 455 static volatile uint32_t s_u32Lock = 0;456 while (!InterlockedCompareExchange( (long volatile *)&s_u32Lock, 1, 0))457 while (s_ u32Lock)444 static volatile long s_lLock = 0; 445 while (!InterlockedCompareExchange(&s_lLock, 1, 0)) 446 while (s_lLock) 458 447 Sleep(1); 459 448 if (g_hDbgHelp) 460 449 { 461 InterlockedExchange( (long volatile *)&s_u32Lock, 0);450 InterlockedExchange(&s_lLock, 0); 462 451 return 0; 463 452 } … … 470 459 if (rc) 471 460 { 472 InterlockedExchange( (volatile long *)&s_u32Lock, 0);461 InterlockedExchange(&s_lLock, 0); 473 462 return rc; 474 463 } … … 479 468 DWORD Err = GetLastError(); 480 469 int rc = kdbgModDHConvWinError(Err); 481 kDbgAssertMsgFailedReturn(("Failed to load '%s', Err=%d rc=% Rrc\n", szPath, Err, rc), rc);470 kDbgAssertMsgFailedReturn(("Failed to load '%s', Err=%d rc=%d\n", szPath, Err, rc), rc); 482 471 } 483 472 … … 515 504 { "SymGetLineFromAddr64", (FARPROC *)&g_pfnSymGetLineFromAddr64 }, 516 505 }; 517 for (unsigned i = 0; i < K DBG_ELEMENTS(s_aFunctions); i++)506 for (unsigned i = 0; i < K_ELEMENTS(s_aFunctions); i++) 518 507 { 519 508 FARPROC pfn = GetProcAddress(hmod, s_aFunctions[i].pszName); … … 522 511 DWORD Err = GetLastError(); 523 512 rc = kdbgModDHConvWinError(Err); 524 kDbgAssertMsgFailed(("Failed to resolve %s in dbghelp, Err=%d rc=% Rrc\n",525 s_aFunctions[i].pszName, Err, rc));513 kDbgAssertMsgFailed(("Failed to resolve %s in dbghelp, Err=%d rc=%d\n", 514 s_aFunctions[i].pszName, Err, rc)); 526 515 break; 527 516 } … … 533 522 g_hDbgHelp = hmod; 534 523 Sleep(1); 535 InterlockedExchange( (volatile long *)&s_u32Lock, 0);524 InterlockedExchange(&s_lLock, 0); 536 525 return 0; 537 526 } … … 547 536 DWORD Err = GetLastError(); 548 537 rc = kdbgModDHConvWinError(Err); 549 kDbgAssertMsgFailed(("Failed to resolve ImagehlpApiVersionEx in dbghelp, Err=%d rc=% Rrc\n", Err, rc));538 kDbgAssertMsgFailed(("Failed to resolve ImagehlpApiVersionEx in dbghelp, Err=%d rc=%d\n", Err, rc)); 550 539 } 551 540 FreeLibrary(hmod); 552 InterlockedExchange( (long volatile *)&s_u32Lock, 0);541 InterlockedExchange(&s_lLock, 0); 553 542 return rc; 554 543 } … … 556 545 557 546 /** 558 * Opens the debug info for a PE image using the windows dbghelp library. 559 * 560 * @returns IPRT status code. 561 * 562 * @param pFile The handle to the module. 563 * @param offHdr The offset of the PE header. 564 * @param pszModulePath The path to the module. 565 * @param ppDbgMod Where to store the module handle. 566 * 567 */ 568 int kdbgModWinDbgHelpOpen(PKDBGHLPFILE pFile, PKDBGMOD *ppDbgMod) 569 { 547 * @copydoc KDBGMODOPS::pfnOpen 548 */ 549 static int kdbgModDHOpen(PKDBGMOD *ppMod, PKRDR pRdr, KBOOL fCloseRdr, KFOFF off, KFOFF cb, struct KLDRMOD *pLdrMod) 550 { 551 /* 552 * This reader doesn't support partial files. 553 * Also weed out small files early on as they cannot be 554 * PE images and will only cause read errors 555 */ 556 if ( off != 0 557 || cb != KFOFF_MAX) 558 return KDBG_ERR_UNKOWN_FORMAT; 559 if (kRdrSize(pRdr) < sizeof(IMAGE_NT_HEADERS32) + sizeof(IMAGE_SECTION_HEADER)) 560 return KDBG_ERR_UNKOWN_FORMAT; 561 570 562 /* 571 563 * We need to read the section headers and get the image size. 572 564 */ 565 /* Find the PE header magic. */ 566 KU32 offHdr = 0; 567 KU32 u32Magic; 568 int rc = kRdrRead(pRdr, &u32Magic, sizeof(u32Magic), 0); 569 kDbgAssertRCReturn(rc, rc); 570 if ((KU16)u32Magic == IMAGE_DOS_SIGNATURE) 571 { 572 rc = kRdrRead(pRdr, &offHdr, sizeof(offHdr), K_OFFSETOF(IMAGE_DOS_HEADER, e_lfanew)); 573 kDbgAssertRCReturn(rc, rc); 574 if (!offHdr) 575 return KDBG_ERR_FORMAT_NOT_SUPPORTED; 576 if ( offHdr < sizeof(IMAGE_DOS_SIGNATURE) 577 || offHdr >= kRdrSize(pRdr) - 4) 578 return KDBG_ERR_BAD_EXE_FORMAT; 579 580 rc = kRdrRead(pRdr, &u32Magic, sizeof(u32Magic), offHdr); 581 kDbgAssertRCReturn(rc, rc); 582 } 583 if (u32Magic != IMAGE_NT_SIGNATURE) 584 return KDBG_ERR_FORMAT_NOT_SUPPORTED; 585 586 /* read the file header and the image size in the optional header.. */ 573 587 IMAGE_FILE_HEADER FHdr; 574 int rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader), &FHdr, sizeof(FHdr));588 rc = kRdrRead(pRdr, &FHdr, sizeof(FHdr), K_OFFSETOF(IMAGE_NT_HEADERS32, FileHeader)); 575 589 kDbgAssertRCReturn(rc, rc); 576 590 577 uint32_tcbImage;591 KU32 cbImage; 578 592 if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER32)) 579 rc = k DbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage),580 &cbImage, sizeof(cbImage));593 rc = kRdrRead(pRdr, &cbImage, sizeof(cbImage), 594 offHdr + K_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader.SizeOfImage)); 581 595 else if (FHdr.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER64)) 582 rc = k DbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage),583 &cbImage, sizeof(cbImage));596 rc = kRdrRead(pRdr, &cbImage, sizeof(cbImage), 597 offHdr + K_OFFSETOF(IMAGE_NT_HEADERS64, OptionalHeader.SizeOfImage)); 584 598 else 585 599 kDbgAssertFailedReturn(KDBG_ERR_BAD_EXE_FORMAT); … … 596 610 * Allocate the module and read/construct the section headers. 597 611 */ 598 PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)k DbgHlpAlloc(KDBG_OFFSETOF(KDBGMODDBGHELP, aSections[FHdr.NumberOfSections + 2]));612 PKDBGMODDBGHELP pModDH = (PKDBGMODDBGHELP)kHlpAlloc(K_OFFSETOF(KDBGMODDBGHELP, aSections[FHdr.NumberOfSections + 2])); 599 613 kDbgAssertReturn(pModDH, KERR_NO_MEMORY); 600 614 pModDH->Core.u32Magic = KDBGMOD_MAGIC; 601 pModDH->Core.pOps = &g_kdbgModDHOps; 602 pModDH->Core.pFile = pFile; 615 pModDH->Core.pOps = &g_kDbgModWinDbgHelpOpen; 616 pModDH->Core.pRdr = pRdr; 617 pModDH->Core.fCloseRdr = fCloseRdr; 618 pModDH->Core.pLdrMod = pLdrMod; 603 619 pModDH->cbImage = cbImage; 604 620 pModDH->cSections = 1 + FHdr.NumberOfSections; 605 rc = kDbgHlpReadAt(pFile, offHdr + KDBG_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader, 606 &pModDH->aSections[1], sizeof(pModDH->aSections[0]) * FHdr.NumberOfSections); 621 622 rc = kRdrRead(pRdr, &pModDH->aSections[1], sizeof(pModDH->aSections[0]) * FHdr.NumberOfSections, 623 offHdr + K_OFFSETOF(IMAGE_NT_HEADERS32, OptionalHeader) + FHdr.SizeOfOptionalHeader); 607 624 if (!rc) 608 625 { 609 626 PIMAGE_SECTION_HEADER pSH = &pModDH->aSections[0]; 610 memcpy(pSH->Name, "headers", sizeof(pSH->Name));627 kHlpMemCopy(pSH->Name, "headers", sizeof(pSH->Name)); 611 628 pSH->Misc.VirtualSize = pModDH->aSections[1].VirtualAddress; 612 629 pSH->VirtualAddress = 0; … … 619 636 pSH->Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_MEM_READ; 620 637 621 uint32_tuTheEnd = pModDH->aSections[FHdr.NumberOfSections].VirtualAddress622 638 KU32 uTheEnd = pModDH->aSections[FHdr.NumberOfSections].VirtualAddress 639 + pModDH->aSections[FHdr.NumberOfSections].Misc.VirtualSize; 623 640 if (uTheEnd < cbImage) 624 641 { 625 642 pSH = &pModDH->aSections[pModDH->cSections++]; 626 memcpy(pSH->Name, "tail\0\0\0", sizeof(pSH->Name));643 kHlpMemCopy(pSH->Name, "tail\0\0\0", sizeof(pSH->Name)); 627 644 pSH->Misc.VirtualSize = cbImage - uTheEnd; 628 645 pSH->VirtualAddress = uTheEnd; … … 642 659 * when we start reusing handles they are no longer in use. :-) 643 660 */ 644 static volatile uint32_ts_u32LastHandle = 1;645 HANDLE hSymInst = (HANDLE)InterlockedIncrement( (long *)&s_u32LastHandle);661 static volatile long s_u32LastHandle = 1; 662 HANDLE hSymInst = (HANDLE)InterlockedIncrement(&s_u32LastHandle); 646 663 while ( hSymInst == INVALID_HANDLE_VALUE 647 664 || hSymInst == (HANDLE)0 648 665 || hSymInst == GetCurrentProcess()) 649 hSymInst = (HANDLE)InterlockedIncrement( (long *)&s_u32LastHandle);666 hSymInst = (HANDLE)InterlockedIncrement(&s_u32LastHandle); 650 667 651 668 /* … … 656 673 g_pfnSymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_AUTO_PUBLICS | SYMOPT_ALLOW_ABSOLUTE_SYMBOLS); 657 674 658 kDbgHlpSeek(pFile, 0); /* don't know if this is required or not... */659 DWORD64 ImageBase = g_pfnSymLoadModule64(hSymInst, (HANDLE)kDbgHlpNativeFileHandle(pFile),660 pszModulePath, NULL, 0x00400000, 0);675 KIPTR NativeFH = kRdrNativeFH(pRdr); 676 DWORD64 ImageBase = g_pfnSymLoadModule64(hSymInst, NativeFH == -1 ? NULL : (HANDLE)NativeFH, 677 kRdrName(pRdr), NULL, 0x00400000, 0); 661 678 if (ImageBase) 662 679 { 663 pModDH->hSymInst = hSymInst;664 pModDH->ImageBase = ImageBase;665 *pp DbgMod = &pModDH->Core;680 pModDH->hSymInst = hSymInst; 681 pModDH->ImageBase = ImageBase; 682 *ppMod = &pModDH->Core; 666 683 return rc; 667 684 } … … 669 686 DWORD Err = GetLastError(); 670 687 rc = kdbgModDHConvWinError(Err); 671 kDbgAssertMsgFailed(("SymLoadModule64 failed: Err=%d rc=% Rrc\n", Err, rc));688 kDbgAssertMsgFailed(("SymLoadModule64 failed: Err=%d rc=%d\n", Err, rc)); 672 689 g_pfnSymCleanup(hSymInst); 673 690 } … … 676 693 DWORD Err = GetLastError(); 677 694 rc = kdbgModDHConvWinError(Err); 678 kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=% Rrc\n", Err, rc));695 kDbgAssertMsgFailed(("SymInitialize failed: Err=%d rc=%d\n", Err, rc)); 679 696 } 680 697 } … … 682 699 kDbgAssertRC(rc); 683 700 684 k DbgHlpFree(pModDH);701 kHlpFree(pModDH); 685 702 return rc; 686 703 } 687 704 705 706 /** 707 * Methods for a PE module. 708 */ 709 const KDBGMODOPS g_kDbgModWinDbgHelpOpen = 710 { 711 "Windows DbgHelp", 712 NULL, 713 kdbgModDHOpen, 714 kdbgModDHClose, 715 kdbgModDHQuerySymbol, 716 kdbgModDHQueryLine, 717 "Windows DbgHelp" 718 }; 719 -
trunk/kStuff/kDbg/kDbgModule.cpp
r3543 r3550 9 9 * This file is part of kStuff. 10 10 * 11 * kStuff is free software; you can redistribute it and/or modify12 * it under the terms of the GNU Lesser General Public License as published13 * by the Free Software Foundation; either version 2 of the License, or14 * (at your option) any later version.11 * kStuff is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Lesser General Public 13 * License as published by the Free Software Foundation; either 14 * version 2.1 of the License, or (at your option) any later version. 15 15 * 16 16 * kStuff is distributed in the hope that it will be useful, 17 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * along with kStuff; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 * 25 */ 26 27 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public 22 * License along with kStuff; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 * 25 */ 28 26 29 27 /******************************************************************************* 30 28 * Header Files * 31 29 *******************************************************************************/ 32 #include <k/kDbgAll.h>33 #include <k/kErrors.h>34 #include <string.h>35 30 #include "kDbgInternal.h" 31 #include <k/kHlpString.h> 32 #include <k/kHlpAlloc.h> 36 33 37 34 … … 47 44 &g_kDbgModWinDbgHelpOpen, 48 45 #endif 49 &g_kDbgModLdr,50 &g_kDbgModCv8,51 &g_kDbgModDwarf,52 &g_kDbgModHll,53 &g_kDbgModStabs,54 &g_kDbgModSym,55 &g_kDbgModMapILink,56 &g_kDbgModMapMSLink,57 &g_kDbgModMapNm,58 &g_kDbgModMapWLink46 // &g_kDbgModLdr, 47 // &g_kDbgModCv8, 48 // &g_kDbgModDwarf, 49 // &g_kDbgModHll, 50 // &g_kDbgModStabs, 51 // &g_kDbgModSym, 52 // &g_kDbgModMapILink, 53 // &g_kDbgModMapMSLink, 54 // &g_kDbgModMapNm, 55 // &g_kDbgModMapWLink 59 56 }; 60 57 … … 93 90 kDbgAssertPtrReturn(pOps->pfnQueryLine, KERR_INVALID_POINTER); 94 91 kDbgAssertPtrReturn(pOps->pszName2, KERR_INVALID_POINTER); 95 if ( strcmp(pOps->pszName, pOps->pszName2))92 if (kHlpStrComp(pOps->pszName, pOps->pszName2)) 96 93 return KERR_INVALID_PARAMETER; 97 94 kDbgAssertReturn(pOps->pNext == NULL, KERR_INVALID_PARAMETER); … … 153 150 154 151 152 153 /** 154 * Worker for the kDbgModuleOpen* APIs. 155 * 156 * This will make sure the reader is buffered. I will also take care of 157 * closing the reader opened by kDbgModuleOpen on failure. 158 * 159 * @returns 0 on success. An appropriate kErrors status code on failure. 160 * @param ppDbgMod Where to store the new debug module reader instance. 161 * @param pRdr The file provider. 162 * @param fCloseRdr Whether pRdr should be close or not. This applies both 163 * to the failure path and to the success path, where it'll 164 * be close when the module is closed by kDbgModuleClose(). 165 * @param off The offset into the file where the debug info is supposed 166 * to be found. 167 * This is 0 if the entire file is the subject. 168 * @param cb The size of the debug info part of the file. 169 * This is KFOFF_MAX if the entire file is the subject. 170 * @param pLdrMod An optional kLdrMod association. 171 */ 172 static int kdbgModuleOpenWorker(PPKDBGMOD ppDbgMod, PKRDR pRdr, KBOOL fCloseRdr, KFOFF off, KFOFF cb, struct KLDRMOD *pLdrMod) 173 { 174 /* 175 * If the reader isn't buffered create a buffered wrapper for it. 176 */ 177 int rc; 178 PKRDR pRdrWrapped = NULL; 179 if (!kRdrBufIsBuffered(pRdr)) 180 { 181 rc = kRdrBufWrap(&pRdrWrapped, pRdr, fCloseRdr); 182 if (rc) 183 { 184 if (fCloseRdr) 185 kRdrClose(pRdr); 186 return rc; 187 } 188 pRdr = pRdrWrapped; 189 } 190 191 /* 192 * Walk the built-in table and the list of registered readers 193 * and let each of them have a go at the file. Stop and return 194 * on the first one returning successfully. 195 */ 196 rc = KDBG_ERR_UNKOWN_FORMAT; 197 for (KSIZE i = 0; i < K_ELEMENTS(g_aBuiltIns); i++) 198 if (g_aBuiltIns[i]->pfnOpen) 199 { 200 int rc2 = g_aBuiltIns[i]->pfnOpen(ppDbgMod, pRdr, fCloseRdr, off, cb, pLdrMod); 201 if (!rc) 202 return 0; 203 if (rc2 != KDBG_ERR_UNKOWN_FORMAT && rc == KDBG_ERR_UNKOWN_FORMAT) 204 rc = rc2; 205 } 206 207 for (PKDBGMODOPS pCur = g_pHead; pCur; pCur = pCur->pNext) 208 if (g_aBuiltIns[i]->pfnOpen) 209 { 210 int rc2 = g_aBuiltIns[i]->pfnOpen(ppDbgMod, pRdr, fCloseRdr, off, cb, pLdrMod); 211 if (!rc) 212 return 0; 213 if (rc2 != KDBG_ERR_UNKOWN_FORMAT && rc == KDBG_ERR_UNKOWN_FORMAT) 214 rc = rc2; 215 } 216 217 if (pRdrWrapped) 218 kRdrClose(pRdrWrapped); 219 else if (fCloseRdr) 220 kRdrClose(pRdr); 221 return rc; 222 } 223 224 155 225 /** 156 226 * Opens a debug module reader for the specified file or file section … … 158 228 * @returns kStuff status code. 159 229 * @param ppDbgMod Where to store the debug module reader handle. 160 * @param p FileThe file reader.230 * @param pRdr The file reader. 161 231 * @param off The offset of the file section. If the entire file, pass 0. 162 232 * @param cb The size of the file section. If the entire file, pass KFOFF_MAX. … … 167 237 * This is an optional parameter, pass NULL if no kLdr module at hand. 168 238 */ 169 KDBG_DECL(int) kDbgModuleOpenFilePart(P KDBGMOD *ppDbgMod, PKDBGHLPFILE pFile, KFOFF off, KFOFF cb, struct KLDRMOD *pLdrMod)239 KDBG_DECL(int) kDbgModuleOpenFilePart(PPKDBGMOD ppDbgMod, PKRDR pRdr, KFOFF off, KFOFF cb, struct KLDRMOD *pLdrMod) 170 240 { 171 241 /* … … 173 243 */ 174 244 kDbgAssertPtrReturn(ppDbgMod, KERR_INVALID_POINTER); 175 kDbgAssertPtrReturn(p File, KERR_INVALID_POINTER);245 kDbgAssertPtrReturn(pRdr, KERR_INVALID_POINTER); 176 246 kDbgAssertPtrNullReturn(pLdrMod, KERR_INVALID_POINTER); 177 247 kDbgAssertMsgReturn(off >= 0 && off < KFOFF_MAX, (KFOFF_PRI "\n", off), KERR_INVALID_OFFSET); … … 181 251 182 252 /* 183 * Walk the built-in table and the list of registered readers 184 * and let each of them have a go at the file. Stop and return 185 * on the first one returning successfully. 186 */ 187 int rc = KDBG_ERR_UNKOWN_FORMAT; 188 for (KSIZE i = 0; i < K_ELEMENTS(g_aBuiltIns); i++) 189 if (g_aBuiltIns[i]->pfnOpen) 190 { 191 int rc2 = g_aBuiltIns[i]->pfnOpen(ppDbgMod, pFile, off, cb, pLdrMod); 192 if (!rc) 193 return 0; 194 if (rc2 != KDBG_ERR_UNKOWN_FORMAT && rc == KDBG_ERR_UNKOWN_FORMAT) 195 rc = rc2; 196 } 197 198 for (PKDBGMODOPS pCur = g_pHead; pCur; pCur = pCur->pNext) 199 if (g_aBuiltIns[i]->pfnOpen) 200 { 201 int rc2 = g_aBuiltIns[i]->pfnOpen(ppDbgMod, pFile, off, cb, pLdrMod); 202 if (!rc) 203 return 0; 204 if (rc2 != KDBG_ERR_UNKOWN_FORMAT && rc == KDBG_ERR_UNKOWN_FORMAT) 205 rc = rc2; 206 } 207 return rc; 253 * Hand it over to the internal worker. 254 */ 255 return kdbgModuleOpenWorker(ppDbgMod, pRdr, K_FALSE /* fCloseRdr */, off, cb, pLdrMod); 208 256 } 209 257 … … 214 262 * @returns kStuff status code. 215 263 * @param ppDbgMod Where to store the debug module reader handle. 216 * @param p FileThe file reader.264 * @param pRdr The file reader. 217 265 * @param pLdrMod Associated kLdr module that the kDbg component can use to 218 266 * verify and suplement the debug info found in the file specified … … 221 269 * This is an optional parameter, pass NULL if no kLdr module at hand. 222 270 */ 223 KDBG_DECL(int) kDbgModuleOpenFile(P KDBGMOD *ppDbgMod, PKDBGHLPFILE pFile, struct KLDRMOD *pLdrMod)224 { 225 return kDbgModuleOpenFilePart(ppDbgMod, p File, 0, KFOFF_MAX, pLdrMod);271 KDBG_DECL(int) kDbgModuleOpenFile(PPKDBGMOD ppDbgMod, PKRDR pRdr, struct KLDRMOD *pLdrMod) 272 { 273 return kDbgModuleOpenFilePart(ppDbgMod, pRdr, 0, KFOFF_MAX, pLdrMod); 226 274 } 227 275 … … 240 288 * This is an optional parameter, pass NULL if no kLdr module at hand. 241 289 */ 242 KDBG_DECL(int) kDbgModuleOpen(P KDBGMOD *ppDbgMod, const char *pszFilename, struct KLDRMOD *pLdrMod)290 KDBG_DECL(int) kDbgModuleOpen(PPKDBGMOD ppDbgMod, const char *pszFilename, struct KLDRMOD *pLdrMod) 243 291 { 244 292 /* … … 254 302 * Open the file and see if we can read it. 255 303 */ 256 PK DBGHLPFILE pFile;257 int rc = k DbgHlpOpenRO(pszFilename, &pFile);304 PKRDR pRdr; 305 int rc = kRdrBufOpen(&pRdr, pszFilename); 258 306 if (rc) 259 307 return rc; 260 rc = kDbgModuleOpenFilePart(ppDbgMod, pFile, 0, KFOFF_MAX, pLdrMod); 261 if (rc) 262 kDbgHlpClose(pFile); 308 rc = kdbgModuleOpenWorker(ppDbgMod, pRdr, K_TRUE /* fCloseRdr */, 0, KFOFF_MAX, pLdrMod); 263 309 return rc; 264 }265 266 267 /**268 * Validates a debug module handle.269 * All necessary asserting will be taken care of here.270 *271 * @returns True / false.272 * @param pMod The debug module handle.273 */274 KDBG_INLINE(bool) kdbgModIsValid(PKDBGMOD pMod)275 {276 kDbgAssertPtrReturn(pMod, false);277 kDbgAssertMsgReturn(pMod->u32Magic == KDBGMOD_MAGIC, ("%#x", pMod->u32Magic), false);278 kDbgAssertPtrReturn(pMod->pOps, false);279 return true;280 310 } 281 311 … … 289 319 KDBG_DECL(int) kDbgModuleClose(PKDBGMOD pMod) 290 320 { 291 if (!kdbgModIsValid(pMod)) 292 return KERR_INVALID_PARAMETER; 293 321 KDBGMOD_VALIDATE(pMod); 294 322 int rc = pMod->pOps->pfnClose(pMod); 295 323 if (!rc) 296 kDbgHlpFree(pMod); 324 { 325 pMod->u32Magic++; 326 kHlpFree(pMod); 327 } 297 328 return rc; 298 329 } … … 314 345 KDBG_DECL(int) kDbgModuleQuerySymbol(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGSYMBOL pSym) 315 346 { 316 if (!kdbgModIsValid(pMod)) 317 return KERR_INVALID_PARAMETER; 347 KDBGMOD_VALIDATE(pMod); 318 348 kDbgAssertPtrReturn(pSym, KERR_INVALID_POINTER); 319 320 349 return pMod->pOps->pfnQuerySymbol(pMod, iSegment, off, pSym); 321 350 } … … 369 398 KDBG_DECL(int) kDbgModuleQueryLine(PKDBGMOD pMod, int32_t iSegment, KDBGADDR off, PKDBGLINE pLine) 370 399 { 371 if (!kdbgModIsValid(pMod)) 372 return KERR_INVALID_PARAMETER; 400 KDBGMOD_VALIDATE(pMod); 373 401 kDbgAssertPtrReturn(pLine, KERR_INVALID_POINTER); 374 375 402 return pMod->pOps->pfnQueryLine(pMod, iSegment, off, pLine); 376 403 } -
trunk/kStuff/kDbg/kDbgSymbol.cpp
r3541 r3550 7 7 * Copyright (c) 2006-2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 8 * 9 * This file is part of k LIBC.9 * This file is part of kStuff. 10 10 * 11 * k LIBC is free software; you can redistribute it and/or modify12 * it under the terms of the GNU General Public License as published by13 * the Free Software Foundation; either version 2 of the License, or14 * (at your option) any later version.11 * kStuff is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Lesser General Public 13 * License as published by the Free Software Foundation; either 14 * version 2.1 of the License, or (at your option) any later version. 15 15 * 16 * k LIBCis distributed in the hope that it will be useful,16 * kStuff is distributed in the hope that it will be useful, 17 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNUGeneral Public License for more details.18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Lesser General Public License for more details. 20 20 * 21 * You should have received a copy of the GNU General Public License22 * along with kLIBC; if not, write to the Free Software23 * Foundation, Inc., 5 9 Temple Place, Suite 330, Boston, MA 02111-1307USA21 * You should have received a copy of the GNU Lesser General Public 22 * License along with kStuff; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 24 * 25 25 */ 26 27 26 28 27 /******************************************************************************* 29 28 * Header Files * 30 29 *******************************************************************************/ 31 #include "kDbg.h"32 30 #include "kDbgInternal.h" 31 #include <k/kHlpAlloc.h> 33 32 34 33 … … 47 46 { 48 47 kDbgAssertPtrReturn(pSymbol, NULL); 49 size_t cb = KDBG_OFFSETOF(KDBGSYMBOL, szName[pSymbol->cchName + 1]); 50 return (PKDBGSYMBOL)kDbgHlpAllocDup(pSymbol, cb); 48 KSIZE cb = K_OFFSETOF(KDBGSYMBOL, szName[pSymbol->cchName + 1]); 49 PKDBGSYMBOL pNewSymbol = (PKDBGSYMBOL)kHlpDup(pSymbol, cb); 50 if (pNewSymbol) 51 pNewSymbol->cbSelf = cb; 52 return pNewSymbol; 51 53 } 52 54 53 55 54 56 /** 55 * Frees a symbol obtained from the RTDbg API.57 * Frees a symbol obtained from the kDbg API. 56 58 * 57 59 * @returns 0 on success. 58 * @returns KERR_INVALID_POINTER if a NULL pointer or an !KDBG_VALID_PTR() is passed in.60 * @returns KERR_INVALID_POINTER if pSymbol isn't a valid pointer. 59 61 * 60 * @param pSymbol The symbol to be freed. 62 * @param pSymbol The symbol to be freed. The null pointer is ignored. 61 63 */ 62 64 KDBG_DECL(int) kDbgSymbolFree(PKDBGSYMBOL pSymbol) 63 65 { 64 66 if (!pSymbol) 65 return KERR_INVALID_POINTER; 66 kDbgAssertPtrReturn(pSymbol, KERR_INVALID_POINTER); 67 68 kDbgHlpFree(pSymbol); 67 { 68 kDbgAssertPtrReturn(pSymbol, KERR_INVALID_POINTER); 69 pSymbol->cbSelf = 0; 70 kHlpFree(pSymbol); 71 } 69 72 return 0; 70 73 }
Note:
See TracChangeset
for help on using the changeset viewer.