VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/dbg/dbgmodldr.cpp@ 46109

Last change on this file since 46109 was 46083, checked in by vboxsync, 12 years ago

Made it possible to find symbols for windows nt using a image-in-guest-memory loader fallback.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: dbgmodldr.cpp 46083 2013-05-14 23:39:28Z vboxsync $ */
2/** @file
3 * IPRT - Debug Module Image Interpretation by RTLdr.
4 */
5
6/*
7 * Copyright (C) 2011 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/assert.h>
35#include <iprt/err.h>
36#include <iprt/file.h>
37#include <iprt/ldr.h>
38#include <iprt/mem.h>
39#include <iprt/param.h>
40#include <iprt/path.h>
41#include <iprt/string.h>
42#include "internal/dbgmod.h"
43#include "internal/ldr.h"
44#include "internal/magics.h"
45
46
47/*******************************************************************************
48* Structures and Typedefs *
49*******************************************************************************/
50/**
51 * The instance data of the RTLdr based image reader.
52 */
53typedef struct RTDBGMODLDR
54{
55 /** The loader handle. */
56 RTLDRMOD hLdrMod;
57} RTDBGMODLDR;
58/** Pointer to instance data NM map reader. */
59typedef RTDBGMODLDR *PRTDBGMODLDR;
60
61
62/** @interface_method_impl{RTDBGMODVTIMG,pfnUnmapPart} */
63static DECLCALLBACK(int) rtDbgModLdr_UnmapPart(PRTDBGMODINT pMod, size_t cb, void const **ppvMap)
64{
65 NOREF(pMod); NOREF(cb);
66 RTMemFree((void *)*ppvMap);
67 *ppvMap = NULL;
68 return VINF_SUCCESS;
69}
70
71
72/** @interface_method_impl{RTDBGMODVTIMG,pfnMapPart} */
73static DECLCALLBACK(int) rtDbgModLdr_MapPart(PRTDBGMODINT pMod, RTFOFF off, size_t cb, void const **ppvMap)
74{
75 PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv;
76
77 void *pvMap = RTMemAlloc(cb);
78 if (!pvMap)
79 return VERR_NO_MEMORY;
80
81 int rc = rtLdrReadAt(pThis->hLdrMod, pvMap, off, cb);
82 if (RT_SUCCESS(rc))
83 *ppvMap = pvMap;
84 else
85 {
86 RTMemFree(pvMap);
87 *ppvMap = NULL;
88 }
89 return rc;
90}
91
92
93/** @interface_method_impl{RTDBGMODVTIMG,pfnGetLoadedSize} */
94static DECLCALLBACK(RTUINTPTR) rtDbgModLdr_GetLoadedSize(PRTDBGMODINT pMod)
95{
96 PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv;
97 return RTLdrSize(pThis->hLdrMod);
98}
99
100
101/** @interface_method_impl{RTDBGMODVTIMG,pfnLinkAddressToSegOffset} */
102static DECLCALLBACK(int) rtDbgModLdr_LinkAddressToSegOffset(PRTDBGMODINT pMod, RTLDRADDR LinkAddress,
103 PRTDBGSEGIDX piSeg, PRTLDRADDR poffSeg)
104{
105 PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv;
106 return RTLdrLinkAddressToSegOffset(pThis->hLdrMod, LinkAddress, piSeg, poffSeg);
107}
108
109
110/** @interface_method_impl{RTDBGMODVTIMG,pfnEnumSegments} */
111static DECLCALLBACK(int) rtDbgModLdr_EnumSegments(PRTDBGMODINT pMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser)
112{
113 PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv;
114 return RTLdrEnumSegments(pThis->hLdrMod, pfnCallback, pvUser);
115}
116
117
118/** @interface_method_impl{RTDBGMODVTIMG,pfnEnumDbgInfo} */
119static DECLCALLBACK(int) rtDbgModLdr_EnumDbgInfo(PRTDBGMODINT pMod, PFNRTLDRENUMDBG pfnCallback, void *pvUser)
120{
121 PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv;
122 return RTLdrEnumDbgInfo(pThis->hLdrMod, NULL, pfnCallback, pvUser);
123}
124
125
126/** @interface_method_impl{RTDBGMODVTIMG,pfnClose} */
127static DECLCALLBACK(int) rtDbgModLdr_Close(PRTDBGMODINT pMod)
128{
129 PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv;
130 AssertPtr(pThis);
131
132 int rc = RTLdrClose(pThis->hLdrMod); AssertRC(rc);
133 pThis->hLdrMod = NIL_RTLDRMOD;
134
135 RTMemFree(pThis);
136
137 return VINF_SUCCESS;
138}
139
140
141/** @interface_method_impl{RTDBGMODVTIMG,pfnTryOpen} */
142static DECLCALLBACK(int) rtDbgModLdr_TryOpen(PRTDBGMODINT pMod)
143{
144 RTLDRMOD hLdrMod;
145 int rc = RTLdrOpen(pMod->pszImgFile, RTLDR_O_FOR_DEBUG, RTLDRARCH_WHATEVER, &hLdrMod);
146 if (RT_SUCCESS(rc))
147 {
148 rc = rtDbgModLdrOpenFromHandle(pMod, hLdrMod);
149 if (RT_FAILURE(rc))
150 RTLdrClose(hLdrMod);
151 }
152 return rc;
153}
154
155
156/** Virtual function table for the RTLdr based image reader. */
157DECL_HIDDEN_CONST(RTDBGMODVTIMG) const g_rtDbgModVtImgLdr =
158{
159 /*.u32Magic = */ RTDBGMODVTIMG_MAGIC,
160 /*.fReserved = */ 0,
161 /*.pszName = */ "RTLdr",
162 /*.pfnTryOpen = */ rtDbgModLdr_TryOpen,
163 /*.pfnClose = */ rtDbgModLdr_Close,
164 /*.pfnEnumDbgInfo = */ rtDbgModLdr_EnumDbgInfo,
165 /*.pfnEnumSegments = */ rtDbgModLdr_EnumSegments,
166 /*.pfnGetLoadedSize = */ rtDbgModLdr_GetLoadedSize,
167 /*.pfnLinkAddressToSegOffset = */ rtDbgModLdr_LinkAddressToSegOffset,
168 /*.pfnMapPart = */ rtDbgModLdr_MapPart,
169 /*.pfnUnmapPart = */ rtDbgModLdr_UnmapPart,
170
171 /*.u32EndMagic = */ RTDBGMODVTIMG_MAGIC
172};
173
174
175/**
176 * Open PE-image trick.
177 *
178 * @returns IPRT status code
179 * @param pDbgMod The debug module instance.
180 * @param hLdrMod The module to open a image debug backend for.
181 */
182DECLHIDDEN(int) rtDbgModLdrOpenFromHandle(PRTDBGMODINT pDbgMod, RTLDRMOD hLdrMod)
183{
184 PRTDBGMODLDR pThis = (PRTDBGMODLDR)RTMemAllocZ(sizeof(RTDBGMODLDR));
185 if (!pThis)
186 return VERR_NO_MEMORY;
187
188 pThis->hLdrMod = hLdrMod;
189 pDbgMod->pvImgPriv = pThis;
190 return VINF_SUCCESS;
191}
192
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette