1 | /* $Id: dbgmoddeferred.cpp 45997 2013-05-13 01:47:44Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Debug Module Deferred Loading Stub.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013 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 | #include <iprt/dbg.h>
|
---|
32 | #include "internal/iprt.h"
|
---|
33 |
|
---|
34 | #include <iprt/asm.h>
|
---|
35 | #include <iprt/assert.h>
|
---|
36 | #include <iprt/err.h>
|
---|
37 | #include <iprt/mem.h>
|
---|
38 | #include <iprt/param.h>
|
---|
39 | #include <iprt/path.h>
|
---|
40 | #include <iprt/string.h>
|
---|
41 | #include "internal/dbgmod.h"
|
---|
42 | #include "internal/magics.h"
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Releases the instance data.
|
---|
48 | *
|
---|
49 | * @param pThis The instance data.
|
---|
50 | */
|
---|
51 | static void rtDbgModDeferredReleaseInstanceData(PRTDBGMODDEFERRED pThis)
|
---|
52 | {
|
---|
53 | AssertPtr(pThis);
|
---|
54 | uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs); Assert(cRefs < 8);
|
---|
55 | if (!cRefs)
|
---|
56 | {
|
---|
57 | RTDbgCfgRelease(pThis->hDbgCfg);
|
---|
58 | pThis->hDbgCfg = NIL_RTDBGCFG;
|
---|
59 | RTMemFree(pThis);
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Does the deferred loading of the real data (image and/or debug info).
|
---|
66 | *
|
---|
67 | * @returns VINF_SUCCESS or VERR_DBG_DEFERRED_LOAD_FAILED.
|
---|
68 | * @param pMod The generic module instance data.
|
---|
69 | * @param fForcedRetry Whether it's a forced retry by one of the
|
---|
70 | * pfnTryOpen methods.
|
---|
71 | */
|
---|
72 | static int rtDbgModDeferredDoIt(PRTDBGMODINT pMod, bool fForcedRetry)
|
---|
73 | {
|
---|
74 | RTCritSectEnter(&pMod->CritSect);
|
---|
75 |
|
---|
76 | int rc;
|
---|
77 | if (!pMod->fDeferredFailed || fForcedRetry)
|
---|
78 | {
|
---|
79 | bool const fDbgVt = pMod->pDbgVt == &g_rtDbgModVtDbgDeferred;
|
---|
80 | bool const fImgVt = pMod->pImgVt == &g_rtDbgModVtImgDeferred;
|
---|
81 | AssertReturnStmt(fDbgVt || fImgVt, RTCritSectLeave(&pMod->CritSect), VERR_INTERNAL_ERROR_5);
|
---|
82 |
|
---|
83 | PRTDBGMODDEFERRED pThis = (PRTDBGMODDEFERRED)(fDbgVt ? pMod->pvDbgPriv : pMod->pvImgPriv);
|
---|
84 |
|
---|
85 | /* Reset the method tables and private data pointes so the deferred loading
|
---|
86 | procedure can figure out what to do and won't get confused. */
|
---|
87 | if (fDbgVt)
|
---|
88 | {
|
---|
89 | pMod->pvDbgPriv = NULL;
|
---|
90 | pMod->pDbgVt = NULL;
|
---|
91 | }
|
---|
92 |
|
---|
93 | if (fImgVt)
|
---|
94 | {
|
---|
95 | pMod->pvImgPriv = NULL;
|
---|
96 | pMod->pImgVt = NULL;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /* Do the deferred loading. */
|
---|
100 | rc = pThis->pfnDeferred(pMod, pThis);
|
---|
101 | if (RT_SUCCESS(rc))
|
---|
102 | {
|
---|
103 | Assert(!fDbgVt || pMod->pDbgVt != NULL);
|
---|
104 | Assert(!fImgVt || pMod->pImgVt != NULL);
|
---|
105 |
|
---|
106 | pMod->fDeferred = false;
|
---|
107 | pMod->fDeferredFailed = false;
|
---|
108 |
|
---|
109 | rtDbgModDeferredReleaseInstanceData(pThis);
|
---|
110 | }
|
---|
111 | else
|
---|
112 | {
|
---|
113 | /* Failed, bail out and restore the deferred setup. */
|
---|
114 | pMod->fDeferredFailed = true;
|
---|
115 |
|
---|
116 | if (fDbgVt)
|
---|
117 | {
|
---|
118 | pMod->pvDbgPriv = pThis;
|
---|
119 | pMod->pDbgVt = &g_rtDbgModVtDbgDeferred;
|
---|
120 | }
|
---|
121 |
|
---|
122 | if (fImgVt)
|
---|
123 | {
|
---|
124 | pMod->pvImgPriv = pThis;
|
---|
125 | pMod->pImgVt = &g_rtDbgModVtImgDeferred;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 | else
|
---|
130 | rc = VERR_DBG_DEFERRED_LOAD_FAILED;
|
---|
131 |
|
---|
132 | RTCritSectLeave(&pMod->CritSect);
|
---|
133 | return rc;
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 | /*
|
---|
140 | *
|
---|
141 | * D e b u g I n f o M e t h o d s
|
---|
142 | * D e b u g I n f o M e t h o d s
|
---|
143 | * D e b u g I n f o M e t h o d s
|
---|
144 | *
|
---|
145 | */
|
---|
146 |
|
---|
147 |
|
---|
148 | /** @interface_method_impl{RTDBGMODVTDBG,pfnLineByAddr} */
|
---|
149 | static DECLCALLBACK(int) rtDbgModDeferredDbg_LineByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
|
---|
150 | PRTINTPTR poffDisp, PRTDBGLINE pLineInfo)
|
---|
151 | {
|
---|
152 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
153 | if (RT_SUCCESS(rc))
|
---|
154 | rc = pMod->pDbgVt->pfnLineByAddr(pMod, iSeg, off, poffDisp, pLineInfo);
|
---|
155 | return rc;
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | /** @interface_method_impl{RTDBGMODVTDBG,pfnLineByOrdinal} */
|
---|
160 | static DECLCALLBACK(int) rtDbgModDeferredDbg_LineByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo)
|
---|
161 | {
|
---|
162 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
163 | if (RT_SUCCESS(rc))
|
---|
164 | rc = pMod->pDbgVt->pfnLineByOrdinal(pMod, iOrdinal, pLineInfo);
|
---|
165 | return rc;
|
---|
166 | }
|
---|
167 |
|
---|
168 |
|
---|
169 | /** @interface_method_impl{RTDBGMODVTDBG,pfnLineCount} */
|
---|
170 | static DECLCALLBACK(uint32_t) rtDbgModDeferredDbg_LineCount(PRTDBGMODINT pMod)
|
---|
171 | {
|
---|
172 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
173 | if (RT_SUCCESS(rc))
|
---|
174 | return pMod->pDbgVt->pfnLineCount(pMod);
|
---|
175 | return 0;
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 | /** @interface_method_impl{RTDBGMODVTDBG,pfnLineAdd} */
|
---|
180 | static DECLCALLBACK(int) rtDbgModDeferredDbg_LineAdd(PRTDBGMODINT pMod, const char *pszFile, size_t cchFile, uint32_t uLineNo,
|
---|
181 | uint32_t iSeg, RTUINTPTR off, uint32_t *piOrdinal)
|
---|
182 | {
|
---|
183 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
184 | if (RT_SUCCESS(rc))
|
---|
185 | rc = pMod->pDbgVt->pfnLineAdd(pMod, pszFile, cchFile, uLineNo, iSeg, off, piOrdinal);
|
---|
186 | return rc;
|
---|
187 | }
|
---|
188 |
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * Fill in symbol info for the fake start symbol.
|
---|
192 | *
|
---|
193 | * @returns VINF_SUCCESS
|
---|
194 | * @param pThis The deferred load data.
|
---|
195 | * @param pSymInfo The output structure.
|
---|
196 | */
|
---|
197 | static int rtDbgModDeferredDbgSymInfo_Start(PRTDBGMODDEFERRED pThis, PRTDBGSYMBOL pSymInfo)
|
---|
198 | {
|
---|
199 | pSymInfo->Value = 0;
|
---|
200 | pSymInfo->cb = pThis->cbImage;
|
---|
201 | pSymInfo->offSeg = 0;
|
---|
202 | pSymInfo->iSeg = 0;
|
---|
203 | pSymInfo->fFlags = 0;
|
---|
204 | pSymInfo->iOrdinal = 0;
|
---|
205 | memcpy(pSymInfo->szName, RT_STR_TUPLE("DeferredStart"));
|
---|
206 | return VINF_SUCCESS;
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Fill in symbol info for the fake last symbol.
|
---|
212 | *
|
---|
213 | * @returns VINF_SUCCESS
|
---|
214 | * @param pThis The deferred load data.
|
---|
215 | * @param pSymInfo The output structure.
|
---|
216 | */
|
---|
217 | static int rtDbgModDeferredDbgSymInfo_Last(PRTDBGMODDEFERRED pThis, PRTDBGSYMBOL pSymInfo)
|
---|
218 | {
|
---|
219 | pSymInfo->Value = pThis->cbImage - 1;
|
---|
220 | pSymInfo->cb = 0;
|
---|
221 | pSymInfo->offSeg = pThis->cbImage - 1;
|
---|
222 | pSymInfo->iSeg = 0;
|
---|
223 | pSymInfo->fFlags = 0;
|
---|
224 | pSymInfo->iOrdinal = 1;
|
---|
225 | memcpy(pSymInfo->szName, RT_STR_TUPLE("DeferredLast"));
|
---|
226 | return VINF_SUCCESS;
|
---|
227 | }
|
---|
228 |
|
---|
229 |
|
---|
230 | /** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByAddr} */
|
---|
231 | static DECLCALLBACK(int) rtDbgModDeferredDbg_SymbolByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off, uint32_t fFlags,
|
---|
232 | PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo)
|
---|
233 | {
|
---|
234 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
235 | if (RT_SUCCESS(rc))
|
---|
236 | rc = pMod->pDbgVt->pfnSymbolByAddr(pMod, iSeg, off, fFlags, poffDisp, pSymInfo);
|
---|
237 | else
|
---|
238 | {
|
---|
239 | PRTDBGMODDEFERRED pThis = (PRTDBGMODDEFERRED)pMod->pvDbgPriv;
|
---|
240 | if (off == 0)
|
---|
241 | rc = rtDbgModDeferredDbgSymInfo_Start(pThis, pSymInfo);
|
---|
242 | else if (off >= pThis->cbImage - 1 || (fFlags & RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL))
|
---|
243 | rc = rtDbgModDeferredDbgSymInfo_Last(pThis, pSymInfo);
|
---|
244 | else
|
---|
245 | rc = rtDbgModDeferredDbgSymInfo_Start(pThis, pSymInfo);
|
---|
246 | if (poffDisp)
|
---|
247 | *poffDisp = off - pSymInfo->offSeg;
|
---|
248 | }
|
---|
249 | return rc;
|
---|
250 | }
|
---|
251 |
|
---|
252 |
|
---|
253 | /** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByName} */
|
---|
254 | static DECLCALLBACK(int) rtDbgModDeferredDbg_SymbolByName(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
|
---|
255 | PRTDBGSYMBOL pSymInfo)
|
---|
256 | {
|
---|
257 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
258 | if (RT_SUCCESS(rc))
|
---|
259 | rc = pMod->pDbgVt->pfnSymbolByName(pMod, pszSymbol, cchSymbol, pSymInfo);
|
---|
260 | else
|
---|
261 | {
|
---|
262 | PRTDBGMODDEFERRED pThis = (PRTDBGMODDEFERRED)pMod->pvDbgPriv;
|
---|
263 | if ( cchSymbol == sizeof("DeferredStart") - 1
|
---|
264 | && !memcmp(pszSymbol, RT_STR_TUPLE("DeferredStart")))
|
---|
265 | rc = rtDbgModDeferredDbgSymInfo_Start(pThis, pSymInfo);
|
---|
266 | else if ( cchSymbol == sizeof("DeferredLast") - 1
|
---|
267 | && !memcmp(pszSymbol, RT_STR_TUPLE("DeferredLast")))
|
---|
268 | rc = rtDbgModDeferredDbgSymInfo_Last(pThis, pSymInfo);
|
---|
269 | else
|
---|
270 | rc = VERR_SYMBOL_NOT_FOUND;
|
---|
271 | }
|
---|
272 | return rc;
|
---|
273 | }
|
---|
274 |
|
---|
275 |
|
---|
276 | /** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByOrdinal} */
|
---|
277 | static DECLCALLBACK(int) rtDbgModDeferredDbg_SymbolByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo)
|
---|
278 | {
|
---|
279 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
280 | if (RT_SUCCESS(rc))
|
---|
281 | rc = pMod->pDbgVt->pfnSymbolByOrdinal(pMod, iOrdinal, pSymInfo);
|
---|
282 | else
|
---|
283 | {
|
---|
284 | PRTDBGMODDEFERRED pThis = (PRTDBGMODDEFERRED)pMod->pvDbgPriv;
|
---|
285 | if (iOrdinal == 0)
|
---|
286 | rc = rtDbgModDeferredDbgSymInfo_Start(pThis, pSymInfo);
|
---|
287 | else if (iOrdinal == 1)
|
---|
288 | rc = rtDbgModDeferredDbgSymInfo_Last(pThis, pSymInfo);
|
---|
289 | else
|
---|
290 | rc = VERR_SYMBOL_NOT_FOUND;
|
---|
291 | }
|
---|
292 | return rc;
|
---|
293 | }
|
---|
294 |
|
---|
295 |
|
---|
296 | /** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolCount} */
|
---|
297 | static DECLCALLBACK(uint32_t) rtDbgModDeferredDbg_SymbolCount(PRTDBGMODINT pMod)
|
---|
298 | {
|
---|
299 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
300 | if (RT_SUCCESS(rc))
|
---|
301 | return pMod->pDbgVt->pfnSymbolCount(pMod);
|
---|
302 | return 2;
|
---|
303 | }
|
---|
304 |
|
---|
305 |
|
---|
306 | /** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolAdd} */
|
---|
307 | static DECLCALLBACK(int) rtDbgModDeferredDbg_SymbolAdd(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
|
---|
308 | RTDBGSEGIDX iSeg, RTUINTPTR off, RTUINTPTR cb, uint32_t fFlags,
|
---|
309 | uint32_t *piOrdinal)
|
---|
310 | {
|
---|
311 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
312 | if (RT_SUCCESS(rc))
|
---|
313 | rc = pMod->pDbgVt->pfnSymbolAdd(pMod, pszSymbol, cchSymbol, iSeg, off, cb, fFlags, piOrdinal);
|
---|
314 | return rc;
|
---|
315 | }
|
---|
316 |
|
---|
317 |
|
---|
318 | /** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentByIndex} */
|
---|
319 | static DECLCALLBACK(int) rtDbgModDeferredDbg_SegmentByIndex(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo)
|
---|
320 | {
|
---|
321 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
322 | if (RT_SUCCESS(rc))
|
---|
323 | rc = pMod->pDbgVt->pfnSegmentByIndex(pMod, iSeg, pSegInfo);
|
---|
324 | else if (iSeg == 0)
|
---|
325 | {
|
---|
326 | PRTDBGMODDEFERRED pThis = (PRTDBGMODDEFERRED)pMod->pvDbgPriv;
|
---|
327 | pSegInfo->Address = 0;
|
---|
328 | pSegInfo->uRva = 0;
|
---|
329 | pSegInfo->cb = pThis->cbImage;
|
---|
330 | pSegInfo->fFlags = 0;
|
---|
331 | pSegInfo->iSeg = 0;
|
---|
332 | memcpy(pSegInfo->szName, RT_STR_TUPLE("LATER"));
|
---|
333 | }
|
---|
334 | else
|
---|
335 | rc = VERR_DBG_INVALID_SEGMENT_INDEX;
|
---|
336 | return rc;
|
---|
337 | }
|
---|
338 |
|
---|
339 |
|
---|
340 | /** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentCount} */
|
---|
341 | static DECLCALLBACK(RTDBGSEGIDX) rtDbgModDeferredDbg_SegmentCount(PRTDBGMODINT pMod)
|
---|
342 | {
|
---|
343 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
344 | if (RT_SUCCESS(rc))
|
---|
345 | return pMod->pDbgVt->pfnSegmentCount(pMod);
|
---|
346 | return 1;
|
---|
347 | }
|
---|
348 |
|
---|
349 |
|
---|
350 | /** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentAdd} */
|
---|
351 | static DECLCALLBACK(int) rtDbgModDeferredDbg_SegmentAdd(PRTDBGMODINT pMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName,
|
---|
352 | size_t cchName, uint32_t fFlags, PRTDBGSEGIDX piSeg)
|
---|
353 | {
|
---|
354 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
355 | if (RT_SUCCESS(rc))
|
---|
356 | rc = pMod->pDbgVt->pfnSegmentAdd(pMod, uRva, cb, pszName, cchName, fFlags, piSeg);
|
---|
357 | return rc;
|
---|
358 | }
|
---|
359 |
|
---|
360 |
|
---|
361 | /** @interface_method_impl{RTDBGMODVTDBG,pfnImageSize} */
|
---|
362 | static DECLCALLBACK(RTUINTPTR) rtDbgModDeferredDbg_ImageSize(PRTDBGMODINT pMod)
|
---|
363 | {
|
---|
364 | PRTDBGMODDEFERRED pThis = (PRTDBGMODDEFERRED)pMod->pvDbgPriv;
|
---|
365 | return pThis->cbImage;
|
---|
366 | }
|
---|
367 |
|
---|
368 |
|
---|
369 | /** @interface_method_impl{RTDBGMODVTDBG,pfnRvaToSegOff} */
|
---|
370 | static DECLCALLBACK(RTDBGSEGIDX) rtDbgModDeferredDbg_RvaToSegOff(PRTDBGMODINT pMod, RTUINTPTR uRva, PRTUINTPTR poffSeg)
|
---|
371 | {
|
---|
372 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
373 | if (RT_SUCCESS(rc))
|
---|
374 | return pMod->pDbgVt->pfnRvaToSegOff(pMod, uRva, poffSeg);
|
---|
375 | return 0;
|
---|
376 | }
|
---|
377 |
|
---|
378 |
|
---|
379 | /** @interface_method_impl{RTDBGMODVTDBG,pfnClose} */
|
---|
380 | static DECLCALLBACK(int) rtDbgModDeferredDbg_Close(PRTDBGMODINT pMod)
|
---|
381 | {
|
---|
382 | rtDbgModDeferredReleaseInstanceData((PRTDBGMODDEFERRED)pMod->pvImgPriv);
|
---|
383 | return VINF_SUCCESS;
|
---|
384 | }
|
---|
385 |
|
---|
386 |
|
---|
387 | /** @interface_method_impl{RTDBGMODVTDBG,pfnTryOpen} */
|
---|
388 | static DECLCALLBACK(int) rtDbgModDeferredDbg_TryOpen(PRTDBGMODINT pMod)
|
---|
389 | {
|
---|
390 | return rtDbgModDeferredDoIt(pMod, true /*fForceRetry*/);
|
---|
391 | }
|
---|
392 |
|
---|
393 |
|
---|
394 |
|
---|
395 | /** Virtual function table for the deferred debug info reader. */
|
---|
396 | DECL_HIDDEN_CONST(RTDBGMODVTDBG) const g_rtDbgModVtDbgDeferred =
|
---|
397 | {
|
---|
398 | /*.u32Magic = */ RTDBGMODVTDBG_MAGIC,
|
---|
399 | /*.fSupports = */ RT_DBGTYPE_MAP,
|
---|
400 | /*.pszName = */ "deferred",
|
---|
401 | /*.pfnTryOpen = */ rtDbgModDeferredDbg_TryOpen,
|
---|
402 | /*.pfnClose = */ rtDbgModDeferredDbg_Close,
|
---|
403 |
|
---|
404 | /*.pfnRvaToSegOff = */ rtDbgModDeferredDbg_RvaToSegOff,
|
---|
405 | /*.pfnImageSize = */ rtDbgModDeferredDbg_ImageSize,
|
---|
406 |
|
---|
407 | /*.pfnSegmentAdd = */ rtDbgModDeferredDbg_SegmentAdd,
|
---|
408 | /*.pfnSegmentCount = */ rtDbgModDeferredDbg_SegmentCount,
|
---|
409 | /*.pfnSegmentByIndex = */ rtDbgModDeferredDbg_SegmentByIndex,
|
---|
410 |
|
---|
411 | /*.pfnSymbolAdd = */ rtDbgModDeferredDbg_SymbolAdd,
|
---|
412 | /*.pfnSymbolCount = */ rtDbgModDeferredDbg_SymbolCount,
|
---|
413 | /*.pfnSymbolByOrdinal = */ rtDbgModDeferredDbg_SymbolByOrdinal,
|
---|
414 | /*.pfnSymbolByName = */ rtDbgModDeferredDbg_SymbolByName,
|
---|
415 | /*.pfnSymbolByAddr = */ rtDbgModDeferredDbg_SymbolByAddr,
|
---|
416 |
|
---|
417 | /*.pfnLineAdd = */ rtDbgModDeferredDbg_LineAdd,
|
---|
418 | /*.pfnLineCount = */ rtDbgModDeferredDbg_LineCount,
|
---|
419 | /*.pfnLineByOrdinal = */ rtDbgModDeferredDbg_LineByOrdinal,
|
---|
420 | /*.pfnLineByAddr = */ rtDbgModDeferredDbg_LineByAddr,
|
---|
421 |
|
---|
422 | /*.u32EndMagic = */ RTDBGMODVTDBG_MAGIC
|
---|
423 | };
|
---|
424 |
|
---|
425 |
|
---|
426 |
|
---|
427 |
|
---|
428 | /*
|
---|
429 | *
|
---|
430 | * I m a g e M e t h o d s
|
---|
431 | * I m a g e M e t h o d s
|
---|
432 | * I m a g e M e t h o d s
|
---|
433 | *
|
---|
434 | */
|
---|
435 |
|
---|
436 |
|
---|
437 | /** @interface_method_impl{RTDBGMODVTIMG,pfnUnmapPart} */
|
---|
438 | static DECLCALLBACK(int) rtDbgModDeferredImg_UnmapPart(PRTDBGMODINT pMod, size_t cb, void const **ppvMap)
|
---|
439 | {
|
---|
440 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
441 | if (RT_SUCCESS(rc))
|
---|
442 | rc = pMod->pImgVt->pfnUnmapPart(pMod, cb, ppvMap);
|
---|
443 | return rc;
|
---|
444 | }
|
---|
445 |
|
---|
446 |
|
---|
447 | /** @interface_method_impl{RTDBGMODVTIMG,pfnMapPart} */
|
---|
448 | static DECLCALLBACK(int) rtDbgModDeferredImg_MapPart(PRTDBGMODINT pMod, RTFOFF off, size_t cb, void const **ppvMap)
|
---|
449 | {
|
---|
450 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
451 | if (RT_SUCCESS(rc))
|
---|
452 | rc = pMod->pImgVt->pfnMapPart(pMod, off, cb, ppvMap);
|
---|
453 | return rc;
|
---|
454 | }
|
---|
455 |
|
---|
456 |
|
---|
457 | /** @interface_method_impl{RTDBGMODVTIMG,pfnImageSize} */
|
---|
458 | static DECLCALLBACK(RTUINTPTR) rtDbgModDeferredImg_ImageSize(PRTDBGMODINT pMod)
|
---|
459 | {
|
---|
460 | PRTDBGMODDEFERRED pThis = (PRTDBGMODDEFERRED)pMod->pvImgPriv;
|
---|
461 | return pThis->cbImage;
|
---|
462 | }
|
---|
463 |
|
---|
464 |
|
---|
465 | /** @interface_method_impl{RTDBGMODVTIMG,pfnLinkAddressToSegOffset} */
|
---|
466 | static DECLCALLBACK(int) rtDbgModDeferredImg_LinkAddressToSegOffset(PRTDBGMODINT pMod, RTLDRADDR LinkAddress,
|
---|
467 | PRTDBGSEGIDX piSeg, PRTLDRADDR poffSeg)
|
---|
468 | {
|
---|
469 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
470 | if (RT_SUCCESS(rc))
|
---|
471 | rc = pMod->pImgVt->pfnLinkAddressToSegOffset(pMod, LinkAddress, piSeg, poffSeg);
|
---|
472 | return rc;
|
---|
473 | }
|
---|
474 |
|
---|
475 |
|
---|
476 | /** @interface_method_impl{RTDBGMODVTIMG,pfnEnumSegments} */
|
---|
477 | static DECLCALLBACK(int) rtDbgModDeferredImg_EnumSegments(PRTDBGMODINT pMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser)
|
---|
478 | {
|
---|
479 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
480 | if (RT_SUCCESS(rc))
|
---|
481 | rc = pMod->pImgVt->pfnEnumSegments(pMod, pfnCallback, pvUser);
|
---|
482 | return rc;
|
---|
483 | }
|
---|
484 |
|
---|
485 |
|
---|
486 | /** @interface_method_impl{RTDBGMODVTIMG,pfnEnumDbgInfo} */
|
---|
487 | static DECLCALLBACK(int) rtDbgModDeferredImg_EnumDbgInfo(PRTDBGMODINT pMod, PFNRTLDRENUMDBG pfnCallback, void *pvUser)
|
---|
488 | {
|
---|
489 | int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
|
---|
490 | if (RT_SUCCESS(rc))
|
---|
491 | rc = pMod->pImgVt->pfnEnumDbgInfo(pMod, pfnCallback, pvUser);
|
---|
492 | return rc;
|
---|
493 | }
|
---|
494 |
|
---|
495 |
|
---|
496 | /** @interface_method_impl{RTDBGMODVTIMG,pfnClose} */
|
---|
497 | static DECLCALLBACK(int) rtDbgModDeferredImg_Close(PRTDBGMODINT pMod)
|
---|
498 | {
|
---|
499 | rtDbgModDeferredReleaseInstanceData((PRTDBGMODDEFERRED)pMod->pvImgPriv);
|
---|
500 | return VINF_SUCCESS;
|
---|
501 | }
|
---|
502 |
|
---|
503 |
|
---|
504 | /** @interface_method_impl{RTDBGMODVTIMG,pfnTryOpen} */
|
---|
505 | static DECLCALLBACK(int) rtDbgModDeferredImg_TryOpen(PRTDBGMODINT pMod)
|
---|
506 | {
|
---|
507 | return rtDbgModDeferredDoIt(pMod, true /*fForceRetry*/);
|
---|
508 | }
|
---|
509 |
|
---|
510 |
|
---|
511 | /** Virtual function table for the RTLdr based image reader. */
|
---|
512 | DECL_HIDDEN_CONST(RTDBGMODVTIMG) const g_rtDbgModVtImgDeferred =
|
---|
513 | {
|
---|
514 | /*.u32Magic = */ RTDBGMODVTIMG_MAGIC,
|
---|
515 | /*.fReserved = */ 0,
|
---|
516 | /*.pszName = */ "deferred",
|
---|
517 | /*.pfnTryOpen = */ rtDbgModDeferredImg_TryOpen,
|
---|
518 | /*.pfnClose = */ rtDbgModDeferredImg_Close,
|
---|
519 | /*.pfnEnumDbgInfo = */ rtDbgModDeferredImg_EnumDbgInfo,
|
---|
520 | /*.pfnEnumSegments = */ rtDbgModDeferredImg_EnumSegments,
|
---|
521 | /*.pfnGetLoadedSize = */ rtDbgModDeferredImg_ImageSize,
|
---|
522 | /*.pfnLinkAddressToSegOffset = */ rtDbgModDeferredImg_LinkAddressToSegOffset,
|
---|
523 | /*.pfnMapPart = */ rtDbgModDeferredImg_MapPart,
|
---|
524 | /*.pfnUnmapPart = */ rtDbgModDeferredImg_UnmapPart,
|
---|
525 |
|
---|
526 | /*.u32EndMagic = */ RTDBGMODVTIMG_MAGIC
|
---|
527 | };
|
---|
528 |
|
---|
529 |
|
---|
530 | /**
|
---|
531 | * Creates a deferred loading stub for both image and debug info.
|
---|
532 | *
|
---|
533 | * @returns IPRT status code.
|
---|
534 | * @param pDbgMod The debug module.
|
---|
535 | * @param pfnDeferred The callback that will try load the image and
|
---|
536 | * debug info.
|
---|
537 | * @param cbImage The size of the image.
|
---|
538 | * @param hDbgCfg The debug config handle. Can be NIL. A
|
---|
539 | * reference will be retained.
|
---|
540 | * @param ppDeferred Where to return the instance data. Can be NULL.
|
---|
541 | */
|
---|
542 | DECLHIDDEN(int) rtDbgModDeferredCreate(PRTDBGMODINT pDbgMod, PFNRTDBGMODDEFERRED pfnDeferred, RTUINTPTR cbImage,
|
---|
543 | RTDBGCFG hDbgCfg, PRTDBGMODDEFERRED *ppDeferred)
|
---|
544 | {
|
---|
545 | AssertReturn(!pDbgMod->pDbgVt, VERR_DBG_MOD_IPE);
|
---|
546 | AssertReturn(!pDbgMod->pImgVt, VERR_DBG_MOD_IPE);
|
---|
547 |
|
---|
548 | PRTDBGMODDEFERRED pDeferred = (PRTDBGMODDEFERRED)RTMemAllocZ(sizeof(*pDeferred));
|
---|
549 | if (!pDeferred)
|
---|
550 | return VERR_NO_MEMORY;
|
---|
551 |
|
---|
552 | pDeferred->cbImage = cbImage;
|
---|
553 | pDeferred->cRefs = 2;
|
---|
554 | if (hDbgCfg != NIL_RTDBGCFG)
|
---|
555 | RTDbgCfgRetain(hDbgCfg);
|
---|
556 | pDeferred->hDbgCfg = hDbgCfg;
|
---|
557 | pDeferred->pfnDeferred = pfnDeferred;
|
---|
558 |
|
---|
559 | pDbgMod->pImgVt = &g_rtDbgModVtImgDeferred;
|
---|
560 | pDbgMod->pvImgPriv = pDeferred;
|
---|
561 | pDbgMod->pDbgVt = &g_rtDbgModVtDbgDeferred;
|
---|
562 | pDbgMod->pvDbgPriv = pDeferred;
|
---|
563 | pDbgMod->fDeferred = true;
|
---|
564 | pDbgMod->fDeferredFailed = false;
|
---|
565 |
|
---|
566 | if (ppDeferred)
|
---|
567 | *ppDeferred = pDeferred;
|
---|
568 | return VINF_SUCCESS;
|
---|
569 | }
|
---|
570 |
|
---|