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
14using namespace lldb_private;
15
17 : range(), file_sp(std::make_shared<SupportFile>()),
18 original_file_sp(std::make_shared<SupportFile>()),
19 is_start_of_statement(0), is_start_of_basic_block(0), is_prologue_end(0),
20 is_epilogue_begin(0), is_terminal_entry(0) {}
21
23 range.Clear();
24 file_sp = std::make_shared<SupportFile>();
25 original_file_sp = std::make_shared<SupportFile>();
27 column = 0;
33}
34
35bool LineEntry::IsValid() const {
37}
38
39bool LineEntry::DumpStopContext(Stream *s, bool show_fullpaths) const {
40 const FileSpec &file = file_sp->GetSpecOnly();
41 if (file) {
42 if (show_fullpaths)
43 file.Dump(s->AsRawOstream());
44 else
45 file.GetFilename().Dump(s);
46
47 if (line)
48 s->PutChar(':');
49 }
50 if (line) {
51 s->Printf("%u", line);
52 if (column) {
53 s->PutChar(':');
54 s->Printf("%u", column);
55 }
56 }
57 return file || line;
58}
59
60bool LineEntry::Dump(Stream *s, Target *target, bool show_file,
62 Address::DumpStyle fallback_style, bool show_range) const {
63 if (show_range) {
64 // Show address range
65 if (!range.Dump(s, target, style, fallback_style))
66 return false;
67 } else {
68 // Show address only
69 if (!range.GetBaseAddress().Dump(s, target, style, fallback_style))
70 return false;
71 }
72 if (show_file)
73 *s << ", file = " << GetFile();
74 if (line)
75 s->Printf(", line = %u", line);
76 if (column)
77 s->Printf(", column = %u", column);
79 *s << ", is_start_of_statement = TRUE";
80
82 *s << ", is_start_of_basic_block = TRUE";
83
85 *s << ", is_prologue_end = TRUE";
86
88 *s << ", is_epilogue_begin = TRUE";
89
91 *s << ", is_terminal_entry = TRUE";
92 return true;
93}
94
96 CompileUnit *cu, Target *target,
97 bool show_address_only) const {
98
99 if (level == lldb::eDescriptionLevelBrief ||
101 if (show_address_only) {
104 } else {
107 }
108
109 *s << ": " << GetFile();
110
111 if (line) {
112 s->Printf(":%u", line);
113 if (column)
114 s->Printf(":%u", column);
115 }
116
117 if (level == lldb::eDescriptionLevelFull) {
119 *s << ", is_start_of_statement = TRUE";
120
122 *s << ", is_start_of_basic_block = TRUE";
123
124 if (is_prologue_end)
125 *s << ", is_prologue_end = TRUE";
126
128 *s << ", is_epilogue_begin = TRUE";
129
131 *s << ", is_terminal_entry = TRUE";
132 } else {
134 s->EOL();
135 }
136 } else {
137 return Dump(s, target, true, Address::DumpStyleLoadAddress,
139 }
140 return true;
141}
142
144 return LineEntry::Compare(a, b) < 0;
145}
146
147int LineEntry::Compare(const LineEntry &a, const LineEntry &b) {
150 if (result != 0)
151 return result;
152
153 const lldb::addr_t a_byte_size = a.range.GetByteSize();
154 const lldb::addr_t b_byte_size = b.range.GetByteSize();
155
156 if (a_byte_size < b_byte_size)
157 return -1;
158 if (a_byte_size > b_byte_size)
159 return +1;
160
161 // Check for an end sequence entry mismatch after we have determined that the
162 // address values are equal. If one of the items is an end sequence, we don't
163 // care about the line, file, or column info.
165 return -1;
167 return +1;
168
169 if (a.line < b.line)
170 return -1;
171 if (a.line > b.line)
172 return +1;
173
174 if (a.column < b.column)
175 return -1;
176 if (a.column > b.column)
177 return +1;
178
179 return FileSpec::Compare(a.GetFile(), b.GetFile(), true);
180}
181
183 bool include_inlined_functions) const {
184 // Add each LineEntry's range to complete_line_range until we find a
185 // different file / line number.
186 AddressRange complete_line_range = range;
187 auto symbol_context_scope = lldb::eSymbolContextLineEntry;
188 Declaration start_call_site(original_file_sp->GetSpecOnly(), line);
189 if (include_inlined_functions)
190 symbol_context_scope |= lldb::eSymbolContextBlock;
191
192 while (true) {
193 SymbolContext next_line_sc;
194 Address range_end(complete_line_range.GetBaseAddress());
195 range_end.Slide(complete_line_range.GetByteSize());
196 range_end.CalculateSymbolContext(&next_line_sc, symbol_context_scope);
197
198 if (!next_line_sc.line_entry.IsValid() ||
199 next_line_sc.line_entry.range.GetByteSize() == 0)
200 break;
201
202 if (original_file_sp->Equal(*next_line_sc.line_entry.original_file_sp,
204 (next_line_sc.line_entry.line == 0 ||
205 line == next_line_sc.line_entry.line)) {
206 // Include any line 0 entries - they indicate that this is compiler-
207 // generated code that does not correspond to user source code.
208 // next_line_sc is the same file & line as this LineEntry, so extend
209 // our AddressRange by its size and continue to see if there are more
210 // LineEntries that we can combine. However, if there was nothing to
211 // extend we're done.
212 if (!complete_line_range.Extend(next_line_sc.line_entry.range))
213 break;
214 continue;
215 }
216
217 if (include_inlined_functions && next_line_sc.block &&
218 next_line_sc.block->GetContainingInlinedBlock() != nullptr) {
219 // The next_line_sc might be in a different file if it's an inlined
220 // function. If this is the case then we still want to expand our line
221 // range to include them if the inlined function is at the same call site
222 // as this line entry. The current block could represent a nested inline
223 // function call so we need to need to check up the block tree to see if
224 // we find one.
225 auto inlined_parent_block =
227 start_call_site);
228 if (!inlined_parent_block)
229 // We didn't find any parent inlined block with a call site at this line
230 // entry so this inlined function is probably at another line.
231 break;
232 // Extend our AddressRange by the size of the inlined block, but if there
233 // was nothing to add then we're done.
234 if (!complete_line_range.Extend(next_line_sc.line_entry.range))
235 break;
236 continue;
237 }
238
239 break;
240 }
241 return complete_line_range;
242}
243
245 if (target_sp) {
246 // Apply any file remappings to our file.
247 if (auto new_file_spec = target_sp->GetSourcePathMap().FindFile(
248 original_file_sp->GetSpecOnly())) {
249 file_sp = std::make_shared<SupportFile>(*new_file_spec,
250 original_file_sp->GetChecksum());
251 }
252 }
253}
A section + offset based address range class.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
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.
void Clear()
Clear the object's state.
bool Extend(const AddressRange &rhs_range)
Extends this range with rhs_range if it overlaps this range on the right side.
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:223
A section + offset based address class.
Definition: Address.h:62
static int CompareFileAddress(const Address &lhs, const Address &rhs)
Compare two Address objects.
Definition: Address.cpp:932
uint32_t CalculateSymbolContext(SymbolContext *sc, lldb::SymbolContextItem resolve_scope=lldb::eSymbolContextEverything) const
Reconstruct a symbol context from an address.
Definition: Address.cpp:832
DumpStyle
Dump styles allow the Address::Dump(Stream *,DumpStyle) const function to display Address contents in...
Definition: Address.h:66
@ DumpStyleFileAddress
Display as the file address (if any).
Definition: Address.h:87
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
Definition: Address.h:93
@ DumpStyleLoadAddress
Display as the load address (if resolved).
Definition: Address.h:99
bool Slide(int64_t offset)
Definition: Address.h:459
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX, bool all_ranges=false, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Dump a description of this object to a Stream.
Definition: Address.cpp:408
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:355
Block * GetContainingInlinedBlockWithCallSite(const Declaration &find_call_site)
Get the inlined block at the given call site that contains this block.
Definition: Block.cpp:225
Block * GetContainingInlinedBlock()
Get the inlined block that contains this block.
Definition: Block.cpp:208
A class that describes a compilation unit.
Definition: CompileUnit.h:41
void Dump(Stream *s, const char *value_if_empty=nullptr) const
Dump the object description to a stream.
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
A file utility class.
Definition: FileSpec.h:56
const ConstString & GetFilename() const
Filename string const get accessor.
Definition: FileSpec.h:240
static int Compare(const FileSpec &lhs, const FileSpec &rhs, bool full)
Compare two FileSpec objects.
Definition: FileSpec.cpp:273
void Dump(llvm::raw_ostream &s) const
Dump this object to a Stream.
Definition: FileSpec.cpp:325
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:401
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutChar(char ch)
Definition: Stream.cpp:131
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:155
Wraps either a FileSpec that represents a local file or a source file whose contents is known (for ex...
Definition: SupportFile.h:21
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Block * block
The Block for a given query.
LineEntry line_entry
The LineEntry for a given query.
#define LLDB_INVALID_LINE_NUMBER
Definition: lldb-defines.h:94
A class that represents a running process on the host machine.
bool operator<(const Address &lhs, const Address &rhs)
Definition: Address.cpp:992
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelBrief
@ eDescriptionLevelFull
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:443
A line table entry class.
Definition: LineEntry.h:21
uint16_t column
The column number of the source line, or zero if there is no column information.
Definition: LineEntry.h:151
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:165
void Clear()
Clear the object's state.
Definition: LineEntry.cpp:22
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:60
lldb::SupportFileSP original_file_sp
The original source file, from debug info.
Definition: LineEntry.h:143
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:182
bool IsValid() const
Check if a line entry object is valid.
Definition: LineEntry.cpp:35
static int Compare(const LineEntry &lhs, const LineEntry &rhs)
Compare two LineEntry objects.
Definition: LineEntry.cpp:147
AddressRange range
The section offset address range for this line entry.
Definition: LineEntry.h:137
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition: LineEntry.h:147
LineEntry()
Default constructor.
Definition: LineEntry.cpp:16
bool GetDescription(Stream *s, lldb::DescriptionLevel level, CompileUnit *cu, Target *target, bool show_address_only) const
Definition: LineEntry.cpp:95
uint16_t is_start_of_basic_block
Indicates this entry is the beginning of a basic block.
Definition: LineEntry.h:157
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:39
const FileSpec & GetFile() const
Helper to access the file.
Definition: LineEntry.h:134
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:161
lldb::SupportFileSP file_sp
The source file, possibly mapped by the target.source-map setting.
Definition: LineEntry.h:140
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:169
void ApplyFileMappings(lldb::TargetSP target_sp)
Apply file mappings from target.source-map to the LineEntry's file.
Definition: LineEntry.cpp:244
uint16_t is_start_of_statement
Indicates this entry is the beginning of a statement.
Definition: LineEntry.h:154