1 | /* $Id: dbgmod.cpp 46199 2013-05-21 19:49:19Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Debug Module Interpreter.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*******************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *******************************************************************************/
|
---|
31 | #define LOG_GROUP RTLOGGROUP_DBG
|
---|
32 | #include <iprt/dbg.h>
|
---|
33 | #include "internal/iprt.h"
|
---|
34 |
|
---|
35 | #include <iprt/alloca.h>
|
---|
36 | #include <iprt/asm.h>
|
---|
37 | #include <iprt/assert.h>
|
---|
38 | #include <iprt/avl.h>
|
---|
39 | #include <iprt/err.h>
|
---|
40 | #include <iprt/initterm.h>
|
---|
41 | #include <iprt/log.h>
|
---|
42 | #include <iprt/mem.h>
|
---|
43 | #include <iprt/once.h>
|
---|
44 | #include <iprt/param.h>
|
---|
45 | #include <iprt/path.h>
|
---|
46 | #include <iprt/semaphore.h>
|
---|
47 | #include <iprt/strcache.h>
|
---|
48 | #include <iprt/string.h>
|
---|
49 | #include "internal/dbgmod.h"
|
---|
50 | #include "internal/magics.h"
|
---|
51 |
|
---|
52 |
|
---|
53 | /*******************************************************************************
|
---|
54 | * Structures and Typedefs *
|
---|
55 | *******************************************************************************/
|
---|
56 | /** Debug info interpreter registration record. */
|
---|
57 | typedef struct RTDBGMODREGDBG
|
---|
58 | {
|
---|
59 | /** Pointer to the next record. */
|
---|
60 | struct RTDBGMODREGDBG *pNext;
|
---|
61 | /** Pointer to the virtual function table for the interpreter. */
|
---|
62 | PCRTDBGMODVTDBG pVt;
|
---|
63 | /** Usage counter. */
|
---|
64 | uint32_t volatile cUsers;
|
---|
65 | } RTDBGMODREGDBG;
|
---|
66 | typedef RTDBGMODREGDBG *PRTDBGMODREGDBG;
|
---|
67 |
|
---|
68 | /** Image interpreter registration record. */
|
---|
69 | typedef struct RTDBGMODREGIMG
|
---|
70 | {
|
---|
71 | /** Pointer to the next record. */
|
---|
72 | struct RTDBGMODREGIMG *pNext;
|
---|
73 | /** Pointer to the virtual function table for the interpreter. */
|
---|
74 | PCRTDBGMODVTIMG pVt;
|
---|
75 | /** Usage counter. */
|
---|
76 | uint32_t volatile cUsers;
|
---|
77 | } RTDBGMODREGIMG;
|
---|
78 | typedef RTDBGMODREGIMG *PRTDBGMODREGIMG;
|
---|
79 |
|
---|
80 |
|
---|
81 | /*******************************************************************************
|
---|
82 | * Defined Constants And Macros *
|
---|
83 | *******************************************************************************/
|
---|
84 | /** Validates a debug module handle and returns rc if not valid. */
|
---|
85 | #define RTDBGMOD_VALID_RETURN_RC(pDbgMod, rc) \
|
---|
86 | do { \
|
---|
87 | AssertPtrReturn((pDbgMod), (rc)); \
|
---|
88 | AssertReturn((pDbgMod)->u32Magic == RTDBGMOD_MAGIC, (rc)); \
|
---|
89 | AssertReturn((pDbgMod)->cRefs > 0, (rc)); \
|
---|
90 | } while (0)
|
---|
91 |
|
---|
92 | /** Locks the debug module. */
|
---|
93 | #define RTDBGMOD_LOCK(pDbgMod) \
|
---|
94 | do { \
|
---|
95 | int rcLock = RTCritSectEnter(&(pDbgMod)->CritSect); \
|
---|
96 | AssertRC(rcLock); \
|
---|
97 | } while (0)
|
---|
98 |
|
---|
99 | /** Unlocks the debug module. */
|
---|
100 | #define RTDBGMOD_UNLOCK(pDbgMod) \
|
---|
101 | do { \
|
---|
102 | int rcLock = RTCritSectLeave(&(pDbgMod)->CritSect); \
|
---|
103 | AssertRC(rcLock); \
|
---|
104 | } while (0)
|
---|
105 |
|
---|
106 |
|
---|
107 | /*******************************************************************************
|
---|
108 | * Global Variables *
|
---|
109 | *******************************************************************************/
|
---|
110 | /** Init once object for lazy registration of the built-in image and debug
|
---|
111 | * info interpreters. */
|
---|
112 | static RTONCE g_rtDbgModOnce = RTONCE_INITIALIZER;
|
---|
113 | /** Read/Write semaphore protecting the list of registered interpreters. */
|
---|
114 | static RTSEMRW g_hDbgModRWSem = NIL_RTSEMRW;
|
---|
115 | /** List of registered image interpreters. */
|
---|
116 | static PRTDBGMODREGIMG g_pImgHead;
|
---|
117 | /** List of registered debug infor interpreters. */
|
---|
118 | static PRTDBGMODREGDBG g_pDbgHead;
|
---|
119 | /** String cache for the debug info interpreters.
|
---|
120 | * RTSTRCACHE is thread safe. */
|
---|
121 | DECLHIDDEN(RTSTRCACHE) g_hDbgModStrCache = NIL_RTSTRCACHE;
|
---|
122 |
|
---|
123 |
|
---|
124 |
|
---|
125 |
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Cleanup debug info interpreter globals.
|
---|
129 | *
|
---|
130 | * @param enmReason The cause of the termination.
|
---|
131 | * @param iStatus The meaning of this depends on enmReason.
|
---|
132 | * @param pvUser User argument, unused.
|
---|
133 | */
|
---|
134 | static DECLCALLBACK(void) rtDbgModTermCallback(RTTERMREASON enmReason, int32_t iStatus, void *pvUser)
|
---|
135 | {
|
---|
136 | NOREF(iStatus); NOREF(pvUser);
|
---|
137 | if (enmReason == RTTERMREASON_UNLOAD)
|
---|
138 | {
|
---|
139 | RTSemRWDestroy(g_hDbgModRWSem);
|
---|
140 | g_hDbgModRWSem = NIL_RTSEMRW;
|
---|
141 |
|
---|
142 | RTStrCacheDestroy(g_hDbgModStrCache);
|
---|
143 | g_hDbgModStrCache = NIL_RTSTRCACHE;
|
---|
144 |
|
---|
145 | PRTDBGMODREGDBG pDbg = g_pDbgHead;
|
---|
146 | g_pDbgHead = NULL;
|
---|
147 | while (pDbg)
|
---|
148 | {
|
---|
149 | PRTDBGMODREGDBG pNext = pDbg->pNext;
|
---|
150 | AssertMsg(pDbg->cUsers == 0, ("%#x %s\n", pDbg->cUsers, pDbg->pVt->pszName));
|
---|
151 | RTMemFree(pDbg);
|
---|
152 | pDbg = pNext;
|
---|
153 | }
|
---|
154 |
|
---|
155 | PRTDBGMODREGIMG pImg = g_pImgHead;
|
---|
156 | g_pImgHead = NULL;
|
---|
157 | while (pImg)
|
---|
158 | {
|
---|
159 | PRTDBGMODREGIMG pNext = pImg->pNext;
|
---|
160 | AssertMsg(pImg->cUsers == 0, ("%#x %s\n", pImg->cUsers, pImg->pVt->pszName));
|
---|
161 | RTMemFree(pImg);
|
---|
162 | pImg = pNext;
|
---|
163 | }
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Internal worker for register a debug interpreter.
|
---|
170 | *
|
---|
171 | * Called while owning the write lock or when locking isn't required.
|
---|
172 | *
|
---|
173 | * @returns IPRT status code.
|
---|
174 | * @retval VERR_NO_MEMORY
|
---|
175 | * @retval VERR_ALREADY_EXISTS
|
---|
176 | *
|
---|
177 | * @param pVt The virtual function table of the debug
|
---|
178 | * module interpreter.
|
---|
179 | */
|
---|
180 | static int rtDbgModDebugInterpreterRegister(PCRTDBGMODVTDBG pVt)
|
---|
181 | {
|
---|
182 | /*
|
---|
183 | * Search or duplicate registration.
|
---|
184 | */
|
---|
185 | PRTDBGMODREGDBG pPrev = NULL;
|
---|
186 | for (PRTDBGMODREGDBG pCur = g_pDbgHead; pCur; pCur = pCur->pNext)
|
---|
187 | {
|
---|
188 | if (pCur->pVt == pVt)
|
---|
189 | return VERR_ALREADY_EXISTS;
|
---|
190 | if (!strcmp(pCur->pVt->pszName, pVt->pszName))
|
---|
191 | return VERR_ALREADY_EXISTS;
|
---|
192 | pPrev = pCur;
|
---|
193 | }
|
---|
194 |
|
---|
195 | /*
|
---|
196 | * Create a new record and add it to the end of the list.
|
---|
197 | */
|
---|
198 | PRTDBGMODREGDBG pReg = (PRTDBGMODREGDBG)RTMemAlloc(sizeof(*pReg));
|
---|
199 | if (!pReg)
|
---|
200 | return VERR_NO_MEMORY;
|
---|
201 | pReg->pVt = pVt;
|
---|
202 | pReg->cUsers = 0;
|
---|
203 | pReg->pNext = NULL;
|
---|
204 | if (pPrev)
|
---|
205 | pPrev->pNext = pReg;
|
---|
206 | else
|
---|
207 | g_pDbgHead = pReg;
|
---|
208 | return VINF_SUCCESS;
|
---|
209 | }
|
---|
210 |
|
---|
211 |
|
---|
212 | /**
|
---|
213 | * Internal worker for register a image interpreter.
|
---|
214 | *
|
---|
215 | * Called while owning the write lock or when locking isn't required.
|
---|
216 | *
|
---|
217 | * @returns IPRT status code.
|
---|
218 | * @retval VERR_NO_MEMORY
|
---|
219 | * @retval VERR_ALREADY_EXISTS
|
---|
220 | *
|
---|
221 | * @param pVt The virtual function table of the image
|
---|
222 | * interpreter.
|
---|
223 | */
|
---|
224 | static int rtDbgModImageInterpreterRegister(PCRTDBGMODVTIMG pVt)
|
---|
225 | {
|
---|
226 | /*
|
---|
227 | * Search or duplicate registration.
|
---|
228 | */
|
---|
229 | PRTDBGMODREGIMG pPrev = NULL;
|
---|
230 | for (PRTDBGMODREGIMG pCur = g_pImgHead; pCur; pCur = pCur->pNext)
|
---|
231 | {
|
---|
232 | if (pCur->pVt == pVt)
|
---|
233 | return VERR_ALREADY_EXISTS;
|
---|
234 | if (!strcmp(pCur->pVt->pszName, pVt->pszName))
|
---|
235 | return VERR_ALREADY_EXISTS;
|
---|
236 | pPrev = pCur;
|
---|
237 | }
|
---|
238 |
|
---|
239 | /*
|
---|
240 | * Create a new record and add it to the end of the list.
|
---|
241 | */
|
---|
242 | PRTDBGMODREGIMG pReg = (PRTDBGMODREGIMG)RTMemAlloc(sizeof(*pReg));
|
---|
243 | if (!pReg)
|
---|
244 | return VERR_NO_MEMORY;
|
---|
245 | pReg->pVt = pVt;
|
---|
246 | pReg->cUsers = 0;
|
---|
247 | pReg->pNext = NULL;
|
---|
248 | if (pPrev)
|
---|
249 | pPrev->pNext = pReg;
|
---|
250 | else
|
---|
251 | g_pImgHead = pReg;
|
---|
252 | return VINF_SUCCESS;
|
---|
253 | }
|
---|
254 |
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * Do-once callback that initializes the read/write semaphore and registers
|
---|
258 | * the built-in interpreters.
|
---|
259 | *
|
---|
260 | * @returns IPRT status code.
|
---|
261 | * @param pvUser NULL.
|
---|
262 | */
|
---|
263 | static DECLCALLBACK(int) rtDbgModInitOnce(void *pvUser)
|
---|
264 | {
|
---|
265 | NOREF(pvUser);
|
---|
266 |
|
---|
267 | /*
|
---|
268 | * Create the semaphore and string cache.
|
---|
269 | */
|
---|
270 | int rc = RTSemRWCreate(&g_hDbgModRWSem);
|
---|
271 | AssertRCReturn(rc, rc);
|
---|
272 |
|
---|
273 | rc = RTStrCacheCreate(&g_hDbgModStrCache, "RTDBGMOD");
|
---|
274 | if (RT_SUCCESS(rc))
|
---|
275 | {
|
---|
276 | /*
|
---|
277 | * Register the interpreters.
|
---|
278 | */
|
---|
279 | rc = rtDbgModDebugInterpreterRegister(&g_rtDbgModVtDbgNm);
|
---|
280 | if (RT_SUCCESS(rc))
|
---|
281 | rc = rtDbgModDebugInterpreterRegister(&g_rtDbgModVtDbgDwarf);
|
---|
282 | #ifdef RT_OS_WINDOWS
|
---|
283 | if (RT_SUCCESS(rc))
|
---|
284 | rc = rtDbgModDebugInterpreterRegister(&g_rtDbgModVtDbgDbgHelp);
|
---|
285 | #endif
|
---|
286 | if (RT_SUCCESS(rc))
|
---|
287 | rc = rtDbgModImageInterpreterRegister(&g_rtDbgModVtImgLdr);
|
---|
288 | if (RT_SUCCESS(rc))
|
---|
289 | {
|
---|
290 | /*
|
---|
291 | * Finally, register the IPRT cleanup callback.
|
---|
292 | */
|
---|
293 | rc = RTTermRegisterCallback(rtDbgModTermCallback, NULL);
|
---|
294 | if (RT_SUCCESS(rc))
|
---|
295 | return VINF_SUCCESS;
|
---|
296 |
|
---|
297 | /* bail out: use the termination callback. */
|
---|
298 | }
|
---|
299 | }
|
---|
300 | else
|
---|
301 | g_hDbgModStrCache = NIL_RTSTRCACHE;
|
---|
302 | rtDbgModTermCallback(RTTERMREASON_UNLOAD, 0, NULL);
|
---|
303 | return rc;
|
---|
304 | }
|
---|
305 |
|
---|
306 |
|
---|
307 | /**
|
---|
308 | * Performs lazy init of our global variables.
|
---|
309 | * @returns IPRT status code.
|
---|
310 | */
|
---|
311 | DECLINLINE(int) rtDbgModLazyInit(void)
|
---|
312 | {
|
---|
313 | return RTOnce(&g_rtDbgModOnce, rtDbgModInitOnce, NULL);
|
---|
314 | }
|
---|
315 |
|
---|
316 |
|
---|
317 | RTDECL(int) RTDbgModCreate(PRTDBGMOD phDbgMod, const char *pszName, RTUINTPTR cbSeg, uint32_t fFlags)
|
---|
318 | {
|
---|
319 | /*
|
---|
320 | * Input validation and lazy initialization.
|
---|
321 | */
|
---|
322 | AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER);
|
---|
323 | *phDbgMod = NIL_RTDBGMOD;
|
---|
324 | AssertPtrReturn(pszName, VERR_INVALID_POINTER);
|
---|
325 | AssertReturn(*pszName, VERR_INVALID_PARAMETER);
|
---|
326 | AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER);
|
---|
327 |
|
---|
328 | int rc = rtDbgModLazyInit();
|
---|
329 | if (RT_FAILURE(rc))
|
---|
330 | return rc;
|
---|
331 |
|
---|
332 | /*
|
---|
333 | * Allocate a new module instance.
|
---|
334 | */
|
---|
335 | PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod));
|
---|
336 | if (!pDbgMod)
|
---|
337 | return VERR_NO_MEMORY;
|
---|
338 | pDbgMod->u32Magic = RTDBGMOD_MAGIC;
|
---|
339 | pDbgMod->cRefs = 1;
|
---|
340 | rc = RTCritSectInit(&pDbgMod->CritSect);
|
---|
341 | if (RT_SUCCESS(rc))
|
---|
342 | {
|
---|
343 | pDbgMod->pszImgFileSpecified = RTStrCacheEnter(g_hDbgModStrCache, pszName);
|
---|
344 | pDbgMod->pszName = RTStrCacheEnterLower(g_hDbgModStrCache, RTPathFilenameEx(pszName, RTPATH_STR_F_STYLE_DOS));
|
---|
345 | if (pDbgMod->pszName)
|
---|
346 | {
|
---|
347 | rc = rtDbgModContainerCreate(pDbgMod, cbSeg);
|
---|
348 | if (RT_SUCCESS(rc))
|
---|
349 | {
|
---|
350 | *phDbgMod = pDbgMod;
|
---|
351 | return rc;
|
---|
352 | }
|
---|
353 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile);
|
---|
354 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
|
---|
355 | }
|
---|
356 | RTCritSectDelete(&pDbgMod->CritSect);
|
---|
357 | }
|
---|
358 |
|
---|
359 | RTMemFree(pDbgMod);
|
---|
360 | return rc;
|
---|
361 | }
|
---|
362 | RT_EXPORT_SYMBOL(RTDbgModCreate);
|
---|
363 |
|
---|
364 |
|
---|
365 | RTDECL(int) RTDbgModCreateFromMap(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName,
|
---|
366 | RTUINTPTR uSubtrahend, RTDBGCFG hDbgCfg)
|
---|
367 | {
|
---|
368 | /*
|
---|
369 | * Input validation and lazy initialization.
|
---|
370 | */
|
---|
371 | AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER);
|
---|
372 | *phDbgMod = NIL_RTDBGMOD;
|
---|
373 | AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
|
---|
374 | AssertReturn(*pszFilename, VERR_INVALID_PARAMETER);
|
---|
375 | AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
|
---|
376 | AssertReturn(uSubtrahend == 0, VERR_NOT_IMPLEMENTED); /** @todo implement uSubtrahend. */
|
---|
377 |
|
---|
378 | int rc = rtDbgModLazyInit();
|
---|
379 | if (RT_FAILURE(rc))
|
---|
380 | return rc;
|
---|
381 |
|
---|
382 | if (!pszName)
|
---|
383 | pszName = RTPathFilenameEx(pszFilename, RTPATH_STR_F_STYLE_DOS);
|
---|
384 |
|
---|
385 | /*
|
---|
386 | * Allocate a new module instance.
|
---|
387 | */
|
---|
388 | PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod));
|
---|
389 | if (!pDbgMod)
|
---|
390 | return VERR_NO_MEMORY;
|
---|
391 | pDbgMod->u32Magic = RTDBGMOD_MAGIC;
|
---|
392 | pDbgMod->cRefs = 1;
|
---|
393 | rc = RTCritSectInit(&pDbgMod->CritSect);
|
---|
394 | if (RT_SUCCESS(rc))
|
---|
395 | {
|
---|
396 | pDbgMod->pszName = RTStrCacheEnterLower(g_hDbgModStrCache, pszName);
|
---|
397 | if (pDbgMod->pszName)
|
---|
398 | {
|
---|
399 | pDbgMod->pszDbgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
|
---|
400 | if (pDbgMod->pszDbgFile)
|
---|
401 | {
|
---|
402 | /*
|
---|
403 | * Try the map file readers.
|
---|
404 | */
|
---|
405 | rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
|
---|
406 | if (RT_SUCCESS(rc))
|
---|
407 | {
|
---|
408 | rc = VERR_DBG_NO_MATCHING_INTERPRETER;
|
---|
409 | for (PRTDBGMODREGDBG pCur = g_pDbgHead; pCur; pCur = pCur->pNext)
|
---|
410 | {
|
---|
411 | if (pCur->pVt->fSupports & RT_DBGTYPE_MAP)
|
---|
412 | {
|
---|
413 | pDbgMod->pDbgVt = pCur->pVt;
|
---|
414 | pDbgMod->pvDbgPriv = NULL;
|
---|
415 | rc = pCur->pVt->pfnTryOpen(pDbgMod, RTLDRARCH_WHATEVER);
|
---|
416 | if (RT_SUCCESS(rc))
|
---|
417 | {
|
---|
418 | ASMAtomicIncU32(&pCur->cUsers);
|
---|
419 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
420 |
|
---|
421 | *phDbgMod = pDbgMod;
|
---|
422 | return rc;
|
---|
423 | }
|
---|
424 | }
|
---|
425 | }
|
---|
426 |
|
---|
427 | /* bail out */
|
---|
428 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
429 | }
|
---|
430 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
|
---|
431 | }
|
---|
432 | else
|
---|
433 | rc = VERR_NO_STR_MEMORY;
|
---|
434 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszDbgFile);
|
---|
435 | }
|
---|
436 | else
|
---|
437 | rc = VERR_NO_STR_MEMORY;
|
---|
438 | RTCritSectDelete(&pDbgMod->CritSect);
|
---|
439 | }
|
---|
440 |
|
---|
441 | RTMemFree(pDbgMod);
|
---|
442 | return rc;
|
---|
443 | }
|
---|
444 | RT_EXPORT_SYMBOL(RTDbgModCreateFromMap);
|
---|
445 |
|
---|
446 |
|
---|
447 |
|
---|
448 | /*
|
---|
449 | *
|
---|
450 | * E x e c u t a b l e I m a g e F i l e s
|
---|
451 | * E x e c u t a b l e I m a g e F i l e s
|
---|
452 | * E x e c u t a b l e I m a g e F i l e s
|
---|
453 | *
|
---|
454 | */
|
---|
455 |
|
---|
456 |
|
---|
457 | /**
|
---|
458 | * Opens debug information for an image.
|
---|
459 | *
|
---|
460 | * @returns IPRT status code
|
---|
461 | * @param pDbgMod The debug module structure.
|
---|
462 | *
|
---|
463 | * @note This will generally not look for debug info stored in external
|
---|
464 | * files. rtDbgModFromPeImageExtDbgInfoCallback can help with that.
|
---|
465 | */
|
---|
466 | static int rtDbgModOpenDebugInfoInsideImage(PRTDBGMODINT pDbgMod)
|
---|
467 | {
|
---|
468 | AssertReturn(!pDbgMod->pDbgVt, VERR_DBG_MOD_IPE);
|
---|
469 | AssertReturn(pDbgMod->pImgVt, VERR_DBG_MOD_IPE);
|
---|
470 |
|
---|
471 | int rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
|
---|
472 | if (RT_SUCCESS(rc))
|
---|
473 | {
|
---|
474 | for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext)
|
---|
475 | {
|
---|
476 | pDbgMod->pDbgVt = pDbg->pVt;
|
---|
477 | pDbgMod->pvDbgPriv = NULL;
|
---|
478 | rc = pDbg->pVt->pfnTryOpen(pDbgMod, pDbgMod->pImgVt->pfnGetArch(pDbgMod));
|
---|
479 | if (RT_SUCCESS(rc))
|
---|
480 | {
|
---|
481 | /*
|
---|
482 | * That's it!
|
---|
483 | */
|
---|
484 | ASMAtomicIncU32(&pDbg->cUsers);
|
---|
485 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
486 | return VINF_SUCCESS;
|
---|
487 | }
|
---|
488 |
|
---|
489 | pDbgMod->pDbgVt = NULL;
|
---|
490 | Assert(pDbgMod->pvDbgPriv == NULL);
|
---|
491 | }
|
---|
492 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
493 | }
|
---|
494 |
|
---|
495 | return VERR_DBG_NO_MATCHING_INTERPRETER;
|
---|
496 | }
|
---|
497 |
|
---|
498 |
|
---|
499 | /** @callback_method_impl{FNRTDBGCFGOPEN} */
|
---|
500 | static DECLCALLBACK(int) rtDbgModExtDbgInfoOpenCallback(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2)
|
---|
501 | {
|
---|
502 | PRTDBGMODINT pDbgMod = (PRTDBGMODINT)pvUser1;
|
---|
503 | PCRTLDRDBGINFO pDbgInfo = (PCRTLDRDBGINFO)pvUser2;
|
---|
504 | NOREF(pDbgInfo); /** @todo consider a more direct search for a interpreter. */
|
---|
505 |
|
---|
506 | Assert(!pDbgMod->pDbgVt);
|
---|
507 | Assert(!pDbgMod->pvDbgPriv);
|
---|
508 | Assert(!pDbgMod->pszDbgFile);
|
---|
509 | Assert(pDbgMod->pImgVt);
|
---|
510 |
|
---|
511 | /*
|
---|
512 | * Set the debug file name and try possible interpreters.
|
---|
513 | */
|
---|
514 | pDbgMod->pszDbgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
|
---|
515 |
|
---|
516 | int rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
|
---|
517 | if (RT_SUCCESS(rc))
|
---|
518 | {
|
---|
519 | for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext)
|
---|
520 | {
|
---|
521 | pDbgMod->pDbgVt = pDbg->pVt;
|
---|
522 | pDbgMod->pvDbgPriv = NULL;
|
---|
523 | rc = pDbg->pVt->pfnTryOpen(pDbgMod, pDbgMod->pImgVt->pfnGetArch(pDbgMod));
|
---|
524 | if (RT_SUCCESS(rc))
|
---|
525 | {
|
---|
526 | /*
|
---|
527 | * Got it!
|
---|
528 | */
|
---|
529 | ASMAtomicIncU32(&pDbg->cUsers);
|
---|
530 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
531 | return VINF_CALLBACK_RETURN;
|
---|
532 | }
|
---|
533 |
|
---|
534 | pDbgMod->pDbgVt = NULL;
|
---|
535 | Assert(pDbgMod->pvDbgPriv == NULL);
|
---|
536 | }
|
---|
537 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
538 | }
|
---|
539 |
|
---|
540 | /* No joy. */
|
---|
541 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszDbgFile);
|
---|
542 | pDbgMod->pszDbgFile = NULL;
|
---|
543 | return rc;
|
---|
544 | }
|
---|
545 |
|
---|
546 |
|
---|
547 | /**
|
---|
548 | * Argument package used by rtDbgModOpenDebugInfoExternalToImage.
|
---|
549 | */
|
---|
550 | typedef struct RTDBGMODOPENDIETI
|
---|
551 | {
|
---|
552 | PRTDBGMODINT pDbgMod;
|
---|
553 | RTDBGCFG hDbgCfg;
|
---|
554 | } RTDBGMODOPENDIETI;
|
---|
555 |
|
---|
556 |
|
---|
557 | /** @callback_method_impl{FNRTLDRENUMDBG} */
|
---|
558 | static DECLCALLBACK(int)
|
---|
559 | rtDbgModOpenDebugInfoExternalToImageCallback(RTLDRMOD hLdrMod, PCRTLDRDBGINFO pDbgInfo, void *pvUser)
|
---|
560 | {
|
---|
561 | RTDBGMODOPENDIETI *pArgs = (RTDBGMODOPENDIETI *)pvUser;
|
---|
562 |
|
---|
563 | Assert(pDbgInfo->enmType > RTLDRDBGINFOTYPE_INVALID && pDbgInfo->enmType < RTLDRDBGINFOTYPE_END);
|
---|
564 | const char *pszExtFile = pDbgInfo->pszExtFile;
|
---|
565 | if (!pszExtFile)
|
---|
566 | {
|
---|
567 | /*
|
---|
568 | * If a external debug type comes without a file name, calculate a
|
---|
569 | * likely debug filename for it. (Hack for NT4 drivers.)
|
---|
570 | */
|
---|
571 | const char *pszExt = NULL;
|
---|
572 | if (pDbgInfo->enmType == RTLDRDBGINFOTYPE_CODEVIEW_DBG)
|
---|
573 | pszExt = ".dbg";
|
---|
574 | else if ( pDbgInfo->enmType == RTLDRDBGINFOTYPE_CODEVIEW_PDB20
|
---|
575 | || pDbgInfo->enmType == RTLDRDBGINFOTYPE_CODEVIEW_PDB70)
|
---|
576 | pszExt = ".pdb";
|
---|
577 | if (pszExt && pArgs->pDbgMod->pszName)
|
---|
578 | {
|
---|
579 | size_t cchName = strlen(pArgs->pDbgMod->pszName);
|
---|
580 | char *psz = (char *)alloca(cchName + strlen(pszExt) + 1);
|
---|
581 | if (psz)
|
---|
582 | {
|
---|
583 | memcpy(psz, pArgs->pDbgMod->pszName, cchName + 1);
|
---|
584 | RTPathStripExt(psz);
|
---|
585 | pszExtFile = strcat(psz, pszExt);
|
---|
586 | }
|
---|
587 | }
|
---|
588 |
|
---|
589 | if (!pszExtFile)
|
---|
590 | {
|
---|
591 | Log2(("rtDbgModOpenDebugInfoExternalToImageCallback: enmType=%d\n", pDbgInfo->enmType));
|
---|
592 | return VINF_SUCCESS;
|
---|
593 | }
|
---|
594 | }
|
---|
595 |
|
---|
596 | /*
|
---|
597 | * Switch on type and call the appropriate search function.
|
---|
598 | */
|
---|
599 | int rc;
|
---|
600 | switch (pDbgInfo->enmType)
|
---|
601 | {
|
---|
602 | case RTLDRDBGINFOTYPE_CODEVIEW_PDB70:
|
---|
603 | rc = RTDbgCfgOpenPdb70(pArgs->hDbgCfg, pszExtFile,
|
---|
604 | &pDbgInfo->u.Pdb70.Uuid,
|
---|
605 | pDbgInfo->u.Pdb70.uAge,
|
---|
606 | rtDbgModExtDbgInfoOpenCallback, pArgs->pDbgMod, (void *)pDbgInfo);
|
---|
607 | break;
|
---|
608 |
|
---|
609 | case RTLDRDBGINFOTYPE_CODEVIEW_PDB20:
|
---|
610 | rc = RTDbgCfgOpenPdb20(pArgs->hDbgCfg, pszExtFile,
|
---|
611 | pDbgInfo->u.Pdb20.cbImage,
|
---|
612 | pDbgInfo->u.Pdb20.uTimestamp,
|
---|
613 | pDbgInfo->u.Pdb20.uAge,
|
---|
614 | rtDbgModExtDbgInfoOpenCallback, pArgs->pDbgMod, (void *)pDbgInfo);
|
---|
615 | break;
|
---|
616 |
|
---|
617 | case RTLDRDBGINFOTYPE_CODEVIEW_DBG:
|
---|
618 | rc = RTDbgCfgOpenDbg(pArgs->hDbgCfg, pszExtFile,
|
---|
619 | pDbgInfo->u.Dbg.cbImage,
|
---|
620 | pDbgInfo->u.Dbg.uTimestamp,
|
---|
621 | rtDbgModExtDbgInfoOpenCallback, pArgs->pDbgMod, (void *)pDbgInfo);
|
---|
622 | break;
|
---|
623 |
|
---|
624 | case RTLDRDBGINFOTYPE_DWARF_DWO:
|
---|
625 | rc = RTDbgCfgOpenDwo(pArgs->hDbgCfg, pszExtFile,
|
---|
626 | pDbgInfo->u.Dwo.uCrc32,
|
---|
627 | rtDbgModExtDbgInfoOpenCallback, pArgs->pDbgMod, (void *)pDbgInfo);
|
---|
628 | break;
|
---|
629 |
|
---|
630 | default:
|
---|
631 | Log(("rtDbgModOpenDebugInfoExternalToImageCallback: Don't know how to handle enmType=%d and pszFileExt=%s\n",
|
---|
632 | pDbgInfo->enmType, pszExtFile));
|
---|
633 | return VERR_DBG_TODO;
|
---|
634 | }
|
---|
635 | if (RT_SUCCESS(rc))
|
---|
636 | {
|
---|
637 | LogFlow(("RTDbgMod: Successfully opened external debug info '%s' for '%s'\n",
|
---|
638 | pArgs->pDbgMod->pszDbgFile, pArgs->pDbgMod->pszImgFile));
|
---|
639 | return VINF_CALLBACK_RETURN;
|
---|
640 | }
|
---|
641 | Log(("rtDbgModOpenDebugInfoExternalToImageCallback: '%s' (enmType=%d) for '%s' -> %Rrc\n",
|
---|
642 | pszExtFile, pDbgInfo->enmType, pArgs->pDbgMod->pszImgFile, rc));
|
---|
643 | return rc;
|
---|
644 | }
|
---|
645 |
|
---|
646 |
|
---|
647 | /**
|
---|
648 | * Opens debug info listed in the image that is stored in a separate file.
|
---|
649 | *
|
---|
650 | * @returns IPRT status code
|
---|
651 | * @param pDbgMod The debug module.
|
---|
652 | * @param hDbgCfg The debug config. Can be NIL.
|
---|
653 | */
|
---|
654 | static int rtDbgModOpenDebugInfoExternalToImage(PRTDBGMODINT pDbgMod, RTDBGCFG hDbgCfg)
|
---|
655 | {
|
---|
656 | Assert(!pDbgMod->pDbgVt);
|
---|
657 |
|
---|
658 | RTDBGMODOPENDIETI Args;
|
---|
659 | Args.pDbgMod = pDbgMod;
|
---|
660 | Args.hDbgCfg = hDbgCfg;
|
---|
661 | int rc = pDbgMod->pImgVt->pfnEnumDbgInfo(pDbgMod, rtDbgModOpenDebugInfoExternalToImageCallback, &Args);
|
---|
662 | if (RT_SUCCESS(rc) && pDbgMod->pDbgVt)
|
---|
663 | return VINF_SUCCESS;
|
---|
664 |
|
---|
665 | LogFlow(("rtDbgModOpenDebugInfoExternalToImage: rc=%Rrc\n", rc));
|
---|
666 | return VERR_NOT_FOUND;
|
---|
667 | }
|
---|
668 |
|
---|
669 |
|
---|
670 | /** @callback_method_impl{FNRTDBGCFGOPEN} */
|
---|
671 | static DECLCALLBACK(int) rtDbgModExtDbgInfoOpenCallback2(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2)
|
---|
672 | {
|
---|
673 | PRTDBGMODINT pDbgMod = (PRTDBGMODINT)pvUser1;
|
---|
674 | NOREF(pvUser2); /** @todo image matching string or smth. */
|
---|
675 |
|
---|
676 | Assert(!pDbgMod->pDbgVt);
|
---|
677 | Assert(!pDbgMod->pvDbgPriv);
|
---|
678 | Assert(!pDbgMod->pszDbgFile);
|
---|
679 | Assert(pDbgMod->pImgVt);
|
---|
680 |
|
---|
681 | /*
|
---|
682 | * Set the debug file name and try possible interpreters.
|
---|
683 | */
|
---|
684 | pDbgMod->pszDbgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
|
---|
685 |
|
---|
686 | int rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
|
---|
687 | if (RT_SUCCESS(rc))
|
---|
688 | {
|
---|
689 | for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext)
|
---|
690 | {
|
---|
691 | pDbgMod->pDbgVt = pDbg->pVt;
|
---|
692 | pDbgMod->pvDbgPriv = NULL;
|
---|
693 | rc = pDbg->pVt->pfnTryOpen(pDbgMod, pDbgMod->pImgVt->pfnGetArch(pDbgMod));
|
---|
694 | if (RT_SUCCESS(rc))
|
---|
695 | {
|
---|
696 | /*
|
---|
697 | * Got it!
|
---|
698 | */
|
---|
699 | ASMAtomicIncU32(&pDbg->cUsers);
|
---|
700 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
701 | return VINF_CALLBACK_RETURN;
|
---|
702 | }
|
---|
703 | pDbgMod->pDbgVt = NULL;
|
---|
704 | Assert(pDbgMod->pvDbgPriv == NULL);
|
---|
705 | }
|
---|
706 | }
|
---|
707 |
|
---|
708 | /* No joy. */
|
---|
709 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
710 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszDbgFile);
|
---|
711 | pDbgMod->pszDbgFile = NULL;
|
---|
712 | return rc;
|
---|
713 | }
|
---|
714 |
|
---|
715 |
|
---|
716 | /**
|
---|
717 | * Opens external debug info that is not listed in the image.
|
---|
718 | *
|
---|
719 | * @returns IPRT status code
|
---|
720 | * @param pDbgMod The debug module.
|
---|
721 | * @param hDbgCfg The debug config. Can be NIL.
|
---|
722 | */
|
---|
723 | static int rtDbgModOpenDebugInfoExternalToImage2(PRTDBGMODINT pDbgMod, RTDBGCFG hDbgCfg)
|
---|
724 | {
|
---|
725 | int rc;
|
---|
726 | Assert(!pDbgMod->pDbgVt);
|
---|
727 | Assert(pDbgMod->pImgVt);
|
---|
728 |
|
---|
729 | /*
|
---|
730 | * Figure out what to search for based on the image format.
|
---|
731 | */
|
---|
732 | const char *pszzExts = NULL;
|
---|
733 | RTLDRFMT enmFmt = pDbgMod->pImgVt->pfnGetFormat(pDbgMod);
|
---|
734 | switch (enmFmt)
|
---|
735 | {
|
---|
736 | case RTLDRFMT_MACHO:
|
---|
737 | {
|
---|
738 | rc = RTDbgCfgOpenDsymBundle(hDbgCfg, pDbgMod->pszImgFile, NULL /**@todo pUuid*/,
|
---|
739 | rtDbgModExtDbgInfoOpenCallback2, pDbgMod, NULL /*pvUser2*/);
|
---|
740 | if (RT_SUCCESS(rc))
|
---|
741 | return VINF_SUCCESS;
|
---|
742 | break;
|
---|
743 | }
|
---|
744 |
|
---|
745 | #if 0 /* Will be links in the image if these apply. .map readers for PE or ELF we don't have. */
|
---|
746 | case RTLDRFMT_ELF:
|
---|
747 | pszzExts = ".debug\0.dwo\0";
|
---|
748 | break;
|
---|
749 | case RTLDRFMT_PE:
|
---|
750 | pszzExts = ".map\0";
|
---|
751 | break;
|
---|
752 | #endif
|
---|
753 | #if 0 /* Haven't implemented .sym or .map file readers for OS/2 yet. */
|
---|
754 | case RTLDRFMT_LX:
|
---|
755 | pszzExts = ".sym\0.map\0";
|
---|
756 | break;
|
---|
757 | #endif
|
---|
758 | default:
|
---|
759 | rc = VERR_NOT_IMPLEMENTED;
|
---|
760 | break;
|
---|
761 | }
|
---|
762 |
|
---|
763 | NOREF(pszzExts);
|
---|
764 | #if 0 /* Later */
|
---|
765 | if (pszzExts)
|
---|
766 | {
|
---|
767 |
|
---|
768 | }
|
---|
769 | #endif
|
---|
770 |
|
---|
771 | LogFlow(("rtDbgModOpenDebugInfoExternalToImage2: rc=%Rrc\n", rc));
|
---|
772 | return VERR_NOT_FOUND;
|
---|
773 | }
|
---|
774 |
|
---|
775 |
|
---|
776 | RTDECL(int) RTDbgModCreateFromImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName,
|
---|
777 | RTLDRARCH enmArch, RTDBGCFG hDbgCfg)
|
---|
778 | {
|
---|
779 | /*
|
---|
780 | * Input validation and lazy initialization.
|
---|
781 | */
|
---|
782 | AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER);
|
---|
783 | *phDbgMod = NIL_RTDBGMOD;
|
---|
784 | AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
|
---|
785 | AssertReturn(*pszFilename, VERR_INVALID_PARAMETER);
|
---|
786 | AssertPtrNullReturn(pszName, VERR_INVALID_POINTER);
|
---|
787 | AssertReturn(enmArch > RTLDRARCH_INVALID && enmArch < RTLDRARCH_END, VERR_INVALID_PARAMETER);
|
---|
788 |
|
---|
789 | int rc = rtDbgModLazyInit();
|
---|
790 | if (RT_FAILURE(rc))
|
---|
791 | return rc;
|
---|
792 |
|
---|
793 | if (!pszName)
|
---|
794 | pszName = RTPathFilenameEx(pszFilename, RTPATH_STR_F_STYLE_DOS);
|
---|
795 |
|
---|
796 | /*
|
---|
797 | * Allocate a new module instance.
|
---|
798 | */
|
---|
799 | PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod));
|
---|
800 | if (!pDbgMod)
|
---|
801 | return VERR_NO_MEMORY;
|
---|
802 | pDbgMod->u32Magic = RTDBGMOD_MAGIC;
|
---|
803 | pDbgMod->cRefs = 1;
|
---|
804 | rc = RTCritSectInit(&pDbgMod->CritSect);
|
---|
805 | if (RT_SUCCESS(rc))
|
---|
806 | {
|
---|
807 | pDbgMod->pszName = RTStrCacheEnterLower(g_hDbgModStrCache, pszName);
|
---|
808 | if (pDbgMod->pszName)
|
---|
809 | {
|
---|
810 | pDbgMod->pszImgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
|
---|
811 | if (pDbgMod->pszImgFile)
|
---|
812 | {
|
---|
813 | RTStrCacheRetain(pDbgMod->pszImgFile);
|
---|
814 | pDbgMod->pszImgFileSpecified = pDbgMod->pszImgFile;
|
---|
815 |
|
---|
816 | /*
|
---|
817 | * Find an image reader which groks the file.
|
---|
818 | */
|
---|
819 | rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
|
---|
820 | if (RT_SUCCESS(rc))
|
---|
821 | {
|
---|
822 | rc = VERR_DBG_NO_MATCHING_INTERPRETER;
|
---|
823 | PRTDBGMODREGIMG pImg;
|
---|
824 | for (pImg = g_pImgHead; pImg; pImg = pImg->pNext)
|
---|
825 | {
|
---|
826 | pDbgMod->pImgVt = pImg->pVt;
|
---|
827 | pDbgMod->pvImgPriv = NULL;
|
---|
828 | /** @todo need to specify some arch stuff here. */
|
---|
829 | rc = pImg->pVt->pfnTryOpen(pDbgMod, enmArch);
|
---|
830 | if (RT_SUCCESS(rc))
|
---|
831 | {
|
---|
832 | /*
|
---|
833 | * Image detected, but found no debug info we were
|
---|
834 | * able to understand.
|
---|
835 | */
|
---|
836 | /** @todo some generic way of matching image and debug info, flexible signature
|
---|
837 | * of some kind. Apple uses UUIDs, microsoft uses a UUID+age or a
|
---|
838 | * size+timestamp, and GNU a CRC32 (last time I checked). */
|
---|
839 | rc = rtDbgModOpenDebugInfoExternalToImage(pDbgMod, hDbgCfg);
|
---|
840 | if (RT_FAILURE(rc))
|
---|
841 | rc = rtDbgModOpenDebugInfoInsideImage(pDbgMod);
|
---|
842 | if (RT_FAILURE(rc))
|
---|
843 | rc = rtDbgModOpenDebugInfoExternalToImage2(pDbgMod, hDbgCfg);
|
---|
844 | if (RT_FAILURE(rc))
|
---|
845 | rc = rtDbgModCreateForExports(pDbgMod);
|
---|
846 | if (RT_SUCCESS(rc))
|
---|
847 | {
|
---|
848 | /*
|
---|
849 | * We're done!
|
---|
850 | */
|
---|
851 | ASMAtomicIncU32(&pImg->cUsers);
|
---|
852 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
853 |
|
---|
854 | *phDbgMod = pDbgMod;
|
---|
855 | return VINF_SUCCESS;
|
---|
856 | }
|
---|
857 |
|
---|
858 | /* Failed, close up the shop. */
|
---|
859 | pDbgMod->pImgVt->pfnClose(pDbgMod);
|
---|
860 | pDbgMod->pImgVt = NULL;
|
---|
861 | pDbgMod->pvImgPriv = NULL;
|
---|
862 | break;
|
---|
863 | }
|
---|
864 | }
|
---|
865 |
|
---|
866 | /*
|
---|
867 | * Could it be a file containing raw debug info?
|
---|
868 | */
|
---|
869 | if (!pImg)
|
---|
870 | {
|
---|
871 | pDbgMod->pImgVt = NULL;
|
---|
872 | pDbgMod->pvImgPriv = NULL;
|
---|
873 | pDbgMod->pszDbgFile = pDbgMod->pszImgFile;
|
---|
874 | pDbgMod->pszImgFile = NULL;
|
---|
875 |
|
---|
876 | for (PRTDBGMODREGDBG pDbg = g_pDbgHead; pDbg; pDbg = pDbg->pNext)
|
---|
877 | {
|
---|
878 | pDbgMod->pDbgVt = pDbg->pVt;
|
---|
879 | pDbgMod->pvDbgPriv = NULL;
|
---|
880 | rc = pDbg->pVt->pfnTryOpen(pDbgMod, enmArch);
|
---|
881 | if (RT_SUCCESS(rc))
|
---|
882 | {
|
---|
883 | /*
|
---|
884 | * That's it!
|
---|
885 | */
|
---|
886 | ASMAtomicIncU32(&pDbg->cUsers);
|
---|
887 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
888 |
|
---|
889 | *phDbgMod = pDbgMod;
|
---|
890 | return rc;
|
---|
891 | }
|
---|
892 | }
|
---|
893 |
|
---|
894 | pDbgMod->pszImgFile = pDbgMod->pszDbgFile;
|
---|
895 | pDbgMod->pszDbgFile = NULL;
|
---|
896 | }
|
---|
897 |
|
---|
898 | /* bail out */
|
---|
899 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
900 | }
|
---|
901 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFileSpecified);
|
---|
902 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile);
|
---|
903 | }
|
---|
904 | else
|
---|
905 | rc = VERR_NO_STR_MEMORY;
|
---|
906 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
|
---|
907 | }
|
---|
908 | else
|
---|
909 | rc = VERR_NO_STR_MEMORY;
|
---|
910 | RTCritSectDelete(&pDbgMod->CritSect);
|
---|
911 | }
|
---|
912 |
|
---|
913 | RTMemFree(pDbgMod);
|
---|
914 | return rc;
|
---|
915 | }
|
---|
916 | RT_EXPORT_SYMBOL(RTDbgModCreateFromImage);
|
---|
917 |
|
---|
918 |
|
---|
919 |
|
---|
920 |
|
---|
921 |
|
---|
922 | /*
|
---|
923 | *
|
---|
924 | * P E I M A G E
|
---|
925 | * P E I M A G E
|
---|
926 | * P E I M A G E
|
---|
927 | *
|
---|
928 | */
|
---|
929 |
|
---|
930 |
|
---|
931 |
|
---|
932 | /** @callback_method_impl{FNRTDBGCFGOPEN} */
|
---|
933 | static DECLCALLBACK(int) rtDbgModFromPeImageOpenCallback(RTDBGCFG hDbgCfg, const char *pszFilename, void *pvUser1, void *pvUser2)
|
---|
934 | {
|
---|
935 | PRTDBGMODINT pDbgMod = (PRTDBGMODINT)pvUser1;
|
---|
936 | PRTDBGMODDEFERRED pDeferred = (PRTDBGMODDEFERRED)pvUser2;
|
---|
937 | LogFlow(("rtDbgModFromPeImageOpenCallback: %s\n", pszFilename));
|
---|
938 |
|
---|
939 | Assert(pDbgMod->pImgVt == NULL);
|
---|
940 | Assert(pDbgMod->pvImgPriv == NULL);
|
---|
941 | Assert(pDbgMod->pDbgVt == NULL);
|
---|
942 | Assert(pDbgMod->pvDbgPriv == NULL);
|
---|
943 |
|
---|
944 | /*
|
---|
945 | * Replace the image file name while probing it.
|
---|
946 | */
|
---|
947 | const char *pszNewImgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
|
---|
948 | if (!pszNewImgFile)
|
---|
949 | return VERR_NO_STR_MEMORY;
|
---|
950 | const char *pszOldImgFile = pDbgMod->pszImgFile;
|
---|
951 | pDbgMod->pszImgFile = pszNewImgFile;
|
---|
952 |
|
---|
953 | /*
|
---|
954 | * Find an image reader which groks the file.
|
---|
955 | */
|
---|
956 | int rc = RTSemRWRequestRead(g_hDbgModRWSem, RT_INDEFINITE_WAIT);
|
---|
957 | if (RT_SUCCESS(rc))
|
---|
958 | {
|
---|
959 | rc = VERR_DBG_NO_MATCHING_INTERPRETER;
|
---|
960 | PRTDBGMODREGIMG pImg;
|
---|
961 | for (pImg = g_pImgHead; pImg; pImg = pImg->pNext)
|
---|
962 | {
|
---|
963 | pDbgMod->pImgVt = pImg->pVt;
|
---|
964 | pDbgMod->pvImgPriv = NULL;
|
---|
965 | rc = pImg->pVt->pfnTryOpen(pDbgMod, RTLDRARCH_WHATEVER);
|
---|
966 | if (RT_SUCCESS(rc))
|
---|
967 | break;
|
---|
968 | pDbgMod->pImgVt = NULL;
|
---|
969 | Assert(pDbgMod->pvImgPriv == NULL);
|
---|
970 | }
|
---|
971 | RTSemRWReleaseRead(g_hDbgModRWSem);
|
---|
972 | if (RT_SUCCESS(rc))
|
---|
973 | {
|
---|
974 | /*
|
---|
975 | * Check the deferred info.
|
---|
976 | */
|
---|
977 | RTUINTPTR cbImage = pDbgMod->pImgVt->pfnImageSize(pDbgMod);
|
---|
978 | if ( pDeferred->cbImage == 0
|
---|
979 | || pDeferred->cbImage == cbImage)
|
---|
980 | {
|
---|
981 | uint32_t uTimestamp = pDeferred->u.PeImage.uTimestamp; /** @todo add method for getting the timestamp. */
|
---|
982 | if ( pDeferred->u.PeImage.uTimestamp == 0
|
---|
983 | || pDeferred->u.PeImage.uTimestamp == uTimestamp)
|
---|
984 | {
|
---|
985 | Log(("RTDbgMod: Found matching PE image '%s'\n", pszFilename));
|
---|
986 |
|
---|
987 | /*
|
---|
988 | * We found the executable image we need, now go find any
|
---|
989 | * debug info associated with it. For PE images, this is
|
---|
990 | * generally found in an external file, so we do a sweep
|
---|
991 | * for that first.
|
---|
992 | *
|
---|
993 | * Then try open debug inside the module, and finally
|
---|
994 | * falling back on exports.
|
---|
995 | */
|
---|
996 | rc = rtDbgModOpenDebugInfoExternalToImage(pDbgMod, pDeferred->hDbgCfg);
|
---|
997 | if (RT_FAILURE(rc))
|
---|
998 | rc = rtDbgModOpenDebugInfoInsideImage(pDbgMod);
|
---|
999 | if (RT_FAILURE(rc))
|
---|
1000 | rc = rtDbgModCreateForExports(pDbgMod);
|
---|
1001 | if (RT_SUCCESS(rc))
|
---|
1002 | {
|
---|
1003 | RTStrCacheRelease(g_hDbgModStrCache, pszOldImgFile);
|
---|
1004 | return VINF_CALLBACK_RETURN;
|
---|
1005 | }
|
---|
1006 |
|
---|
1007 | /* Something bad happened, just give up. */
|
---|
1008 | Log(("rtDbgModFromPeImageOpenCallback: rtDbgModCreateForExports failed: %Rrc\n", rc));
|
---|
1009 | }
|
---|
1010 | else
|
---|
1011 | {
|
---|
1012 | LogFlow(("rtDbgModFromPeImageOpenCallback: uTimestamp mismatch (found %#x, expected %#x) - %s\n",
|
---|
1013 | uTimestamp, pDeferred->u.PeImage.uTimestamp, pszFilename));
|
---|
1014 | rc = VERR_DBG_FILE_MISMATCH;
|
---|
1015 | }
|
---|
1016 | }
|
---|
1017 | else
|
---|
1018 | {
|
---|
1019 | LogFlow(("rtDbgModFromPeImageOpenCallback: cbImage mismatch (found %#x, expected %#x) - %s\n",
|
---|
1020 | cbImage, pDeferred->cbImage, pszFilename));
|
---|
1021 | rc = VERR_DBG_FILE_MISMATCH;
|
---|
1022 | }
|
---|
1023 |
|
---|
1024 | pDbgMod->pImgVt->pfnClose(pDbgMod);
|
---|
1025 | pDbgMod->pImgVt = NULL;
|
---|
1026 | pDbgMod->pvImgPriv = NULL;
|
---|
1027 | }
|
---|
1028 | else
|
---|
1029 | LogFlow(("rtDbgModFromPeImageOpenCallback: Failed %Rrc - %s\n", rc, pszFilename));
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | /* Restore image name. */
|
---|
1033 | pDbgMod->pszImgFile = pszOldImgFile;
|
---|
1034 | RTStrCacheRelease(g_hDbgModStrCache, pszNewImgFile);
|
---|
1035 | return rc;
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 |
|
---|
1039 | /** @callback_method_impl{FNRTDBGMODDEFERRED} */
|
---|
1040 | static DECLCALLBACK(int) rtDbgModFromPeImageDeferredCallback(PRTDBGMODINT pDbgMod, PRTDBGMODDEFERRED pDeferred)
|
---|
1041 | {
|
---|
1042 | int rc;
|
---|
1043 |
|
---|
1044 | Assert(pDbgMod->pszImgFile);
|
---|
1045 | if (!pDbgMod->pImgVt)
|
---|
1046 | rc = RTDbgCfgOpenPeImage(pDeferred->hDbgCfg, pDbgMod->pszImgFile,
|
---|
1047 | pDeferred->cbImage, pDeferred->u.PeImage.uTimestamp,
|
---|
1048 | rtDbgModFromPeImageOpenCallback, pDbgMod, pDeferred);
|
---|
1049 | else
|
---|
1050 | {
|
---|
1051 | rc = rtDbgModOpenDebugInfoExternalToImage(pDbgMod, pDeferred->hDbgCfg);
|
---|
1052 | if (RT_FAILURE(rc))
|
---|
1053 | rc = rtDbgModOpenDebugInfoInsideImage(pDbgMod);
|
---|
1054 | if (RT_FAILURE(rc))
|
---|
1055 | rc = rtDbgModCreateForExports(pDbgMod);
|
---|
1056 | }
|
---|
1057 | return rc;
|
---|
1058 | }
|
---|
1059 |
|
---|
1060 |
|
---|
1061 | RTDECL(int) RTDbgModCreateFromPeImage(PRTDBGMOD phDbgMod, const char *pszFilename, const char *pszName, RTLDRMOD hLdrMod,
|
---|
1062 | uint32_t cbImage, uint32_t uTimestamp, RTDBGCFG hDbgCfg)
|
---|
1063 | {
|
---|
1064 | /*
|
---|
1065 | * Input validation and lazy initialization.
|
---|
1066 | */
|
---|
1067 | AssertPtrReturn(phDbgMod, VERR_INVALID_POINTER);
|
---|
1068 | *phDbgMod = NIL_RTDBGMOD;
|
---|
1069 | AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
|
---|
1070 | AssertReturn(*pszFilename, VERR_INVALID_PARAMETER);
|
---|
1071 | if (!pszName)
|
---|
1072 | pszName = RTPathFilenameEx(pszFilename, RTPATH_STR_F_STYLE_DOS);
|
---|
1073 | AssertPtrReturn(pszName, VERR_INVALID_POINTER);
|
---|
1074 | AssertReturn(hLdrMod == NIL_RTLDRMOD || RTLdrSize(hLdrMod) != ~(size_t)0, VERR_INVALID_HANDLE);
|
---|
1075 |
|
---|
1076 | int rc = rtDbgModLazyInit();
|
---|
1077 | if (RT_FAILURE(rc))
|
---|
1078 | return rc;
|
---|
1079 |
|
---|
1080 | uint64_t fDbgCfg = 0;
|
---|
1081 | if (hDbgCfg)
|
---|
1082 | {
|
---|
1083 | rc = RTDbgCfgQueryUInt(hDbgCfg, RTDBGCFGPROP_FLAGS, &fDbgCfg);
|
---|
1084 | AssertRCReturn(rc, rc);
|
---|
1085 | }
|
---|
1086 |
|
---|
1087 | /*
|
---|
1088 | * Allocate a new module instance.
|
---|
1089 | */
|
---|
1090 | PRTDBGMODINT pDbgMod = (PRTDBGMODINT)RTMemAllocZ(sizeof(*pDbgMod));
|
---|
1091 | if (!pDbgMod)
|
---|
1092 | return VERR_NO_MEMORY;
|
---|
1093 | pDbgMod->u32Magic = RTDBGMOD_MAGIC;
|
---|
1094 | pDbgMod->cRefs = 1;
|
---|
1095 | rc = RTCritSectInit(&pDbgMod->CritSect);
|
---|
1096 | if (RT_SUCCESS(rc))
|
---|
1097 | {
|
---|
1098 | pDbgMod->pszName = RTStrCacheEnterLower(g_hDbgModStrCache, pszName);
|
---|
1099 | if (pDbgMod->pszName)
|
---|
1100 | {
|
---|
1101 | pDbgMod->pszImgFile = RTStrCacheEnter(g_hDbgModStrCache, pszFilename);
|
---|
1102 | if (pDbgMod->pszImgFile)
|
---|
1103 | {
|
---|
1104 | RTStrCacheRetain(pDbgMod->pszImgFile);
|
---|
1105 | pDbgMod->pszImgFileSpecified = pDbgMod->pszImgFile;
|
---|
1106 |
|
---|
1107 | /*
|
---|
1108 | * If we have a loader module, we must instantiate the loader
|
---|
1109 | * side of things regardless of the deferred setting.
|
---|
1110 | */
|
---|
1111 | if (hLdrMod != NIL_RTLDRMOD)
|
---|
1112 | {
|
---|
1113 | if (!cbImage)
|
---|
1114 | cbImage = (uint32_t)RTLdrSize(hLdrMod);
|
---|
1115 | pDbgMod->pImgVt = &g_rtDbgModVtImgLdr;
|
---|
1116 |
|
---|
1117 | rc = rtDbgModLdrOpenFromHandle(pDbgMod, hLdrMod);
|
---|
1118 | }
|
---|
1119 | if (RT_SUCCESS(rc))
|
---|
1120 | {
|
---|
1121 | /*
|
---|
1122 | * Do it now or procrastinate?
|
---|
1123 | */
|
---|
1124 | if (!(fDbgCfg & RTDBGCFG_FLAGS_DEFERRED) || !cbImage)
|
---|
1125 | {
|
---|
1126 | RTDBGMODDEFERRED Deferred;
|
---|
1127 | Deferred.cbImage = cbImage;
|
---|
1128 | Deferred.hDbgCfg = hDbgCfg;
|
---|
1129 | Deferred.u.PeImage.uTimestamp = uTimestamp;
|
---|
1130 | rc = rtDbgModFromPeImageDeferredCallback(pDbgMod, &Deferred);
|
---|
1131 | }
|
---|
1132 | else
|
---|
1133 | {
|
---|
1134 | PRTDBGMODDEFERRED pDeferred;
|
---|
1135 | rc = rtDbgModDeferredCreate(pDbgMod, rtDbgModFromPeImageDeferredCallback, cbImage, hDbgCfg, &pDeferred);
|
---|
1136 | if (RT_SUCCESS(rc))
|
---|
1137 | pDeferred->u.PeImage.uTimestamp = uTimestamp;
|
---|
1138 | }
|
---|
1139 | if (RT_SUCCESS(rc))
|
---|
1140 | {
|
---|
1141 | *phDbgMod = pDbgMod;
|
---|
1142 | return VINF_SUCCESS;
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 | /* Failed, bail out. */
|
---|
1146 | if (hLdrMod != NIL_RTLDRMOD)
|
---|
1147 | {
|
---|
1148 | Assert(pDbgMod->pImgVt);
|
---|
1149 | pDbgMod->pImgVt->pfnClose(pDbgMod);
|
---|
1150 | }
|
---|
1151 | }
|
---|
1152 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
|
---|
1153 | }
|
---|
1154 | else
|
---|
1155 | rc = VERR_NO_STR_MEMORY;
|
---|
1156 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFileSpecified);
|
---|
1157 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile);
|
---|
1158 | }
|
---|
1159 | else
|
---|
1160 | rc = VERR_NO_STR_MEMORY;
|
---|
1161 | RTCritSectDelete(&pDbgMod->CritSect);
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | RTMemFree(pDbgMod);
|
---|
1165 | return rc;
|
---|
1166 | }
|
---|
1167 | RT_EXPORT_SYMBOL(RTDbgModCreateFromPeImage);
|
---|
1168 |
|
---|
1169 |
|
---|
1170 | /**
|
---|
1171 | * Destroys an module after the reference count has reached zero.
|
---|
1172 | *
|
---|
1173 | * @param pDbgMod The module instance.
|
---|
1174 | */
|
---|
1175 | static void rtDbgModDestroy(PRTDBGMODINT pDbgMod)
|
---|
1176 | {
|
---|
1177 | /*
|
---|
1178 | * Close the debug info interpreter first, then the image interpret.
|
---|
1179 | */
|
---|
1180 | RTCritSectEnter(&pDbgMod->CritSect); /* paranoia */
|
---|
1181 |
|
---|
1182 | if (pDbgMod->pDbgVt)
|
---|
1183 | {
|
---|
1184 | pDbgMod->pDbgVt->pfnClose(pDbgMod);
|
---|
1185 | pDbgMod->pDbgVt = NULL;
|
---|
1186 | pDbgMod->pvDbgPriv = NULL;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | if (pDbgMod->pImgVt)
|
---|
1190 | {
|
---|
1191 | pDbgMod->pImgVt->pfnClose(pDbgMod);
|
---|
1192 | pDbgMod->pImgVt = NULL;
|
---|
1193 | pDbgMod->pvImgPriv = NULL;
|
---|
1194 | }
|
---|
1195 |
|
---|
1196 | /*
|
---|
1197 | * Free the resources.
|
---|
1198 | */
|
---|
1199 | ASMAtomicWriteU32(&pDbgMod->u32Magic, ~RTDBGMOD_MAGIC);
|
---|
1200 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
|
---|
1201 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile);
|
---|
1202 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFileSpecified);
|
---|
1203 | RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszDbgFile);
|
---|
1204 | RTCritSectLeave(&pDbgMod->CritSect); /* paranoia */
|
---|
1205 | RTCritSectDelete(&pDbgMod->CritSect);
|
---|
1206 | RTMemFree(pDbgMod);
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 |
|
---|
1210 | RTDECL(uint32_t) RTDbgModRetain(RTDBGMOD hDbgMod)
|
---|
1211 | {
|
---|
1212 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1213 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
|
---|
1214 | return ASMAtomicIncU32(&pDbgMod->cRefs);
|
---|
1215 | }
|
---|
1216 | RT_EXPORT_SYMBOL(RTDbgModRetain);
|
---|
1217 |
|
---|
1218 |
|
---|
1219 | RTDECL(uint32_t) RTDbgModRelease(RTDBGMOD hDbgMod)
|
---|
1220 | {
|
---|
1221 | if (hDbgMod == NIL_RTDBGMOD)
|
---|
1222 | return 0;
|
---|
1223 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1224 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
|
---|
1225 |
|
---|
1226 | uint32_t cRefs = ASMAtomicDecU32(&pDbgMod->cRefs);
|
---|
1227 | if (!cRefs)
|
---|
1228 | rtDbgModDestroy(pDbgMod);
|
---|
1229 | return cRefs;
|
---|
1230 | }
|
---|
1231 | RT_EXPORT_SYMBOL(RTDbgModRelease);
|
---|
1232 |
|
---|
1233 |
|
---|
1234 | RTDECL(const char *) RTDbgModName(RTDBGMOD hDbgMod)
|
---|
1235 | {
|
---|
1236 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1237 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, NULL);
|
---|
1238 | return pDbgMod->pszName;
|
---|
1239 | }
|
---|
1240 | RT_EXPORT_SYMBOL(RTDbgModName);
|
---|
1241 |
|
---|
1242 |
|
---|
1243 | RTDECL(const char *) RTDbgModDebugFile(RTDBGMOD hDbgMod)
|
---|
1244 | {
|
---|
1245 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1246 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, NULL);
|
---|
1247 | if (pDbgMod->fDeferred || pDbgMod->fExports)
|
---|
1248 | return NULL;
|
---|
1249 | return pDbgMod->pszDbgFile;
|
---|
1250 | }
|
---|
1251 | RT_EXPORT_SYMBOL(RTDbgModDebugFile);
|
---|
1252 |
|
---|
1253 |
|
---|
1254 | RTDECL(const char *) RTDbgModImageFile(RTDBGMOD hDbgMod)
|
---|
1255 | {
|
---|
1256 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1257 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, NULL);
|
---|
1258 | return pDbgMod->pszImgFileSpecified;
|
---|
1259 | }
|
---|
1260 | RT_EXPORT_SYMBOL(RTDbgModImageFile);
|
---|
1261 |
|
---|
1262 |
|
---|
1263 | RTDECL(const char *) RTDbgModImageFileUsed(RTDBGMOD hDbgMod)
|
---|
1264 | {
|
---|
1265 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1266 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, NULL);
|
---|
1267 | return pDbgMod->pszImgFile == pDbgMod->pszImgFileSpecified ? NULL : pDbgMod->pszImgFile;
|
---|
1268 | }
|
---|
1269 | RT_EXPORT_SYMBOL(RTDbgModImageFileUsed);
|
---|
1270 |
|
---|
1271 |
|
---|
1272 | RTDECL(bool) RTDbgModIsDeferred(RTDBGMOD hDbgMod)
|
---|
1273 | {
|
---|
1274 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1275 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, false);
|
---|
1276 | return pDbgMod->fDeferred;
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 |
|
---|
1280 | RTDECL(bool) RTDbgModIsExports(RTDBGMOD hDbgMod)
|
---|
1281 | {
|
---|
1282 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1283 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, false);
|
---|
1284 | return pDbgMod->fExports;
|
---|
1285 | }
|
---|
1286 |
|
---|
1287 |
|
---|
1288 | RTDECL(int) RTDbgModRemoveAll(RTDBGMOD hDbgMod, bool fLeaveSegments)
|
---|
1289 | {
|
---|
1290 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1291 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
|
---|
1292 |
|
---|
1293 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1294 |
|
---|
1295 | /* Only possible on container modules. */
|
---|
1296 | int rc = VINF_SUCCESS;
|
---|
1297 | if (pDbgMod->pDbgVt != &g_rtDbgModVtDbgContainer)
|
---|
1298 | {
|
---|
1299 | if (fLeaveSegments)
|
---|
1300 | {
|
---|
1301 | rc = rtDbgModContainer_LineRemoveAll(pDbgMod);
|
---|
1302 | if (RT_SUCCESS(rc))
|
---|
1303 | rc = rtDbgModContainer_SymbolRemoveAll(pDbgMod);
|
---|
1304 | }
|
---|
1305 | else
|
---|
1306 | rc = rtDbgModContainer_RemoveAll(pDbgMod);
|
---|
1307 | }
|
---|
1308 | else
|
---|
1309 | rc = VERR_ACCESS_DENIED;
|
---|
1310 |
|
---|
1311 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1312 | return rc;
|
---|
1313 | }
|
---|
1314 |
|
---|
1315 |
|
---|
1316 | RTDECL(RTDBGSEGIDX) RTDbgModRvaToSegOff(RTDBGMOD hDbgMod, RTUINTPTR uRva, PRTUINTPTR poffSeg)
|
---|
1317 | {
|
---|
1318 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1319 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, NIL_RTDBGSEGIDX);
|
---|
1320 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1321 |
|
---|
1322 | RTDBGSEGIDX iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, uRva, poffSeg);
|
---|
1323 |
|
---|
1324 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1325 | return iSeg;
|
---|
1326 | }
|
---|
1327 | RT_EXPORT_SYMBOL(RTDbgModRvaToSegOff);
|
---|
1328 |
|
---|
1329 |
|
---|
1330 | RTDECL(RTUINTPTR) RTDbgModImageSize(RTDBGMOD hDbgMod)
|
---|
1331 | {
|
---|
1332 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1333 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, RTUINTPTR_MAX);
|
---|
1334 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1335 |
|
---|
1336 | RTUINTPTR cbImage = pDbgMod->pDbgVt->pfnImageSize(pDbgMod);
|
---|
1337 |
|
---|
1338 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1339 | return cbImage;
|
---|
1340 | }
|
---|
1341 | RT_EXPORT_SYMBOL(RTDbgModImageSize);
|
---|
1342 |
|
---|
1343 |
|
---|
1344 | RTDECL(uint64_t) RTDbgModGetTag(RTDBGMOD hDbgMod)
|
---|
1345 | {
|
---|
1346 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1347 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, 0);
|
---|
1348 | return pDbgMod->uTag;
|
---|
1349 | }
|
---|
1350 | RT_EXPORT_SYMBOL(RTDbgModGetTag);
|
---|
1351 |
|
---|
1352 |
|
---|
1353 | RTDECL(int) RTDbgModSetTag(RTDBGMOD hDbgMod, uint64_t uTag)
|
---|
1354 | {
|
---|
1355 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1356 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
|
---|
1357 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1358 |
|
---|
1359 | pDbgMod->uTag = uTag;
|
---|
1360 |
|
---|
1361 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1362 | return VINF_SUCCESS;
|
---|
1363 | }
|
---|
1364 | RT_EXPORT_SYMBOL(RTDbgModSetTag);
|
---|
1365 |
|
---|
1366 |
|
---|
1367 | RTDECL(int) RTDbgModSegmentAdd(RTDBGMOD hDbgMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName,
|
---|
1368 | uint32_t fFlags, PRTDBGSEGIDX piSeg)
|
---|
1369 | {
|
---|
1370 | /*
|
---|
1371 | * Validate input.
|
---|
1372 | */
|
---|
1373 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1374 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
|
---|
1375 | AssertMsgReturn(uRva + cb >= uRva, ("uRva=%RTptr cb=%RTptr\n", uRva, cb), VERR_DBG_ADDRESS_WRAP);
|
---|
1376 | Assert(*pszName);
|
---|
1377 | size_t cchName = strlen(pszName);
|
---|
1378 | AssertReturn(cchName > 0, VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE);
|
---|
1379 | AssertReturn(cchName < RTDBG_SEGMENT_NAME_LENGTH, VERR_DBG_SEGMENT_NAME_OUT_OF_RANGE);
|
---|
1380 | AssertMsgReturn(!fFlags, ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
|
---|
1381 | AssertPtrNull(piSeg);
|
---|
1382 | AssertMsgReturn(!piSeg || *piSeg == NIL_RTDBGSEGIDX || *piSeg <= RTDBGSEGIDX_LAST, ("%#x\n", *piSeg), VERR_DBG_SPECIAL_SEGMENT);
|
---|
1383 |
|
---|
1384 | /*
|
---|
1385 | * Do the deed.
|
---|
1386 | */
|
---|
1387 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1388 | int rc = pDbgMod->pDbgVt->pfnSegmentAdd(pDbgMod, uRva, cb, pszName, cchName, fFlags, piSeg);
|
---|
1389 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1390 |
|
---|
1391 | return rc;
|
---|
1392 |
|
---|
1393 | }
|
---|
1394 | RT_EXPORT_SYMBOL(RTDbgModSegmentAdd);
|
---|
1395 |
|
---|
1396 |
|
---|
1397 | RTDECL(RTDBGSEGIDX) RTDbgModSegmentCount(RTDBGMOD hDbgMod)
|
---|
1398 | {
|
---|
1399 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1400 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, NIL_RTDBGSEGIDX);
|
---|
1401 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1402 |
|
---|
1403 | RTDBGSEGIDX cSegs = pDbgMod->pDbgVt->pfnSegmentCount(pDbgMod);
|
---|
1404 |
|
---|
1405 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1406 | return cSegs;
|
---|
1407 | }
|
---|
1408 | RT_EXPORT_SYMBOL(RTDbgModSegmentCount);
|
---|
1409 |
|
---|
1410 |
|
---|
1411 | RTDECL(int) RTDbgModSegmentByIndex(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo)
|
---|
1412 | {
|
---|
1413 | AssertMsgReturn(iSeg <= RTDBGSEGIDX_LAST, ("%#x\n", iSeg), VERR_DBG_SPECIAL_SEGMENT);
|
---|
1414 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1415 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
|
---|
1416 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1417 |
|
---|
1418 | int rc = pDbgMod->pDbgVt->pfnSegmentByIndex(pDbgMod, iSeg, pSegInfo);
|
---|
1419 |
|
---|
1420 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1421 | return rc;
|
---|
1422 | }
|
---|
1423 | RT_EXPORT_SYMBOL(RTDbgModSegmentByIndex);
|
---|
1424 |
|
---|
1425 |
|
---|
1426 | RTDECL(RTUINTPTR) RTDbgModSegmentSize(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg)
|
---|
1427 | {
|
---|
1428 | if (iSeg == RTDBGSEGIDX_RVA)
|
---|
1429 | return RTDbgModImageSize(hDbgMod);
|
---|
1430 | RTDBGSEGMENT SegInfo;
|
---|
1431 | int rc = RTDbgModSegmentByIndex(hDbgMod, iSeg, &SegInfo);
|
---|
1432 | return RT_SUCCESS(rc) ? SegInfo.cb : RTUINTPTR_MAX;
|
---|
1433 | }
|
---|
1434 | RT_EXPORT_SYMBOL(RTDbgModSegmentSize);
|
---|
1435 |
|
---|
1436 |
|
---|
1437 | RTDECL(RTUINTPTR) RTDbgModSegmentRva(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg)
|
---|
1438 | {
|
---|
1439 | RTDBGSEGMENT SegInfo;
|
---|
1440 | int rc = RTDbgModSegmentByIndex(hDbgMod, iSeg, &SegInfo);
|
---|
1441 | return RT_SUCCESS(rc) ? SegInfo.uRva : RTUINTPTR_MAX;
|
---|
1442 | }
|
---|
1443 | RT_EXPORT_SYMBOL(RTDbgModSegmentRva);
|
---|
1444 |
|
---|
1445 |
|
---|
1446 | RTDECL(int) RTDbgModSymbolAdd(RTDBGMOD hDbgMod, const char *pszSymbol, RTDBGSEGIDX iSeg, RTUINTPTR off,
|
---|
1447 | RTUINTPTR cb, uint32_t fFlags, uint32_t *piOrdinal)
|
---|
1448 | {
|
---|
1449 | /*
|
---|
1450 | * Validate input.
|
---|
1451 | */
|
---|
1452 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1453 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
|
---|
1454 | AssertPtr(pszSymbol);
|
---|
1455 | size_t cchSymbol = strlen(pszSymbol);
|
---|
1456 | AssertReturn(cchSymbol, VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE);
|
---|
1457 | AssertReturn(cchSymbol < RTDBG_SYMBOL_NAME_LENGTH, VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE);
|
---|
1458 | AssertMsgReturn( iSeg <= RTDBGSEGIDX_LAST
|
---|
1459 | || ( iSeg >= RTDBGSEGIDX_SPECIAL_FIRST
|
---|
1460 | && iSeg <= RTDBGSEGIDX_SPECIAL_LAST),
|
---|
1461 | ("%#x\n", iSeg),
|
---|
1462 | VERR_DBG_INVALID_SEGMENT_INDEX);
|
---|
1463 | AssertMsgReturn(off + cb >= off, ("off=%RTptr cb=%RTptr\n", off, cb), VERR_DBG_ADDRESS_WRAP);
|
---|
1464 | AssertReturn(!fFlags, VERR_INVALID_PARAMETER); /* currently reserved. */
|
---|
1465 |
|
---|
1466 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1467 |
|
---|
1468 | /*
|
---|
1469 | * Convert RVAs.
|
---|
1470 | */
|
---|
1471 | if (iSeg == RTDBGSEGIDX_RVA)
|
---|
1472 | {
|
---|
1473 | iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, off, &off);
|
---|
1474 | if (iSeg == NIL_RTDBGSEGIDX)
|
---|
1475 | {
|
---|
1476 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1477 | return VERR_DBG_INVALID_RVA;
|
---|
1478 | }
|
---|
1479 | }
|
---|
1480 |
|
---|
1481 | /*
|
---|
1482 | * Get down to business.
|
---|
1483 | */
|
---|
1484 | int rc = pDbgMod->pDbgVt->pfnSymbolAdd(pDbgMod, pszSymbol, cchSymbol, iSeg, off, cb, fFlags, piOrdinal);
|
---|
1485 |
|
---|
1486 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1487 | return rc;
|
---|
1488 | }
|
---|
1489 | RT_EXPORT_SYMBOL(RTDbgModSymbolAdd);
|
---|
1490 |
|
---|
1491 |
|
---|
1492 | RTDECL(uint32_t) RTDbgModSymbolCount(RTDBGMOD hDbgMod)
|
---|
1493 | {
|
---|
1494 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1495 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
|
---|
1496 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1497 |
|
---|
1498 | uint32_t cSymbols = pDbgMod->pDbgVt->pfnSymbolCount(pDbgMod);
|
---|
1499 |
|
---|
1500 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1501 | return cSymbols;
|
---|
1502 | }
|
---|
1503 | RT_EXPORT_SYMBOL(RTDbgModSymbolCount);
|
---|
1504 |
|
---|
1505 |
|
---|
1506 | RTDECL(int) RTDbgModSymbolByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo)
|
---|
1507 | {
|
---|
1508 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1509 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
|
---|
1510 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1511 |
|
---|
1512 | int rc = pDbgMod->pDbgVt->pfnSymbolByOrdinal(pDbgMod, iOrdinal, pSymInfo);
|
---|
1513 |
|
---|
1514 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1515 | return rc;
|
---|
1516 | }
|
---|
1517 | RT_EXPORT_SYMBOL(RTDbgModSymbolByOrdinal);
|
---|
1518 |
|
---|
1519 |
|
---|
1520 | RTDECL(int) RTDbgModSymbolByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGSYMBOL *ppSymInfo)
|
---|
1521 | {
|
---|
1522 | AssertPtr(ppSymInfo);
|
---|
1523 | *ppSymInfo = NULL;
|
---|
1524 |
|
---|
1525 | PRTDBGSYMBOL pSymInfo = RTDbgSymbolAlloc();
|
---|
1526 | if (!pSymInfo)
|
---|
1527 | return VERR_NO_MEMORY;
|
---|
1528 |
|
---|
1529 | int rc = RTDbgModSymbolByOrdinal(hDbgMod, iOrdinal, pSymInfo);
|
---|
1530 |
|
---|
1531 | if (RT_SUCCESS(rc))
|
---|
1532 | *ppSymInfo = pSymInfo;
|
---|
1533 | else
|
---|
1534 | RTDbgSymbolFree(pSymInfo);
|
---|
1535 | return rc;
|
---|
1536 | }
|
---|
1537 | RT_EXPORT_SYMBOL(RTDbgModSymbolByOrdinalA);
|
---|
1538 |
|
---|
1539 |
|
---|
1540 | RTDECL(int) RTDbgModSymbolByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
|
---|
1541 | PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo)
|
---|
1542 | {
|
---|
1543 | /*
|
---|
1544 | * Validate input.
|
---|
1545 | */
|
---|
1546 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1547 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
|
---|
1548 | AssertPtrNull(poffDisp);
|
---|
1549 | AssertPtr(pSymInfo);
|
---|
1550 | AssertReturn(!(fFlags & ~RTDBGSYMADDR_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER);
|
---|
1551 |
|
---|
1552 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1553 |
|
---|
1554 | /*
|
---|
1555 | * Convert RVAs.
|
---|
1556 | */
|
---|
1557 | if (iSeg == RTDBGSEGIDX_RVA)
|
---|
1558 | {
|
---|
1559 | iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, off, &off);
|
---|
1560 | if (iSeg == NIL_RTDBGSEGIDX)
|
---|
1561 | {
|
---|
1562 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1563 | return VERR_DBG_INVALID_RVA;
|
---|
1564 | }
|
---|
1565 | }
|
---|
1566 |
|
---|
1567 | /*
|
---|
1568 | * Get down to business.
|
---|
1569 | */
|
---|
1570 | int rc = pDbgMod->pDbgVt->pfnSymbolByAddr(pDbgMod, iSeg, off, fFlags, poffDisp, pSymInfo);
|
---|
1571 |
|
---|
1572 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1573 | return rc;
|
---|
1574 | }
|
---|
1575 | RT_EXPORT_SYMBOL(RTDbgModSymbolByAddr);
|
---|
1576 |
|
---|
1577 |
|
---|
1578 | RTDECL(int) RTDbgModSymbolByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
|
---|
1579 | PRTINTPTR poffDisp, PRTDBGSYMBOL *ppSymInfo)
|
---|
1580 | {
|
---|
1581 | AssertPtr(ppSymInfo);
|
---|
1582 | *ppSymInfo = NULL;
|
---|
1583 |
|
---|
1584 | PRTDBGSYMBOL pSymInfo = RTDbgSymbolAlloc();
|
---|
1585 | if (!pSymInfo)
|
---|
1586 | return VERR_NO_MEMORY;
|
---|
1587 |
|
---|
1588 | int rc = RTDbgModSymbolByAddr(hDbgMod, iSeg, off, fFlags, poffDisp, pSymInfo);
|
---|
1589 |
|
---|
1590 | if (RT_SUCCESS(rc))
|
---|
1591 | *ppSymInfo = pSymInfo;
|
---|
1592 | else
|
---|
1593 | RTDbgSymbolFree(pSymInfo);
|
---|
1594 | return rc;
|
---|
1595 | }
|
---|
1596 | RT_EXPORT_SYMBOL(RTDbgModSymbolByAddrA);
|
---|
1597 |
|
---|
1598 |
|
---|
1599 | RTDECL(int) RTDbgModSymbolByName(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL pSymInfo)
|
---|
1600 | {
|
---|
1601 | /*
|
---|
1602 | * Validate input.
|
---|
1603 | */
|
---|
1604 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1605 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
|
---|
1606 | AssertPtr(pszSymbol);
|
---|
1607 | size_t cchSymbol = strlen(pszSymbol);
|
---|
1608 | AssertReturn(cchSymbol, VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE);
|
---|
1609 | AssertReturn(cchSymbol < RTDBG_SYMBOL_NAME_LENGTH, VERR_DBG_SYMBOL_NAME_OUT_OF_RANGE);
|
---|
1610 | AssertPtr(pSymInfo);
|
---|
1611 |
|
---|
1612 | /*
|
---|
1613 | * Make the query.
|
---|
1614 | */
|
---|
1615 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1616 | int rc = pDbgMod->pDbgVt->pfnSymbolByName(pDbgMod, pszSymbol, cchSymbol, pSymInfo);
|
---|
1617 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1618 |
|
---|
1619 | return rc;
|
---|
1620 | }
|
---|
1621 | RT_EXPORT_SYMBOL(RTDbgModSymbolByName);
|
---|
1622 |
|
---|
1623 |
|
---|
1624 | RTDECL(int) RTDbgModSymbolByNameA(RTDBGMOD hDbgMod, const char *pszSymbol, PRTDBGSYMBOL *ppSymInfo)
|
---|
1625 | {
|
---|
1626 | AssertPtr(ppSymInfo);
|
---|
1627 | *ppSymInfo = NULL;
|
---|
1628 |
|
---|
1629 | PRTDBGSYMBOL pSymInfo = RTDbgSymbolAlloc();
|
---|
1630 | if (!pSymInfo)
|
---|
1631 | return VERR_NO_MEMORY;
|
---|
1632 |
|
---|
1633 | int rc = RTDbgModSymbolByName(hDbgMod, pszSymbol, pSymInfo);
|
---|
1634 |
|
---|
1635 | if (RT_SUCCESS(rc))
|
---|
1636 | *ppSymInfo = pSymInfo;
|
---|
1637 | else
|
---|
1638 | RTDbgSymbolFree(pSymInfo);
|
---|
1639 | return rc;
|
---|
1640 | }
|
---|
1641 | RT_EXPORT_SYMBOL(RTDbgModSymbolByNameA);
|
---|
1642 |
|
---|
1643 |
|
---|
1644 | RTDECL(int) RTDbgModLineAdd(RTDBGMOD hDbgMod, const char *pszFile, uint32_t uLineNo,
|
---|
1645 | RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t *piOrdinal)
|
---|
1646 | {
|
---|
1647 | /*
|
---|
1648 | * Validate input.
|
---|
1649 | */
|
---|
1650 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1651 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
|
---|
1652 | AssertPtr(pszFile);
|
---|
1653 | size_t cchFile = strlen(pszFile);
|
---|
1654 | AssertReturn(cchFile, VERR_DBG_FILE_NAME_OUT_OF_RANGE);
|
---|
1655 | AssertReturn(cchFile < RTDBG_FILE_NAME_LENGTH, VERR_DBG_FILE_NAME_OUT_OF_RANGE);
|
---|
1656 | AssertMsgReturn( iSeg <= RTDBGSEGIDX_LAST
|
---|
1657 | || iSeg == RTDBGSEGIDX_RVA,
|
---|
1658 | ("%#x\n", iSeg),
|
---|
1659 | VERR_DBG_INVALID_SEGMENT_INDEX);
|
---|
1660 | AssertReturn(uLineNo > 0 && uLineNo < UINT32_MAX, VERR_INVALID_PARAMETER);
|
---|
1661 |
|
---|
1662 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1663 |
|
---|
1664 | /*
|
---|
1665 | * Convert RVAs.
|
---|
1666 | */
|
---|
1667 | if (iSeg == RTDBGSEGIDX_RVA)
|
---|
1668 | {
|
---|
1669 | iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, off, &off);
|
---|
1670 | if (iSeg == NIL_RTDBGSEGIDX)
|
---|
1671 | {
|
---|
1672 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1673 | return VERR_DBG_INVALID_RVA;
|
---|
1674 | }
|
---|
1675 | }
|
---|
1676 |
|
---|
1677 | /*
|
---|
1678 | * Get down to business.
|
---|
1679 | */
|
---|
1680 | int rc = pDbgMod->pDbgVt->pfnLineAdd(pDbgMod, pszFile, cchFile, uLineNo, iSeg, off, piOrdinal);
|
---|
1681 |
|
---|
1682 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1683 | return rc;
|
---|
1684 | }
|
---|
1685 | RT_EXPORT_SYMBOL(RTDbgModLineAdd);
|
---|
1686 |
|
---|
1687 |
|
---|
1688 | RTDECL(uint32_t) RTDbgModLineCount(RTDBGMOD hDbgMod)
|
---|
1689 | {
|
---|
1690 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1691 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, UINT32_MAX);
|
---|
1692 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1693 |
|
---|
1694 | uint32_t cLineNumbers = pDbgMod->pDbgVt->pfnLineCount(pDbgMod);
|
---|
1695 |
|
---|
1696 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1697 | return cLineNumbers;
|
---|
1698 | }
|
---|
1699 | RT_EXPORT_SYMBOL(RTDbgModLineCount);
|
---|
1700 |
|
---|
1701 |
|
---|
1702 | RTDECL(int) RTDbgModLineByOrdinal(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo)
|
---|
1703 | {
|
---|
1704 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1705 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
|
---|
1706 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1707 |
|
---|
1708 | int rc = pDbgMod->pDbgVt->pfnLineByOrdinal(pDbgMod, iOrdinal, pLineInfo);
|
---|
1709 |
|
---|
1710 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1711 | return rc;
|
---|
1712 | }
|
---|
1713 | RT_EXPORT_SYMBOL(RTDbgModLineByOrdinal);
|
---|
1714 |
|
---|
1715 |
|
---|
1716 | RTDECL(int) RTDbgModLineByOrdinalA(RTDBGMOD hDbgMod, uint32_t iOrdinal, PRTDBGLINE *ppLineInfo)
|
---|
1717 | {
|
---|
1718 | AssertPtr(ppLineInfo);
|
---|
1719 | *ppLineInfo = NULL;
|
---|
1720 |
|
---|
1721 | PRTDBGLINE pLineInfo = RTDbgLineAlloc();
|
---|
1722 | if (!pLineInfo)
|
---|
1723 | return VERR_NO_MEMORY;
|
---|
1724 |
|
---|
1725 | int rc = RTDbgModLineByOrdinal(hDbgMod, iOrdinal, pLineInfo);
|
---|
1726 |
|
---|
1727 | if (RT_SUCCESS(rc))
|
---|
1728 | *ppLineInfo = pLineInfo;
|
---|
1729 | else
|
---|
1730 | RTDbgLineFree(pLineInfo);
|
---|
1731 | return rc;
|
---|
1732 | }
|
---|
1733 | RT_EXPORT_SYMBOL(RTDbgModLineByOrdinalA);
|
---|
1734 |
|
---|
1735 |
|
---|
1736 | RTDECL(int) RTDbgModLineByAddr(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE pLineInfo)
|
---|
1737 | {
|
---|
1738 | /*
|
---|
1739 | * Validate input.
|
---|
1740 | */
|
---|
1741 | PRTDBGMODINT pDbgMod = hDbgMod;
|
---|
1742 | RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
|
---|
1743 | AssertPtrNull(poffDisp);
|
---|
1744 | AssertPtr(pLineInfo);
|
---|
1745 |
|
---|
1746 | RTDBGMOD_LOCK(pDbgMod);
|
---|
1747 |
|
---|
1748 | /*
|
---|
1749 | * Convert RVAs.
|
---|
1750 | */
|
---|
1751 | if (iSeg == RTDBGSEGIDX_RVA)
|
---|
1752 | {
|
---|
1753 | iSeg = pDbgMod->pDbgVt->pfnRvaToSegOff(pDbgMod, off, &off);
|
---|
1754 | if (iSeg == NIL_RTDBGSEGIDX)
|
---|
1755 | {
|
---|
1756 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1757 | return VERR_DBG_INVALID_RVA;
|
---|
1758 | }
|
---|
1759 | }
|
---|
1760 |
|
---|
1761 | int rc = pDbgMod->pDbgVt->pfnLineByAddr(pDbgMod, iSeg, off, poffDisp, pLineInfo);
|
---|
1762 |
|
---|
1763 | RTDBGMOD_UNLOCK(pDbgMod);
|
---|
1764 | return rc;
|
---|
1765 | }
|
---|
1766 | RT_EXPORT_SYMBOL(RTDbgModLineByAddr);
|
---|
1767 |
|
---|
1768 |
|
---|
1769 | RTDECL(int) RTDbgModLineByAddrA(RTDBGMOD hDbgMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTINTPTR poffDisp, PRTDBGLINE *ppLineInfo)
|
---|
1770 | {
|
---|
1771 | AssertPtr(ppLineInfo);
|
---|
1772 | *ppLineInfo = NULL;
|
---|
1773 |
|
---|
1774 | PRTDBGLINE pLineInfo = RTDbgLineAlloc();
|
---|
1775 | if (!pLineInfo)
|
---|
1776 | return VERR_NO_MEMORY;
|
---|
1777 |
|
---|
1778 | int rc = RTDbgModLineByAddr(hDbgMod, iSeg, off, poffDisp, pLineInfo);
|
---|
1779 |
|
---|
1780 | if (RT_SUCCESS(rc))
|
---|
1781 | *ppLineInfo = pLineInfo;
|
---|
1782 | else
|
---|
1783 | RTDbgLineFree(pLineInfo);
|
---|
1784 | return rc;
|
---|
1785 | }
|
---|
1786 | RT_EXPORT_SYMBOL(RTDbgModLineByAddrA);
|
---|
1787 |
|
---|