2010-06-09 00:52:24 +08:00
|
|
|
//===-- BreakpointResolverName.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/Breakpoint/BreakpointResolverName.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
|
|
|
#include "lldb/Core/Log.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"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/StreamString.h"
|
2011-10-12 10:08:07 +08:00
|
|
|
#include "lldb/Symbol/ClangNamespaceDecl.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/Block.h"
|
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Symbol/Symbol.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
2013-01-30 08:18:29 +08:00
|
|
|
#include "lldb/Target/ObjCLanguageRuntime.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2013-04-03 10:00:15 +08:00
|
|
|
BreakpointResolverName::BreakpointResolverName (Breakpoint *bkpt,
|
|
|
|
const char *name_cstr,
|
|
|
|
uint32_t name_type_mask,
|
|
|
|
Breakpoint::MatchType type,
|
|
|
|
bool skip_prologue) :
|
2010-10-29 01:27:46 +08:00
|
|
|
BreakpointResolver (bkpt, BreakpointResolver::NameResolver),
|
2010-06-29 05:30:43 +08:00
|
|
|
m_class_name (),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_regex (),
|
2011-07-13 01:06:17 +08:00
|
|
|
m_match_type (type),
|
|
|
|
m_skip_prologue (skip_prologue)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-03-03 10:05:11 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_match_type == Breakpoint::Regexp)
|
|
|
|
{
|
2013-04-03 10:00:15 +08:00
|
|
|
if (!m_regex.Compile (name_cstr))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (log)
|
2013-04-03 10:00:15 +08:00
|
|
|
log->Warning ("function name regexp: \"%s\" did not compile.", name_cstr);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-03 10:05:11 +08:00
|
|
|
else
|
|
|
|
{
|
2013-04-03 10:00:15 +08:00
|
|
|
AddNameLookup (ConstString(name_cstr), name_type_mask);
|
2012-03-03 10:05:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointResolverName::BreakpointResolverName (Breakpoint *bkpt,
|
|
|
|
const char *names[],
|
|
|
|
size_t num_names,
|
|
|
|
uint32_t name_type_mask,
|
|
|
|
bool skip_prologue) :
|
|
|
|
BreakpointResolver (bkpt, BreakpointResolver::NameResolver),
|
2012-03-06 08:37:27 +08:00
|
|
|
m_match_type (Breakpoint::Exact),
|
2012-03-03 10:05:11 +08:00
|
|
|
m_skip_prologue (skip_prologue)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < num_names; i++)
|
|
|
|
{
|
2013-04-03 10:00:15 +08:00
|
|
|
AddNameLookup (ConstString (names[i]), name_type_mask);
|
2012-03-03 10:05:11 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-03-06 08:37:27 +08:00
|
|
|
BreakpointResolverName::BreakpointResolverName (Breakpoint *bkpt,
|
|
|
|
std::vector<std::string> names,
|
|
|
|
uint32_t name_type_mask,
|
|
|
|
bool skip_prologue) :
|
|
|
|
BreakpointResolver (bkpt, BreakpointResolver::NameResolver),
|
|
|
|
m_match_type (Breakpoint::Exact),
|
|
|
|
m_skip_prologue (skip_prologue)
|
|
|
|
{
|
2013-04-03 10:00:15 +08:00
|
|
|
for (const std::string& name : names)
|
2012-03-06 08:37:27 +08:00
|
|
|
{
|
2013-04-03 10:00:15 +08:00
|
|
|
AddNameLookup (ConstString (name.c_str(), name.size()), name_type_mask);
|
2012-03-06 08:37:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-03 10:00:15 +08:00
|
|
|
BreakpointResolverName::BreakpointResolverName (Breakpoint *bkpt,
|
|
|
|
RegularExpression &func_regex,
|
|
|
|
bool skip_prologue) :
|
2010-10-29 01:27:46 +08:00
|
|
|
BreakpointResolver (bkpt, BreakpointResolver::NameResolver),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_class_name (NULL),
|
|
|
|
m_regex (func_regex),
|
2011-07-13 01:06:17 +08:00
|
|
|
m_match_type (Breakpoint::Regexp),
|
|
|
|
m_skip_prologue (skip_prologue)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointResolverName::BreakpointResolverName
|
|
|
|
(
|
|
|
|
Breakpoint *bkpt,
|
|
|
|
const char *class_name,
|
|
|
|
const char *method,
|
2011-07-13 01:06:17 +08:00
|
|
|
Breakpoint::MatchType type,
|
|
|
|
bool skip_prologue
|
2010-06-09 00:52:24 +08:00
|
|
|
) :
|
2010-10-29 01:27:46 +08:00
|
|
|
BreakpointResolver (bkpt, BreakpointResolver::NameResolver),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_class_name (class_name),
|
|
|
|
m_regex (),
|
2011-07-13 01:06:17 +08:00
|
|
|
m_match_type (type),
|
|
|
|
m_skip_prologue (skip_prologue)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-04-03 10:00:15 +08:00
|
|
|
LookupInfo lookup;
|
|
|
|
lookup.name.SetCString(method);
|
|
|
|
lookup.lookup_name = lookup.name;
|
|
|
|
lookup.name_type_mask = eFunctionNameTypeMethod;
|
|
|
|
lookup.match_name_after_lookup = false;
|
|
|
|
m_lookups.push_back (lookup);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointResolverName::~BreakpointResolverName ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-03 10:00:15 +08:00
|
|
|
void
|
|
|
|
BreakpointResolverName::AddNameLookup (const ConstString &name, uint32_t name_type_mask)
|
|
|
|
{
|
|
|
|
ObjCLanguageRuntime::MethodName objc_method(name.GetCString(), false);
|
|
|
|
if (objc_method.IsValid(false))
|
|
|
|
{
|
|
|
|
std::vector<ConstString> objc_names;
|
|
|
|
objc_method.GetFullNames(objc_names, true);
|
|
|
|
for (ConstString objc_name : objc_names)
|
|
|
|
{
|
|
|
|
LookupInfo lookup;
|
|
|
|
lookup.name = name;
|
|
|
|
lookup.lookup_name = objc_name;
|
|
|
|
lookup.name_type_mask = eFunctionNameTypeFull;
|
|
|
|
lookup.match_name_after_lookup = false;
|
|
|
|
m_lookups.push_back (lookup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LookupInfo lookup;
|
|
|
|
lookup.name = name;
|
|
|
|
Module::PrepareForFunctionNameLookup(lookup.name, name_type_mask, lookup.lookup_name, lookup.name_type_mask, lookup.match_name_after_lookup);
|
|
|
|
m_lookups.push_back (lookup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
BreakpointResolverName::LookupInfo::Prune (SymbolContextList &sc_list, size_t start_idx) const
|
|
|
|
{
|
|
|
|
if (match_name_after_lookup && name)
|
|
|
|
{
|
|
|
|
SymbolContext sc;
|
|
|
|
size_t i = start_idx;
|
|
|
|
while (i < sc_list.GetSize())
|
|
|
|
{
|
|
|
|
if (!sc_list.GetContextAtIndex(i, sc))
|
|
|
|
break;
|
|
|
|
ConstString full_name (sc.GetFunctionName());
|
|
|
|
if (full_name && ::strstr(full_name.GetCString(), name.GetCString()) == NULL)
|
|
|
|
{
|
|
|
|
sc_list.RemoveContextAtIndex(i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 accelerate function
|
|
|
|
// lookup. At that point, we should switch the depth to CompileUnit, and look in these tables.
|
|
|
|
|
|
|
|
Searcher::CallbackReturn
|
|
|
|
BreakpointResolverName::SearchCallback
|
|
|
|
(
|
|
|
|
SearchFilter &filter,
|
|
|
|
SymbolContext &context,
|
|
|
|
Address *addr,
|
|
|
|
bool containing
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SymbolContextList func_list;
|
2013-06-12 08:46:38 +08:00
|
|
|
//SymbolContextList sym_list;
|
2010-06-29 05:30:43 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t i;
|
|
|
|
bool new_location;
|
|
|
|
Address break_addr;
|
|
|
|
assert (m_breakpoint != NULL);
|
2010-06-29 05:30:43 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
|
2010-06-29 05:30:43 +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;
|
|
|
|
}
|
2013-06-12 08:46:38 +08:00
|
|
|
bool filter_by_cu = (filter.GetFilterRequiredItems() & eSymbolContextCompUnit) != 0;
|
|
|
|
const bool include_symbols = filter_by_cu == false;
|
2012-02-11 06:52:19 +08:00
|
|
|
const bool include_inlines = true;
|
2012-03-03 10:05:11 +08:00
|
|
|
const bool append = true;
|
2011-09-23 08:54:11 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (m_match_type)
|
|
|
|
{
|
2010-06-29 05:30:43 +08:00
|
|
|
case Breakpoint::Exact:
|
|
|
|
if (context.module_sp)
|
|
|
|
{
|
2013-04-03 10:00:15 +08:00
|
|
|
for (const LookupInfo &lookup : m_lookups)
|
2011-09-02 12:03:59 +08:00
|
|
|
{
|
2013-04-03 10:00:15 +08:00
|
|
|
const size_t start_func_idx = func_list.GetSize();
|
|
|
|
context.module_sp->FindFunctions (lookup.lookup_name,
|
|
|
|
NULL,
|
|
|
|
lookup.name_type_mask,
|
|
|
|
include_symbols,
|
|
|
|
include_inlines,
|
|
|
|
append,
|
|
|
|
func_list);
|
|
|
|
const size_t end_func_idx = func_list.GetSize();
|
|
|
|
|
|
|
|
if (start_func_idx < end_func_idx)
|
|
|
|
lookup.Prune (func_list, start_func_idx);
|
2011-09-02 12:03:59 +08:00
|
|
|
}
|
2010-06-29 05:30:43 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Breakpoint::Regexp:
|
|
|
|
if (context.module_sp)
|
|
|
|
{
|
2013-06-12 08:46:38 +08:00
|
|
|
context.module_sp->FindFunctions (m_regex,
|
|
|
|
!filter_by_cu, // include symbols only if we aren't filterning by CU
|
2012-02-11 06:52:19 +08:00
|
|
|
include_inlines,
|
2011-01-27 14:44:37 +08:00
|
|
|
append,
|
|
|
|
func_list);
|
2010-06-29 05:30:43 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Breakpoint::Glob:
|
|
|
|
if (log)
|
|
|
|
log->Warning ("glob is not supported yet.");
|
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-09-23 08:54:11 +08:00
|
|
|
|
|
|
|
// If the filter specifies a Compilation Unit, remove the ones that don't pass at this point.
|
|
|
|
if (filter_by_cu)
|
|
|
|
{
|
|
|
|
uint32_t num_functions = func_list.GetSize();
|
|
|
|
|
|
|
|
for (size_t idx = 0; idx < num_functions; idx++)
|
|
|
|
{
|
|
|
|
SymbolContext sc;
|
|
|
|
func_list.GetContextAtIndex(idx, sc);
|
|
|
|
if (!sc.comp_unit || !filter.CompUnitPasses(*sc.comp_unit))
|
|
|
|
{
|
|
|
|
func_list.RemoveContextAtIndex(idx);
|
|
|
|
num_functions--;
|
|
|
|
idx--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-14 08:22:48 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Remove any duplicates between the funcion list and the symbol list
|
2013-04-03 10:00:15 +08:00
|
|
|
SymbolContext sc;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (func_list.GetSize())
|
|
|
|
{
|
|
|
|
for (i = 0; i < func_list.GetSize(); i++)
|
|
|
|
{
|
|
|
|
if (func_list.GetContextAtIndex(i, sc))
|
|
|
|
{
|
2010-11-14 08:22:48 +08:00
|
|
|
if (sc.block && sc.block->GetInlinedFunctionInfo())
|
|
|
|
{
|
|
|
|
if (!sc.block->GetStartAddress(break_addr))
|
|
|
|
break_addr.Clear();
|
|
|
|
}
|
|
|
|
else if (sc.function)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
break_addr = sc.function->GetAddressRange().GetBaseAddress();
|
2013-06-12 08:46:38 +08:00
|
|
|
if (m_skip_prologue && break_addr.IsValid())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-06-12 08:46:38 +08:00
|
|
|
const uint32_t prologue_byte_size = sc.function->GetPrologueByteSize();
|
|
|
|
if (prologue_byte_size)
|
|
|
|
break_addr.SetOffset(break_addr.GetOffset() + prologue_byte_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (sc.symbol)
|
|
|
|
{
|
|
|
|
break_addr = sc.symbol->GetAddress();
|
|
|
|
if (m_skip_prologue && break_addr.IsValid())
|
|
|
|
{
|
|
|
|
const uint32_t prologue_byte_size = sc.symbol->GetPrologueByteSize();
|
|
|
|
if (prologue_byte_size)
|
|
|
|
break_addr.SetOffset(break_addr.GetOffset() + prologue_byte_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-11-14 08:22:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (break_addr.IsValid())
|
|
|
|
{
|
2010-06-09 00:52:24 +08:00
|
|
|
if (filter.AddressPasses(break_addr))
|
|
|
|
{
|
|
|
|
BreakpointLocationSP bp_loc_sp (m_breakpoint->AddLocation(break_addr, &new_location));
|
|
|
|
if (bp_loc_sp && new_location && !m_breakpoint->IsInternal())
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
StreamString s;
|
|
|
|
bp_loc_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
|
|
|
|
log->Printf ("Added location: %s\n", s.GetData());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-29 05:30:43 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return Searcher::eCallbackReturnContinue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Searcher::Depth
|
|
|
|
BreakpointResolverName::GetDepth()
|
|
|
|
{
|
|
|
|
return Searcher::eDepthModule;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BreakpointResolverName::GetDescription (Stream *s)
|
|
|
|
{
|
|
|
|
if (m_match_type == Breakpoint::Regexp)
|
2010-06-29 05:30:43 +08:00
|
|
|
s->Printf("regex = '%s'", m_regex.GetText());
|
2010-10-12 12:29:14 +08:00
|
|
|
else
|
2012-03-03 10:05:11 +08:00
|
|
|
{
|
2013-04-03 10:00:15 +08:00
|
|
|
size_t num_names = m_lookups.size();
|
2012-03-03 10:05:11 +08:00
|
|
|
if (num_names == 1)
|
2013-04-03 10:00:15 +08:00
|
|
|
s->Printf("name = '%s'", m_lookups[0].name.GetCString());
|
2012-03-03 10:05:11 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
s->Printf("names = {");
|
|
|
|
for (size_t i = 0; i < num_names - 1; i++)
|
|
|
|
{
|
2013-04-03 10:00:15 +08:00
|
|
|
s->Printf ("'%s', ", m_lookups[i].name.GetCString());
|
2012-03-03 10:05:11 +08:00
|
|
|
}
|
2013-04-03 10:00:15 +08:00
|
|
|
s->Printf ("'%s'}", m_lookups[num_names - 1].name.GetCString());
|
2012-03-03 10:05:11 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BreakpointResolverName::Dump (Stream *s) const
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|