VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/dbg/dbgmodcontainer.cpp@ 20739

Last change on this file since 20739 was 20739, checked in by vboxsync, 15 years ago

iprt: RTDbgMod coding in progress.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1
2/*******************************************************************************
3* Header Files *
4*******************************************************************************/
5#include <iprt/dbg.h>
6
7#include <iprt/avl.h>
8#include <iprt/err.h>
9#include <iprt/mem.h>
10#include <iprt/string.h>
11#include <iprt/strcache.h>
12#include "internal/dbgmod.h"
13
14
15/*******************************************************************************
16* Structures and Typedefs *
17*******************************************************************************/
18/**
19 * Symbol entry.
20 */
21typedef struct RTDBGMODCONTAINERSYMBOL
22{
23 /** The address core. */
24 AVLRUINTPTRNODECORE AddrCore;
25 /** The name space core. */
26 RTSTRSPACECORE NameCore;
27 /** The segent offset. */
28 RTUINTPTR off;
29 /** The segment index. */
30 RTDBGSEGIDX iSeg;
31} RTDBGMODCONTAINERSYMBOL;
32/** Pointer to a symbol entry in the debug info container. */
33typedef RTDBGMODCONTAINERSYMBOL *PRTDBGMODCONTAINERSYMBOL;
34
35/**
36 * Segment entry.
37 */
38typedef struct RTDBGMODCONTAINERSEGMENT
39{
40 /** The segment offset. */
41 RTUINTPTR off;
42 /** The segment size. */
43 RTUINTPTR cb;
44 /** The segment name. */
45 const char *pszName;
46} RTDBGMODCONTAINERSEGMENT;
47/** Pointer to a segment entry in the debug info container. */
48typedef RTDBGMODCONTAINERSEGMENT *PRTDBGMODCONTAINERSEGMENT;
49
50/**
51 * Instance data.
52 */
53typedef struct RTDBGMODCONTAINER
54{
55 /** The name space. */
56 RTSTRSPACE Names;
57 /** The address space tree. */
58 AVLRUINTPTRTREE Addresses;
59 /** Segment table. */
60 PRTDBGMODCONTAINERSEGMENT paSegs;
61 /** The number of segments in the segment table. */
62 RTDBGSEGIDX cSegs;
63 /** The image size. 0 means unlimited. */
64 RTUINTPTR cb;
65} RTDBGMODCONTAINER;
66/** Pointer to instance data for the debug info container. */
67typedef RTDBGMODCONTAINER *PRTDBGMODCONTAINER;
68
69
70
71/** @copydoc RTDBGMODVTDBG::pfnLineByAddr */
72static DECLCALLBACK(int) rtDbgModContainer_LineByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTGCUINTPTR off, PRTGCINTPTR poffDisp, PRTDBGLINE pLine)
73{
74 /** @todo Make it possible to add line numbers. */
75 return VERR_DBG_NO_LINE_NUMBERS;
76}
77
78
79/** @copydoc RTDBGMODVTDBG::pfnSymbolByAddr */
80static DECLCALLBACK(int) rtDbgModContainer_SymbolByAddr(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTGCUINTPTR off, PRTGCINTPTR poffDisp, PRTDBGSYMBOL pSymbol)
81{
82 return VINF_SUCCESS;
83}
84
85
86/** @copydoc RTDBGMODVTDBG::pfnSymbolByName */
87static DECLCALLBACK(int) rtDbgModContainer_SymbolByName(PRTDBGMODINT pMod, const char *pszSymbol, PRTDBGSYMBOL pSymbol)
88{
89 return VINF_SUCCESS;
90}
91
92
93/** @copydoc RTDBGMODVTDBG::pfnSymbolAdd */
94static DECLCALLBACK(int) rtDbgModContainer_SymbolAdd(PRTDBGMODINT pMod, const char *pszSymbol, RTDBGSEGIDX iSeg, RTGCUINTPTR off, uint32_t cbSymbol)
95{
96 PRTDBGMODCONTAINER pThis = (PRTDBGMODCONTAINER)pMod->pvDbgPriv;
97
98 /*
99 * Address validation. The other arguments have already been validated.
100 */
101 AssertMsgReturn( ( iSeg >= RTDBGSEGIDX_SPECIAL_FIRST
102 && iSeg <= RTDBGSEGIDX_SPECIAL_LAST)
103 || iSeg < pThis->cSegs,
104 ("iSeg=%x cSegs=%x\n", pThis->cSegs),
105 VERR_DBG_INVALID_SEGMENT_INDEX);
106 AssertMsgReturn( iSeg >= RTDBGSEGIDX_SPECIAL_FIRST
107 || pThis->paSegs[iSeg].cb <= off + cbSymbol,
108 ("off=%RTptr cbSymbol=%RTptr cbSeg=%RTptr\n", off, cbSymbol, pThis->paSegs[iSeg].cb),
109 VERR_DBG_INVALID_SEGMENT_OFFSET);
110
111 /*
112 * Create a new entry.
113 */
114 PRTDBGMODCONTAINERSYMBOL pSymbol = (PRTDBGMODCONTAINERSYMBOL)RTMemAllocZ(sizeof(*pSymbol));
115 if (!pSymbol)
116 return VERR_NO_MEMORY;
117
118#if 0 /* continue on the workstation */
119 pSymbol->AddrCore.Key = iSeg < RTDBGSEGIDX_SPECIAL_FIRST
120 ? pThis->paSegs->off + off
121 : off;
122 pSymbol->AddrCore.KeyLast = pSymbol->AddrCore.Key + cbSymbol;
123 pSymbol->off = off;
124 pSymbol->iSeg = iSeg;
125 pSymbol->NameCore.pszString = RTStrCacheEnter(g_hDbgModStrCache, pszSymbol);
126 if (pSymbol->NameCore.pszString)
127 {
128 if (RTStrSpaceInsert(&pThis->Names, &pSymbol->NameCore))
129 {
130 if (RTStrSpaceInsert(&pThis->Names, &pSymbol->NameCore))
131 {
132
133 }
134 }
135 }
136#endif
137int rc = VERR_NOT_IMPLEMENTED;
138
139 return rc;
140}
141
142
143/** Destroy a symbol node. */
144static DECLCALLBACK(int) rtDbgModContainer_DestroyTreeNode(PAVLRUINTPTRNODECORE pNode, void *pvUser)
145{
146 PRTDBGMODCONTAINERSYMBOL pSym = RT_FROM_MEMBER(pNode, RTDBGMODCONTAINERSYMBOL, AddrCore);
147 RTStrCacheRelease(g_hDbgModStrCache, pSym->NameCore.pszString);
148 RTMemFree(pSym);
149 return 0;
150}
151
152
153/** @copydoc RTDBGMODVTDBG::pfnClose */
154static DECLCALLBACK(int) rtDbgModContainer_Close(PRTDBGMODINT pMod)
155{
156 PRTDBGMODCONTAINER pThis = (PRTDBGMODCONTAINER)pMod->pvDbgPriv;
157
158 /*
159 * Destroy the symbols and instance data.
160 */
161 RTAvlrUIntPtrDestroy(&pThis->Addresses, rtDbgModContainer_DestroyTreeNode, NULL);
162 pThis->Names = NULL;
163 RTMemFree(pThis->paSegs);
164 pThis->paSegs = NULL;
165 RTMemFree(pThis);
166
167 return VINF_SUCCESS;
168}
169
170
171/** @copydoc RTDBGMODVTDBG::pfnTryOpen */
172static DECLCALLBACK(int) rtDbgModContainer_TryOpen(PRTDBGMODINT pMod)
173{
174 return VERR_INTERNAL_ERROR_5;
175}
176
177
178
179/** Virtual function table for the debug info container. */
180static RTDBGMODVTDBG const g_rtDbgModVtDbgContainer =
181{
182 /*.u32Magic = */ RTDBGMODVTDBG_MAGIC,
183 /*.fSupports = */ 0, ///@todo iprt/types.h isn't up to date...
184 /*.pszName = */ "container",
185 /*.pfnTryOpen = */ rtDbgModContainer_TryOpen,
186 /*.pfnClose = */ rtDbgModContainer_Close,
187 /*.pfnSymbolAdd = */ rtDbgModContainer_SymbolAdd,
188 /*.pfnSymbolByName = */ rtDbgModContainer_SymbolByName,
189 /*.pfnSymbolByAddr = */ rtDbgModContainer_SymbolByAddr,
190 /*.pfnLineByAddr = */ rtDbgModContainer_LineByAddr,
191 /*.u32EndMagic = */ RTDBGMODVTDBG_MAGIC
192};
193
194
195
196/**
197 * Creates a generic debug info container and associates it with the module.
198 *
199 * @returns IPRT status code.
200 * @param pMod The module instance.
201 * @param cb The module size.
202 */
203int rtDbgModContainerCreate(PRTDBGMODINT pMod, RTUINTPTR cb)
204{
205 PRTDBGMODCONTAINER pThis = (PRTDBGMODCONTAINER)RTMemAlloc(sizeof(*pThis));
206 if (!pThis)
207 return VERR_NO_MEMORY;
208
209 pThis->Names = NULL;
210 pThis->Addresses = NULL;
211 pThis->paSegs = NULL;
212 pThis->cSegs = 0;
213 pThis->cb = cb;
214
215 pMod->pDbgVt = &g_rtDbgModVtDbgContainer;
216 pMod->pvDbgPriv = pThis;
217 return VINF_SUCCESS;
218}
219
Note: See TracBrowser for help on using the repository browser.

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