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