HPCToolkit
ElfHelper.hpp
Go to the documentation of this file.
1 // * BeginRiceCopyright *****************************************************
2 //
3 // $HeadURL$
4 // $Id$
5 //
6 // --------------------------------------------------------------------------
7 // Part of HPCToolkit (hpctoolkit.org)
8 //
9 // Information about sources of support for research and development of
10 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
11 // --------------------------------------------------------------------------
12 //
13 // Copyright ((c)) 2002-2019, Rice University
14 // All rights reserved.
15 //
16 // Redistribution and use in source and binary forms, with or without
17 // modification, are permitted provided that the following conditions are
18 // met:
19 //
20 // * Redistributions of source code must retain the above copyright
21 // notice, this list of conditions and the following disclaimer.
22 //
23 // * Redistributions in binary form must reproduce the above copyright
24 // notice, this list of conditions and the following disclaimer in the
25 // documentation and/or other materials provided with the distribution.
26 //
27 // * Neither the name of Rice University (RICE) nor the names of its
28 // contributors may be used to endorse or promote products derived from
29 // this software without specific prior written permission.
30 //
31 // This software is provided by RICE and contributors "as is" and any
32 // express or implied warranties, including, but not limited to, the
33 // implied warranties of merchantability and fitness for a particular
34 // purpose are disclaimed. In no event shall RICE or contributors be
35 // liable for any direct, indirect, incidental, special, exemplary, or
36 // consequential damages (including, but not limited to, procurement of
37 // substitute goods or services; loss of use, data, or profits; or
38 // business interruption) however caused and on any theory of liability,
39 // whether in contract, strict liability, or tort (including negligence
40 // or otherwise) arising in any way out of the use of this software, even
41 // if advised of the possibility of such damage.
42 //
43 // ******************************************************* EndRiceCopyright *
44 
45 
46 //***************************************************************************
47 //
48 // File: ElfHelper.hpp
49 //
50 // Purpose:
51 // Interface for a module that scans an elf file and returns a vector
52 // of sections
53 //
54 //***************************************************************************
55 
56 #ifndef __ElfHelper_hpp__
57 #define __ElfHelper_hpp__
58 
59 
60 //******************************************************************************
61 // system includes
62 //******************************************************************************
63 
64 #include <vector>
65 #include <string>
66 
67 #include <libelf.h>
68 #include <gelf.h>
69 
70 
71 //******************************************************************************
72 // macros
73 //******************************************************************************
74 
75 
76 //******************************************************************************
77 // type definitions
78 //******************************************************************************
79 
80 class ElfFile {
81 public:
82  ElfFile() { memPtr = 0; elf = 0; memLen = 0; }
83  bool open(char *_memPtr, size_t _memLen, std::string _fileName);
84  ~ElfFile();
85  Elf *getElf() { return elf; };
86  char *getMemory() { return memPtr; };
87  size_t getLength() { return memLen; };
88  std::string getFileName() { return fileName; };
89 private:
90  char *memPtr;
91  size_t memLen;
92  Elf *elf;
93  std::string fileName;
94 };
95 
96 
97 class ElfFileVector : public std::vector<ElfFile *> {};
98 
99 
100 class ElfSectionVector : public std::vector<Elf_Scn *> {};
101 
102 
103 
104 //******************************************************************************
105 // interface functions
106 //******************************************************************************
107 
110 (
111  Elf *elf
112 );
113 
114 
115 char *
117 (
118  char *obj_ptr,
119  GElf_Shdr *shdr
120 );
121 
122 
123 
124 #endif
std::string fileName
Definition: ElfHelper.hpp:93
char * getMemory()
Definition: ElfHelper.hpp:86
Elf * elf
Definition: ElfHelper.hpp:92
Elf * getElf()
Definition: ElfHelper.hpp:85
bool open(char *_memPtr, size_t _memLen, std::string _fileName)
Definition: ElfHelper.cpp:96
ElfSectionVector * elfGetSectionVector(Elf *elf)
Definition: ElfHelper.cpp:142
std::string getFileName()
Definition: ElfHelper.hpp:88
char * elfSectionGetData(char *obj_ptr, GElf_Shdr *shdr)
Definition: ElfHelper.cpp:165
char * memPtr
Definition: ElfHelper.hpp:88
size_t getLength()
Definition: ElfHelper.hpp:87
size_t memLen
Definition: ElfHelper.hpp:91