HPCToolkit
Dbg-LM.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // $HeadURL$
51 //
52 // Purpose:
53 // [The purpose of this file]
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 #ifndef BinUtil_Dbg_LM_hpp
61 #define BinUtil_Dbg_LM_hpp
62 
63 //************************* System Include Files ****************************
64 
65 #include <string>
66 #include <deque>
67 #include <map>
68 #include <iostream>
69 
70 //*************************** User Include Files ****************************
71 
72 #include <include/uint.h>
73 
74 #include "VMAInterval.hpp"
75 
76 #include <lib/isa/ISATypes.hpp>
77 
78 //*************************** Forward Declarations **************************
79 
80 //***************************************************************************
81 // LM (LoadModule)
82 //***************************************************************************
83 
84 namespace BinUtil {
85 
86 namespace Dbg {
87 
88 class Proc;
89 
90 // --------------------------------------------------------------------------
91 // 'LM' represents debug information for a load module
92 //
93 // Note: Most references to VMA (virtual memory address) could be
94 // replaced with 'PC' (program counter) or IP (instruction pointer).
95 // --------------------------------------------------------------------------
96 
97 class LM {
98 public:
99  // A VMA -> Dbg::Proc map (could use VMAInterval -> Dbg::Proc)
100  typedef VMA key_type;
102 
103  typedef std::map<key_type, mapped_type> My_t;
104  typedef std::pair<const key_type, mapped_type> value_type;
105  typedef My_t::key_compare key_compare;
106  typedef My_t::allocator_type allocator_type;
107  typedef My_t::reference reference;
108  typedef My_t::const_reference const_reference;
109  typedef My_t::iterator iterator;
110  typedef My_t::const_iterator const_iterator;
111  typedef My_t::size_type size_type;
112 
113  // A string -> Dbg::Proc map (could use VMAInterval -> Dbg::Proc)
114  typedef std::string key_type1;
115 
116  typedef std::map<key_type1, mapped_type> My1_t;
117  typedef std::pair<const key_type1, mapped_type> value_type1;
118  typedef My1_t::key_compare key_compare1;
119  typedef My1_t::allocator_type allocator_type1;
120  typedef My1_t::reference reference1;
121  typedef My1_t::const_reference const_reference1;
122  typedef My1_t::iterator iterator1;
123  typedef My1_t::const_iterator const_iterator1;
124  typedef My1_t::size_type size_type1;
125 
126 public:
127  LM();
128  ~LM();
129 
130  void read(bfd* abfd, asymbol** bfdSymTab);
131 
132  // -------------------------------------------------------
133  // iterator, find/insert, etc [My_t]
134  // -------------------------------------------------------
135 
136  // iterators:
137  iterator begin()
138  { return m_map.begin(); }
139  const_iterator begin() const
140  { return m_map.begin(); }
141  iterator end()
142  { return m_map.end(); }
143  const_iterator end() const
144  { return m_map.end(); }
145 
146  // capacity:
147  size_type size() const
148  { return m_map.size(); }
149 
150  // element access:
151  mapped_type& operator[](const key_type& x)
152  { return m_map[x]; }
153 
154  // modifiers:
155  std::pair<iterator, bool> insert(const value_type& x)
156  { return m_map.insert(x); }
157  iterator insert(iterator position, const value_type& x)
158  { return m_map.insert(position, x); }
159 
160  void erase(iterator position)
161  { m_map.erase(position); }
162  size_type erase(const key_type& x)
163  { return m_map.erase(x); }
164  void erase(iterator first, iterator last)
165  { m_map.erase(first, last); }
166 
167  void clear();
168 
169  // m_map operations:
170  iterator find(const key_type& x)
171  { return m_map.find(x); }
172  const_iterator find(const key_type& x) const
173  { return m_map.find(x); }
174  size_type count(const key_type& x) const
175  { return m_map.count(x); }
176 
177 
178  // -------------------------------------------------------
179  // iterator, find/insert, etc [My1_t]
180  // -------------------------------------------------------
181 
182  // iterators:
183  iterator1 begin1()
184  { return m_map1.begin(); }
185  const_iterator1 begin1() const
186  { return m_map1.begin(); }
187  iterator1 end1()
188  { return m_map1.end(); }
189  const_iterator1 end1() const
190  { return m_map1.end(); }
191 
192  // capacity:
193  size_type size1() const
194  { return m_map1.size(); }
195 
196  // element access:
197  mapped_type& operator[](const key_type1& x)
198  { return m_map1[x]; }
199 
200  // modifiers:
201  std::pair<iterator1, bool> insert1(const value_type1& x)
202  { return m_map1.insert(x); }
203  iterator1 insert1(iterator1 position, const value_type1& x)
204  { return m_map1.insert(position, x); }
205 
206  void erase1(iterator1 position)
207  { m_map1.erase(position); }
208  size_type erase1(const key_type1& x)
209  { return m_map1.erase(x); }
210  void erase1(iterator1 first, iterator1 last)
211  { m_map1.erase(first, last); }
212 
213  void clear1();
214 
215  // m_map operations:
216  iterator1 find1(const key_type1& x)
217  { return m_map1.find(x); }
218  const_iterator1 find1(const key_type1& x) const
219  { return m_map1.find(x); }
220  size_type count1(const key_type1& x) const
221  { return m_map1.count(x); }
222 
223 
224  // -------------------------------------------------------
225  // debugging
226  // -------------------------------------------------------
227  std::string toString() const;
228 
229  std::ostream& dump(std::ostream& os) const;
230 
231  void ddump() const;
232 
233 private:
234 
235  // -------------------------------------------------------
236  //
237  // -------------------------------------------------------
238 
239  // Callback for bfd_elf_forall_dbg_funcinfo
240  static int bfd_dbgInfoCallback(void* callback_obj, void* parent,
241  void* funcinfo);
242 
243  void setParentPointers();
244 
245 private:
246  My_t m_map;
247  My1_t m_map1;
248 };
249 
250 
251 } // namespace Dbg
252 
253 } // namespace BinUtil
254 
255 //***************************************************************************
256 
257 #endif // BinUtil_Dbg_LM_hpp
const_iterator end() const
Definition: Dbg-LM.hpp:143
My1_t::const_iterator const_iterator1
Definition: Dbg-LM.hpp:123
My1_t::size_type size_type1
Definition: Dbg-LM.hpp:124
std::string toString() const
Definition: Dbg-LM.cpp:149
My_t::allocator_type allocator_type
Definition: Dbg-LM.hpp:106
iterator1 find1(const key_type1 &x)
Definition: Dbg-LM.hpp:216
My1_t::key_compare key_compare1
Definition: Dbg-LM.hpp:118
void erase1(iterator1 position)
Definition: Dbg-LM.hpp:206
bfd_vma VMA
Definition: ISATypes.hpp:79
size_type erase(const key_type &x)
Definition: Dbg-LM.hpp:162
My1_t::reference reference1
Definition: Dbg-LM.hpp:120
iterator insert(iterator position, const value_type &x)
Definition: Dbg-LM.hpp:157
const_iterator1 end1() const
Definition: Dbg-LM.hpp:189
void setParentPointers()
Definition: Dbg-LM.cpp:293
iterator1 end1()
Definition: Dbg-LM.hpp:187
std::pair< const key_type1, mapped_type > value_type1
Definition: Dbg-LM.hpp:117
iterator find(const key_type &x)
Definition: Dbg-LM.hpp:170
iterator1 begin1()
Definition: Dbg-LM.hpp:183
const_iterator begin() const
Definition: Dbg-LM.hpp:139
const_iterator1 begin1() const
Definition: Dbg-LM.hpp:185
My_t::iterator iterator
Definition: Dbg-LM.hpp:109
size_type count1(const key_type1 &x) const
Definition: Dbg-LM.hpp:220
std::pair< const key_type, mapped_type > value_type
Definition: Dbg-LM.hpp:104
My_t::key_compare key_compare
Definition: Dbg-LM.hpp:105
Dbg::Proc * mapped_type
Definition: Dbg-LM.hpp:101
std::pair< iterator1, bool > insert1(const value_type1 &x)
Definition: Dbg-LM.hpp:201
size_type size1() const
Definition: Dbg-LM.hpp:193
iterator1 insert1(iterator1 position, const value_type1 &x)
Definition: Dbg-LM.hpp:203
const_iterator find(const key_type &x) const
Definition: Dbg-LM.hpp:172
mapped_type & operator[](const key_type &x)
Definition: Dbg-LM.hpp:151
std::map< key_type, mapped_type > My_t
Definition: Dbg-LM.hpp:103
My1_t::iterator iterator1
Definition: Dbg-LM.hpp:122
iterator end()
Definition: Dbg-LM.hpp:141
static int bfd_dbgInfoCallback(void *callback_obj, void *parent, void *funcinfo)
Definition: Dbg-LM.cpp:186
std::map< key_type1, mapped_type > My1_t
Definition: Dbg-LM.hpp:116
My1_t::allocator_type allocator_type1
Definition: Dbg-LM.hpp:119
void ddump() const
Definition: Dbg-LM.cpp:176
const_iterator1 find1(const key_type1 &x) const
Definition: Dbg-LM.hpp:218
std::ostream & dump(std::ostream &os) const
Definition: Dbg-LM.cpp:158
My_t::const_iterator const_iterator
Definition: Dbg-LM.hpp:110
size_type size() const
Definition: Dbg-LM.hpp:147
void erase(iterator position)
Definition: Dbg-LM.hpp:160
void read(bfd *abfd, asymbol **bfdSymTab)
Definition: Dbg-LM.cpp:108
mapped_type & operator[](const key_type1 &x)
Definition: Dbg-LM.hpp:197
My_t::size_type size_type
Definition: Dbg-LM.hpp:111
std::pair< iterator, bool > insert(const value_type &x)
Definition: Dbg-LM.hpp:155
My1_t::const_reference const_reference1
Definition: Dbg-LM.hpp:121
My_t::reference reference
Definition: Dbg-LM.hpp:107
void erase(iterator first, iterator last)
Definition: Dbg-LM.hpp:164
size_type erase1(const key_type1 &x)
Definition: Dbg-LM.hpp:208
void erase1(iterator1 first, iterator1 last)
Definition: Dbg-LM.hpp:210
static char * last
Definition: tokenize.c:65
size_type count(const key_type &x) const
Definition: Dbg-LM.hpp:174
std::string key_type1
Definition: Dbg-LM.hpp:114
My_t::const_reference const_reference
Definition: Dbg-LM.hpp:108
iterator begin()
Definition: Dbg-LM.hpp:137