[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
|
|
|
//===-- BreakpointResolverFileRegex.cpp -----------------------------------===//
|
2011-09-21 09:17:13 +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
|
2011-09-21 09:17:13 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
|
|
|
#include "lldb/Core/SourceManager.h"
|
<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
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
2011-09-21 09:17:13 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2011-09-21 09:17:13 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
// BreakpointResolverFileRegex:
|
|
|
|
BreakpointResolverFileRegex::BreakpointResolverFileRegex(
|
2020-03-03 18:29:12 +08:00
|
|
|
const lldb::BreakpointSP &bkpt, RegularExpression regex,
|
2016-04-28 09:40:57 +08:00
|
|
|
const std::unordered_set<std::string> &func_names, bool exact_match)
|
2016-09-16 09:41:27 +08:00
|
|
|
: BreakpointResolver(bkpt, BreakpointResolver::FileRegexResolver),
|
2019-08-17 05:25:36 +08:00
|
|
|
m_regex(std::move(regex)), m_exact_match(exact_match),
|
|
|
|
m_function_names(func_names) {}
|
2011-09-21 09:17:13 +08:00
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
BreakpointResolver *BreakpointResolverFileRegex::CreateFromStructuredData(
|
2020-03-03 18:29:12 +08:00
|
|
|
const lldb::BreakpointSP &bkpt, const StructuredData::Dictionary &options_dict,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &error) {
|
2016-09-13 07:10:56 +08:00
|
|
|
bool success;
|
|
|
|
|
2017-05-12 13:49:54 +08:00
|
|
|
llvm::StringRef regex_string;
|
2016-09-13 07:10:56 +08:00
|
|
|
success = options_dict.GetValueForKeyAsString(
|
|
|
|
GetKey(OptionNames::RegexString), regex_string);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRFR::CFSD: Couldn't find regex entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-09-22 00:01:28 +08:00
|
|
|
RegularExpression regex(regex_string);
|
2016-09-13 07:10:56 +08:00
|
|
|
|
|
|
|
bool exact_match;
|
|
|
|
success = options_dict.GetValueForKeyAsBoolean(
|
|
|
|
GetKey(OptionNames::ExactMatch), exact_match);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRFL::CFSD: Couldn't find exact match entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The names array is optional:
|
|
|
|
std::unordered_set<std::string> names_set;
|
|
|
|
StructuredData::Array *names_array;
|
|
|
|
success = options_dict.GetValueForKeyAsArray(
|
|
|
|
GetKey(OptionNames::SymbolNameArray), names_array);
|
|
|
|
if (success && names_array) {
|
|
|
|
size_t num_names = names_array->GetSize();
|
|
|
|
for (size_t i = 0; i < num_names; i++) {
|
2017-05-12 13:49:54 +08:00
|
|
|
llvm::StringRef name;
|
2016-09-13 07:10:56 +08:00
|
|
|
success = names_array->GetItemAtIndexAsString(i, name);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"BRFR::CFSD: Malformed element %zu in the names array.", i);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-01-29 03:23:46 +08:00
|
|
|
names_set.insert(std::string(name));
|
2016-09-13 07:10:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-17 05:25:36 +08:00
|
|
|
return new BreakpointResolverFileRegex(bkpt, std::move(regex), names_set,
|
|
|
|
exact_match);
|
2016-09-13 07:10:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StructuredData::ObjectSP
|
|
|
|
BreakpointResolverFileRegex::SerializeToStructuredData() {
|
|
|
|
StructuredData::DictionarySP options_dict_sp(
|
|
|
|
new StructuredData::Dictionary());
|
|
|
|
|
|
|
|
options_dict_sp->AddStringItem(GetKey(OptionNames::RegexString),
|
|
|
|
m_regex.GetText());
|
|
|
|
options_dict_sp->AddBooleanItem(GetKey(OptionNames::ExactMatch),
|
|
|
|
m_exact_match);
|
|
|
|
if (!m_function_names.empty()) {
|
|
|
|
StructuredData::ArraySP names_array_sp(new StructuredData::Array());
|
|
|
|
for (std::string name : m_function_names) {
|
|
|
|
StructuredData::StringSP item(new StructuredData::String(name));
|
|
|
|
names_array_sp->AddItem(item);
|
|
|
|
}
|
|
|
|
options_dict_sp->AddItem(GetKey(OptionNames::LineNumber), names_array_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return WrapOptionsDict(options_dict_sp);
|
|
|
|
}
|
|
|
|
|
2019-10-10 19:26:51 +08:00
|
|
|
Searcher::CallbackReturn BreakpointResolverFileRegex::SearchCallback(
|
|
|
|
SearchFilter &filter, SymbolContext &context, Address *addr) {
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-21 09:17:13 +08:00
|
|
|
if (!context.target_sp)
|
|
|
|
return eCallbackReturnContinue;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-21 09:17:13 +08:00
|
|
|
CompileUnit *cu = context.comp_unit;
|
2019-11-28 23:22:44 +08:00
|
|
|
FileSpec cu_file_spec = cu->GetPrimaryFile();
|
2011-09-23 08:54:11 +08:00
|
|
|
std::vector<uint32_t> line_matches;
|
2013-09-27 09:16:58 +08:00
|
|
|
context.target_sp->GetSourceManager().FindLinesMatchingRegex(
|
|
|
|
cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-23 08:54:11 +08:00
|
|
|
uint32_t num_matches = line_matches.size();
|
2013-06-20 03:04:53 +08:00
|
|
|
for (uint32_t i = 0; i < num_matches; i++) {
|
2013-09-27 09:16:58 +08:00
|
|
|
SymbolContextList sc_list;
|
|
|
|
const bool search_inlines = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-05-18 21:41:01 +08:00
|
|
|
cu->ResolveSymbolContext(cu_file_spec, line_matches[i], search_inlines,
|
|
|
|
m_exact_match, eSymbolContextEverything, sc_list);
|
2016-04-28 09:40:57 +08:00
|
|
|
// Find all the function names:
|
|
|
|
if (!m_function_names.empty()) {
|
|
|
|
std::vector<size_t> sc_to_remove;
|
|
|
|
for (size_t i = 0; i < sc_list.GetSize(); i++) {
|
|
|
|
SymbolContext sc_ctx;
|
|
|
|
sc_list.GetContextAtIndex(i, sc_ctx);
|
|
|
|
std::string name(
|
|
|
|
sc_ctx
|
|
|
|
.GetFunctionName(
|
|
|
|
Mangled::NamePreference::ePreferDemangledWithoutArguments)
|
|
|
|
.AsCString());
|
|
|
|
if (!m_function_names.count(name)) {
|
|
|
|
sc_to_remove.push_back(i);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-04-28 09:40:57 +08:00
|
|
|
if (!sc_to_remove.empty()) {
|
|
|
|
std::vector<size_t>::reverse_iterator iter;
|
|
|
|
std::vector<size_t>::reverse_iterator rend = sc_to_remove.rend();
|
|
|
|
for (iter = sc_to_remove.rbegin(); iter != rend; iter++) {
|
|
|
|
sc_list.RemoveContextAtIndex(*iter);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-09-21 09:17:13 +08:00
|
|
|
}
|
2011-09-23 08:54:11 +08:00
|
|
|
|
2011-09-21 09:17:13 +08:00
|
|
|
const bool skip_prologue = true;
|
|
|
|
|
|
|
|
BreakpointResolver::SetSCMatchesByLine(filter, sc_list, skip_prologue,
|
|
|
|
m_regex.GetText());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-09-21 09:17:13 +08:00
|
|
|
|
2015-05-18 21:41:01 +08:00
|
|
|
return Searcher::eCallbackReturnContinue;
|
2011-09-21 09:17:13 +08:00
|
|
|
}
|
|
|
|
|
2018-09-08 02:43:04 +08:00
|
|
|
lldb::SearchDepth BreakpointResolverFileRegex::GetDepth() {
|
|
|
|
return lldb::eSearchDepthCompUnit;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-09-21 09:17:13 +08:00
|
|
|
|
|
|
|
void BreakpointResolverFileRegex::GetDescription(Stream *s) {
|
2016-09-22 00:01:28 +08:00
|
|
|
s->Printf("source regex = \"%s\", exact_match = %d",
|
|
|
|
m_regex.GetText().str().c_str(), m_exact_match);
|
2011-09-21 09:17:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverFileRegex::Dump(Stream *s) const {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-12-06 09:28:03 +08:00
|
|
|
lldb::BreakpointResolverSP
|
2020-03-03 18:29:12 +08:00
|
|
|
BreakpointResolverFileRegex::CopyForBreakpoint(BreakpointSP &breakpoint) {
|
2016-04-28 09:40:57 +08:00
|
|
|
lldb::BreakpointResolverSP ret_sp(new BreakpointResolverFileRegex(
|
2020-03-03 18:29:12 +08:00
|
|
|
breakpoint, m_regex, m_function_names, m_exact_match));
|
2014-12-06 09:28:03 +08:00
|
|
|
return ret_sp;
|
|
|
|
}
|
|
|
|
|
2016-04-28 09:40:57 +08:00
|
|
|
void BreakpointResolverFileRegex::AddFunctionName(const char *func_name) {
|
|
|
|
m_function_names.insert(func_name);
|
|
|
|
}
|