[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
|
|
|
|
//===-- LineTable.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/LineTable.h"
|
|
|
|
|
#include "lldb/Core/Address.h"
|
2013-03-05 05:46:16 +08:00
|
|
|
|
#include "lldb/Core/Module.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
#include "lldb/Core/Section.h"
|
|
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
|
#include "lldb/Utility/Stream.h"
|
2010-06-09 17:32:42 +08:00
|
|
|
|
#include <algorithm>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
// LineTable constructor
|
|
|
|
|
LineTable::LineTable(CompileUnit *comp_unit)
|
|
|
|
|
: m_comp_unit(comp_unit), m_entries() {}
|
|
|
|
|
|
2020-01-21 21:42:39 +08:00
|
|
|
|
LineTable::LineTable(CompileUnit *comp_unit,
|
|
|
|
|
std::vector<std::unique_ptr<LineSequence>> &&sequences)
|
2020-01-20 19:49:15 +08:00
|
|
|
|
: m_comp_unit(comp_unit), m_entries() {
|
|
|
|
|
LineTable::Entry::LessThanBinaryPredicate less_than_bp(this);
|
2020-01-21 21:04:59 +08:00
|
|
|
|
llvm::stable_sort(sequences, less_than_bp);
|
2020-01-21 21:42:39 +08:00
|
|
|
|
for (const auto &sequence : sequences) {
|
|
|
|
|
LineSequenceImpl *seq = static_cast<LineSequenceImpl *>(sequence.get());
|
2020-01-20 19:49:15 +08:00
|
|
|
|
m_entries.insert(m_entries.end(), seq->m_entries.begin(),
|
2020-01-21 21:42:39 +08:00
|
|
|
|
seq->m_entries.end());
|
2020-01-20 19:49:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
// Destructor
|
|
|
|
|
LineTable::~LineTable() {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
void LineTable::InsertLineEntry(lldb::addr_t file_addr, uint32_t line,
|
|
|
|
|
uint16_t column, uint16_t file_idx,
|
|
|
|
|
bool is_start_of_statement,
|
|
|
|
|
bool is_start_of_basic_block,
|
2013-03-05 05:46:16 +08:00
|
|
|
|
bool is_prologue_end, bool is_epilogue_begin,
|
2010-06-09 00:52:24 +08:00
|
|
|
|
bool is_terminal_entry) {
|
2013-03-05 05:46:16 +08:00
|
|
|
|
Entry entry(file_addr, line, column, file_idx, is_start_of_statement,
|
|
|
|
|
is_start_of_basic_block, is_prologue_end, is_epilogue_begin,
|
|
|
|
|
is_terminal_entry);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
LineTable::Entry::LessThanBinaryPredicate less_than_bp(this);
|
|
|
|
|
entry_collection::iterator pos =
|
2019-12-03 23:14:32 +08:00
|
|
|
|
llvm::upper_bound(m_entries, entry, less_than_bp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
// Stream s(stdout);
|
|
|
|
|
// s << "\n\nBefore:\n";
|
|
|
|
|
// Dump (&s, Address::DumpStyleFileAddress);
|
|
|
|
|
m_entries.insert(pos, entry);
|
|
|
|
|
// s << "After:\n";
|
|
|
|
|
// Dump (&s, Address::DumpStyleFileAddress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LineSequence::LineSequence() {}
|
|
|
|
|
|
2013-01-05 06:57:56 +08:00
|
|
|
|
void LineTable::LineSequenceImpl::Clear() { m_entries.clear(); }
|
|
|
|
|
|
2020-01-21 21:42:39 +08:00
|
|
|
|
std::unique_ptr<LineSequence> LineTable::CreateLineSequenceContainer() {
|
|
|
|
|
return std::make_unique<LineTable::LineSequenceImpl>();
|
2013-01-05 06:57:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LineTable::AppendLineEntryToSequence(
|
|
|
|
|
LineSequence *sequence, lldb::addr_t file_addr, uint32_t line,
|
|
|
|
|
uint16_t column, uint16_t file_idx, bool is_start_of_statement,
|
|
|
|
|
bool is_start_of_basic_block, bool is_prologue_end, bool is_epilogue_begin,
|
2010-06-09 00:52:24 +08:00
|
|
|
|
bool is_terminal_entry) {
|
2013-01-05 06:57:56 +08:00
|
|
|
|
assert(sequence != nullptr);
|
|
|
|
|
LineSequenceImpl *seq = reinterpret_cast<LineSequenceImpl *>(sequence);
|
2013-03-05 05:46:16 +08:00
|
|
|
|
Entry entry(file_addr, line, column, file_idx, is_start_of_statement,
|
|
|
|
|
is_start_of_basic_block, is_prologue_end, is_epilogue_begin,
|
|
|
|
|
is_terminal_entry);
|
2014-06-19 03:55:34 +08:00
|
|
|
|
entry_collection &entries = seq->m_entries;
|
|
|
|
|
// Replace the last entry if the address is the same, otherwise append it. If
|
2018-05-01 00:49:04 +08:00
|
|
|
|
// we have multiple line entries at the same address, this indicates illegal
|
|
|
|
|
// DWARF so this "fixes" the line table to be correct. If not fixed this can
|
|
|
|
|
// cause a line entry's address that when resolved back to a symbol context,
|
|
|
|
|
// could resolve to a different line entry. We really want a
|
2014-06-19 03:55:34 +08:00
|
|
|
|
// 1 to 1 mapping
|
2018-05-01 00:49:04 +08:00
|
|
|
|
// here to avoid these kinds of inconsistencies. We will need tor revisit
|
|
|
|
|
// this if the DWARF line tables are updated to allow multiple entries at the
|
|
|
|
|
// same address legally.
|
2013-01-05 06:57:56 +08:00
|
|
|
|
if (!entries.empty() && entries.back().file_addr == file_addr) {
|
2015-09-16 20:36:37 +08:00
|
|
|
|
// GCC don't use the is_prologue_end flag to mark the first instruction
|
|
|
|
|
// after the prologue.
|
2016-07-19 23:28:02 +08:00
|
|
|
|
// Instead of it it is issuing a line table entry for the first instruction
|
2018-05-01 00:49:04 +08:00
|
|
|
|
// of the prologue and one for the first instruction after the prologue. If
|
|
|
|
|
// the size of the prologue is 0 instruction then the 2 line entry will
|
|
|
|
|
// have the same file address. Removing it will remove our ability to
|
|
|
|
|
// properly detect the location of the end of prologe so we set the
|
|
|
|
|
// prologue_end flag to preserve this information (setting the prologue_end
|
|
|
|
|
// flag for an entry what is after the prologue end don't have any effect)
|
2015-09-16 20:36:37 +08:00
|
|
|
|
entry.is_prologue_end = entry.file_idx == entries.back().file_idx;
|
2014-06-19 03:55:34 +08:00
|
|
|
|
entries.back() = entry;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
} else
|
2014-06-19 03:55:34 +08:00
|
|
|
|
entries.push_back(entry);
|
2013-01-05 06:57:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LineTable::InsertSequence(LineSequence *sequence) {
|
|
|
|
|
assert(sequence != nullptr);
|
|
|
|
|
LineSequenceImpl *seq = reinterpret_cast<LineSequenceImpl *>(sequence);
|
2013-03-05 05:46:16 +08:00
|
|
|
|
if (seq->m_entries.empty())
|
|
|
|
|
return;
|
2014-06-19 03:55:34 +08:00
|
|
|
|
Entry &entry = seq->m_entries.front();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2014-06-19 03:55:34 +08:00
|
|
|
|
// If the first entry address in this sequence is greater than or equal to
|
2016-07-19 23:28:02 +08:00
|
|
|
|
// the address of the last item in our entry collection, just append.
|
2015-09-16 20:36:37 +08:00
|
|
|
|
if (m_entries.empty() ||
|
|
|
|
|
!Entry::EntryAddressLessThan(entry, m_entries.back())) {
|
|
|
|
|
m_entries.insert(m_entries.end(), seq->m_entries.begin(),
|
|
|
|
|
seq->m_entries.end());
|
|
|
|
|
return;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-16 20:36:37 +08:00
|
|
|
|
// Otherwise, find where this belongs in the collection
|
|
|
|
|
entry_collection::iterator begin_pos = m_entries.begin();
|
2013-03-05 05:46:16 +08:00
|
|
|
|
entry_collection::iterator end_pos = m_entries.end();
|
2013-01-05 06:57:56 +08:00
|
|
|
|
LineTable::Entry::LessThanBinaryPredicate less_than_bp(this);
|
|
|
|
|
entry_collection::iterator pos =
|
|
|
|
|
upper_bound(begin_pos, end_pos, entry, less_than_bp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2016-01-08 09:39:14 +08:00
|
|
|
|
// We should never insert a sequence in the middle of another sequence
|
|
|
|
|
if (pos != begin_pos) {
|
|
|
|
|
while (pos < end_pos && !((pos - 1)->is_terminal_entry))
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-07 08:14:20 +08:00
|
|
|
|
#ifndef NDEBUG
|
2013-01-05 06:57:56 +08:00
|
|
|
|
// If we aren't inserting at the beginning, the previous entry should
|
|
|
|
|
// terminate a sequence.
|
|
|
|
|
if (pos != begin_pos) {
|
|
|
|
|
entry_collection::iterator prev_pos = pos - 1;
|
|
|
|
|
assert(prev_pos->is_terminal_entry);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2013-03-05 05:46:16 +08:00
|
|
|
|
m_entries.insert(pos, seq->m_entries.begin(), seq->m_entries.end());
|
2013-01-05 06:57:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
LineTable::Entry::LessThanBinaryPredicate::LessThanBinaryPredicate(
|
|
|
|
|
LineTable *line_table)
|
|
|
|
|
: m_line_table(line_table) {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
bool LineTable::Entry::LessThanBinaryPredicate::
|
|
|
|
|
operator()(const LineTable::Entry &a, const LineTable::Entry &b) const {
|
2013-03-05 05:46:16 +08:00
|
|
|
|
#define LT_COMPARE(a, b) \
|
|
|
|
|
if (a != b) \
|
|
|
|
|
return a < b
|
|
|
|
|
LT_COMPARE(a.file_addr, b.file_addr);
|
|
|
|
|
// b and a reversed on purpose below.
|
|
|
|
|
LT_COMPARE(b.is_terminal_entry, a.is_terminal_entry);
|
|
|
|
|
LT_COMPARE(a.line, b.line);
|
|
|
|
|
LT_COMPARE(a.column, b.column);
|
|
|
|
|
LT_COMPARE(a.is_start_of_statement, b.is_start_of_statement);
|
|
|
|
|
LT_COMPARE(a.is_start_of_basic_block, b.is_start_of_basic_block);
|
|
|
|
|
// b and a reversed on purpose below.
|
|
|
|
|
LT_COMPARE(b.is_prologue_end, a.is_prologue_end);
|
|
|
|
|
LT_COMPARE(a.is_epilogue_begin, b.is_epilogue_begin);
|
|
|
|
|
LT_COMPARE(a.file_idx, b.file_idx);
|
|
|
|
|
return false;
|
|
|
|
|
#undef LT_COMPARE
|
2010-06-09 17:32:42 +08:00
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
2020-01-20 19:49:15 +08:00
|
|
|
|
bool LineTable::Entry::LessThanBinaryPredicate::
|
2020-01-21 21:42:39 +08:00
|
|
|
|
operator()(const std::unique_ptr<LineSequence> &sequence_a,
|
|
|
|
|
const std::unique_ptr<LineSequence> &sequence_b) const {
|
|
|
|
|
auto *seq_a = static_cast<const LineSequenceImpl *>(sequence_a.get());
|
|
|
|
|
auto *seq_b = static_cast<const LineSequenceImpl *>(sequence_b.get());
|
2020-01-20 19:49:15 +08:00
|
|
|
|
return (*this)(seq_a->m_entries.front(), seq_b->m_entries.front());
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
uint32_t LineTable::GetSize() const { return m_entries.size(); }
|
|
|
|
|
|
|
|
|
|
bool LineTable::GetLineEntryAtIndex(uint32_t idx, LineEntry &line_entry) {
|
|
|
|
|
if (idx < m_entries.size()) {
|
|
|
|
|
ConvertEntryAtIndexToLineEntry(idx, line_entry);
|
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
line_entry.Clear();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LineTable::FindLineEntryByAddress(const Address &so_addr,
|
|
|
|
|
LineEntry &line_entry,
|
|
|
|
|
uint32_t *index_ptr) {
|
|
|
|
|
if (index_ptr != nullptr)
|
|
|
|
|
*index_ptr = UINT32_MAX;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
bool success = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
if (so_addr.GetModule().get() == m_comp_unit->GetModule().get()) {
|
|
|
|
|
Entry search_entry;
|
2013-03-05 05:46:16 +08:00
|
|
|
|
search_entry.file_addr = so_addr.GetFileAddress();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
if (search_entry.file_addr != LLDB_INVALID_ADDRESS) {
|
|
|
|
|
entry_collection::const_iterator begin_pos = m_entries.begin();
|
|
|
|
|
entry_collection::const_iterator end_pos = m_entries.end();
|
|
|
|
|
entry_collection::const_iterator pos = lower_bound(
|
|
|
|
|
begin_pos, end_pos, search_entry, Entry::EntryAddressLessThan);
|
2013-03-05 05:46:16 +08:00
|
|
|
|
if (pos != end_pos) {
|
|
|
|
|
if (pos != begin_pos) {
|
2010-06-09 00:52:24 +08:00
|
|
|
|
if (pos->file_addr != search_entry.file_addr)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
--pos;
|
2013-03-05 05:46:16 +08:00
|
|
|
|
else if (pos->file_addr == search_entry.file_addr) {
|
2018-05-01 00:49:04 +08:00
|
|
|
|
// If this is a termination entry, it shouldn't match since entries
|
|
|
|
|
// with the "is_terminal_entry" member set to true are termination
|
|
|
|
|
// entries that define the range for the previous entry.
|
2010-06-09 00:52:24 +08:00
|
|
|
|
if (pos->is_terminal_entry) {
|
2018-05-01 00:49:04 +08:00
|
|
|
|
// The matching entry is a terminal entry, so we skip ahead to
|
|
|
|
|
// the next entry to see if there is another entry following this
|
|
|
|
|
// one whose section/offset matches.
|
2010-06-09 00:52:24 +08:00
|
|
|
|
++pos;
|
2013-03-05 05:46:16 +08:00
|
|
|
|
if (pos != end_pos) {
|
2010-06-09 00:52:24 +08:00
|
|
|
|
if (pos->file_addr != search_entry.file_addr)
|
|
|
|
|
pos = end_pos;
|
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
2013-03-05 05:46:16 +08:00
|
|
|
|
if (pos != end_pos) {
|
2018-05-01 00:49:04 +08:00
|
|
|
|
// While in the same section/offset backup to find the first line
|
|
|
|
|
// entry that matches the address in case there are multiple
|
2013-03-05 05:46:16 +08:00
|
|
|
|
while (pos != begin_pos) {
|
|
|
|
|
entry_collection::const_iterator prev_pos = pos - 1;
|
|
|
|
|
if (prev_pos->file_addr == search_entry.file_addr &&
|
|
|
|
|
prev_pos->is_terminal_entry == false)
|
|
|
|
|
--pos;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-07-07 07:34:08 +08:00
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
}
|
2017-03-21 03:19:03 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
2018-05-01 00:49:04 +08:00
|
|
|
|
// There might be code in the containing objfile before the first
|
|
|
|
|
// line table entry. Make sure that does not get considered part of
|
|
|
|
|
// the first line table entry.
|
2017-03-21 03:19:03 +08:00
|
|
|
|
if (pos->file_addr > so_addr.GetFileAddress())
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
|
|
// Make sure we have a valid match and that the match isn't a
|
2018-05-01 00:49:04 +08:00
|
|
|
|
// terminating entry for a previous line...
|
2013-03-05 05:46:16 +08:00
|
|
|
|
if (pos != end_pos && pos->is_terminal_entry == false) {
|
|
|
|
|
uint32_t match_idx = std::distance(begin_pos, pos);
|
2016-05-12 06:46:53 +08:00
|
|
|
|
success = ConvertEntryAtIndexToLineEntry(match_idx, line_entry);
|
2013-03-05 05:46:16 +08:00
|
|
|
|
if (index_ptr != nullptr && success)
|
|
|
|
|
*index_ptr = match_idx;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-12 14:24:05 +08:00
|
|
|
|
bool LineTable::ConvertEntryAtIndexToLineEntry(uint32_t idx,
|
|
|
|
|
LineEntry &line_entry) {
|
2019-08-06 14:52:05 +08:00
|
|
|
|
if (idx >= m_entries.size())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const Entry &entry = m_entries[idx];
|
|
|
|
|
ModuleSP module_sp(m_comp_unit->GetModule());
|
|
|
|
|
if (!module_sp)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
addr_t file_addr = entry.file_addr;
|
|
|
|
|
|
|
|
|
|
// A terminal entry can point outside of a module or a section. Decrement the
|
|
|
|
|
// address to ensure it resolves correctly.
|
|
|
|
|
if (entry.is_terminal_entry)
|
|
|
|
|
--file_addr;
|
|
|
|
|
|
|
|
|
|
if (!module_sp->ResolveFileAddress(file_addr,
|
|
|
|
|
line_entry.range.GetBaseAddress()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Now undo the decrement above.
|
|
|
|
|
if (entry.is_terminal_entry)
|
|
|
|
|
line_entry.range.GetBaseAddress().Slide(1);
|
|
|
|
|
|
|
|
|
|
if (!entry.is_terminal_entry && idx + 1 < m_entries.size())
|
|
|
|
|
line_entry.range.SetByteSize(m_entries[idx + 1].file_addr -
|
|
|
|
|
entry.file_addr);
|
|
|
|
|
else
|
|
|
|
|
line_entry.range.SetByteSize(0);
|
|
|
|
|
|
|
|
|
|
line_entry.file =
|
|
|
|
|
m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx);
|
|
|
|
|
line_entry.original_file =
|
|
|
|
|
m_comp_unit->GetSupportFiles().GetFileSpecAtIndex(entry.file_idx);
|
|
|
|
|
line_entry.line = entry.line;
|
|
|
|
|
line_entry.column = entry.column;
|
|
|
|
|
line_entry.is_start_of_statement = entry.is_start_of_statement;
|
|
|
|
|
line_entry.is_start_of_basic_block = entry.is_start_of_basic_block;
|
|
|
|
|
line_entry.is_prologue_end = entry.is_prologue_end;
|
|
|
|
|
line_entry.is_epilogue_begin = entry.is_epilogue_begin;
|
|
|
|
|
line_entry.is_terminal_entry = entry.is_terminal_entry;
|
|
|
|
|
return true;
|
2010-09-12 14:24:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
uint32_t LineTable::FindLineEntryIndexByFileIndex(
|
2021-05-05 12:28:28 +08:00
|
|
|
|
uint32_t start_idx, uint32_t file_idx,
|
2021-05-05 07:03:10 +08:00
|
|
|
|
const SourceLocationSpec &src_location_spec, LineEntry *line_entry_ptr) {
|
2021-05-05 12:28:28 +08:00
|
|
|
|
auto file_idx_matcher = [](uint32_t file_index, uint16_t entry_file_idx) {
|
|
|
|
|
return file_index == entry_file_idx;
|
|
|
|
|
};
|
|
|
|
|
return FindLineEntryIndexByFileIndexImpl<uint32_t>(
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2021-05-05 12:28:28 +08:00
|
|
|
|
start_idx, file_idx, src_location_spec, line_entry_ptr, file_idx_matcher);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-05 07:03:10 +08:00
|
|
|
|
uint32_t LineTable::FindLineEntryIndexByFileIndex(
|
2021-05-05 12:28:28 +08:00
|
|
|
|
uint32_t start_idx, const std::vector<uint32_t> &file_idx,
|
2021-05-05 07:03:10 +08:00
|
|
|
|
const SourceLocationSpec &src_location_spec, LineEntry *line_entry_ptr) {
|
2021-05-05 12:28:28 +08:00
|
|
|
|
auto file_idx_matcher = [](const std::vector<uint32_t> &file_indexes,
|
|
|
|
|
uint16_t entry_file_idx) {
|
|
|
|
|
return llvm::is_contained(file_indexes, entry_file_idx);
|
|
|
|
|
};
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2021-05-05 12:28:28 +08:00
|
|
|
|
return FindLineEntryIndexByFileIndexImpl<std::vector<uint32_t>>(
|
|
|
|
|
start_idx, file_idx, src_location_spec, line_entry_ptr, file_idx_matcher);
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 12:19:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
size_t LineTable::FineLineEntriesForFileIndex(uint32_t file_idx, bool append,
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 12:19:37 +08:00
|
|
|
|
SymbolContextList &sc_list) {
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
|
if (!append)
|
2016-05-12 06:46:53 +08:00
|
|
|
|
sc_list.Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 12:19:37 +08:00
|
|
|
|
size_t num_added = 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
const size_t count = m_entries.size();
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 12:19:37 +08:00
|
|
|
|
if (count > 0) {
|
|
|
|
|
SymbolContext sc(m_comp_unit);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
|
|
for (size_t idx = 0; idx < count; ++idx) {
|
2018-05-01 00:49:04 +08:00
|
|
|
|
// Skip line table rows that terminate the previous row
|
|
|
|
|
// (is_terminal_entry is non-zero)
|
2010-06-09 00:52:24 +08:00
|
|
|
|
if (m_entries[idx].is_terminal_entry)
|
2010-09-15 07:36:40 +08:00
|
|
|
|
continue;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
2012-12-13 01:30:52 +08:00
|
|
|
|
if (m_entries[idx].file_idx == file_idx) {
|
|
|
|
|
if (ConvertEntryAtIndexToLineEntry(idx, sc.line_entry)) {
|
2013-03-05 05:46:16 +08:00
|
|
|
|
++num_added;
|
2012-12-13 01:30:52 +08:00
|
|
|
|
sc_list.Append(sc);
|
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2012-12-13 01:30:52 +08:00
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2012-12-13 01:30:52 +08:00
|
|
|
|
return num_added;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 05:46:16 +08:00
|
|
|
|
void LineTable::Dump(Stream *s, Target *target, Address::DumpStyle style,
|
|
|
|
|
Address::DumpStyle fallback_style, bool show_line_ranges) {
|
|
|
|
|
const size_t count = m_entries.size();
|
|
|
|
|
LineEntry line_entry;
|
2014-04-20 21:17:36 +08:00
|
|
|
|
FileSpec prev_file;
|
2013-03-05 05:46:16 +08:00
|
|
|
|
for (size_t idx = 0; idx < count; ++idx) {
|
|
|
|
|
ConvertEntryAtIndexToLineEntry(idx, line_entry);
|
|
|
|
|
line_entry.Dump(s, target, prev_file != line_entry.original_file, style,
|
|
|
|
|
fallback_style, show_line_ranges);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
s->EOL();
|
2013-03-05 05:46:16 +08:00
|
|
|
|
prev_file = line_entry.original_file;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2013-03-05 05:46:16 +08:00
|
|
|
|
}
|
2013-03-07 07:23:27 +08:00
|
|
|
|
|
|
|
|
|
void LineTable::GetDescription(Stream *s, Target *target,
|
|
|
|
|
DescriptionLevel level) {
|
|
|
|
|
const size_t count = m_entries.size();
|
2013-03-15 00:47:56 +08:00
|
|
|
|
LineEntry line_entry;
|
2013-03-07 07:23:27 +08:00
|
|
|
|
for (size_t idx = 0; idx < count; ++idx) {
|
|
|
|
|
ConvertEntryAtIndexToLineEntry(idx, line_entry);
|
|
|
|
|
line_entry.GetDescription(s, level, m_comp_unit, target, true);
|
|
|
|
|
s->EOL();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 05:46:16 +08:00
|
|
|
|
size_t LineTable::GetContiguousFileAddressRanges(FileAddressRanges &file_ranges,
|
|
|
|
|
bool append) {
|
|
|
|
|
if (!append)
|
|
|
|
|
file_ranges.Clear();
|
2012-12-13 01:30:52 +08:00
|
|
|
|
const size_t initial_count = file_ranges.GetSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2013-03-05 05:46:16 +08:00
|
|
|
|
const size_t count = m_entries.size();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
LineEntry line_entry;
|
2012-12-13 01:30:52 +08:00
|
|
|
|
FileAddressRanges::Entry range(LLDB_INVALID_ADDRESS, 0);
|
2010-09-12 14:24:05 +08:00
|
|
|
|
for (size_t idx = 0; idx < count; ++idx) {
|
2013-03-05 05:46:16 +08:00
|
|
|
|
const Entry &entry = m_entries[idx];
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2013-03-05 05:46:16 +08:00
|
|
|
|
if (entry.is_terminal_entry) {
|
2014-04-20 21:17:36 +08:00
|
|
|
|
if (range.GetRangeBase() != LLDB_INVALID_ADDRESS) {
|
|
|
|
|
range.SetRangeEnd(entry.file_addr);
|
2013-03-07 07:23:27 +08:00
|
|
|
|
file_ranges.Append(range);
|
2012-12-13 01:30:52 +08:00
|
|
|
|
range.Clear(LLDB_INVALID_ADDRESS);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2013-03-07 07:23:27 +08:00
|
|
|
|
} else if (range.GetRangeBase() == LLDB_INVALID_ADDRESS) {
|
|
|
|
|
range.SetRangeBase(entry.file_addr);
|
2013-03-05 05:46:16 +08:00
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2013-03-05 05:46:16 +08:00
|
|
|
|
return file_ranges.GetSize() - initial_count;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-15 07:36:40 +08:00
|
|
|
|
LineTable *LineTable::LinkLineTable(const FileRangeMap &file_range_map) {
|
2019-02-13 14:25:41 +08:00
|
|
|
|
std::unique_ptr<LineTable> line_table_up(new LineTable(m_comp_unit));
|
2013-03-05 05:46:16 +08:00
|
|
|
|
LineSequenceImpl sequence;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
const size_t count = m_entries.size();
|
|
|
|
|
LineEntry line_entry;
|
2014-04-20 21:17:36 +08:00
|
|
|
|
const FileRangeMap::Entry *file_range_entry = nullptr;
|
|
|
|
|
const FileRangeMap::Entry *prev_file_range_entry = nullptr;
|
2013-03-05 05:46:16 +08:00
|
|
|
|
lldb::addr_t prev_file_addr = LLDB_INVALID_ADDRESS;
|
|
|
|
|
bool prev_entry_was_linked = false;
|
2013-03-07 07:23:27 +08:00
|
|
|
|
bool range_changed = false;
|
2010-09-12 14:24:05 +08:00
|
|
|
|
for (size_t idx = 0; idx < count; ++idx) {
|
2012-12-13 01:30:52 +08:00
|
|
|
|
const Entry &entry = m_entries[idx];
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2013-03-05 05:46:16 +08:00
|
|
|
|
const bool end_sequence = entry.is_terminal_entry;
|
|
|
|
|
const lldb::addr_t lookup_file_addr =
|
|
|
|
|
entry.file_addr - (end_sequence ? 1 : 0);
|
2014-04-20 21:17:36 +08:00
|
|
|
|
if (file_range_entry == nullptr ||
|
|
|
|
|
!file_range_entry->Contains(lookup_file_addr)) {
|
2013-03-07 07:23:27 +08:00
|
|
|
|
prev_file_range_entry = file_range_entry;
|
2014-04-20 21:17:36 +08:00
|
|
|
|
file_range_entry = file_range_map.FindEntryThatContains(lookup_file_addr);
|
2013-03-07 07:23:27 +08:00
|
|
|
|
range_changed = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2012-12-13 01:30:52 +08:00
|
|
|
|
|
2013-03-07 07:23:27 +08:00
|
|
|
|
lldb::addr_t prev_end_entry_linked_file_addr = LLDB_INVALID_ADDRESS;
|
|
|
|
|
lldb::addr_t entry_linked_file_addr = LLDB_INVALID_ADDRESS;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2013-03-07 07:23:27 +08:00
|
|
|
|
bool terminate_previous_entry = false;
|
2013-03-05 05:46:16 +08:00
|
|
|
|
if (file_range_entry) {
|
2013-03-07 07:23:27 +08:00
|
|
|
|
entry_linked_file_addr = entry.file_addr -
|
|
|
|
|
file_range_entry->GetRangeBase() +
|
|
|
|
|
file_range_entry->data;
|
|
|
|
|
// Determine if we need to terminate the previous entry when the previous
|
2015-07-22 08:16:02 +08:00
|
|
|
|
// entry was not contiguous with this one after being linked.
|
2013-03-07 07:23:27 +08:00
|
|
|
|
if (range_changed && prev_file_range_entry) {
|
|
|
|
|
prev_end_entry_linked_file_addr =
|
|
|
|
|
std::min<lldb::addr_t>(entry.file_addr,
|
|
|
|
|
prev_file_range_entry->GetRangeEnd()) -
|
|
|
|
|
prev_file_range_entry->GetRangeBase() + prev_file_range_entry->data;
|
|
|
|
|
if (prev_end_entry_linked_file_addr != entry_linked_file_addr)
|
2013-03-15 00:47:56 +08:00
|
|
|
|
terminate_previous_entry = prev_entry_was_linked;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2013-03-05 05:46:16 +08:00
|
|
|
|
} else if (prev_entry_was_linked) {
|
2018-05-01 00:49:04 +08:00
|
|
|
|
// This entry doesn't have a remapping and it needs to be removed. Watch
|
|
|
|
|
// out in case we need to terminate a previous entry needs to be
|
|
|
|
|
// terminated now that one line entry in a sequence is not longer valid.
|
2015-02-11 00:53:40 +08:00
|
|
|
|
if (!sequence.m_entries.empty() &&
|
2013-03-05 05:46:16 +08:00
|
|
|
|
!sequence.m_entries.back().is_terminal_entry) {
|
2013-03-07 07:23:27 +08:00
|
|
|
|
terminate_previous_entry = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
2013-03-15 00:47:56 +08:00
|
|
|
|
if (terminate_previous_entry && !sequence.m_entries.empty()) {
|
2013-03-07 07:23:27 +08:00
|
|
|
|
assert(prev_file_addr != LLDB_INVALID_ADDRESS);
|
2017-01-20 18:24:03 +08:00
|
|
|
|
UNUSED_IF_ASSERT_DISABLED(prev_file_addr);
|
2013-03-07 07:23:27 +08:00
|
|
|
|
sequence.m_entries.push_back(sequence.m_entries.back());
|
|
|
|
|
if (prev_end_entry_linked_file_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
|
prev_end_entry_linked_file_addr =
|
|
|
|
|
std::min<lldb::addr_t>(entry.file_addr,
|
|
|
|
|
prev_file_range_entry->GetRangeEnd()) -
|
|
|
|
|
prev_file_range_entry->GetRangeBase() + prev_file_range_entry->data;
|
|
|
|
|
sequence.m_entries.back().file_addr = prev_end_entry_linked_file_addr;
|
|
|
|
|
sequence.m_entries.back().is_terminal_entry = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
2013-03-07 07:23:27 +08:00
|
|
|
|
// Append the sequence since we just terminated the previous one
|
2019-02-13 14:25:41 +08:00
|
|
|
|
line_table_up->InsertSequence(&sequence);
|
2013-03-05 05:46:16 +08:00
|
|
|
|
sequence.Clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
2013-03-07 07:23:27 +08:00
|
|
|
|
// Now link the current entry
|
2013-03-05 05:46:16 +08:00
|
|
|
|
if (file_range_entry) {
|
2013-03-07 07:23:27 +08:00
|
|
|
|
// This entry has an address remapping and it needs to have its address
|
|
|
|
|
// relinked
|
|
|
|
|
sequence.m_entries.push_back(entry);
|
|
|
|
|
sequence.m_entries.back().file_addr = entry_linked_file_addr;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 05:46:16 +08:00
|
|
|
|
// If we have items in the sequence and the last entry is a terminal entry,
|
|
|
|
|
// insert this sequence into our new line table.
|
2015-02-11 00:53:40 +08:00
|
|
|
|
if (!sequence.m_entries.empty() &&
|
2013-03-05 05:46:16 +08:00
|
|
|
|
sequence.m_entries.back().is_terminal_entry) {
|
2019-02-13 14:25:41 +08:00
|
|
|
|
line_table_up->InsertSequence(&sequence);
|
2013-03-05 05:46:16 +08:00
|
|
|
|
sequence.Clear();
|
|
|
|
|
prev_entry_was_linked = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
} else {
|
2013-03-07 07:23:27 +08:00
|
|
|
|
prev_entry_was_linked = file_range_entry != nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2013-03-07 07:23:27 +08:00
|
|
|
|
prev_file_addr = entry.file_addr;
|
|
|
|
|
range_changed = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|
2019-02-13 14:25:41 +08:00
|
|
|
|
if (line_table_up->m_entries.empty())
|
2014-04-20 21:17:36 +08:00
|
|
|
|
return nullptr;
|
2019-02-13 14:25:41 +08:00
|
|
|
|
return line_table_up.release();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
}
|