1 | /* $Id: dbgmod.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Internal Header for RTDbgMod and the associated interpreters.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef IPRT_INCLUDED_INTERNAL_dbgmod_h
|
---|
38 | #define IPRT_INCLUDED_INTERNAL_dbgmod_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <iprt/types.h>
|
---|
44 | #include <iprt/critsect.h>
|
---|
45 | #include <iprt/ldr.h> /* for PFNRTLDRENUMDBG */
|
---|
46 | #include "internal/magics.h"
|
---|
47 |
|
---|
48 | RT_C_DECLS_BEGIN
|
---|
49 |
|
---|
50 | /** @addtogroup grp_rt_dbgmod
|
---|
51 | * @internal
|
---|
52 | * @{
|
---|
53 | */
|
---|
54 |
|
---|
55 |
|
---|
56 | /** Pointer to the internal module structure. */
|
---|
57 | typedef struct RTDBGMODINT *PRTDBGMODINT;
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Virtual method table for executable image interpreters.
|
---|
61 | */
|
---|
62 | typedef struct RTDBGMODVTIMG
|
---|
63 | {
|
---|
64 | /** Magic number (RTDBGMODVTIMG_MAGIC). */
|
---|
65 | uint32_t u32Magic;
|
---|
66 | /** Reserved. */
|
---|
67 | uint32_t fReserved;
|
---|
68 | /** The name of the interpreter. */
|
---|
69 | const char *pszName;
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Try open the image.
|
---|
73 | *
|
---|
74 | * This combines probing and opening.
|
---|
75 | *
|
---|
76 | * @returns IPRT status code. No informational returns defined.
|
---|
77 | *
|
---|
78 | * @param pMod Pointer to the module that is being opened.
|
---|
79 | *
|
---|
80 | * The RTDBGMOD::pszDbgFile member will point to
|
---|
81 | * the filename of any debug info we're aware of
|
---|
82 | * on input. Also, or alternatively, it is expected
|
---|
83 | * that the interpreter will look for debug info in
|
---|
84 | * the executable image file when present and that it
|
---|
85 | * may ask the image interpreter for this when it's
|
---|
86 | * around.
|
---|
87 | *
|
---|
88 | * Upon successful return the method is expected to
|
---|
89 | * initialize pImgOps and pvImgPriv.
|
---|
90 | * @param enmArch The desired architecture.
|
---|
91 | * @param fLdrFlags Extra loader flags (RTLDR_O_XXX).
|
---|
92 | */
|
---|
93 | DECLCALLBACKMEMBER(int, pfnTryOpen,(PRTDBGMODINT pMod, RTLDRARCH enmArch, uint32_t fLdrFlags));
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Close the interpreter, freeing all associated resources.
|
---|
97 | *
|
---|
98 | * The caller sets the pDbgOps and pvDbgPriv RTDBGMOD members
|
---|
99 | * to NULL upon return.
|
---|
100 | *
|
---|
101 | * @param pMod Pointer to the module structure.
|
---|
102 | */
|
---|
103 | DECLCALLBACKMEMBER(int, pfnClose,(PRTDBGMODINT pMod));
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Enumerate the debug info contained in the executable image.
|
---|
107 | *
|
---|
108 | * Identical to RTLdrEnumDbgInfo.
|
---|
109 | *
|
---|
110 | * @returns IPRT status code or whatever pfnCallback returns.
|
---|
111 | *
|
---|
112 | * @param pMod Pointer to the module structure.
|
---|
113 | * @param pfnCallback The callback function. Ignore the module
|
---|
114 | * handle argument!
|
---|
115 | * @param pvUser The user argument.
|
---|
116 | */
|
---|
117 | DECLCALLBACKMEMBER(int, pfnEnumDbgInfo,(PRTDBGMODINT pMod, PFNRTLDRENUMDBG pfnCallback, void *pvUser));
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Enumerate the segments in the executable image.
|
---|
121 | *
|
---|
122 | * Identical to RTLdrEnumSegments.
|
---|
123 | *
|
---|
124 | * @returns IPRT status code or whatever pfnCallback returns.
|
---|
125 | *
|
---|
126 | * @param pMod Pointer to the module structure.
|
---|
127 | * @param pfnCallback The callback function. Ignore the module
|
---|
128 | * handle argument!
|
---|
129 | * @param pvUser The user argument.
|
---|
130 | */
|
---|
131 | DECLCALLBACKMEMBER(int, pfnEnumSegments,(PRTDBGMODINT pMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser));
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Enumerates the symbols exported by the module.
|
---|
135 | *
|
---|
136 | * @returns iprt status code, which might have been returned by pfnCallback.
|
---|
137 | * @param pMod Pointer to the module structure.
|
---|
138 | * @param fFlags Flags indicating what to return and such.
|
---|
139 | * @param BaseAddress The image base addressto use when calculating the
|
---|
140 | * symbol values.
|
---|
141 | * @param pfnCallback The callback function which each symbol is to be fed
|
---|
142 | * to.
|
---|
143 | * @param pvUser User argument to pass to the enumerator.
|
---|
144 | */
|
---|
145 | DECLCALLBACKMEMBER(int, pfnEnumSymbols,(PRTDBGMODINT pMod, uint32_t fFlags, RTLDRADDR BaseAddress,
|
---|
146 | PFNRTLDRENUMSYMS pfnCallback, void *pvUser));
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Gets the size of the loaded image.
|
---|
150 | *
|
---|
151 | * Identical to RTLdrSize.
|
---|
152 | *
|
---|
153 | * @returns The size in bytes, RTUINTPTR_MAX on failure.
|
---|
154 | *
|
---|
155 | * @param pMod Pointer to the module structure.
|
---|
156 | */
|
---|
157 | DECLCALLBACKMEMBER(RTUINTPTR, pfnImageSize,(PRTDBGMODINT pMod));
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * Converts a link address to a segment:offset address (RVA included).
|
---|
161 | *
|
---|
162 | * @returns IPRT status code.
|
---|
163 | *
|
---|
164 | * @param pMod Pointer to the module structure.
|
---|
165 | * @param LinkAddress The link address to convert.
|
---|
166 | * @param piSeg The segment index.
|
---|
167 | * @param poffSeg Where to return the segment offset.
|
---|
168 | */
|
---|
169 | DECLCALLBACKMEMBER(int, pfnLinkAddressToSegOffset,(PRTDBGMODINT pMod, RTLDRADDR LinkAddress,
|
---|
170 | PRTDBGSEGIDX piSeg, PRTLDRADDR poffSeg));
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * Converts an image relative virtual address to a segment:offset.
|
---|
174 | *
|
---|
175 | * @returns IPRT status code.
|
---|
176 | *
|
---|
177 | * @param pMod Pointer to the loader module structure.
|
---|
178 | * @param Rva The RVA to convert.
|
---|
179 | * @param piSeg The segment index.
|
---|
180 | * @param poffSeg Where to return the segment offset.
|
---|
181 | */
|
---|
182 | DECLCALLBACKMEMBER(int, pfnRvaToSegOffset,(PRTDBGMODINT pMod, RTLDRADDR Rva, uint32_t *piSeg, PRTLDRADDR poffSeg));
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Creates a read-only mapping of a part of the image file.
|
---|
186 | *
|
---|
187 | * @returns IPRT status code and *ppvMap set on success.
|
---|
188 | *
|
---|
189 | * @param pMod Pointer to the module structure.
|
---|
190 | * @param iDbgInfo The debug info ordinal number if the request
|
---|
191 | * corresponds exactly to a debug info part from
|
---|
192 | * pfnEnumDbgInfo. Otherwise, pass UINT32_MAX.
|
---|
193 | * @param off The offset into the image file.
|
---|
194 | * @param cb The number of bytes to map.
|
---|
195 | * @param ppvMap Where to return the mapping address on success.
|
---|
196 | *
|
---|
197 | * @remarks Fixups will only be applied if @a iDbgInfo is specified.
|
---|
198 | */
|
---|
199 | DECLCALLBACKMEMBER(int, pfnMapPart,(PRTDBGMODINT pMod, uint32_t iDbgInfo, RTFOFF off, size_t cb, void const **ppvMap));
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * Unmaps memory previously mapped by pfnMapPart.
|
---|
203 | *
|
---|
204 | * @returns IPRT status code, *ppvMap set to NULL on success.
|
---|
205 | *
|
---|
206 | * @param pMod Pointer to the module structure.
|
---|
207 | * @param cb The size of the mapping.
|
---|
208 | * @param ppvMap The mapping address on input, NULL on
|
---|
209 | * successful return.
|
---|
210 | */
|
---|
211 | DECLCALLBACKMEMBER(int, pfnUnmapPart,(PRTDBGMODINT pMod, size_t cb, void const **ppvMap));
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * Reads data from the image file.
|
---|
215 | *
|
---|
216 | * @returns IPRT status code, *ppvMap set to NULL on success.
|
---|
217 | *
|
---|
218 | * @param pMod Pointer to the module structure.
|
---|
219 | * @param iDbgInfoHint The debug info ordinal number hint, pass UINT32_MAX
|
---|
220 | * if not know or sure.
|
---|
221 | * @param off The offset into the image file.
|
---|
222 | * @param pvBuf The buffer to read into.
|
---|
223 | * @param cb The number of bytes to read.
|
---|
224 | */
|
---|
225 | DECLCALLBACKMEMBER(int, pfnReadAt,(PRTDBGMODINT pMod, uint32_t iDbgInfoHint, RTFOFF off, void *pvBuf, size_t cb));
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Gets the image format.
|
---|
229 | *
|
---|
230 | * @returns Valid image format on success, RTLDRFMT_INVALID if not supported.
|
---|
231 | * @param pMod Pointer to the module structure.
|
---|
232 | */
|
---|
233 | DECLCALLBACKMEMBER(RTLDRFMT, pfnGetFormat,(PRTDBGMODINT pMod));
|
---|
234 |
|
---|
235 | /**
|
---|
236 | * Gets the image architecture.
|
---|
237 | *
|
---|
238 | * @returns Valid image architecutre on success, RTLDRARCH_WHATEVER if not
|
---|
239 | * supported.
|
---|
240 | * @param pMod Pointer to the module structure.
|
---|
241 | */
|
---|
242 | DECLCALLBACKMEMBER(RTLDRARCH, pfnGetArch,(PRTDBGMODINT pMod));
|
---|
243 |
|
---|
244 | /**
|
---|
245 | * Generic method for querying image properties.
|
---|
246 | *
|
---|
247 | * @returns IPRT status code.
|
---|
248 | * @param pMod Pointer to the module structure.
|
---|
249 | * @param enmProp The property to query.
|
---|
250 | * @param pvBuf Pointer to the return buffer.
|
---|
251 | * @param cbBuf The size of the return buffer.
|
---|
252 | * @param pcbRet How many bytes was actually returned. In the
|
---|
253 | * case of VERR_BUFFER_OVERFLOW this will contain
|
---|
254 | * the required buffer size. Optional.
|
---|
255 | * @sa RTLdrQueryPropEx
|
---|
256 | */
|
---|
257 | DECLCALLBACKMEMBER(int, pfnQueryProp,(PRTDBGMODINT pMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf, size_t *pcbRet));
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * Try use unwind information to unwind one frame.
|
---|
261 | *
|
---|
262 | * @returns IPRT status code. Last informational status from stack reader callback.
|
---|
263 | * @retval VERR_DBG_NO_UNWIND_INFO if the module contains no unwind information.
|
---|
264 | * @retval VERR_DBG_UNWIND_INFO_NOT_FOUND if no unwind information was found
|
---|
265 | * for the location given by iSeg:off.
|
---|
266 | *
|
---|
267 | * @param pMod Pointer to the module structure.
|
---|
268 | * @param iSeg The segment number of the program counter.
|
---|
269 | * @param off The offset into @a iSeg. Together with @a iSeg
|
---|
270 | * this corresponds to the RTDBGUNWINDSTATE::uPc
|
---|
271 | * value pointed to by @a pState.
|
---|
272 | * @param pState The unwind state to work.
|
---|
273 | *
|
---|
274 | * @sa RTLdrUnwindFrame, RTDbgModUnwindFrame
|
---|
275 | */
|
---|
276 | DECLCALLBACKMEMBER(int, pfnUnwindFrame,(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTDBGUNWINDSTATE pState));
|
---|
277 |
|
---|
278 | /** For catching initialization errors (RTDBGMODVTIMG_MAGIC). */
|
---|
279 | uint32_t u32EndMagic;
|
---|
280 | } RTDBGMODVTIMG;
|
---|
281 | /** Pointer to a const RTDBGMODVTIMG. */
|
---|
282 | typedef RTDBGMODVTIMG const *PCRTDBGMODVTIMG;
|
---|
283 |
|
---|
284 |
|
---|
285 | /**
|
---|
286 | * Virtual method table for debug info interpreters.
|
---|
287 | */
|
---|
288 | typedef struct RTDBGMODVTDBG
|
---|
289 | {
|
---|
290 | /** Magic number (RTDBGMODVTDBG_MAGIC). */
|
---|
291 | uint32_t u32Magic;
|
---|
292 | /** Mask of supported debug info types, see grp_rt_dbg_type.
|
---|
293 | * Used to speed up the search for a suitable interpreter. */
|
---|
294 | uint32_t fSupports;
|
---|
295 | /** The name of the interpreter. */
|
---|
296 | const char *pszName;
|
---|
297 |
|
---|
298 | /**
|
---|
299 | * Try open the image.
|
---|
300 | *
|
---|
301 | * This combines probing and opening.
|
---|
302 | *
|
---|
303 | * @returns IPRT status code. No informational returns defined.
|
---|
304 | *
|
---|
305 | * @param pMod Pointer to the module that is being opened.
|
---|
306 | *
|
---|
307 | * The RTDBGMOD::pszDbgFile member will point to
|
---|
308 | * the filename of any debug info we're aware of
|
---|
309 | * on input. Also, or alternatively, it is expected
|
---|
310 | * that the interpreter will look for debug info in
|
---|
311 | * the executable image file when present and that it
|
---|
312 | * may ask the image interpreter for this when it's
|
---|
313 | * around.
|
---|
314 | *
|
---|
315 | * Upon successful return the method is expected to
|
---|
316 | * initialize pDbgOps and pvDbgPriv.
|
---|
317 | * @param enmArch The desired architecture.
|
---|
318 | */
|
---|
319 | DECLCALLBACKMEMBER(int, pfnTryOpen,(PRTDBGMODINT pMod, RTLDRARCH enmArch));
|
---|
320 |
|
---|
321 | /**
|
---|
322 | * Close the interpreter, freeing all associated resources.
|
---|
323 | *
|
---|
324 | * The caller sets the pDbgOps and pvDbgPriv RTDBGMOD members
|
---|
325 | * to NULL upon return.
|
---|
326 | *
|
---|
327 | * @param pMod Pointer to the module structure.
|
---|
328 | */
|
---|
329 | DECLCALLBACKMEMBER(int, pfnClose,(PRTDBGMODINT pMod));
|
---|
330 |
|
---|
331 |
|
---|
332 |
|
---|
333 | /**
|
---|
334 | * Converts an image relative virtual address address to a segmented address.
|
---|
335 | *
|
---|
336 | * @returns Segment index on success, NIL_RTDBGSEGIDX on failure.
|
---|
337 | * @param pMod Pointer to the module structure.
|
---|
338 | * @param uRva The image relative address to convert.
|
---|
339 | * @param poffSeg Where to return the segment offset. Optional.
|
---|
340 | */
|
---|
341 | DECLCALLBACKMEMBER(RTDBGSEGIDX, pfnRvaToSegOff,(PRTDBGMODINT pMod, RTUINTPTR uRva, PRTUINTPTR poffSeg));
|
---|
342 |
|
---|
343 | /**
|
---|
344 | * Image size when mapped if segments are mapped adjacently.
|
---|
345 | *
|
---|
346 | * For ELF, PE, and Mach-O images this is (usually) a natural query, for LX and
|
---|
347 | * NE and such it's a bit odder and the answer may not make much sense for them.
|
---|
348 | *
|
---|
349 | * @returns Image mapped size.
|
---|
350 | * @param pMod Pointer to the module structure.
|
---|
351 | */
|
---|
352 | DECLCALLBACKMEMBER(RTUINTPTR, pfnImageSize,(PRTDBGMODINT pMod));
|
---|
353 |
|
---|
354 |
|
---|
355 |
|
---|
356 | /**
|
---|
357 | * Adds a segment to the module (optional).
|
---|
358 | *
|
---|
359 | * @returns IPRT status code.
|
---|
360 | * @retval VERR_NOT_SUPPORTED if the interpreter doesn't support this feature.
|
---|
361 | * @retval VERR_DBG_SEGMENT_INDEX_CONFLICT if the segment index exists already.
|
---|
362 | *
|
---|
363 | * @param pMod Pointer to the module structure.
|
---|
364 | * @param uRva The segment image relative address.
|
---|
365 | * @param cb The segment size.
|
---|
366 | * @param pszName The segment name.
|
---|
367 | * @param cchName The length of the segment name.
|
---|
368 | * @param fFlags Segment flags.
|
---|
369 | * @param piSeg The segment index or NIL_RTDBGSEGIDX on input.
|
---|
370 | * The assigned segment index on successful return.
|
---|
371 | * Optional.
|
---|
372 | */
|
---|
373 | DECLCALLBACKMEMBER(int, pfnSegmentAdd,(PRTDBGMODINT pMod, RTUINTPTR uRva, RTUINTPTR cb, const char *pszName, size_t cchName,
|
---|
374 | uint32_t fFlags, PRTDBGSEGIDX piSeg));
|
---|
375 |
|
---|
376 | /**
|
---|
377 | * Gets the segment count.
|
---|
378 | *
|
---|
379 | * @returns Number of segments.
|
---|
380 | * @retval NIL_RTDBGSEGIDX if unknown.
|
---|
381 | *
|
---|
382 | * @param pMod Pointer to the module structure.
|
---|
383 | */
|
---|
384 | DECLCALLBACKMEMBER(RTDBGSEGIDX, pfnSegmentCount,(PRTDBGMODINT pMod));
|
---|
385 |
|
---|
386 | /**
|
---|
387 | * Gets information about a segment.
|
---|
388 | *
|
---|
389 | * @returns IPRT status code.
|
---|
390 | * @retval VERR_DBG_INVALID_SEGMENT_INDEX if iSeg is too high.
|
---|
391 | *
|
---|
392 | * @param pMod Pointer to the module structure.
|
---|
393 | * @param iSeg The segment.
|
---|
394 | * @param pSegInfo Where to store the segment information.
|
---|
395 | */
|
---|
396 | DECLCALLBACKMEMBER(int, pfnSegmentByIndex,(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, PRTDBGSEGMENT pSegInfo));
|
---|
397 |
|
---|
398 |
|
---|
399 |
|
---|
400 | /**
|
---|
401 | * Adds a symbol to the module (optional).
|
---|
402 | *
|
---|
403 | * @returns IPRT code.
|
---|
404 | * @retval VERR_NOT_SUPPORTED if the interpreter doesn't support this feature.
|
---|
405 | *
|
---|
406 | * @param pMod Pointer to the module structure.
|
---|
407 | * @param pszSymbol The symbol name.
|
---|
408 | * @param cchSymbol The length for the symbol name.
|
---|
409 | * @param iSeg The segment number (0-based). RTDBGMOD_SEG_RVA can be used.
|
---|
410 | * @param off The offset into the segment.
|
---|
411 | * @param cb The area covered by the symbol. 0 is fine.
|
---|
412 | * @param fFlags Flags.
|
---|
413 | * @param piOrdinal Where to return the symbol ordinal on success. If the
|
---|
414 | * interpreter doesn't do ordinals, this will be set to
|
---|
415 | * UINT32_MAX. Optional
|
---|
416 | */
|
---|
417 | DECLCALLBACKMEMBER(int, pfnSymbolAdd,(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol,
|
---|
418 | uint32_t iSeg, RTUINTPTR off, RTUINTPTR cb, uint32_t fFlags,
|
---|
419 | uint32_t *piOrdinal));
|
---|
420 |
|
---|
421 | /**
|
---|
422 | * Gets the number of symbols in the module.
|
---|
423 | *
|
---|
424 | * This is used for figuring out the max value to pass to pfnSymbolByIndex among
|
---|
425 | * other things.
|
---|
426 | *
|
---|
427 | * @returns The number of symbols, UINT32_MAX if not known/supported.
|
---|
428 | *
|
---|
429 | * @param pMod Pointer to the module structure.
|
---|
430 | */
|
---|
431 | DECLCALLBACKMEMBER(uint32_t, pfnSymbolCount,(PRTDBGMODINT pMod));
|
---|
432 |
|
---|
433 | /**
|
---|
434 | * Queries symbol information by ordinal number.
|
---|
435 | *
|
---|
436 | * @returns IPRT status code.
|
---|
437 | * @retval VINF_SUCCESS on success, no informational status code.
|
---|
438 | * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
|
---|
439 | * @retval VERR_NOT_SUPPORTED if lookup by ordinal is not supported.
|
---|
440 | * @retval VERR_SYMBOL_NOT_FOUND if there is no symbol at that index.
|
---|
441 | *
|
---|
442 | * @param pMod Pointer to the module structure.
|
---|
443 | * @param iOrdinal The symbol ordinal number.
|
---|
444 | * @param pSymInfo Where to store the symbol information.
|
---|
445 | */
|
---|
446 | DECLCALLBACKMEMBER(int, pfnSymbolByOrdinal,(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGSYMBOL pSymInfo));
|
---|
447 |
|
---|
448 | /**
|
---|
449 | * Queries symbol information by symbol name.
|
---|
450 | *
|
---|
451 | * @returns IPRT status code.
|
---|
452 | * @retval VINF_SUCCESS on success, no informational status code.
|
---|
453 | * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
|
---|
454 | * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
|
---|
455 | *
|
---|
456 | * @param pMod Pointer to the module structure.
|
---|
457 | * @param pszSymbol The symbol name.
|
---|
458 | * @param cchSymbol The length of the symbol name.
|
---|
459 | * @param pSymInfo Where to store the symbol information.
|
---|
460 | */
|
---|
461 | DECLCALLBACKMEMBER(int, pfnSymbolByName,(PRTDBGMODINT pMod, const char *pszSymbol, size_t cchSymbol, PRTDBGSYMBOL pSymInfo));
|
---|
462 |
|
---|
463 | /**
|
---|
464 | * Queries symbol information by address.
|
---|
465 | *
|
---|
466 | * The returned symbol is what the debug info interpreter considers the symbol
|
---|
467 | * most applicable to the specified address. This usually means a symbol with an
|
---|
468 | * address equal or lower than the requested.
|
---|
469 | *
|
---|
470 | * @returns IPRT status code.
|
---|
471 | * @retval VINF_SUCCESS on success, no informational status code.
|
---|
472 | * @retval VERR_DBG_NO_SYMBOLS if there aren't any symbols.
|
---|
473 | * @retval VERR_SYMBOL_NOT_FOUND if no suitable symbol was found.
|
---|
474 | *
|
---|
475 | * @param pMod Pointer to the module structure.
|
---|
476 | * @param iSeg The segment number (0-based) or RTDBGSEGIDX_ABS.
|
---|
477 | * @param off The offset into the segment.
|
---|
478 | * @param fFlags Symbol search flags, see RTDBGSYMADDR_FLAGS_XXX.
|
---|
479 | * @param poffDisp Where to store the distance between the specified address
|
---|
480 | * and the returned symbol. Optional.
|
---|
481 | * @param pSymInfo Where to store the symbol information.
|
---|
482 | */
|
---|
483 | DECLCALLBACKMEMBER(int, pfnSymbolByAddr,(PRTDBGMODINT pMod, uint32_t iSeg, RTUINTPTR off, uint32_t fFlags,
|
---|
484 | PRTINTPTR poffDisp, PRTDBGSYMBOL pSymInfo));
|
---|
485 |
|
---|
486 |
|
---|
487 |
|
---|
488 | /**
|
---|
489 | * Adds a line number to the module (optional).
|
---|
490 | *
|
---|
491 | * @returns IPRT status code.
|
---|
492 | * @retval VERR_NOT_SUPPORTED if the interpreter doesn't support this feature.
|
---|
493 | *
|
---|
494 | * @param pMod Pointer to the module structure.
|
---|
495 | * @param pszFile The filename.
|
---|
496 | * @param cchFile The length of the filename.
|
---|
497 | * @param uLineNo The line number.
|
---|
498 | * @param iSeg The segment number (0-based).
|
---|
499 | * @param off The offset into the segment.
|
---|
500 | * @param piOrdinal Where to return the line number ordinal on success. If
|
---|
501 | * the interpreter doesn't do ordinals, this will be set to
|
---|
502 | * UINT32_MAX. Optional
|
---|
503 | */
|
---|
504 | DECLCALLBACKMEMBER(int, pfnLineAdd,(PRTDBGMODINT pMod, const char *pszFile, size_t cchFile, uint32_t uLineNo,
|
---|
505 | uint32_t iSeg, RTUINTPTR off, uint32_t *piOrdinal));
|
---|
506 |
|
---|
507 | /**
|
---|
508 | * Gets the number of line numbers in the module.
|
---|
509 | *
|
---|
510 | * @returns The number or UINT32_MAX if not known/supported.
|
---|
511 | *
|
---|
512 | * @param pMod Pointer to the module structure.
|
---|
513 | */
|
---|
514 | DECLCALLBACKMEMBER(uint32_t, pfnLineCount,(PRTDBGMODINT pMod));
|
---|
515 |
|
---|
516 | /**
|
---|
517 | * Queries line number information by ordinal number.
|
---|
518 | *
|
---|
519 | * @returns IPRT status code.
|
---|
520 | * @retval VINF_SUCCESS on success, no informational status code.
|
---|
521 | * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
|
---|
522 | * @retval VERR_DBG_LINE_NOT_FOUND if there is no line number with that
|
---|
523 | * ordinal.
|
---|
524 | *
|
---|
525 | * @param pMod Pointer to the module structure.
|
---|
526 | * @param iOrdinal The line number ordinal number.
|
---|
527 | * @param pLineInfo Where to store the information about the line number.
|
---|
528 | */
|
---|
529 | DECLCALLBACKMEMBER(int, pfnLineByOrdinal,(PRTDBGMODINT pMod, uint32_t iOrdinal, PRTDBGLINE pLineInfo));
|
---|
530 |
|
---|
531 | /**
|
---|
532 | * Queries line number information by address.
|
---|
533 | *
|
---|
534 | * @returns IPRT status code.
|
---|
535 | * @retval VINF_SUCCESS on success, no informational status code.
|
---|
536 | * @retval VERR_DBG_NO_LINE_NUMBERS if there aren't any line numbers.
|
---|
537 | * @retval VERR_DBG_LINE_NOT_FOUND if no suitable line number was found.
|
---|
538 | *
|
---|
539 | * @param pMod Pointer to the module structure.
|
---|
540 | * @param iSeg The segment number (0-based) or RTDBGSEGIDX_ABS.
|
---|
541 | * @param off The offset into the segment.
|
---|
542 | * @param poffDisp Where to store the distance between the specified address
|
---|
543 | * and the returned line number. Optional.
|
---|
544 | * @param pLineInfo Where to store the information about the closest line
|
---|
545 | * number.
|
---|
546 | */
|
---|
547 | DECLCALLBACKMEMBER(int, pfnLineByAddr,(PRTDBGMODINT pMod, uint32_t iSeg, RTUINTPTR off,
|
---|
548 | PRTINTPTR poffDisp, PRTDBGLINE pLineInfo));
|
---|
549 |
|
---|
550 | /**
|
---|
551 | * Try use unwind information to unwind one frame.
|
---|
552 | *
|
---|
553 | * @returns IPRT status code. Last informational status from stack reader callback.
|
---|
554 | * @retval VERR_DBG_NO_UNWIND_INFO if the module contains no unwind information.
|
---|
555 | * @retval VERR_DBG_UNWIND_INFO_NOT_FOUND if no unwind information was found
|
---|
556 | * for the location given by iSeg:off.
|
---|
557 | *
|
---|
558 | * @param pMod Pointer to the module structure.
|
---|
559 | * @param iSeg The segment number of the program counter.
|
---|
560 | * @param off The offset into @a iSeg. Together with @a iSeg
|
---|
561 | * this corresponds to the RTDBGUNWINDSTATE::uPc
|
---|
562 | * value pointed to by @a pState.
|
---|
563 | * @param pState The unwind state to work.
|
---|
564 | *
|
---|
565 | * @sa RTDbgModUnwindFrame
|
---|
566 | */
|
---|
567 | DECLCALLBACKMEMBER(int, pfnUnwindFrame,(PRTDBGMODINT pMod, RTDBGSEGIDX iSeg, RTUINTPTR off, PRTDBGUNWINDSTATE pState));
|
---|
568 |
|
---|
569 | /** For catching initialization errors (RTDBGMODVTDBG_MAGIC). */
|
---|
570 | uint32_t u32EndMagic;
|
---|
571 | } RTDBGMODVTDBG;
|
---|
572 | /** Pointer to a const RTDBGMODVTDBG. */
|
---|
573 | typedef RTDBGMODVTDBG const *PCRTDBGMODVTDBG;
|
---|
574 |
|
---|
575 |
|
---|
576 | /**
|
---|
577 | * Deferred loading callback.
|
---|
578 | *
|
---|
579 | * @returns IPRT status code. On success the necessary method tables should be
|
---|
580 | * installed in @a pMod.
|
---|
581 | * @param pDbgMod Pointer to the debug module structure.
|
---|
582 | * @param pDeferred The deferred load data.
|
---|
583 | */
|
---|
584 | typedef DECLCALLBACKTYPE(int, FNRTDBGMODDEFERRED,(PRTDBGMODINT pDbgMod, struct RTDBGMODDEFERRED *pDeferred));
|
---|
585 | /** Pointer to a deferred loading callback. */
|
---|
586 | typedef FNRTDBGMODDEFERRED *PFNRTDBGMODDEFERRED;
|
---|
587 |
|
---|
588 |
|
---|
589 | /**
|
---|
590 | * Structure pointed to by pvDbgPriv and/or pvImgPriv when
|
---|
591 | * g_rtDbgModVtDbgDeferred and/or g_rtDbgModVtImgDeferred are being used.
|
---|
592 | */
|
---|
593 | typedef struct RTDBGMODDEFERRED
|
---|
594 | {
|
---|
595 | /** Magic value (RTDBGMODDEFERRED_MAGIC). */
|
---|
596 | uint32_t u32Magic;
|
---|
597 | /** Reference counter. */
|
---|
598 | uint32_t volatile cRefs;
|
---|
599 | /** RTDBGMOD_F_XXX */
|
---|
600 | uint32_t fFlags;
|
---|
601 | /** The image size.
|
---|
602 | * Deferred loading is almost pointless without knowing the module size, as
|
---|
603 | * it cannot be mapped (correctly) without it. */
|
---|
604 | RTUINTPTR cbImage;
|
---|
605 | /** The configuration instance (referenced), can be NIL. */
|
---|
606 | RTDBGCFG hDbgCfg;
|
---|
607 | /** Performs deferred loading of the module. */
|
---|
608 | PFNRTDBGMODDEFERRED pfnDeferred;
|
---|
609 | /** Callback specific data. */
|
---|
610 | union
|
---|
611 | {
|
---|
612 | struct
|
---|
613 | {
|
---|
614 | /** The time/date stamp of the executable image and codeview file. */
|
---|
615 | uint32_t uTimestamp;
|
---|
616 | } PeImage,
|
---|
617 | OldCodeView;
|
---|
618 |
|
---|
619 | struct
|
---|
620 | {
|
---|
621 | /** The PDB uuid. */
|
---|
622 | RTUUID Uuid;
|
---|
623 | /** The PDB age. */
|
---|
624 | uint32_t uAge;
|
---|
625 | } NewCodeview;
|
---|
626 |
|
---|
627 | struct
|
---|
628 | {
|
---|
629 | /** The CRC-32 value found in the .gnu_debuglink section. */
|
---|
630 | uint32_t uCrc32;
|
---|
631 | } GnuDebugLink;
|
---|
632 |
|
---|
633 | struct
|
---|
634 | {
|
---|
635 | /** The image UUID. */
|
---|
636 | RTUUID Uuid;
|
---|
637 | /** Image architecture. */
|
---|
638 | RTLDRARCH enmArch;
|
---|
639 | /** Number of segment mappings. */
|
---|
640 | uint32_t cSegs;
|
---|
641 | /** Segment mappings. */
|
---|
642 | RTDBGSEGMENT aSegs[1];
|
---|
643 | } MachO;
|
---|
644 | } u;
|
---|
645 | } RTDBGMODDEFERRED;
|
---|
646 | /** Pointer to the deferred loading data. */
|
---|
647 | typedef RTDBGMODDEFERRED *PRTDBGMODDEFERRED;
|
---|
648 |
|
---|
649 |
|
---|
650 | /**
|
---|
651 | * Debug module structure.
|
---|
652 | */
|
---|
653 | typedef struct RTDBGMODINT
|
---|
654 | {
|
---|
655 | /** Magic value (RTDBGMOD_MAGIC). */
|
---|
656 | uint32_t u32Magic;
|
---|
657 | /** The number of reference there are to this module.
|
---|
658 | * This is used to perform automatic cleanup and sharing. */
|
---|
659 | uint32_t volatile cRefs;
|
---|
660 | /** The module tag. */
|
---|
661 | uint64_t uTag;
|
---|
662 |
|
---|
663 | /** When set, the loading of the image and debug info (including locating any
|
---|
664 | * external files), will not have taken place yet. */
|
---|
665 | uint32_t fDeferred : 1;
|
---|
666 | /** Set if deferred loading failed. */
|
---|
667 | uint32_t fDeferredFailed : 1;
|
---|
668 | /** Set if the debug info is based on image exports and segments. */
|
---|
669 | uint32_t fExports : 1;
|
---|
670 | /** Alignment padding. */
|
---|
671 | uint32_t fPadding1 : 29;
|
---|
672 | #if ARCH_BITS == 64
|
---|
673 | uint32_t u32Padding2;
|
---|
674 | #endif
|
---|
675 |
|
---|
676 | /** The module name (short). */
|
---|
677 | char const *pszName;
|
---|
678 | /** The image file specified by the user. Can be NULL. */
|
---|
679 | char const *pszImgFileSpecified;
|
---|
680 | /** The module filename. Can be NULL. */
|
---|
681 | char const *pszImgFile;
|
---|
682 | /** The debug info file (if external). Can be NULL. */
|
---|
683 | char const *pszDbgFile;
|
---|
684 |
|
---|
685 | /** The method table for the executable image interpreter. */
|
---|
686 | PCRTDBGMODVTIMG pImgVt;
|
---|
687 | /** Pointer to the private data of the executable image interpreter. */
|
---|
688 | void *pvImgPriv;
|
---|
689 |
|
---|
690 | /** The method table for the debug info interpreter. */
|
---|
691 | PCRTDBGMODVTDBG pDbgVt;
|
---|
692 | /** Pointer to the private data of the debug info interpreter. */
|
---|
693 | void *pvDbgPriv;
|
---|
694 |
|
---|
695 | /** Critical section serializing access to the module. */
|
---|
696 | RTCRITSECT CritSect;
|
---|
697 | } RTDBGMODINT;
|
---|
698 | /** Pointer to an debug module structure. */
|
---|
699 | typedef RTDBGMODINT *PRTDBGMODINT;
|
---|
700 |
|
---|
701 |
|
---|
702 | extern DECL_HIDDEN_DATA(RTSTRCACHE) g_hDbgModStrCache;
|
---|
703 | extern DECL_HIDDEN_DATA(RTDBGMODVTDBG const) g_rtDbgModVtDbgCodeView;
|
---|
704 | extern DECL_HIDDEN_DATA(RTDBGMODVTDBG const) g_rtDbgModVtDbgDwarf;
|
---|
705 | extern DECL_HIDDEN_DATA(RTDBGMODVTDBG const) g_rtDbgModVtDbgNm;
|
---|
706 | extern DECL_HIDDEN_DATA(RTDBGMODVTDBG const) g_rtDbgModVtDbgMapSym;
|
---|
707 | #ifdef IPRT_WITH_GHIDRA_DBG_MOD
|
---|
708 | extern DECL_HIDDEN_DATA(RTDBGMODVTDBG const) g_rtDbgModVtDbgGhidra;
|
---|
709 | #endif
|
---|
710 | #ifdef RT_OS_WINDOWS
|
---|
711 | extern DECL_HIDDEN_DATA(RTDBGMODVTDBG const) g_rtDbgModVtDbgDbgHelp;
|
---|
712 | #endif
|
---|
713 | extern DECL_HIDDEN_DATA(RTDBGMODVTDBG const) g_rtDbgModVtDbgDeferred;
|
---|
714 | extern DECL_HIDDEN_DATA(RTDBGMODVTDBG const) g_rtDbgModVtDbgContainer;
|
---|
715 |
|
---|
716 | extern DECL_HIDDEN_DATA(RTDBGMODVTIMG const) g_rtDbgModVtImgLdr;
|
---|
717 | extern DECL_HIDDEN_DATA(RTDBGMODVTIMG const) g_rtDbgModVtImgDeferred;
|
---|
718 |
|
---|
719 | DECLHIDDEN(int) rtDbgModContainerCreate(PRTDBGMODINT pMod, RTUINTPTR cbSeg);
|
---|
720 | DECLHIDDEN(int) rtDbgModContainer_SymbolRemoveAll(PRTDBGMODINT pMod);
|
---|
721 | DECLHIDDEN(int) rtDbgModContainer_LineRemoveAll(PRTDBGMODINT pMod);
|
---|
722 | DECLHIDDEN(int) rtDbgModContainer_RemoveAll(PRTDBGMODINT pMod);
|
---|
723 |
|
---|
724 | DECLHIDDEN(int) rtDbgModCreateForExports(PRTDBGMODINT pDbgMod);
|
---|
725 | DECLHIDDEN(int) rtDbgModDeferredCreate(PRTDBGMODINT pDbgMod, PFNRTDBGMODDEFERRED pfnDeferred, RTUINTPTR cbImage,
|
---|
726 | RTDBGCFG hDbgCfg, size_t cbDeferred, uint32_t fFlags, PRTDBGMODDEFERRED *ppDeferred);
|
---|
727 |
|
---|
728 | DECLHIDDEN(int) rtDbgModLdrOpenFromHandle(PRTDBGMODINT pDbgMod, RTLDRMOD hLdrMod);
|
---|
729 |
|
---|
730 | DECLHIDDEN(int) rtDwarfUnwind_EhData(void const *pvSection, size_t cbSection, RTUINTPTR uRvaSection,
|
---|
731 | RTDBGSEGIDX idxSeg, RTUINTPTR offSeg, RTUINTPTR uRva,
|
---|
732 | PRTDBGUNWINDSTATE pState, RTLDRARCH enmArch);
|
---|
733 |
|
---|
734 | /** @} */
|
---|
735 |
|
---|
736 | RT_C_DECLS_END
|
---|
737 |
|
---|
738 | #endif /* !IPRT_INCLUDED_INTERNAL_dbgmod_h */
|
---|
739 |
|
---|