1 //===-- LineEntry.cpp -------------------------------------------*- 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 #include "lldb/Symbol/LineEntry.h"
11 #include "lldb/Symbol/CompileUnit.h"
12 #include "lldb/Target/Process.h"
13 #include "lldb/Target/Target.h"
15 using namespace lldb_private;
17 LineEntry::LineEntry() :
20 line(LLDB_INVALID_LINE_NUMBER),
22 is_start_of_statement(0),
23 is_start_of_basic_block(0),
32 const lldb::SectionSP §ion_sp,
33 lldb::addr_t section_offset,
34 lldb::addr_t byte_size,
35 const FileSpec &_file,
38 bool _is_start_of_statement,
39 bool _is_start_of_basic_block,
40 bool _is_prologue_end,
41 bool _is_epilogue_begin,
42 bool _is_terminal_entry
44 range(section_sp, section_offset, byte_size),
48 is_start_of_statement(_is_start_of_statement),
49 is_start_of_basic_block(_is_start_of_basic_block),
50 is_prologue_end(_is_prologue_end),
51 is_epilogue_begin(_is_epilogue_begin),
52 is_terminal_entry(_is_terminal_entry)
61 line = LLDB_INVALID_LINE_NUMBER;
63 is_start_of_statement = 0;
64 is_start_of_basic_block = 0;
66 is_epilogue_begin = 0;
67 is_terminal_entry = 0;
72 LineEntry::IsValid() const
74 return range.GetBaseAddress().IsValid() && line != LLDB_INVALID_LINE_NUMBER;
78 LineEntry::DumpStopContext(Stream *s, bool show_fullpaths) const
86 file.GetFilename().Dump (s);
93 s->Printf ("%u", line);
106 Address::DumpStyle style,
107 Address::DumpStyle fallback_style,
113 // Show address range
114 if (!range.Dump(s, target, style, fallback_style))
120 if (!range.GetBaseAddress().Dump(s,
127 *s << ", file = " << file;
129 s->Printf(", line = %u", line);
131 s->Printf(", column = %u", column);
132 if (is_start_of_statement)
133 *s << ", is_start_of_statement = TRUE";
135 if (is_start_of_basic_block)
136 *s << ", is_start_of_basic_block = TRUE";
139 *s << ", is_prologue_end = TRUE";
141 if (is_epilogue_begin)
142 *s << ", is_epilogue_begin = TRUE";
144 if (is_terminal_entry)
145 *s << ", is_terminal_entry = TRUE";
150 LineEntry::GetDescription (Stream *s, lldb::DescriptionLevel level, CompileUnit* cu, Target *target, bool show_address_only) const
153 if (level == lldb::eDescriptionLevelBrief || level == lldb::eDescriptionLevelFull)
155 if (show_address_only)
157 range.GetBaseAddress().Dump(s, target, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress);
161 range.Dump(s, target, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress);
168 s->Printf(":%u", line);
170 s->Printf(":%u", column);
174 if (level == lldb::eDescriptionLevelFull)
176 if (is_start_of_statement)
177 *s << ", is_start_of_statement = TRUE";
179 if (is_start_of_basic_block)
180 *s << ", is_start_of_basic_block = TRUE";
183 *s << ", is_prologue_end = TRUE";
185 if (is_epilogue_begin)
186 *s << ", is_epilogue_begin = TRUE";
188 if (is_terminal_entry)
189 *s << ", is_terminal_entry = TRUE";
193 if (is_terminal_entry)
199 return Dump (s, target, true, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress, true);
206 lldb_private::operator< (const LineEntry& a, const LineEntry& b)
208 return LineEntry::Compare (a, b) < 0;
212 LineEntry::Compare (const LineEntry& a, const LineEntry& b)
214 int result = Address::CompareFileAddress (a.range.GetBaseAddress(), b.range.GetBaseAddress());
218 const lldb::addr_t a_byte_size = a.range.GetByteSize();
219 const lldb::addr_t b_byte_size = b.range.GetByteSize();
221 if (a_byte_size < b_byte_size)
223 if (a_byte_size > b_byte_size)
226 // Check for an end sequence entry mismatch after we have determined
227 // that the address values are equal. If one of the items is an end
228 // sequence, we don't care about the line, file, or column info.
229 if (a.is_terminal_entry > b.is_terminal_entry)
231 if (a.is_terminal_entry < b.is_terminal_entry)
239 if (a.column < b.column)
241 if (a.column > b.column)
244 return FileSpec::Compare (a.file, b.file, true);
248 LineEntry::GetSameLineContiguousAddressRange () const
250 // Add each LineEntry's range to complete_line_range until we find
251 // a different file / line number.
252 AddressRange complete_line_range = range;
256 SymbolContext next_line_sc;
257 Address range_end (complete_line_range.GetBaseAddress());
258 range_end.Slide (complete_line_range.GetByteSize());
259 range_end.CalculateSymbolContext (&next_line_sc, lldb::eSymbolContextLineEntry);
261 if (next_line_sc.line_entry.IsValid()
262 && next_line_sc.line_entry.range.GetByteSize() > 0
263 && file == next_line_sc.line_entry.file)
265 // Include any line 0 entries - they indicate that this is compiler-generated code
266 // that does not correspond to user source code.
267 if (next_line_sc.line_entry.line == 0)
269 complete_line_range.SetByteSize (complete_line_range.GetByteSize() + next_line_sc.line_entry.range.GetByteSize());
273 if (line == next_line_sc.line_entry.line)
275 // next_line_sc is the same file & line as this LineEntry, so extend our
276 // AddressRange by its size and continue to see if there are more LineEntries
277 // that we can combine.
278 complete_line_range.SetByteSize (complete_line_range.GetByteSize() + next_line_sc.line_entry.range.GetByteSize());
284 return complete_line_range;