Changeset 20355 in vbox for trunk/src/VBox/Runtime/common/dbg
- Timestamp:
- Jun 7, 2009 9:11:41 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 48278
- Location:
- trunk/src/VBox/Runtime/common/dbg
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/dbg/dbgas.cpp
r19757 r20355 130 130 * Defined Constants And Macros * 131 131 *******************************************************************************/ 132 /** Validates a contexthandle and returns rc if not valid. */132 /** Validates an address space handle and returns rc if not valid. */ 133 133 #define RTDBGAS_VALID_RETURN_RC(pDbgAs, rc) \ 134 134 do { \ … … 337 337 338 338 /** 339 * Retains a reference to the address space.339 * Retains another reference to the address space. 340 340 * 341 341 * @returns New reference count, UINT32_MAX on invalid handle (asserted). -
trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp
r19757 r20355 33 33 *******************************************************************************/ 34 34 #include <iprt/dbg.h> 35 35 36 #include <iprt/asm.h> 37 #include <iprt/assert.h> 36 38 #include <iprt/avl.h> 39 #include <iprt/err.h> 40 #include <iprt/initterm.h> 41 #include <iprt/mem.h> 42 #include <iprt/once.h> 43 #include <iprt/param.h> 44 #include <iprt/semaphore.h> 37 45 #include <iprt/string.h> 38 39 #include <iprt/mem.h>40 #include <iprt/err.h>41 #include <iprt/assert.h>42 #include <iprt/param.h>43 46 #include "internal/dbgmod.h" 44 47 #include "internal/magics.h" 45 48 46 49 47 RTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cb, uint32_t fFlags) 48 { 49 return VERR_NOT_IMPLEMENTED; 50 /******************************************************************************* 51 * Structures and Typedefs * 52 *******************************************************************************/ 53 /** Debug info interpreter regisration record. */ 54 typedef struct RTDBGMODREGDBG 55 { 56 /** Pointer to the next record. */ 57 struct RTDBGMODREGDBG *pNext; 58 /** Pointer to the virtual function table for the interpreter. */ 59 PCRTDBGMODVTDBG pVt; 60 /** Usage counter. */ 61 uint32_t volatile cUsers; 62 } RTDBGMODREGDBG; 63 typedef RTDBGMODREGDBG *PRTDBGMODREGDBG; 64 65 /** Image interpreter regisration record. */ 66 typedef struct RTDBGMODREGIMG 67 { 68 /** Pointer to the next record. */ 69 struct RTDBGMODREGIMG *pNext; 70 /** Pointer to the virtual function table for the interpreter. */ 71 PCRTDBGMODVTIMG pVt; 72 /** Usage counter. */ 73 uint32_t volatile cUsers; 74 } RTDBGMODREGIMG; 75 typedef RTDBGMODREGIMG *PRTDBGMODREGIMG; 76 77 78 /******************************************************************************* 79 * Defined Constants And Macros * 80 *******************************************************************************/ 81 /** Validates a debug module handle and returns rc if not valid. */ 82 #define RTDBGMOD_VALID_RETURN_RC(pDbgMod, rc) \ 83 do { \ 84 AssertPtrReturn((pDbgMod), (rc)); \ 85 AssertReturn((pDbgMod)->u32Magic == RTDBGMOD_MAGIC, (rc)); \ 86 AssertReturn((pDbgMod)->cRefs > 0, (rc)); \ 87 } while (0) 88 89 /** Locks the debug module. */ 90 #define RTDBGMOD_LOCK(pDbgMod) \ 91 do { \ 92 int rcLock = RTCritSectEnter(&(pDbgMod)->CritSect); \ 93 AssertRC(rcLock); \ 94 } while (0) 95 96 /** Unlocks the debug module. */ 97 #define RTDBGMOD_UNLOCK(pDbgMod) \ 98 do { \ 99 int rcLock = RTCritSectLeave(&(pDbgMod)->CritSect); \ 100 AssertRC(rcLock); \ 101 } while (0) 102 103 104 /******************************************************************************* 105 * Global Variables * 106 *******************************************************************************/ 107 /** Init once object for lazy registration of the built-in image and debug 108 * info interpreters. */ 109 static RTONCE g_rtDbgModOnce = RTONCE_INITIALIZER; 110 /** Read/Write semaphore protecting the list of registered interpreters. */ 111 static RTSEMRW g_hDbgModRWSem = NIL_RTSEMRW; 112 /** List of registered image interpreters. */ 113 static RTDBGMODREGIMG g_pImgHead; 114 /** List of registered debug infor interpreters. */ 115 static RTDBGMODREGDBG g_pDbgHead; 116 117 118 119 /** 120 * Do-once callback that initializes the read/write semaphore and registers 121 * the built-in interpreters. 122 * 123 * @returns IPRT status code. 124 * @param pvUser1 NULL. 125 * @param pvUser2 NULL. 126 */ 127 static DECLCALLBACK(int) rtDbgModInitOnce(void *pvUser1, void *pvUser2) 128 { 129 int rc = RTSemRWCreate(&g_hDbgModRWSem); 130 AssertRCReturn(rc, rc); 131 132 /* Register them. */ 133 134 return rc; 135 } 136 137 138 DECLINLINE(int) rtDbgModLazyInit(void) 139 { 140 return RTOnce(&g_rtDbgModOnce, rtDbgModInitOnce, NULL, NULL); 141 } 142 143 144 RTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cb, uint32_t fFlags) 145 { 146 /* 147 * Input validation and lazy initialization. 148 */ 149 AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER); 150 *phDbgMod = NIL_RTDBGMOD; 151 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 152 AssertReturn(*pszName, VERR_INVALID_PARAMETER); 153 AssertReturn(cb > 0, VERR_INVALID_PARAMETER); 154 AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER); 155 156 int rc = rtDbgModLazyInit(); 157 if (RT_FAILURE(rc)) 158 return rc; 159 160 /* 161 * Allocate a new module instance. 162 */ 163 PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod)); 164 if (!pDbgMod) 165 return VERR_NO_MEMORY; 166 pDbgMod->u32Magic = RTDBGMOD_MAGIC; 167 pDbgMod->cRefs = 1; 168 rc = RTCritSectInit(&pDbgMod->CritSect); 169 if (RT_SUCCESS(rc)) 170 { 171 pDbgMod->pszName = RTStrDup(pszName); 172 if (pDbgMod->pszName) 173 { 174 pDbgMod->pDbgVt = &g_rtDbgModVtDbgContainer; 175 rc = pDbgMod->pDbgVt->pfnTryOpen(pDbgMod); 176 if (RT_SUCCESS(rc)) 177 { 178 *phDbgMod = pDbgMod; 179 return rc; 180 } 181 RTStrFree(pDbgMod->pszName); 182 } 183 RTCritSectDelete(&pDbgMod->CritSect); 184 } 185 186 RTMemFree(pDbgMod); 187 return rc; 50 188 } 51 189 … … 60 198 } 61 199 62 RTDECL(int) RTDbgModDestroy(RTDBGMOD hDbgMod) 63 { 64 return VERR_NOT_IMPLEMENTED; 65 } 66 67 RTDECL(uint32_t) RTDbgModRetain(RTDBGMOD hDbgMod) 68 { 69 return 0; 70 } 71 72 RTDECL(uint32_t) RTDbgModRelease(RTDBGMOD hDbgMod) 73 { 74 return 0; 75 } 76 200 201 /** 202 * Destroys an module after the reference count has reached zero. 203 * 204 * @param pDbgMod The module instance. 205 */ 206 static void rtDbgModDestroy(PRTDBGMODINT pDbgMod) 207 { 208 /* 209 * Close the debug info interpreter first, then the image interpret. 210 */ 211 RTCritSectEnter(&pDbgMod->CritSect); /* paranoia */ 212 if (pDbgMod->pDbgVt) 213 pDbgMod->pDbgVt->pfnClose(pDbgMod); 214 if (pDbgMod->pImgVt) 215 pDbgMod->pImgVt->pfnClose(pDbgMod); 216 217 /* 218 * Free the resources. 219 */ 220 ASMAtomicWriteU32(&pDbgMod->u32Magic, ~RTDBGMOD_MAGIC); 221 RTStrFree(pDbgMod->pszName); 222 RTStrFree(pDbgMod->pszImgFile); 223 RTStrFree(pDbgMod->pszDbgFile); 224 RTCritSectLeave(&pDbgMod->CritSect); /* paranoia */ 225 RTCritSectDelete(&pDbgMod->CritSect); 226 RTMemFree(pDbgMod); 227 } 228 229 230 /** 231 * Retains another reference to the module. 232 * 233 * @returns New reference count, UINT32_MAX on invalid handle (asserted). 234 * 235 * @param hDbgMod The module handle. 236 * 237 * @remarks Will not take any locks. 238 */ 239 RTDECL(uint32_t) RTDbgModRetain(RTDBGMOD hDbgMod) 240 { 241 PRTDBGMODINT pDbgMod = hDbgMod; 242 RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX); 243 return ASMAtomicIncU32(&pDbgMod->cRefs); 244 } 245 246 247 /** 248 * Release a reference to the module. 249 * 250 * When the reference count reaches zero, the module is destroyed. 251 * 252 * @returns New reference count, UINT32_MAX on invalid handle (asserted). 253 * 254 * @param hDbgMod The module handle. The NIL handle is quietly ignored 255 * and 0 is returned. 256 * 257 * @remarks Will not take any locks. 258 */ 259 RTDECL(uint32_t) RTDbgModRelease(RTDBGMOD hDbgMod) 260 { 261 if (hDbgMod == NIL_RTDBGMOD) 262 return 0; 263 PRTDBGMODINT pDbgMod = hDbgMod; 264 RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX); 265 266 uint32_t cRefs = ASMAtomicDecU32(&pDbgMod->cRefs); 267 if (!cRefs) 268 rtDbgModDestroy(pDbgMod); 269 return cRefs; 270 } 271 272 273 /** 274 * Gets the module name. 275 * 276 * @returns Pointer to a read only string containing the name. 277 * 278 * @param hDbgMod The module handle. 279 */ 77 280 RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod) 78 281 { 79 return NULL; 80 } 282 PRTDBGMODINT pDbgMod = hDbgMod; 283 RTDBGMOD_VALID_RETURN_RC(pDbgMod, NULL); 284 return pDbgMod->pszName; 285 } 286 81 287 82 288 RTDECL(RTUINTPTR) RTDbgModImageSize(RTDBGMOD hDbgMod)
Note:
See TracChangeset
for help on using the changeset viewer.