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 "internal/dbgmod.h"
|
---|
12 |
|
---|
13 |
|
---|
14 | /*******************************************************************************
|
---|
15 | * Structures and Typedefs *
|
---|
16 | *******************************************************************************/
|
---|
17 | /**
|
---|
18 | * Symbol entry.
|
---|
19 | */
|
---|
20 | typedef struct RTDBGMODCONTAINERSYMBOL
|
---|
21 | {
|
---|
22 | /** The address core. */
|
---|
23 | AVLRUINTPTRNODECORE AddrCore;
|
---|
24 | /** The name space core. */
|
---|
25 | RTSTRSPACECORE NameCore;
|
---|
26 | /** The name. */
|
---|
27 | char *pszName;
|
---|
28 | /** The segent offset. */
|
---|
29 | RTUINTPTR off;
|
---|
30 | /** The segment index. */
|
---|
31 | RTDBGSEGIDX iSeg;
|
---|
32 | } RTDBGMODCONTAINERSYMBOL;
|
---|
33 | /** Pointer to a symbol entry in the debug info container. */
|
---|
34 | typedef RTDBGMODCONTAINERSYMBOL *PRTDBGMODCONTAINERSYMBOL;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Segment entry.
|
---|
38 | */
|
---|
39 | typedef struct RTDBGMODCONTAINERSEGMENT
|
---|
40 | {
|
---|
41 | /** The segment offset. */
|
---|
42 | RTUINTPTR off;
|
---|
43 | /** The segment size. */
|
---|
44 | RTUINTPTR cb;
|
---|
45 | /** The segment name. */
|
---|
46 | const char *pszName;
|
---|
47 | } RTDBGMODCONTAINERSEGMENT;
|
---|
48 | /** Pointer to a segment entry in the debug info container. */
|
---|
49 | typedef RTDBGMODCONTAINERSEGMENT *PRTDBGMODCONTAINERSEGMENT;
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Instance data.
|
---|
53 | */
|
---|
54 | typedef struct RTDBGMODCONTAINER
|
---|
55 | {
|
---|
56 | /** The name space. */
|
---|
57 | RTSTRSPACE Names;
|
---|
58 | /** The address space tree. */
|
---|
59 | AVLRUINTPTRTREE AddrTree;
|
---|
60 | /** Segment table. */
|
---|
61 | PRTDBGMODCONTAINERSEGMENT paSegs;
|
---|
62 | /** The number of segments in the segment table. */
|
---|
63 | RTDBGSEGIDX cSegs;
|
---|
64 | /** The image size. 0 means unlimited. */
|
---|
65 | RTUINTPTR cb;
|
---|
66 | } RTDBGMODCONTAINER;
|
---|
67 | /** Pointer to instance data for the debug info container. */
|
---|
68 | typedef RTDBGMODCONTAINER *PRTDBGMODCONTAINER;
|
---|
69 |
|
---|
70 |
|
---|
71 |
|
---|
72 | /** @copydoc RTDBGMODVTDBG::pfnLineByAddr */
|
---|
73 | static DECLCALLBACK(int) rtDbgModContainer_LineByAddr(PRTDBGMODINT pMod, uint32_t iSeg, RTGCUINTPTR off, PRTGCINTPTR poffDisp, PRTDBGLINE pLine)
|
---|
74 | {
|
---|
75 | return VINF_SUCCESS;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | /** @copydoc RTDBGMODVTDBG::pfnSymbolByAddr */
|
---|
80 | static DECLCALLBACK(int) rtDbgModContainer_SymbolByAddr(PRTDBGMODINT pMod, uint32_t iSeg, RTGCUINTPTR off, PRTGCINTPTR poffDisp, PRTDBGSYMBOL pSymbol)
|
---|
81 | {
|
---|
82 | return VINF_SUCCESS;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | /** @copydoc RTDBGMODVTDBG::pfnSymbolByName */
|
---|
87 | static DECLCALLBACK(int) rtDbgModContainer_SymbolByName(PRTDBGMODINT pMod, const char *pszSymbol, PRTDBGSYMBOL pSymbol)
|
---|
88 | {
|
---|
89 | return VINF_SUCCESS;
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | /** @copydoc RTDBGMODVTDBG::pfnSymbolAdd */
|
---|
94 | static DECLCALLBACK(int) rtDbgModContainer_SymbolAdd(PRTDBGMODINT pMod, const char *pszSymbol, uint32_t iSeg, RTGCUINTPTR off, RTUINT cbSymbol)
|
---|
95 | {
|
---|
96 | return VINF_SUCCESS;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | /** Destroy a symbol node. */
|
---|
101 | static DECLCALLBACK(int) rtDbgModContainer_DestroyTreeNode(PAVLRUINTPTRNODECORE pNode, void *pvUser)
|
---|
102 | {
|
---|
103 | PRTDBGMODCONTAINERSYMBOL pSym = RT_FROM_MEMBER(pNode, RTDBGMODCONTAINERSYMBOL, AddrCore);
|
---|
104 | RTStrFree(pSym->pszName);
|
---|
105 | RTMemFree(pSym);
|
---|
106 | return 0;
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | /** @copydoc RTDBGMODVTDBG::pfnClose */
|
---|
111 | static DECLCALLBACK(int) rtDbgModContainer_Close(PRTDBGMODINT pMod)
|
---|
112 | {
|
---|
113 | PRTDBGMODCONTAINER pThis = (PRTDBGMODCONTAINER)pMod->pvDbgPriv;
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * Destroy the symbols and instance data.
|
---|
117 | */
|
---|
118 | RTAvlrUIntPtrDestroy(&pThis->AddrTree, rtDbgModContainer_DestroyTreeNode, NULL);
|
---|
119 | pThis->Names = NULL;
|
---|
120 | RTMemFree(pThis->paSegs);
|
---|
121 | pThis->paSegs = NULL;
|
---|
122 | RTMemFree(pThis);
|
---|
123 |
|
---|
124 | return VINF_SUCCESS;
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|
128 | /** @copydoc RTDBGMODVTDBG::pfnTryOpen */
|
---|
129 | static DECLCALLBACK(int) rtDbgModContainer_TryOpen(PRTDBGMODINT pMod)
|
---|
130 | {
|
---|
131 | return VERR_INTERNAL_ERROR_5;
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 |
|
---|
136 | /** Virtual function table for the debug info container. */
|
---|
137 | static RTDBGMODVTDBG const g_rtDbgModVtDbgContainer =
|
---|
138 | {
|
---|
139 | /*.u32Magic = */ RTDBGMODVTDBG_MAGIC,
|
---|
140 | /*.fSupports = */ 0, ///@todo iprt/types.h isn't up to date...
|
---|
141 | /*.pszName = */ "container",
|
---|
142 | /*.pfnTryOpen = */ rtDbgModContainer_TryOpen,
|
---|
143 | /*.pfnClose = */ rtDbgModContainer_Close,
|
---|
144 | /*.pfnSymbolAdd = */ rtDbgModContainer_SymbolAdd,
|
---|
145 | /*.pfnSymbolByName = */ rtDbgModContainer_SymbolByName,
|
---|
146 | /*.pfnSymbolByAddr = */ rtDbgModContainer_SymbolByAddr,
|
---|
147 | /*.pfnLineByAddr = */ rtDbgModContainer_LineByAddr,
|
---|
148 | /*.u32EndMagic = */ RTDBGMODVTDBG_MAGIC
|
---|
149 | };
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Creates a generic debug info container and associates it with the module.
|
---|
155 | *
|
---|
156 | * @returns IPRT status code.
|
---|
157 | * @param pMod The module instance.
|
---|
158 | * @param cb The module size.
|
---|
159 | */
|
---|
160 | int rtDbgModContainerCreate(PRTDBGMODINT pMod, RTUINTPTR cb)
|
---|
161 | {
|
---|
162 | PRTDBGMODCONTAINER pThis = (PRTDBGMODCONTAINER)RTMemAlloc(sizeof(*pThis));
|
---|
163 | if (!pThis)
|
---|
164 | return VERR_NO_MEMORY;
|
---|
165 |
|
---|
166 | pThis->Names = NULL;
|
---|
167 | pThis->AddrTree = NULL;
|
---|
168 | pThis->paSegs = NULL;
|
---|
169 | pThis->cSegs = 0;
|
---|
170 | pThis->cb = cb;
|
---|
171 |
|
---|
172 | pMod->pDbgVt = &g_rtDbgModVtDbgContainer;
|
---|
173 | pMod->pvDbgPriv = pThis;
|
---|
174 | return VINF_SUCCESS;
|
---|
175 | }
|
---|
176 |
|
---|