LLDB  mainline
LineEntry.cpp
Go to the documentation of this file.
1 //===-- LineEntry.cpp -----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
11 #include "lldb/Target/Process.h"
12 #include "lldb/Target/Target.h"
13 
14 using namespace lldb_private;
15 
17  : range(), file(), is_start_of_statement(0), is_start_of_basic_block(0),
18  is_prologue_end(0), is_epilogue_begin(0), is_terminal_entry(0) {}
19 
20 LineEntry::LineEntry(const lldb::SectionSP &section_sp,
21  lldb::addr_t section_offset, lldb::addr_t byte_size,
22  const FileSpec &_file, uint32_t _line, uint16_t _column,
23  bool _is_start_of_statement, bool _is_start_of_basic_block,
24  bool _is_prologue_end, bool _is_epilogue_begin,
25  bool _is_terminal_entry)
26  : range(section_sp, section_offset, byte_size), file(_file),
27  original_file(_file), line(_line), column(_column),
28  is_start_of_statement(_is_start_of_statement),
29  is_start_of_basic_block(_is_start_of_basic_block),
30  is_prologue_end(_is_prologue_end), is_epilogue_begin(_is_epilogue_begin),
31  is_terminal_entry(_is_terminal_entry) {}
32 
34  range.Clear();
35  file.Clear();
38  column = 0;
41  is_prologue_end = 0;
44 }
45 
46 bool LineEntry::IsValid() const {
48 }
49 
50 bool LineEntry::DumpStopContext(Stream *s, bool show_fullpaths) const {
51  if (file) {
52  if (show_fullpaths)
53  file.Dump(s->AsRawOstream());
54  else
55  file.GetFilename().Dump(s);
56 
57  if (line)
58  s->PutChar(':');
59  }
60  if (line) {
61  s->Printf("%u", line);
62  if (column) {
63  s->PutChar(':');
64  s->Printf("%u", column);
65  }
66  }
67  return file || line;
68 }
69 
70 bool LineEntry::Dump(Stream *s, Target *target, bool show_file,
71  Address::DumpStyle style,
72  Address::DumpStyle fallback_style, bool show_range) const {
73  if (show_range) {
74  // Show address range
75  if (!range.Dump(s, target, style, fallback_style))
76  return false;
77  } else {
78  // Show address only
79  if (!range.GetBaseAddress().Dump(s, target, style, fallback_style))
80  return false;
81  }
82  if (show_file)
83  *s << ", file = " << file;
84  if (line)
85  s->Printf(", line = %u", line);
86  if (column)
87  s->Printf(", column = %u", column);
89  *s << ", is_start_of_statement = TRUE";
90 
92  *s << ", is_start_of_basic_block = TRUE";
93 
94  if (is_prologue_end)
95  *s << ", is_prologue_end = TRUE";
96 
98  *s << ", is_epilogue_begin = TRUE";
99 
100  if (is_terminal_entry)
101  *s << ", is_terminal_entry = TRUE";
102  return true;
103 }
104 
106  CompileUnit *cu, Target *target,
107  bool show_address_only) const {
108 
109  if (level == lldb::eDescriptionLevelBrief ||
110  level == lldb::eDescriptionLevelFull) {
111  if (show_address_only) {
114  } else {
117  }
118 
119  *s << ": " << file;
120 
121  if (line) {
122  s->Printf(":%u", line);
123  if (column)
124  s->Printf(":%u", column);
125  }
126 
127  if (level == lldb::eDescriptionLevelFull) {
129  *s << ", is_start_of_statement = TRUE";
130 
132  *s << ", is_start_of_basic_block = TRUE";
133 
134  if (is_prologue_end)
135  *s << ", is_prologue_end = TRUE";
136 
137  if (is_epilogue_begin)
138  *s << ", is_epilogue_begin = TRUE";
139 
140  if (is_terminal_entry)
141  *s << ", is_terminal_entry = TRUE";
142  } else {
143  if (is_terminal_entry)
144  s->EOL();
145  }
146  } else {
147  return Dump(s, target, true, Address::DumpStyleLoadAddress,
149  }
150  return true;
151 }
152 
153 bool lldb_private::operator<(const LineEntry &a, const LineEntry &b) {
154  return LineEntry::Compare(a, b) < 0;
155 }
156 
157 int LineEntry::Compare(const LineEntry &a, const LineEntry &b) {
159  b.range.GetBaseAddress());
160  if (result != 0)
161  return result;
162 
163  const lldb::addr_t a_byte_size = a.range.GetByteSize();
164  const lldb::addr_t b_byte_size = b.range.GetByteSize();
165 
166  if (a_byte_size < b_byte_size)
167  return -1;
168  if (a_byte_size > b_byte_size)
169  return +1;
170 
171  // Check for an end sequence entry mismatch after we have determined that the
172  // address values are equal. If one of the items is an end sequence, we don't
173  // care about the line, file, or column info.
175  return -1;
177  return +1;
178 
179  if (a.line < b.line)
180  return -1;
181  if (a.line > b.line)
182  return +1;
183 
184  if (a.column < b.column)
185  return -1;
186  if (a.column > b.column)
187  return +1;
188 
189  return FileSpec::Compare(a.file, b.file, true);
190 }
191 
193  bool include_inlined_functions) const {
194  // Add each LineEntry's range to complete_line_range until we find a
195  // different file / line number.
196  AddressRange complete_line_range = range;
197  auto symbol_context_scope = lldb::eSymbolContextLineEntry;
198  Declaration start_call_site(original_file, line);
199  if (include_inlined_functions)
200  symbol_context_scope |= lldb::eSymbolContextBlock;
201 
202  while (true) {
203  SymbolContext next_line_sc;
204  Address range_end(complete_line_range.GetBaseAddress());
205  range_end.Slide(complete_line_range.GetByteSize());
206  range_end.CalculateSymbolContext(&next_line_sc, symbol_context_scope);
207 
208  if (!next_line_sc.line_entry.IsValid() ||
209  next_line_sc.line_entry.range.GetByteSize() == 0)
210  break;
211 
212  if (original_file == next_line_sc.line_entry.original_file &&
213  (next_line_sc.line_entry.line == 0 ||
214  line == next_line_sc.line_entry.line)) {
215  // Include any line 0 entries - they indicate that this is compiler-
216  // generated code that does not correspond to user source code.
217  // next_line_sc is the same file & line as this LineEntry, so extend
218  // our AddressRange by its size and continue to see if there are more
219  // LineEntries that we can combine. However, if there was nothing to
220  // extend we're done.
221  if (!complete_line_range.Extend(next_line_sc.line_entry.range))
222  break;
223  continue;
224  }
225 
226  if (include_inlined_functions && next_line_sc.block &&
227  next_line_sc.block->GetContainingInlinedBlock() != nullptr) {
228  // The next_line_sc might be in a different file if it's an inlined
229  // function. If this is the case then we still want to expand our line
230  // range to include them if the inlined function is at the same call site
231  // as this line entry. The current block could represent a nested inline
232  // function call so we need to need to check up the block tree to see if
233  // we find one.
234  auto inlined_parent_block =
236  start_call_site);
237  if (!inlined_parent_block)
238  // We didn't find any parent inlined block with a call site at this line
239  // entry so this inlined function is probably at another line.
240  break;
241  // Extend our AddressRange by the size of the inlined block, but if there
242  // was nothing to add then we're done.
243  if (!complete_line_range.Extend(next_line_sc.line_entry.range))
244  break;
245  continue;
246  }
247 
248  break;
249  }
250  return complete_line_range;
251 }
252 
253 void LineEntry::ApplyFileMappings(lldb::TargetSP target_sp) {
254  if (target_sp) {
255  // Apply any file remappings to our file.
256  if (auto new_file_spec =
257  target_sp->GetSourcePathMap().FindFile(original_file))
258  file = *new_file_spec;
259  }
260 }
lldb_private::AddressRange::GetBaseAddress
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:209
lldb_private::SymbolContext::block
Block * block
The Block for a given query.
Definition: SymbolContext.h:321
lldb_private::LineEntry::Compare
static int Compare(const LineEntry &lhs, const LineEntry &rhs)
Compare two LineEntry objects.
Definition: LineEntry.cpp:157
lldb_private::LineEntry::file
FileSpec file
The source file, possibly mapped by the target.source-map setting.
Definition: LineEntry.h:140
lldb_private::Address::IsValid
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:336
lldb_private::LineEntry::DumpStopContext
bool DumpStopContext(Stream *s, bool show_fullpaths) const
Dumps information specific to a process that stops at this line entry to the supplied stream s.
Definition: LineEntry.cpp:50
CompileUnit.h
lldb_private::LineEntry::IsValid
bool IsValid() const
Check if a line entry object is valid.
Definition: LineEntry.cpp:46
lldb_private::Address::DumpStyleFileAddress
@ DumpStyleFileAddress
Display as the file address (if any).
Definition: Address.h:84
lldb_private::LineEntry::is_prologue_end
uint16_t is_prologue_end
Indicates this entry is one (of possibly many) where execution should be suspended for an entry break...
Definition: LineEntry.h:155
lldb_private::AddressRange::GetByteSize
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:221
lldb_private::LineEntry::GetSameLineContiguousAddressRange
AddressRange GetSameLineContiguousAddressRange(bool include_inlined_functions) const
Give the range for this LineEntry + any additional LineEntries for this same source line that are con...
Definition: LineEntry.cpp:192
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::Target
Definition: Target.h:451
Process.h
lldb_private::LineEntry::GetDescription
bool GetDescription(Stream *s, lldb::DescriptionLevel level, CompileUnit *cu, Target *target, bool show_address_only) const
Definition: LineEntry.cpp:105
lldb_private::CompileUnit
Definition: CompileUnit.h:38
Target.h
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::FileSpec::Compare
static int Compare(const FileSpec &lhs, const FileSpec &rhs, bool full)
Compare two FileSpec objects.
Definition: FileSpec.cpp:274
lldb_private::LineEntry::Dump
bool Dump(Stream *s, Target *target, bool show_file, Address::DumpStyle style, Address::DumpStyle fallback_style, bool show_range) const
Dump a description of this object to a Stream.
Definition: LineEntry.cpp:70
lldb_private::LineEntry::ApplyFileMappings
void ApplyFileMappings(lldb::TargetSP target_sp)
Apply file mappings from target.source-map to the LineEntry's file.
Definition: LineEntry.cpp:253
lldb_private::Address::DumpStyleLoadAddress
@ DumpStyleLoadAddress
Display as the load address (if resolved).
Definition: Address.h:96
LineEntry.h
lldb::eDescriptionLevelFull
@ eDescriptionLevelFull
Definition: lldb-enumerations.h:209
lldb_private::AddressRange
Definition: AddressRange.h:25
lldb_private::LineEntry::column
uint16_t column
The column number of the source line, or zero if there is no column information.
Definition: LineEntry.h:146
lldb_private::Stream::PutChar
size_t PutChar(char ch)
Definition: Stream.cpp:104
lldb_private::ConstString::Dump
void Dump(Stream *s, const char *value_if_empty=nullptr) const
Dump the object description to a stream.
Definition: ConstString.cpp:283
lldb_private::Block::GetContainingInlinedBlockWithCallSite
Block * GetContainingInlinedBlockWithCallSite(const Declaration &find_call_site)
Get the inlined block at the given call site that contains this block.
Definition: Block.cpp:214
lldb_private::Address::DumpStyleModuleWithFileAddress
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
Definition: Address.h:90
lldb_private::LineEntry::original_file
FileSpec original_file
The original source file, from debug info.
Definition: LineEntry.h:142
lldb_private::LineEntry::line
uint32_t line
The source line number, or zero if there is no line number information.
Definition: LineEntry.h:143
LLDB_INVALID_LINE_NUMBER
#define LLDB_INVALID_LINE_NUMBER
Definition: lldb-defines.h:98
lldb_private::FileSpec::Clear
void Clear()
Clears the object state.
Definition: FileSpec.cpp:261
lldb_private::AddressRange::Extend
bool Extend(const AddressRange &rhs_range)
Extends this range with rhs_range if it overlaps this range on the right side.
Definition: AddressRange.cpp:134
lldb_private::Address::CompareFileAddress
static int CompareFileAddress(const Address &lhs, const Address &rhs)
Compare two Address objects.
Definition: Address.cpp:908
lldb_private::AddressRange::Clear
void Clear()
Clear the object's state.
Definition: AddressRange.cpp:152
uint32_t
lldb_private::LineEntry::LineEntry
LineEntry()
Default constructor.
Definition: LineEntry.cpp:16
lldb_private::AddressRange::Dump
bool Dump(Stream *s, Target *target, Address::DumpStyle style, Address::DumpStyle fallback_style=Address::DumpStyleInvalid) const
Dump a description of this object to a Stream.
Definition: AddressRange.cpp:157
lldb_private::Address
Definition: Address.h:59
lldb_private::Stream::EOL
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:128
lldb_private::Stream::AsRawOstream
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:357
lldb_private::LineEntry::range
AddressRange range
The section offset address range for this line entry.
Definition: LineEntry.h:139
lldb_private::operator<
bool operator<(const Address &lhs, const Address &rhs)
Definition: Address.cpp:968
lldb_private::Address::Dump
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX) const
Dump a description of this object to a Stream.
Definition: Address.cpp:405
uint16_t
lldb_private::FileSpec::Dump
void Dump(llvm::raw_ostream &s) const
Dump this object to a Stream.
Definition: FileSpec.cpp:324
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::LineEntry::is_start_of_basic_block
uint16_t is_start_of_basic_block
Indicates this entry is the beginning of a basic block.
Definition: LineEntry.h:152
lldb_private::LineEntry::Clear
void Clear()
Clear the object's state.
Definition: LineEntry.cpp:33
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Address::DumpStyle
DumpStyle
Dump styles allow the Address::Dump(Stream *,DumpStyle) const function to display Address contents in...
Definition: Address.h:63
lldb_private::SymbolContext::line_entry
LineEntry line_entry
The LineEntry for a given query.
Definition: SymbolContext.h:322
lldb_private::Declaration
Definition: Declaration.h:24
lldb_private::Address::Slide
bool Slide(int64_t offset)
Definition: Address.h:440
lldb_private::LineEntry::is_start_of_statement
uint16_t is_start_of_statement
Indicates this entry is the beginning of a statement.
Definition: LineEntry.h:150
lldb_private::FileSpec::GetFilename
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:341
lldb_private::Address::CalculateSymbolContext
uint32_t CalculateSymbolContext(SymbolContext *sc, lldb::SymbolContextItem resolve_scope=lldb::eSymbolContextEverything) const
Reconstruct a symbol context from an address.
Definition: Address.cpp:808
lldb_private::LineEntry
Definition: LineEntry.h:20
lldb_private::Block::GetContainingInlinedBlock
Block * GetContainingInlinedBlock()
Get the inlined block that contains this block.
Definition: Block.cpp:197
lldb::eDescriptionLevelBrief
@ eDescriptionLevelBrief
Definition: lldb-enumerations.h:208
lldb_private::LineEntry::is_epilogue_begin
uint16_t is_epilogue_begin
Indicates this entry is one (of possibly many) where execution should be suspended for an exit breakp...
Definition: LineEntry.h:158
lldb::DescriptionLevel
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
Definition: lldb-enumerations.h:207
lldb_private::LineEntry::is_terminal_entry
uint16_t is_terminal_entry
Indicates this entry is that of the first byte after the end of a sequence of target machine instruct...
Definition: LineEntry.h:159