Added the ability to _not_ skip the prologue when settings breakpoints

by name by adding an extra parameter to the lldb_private::Target breakpoint 
setting functions.

Added a function in the DWARF symbol file plug-in that can dump errors
and prints out which DWARF file the error is happening in so we can track
down what used to be assertions easily.

Fixed the MacOSX kernel plug-in to properly read the kext images and set
the kext breakpoint to watch for kexts as they are loaded.

llvm-svn: 134990
This commit is contained in:
Greg Clayton
2011-07-12 17:06:17 +00:00
parent 5fa8e20878
commit d16e1e596a
9 changed files with 252 additions and 63 deletions

View File

@@ -32,16 +32,19 @@ public:
BreakpointResolverName (Breakpoint *bkpt,
const char *name,
uint32_t name_type_mask,
Breakpoint::MatchType type);
Breakpoint::MatchType type,
bool skip_prologue);
// Creates a function breakpoint by regular expression. Takes over control of the lifespan of func_regex.
BreakpointResolverName (Breakpoint *bkpt,
RegularExpression &func_regex);
RegularExpression &func_regex,
bool skip_prologue);
BreakpointResolverName (Breakpoint *bkpt,
const char *class_name,
const char *method,
Breakpoint::MatchType type);
Breakpoint::MatchType type,
bool skip_prologue);
virtual
~BreakpointResolverName ();
@@ -81,6 +84,7 @@ protected:
ConstString m_class_name; // FIXME: Not used yet. The idea would be to stop on methods of this class.
RegularExpression m_regex;
Breakpoint::MatchType m_match_type;
bool m_skip_prologue;
private:
DISALLOW_COPY_AND_ASSIGN(BreakpointResolverName);

View File

@@ -238,17 +238,23 @@ public:
bool internal = false);
// Use this to create a function breakpoint by regexp in containingModule, or all modules if it is NULL
// When "skip_prologue is set to eLazyBoolCalculate, we use the current target
// setting, else we use the values passed in
lldb::BreakpointSP
CreateBreakpoint (const FileSpec *containingModule,
RegularExpression &func_regexp,
bool internal = false);
bool internal = false,
LazyBool skip_prologue = eLazyBoolCalculate);
// Use this to create a function breakpoint by name in containingModule, or all modules if it is NULL
// When "skip_prologue is set to eLazyBoolCalculate, we use the current target
// setting, else we use the values passed in
lldb::BreakpointSP
CreateBreakpoint (const FileSpec *containingModule,
const char *func_name,
uint32_t func_name_type_mask,
bool internal = false);
bool internal = false,
LazyBool skip_prologue = eLazyBoolCalculate);
// Use this to create a general breakpoint:
lldb::BreakpointSP
@@ -461,6 +467,27 @@ public:
size_t dst_len,
Error &error);
size_t
ReadScalarIntegerFromMemory (const Address& addr,
bool prefer_file_cache,
uint32_t byte_size,
bool is_signed,
Scalar &scalar,
Error &error);
uint64_t
ReadUnsignedIntegerFromMemory (const Address& addr,
bool prefer_file_cache,
size_t integer_byte_size,
uint64_t fail_value,
Error &error);
bool
ReadPointerFromMemory (const Address& addr,
bool prefer_file_cache,
Error &error,
Address &pointer_addr);
SectionLoadList&
GetSectionLoadList()
{

View File

@@ -26,7 +26,8 @@ BreakpointResolverName::BreakpointResolverName
Breakpoint *bkpt,
const char *func_name,
uint32_t func_name_type_mask,
Breakpoint::MatchType type
Breakpoint::MatchType type,
bool skip_prologue
) :
BreakpointResolver (bkpt, BreakpointResolver::NameResolver),
m_func_name (),
@@ -34,7 +35,8 @@ BreakpointResolverName::BreakpointResolverName
m_func_name_type_mask (func_name_type_mask),
m_class_name (),
m_regex (),
m_match_type (type)
m_match_type (type),
m_skip_prologue (skip_prologue)
{
if (func_name_type_mask == eFunctionNameTypeAuto)
{
@@ -92,13 +94,15 @@ BreakpointResolverName::BreakpointResolverName
BreakpointResolverName::BreakpointResolverName
(
Breakpoint *bkpt,
RegularExpression &func_regex
RegularExpression &func_regex,
bool skip_prologue
) :
BreakpointResolver (bkpt, BreakpointResolver::NameResolver),
m_func_name (NULL),
m_class_name (NULL),
m_regex (func_regex),
m_match_type (Breakpoint::Regexp)
m_match_type (Breakpoint::Regexp),
m_skip_prologue (skip_prologue)
{
}
@@ -108,13 +112,15 @@ BreakpointResolverName::BreakpointResolverName
Breakpoint *bkpt,
const char *class_name,
const char *method,
Breakpoint::MatchType type
Breakpoint::MatchType type,
bool skip_prologue
) :
BreakpointResolver (bkpt, BreakpointResolver::NameResolver),
m_func_name (method),
m_class_name (class_name),
m_regex (),
m_match_type (type)
m_match_type (type),
m_skip_prologue (skip_prologue)
{
}
@@ -139,18 +145,12 @@ BreakpointResolverName::SearchCallback
SymbolContextList func_list;
SymbolContextList sym_list;
bool skip_prologue = true;
uint32_t i;
bool new_location;
SymbolContext sc;
Address break_addr;
assert (m_breakpoint != NULL);
if (context.target_sp)
{
skip_prologue = context.target_sp->GetSkipPrologue();
}
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
if (m_class_name)
@@ -294,7 +294,7 @@ BreakpointResolverName::SearchCallback
else if (sc.function)
{
break_addr = sc.function->GetAddressRange().GetBaseAddress();
if (skip_prologue)
if (m_skip_prologue)
{
if (break_addr.IsValid())
{
@@ -333,7 +333,7 @@ BreakpointResolverName::SearchCallback
{
break_addr = sc.symbol->GetAddressRangePtr()->GetBaseAddress();
if (skip_prologue)
if (m_skip_prologue)
{
const uint32_t prologue_byte_size = sc.symbol->GetPrologueByteSize();
if (prologue_byte_size)

View File

@@ -87,6 +87,7 @@ DynamicLoaderMacOSXKernel::CreateInstance (Process* process, bool force)
DynamicLoaderMacOSXKernel::DynamicLoaderMacOSXKernel (Process* process) :
DynamicLoader(process),
m_kernel(),
m_kext_summary_header_ptr_addr (),
m_kext_summary_header_addr (),
m_kext_summary_header (),
m_break_id (LLDB_INVALID_BREAK_ID),
@@ -150,6 +151,7 @@ DynamicLoaderMacOSXKernel::Clear (bool clear_process)
if (clear_process)
m_process = NULL;
m_kernel.Clear(false);
m_kext_summary_header_ptr_addr.Clear();
m_kext_summary_header_addr.Clear();
m_kext_summaries.clear();
m_break_id = LLDB_INVALID_BREAK_ID;
@@ -165,7 +167,7 @@ DynamicLoaderMacOSXKernel::Clear (bool clear_process)
void
DynamicLoaderMacOSXKernel::LoadKernelModuleIfNeeded()
{
if (!m_kext_summary_header_addr.IsValid())
if (!m_kext_summary_header_ptr_addr.IsValid())
{
m_kernel.Clear(false);
m_kernel.module_sp = m_process->GetTarget().GetExecutableModule();
@@ -176,7 +178,7 @@ DynamicLoaderMacOSXKernel::LoadKernelModuleIfNeeded()
const Symbol *symbol = NULL;
symbol = m_kernel.module_sp->FindFirstSymbolWithNameAndType (kext_summary_symbol, eSymbolTypeData);
if (symbol)
m_kext_summary_header_addr = symbol->GetValue();
m_kext_summary_header_ptr_addr = symbol->GetValue();
symbol = m_kernel.module_sp->FindFirstSymbolWithNameAndType (mach_header_name, eSymbolTypeAbsolute);
if (symbol)
@@ -395,7 +397,15 @@ DynamicLoaderMacOSXKernel::BreakpointHit (StoppointCallbackContext *context,
user_id_t break_id,
user_id_t break_loc_id)
{
LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
if (log)
log->Printf ("DynamicLoaderMacOSXKernel::BreakpointHit (...)\n");
ReadAllKextSummaries ();
if (log)
PutToLog(log.get());
return GetStopWhenImagesChange();
}
@@ -408,7 +418,7 @@ DynamicLoaderMacOSXKernel::ReadKextSummaryHeader ()
// the all image infos is already valid for this process stop ID
m_kext_summaries.clear();
if (m_kext_summary_header_addr.IsValid())
if (m_kext_summary_header_ptr_addr.IsValid())
{
const uint32_t addr_size = m_kernel.GetAddressByteSize ();
const ByteOrder byte_order = m_kernel.GetByteOrder();
@@ -419,17 +429,29 @@ DynamicLoaderMacOSXKernel::ReadKextSummaryHeader ()
DataExtractor data (buf, sizeof(buf), byte_order, addr_size);
const size_t count = 4 * sizeof(uint32_t) + addr_size;
const bool prefer_file_cache = false;
const size_t bytes_read = m_process->GetTarget().ReadMemory (m_kext_summary_header_addr, prefer_file_cache, buf, count, error);
if (bytes_read == count)
if (m_process->GetTarget().ReadPointerFromMemory (m_kext_summary_header_ptr_addr,
prefer_file_cache,
error,
m_kext_summary_header_addr))
{
uint32_t offset = 0;
m_kext_summary_header.version = data.GetU32(&offset);
m_kext_summary_header.entry_size = data.GetU32(&offset);
m_kext_summary_header.entry_count = data.GetU32(&offset);
m_kext_summary_header.reserved = data.GetU32(&offset);
return true;
// We got a valid address for our kext summary header and make sure it isn't NULL
if (m_kext_summary_header_addr.IsValid() &&
m_kext_summary_header_addr.GetFileAddress() != 0)
{
const size_t bytes_read = m_process->GetTarget().ReadMemory (m_kext_summary_header_addr, prefer_file_cache, buf, count, error);
if (bytes_read == count)
{
uint32_t offset = 0;
m_kext_summary_header.version = data.GetU32(&offset);
m_kext_summary_header.entry_size = data.GetU32(&offset);
m_kext_summary_header.entry_count = data.GetU32(&offset);
m_kext_summary_header.reserved = data.GetU32(&offset);
return true;
}
}
}
}
m_kext_summary_header_addr.Clear();
return false;
}
@@ -471,16 +493,9 @@ DynamicLoaderMacOSXKernel::AddModulesUsingImageInfos (OSKextLoadedKextSummary::c
{
// Now add these images to the main list.
ModuleList loaded_module_list;
LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
for (uint32_t idx = 0; idx < image_infos.size(); ++idx)
{
if (log)
{
log->Printf ("Adding new image at address=0x%16.16llx.", image_infos[idx].address);
image_infos[idx].PutToLog (log.get());
}
m_kext_summaries.push_back(image_infos[idx]);
if (FindTargetModule (image_infos[idx], true, NULL))
@@ -517,8 +532,8 @@ DynamicLoaderMacOSXKernel::AddModulesUsingImageInfos (OSKextLoadedKextSummary::c
}
}
}
if (log)
loaded_module_list.LogUUIDAndPaths (log, "DynamicLoaderMacOSXKernel::ModulesDidLoad");
// if (log)
// loaded_module_list.LogUUIDAndPaths (log, "DynamicLoaderMacOSXKernel::ModulesDidLoad");
m_process->GetTarget().ModulesDidLoad (loaded_module_list);
}
return true;
@@ -895,11 +910,14 @@ DynamicLoaderMacOSXKernel::SetNotificationBreakpointIfNeeded ()
{
DEBUG_PRINTF("DynamicLoaderMacOSXKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
const bool internal_bp = false;
const LazyBool skip_prologue = eLazyBoolNo;
Breakpoint *bp = m_process->GetTarget().CreateBreakpoint (&m_kernel.module_sp->GetFileSpec(),
"OSKextLoadedKextSummariesUpdated",
eFunctionNameTypeFull,
internal_bp).get();
internal_bp,
skip_prologue).get();
bp->SetCallback (DynamicLoaderMacOSXKernel::BreakpointHitCallback, this, true);
m_break_id = bp->GetID();

View File

@@ -411,6 +411,7 @@ protected:
UnloadImageLoadAddress (OSKextLoadedKextSummary& info);
OSKextLoadedKextSummary m_kernel; // Info about the current kernel image being used
lldb_private::Address m_kext_summary_header_ptr_addr;
lldb_private::Address m_kext_summary_header_addr;
OSKextLoadedKextSummaryHeader m_kext_summary_header;
OSKextLoadedKextSummary::collection m_kext_summaries;

View File

@@ -1218,16 +1218,30 @@ SymbolFileDWARF::ParseChildMembers
if (is_artificial == false)
{
Type *member_type = ResolveTypeUID(encoding_uid);
assert(member_type);
if (accessibility == eAccessNone)
accessibility = default_accessibility;
member_accessibilities.push_back(accessibility);
if (member_type)
{
if (accessibility == eAccessNone)
accessibility = default_accessibility;
member_accessibilities.push_back(accessibility);
GetClangASTContext().AddFieldToRecordType (class_clang_type,
name,
member_type->GetClangLayoutType(),
accessibility,
bit_size);
GetClangASTContext().AddFieldToRecordType (class_clang_type,
name,
member_type->GetClangLayoutType(),
accessibility,
bit_size);
}
else
{
if (name)
ReportError ("0x%8.8x: DW_TAG_member '%s' refers to type 0x%8.8x which was unable to be parsed",
die->GetOffset(),
name,
encoding_uid);
else
ReportError ("0x%8.8x: DW_TAG_member refers to type 0x%8.8x which was unable to be parsed",
die->GetOffset(),
encoding_uid);
}
}
}
++member_idx;
@@ -2237,6 +2251,19 @@ SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, Symb
// Return the number of variable that were appended to the list
return sc_list.GetSize() - original_size;
}
void
SymbolFileDWARF::ReportError (const char *format, ...)
{
::fprintf (stderr,
"error: %s/%s ",
m_obj_file->GetFileSpec().GetDirectory().GetCString(),
m_obj_file->GetFileSpec().GetFilename().GetCString());
va_list args;
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
}
uint32_t
SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types)

View File

@@ -347,6 +347,9 @@ protected:
m_decl_ctx_to_die[decl_ctx] = die;
}
void
ReportError (const char *format, ...);
SymbolFileDWARFDebugMap * m_debug_map_symfile;
clang::TranslationUnitDecl * m_clang_tu_decl;
lldb_private::Flags m_flags;

View File

@@ -164,7 +164,7 @@ SymbolContext::DumpStopContext
dumped_something = true;
s->PutCString(" at ");
if (line_entry.DumpStopContext(s, show_fullpaths))
return dumped_something;
dumped_something = true;
}
}
}

View File

@@ -213,13 +213,22 @@ Target::CreateBreakpoint (Address &addr, bool internal)
}
BreakpointSP
Target::CreateBreakpoint (const FileSpec *containingModule, const char *func_name, uint32_t func_name_type_mask, bool internal)
Target::CreateBreakpoint (const FileSpec *containingModule,
const char *func_name,
uint32_t func_name_type_mask,
bool internal,
LazyBool skip_prologue)
{
BreakpointSP bp_sp;
if (func_name)
{
SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, func_name, func_name_type_mask, Breakpoint::Exact));
BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
func_name,
func_name_type_mask,
Breakpoint::Exact,
skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
}
return bp_sp;
@@ -247,10 +256,15 @@ Target::GetSearchFilterForModule (const FileSpec *containingModule)
}
BreakpointSP
Target::CreateBreakpoint (const FileSpec *containingModule, RegularExpression &func_regex, bool internal)
Target::CreateBreakpoint (const FileSpec *containingModule,
RegularExpression &func_regex,
bool internal,
LazyBool skip_prologue)
{
SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule));
BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, func_regex));
BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
func_regex,
skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
return CreateBreakpoint (filter_sp, resolver_sp, internal);
}
@@ -600,19 +614,21 @@ Target::ReadMemory (const Address& addr, bool prefer_file_cache, void *dst, size
Address resolved_addr;
if (!addr.IsSectionOffset())
{
if (process_is_valid)
if (m_section_load_list.IsEmpty())
{
// Process is valid and we were given an address that
// isn't section offset, so assume this is a load address
load_addr = addr.GetOffset();
m_section_load_list.ResolveLoadAddress (addr.GetOffset(), resolved_addr);
// No sections are loaded, so we must assume we are not running
// yet and anything we are given is a file address.
file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
m_images.ResolveFileAddress (file_addr, resolved_addr);
}
else
{
// Process is NOT valid and we were given an address that
// isn't section offset, so assume this is a file address
file_addr = addr.GetOffset();
m_images.ResolveFileAddress(addr.GetOffset(), resolved_addr);
// We have at least one section loaded. This can be becuase
// we have manually loaded some sections with "target modules load ..."
// or because we have have a live process that has sections loaded
// through the dynamic loader
load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
}
}
if (!resolved_addr.IsValid())
@@ -674,6 +690,99 @@ Target::ReadMemory (const Address& addr, bool prefer_file_cache, void *dst, size
return 0;
}
size_t
Target::ReadScalarIntegerFromMemory (const Address& addr,
bool prefer_file_cache,
uint32_t byte_size,
bool is_signed,
Scalar &scalar,
Error &error)
{
uint64_t uval;
if (byte_size <= sizeof(uval))
{
size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
if (bytes_read == byte_size)
{
DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
uint32_t offset = 0;
if (byte_size <= 4)
scalar = data.GetMaxU32 (&offset, byte_size);
else
scalar = data.GetMaxU64 (&offset, byte_size);
if (is_signed)
scalar.SignExtend(byte_size * 8);
return bytes_read;
}
}
else
{
error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
}
return 0;
}
uint64_t
Target::ReadUnsignedIntegerFromMemory (const Address& addr,
bool prefer_file_cache,
size_t integer_byte_size,
uint64_t fail_value,
Error &error)
{
Scalar scalar;
if (ReadScalarIntegerFromMemory (addr,
prefer_file_cache,
integer_byte_size,
false,
scalar,
error))
return scalar.ULongLong(fail_value);
return fail_value;
}
bool
Target::ReadPointerFromMemory (const Address& addr,
bool prefer_file_cache,
Error &error,
Address &pointer_addr)
{
Scalar scalar;
if (ReadScalarIntegerFromMemory (addr,
prefer_file_cache,
m_arch.GetAddressByteSize(),
false,
scalar,
error))
{
addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
{
if (m_section_load_list.IsEmpty())
{
// No sections are loaded, so we must assume we are not running
// yet and anything we are given is a file address.
m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
}
else
{
// We have at least one section loaded. This can be becuase
// we have manually loaded some sections with "target modules load ..."
// or because we have have a live process that has sections loaded
// through the dynamic loader
m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
}
// We weren't able to resolve the pointer value, so just return
// an address with no section
if (!pointer_addr.IsValid())
pointer_addr.SetOffset (pointer_vm_addr);
return true;
}
}
return false;
}
ModuleSP
Target::GetSharedModule