2010-06-09 00:52:24 +08:00
|
|
|
//===-- AddressResolverName.cpp ---------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/AddressResolverName.h"
|
|
|
|
|
2017-04-07 05:28:29 +08:00
|
|
|
#include "lldb/Core/Address.h" // for Address, operator==
|
|
|
|
#include "lldb/Core/AddressRange.h" // for AddressRange
|
<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"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
#include "lldb/Utility/Logging.h" // for GetLogIfAllCategoriesSet, LIB...
|
|
|
|
#include "lldb/Utility/Stream.h" // for Stream
|
|
|
|
#include "lldb/lldb-enumerations.h" // for SymbolType::eSymbolTypeCode
|
|
|
|
#include "lldb/lldb-forward.h" // for ModuleSP
|
|
|
|
#include "lldb/lldb-types.h" // for addr_t
|
|
|
|
#include "llvm/ADT/StringRef.h" // for StringRef
|
|
|
|
|
|
|
|
#include <memory> // for shared_ptr
|
|
|
|
#include <string> // for string
|
|
|
|
#include <vector> // for vector
|
|
|
|
|
|
|
|
#include <stdint.h> // for uint32_t
|
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,
|
2016-09-07 04:57:50 +08:00
|
|
|
AddressResolver::MatchType type)
|
|
|
|
: AddressResolver(), m_func_name(func_name), m_class_name(nullptr),
|
|
|
|
m_regex(), m_match_type(type) {
|
|
|
|
if (m_match_type == AddressResolver::Regexp) {
|
2016-09-22 00:01:28 +08:00
|
|
|
if (!m_regex.Compile(m_func_name.GetStringRef())) {
|
2016-09-07 04:57:50 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Warning("function name regexp: \"%s\" did not compile.",
|
|
|
|
m_func_name.AsCString());
|
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
|
|
|
AddressResolverName::AddressResolverName(RegularExpression &func_regex)
|
|
|
|
: AddressResolver(), m_func_name(nullptr), m_class_name(nullptr),
|
|
|
|
m_regex(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,
|
2016-09-07 04:57:50 +08:00
|
|
|
AddressResolver::MatchType type)
|
|
|
|
: AddressResolver(), m_func_name(method), m_class_name(class_name),
|
|
|
|
m_regex(), m_match_type(type) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-03-02 09:09:03 +08:00
|
|
|
AddressResolverName::~AddressResolverName() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +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,
|
2016-09-07 04:57:50 +08:00
|
|
|
SymbolContext &context, Address *addr,
|
|
|
|
bool containing) {
|
|
|
|
SymbolContextList func_list;
|
|
|
|
SymbolContextList sym_list;
|
|
|
|
|
|
|
|
bool skip_prologue = true;
|
|
|
|
uint32_t i;
|
|
|
|
SymbolContext sc;
|
|
|
|
Address func_addr;
|
|
|
|
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
|
|
|
|
|
|
|
|
if (m_class_name) {
|
|
|
|
if (log)
|
|
|
|
log->Warning("Class/method function specification not supported yet.\n");
|
|
|
|
return Searcher::eCallbackReturnStop;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool include_symbols = false;
|
|
|
|
const bool include_inlines = true;
|
|
|
|
const bool append = false;
|
|
|
|
switch (m_match_type) {
|
|
|
|
case AddressResolver::Exact:
|
|
|
|
if (context.module_sp) {
|
|
|
|
context.module_sp->FindSymbolsWithNameAndType(m_func_name,
|
|
|
|
eSymbolTypeCode, sym_list);
|
|
|
|
context.module_sp->FindFunctions(m_func_name, nullptr,
|
|
|
|
eFunctionNameTypeAuto, include_symbols,
|
|
|
|
include_inlines, append, func_list);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AddressResolver::Regexp:
|
|
|
|
if (context.module_sp) {
|
|
|
|
context.module_sp->FindSymbolsMatchingRegExAndType(
|
|
|
|
m_regex, eSymbolTypeCode, sym_list);
|
|
|
|
context.module_sp->FindFunctions(m_regex, include_symbols,
|
|
|
|
include_inlines, append, func_list);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AddressResolver::Glob:
|
|
|
|
if (log)
|
|
|
|
log->Warning("glob is not supported yet.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove any duplicates between the function list and the symbol list
|
|
|
|
if (func_list.GetSize()) {
|
|
|
|
for (i = 0; i < func_list.GetSize(); i++) {
|
|
|
|
if (!func_list.GetContextAtIndex(i, sc))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sc.function == nullptr)
|
|
|
|
continue;
|
|
|
|
uint32_t j = 0;
|
|
|
|
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);
|
|
|
|
continue; // Don't increment j
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-01-27 14:44:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
j++;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
for (i = 0; i < func_list.GetSize(); i++) {
|
|
|
|
if (func_list.GetContextAtIndex(i, sc)) {
|
|
|
|
if (sc.function) {
|
|
|
|
func_addr = sc.function->GetAddressRange().GetBaseAddress();
|
|
|
|
addr_t byte_size = sc.function->GetAddressRange().GetByteSize();
|
|
|
|
if (skip_prologue) {
|
|
|
|
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;
|
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
|
|
|
if (filter.AddressPasses(func_addr)) {
|
|
|
|
AddressRange new_range(func_addr, byte_size);
|
|
|
|
m_address_ranges.push_back(new_range);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sym_list.GetSize(); i++) {
|
|
|
|
if (sym_list.GetContextAtIndex(i, sc)) {
|
|
|
|
if (sc.symbol && sc.symbol->ValueIsAddress()) {
|
|
|
|
func_addr = sc.symbol->GetAddressRef();
|
|
|
|
addr_t byte_size = sc.symbol->GetByteSize();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (filter.AddressPasses(func_addr)) {
|
|
|
|
AddressRange new_range(func_addr, byte_size);
|
|
|
|
m_address_ranges.push_back(new_range);
|
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
|
|
|
}
|
|
|
|
return Searcher::eCallbackReturnContinue;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Searcher::Depth AddressResolverName::GetDepth() {
|
|
|
|
return Searcher::eDepthModule;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void AddressResolverName::GetDescription(Stream *s) {
|
|
|
|
s->PutCString("Address by function name: ");
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
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());
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
|
|
|
s->Printf("'%s'", m_func_name.AsCString());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|