VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/dbg/dbgmoddwarf.cpp@ 38515

Last change on this file since 38515 was 38515, checked in by vboxsync, 14 years ago

IPRT: Working on debug info again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 KB
Line 
1/* $Id: dbgmoddwarf.cpp 38515 2011-08-24 14:33:32Z vboxsync $ */
2/** @file
3 * IPRT - Debug Info Reader For DWARF.
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.215389.xyz. 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/err.h>
35#include <iprt/ctype.h>
36#include <iprt/mem.h>
37#include <iprt/stream.h>
38#include <iprt/string.h>
39#include "internal/dbgmod.h"
40
41
42/*******************************************************************************
43* Structures and Typedefs *
44*******************************************************************************/
45/**
46 * The instance data of the DWARF reader.
47 */
48typedef struct RTDBGMODDWARF
49{
50 /** Pointer to back to the debug info module. */
51 PRTDBGMODINT pMod;
52 /** The number of DWARF sections in the image. */
53 uint32_t cSections;
54
55 /** Total line number count. */
56 uint32_t cLines;
57 /** Total symbol count. */
58 uint32_t cSymbols;
59} RTDBGMODDWARF;
60/** Pointer to instance data of the DWARF reader. */
61typedef RTDBGMODDWARF *PRTDBGMODDWARF;
62
63
64
65/** @interface_method_impl{RTDBGMODVTDBG,pfnLineByAddr} */
66static DECLCALLBACK(int) rtDbgModDwarf_LineByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
67 PRTINTPTR poffDisp, PRTDBGLINE pLineInfo)
68{
69 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
70 return VERR_DBG_NO_LINE_NUMBERS;
71}
72
73
74/** @interface_method_impl{RTDBGMODVTDBG,pfnLineByOrdinal} */
75static DECLCALLBACK(int) rtDbgModDwarf_LineByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo)
76{
77 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
78 return VERR_DBG_NO_LINE_NUMBERS;
79}
80
81
82/** @interface_method_impl{RTDBGMODVTDBG,pfnLineCount} */
83static DECLCALLBACK(uint32_t) rtDbgModDwarf_LineCount(PRTDBGMODINT pMod)
84{
85 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
86 return pThis->cLines;
87}
88
89
90/** @interface_method_impl{RTDBGMODVTDBG,pfnLineAdd} */
91static DECLCALLBACK(int) rtDbgModDwarf_LineAdd(PRTDBGMODINT pMod, const char *pszFile, size_t cchFile, uint32_t uLineNo,
92 uint32_t iSeg, RTUINTPTR off, uint32_t *piOrdinal)
93{
94 return VERR_NOT_SUPPORTED;
95}
96
97
98/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByAddr} */
99static DECLCALLBACK(int) rtDbgModDwarf_SymbolByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off,
100 PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo)
101{
102 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
103 return VERR_DBG_NO_SYMBOLS;
104}
105
106
107/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByName} */
108static DECLCALLBACK(int) rtDbgModDwarf_SymbolByName(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
109 PRTDBGSYMBOL pSymInfo)
110{
111 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
112 return VERR_DBG_NO_SYMBOLS;
113}
114
115
116/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolByOrdinal} */
117static DECLCALLBACK(int) rtDbgModDwarf_SymbolByOrdinal(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo)
118{
119 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
120 return VERR_DBG_NO_SYMBOLS;
121}
122
123
124/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolCount} */
125static DECLCALLBACK(uint32_t) rtDbgModDwarf_SymbolCount(PRTDBGMODINT pMod)
126{
127 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
128 return pThis->cSymbols;
129}
130
131
132/** @interface_method_impl{RTDBGMODVTDBG,pfnSymbolAdd} */
133static DECLCALLBACK(int) rtDbgModDwarf_SymbolAdd(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
134 RTDBGSEGIDX iSeg, RTUINTPTR off, RTUINTPTR cb, uint32_t fFlags,
135 uint32_t *piOrdinal)
136{
137 return VERR_NOT_SUPPORTED;
138}
139
140
141/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentByIndex} */
142static DECLCALLBACK(int) rtDbgModDwarf_SegmentByIndex(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo)
143{
144 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
145 return VERR_DBG_INVALID_SEGMENT_INDEX;
146}
147
148
149/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentCount} */
150static DECLCALLBACK(RTDBGSEGIDX) rtDbgModDwarf_SegmentCount(PRTDBGMODINT pMod)
151{
152 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
153 return 0; /** @todo defer to image reader if present? */
154}
155
156
157/** @interface_method_impl{RTDBGMODVTDBG,pfnSegmentAdd} */
158static DECLCALLBACK(int) rtDbgModDwarf_SegmentAdd(PRTDBGMODINT pMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName, size_t cchName,
159 uint32_t fFlags, PRTDBGSEGIDX piSeg)
160{
161 return VERR_NOT_SUPPORTED;
162}
163
164
165/** @interface_method_impl{RTDBGMODVTDBG,pfnImageSize} */
166static DECLCALLBACK(RTUINTPTR) rtDbgModDwarf_ImageSize(PRTDBGMODINT pMod)
167{
168 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
169 return 0; /** @todo defer to image reader if present? */
170}
171
172
173/** @interface_method_impl{RTDBGMODVTDBG,pfnRvaToSegOff} */
174static DECLCALLBACK(RTDBGSEGIDX) rtDbgModDwarf_RvaToSegOff(PRTDBGMODINT pMod, RTUINTPTR uRva, PRTUINTPTR poffSeg)
175{
176 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
177 /** @todo defer to image reader if present? */
178 *poffSeg = uRva;
179 return 0;
180}
181
182
183/** @interface_method_impl{RTDBGMODVTDBG,pfnClose} */
184static DECLCALLBACK(int) rtDbgModDwarf_Close(PRTDBGMODINT pMod)
185{
186 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pMod->pvDbgPriv;
187 RTMemFree(pThis);
188 return VINF_SUCCESS;
189}
190
191
192/** @callback_method_impl{FNRTLDRENUMDBG} */
193static DECLCALLBACK(int) rtDbgModDwarf_EnumCallback(RTLDRMOD hLdrMod, uint32_t iDbgInfo, RTLDRDBGINFOTYPE enmType,
194 uint16_t iMajorVer, uint16_t iMinorVer, const char *pszPartNm,
195 RTFOFF offFile, RTUINTPTR LinkAddress, RTUINTPTR cb,
196 const char *pszExtFile, void *pvUser)
197{
198 /*
199 * Skip stuff we can't handle.
200 */
201 if ( enmType != RTLDRDBGINFOTYPE_DWARF
202 || !pszPartNm
203 || pszExtFile)
204 return VINF_SUCCESS;
205
206 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)pvUser;
207 pThis->cSections++;
208 /** @todo detect what and record it */
209 return VINF_SUCCESS;
210}
211
212
213/** @interface_method_impl{RTDBGMODVTDBG,pfnTryOpen} */
214static DECLCALLBACK(int) rtDbgModDwarf_TryOpen(PRTDBGMODINT pMod)
215{
216 /*
217 * DWARF is only supported when part of an image.
218 */
219 if (!pMod->pImgVt)
220 return VERR_DBG_NO_MATCHING_INTERPRETER;
221
222 /*
223 * Enumeate the debug info in the module, looking for DWARF bits.
224 */
225 PRTDBGMODDWARF pThis = (PRTDBGMODDWARF)RTMemAllocZ(sizeof(*pThis));
226 if (!pThis)
227 return VERR_NO_MEMORY;
228 pThis->pMod = pMod;
229
230 int rc = pMod->pImgVt->pfnEnumDbgInfo(pMod, rtDbgModDwarf_EnumCallback, pThis);
231 if (RT_SUCCESS(rc))
232 {
233 if (pThis->cSections)
234 {
235 pMod->pvDbgPriv = pThis;
236 return VINF_SUCCESS;
237 }
238
239 /* Didn't find any DWARF info, bail out. */
240 rc = VERR_DBG_NO_MATCHING_INTERPRETER;
241 }
242 RTMemFree(pThis);
243
244 return rc;
245}
246
247
248
249/** Virtual function table for the DWARF debug info reader. */
250DECL_HIDDEN_CONST(RTDBGMODVTDBG) const g_rtDbgModVtDbgDwarf =
251{
252 /*.u32Magic = */ RTDBGMODVTDBG_MAGIC,
253 /*.fSupports = */ RT_DBGTYPE_DWARF,
254 /*.pszName = */ "dwarf",
255 /*.pfnTryOpen = */ rtDbgModDwarf_TryOpen,
256 /*.pfnClose = */ rtDbgModDwarf_Close,
257
258 /*.pfnRvaToSegOff = */ rtDbgModDwarf_RvaToSegOff,
259 /*.pfnImageSize = */ rtDbgModDwarf_ImageSize,
260
261 /*.pfnSegmentAdd = */ rtDbgModDwarf_SegmentAdd,
262 /*.pfnSegmentCount = */ rtDbgModDwarf_SegmentCount,
263 /*.pfnSegmentByIndex = */ rtDbgModDwarf_SegmentByIndex,
264
265 /*.pfnSymbolAdd = */ rtDbgModDwarf_SymbolAdd,
266 /*.pfnSymbolCount = */ rtDbgModDwarf_SymbolCount,
267 /*.pfnSymbolByOrdinal = */ rtDbgModDwarf_SymbolByOrdinal,
268 /*.pfnSymbolByName = */ rtDbgModDwarf_SymbolByName,
269 /*.pfnSymbolByAddr = */ rtDbgModDwarf_SymbolByAddr,
270
271 /*.pfnLineAdd = */ rtDbgModDwarf_LineAdd,
272 /*.pfnLineCount = */ rtDbgModDwarf_LineCount,
273 /*.pfnLineByOrdinal = */ rtDbgModDwarf_LineByOrdinal,
274 /*.pfnLineByAddr = */ rtDbgModDwarf_LineByAddr,
275
276 /*.u32EndMagic = */ RTDBGMODVTDBG_MAGIC
277};
278
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