1 | /* $Id: DBGPlugInCommonELF.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGPlugInCommonELF - Common code for dealing with ELF images.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2020 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 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_DBGF /// @todo add new log group.
|
---|
23 | #include "DBGPlugInCommonELF.h"
|
---|
24 |
|
---|
25 | #include <VBox/vmm/dbgf.h>
|
---|
26 | #include <iprt/alloca.h>
|
---|
27 | #include <iprt/asm.h>
|
---|
28 | #include <iprt/assert.h>
|
---|
29 | #include <iprt/dbg.h>
|
---|
30 | #include <iprt/err.h>
|
---|
31 | #include <iprt/mem.h>
|
---|
32 | #include <iprt/string.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /*********************************************************************************************************************************
|
---|
36 | * Structures and Typedefs *
|
---|
37 | *********************************************************************************************************************************/
|
---|
38 | typedef struct DBGDIGGERELFSEG
|
---|
39 | {
|
---|
40 | /** The segment load address. */
|
---|
41 | RTGCPTR uLoadAddr;
|
---|
42 | /** The last address in the segment. */
|
---|
43 | RTGCPTR uLastAddr;
|
---|
44 | /** The segment index. */
|
---|
45 | RTDBGSEGIDX iSeg;
|
---|
46 | } DBGDIGGERELFSEG;
|
---|
47 | typedef DBGDIGGERELFSEG *PDBGDIGGERELFSEG;
|
---|
48 |
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Links the segments of the module into the address space.
|
---|
52 | *
|
---|
53 | * @returns VBox status code on failure.
|
---|
54 | *
|
---|
55 | * @param hAs The address space.
|
---|
56 | * @param hMod The module.
|
---|
57 | * @param paSegs Array of segment indexes and load addresses.
|
---|
58 | * @param cSegs The number of segments in the array.
|
---|
59 | */
|
---|
60 | static int dbgDiggerCommonLinkElfSegs(RTDBGAS hAs, RTDBGMOD hMod, PDBGDIGGERELFSEG paSegs, uint32_t cSegs)
|
---|
61 | {
|
---|
62 | for (uint32_t i = 0; i < cSegs; i++)
|
---|
63 | if (paSegs[i].iSeg != NIL_RTDBGSEGIDX)
|
---|
64 | {
|
---|
65 | int rc = RTDbgAsModuleLinkSeg(hAs, hMod, paSegs[i].iSeg, paSegs[i].uLoadAddr, RTDBGASLINK_FLAGS_REPLACE);
|
---|
66 | if (RT_FAILURE(rc))
|
---|
67 | {
|
---|
68 | RTDbgAsModuleUnlink(hAs, hMod);
|
---|
69 | return rc;
|
---|
70 | }
|
---|
71 | }
|
---|
72 | return VINF_SUCCESS;
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | /*
|
---|
77 | * Instantiate the code templates for dealing with the two ELF versions.
|
---|
78 | */
|
---|
79 |
|
---|
80 | #define ELF_MODE 32
|
---|
81 | #include "DBGPlugInCommonELFTmpl.cpp.h"
|
---|
82 |
|
---|
83 | #undef ELF_MODE
|
---|
84 | #define ELF_MODE 64
|
---|
85 | #include "DBGPlugInCommonELFTmpl.cpp.h"
|
---|
86 |
|
---|