1 //===-- LineTable.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_LineTable_h_
11 #define liblldb_LineTable_h_
15 #include "lldb/lldb-private.h"
16 #include "lldb/Symbol/LineEntry.h"
17 #include "lldb/Core/ModuleChild.h"
18 #include "lldb/Core/Section.h"
19 #include "lldb/Core/RangeMap.h"
21 namespace lldb_private {
23 //----------------------------------------------------------------------
24 /// @class LineSequence LineTable.h "lldb/Symbol/LineTable.h"
25 /// @brief An abstract base class used during symbol table creation.
26 //----------------------------------------------------------------------
39 DISALLOW_COPY_AND_ASSIGN (LineSequence);
42 //----------------------------------------------------------------------
43 /// @class LineTable LineTable.h "lldb/Symbol/LineTable.h"
44 /// @brief A line table class.
45 //----------------------------------------------------------------------
49 //------------------------------------------------------------------
50 /// Construct with compile unit.
52 /// @param[in] comp_unit
53 /// The compile unit to which this line table belongs.
54 //------------------------------------------------------------------
55 LineTable (CompileUnit* comp_unit);
57 //------------------------------------------------------------------
59 //------------------------------------------------------------------
62 //------------------------------------------------------------------
63 /// Adds a new line entry to this line table.
65 /// All line entries are maintained in file address order.
67 /// @param[in] line_entry
68 /// A const reference to a new line_entry to add to this line
71 /// @see Address::DumpStyle
72 //------------------------------------------------------------------
74 // AddLineEntry (const LineEntry& line_entry);
76 // Called when you can't guarantee the addresses are in increasing order
78 InsertLineEntry (lldb::addr_t file_addr,
82 bool is_start_of_statement,
83 bool is_start_of_basic_block,
85 bool is_epilogue_begin,
86 bool is_terminal_entry);
88 // Used to instantiate the LineSequence helper classw
90 CreateLineSequenceContainer ();
92 // Append an entry to a caller-provided collection that will later be
93 // inserted in this line table.
95 AppendLineEntryToSequence (LineSequence* sequence,
96 lldb::addr_t file_addr,
100 bool is_start_of_statement,
101 bool is_start_of_basic_block,
102 bool is_prologue_end,
103 bool is_epilogue_begin,
104 bool is_terminal_entry);
106 // Insert a sequence of entries into this line table.
108 InsertSequence (LineSequence* sequence);
110 //------------------------------------------------------------------
111 /// Dump all line entries in this line table to the stream \a s.
114 /// The stream to which to dump the object descripton.
117 /// The display style for the address.
119 /// @see Address::DumpStyle
120 //------------------------------------------------------------------
122 Dump (Stream *s, Target *target,
123 Address::DumpStyle style,
124 Address::DumpStyle fallback_style,
125 bool show_line_ranges);
128 GetDescription (Stream *s,
130 lldb::DescriptionLevel level);
132 //------------------------------------------------------------------
133 /// Find a line entry that contains the section offset address \a
136 /// @param[in] so_addr
137 /// A section offset address object containing the address we
138 /// are searching for.
140 /// @param[out] line_entry
141 /// A copy of the line entry that was found if \b true is
142 /// returned, otherwise \a entry is left unmodified.
144 /// @param[out] index_ptr
145 /// A pointer to a 32 bit integer that will get the actual line
146 /// entry index if it is not NULL.
149 /// Returns \b true if \a so_addr is contained in a line entry
150 /// in this line table, \b false otherwise.
151 //------------------------------------------------------------------
153 FindLineEntryByAddress (const Address &so_addr, LineEntry& line_entry, uint32_t *index_ptr = NULL);
155 //------------------------------------------------------------------
156 /// Find a line entry index that has a matching file index and
157 /// source line number.
159 /// Finds the next line entry that has a matching \a file_idx and
160 /// source line number \a line starting at the \a start_idx entries
161 /// into the line entry collection.
163 /// @param[in] start_idx
164 /// The number of entries to skip when starting the search.
166 /// @param[out] file_idx
167 /// The file index to search for that should be found prior
168 /// to calling this function using the following functions:
169 /// CompileUnit::GetSupportFiles()
170 /// FileSpecList::FindFileIndex (uint32_t, const FileSpec &) const
173 /// The source line to match.
176 /// If true, match only if you find a line entry exactly matching \a line.
177 /// If false, return the closest line entry greater than \a line.
179 /// @param[out] line_entry
180 /// A reference to a line entry object that will get a copy of
181 /// the line entry if \b true is returned, otherwise \a
182 /// line_entry is left untouched.
185 /// Returns \b true if a matching line entry is found in this
186 /// line table, \b false otherwise.
188 /// @see CompileUnit::GetSupportFiles()
189 /// @see FileSpecList::FindFileIndex (uint32_t, const FileSpec &) const
190 //------------------------------------------------------------------
192 FindLineEntryIndexByFileIndex (uint32_t start_idx,
196 LineEntry* line_entry_ptr);
199 FindLineEntryIndexByFileIndex (uint32_t start_idx,
200 const std::vector<uint32_t> &file_indexes,
203 LineEntry* line_entry_ptr);
206 FineLineEntriesForFileIndex (uint32_t file_idx,
208 SymbolContextList &sc_list);
210 //------------------------------------------------------------------
211 /// Get the line entry from the line table at index \a idx.
214 /// An index into the line table entry collection.
217 /// A valid line entry if \a idx is a valid index, or an invalid
218 /// line entry if \a idx is not valid.
220 /// @see LineTable::GetSize()
221 /// @see LineEntry::IsValid() const
222 //------------------------------------------------------------------
224 GetLineEntryAtIndex(uint32_t idx, LineEntry& line_entry);
226 //------------------------------------------------------------------
227 /// Gets the size of the line table in number of line table entries.
230 /// The number of line table entries in this line table.
231 //------------------------------------------------------------------
235 typedef lldb_private::RangeArray<lldb::addr_t, lldb::addr_t, 32> FileAddressRanges;
237 //------------------------------------------------------------------
238 /// Gets all contiguous file address ranges for the entire line table.
240 /// @param[out] file_ranges
241 /// A collection of file address ranges that will be filled in
242 /// by this function.
244 /// @param[out] append
245 /// If \b true, then append to \a file_ranges, otherwise clear
246 /// \a file_ranges prior to adding any ranges.
249 /// The number of address ranges added to \a file_ranges
250 //------------------------------------------------------------------
252 GetContiguousFileAddressRanges (FileAddressRanges &file_ranges, bool append);
254 //------------------------------------------------------------------
255 /// Given a file range link map, relink the current line table
256 /// and return a fixed up line table.
258 /// @param[out] file_range_map
259 /// A collection of file ranges that maps to new file ranges
260 /// that will be used when linking the line table.
263 /// A new line table if at least one line table entry was able
265 //------------------------------------------------------------------
266 typedef RangeDataVector<lldb::addr_t, lldb::addr_t, lldb::addr_t> FileRangeMap;
269 LinkLineTable (const FileRangeMap &file_range_map);
276 file_addr (LLDB_INVALID_ADDRESS),
280 is_start_of_statement (false),
281 is_start_of_basic_block (false),
282 is_prologue_end (false),
283 is_epilogue_begin (false),
284 is_terminal_entry (false)
288 Entry ( lldb::addr_t _file_addr,
292 bool _is_start_of_statement,
293 bool _is_start_of_basic_block,
294 bool _is_prologue_end,
295 bool _is_epilogue_begin,
296 bool _is_terminal_entry) :
297 file_addr (_file_addr),
300 file_idx (_file_idx),
301 is_start_of_statement (_is_start_of_statement),
302 is_start_of_basic_block (_is_start_of_basic_block),
303 is_prologue_end (_is_prologue_end),
304 is_epilogue_begin (_is_epilogue_begin),
305 is_terminal_entry (_is_terminal_entry)
310 bsearch_compare (const void *key, const void *arrmem);
315 file_addr = LLDB_INVALID_ADDRESS;
319 is_start_of_statement = false;
320 is_start_of_basic_block = false;
321 is_prologue_end = false;
322 is_epilogue_begin = false;
323 is_terminal_entry = false;
327 Compare (const Entry& lhs, const Entry& rhs)
329 // Compare the sections before calling
330 #define SCALAR_COMPARE(a,b) if (a < b) return -1; if (a > b) return +1
331 SCALAR_COMPARE (lhs.file_addr, rhs.file_addr);
332 SCALAR_COMPARE (lhs.line, rhs.line);
333 SCALAR_COMPARE (lhs.column, rhs.column);
334 SCALAR_COMPARE (lhs.is_start_of_statement, rhs.is_start_of_statement);
335 SCALAR_COMPARE (lhs.is_start_of_basic_block, rhs.is_start_of_basic_block);
336 // rhs and lhs reversed on purpose below.
337 SCALAR_COMPARE (rhs.is_prologue_end, lhs.is_prologue_end);
338 SCALAR_COMPARE (lhs.is_epilogue_begin, rhs.is_epilogue_begin);
339 // rhs and lhs reversed on purpose below.
340 SCALAR_COMPARE (rhs.is_terminal_entry, lhs.is_terminal_entry);
341 SCALAR_COMPARE (lhs.file_idx, rhs.file_idx);
342 #undef SCALAR_COMPARE
347 class LessThanBinaryPredicate
350 LessThanBinaryPredicate(LineTable *line_table);
351 bool operator() (const LineTable::Entry&, const LineTable::Entry&) const;
353 LineTable *m_line_table;
356 static bool EntryAddressLessThan (const Entry& lhs, const Entry& rhs)
358 return lhs.file_addr < rhs.file_addr;
361 //------------------------------------------------------------------
363 //------------------------------------------------------------------
364 lldb::addr_t file_addr; ///< The file address for this line entry
365 uint32_t line; ///< The source line number, or zero if there is no line number information.
366 uint16_t column; ///< The column number of the source line, or zero if there is no column information.
367 uint16_t file_idx:11, ///< The file index into CompileUnit's file table, or zero if there is no file information.
368 is_start_of_statement:1, ///< Indicates this entry is the beginning of a statement.
369 is_start_of_basic_block:1, ///< Indicates this entry is the beginning of a basic block.
370 is_prologue_end:1, ///< Indicates this entry is one (of possibly many) where execution should be suspended for an entry breakpoint of a function.
371 is_epilogue_begin:1, ///< Indicates this entry is one (of possibly many) where execution should be suspended for an exit breakpoint of a function.
372 is_terminal_entry:1; ///< Indicates this entry is that of the first byte after the end of a sequence of target machine instructions.
375 struct EntrySearchInfo
377 LineTable* line_table;
378 lldb_private::Section *a_section;
382 //------------------------------------------------------------------
384 //------------------------------------------------------------------
385 typedef std::vector<lldb_private::Section*> section_collection; ///< The collection type for the sections.
386 typedef std::vector<Entry> entry_collection; ///< The collection type for the line entries.
387 //------------------------------------------------------------------
389 //------------------------------------------------------------------
390 CompileUnit* m_comp_unit; ///< The compile unit that this line table belongs to.
391 entry_collection m_entries; ///< The collection of line entries in this line table.
393 //------------------------------------------------------------------
395 //------------------------------------------------------------------
396 class LineSequenceImpl : public LineSequence
410 entry_collection m_entries; ///< The collection of line entries in this sequence.
414 ConvertEntryAtIndexToLineEntry (uint32_t idx, LineEntry &line_entry);
417 DISALLOW_COPY_AND_ASSIGN (LineTable);
420 } // namespace lldb_private
422 #endif // liblldb_LineTable_h_