[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
|
|
|
//===-- VariableList.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/VariableList.h"
|
2010-10-11 07:55:27 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/Block.h"
|
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
|
|
|
#include "lldb/Symbol/Function.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/RegularExpression.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
// VariableList constructor
|
|
|
|
VariableList::VariableList() : m_variables() {}
|
|
|
|
|
|
|
|
// Destructor
|
2021-07-03 02:27:37 +08:00
|
|
|
VariableList::~VariableList() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void VariableList::AddVariable(const VariableSP &var_sp) {
|
2010-10-11 07:55:27 +08:00
|
|
|
m_variables.push_back(var_sp);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-07-09 05:46:14 +08:00
|
|
|
bool VariableList::AddVariableIfUnique(const lldb::VariableSP &var_sp) {
|
2010-10-11 07:55:27 +08:00
|
|
|
if (FindVariableIndex(var_sp) == UINT32_MAX) {
|
|
|
|
m_variables.push_back(var_sp);
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-10-11 07:55:27 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 03:35:13 +08:00
|
|
|
void VariableList::AddVariables(VariableList *variable_list) {
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
if (variable_list) {
|
|
|
|
std::copy(variable_list->m_variables.begin(), // source begin
|
|
|
|
variable_list->m_variables.end(), // source end
|
|
|
|
back_inserter(m_variables)); // destination
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-11 07:55:27 +08:00
|
|
|
void VariableList::Clear() { m_variables.clear(); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
VariableSP VariableList::GetVariableAtIndex(size_t idx) const {
|
2010-10-11 07:55:27 +08:00
|
|
|
VariableSP var_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (idx < m_variables.size())
|
2010-10-11 07:55:27 +08:00
|
|
|
var_sp = m_variables[idx];
|
|
|
|
return var_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
VariableSP VariableList::RemoveVariableAtIndex(size_t idx) {
|
2011-07-09 05:46:14 +08:00
|
|
|
VariableSP var_sp;
|
|
|
|
if (idx < m_variables.size()) {
|
|
|
|
var_sp = m_variables[idx];
|
|
|
|
m_variables.erase(m_variables.begin() + idx);
|
|
|
|
}
|
|
|
|
return var_sp;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-11 07:55:27 +08:00
|
|
|
uint32_t VariableList::FindVariableIndex(const VariableSP &var_sp) {
|
|
|
|
iterator pos, end = m_variables.end();
|
2010-06-09 00:52:24 +08:00
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos) {
|
2010-09-02 10:59:18 +08:00
|
|
|
if (pos->get() == var_sp.get())
|
2010-10-11 07:55:27 +08:00
|
|
|
return std::distance(m_variables.begin(), pos);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-10-11 07:55:27 +08:00
|
|
|
return UINT32_MAX;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
VariableSP VariableList::FindVariable(ConstString name,
|
2015-08-19 06:46:57 +08:00
|
|
|
bool include_static_members) {
|
2010-10-11 07:55:27 +08:00
|
|
|
VariableSP var_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
iterator pos, end = m_variables.end();
|
2010-10-11 07:55:27 +08:00
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos) {
|
|
|
|
if ((*pos)->NameMatches(name)) {
|
|
|
|
if (include_static_members || !(*pos)->IsStaticMember()) {
|
|
|
|
var_sp = (*pos);
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-10-11 07:55:27 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-10-11 07:55:27 +08:00
|
|
|
return var_sp;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
VariableSP VariableList::FindVariable(ConstString name,
|
2015-08-19 06:46:57 +08:00
|
|
|
lldb::ValueType value_type,
|
|
|
|
bool include_static_members) {
|
2010-06-09 00:52:24 +08:00
|
|
|
VariableSP var_sp;
|
|
|
|
iterator pos, end = m_variables.end();
|
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos) {
|
Just like functions can have a basename and a mangled/demangled name, variable
can too. So now the lldb_private::Variable class has support for this.
Variables now have support for having a basename ("i"), and a mangled name
("_ZN12_GLOBAL__N_11iE"), and a demangled name ("(anonymous namespace)::i").
Nowwhen searching for a variable by name, users might enter the fully qualified
name, or just the basename. So new test functions were added to the Variable
and Mangled classes as:
bool NameMatches (const ConstString &name);
bool NameMatches (const RegularExpression ®ex);
I also modified "ClangExpressionDeclMap::FindVariableInScope" to also search
for global variables that are not in the current file scope by first starting
with the current module, then moving on to all modules.
Fixed an issue in the DWARF parser that could cause a varaible to get parsed
more than once. Now, once we have parsed a VariableSP for a DIE, we cache
the result even if a variable wasn't made so we don't do any re-parsing. Some
DW_TAG_variable DIEs don't have locations, or are missing vital info that
stops a debugger from being able to display anything for it, we parse a NULL
variable shared pointer for these DIEs so we don't keep trying to reparse it.
llvm-svn: 119085
2010-11-15 06:13:40 +08:00
|
|
|
if ((*pos)->NameMatches(name) && (*pos)->GetScope() == value_type) {
|
2015-08-19 06:46:57 +08:00
|
|
|
if (include_static_members || !(*pos)->IsStaticMember()) {
|
|
|
|
var_sp = (*pos);
|
|
|
|
break;
|
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 var_sp;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-08-19 06:46:57 +08:00
|
|
|
size_t VariableList::AppendVariablesIfUnique(VariableList &var_list) {
|
|
|
|
const size_t initial_size = var_list.GetSize();
|
2014-02-19 07:48:11 +08:00
|
|
|
iterator pos, end = m_variables.end();
|
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos)
|
|
|
|
var_list.AddVariableIfUnique(*pos);
|
|
|
|
return var_list.GetSize() - initial_size;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-02-19 07:48:11 +08:00
|
|
|
size_t VariableList::AppendVariablesIfUnique(const RegularExpression ®ex,
|
2010-10-11 07:55:27 +08:00
|
|
|
VariableList &var_list,
|
2014-02-19 07:48:11 +08:00
|
|
|
size_t &total_matches) {
|
|
|
|
const size_t initial_size = var_list.GetSize();
|
2014-02-20 03:35:13 +08:00
|
|
|
iterator pos, end = m_variables.end();
|
2014-02-19 07:48:11 +08:00
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos) {
|
|
|
|
if ((*pos)->NameMatches(regex)) {
|
2015-08-19 06:46:57 +08:00
|
|
|
// Note the total matches found
|
|
|
|
total_matches++;
|
|
|
|
// Only add this variable if it isn't already in the "var_list"
|
|
|
|
var_list.AddVariableIfUnique(*pos);
|
2014-02-19 07:48:11 +08:00
|
|
|
}
|
|
|
|
}
|
2014-02-20 03:35:13 +08:00
|
|
|
// Return the number of new unique variables added to "var_list"
|
|
|
|
return var_list.GetSize() - initial_size;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 03:35:13 +08:00
|
|
|
size_t VariableList::AppendVariablesWithScope(lldb::ValueType type,
|
|
|
|
VariableList &var_list,
|
|
|
|
bool if_unique) {
|
|
|
|
const size_t initial_size = var_list.GetSize();
|
|
|
|
iterator pos, end = m_variables.end();
|
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos) {
|
2013-05-09 04:27:37 +08:00
|
|
|
if ((*pos)->GetScope() == type) {
|
|
|
|
if (if_unique)
|
2014-02-20 03:35:13 +08:00
|
|
|
var_list.AddVariableIfUnique(*pos);
|
2013-05-09 04:27:37 +08:00
|
|
|
else
|
2010-06-09 00:52:24 +08:00
|
|
|
var_list.AddVariable(*pos);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-10-11 07:55:27 +08:00
|
|
|
// Return the number of new unique variables added to "var_list"
|
2014-02-20 03:35:13 +08:00
|
|
|
return var_list.GetSize() - initial_size;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-09-02 10:59:18 +08:00
|
|
|
uint32_t VariableList::FindIndexForVariable(Variable *variable) {
|
2014-02-19 07:48:11 +08:00
|
|
|
VariableSP var_sp;
|
2010-09-02 10:59:18 +08:00
|
|
|
iterator pos;
|
|
|
|
const iterator begin = m_variables.begin();
|
|
|
|
const iterator end = m_variables.end();
|
2010-10-11 07:55:27 +08:00
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos) {
|
2010-09-02 10:59:18 +08:00
|
|
|
if ((*pos).get() == variable)
|
|
|
|
return std::distance(begin, pos);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-09-02 10:59:18 +08:00
|
|
|
return UINT32_MAX;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
size_t VariableList::MemorySize() const {
|
|
|
|
size_t mem_size = sizeof(VariableList);
|
|
|
|
const_iterator pos, end = m_variables.end();
|
2010-10-11 07:55:27 +08:00
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos)
|
2010-06-09 00:52:24 +08:00
|
|
|
mem_size += (*pos)->MemorySize();
|
|
|
|
return mem_size;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-10-11 07:55:27 +08:00
|
|
|
size_t VariableList::GetSize() const { return m_variables.size(); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void VariableList::Dump(Stream *s, bool show_context) const {
|
|
|
|
// s.Printf("%.*p: ", (int)sizeof(void*) * 2, this);
|
|
|
|
// s.Indent();
|
|
|
|
// s << "VariableList\n";
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
const_iterator pos, end = m_variables.end();
|
2013-05-09 04:27:37 +08:00
|
|
|
for (pos = m_variables.begin(); pos != end; ++pos) {
|
2010-06-09 00:52:24 +08:00
|
|
|
(*pos)->Dump(s, show_context);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|