]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Symbol/LineTable.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / Symbol / LineTable.h
1 //===-- LineTable.h ---------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_LineTable_h_
11 #define liblldb_LineTable_h_
12
13 // C Includes
14 // C++ Includes
15 #include <vector>
16
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/Core/ModuleChild.h"
20 #include "lldb/Core/RangeMap.h"
21 #include "lldb/Core/Section.h"
22 #include "lldb/Symbol/LineEntry.h"
23 #include "lldb/lldb-private.h"
24
25 namespace lldb_private {
26
27 //----------------------------------------------------------------------
28 /// @class LineSequence LineTable.h "lldb/Symbol/LineTable.h"
29 /// @brief An abstract base class used during symbol table creation.
30 //----------------------------------------------------------------------
31 class LineSequence {
32 public:
33   LineSequence();
34
35   virtual ~LineSequence() = default;
36
37   virtual void Clear() = 0;
38
39 private:
40   DISALLOW_COPY_AND_ASSIGN(LineSequence);
41 };
42
43 //----------------------------------------------------------------------
44 /// @class LineTable LineTable.h "lldb/Symbol/LineTable.h"
45 /// @brief A line table class.
46 //----------------------------------------------------------------------
47 class LineTable {
48 public:
49   //------------------------------------------------------------------
50   /// Construct with compile unit.
51   ///
52   /// @param[in] comp_unit
53   ///     The compile unit to which this line table belongs.
54   //------------------------------------------------------------------
55   LineTable(CompileUnit *comp_unit);
56
57   //------------------------------------------------------------------
58   /// Destructor.
59   //------------------------------------------------------------------
60   ~LineTable();
61
62   //------------------------------------------------------------------
63   /// Adds a new line entry to this line table.
64   ///
65   /// All line entries are maintained in file address order.
66   ///
67   /// @param[in] line_entry
68   ///     A const reference to a new line_entry to add to this line
69   ///     table.
70   ///
71   /// @see Address::DumpStyle
72   //------------------------------------------------------------------
73   //  void
74   //  AddLineEntry (const LineEntry& line_entry);
75
76   // Called when you can't guarantee the addresses are in increasing order
77   void InsertLineEntry(lldb::addr_t file_addr, uint32_t line, uint16_t column,
78                        uint16_t file_idx, bool is_start_of_statement,
79                        bool is_start_of_basic_block, bool is_prologue_end,
80                        bool is_epilogue_begin, bool is_terminal_entry);
81
82   // Used to instantiate the LineSequence helper class
83   LineSequence *CreateLineSequenceContainer();
84
85   // Append an entry to a caller-provided collection that will later be
86   // inserted in this line table.
87   void AppendLineEntryToSequence(LineSequence *sequence, lldb::addr_t file_addr,
88                                  uint32_t line, uint16_t column,
89                                  uint16_t file_idx, bool is_start_of_statement,
90                                  bool is_start_of_basic_block,
91                                  bool is_prologue_end, bool is_epilogue_begin,
92                                  bool is_terminal_entry);
93
94   // Insert a sequence of entries into this line table.
95   void InsertSequence(LineSequence *sequence);
96
97   //------------------------------------------------------------------
98   /// Dump all line entries in this line table to the stream \a s.
99   ///
100   /// @param[in] s
101   ///     The stream to which to dump the object description.
102   ///
103   /// @param[in] style
104   ///     The display style for the address.
105   ///
106   /// @see Address::DumpStyle
107   //------------------------------------------------------------------
108   void Dump(Stream *s, Target *target, Address::DumpStyle style,
109             Address::DumpStyle fallback_style, bool show_line_ranges);
110
111   void GetDescription(Stream *s, Target *target, lldb::DescriptionLevel level);
112
113   //------------------------------------------------------------------
114   /// Find a line entry that contains the section offset address \a
115   /// so_addr.
116   ///
117   /// @param[in] so_addr
118   ///     A section offset address object containing the address we
119   ///     are searching for.
120   ///
121   /// @param[out] line_entry
122   ///     A copy of the line entry that was found if \b true is
123   ///     returned, otherwise \a entry is left unmodified.
124   ///
125   /// @param[out] index_ptr
126   ///     A pointer to a 32 bit integer that will get the actual line
127   ///     entry index if it is not nullptr.
128   ///
129   /// @return
130   ///     Returns \b true if \a so_addr is contained in a line entry
131   ///     in this line table, \b false otherwise.
132   //------------------------------------------------------------------
133   bool FindLineEntryByAddress(const Address &so_addr, LineEntry &line_entry,
134                               uint32_t *index_ptr = nullptr);
135
136   //------------------------------------------------------------------
137   /// Find a line entry index that has a matching file index and
138   /// source line number.
139   ///
140   /// Finds the next line entry that has a matching \a file_idx and
141   /// source line number \a line starting at the \a start_idx entries
142   /// into the line entry collection.
143   ///
144   /// @param[in] start_idx
145   ///     The number of entries to skip when starting the search.
146   ///
147   /// @param[out] file_idx
148   ///     The file index to search for that should be found prior
149   ///     to calling this function using the following functions:
150   ///     CompileUnit::GetSupportFiles()
151   ///     FileSpecList::FindFileIndex (uint32_t, const FileSpec &) const
152   ///
153   /// @param[in] line
154   ///     The source line to match.
155   ///
156   /// @param[in] exact
157   ///     If true, match only if you find a line entry exactly matching \a line.
158   ///     If false, return the closest line entry greater than \a line.
159   ///
160   /// @param[out] line_entry
161   ///     A reference to a line entry object that will get a copy of
162   ///     the line entry if \b true is returned, otherwise \a
163   ///     line_entry is left untouched.
164   ///
165   /// @return
166   ///     Returns \b true if a matching line entry is found in this
167   ///     line table, \b false otherwise.
168   ///
169   /// @see CompileUnit::GetSupportFiles()
170   /// @see FileSpecList::FindFileIndex (uint32_t, const FileSpec &) const
171   //------------------------------------------------------------------
172   uint32_t FindLineEntryIndexByFileIndex(uint32_t start_idx, uint32_t file_idx,
173                                          uint32_t line, bool exact,
174                                          LineEntry *line_entry_ptr);
175
176   uint32_t FindLineEntryIndexByFileIndex(
177       uint32_t start_idx, const std::vector<uint32_t> &file_indexes,
178       uint32_t line, bool exact, LineEntry *line_entry_ptr);
179
180   size_t FineLineEntriesForFileIndex(uint32_t file_idx, bool append,
181                                      SymbolContextList &sc_list);
182
183   //------------------------------------------------------------------
184   /// Get the line entry from the line table at index \a idx.
185   ///
186   /// @param[in] idx
187   ///     An index into the line table entry collection.
188   ///
189   /// @return
190   ///     A valid line entry if \a idx is a valid index, or an invalid
191   ///     line entry if \a idx is not valid.
192   ///
193   /// @see LineTable::GetSize()
194   /// @see LineEntry::IsValid() const
195   //------------------------------------------------------------------
196   bool GetLineEntryAtIndex(uint32_t idx, LineEntry &line_entry);
197
198   //------------------------------------------------------------------
199   /// Gets the size of the line table in number of line table entries.
200   ///
201   /// @return
202   ///     The number of line table entries in this line table.
203   //------------------------------------------------------------------
204   uint32_t GetSize() const;
205
206   typedef lldb_private::RangeArray<lldb::addr_t, lldb::addr_t, 32>
207       FileAddressRanges;
208
209   //------------------------------------------------------------------
210   /// Gets all contiguous file address ranges for the entire line table.
211   ///
212   /// @param[out] file_ranges
213   ///     A collection of file address ranges that will be filled in
214   ///     by this function.
215   ///
216   /// @param[out] append
217   ///     If \b true, then append to \a file_ranges, otherwise clear
218   ///     \a file_ranges prior to adding any ranges.
219   ///
220   /// @return
221   ///     The number of address ranges added to \a file_ranges
222   //------------------------------------------------------------------
223   size_t GetContiguousFileAddressRanges(FileAddressRanges &file_ranges,
224                                         bool append);
225
226   //------------------------------------------------------------------
227   /// Given a file range link map, relink the current line table
228   /// and return a fixed up line table.
229   ///
230   /// @param[out] file_range_map
231   ///     A collection of file ranges that maps to new file ranges
232   ///     that will be used when linking the line table.
233   ///
234   /// @return
235   ///     A new line table if at least one line table entry was able
236   ///     to be mapped.
237   //------------------------------------------------------------------
238   typedef RangeDataVector<lldb::addr_t, lldb::addr_t, lldb::addr_t>
239       FileRangeMap;
240
241   LineTable *LinkLineTable(const FileRangeMap &file_range_map);
242
243 protected:
244   struct Entry {
245     Entry()
246         : file_addr(LLDB_INVALID_ADDRESS), line(0), column(0), file_idx(0),
247           is_start_of_statement(false), is_start_of_basic_block(false),
248           is_prologue_end(false), is_epilogue_begin(false),
249           is_terminal_entry(false) {}
250
251     Entry(lldb::addr_t _file_addr, uint32_t _line, uint16_t _column,
252           uint16_t _file_idx, bool _is_start_of_statement,
253           bool _is_start_of_basic_block, bool _is_prologue_end,
254           bool _is_epilogue_begin, bool _is_terminal_entry)
255         : file_addr(_file_addr), line(_line), column(_column),
256           file_idx(_file_idx), is_start_of_statement(_is_start_of_statement),
257           is_start_of_basic_block(_is_start_of_basic_block),
258           is_prologue_end(_is_prologue_end),
259           is_epilogue_begin(_is_epilogue_begin),
260           is_terminal_entry(_is_terminal_entry) {}
261
262     int bsearch_compare(const void *key, const void *arrmem);
263
264     void Clear() {
265       file_addr = LLDB_INVALID_ADDRESS;
266       line = 0;
267       column = 0;
268       file_idx = 0;
269       is_start_of_statement = false;
270       is_start_of_basic_block = false;
271       is_prologue_end = false;
272       is_epilogue_begin = false;
273       is_terminal_entry = false;
274     }
275
276     static int Compare(const Entry &lhs, const Entry &rhs) {
277 // Compare the sections before calling
278 #define SCALAR_COMPARE(a, b)                                                   \
279   if (a < b)                                                                   \
280     return -1;                                                                 \
281   if (a > b)                                                                   \
282   return +1
283       SCALAR_COMPARE(lhs.file_addr, rhs.file_addr);
284       SCALAR_COMPARE(lhs.line, rhs.line);
285       SCALAR_COMPARE(lhs.column, rhs.column);
286       SCALAR_COMPARE(lhs.is_start_of_statement, rhs.is_start_of_statement);
287       SCALAR_COMPARE(lhs.is_start_of_basic_block, rhs.is_start_of_basic_block);
288       // rhs and lhs reversed on purpose below.
289       SCALAR_COMPARE(rhs.is_prologue_end, lhs.is_prologue_end);
290       SCALAR_COMPARE(lhs.is_epilogue_begin, rhs.is_epilogue_begin);
291       // rhs and lhs reversed on purpose below.
292       SCALAR_COMPARE(rhs.is_terminal_entry, lhs.is_terminal_entry);
293       SCALAR_COMPARE(lhs.file_idx, rhs.file_idx);
294 #undef SCALAR_COMPARE
295       return 0;
296     }
297
298     class LessThanBinaryPredicate {
299     public:
300       LessThanBinaryPredicate(LineTable *line_table);
301       bool operator()(const LineTable::Entry &, const LineTable::Entry &) const;
302
303     protected:
304       LineTable *m_line_table;
305     };
306
307     static bool EntryAddressLessThan(const Entry &lhs, const Entry &rhs) {
308       return lhs.file_addr < rhs.file_addr;
309     }
310
311     //------------------------------------------------------------------
312     // Member variables.
313     //------------------------------------------------------------------
314     lldb::addr_t file_addr; ///< The file address for this line entry
315     uint32_t line;   ///< The source line number, or zero if there is no line
316                      ///number information.
317     uint16_t column; ///< The column number of the source line, or zero if there
318                      ///is no column information.
319     uint16_t file_idx : 11, ///< The file index into CompileUnit's file table,
320                             ///or zero if there is no file information.
321         is_start_of_statement : 1, ///< Indicates this entry is the beginning of
322                                    ///a statement.
323         is_start_of_basic_block : 1, ///< Indicates this entry is the beginning
324                                      ///of a basic block.
325         is_prologue_end : 1, ///< Indicates this entry is one (of possibly many)
326                              ///where execution should be suspended for an entry
327                              ///breakpoint of a function.
328         is_epilogue_begin : 1, ///< Indicates this entry is one (of possibly
329                                ///many) where execution should be suspended for
330                                ///an exit breakpoint of a function.
331         is_terminal_entry : 1; ///< Indicates this entry is that of the first
332                                ///byte after the end of a sequence of target
333                                ///machine instructions.
334   };
335
336   struct EntrySearchInfo {
337     LineTable *line_table;
338     lldb_private::Section *a_section;
339     Entry *a_entry;
340   };
341
342   //------------------------------------------------------------------
343   // Types
344   //------------------------------------------------------------------
345   typedef std::vector<lldb_private::Section *>
346       section_collection; ///< The collection type for the sections.
347   typedef std::vector<Entry>
348       entry_collection; ///< The collection type for the line entries.
349   //------------------------------------------------------------------
350   // Member variables.
351   //------------------------------------------------------------------
352   CompileUnit
353       *m_comp_unit; ///< The compile unit that this line table belongs to.
354   entry_collection
355       m_entries; ///< The collection of line entries in this line table.
356
357   //------------------------------------------------------------------
358   // Helper class
359   //------------------------------------------------------------------
360   class LineSequenceImpl : public LineSequence {
361   public:
362     LineSequenceImpl() = default;
363
364     ~LineSequenceImpl() override = default;
365
366     void Clear() override;
367
368     entry_collection
369         m_entries; ///< The collection of line entries in this sequence.
370   };
371
372   bool ConvertEntryAtIndexToLineEntry(uint32_t idx, LineEntry &line_entry);
373
374 private:
375   DISALLOW_COPY_AND_ASSIGN(LineTable);
376 };
377
378 } // namespace lldb_private
379
380 #endif // liblldb_LineTable_h_