[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- LineEntry.cpp -----------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Symbol/LineEntry.h"
|
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
2010-09-15 07:36:40 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
LineEntry::LineEntry()
|
|
|
|
: range(), file(), is_start_of_statement(0), is_start_of_basic_block(0),
|
|
|
|
is_prologue_end(0), is_epilogue_begin(0), is_terminal_entry(0) {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
LineEntry::LineEntry(const lldb::SectionSP §ion_sp,
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb::addr_t section_offset, lldb::addr_t byte_size,
|
|
|
|
const FileSpec &_file, uint32_t _line, uint16_t _column,
|
|
|
|
bool _is_start_of_statement, bool _is_start_of_basic_block,
|
|
|
|
bool _is_prologue_end, bool _is_epilogue_begin,
|
|
|
|
bool _is_terminal_entry)
|
2012-02-24 09:59:29 +08:00
|
|
|
: range(section_sp, section_offset, byte_size), file(_file),
|
2016-05-12 06:46:53 +08:00
|
|
|
original_file(_file), line(_line), column(_column),
|
2010-06-09 00:52:24 +08:00
|
|
|
is_start_of_statement(_is_start_of_statement),
|
|
|
|
is_start_of_basic_block(_is_start_of_basic_block),
|
2010-07-06 03:13:23 +08:00
|
|
|
is_prologue_end(_is_prologue_end), is_epilogue_begin(_is_epilogue_begin),
|
|
|
|
is_terminal_entry(_is_terminal_entry) {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void LineEntry::Clear() {
|
|
|
|
range.Clear();
|
|
|
|
file.Clear();
|
2016-05-12 06:46:53 +08:00
|
|
|
original_file.Clear();
|
2013-09-27 09:15:46 +08:00
|
|
|
line = LLDB_INVALID_LINE_NUMBER;
|
2010-06-09 00:52:24 +08:00
|
|
|
column = 0;
|
|
|
|
is_start_of_statement = 0;
|
|
|
|
is_start_of_basic_block = 0;
|
|
|
|
is_prologue_end = 0;
|
|
|
|
is_epilogue_begin = 0;
|
|
|
|
is_terminal_entry = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LineEntry::IsValid() const {
|
|
|
|
return range.GetBaseAddress().IsValid() && line != LLDB_INVALID_LINE_NUMBER;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LineEntry::DumpStopContext(Stream *s, bool show_fullpaths) const {
|
|
|
|
if (file) {
|
2010-09-03 05:44:10 +08:00
|
|
|
if (show_fullpaths)
|
2019-12-06 15:38:23 +08:00
|
|
|
file.Dump(s->AsRawOstream());
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2016-05-12 06:46:53 +08:00
|
|
|
file.GetFilename().Dump(s);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (line)
|
|
|
|
s->PutChar(':');
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2018-08-30 23:11:00 +08:00
|
|
|
if (line) {
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Printf("%u", line);
|
2018-08-30 23:11:00 +08:00
|
|
|
if (column) {
|
|
|
|
s->PutChar(':');
|
|
|
|
s->Printf("%u", column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return file || line;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
bool LineEntry::Dump(Stream *s, Target *target, bool show_file,
|
|
|
|
Address::DumpStyle style,
|
|
|
|
Address::DumpStyle fallback_style, bool show_range) const {
|
|
|
|
if (show_range) {
|
2013-09-27 09:15:46 +08:00
|
|
|
// Show address range
|
2010-09-15 07:36:40 +08:00
|
|
|
if (!range.Dump(s, target, style, fallback_style))
|
2013-09-27 09:15:46 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2010-06-09 00:52:24 +08:00
|
|
|
// Show address only
|
2013-09-27 09:15:46 +08:00
|
|
|
if (!range.GetBaseAddress().Dump(s, target, style, fallback_style))
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-29 05:30:43 +08:00
|
|
|
if (show_file)
|
|
|
|
*s << ", file = " << file;
|
2013-09-27 09:15:46 +08:00
|
|
|
if (line)
|
|
|
|
s->Printf(", line = %u", line);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (column)
|
|
|
|
s->Printf(", column = %u", column);
|
|
|
|
if (is_start_of_statement)
|
|
|
|
*s << ", is_start_of_statement = TRUE";
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (is_start_of_basic_block)
|
|
|
|
*s << ", is_start_of_basic_block = TRUE";
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (is_prologue_end)
|
|
|
|
*s << ", is_prologue_end = TRUE";
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-09-27 09:15:46 +08:00
|
|
|
if (is_epilogue_begin)
|
2010-06-09 00:52:24 +08:00
|
|
|
*s << ", is_epilogue_begin = TRUE";
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-09-27 09:15:46 +08:00
|
|
|
if (is_terminal_entry)
|
2010-06-09 00:52:24 +08:00
|
|
|
*s << ", is_terminal_entry = TRUE";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-03 05:44:10 +08:00
|
|
|
bool LineEntry::GetDescription(Stream *s, lldb::DescriptionLevel level,
|
|
|
|
CompileUnit *cu, Target *target,
|
|
|
|
bool show_address_only) const {
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (level == lldb::eDescriptionLevelBrief ||
|
|
|
|
level == lldb::eDescriptionLevelFull) {
|
2010-09-03 05:44:10 +08:00
|
|
|
if (show_address_only) {
|
|
|
|
range.GetBaseAddress().Dump(s, target, Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleFileAddress);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2010-06-09 00:52:24 +08:00
|
|
|
range.Dump(s, target, Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleFileAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
*s << ": " << file;
|
|
|
|
|
|
|
|
if (line) {
|
2010-09-15 07:36:40 +08:00
|
|
|
s->Printf(":%u", line);
|
|
|
|
if (column)
|
2010-06-09 00:52:24 +08:00
|
|
|
s->Printf(":%u", column);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (level == lldb::eDescriptionLevelFull) {
|
|
|
|
if (is_start_of_statement)
|
|
|
|
*s << ", is_start_of_statement = TRUE";
|
|
|
|
|
|
|
|
if (is_start_of_basic_block)
|
|
|
|
*s << ", is_start_of_basic_block = TRUE";
|
|
|
|
|
|
|
|
if (is_prologue_end)
|
|
|
|
*s << ", is_prologue_end = TRUE";
|
|
|
|
|
|
|
|
if (is_epilogue_begin)
|
|
|
|
*s << ", is_epilogue_begin = TRUE";
|
|
|
|
|
|
|
|
if (is_terminal_entry)
|
|
|
|
*s << ", is_terminal_entry = TRUE";
|
2010-06-29 05:30:43 +08:00
|
|
|
} else {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (is_terminal_entry)
|
|
|
|
s->EOL();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2010-09-15 07:36:40 +08:00
|
|
|
return Dump(s, target, true, Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleModuleWithFileAddress, true);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lldb_private::operator<(const LineEntry &a, const LineEntry &b) {
|
|
|
|
return LineEntry::Compare(a, b) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LineEntry::Compare(const LineEntry &a, const LineEntry &b) {
|
|
|
|
int result = Address::CompareFileAddress(a.range.GetBaseAddress(),
|
|
|
|
b.range.GetBaseAddress());
|
|
|
|
if (result != 0)
|
|
|
|
return result;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const lldb::addr_t a_byte_size = a.range.GetByteSize();
|
|
|
|
const lldb::addr_t b_byte_size = b.range.GetByteSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (a_byte_size < b_byte_size)
|
|
|
|
return -1;
|
|
|
|
if (a_byte_size > b_byte_size)
|
|
|
|
return +1;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Check for an end sequence entry mismatch after we have determined that the
|
|
|
|
// address values are equal. If one of the items is an end sequence, we don't
|
|
|
|
// care about the line, file, or column info.
|
2010-06-09 00:52:24 +08:00
|
|
|
if (a.is_terminal_entry > b.is_terminal_entry)
|
|
|
|
return -1;
|
|
|
|
if (a.is_terminal_entry < b.is_terminal_entry)
|
|
|
|
return +1;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (a.line < b.line)
|
|
|
|
return -1;
|
|
|
|
if (a.line > b.line)
|
|
|
|
return +1;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (a.column < b.column)
|
|
|
|
return -1;
|
|
|
|
if (a.column > b.column)
|
|
|
|
return +1;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return FileSpec::Compare(a.file, b.file, true);
|
|
|
|
}
|
|
|
|
|
2019-05-07 04:01:21 +08:00
|
|
|
AddressRange LineEntry::GetSameLineContiguousAddressRange(
|
|
|
|
bool include_inlined_functions) const {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Add each LineEntry's range to complete_line_range until we find a
|
|
|
|
// different file / line number.
|
2015-12-15 08:40:30 +08:00
|
|
|
AddressRange complete_line_range = range;
|
2019-05-07 04:01:21 +08:00
|
|
|
auto symbol_context_scope = lldb::eSymbolContextLineEntry;
|
|
|
|
Declaration start_call_site(original_file, line);
|
|
|
|
if (include_inlined_functions)
|
|
|
|
symbol_context_scope |= lldb::eSymbolContextBlock;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-12-15 08:40:30 +08:00
|
|
|
while (true) {
|
|
|
|
SymbolContext next_line_sc;
|
|
|
|
Address range_end(complete_line_range.GetBaseAddress());
|
|
|
|
range_end.Slide(complete_line_range.GetByteSize());
|
2019-05-07 04:01:21 +08:00
|
|
|
range_end.CalculateSymbolContext(&next_line_sc, symbol_context_scope);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-05-07 04:01:21 +08:00
|
|
|
if (!next_line_sc.line_entry.IsValid() ||
|
|
|
|
next_line_sc.line_entry.range.GetByteSize() == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (original_file == next_line_sc.line_entry.original_file &&
|
|
|
|
(next_line_sc.line_entry.line == 0 ||
|
|
|
|
line == next_line_sc.line_entry.line)) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Include any line 0 entries - they indicate that this is compiler-
|
|
|
|
// generated code that does not correspond to user source code.
|
2019-05-07 04:01:21 +08:00
|
|
|
// next_line_sc is the same file & line as this LineEntry, so extend
|
|
|
|
// our AddressRange by its size and continue to see if there are more
|
|
|
|
// LineEntries that we can combine. However, if there was nothing to
|
|
|
|
// extend we're done.
|
|
|
|
if (!complete_line_range.Extend(next_line_sc.line_entry.range))
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (include_inlined_functions && next_line_sc.block &&
|
|
|
|
next_line_sc.block->GetContainingInlinedBlock() != nullptr) {
|
|
|
|
// The next_line_sc might be in a different file if it's an inlined
|
|
|
|
// function. If this is the case then we still want to expand our line
|
|
|
|
// range to include them if the inlined function is at the same call site
|
|
|
|
// as this line entry. The current block could represent a nested inline
|
|
|
|
// function call so we need to need to check up the block tree to see if
|
|
|
|
// we find one.
|
|
|
|
auto inlined_parent_block =
|
|
|
|
next_line_sc.block->GetContainingInlinedBlockWithCallSite(
|
|
|
|
start_call_site);
|
|
|
|
if (!inlined_parent_block)
|
|
|
|
// We didn't find any parent inlined block with a call site at this line
|
|
|
|
// entry so this inlined function is probably at another line.
|
|
|
|
break;
|
|
|
|
// Extend our AddressRange by the size of the inlined block, but if there
|
|
|
|
// was nothing to add then we're done.
|
|
|
|
if (!complete_line_range.Extend(next_line_sc.line_entry.range))
|
|
|
|
break;
|
|
|
|
continue;
|
2015-12-15 08:40:30 +08:00
|
|
|
}
|
2019-05-07 04:01:21 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-12-15 08:40:30 +08:00
|
|
|
return complete_line_range;
|
|
|
|
}
|
2016-05-12 06:46:53 +08:00
|
|
|
|
|
|
|
void LineEntry::ApplyFileMappings(lldb::TargetSP target_sp) {
|
|
|
|
if (target_sp) {
|
2021-06-30 05:59:12 +08:00
|
|
|
// Apply any file remappings to our file.
|
|
|
|
if (auto new_file_spec =
|
|
|
|
target_sp->GetSourcePathMap().FindFile(original_file))
|
|
|
|
file = *new_file_spec;
|
2016-05-12 06:46:53 +08:00
|
|
|
}
|
|
|
|
}
|