[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
|
|
|
//===-- AddressResolverName.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/Core/AddressResolverName.h"
|
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Core/Address.h"
|
|
|
|
#include "lldb/Core/AddressRange.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/Core/Module.h"
|
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Symbol/Symbol.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/Logging.h"
|
|
|
|
#include "lldb/Utility/Stream.h"
|
|
|
|
#include "lldb/lldb-enumerations.h"
|
|
|
|
#include "lldb/lldb-forward.h"
|
|
|
|
#include "lldb/lldb-types.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-03-02 09:09:03 +08:00
|
|
|
AddressResolverName::AddressResolverName(const char *func_name,
|
|
|
|
AddressResolver::MatchType type)
|
|
|
|
: AddressResolver(), m_func_name(func_name), m_class_name(nullptr),
|
|
|
|
m_regex(), m_match_type(type) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_match_type == AddressResolver::Regexp) {
|
2019-08-20 17:24:20 +08:00
|
|
|
m_regex = RegularExpression(m_func_name.GetStringRef());
|
|
|
|
if (!m_regex.IsValid()) {
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (log)
|
|
|
|
log->Warning("function name regexp: \"%s\" did not compile.",
|
|
|
|
m_func_name.AsCString());
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-08-17 05:25:36 +08:00
|
|
|
AddressResolverName::AddressResolverName(RegularExpression func_regex)
|
2016-03-02 09:09:03 +08:00
|
|
|
: AddressResolver(), m_func_name(nullptr), m_class_name(nullptr),
|
2019-08-17 05:25:36 +08:00
|
|
|
m_regex(std::move(func_regex)), m_match_type(AddressResolver::Regexp) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-03-02 09:09:03 +08:00
|
|
|
AddressResolverName::AddressResolverName(const char *class_name,
|
|
|
|
const char *method,
|
|
|
|
AddressResolver::MatchType type)
|
2010-06-09 00:52:24 +08:00
|
|
|
: AddressResolver(), m_func_name(method), m_class_name(class_name),
|
|
|
|
m_regex(), m_match_type(type) {}
|
|
|
|
|
2016-03-02 09:09:03 +08:00
|
|
|
AddressResolverName::~AddressResolverName() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// FIXME: Right now we look at the module level, and call the module's
|
|
|
|
// "FindFunctions".
|
|
|
|
// Greg says he will add function tables, maybe at the CompileUnit level to
|
2018-05-01 00:49:04 +08:00
|
|
|
// accelerate function lookup. At that point, we should switch the depth to
|
|
|
|
// CompileUnit, and look in these tables.
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
Searcher::CallbackReturn
|
2016-03-02 09:09:03 +08:00
|
|
|
AddressResolverName::SearchCallback(SearchFilter &filter,
|
2019-10-10 19:26:51 +08:00
|
|
|
SymbolContext &context, Address *addr) {
|
2010-06-09 00:52:24 +08:00
|
|
|
SymbolContextList func_list;
|
|
|
|
SymbolContextList sym_list;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool skip_prologue = true;
|
|
|
|
uint32_t i;
|
|
|
|
SymbolContext sc;
|
|
|
|
Address func_addr;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_class_name) {
|
|
|
|
if (log)
|
|
|
|
log->Warning("Class/method function specification not supported yet.\n");
|
|
|
|
return Searcher::eCallbackReturnStop;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-01-27 14:44:37 +08:00
|
|
|
const bool include_symbols = false;
|
2012-02-11 06:52:19 +08:00
|
|
|
const bool include_inlines = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (m_match_type) {
|
2011-01-27 14:44:37 +08:00
|
|
|
case AddressResolver::Exact:
|
2010-06-09 00:52:24 +08:00
|
|
|
if (context.module_sp) {
|
2011-10-12 10:08:07 +08:00
|
|
|
context.module_sp->FindSymbolsWithNameAndType(m_func_name,
|
2010-06-29 05:30:43 +08:00
|
|
|
eSymbolTypeCode, sym_list);
|
2020-02-18 02:25:52 +08:00
|
|
|
context.module_sp->FindFunctions(m_func_name, CompilerDeclContext(),
|
2016-03-02 09:09:03 +08:00
|
|
|
eFunctionNameTypeAuto, include_symbols,
|
2019-10-18 03:56:40 +08:00
|
|
|
include_inlines, func_list);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-01-27 14:44:37 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-01-27 14:44:37 +08:00
|
|
|
case AddressResolver::Regexp:
|
2010-06-09 00:52:24 +08:00
|
|
|
if (context.module_sp) {
|
2011-10-12 10:08:07 +08:00
|
|
|
context.module_sp->FindSymbolsMatchingRegExAndType(
|
2010-06-29 05:30:43 +08:00
|
|
|
m_regex, eSymbolTypeCode, sym_list);
|
2016-03-02 09:09:03 +08:00
|
|
|
context.module_sp->FindFunctions(m_regex, include_symbols,
|
2019-10-18 03:56:40 +08:00
|
|
|
include_inlines, func_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-01-27 14:44:37 +08:00
|
|
|
case AddressResolver::Glob:
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
2016-03-02 09:09:03 +08:00
|
|
|
log->Warning("glob is not supported yet.");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-02 09:09:03 +08:00
|
|
|
// Remove any duplicates between the function list and the symbol list
|
2010-06-09 00:52:24 +08:00
|
|
|
if (func_list.GetSize()) {
|
2016-03-02 09:09:03 +08:00
|
|
|
for (i = 0; i < func_list.GetSize(); i++) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (!func_list.GetContextAtIndex(i, sc))
|
|
|
|
continue;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (sc.function == nullptr)
|
2010-06-29 05:30:43 +08:00
|
|
|
continue;
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t j = 0;
|
2010-06-29 05:30:43 +08:00
|
|
|
while (j < sym_list.GetSize()) {
|
|
|
|
SymbolContext symbol_sc;
|
|
|
|
if (sym_list.GetContextAtIndex(j, symbol_sc)) {
|
|
|
|
if (symbol_sc.symbol && symbol_sc.symbol->ValueIsAddress()) {
|
|
|
|
if (sc.function->GetAddressRange().GetBaseAddress() ==
|
|
|
|
symbol_sc.symbol->GetAddressRef()) {
|
|
|
|
sym_list.RemoveContextAtIndex(j);
|
2012-02-11 06:52:19 +08:00
|
|
|
continue; // Don't increment j
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-01-27 14:44:37 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
j++;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < func_list.GetSize(); i++) {
|
2016-03-02 09:09:03 +08:00
|
|
|
if (func_list.GetContextAtIndex(i, sc)) {
|
|
|
|
if (sc.function) {
|
2015-06-26 05:46:34 +08:00
|
|
|
func_addr = sc.function->GetAddressRange().GetBaseAddress();
|
|
|
|
addr_t byte_size = sc.function->GetAddressRange().GetByteSize();
|
|
|
|
if (skip_prologue) {
|
2010-06-09 00:52:24 +08:00
|
|
|
const uint32_t prologue_byte_size =
|
|
|
|
sc.function->GetPrologueByteSize();
|
|
|
|
if (prologue_byte_size) {
|
|
|
|
func_addr.SetOffset(func_addr.GetOffset() + prologue_byte_size);
|
|
|
|
byte_size -= prologue_byte_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter.AddressPasses(func_addr)) {
|
|
|
|
AddressRange new_range(func_addr, byte_size);
|
|
|
|
m_address_ranges.push_back(new_range);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
for (i = 0; i < sym_list.GetSize(); i++) {
|
|
|
|
if (sym_list.GetContextAtIndex(i, sc)) {
|
2012-03-08 05:03:09 +08:00
|
|
|
if (sc.symbol && sc.symbol->ValueIsAddress()) {
|
2015-06-26 05:46:34 +08:00
|
|
|
func_addr = sc.symbol->GetAddressRef();
|
2012-03-08 05:03:09 +08:00
|
|
|
addr_t byte_size = sc.symbol->GetByteSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (skip_prologue) {
|
|
|
|
const uint32_t prologue_byte_size = sc.symbol->GetPrologueByteSize();
|
|
|
|
if (prologue_byte_size) {
|
|
|
|
func_addr.SetOffset(func_addr.GetOffset() + prologue_byte_size);
|
|
|
|
byte_size -= prologue_byte_size;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (filter.AddressPasses(func_addr)) {
|
|
|
|
AddressRange new_range(func_addr, byte_size);
|
|
|
|
m_address_ranges.push_back(new_range);
|
|
|
|
}
|
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 Searcher::eCallbackReturnContinue;
|
|
|
|
}
|
|
|
|
|
2018-09-08 02:43:04 +08:00
|
|
|
lldb::SearchDepth AddressResolverName::GetDepth() {
|
|
|
|
return lldb::eSearchDepthModule;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddressResolverName::GetDescription(Stream *s) {
|
|
|
|
s->PutCString("Address by function name: ");
|
|
|
|
|
|
|
|
if (m_match_type == AddressResolver::Regexp)
|
2016-09-22 00:01:28 +08:00
|
|
|
s->Printf("'%s' (regular expression)", m_regex.GetText().str().c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
|
|
|
s->Printf("'%s'", m_func_name.AsCString());
|
|
|
|
}
|