llvm-project/lldb/source/Symbol/ObjectFile.cpp

746 lines
28 KiB
C++
Raw Normal View History

//===-- ObjectFile.cpp ------------------------------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.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/Section.h"
#include "lldb/Symbol/ObjectContainer.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataBuffer.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/RegularExpression.h"
#include "lldb/Utility/Timer.h"
#include "lldb/lldb-private.h"
using namespace lldb;
using namespace lldb_private;
ObjectFileSP
ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file,
lldb::offset_t file_offset, lldb::offset_t file_size,
DataBufferSP &data_sp, lldb::offset_t &data_offset) {
ObjectFileSP object_file_sp;
if (module_sp) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(
func_cat,
"ObjectFile::FindPlugin (module = %s, file = %p, file_offset = "
"0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")",
module_sp->GetFileSpec().GetPath().c_str(),
static_cast<const void *>(file), static_cast<uint64_t>(file_offset),
static_cast<uint64_t>(file_size));
if (file) {
FileSpec archive_file;
ObjectContainerCreateInstance create_object_container_callback;
const bool file_exists = FileSystem::Instance().Exists(*file);
if (!data_sp) {
// We have an object name which most likely means we have a .o file in
// a static archive (.a file). Try and see if we have a cached archive
// first without reading any data first
if (file_exists && module_sp->GetObjectName()) {
for (uint32_t idx = 0;
(create_object_container_callback =
PluginManager::GetObjectContainerCreateCallbackAtIndex(
idx)) != nullptr;
++idx) {
std::unique_ptr<ObjectContainer> object_container_up(
create_object_container_callback(module_sp, data_sp,
data_offset, file, file_offset,
file_size));
if (object_container_up)
object_file_sp = object_container_up->GetObjectFile(file);
if (object_file_sp.get())
return object_file_sp;
}
}
// Ok, we didn't find any containers that have a named object, now lets
// read the first 512 bytes from the file so the object file and object
// container plug-ins can use these bytes to see if they can parse this
// file.
if (file_size > 0) {
data_sp = FileSystem::Instance().CreateDataBuffer(file->GetPath(),
512, file_offset);
data_offset = 0;
}
}
if (!data_sp || data_sp->GetByteSize() == 0) {
// Check for archive file with format "/path/to/archive.a(object.o)"
char path_with_object[PATH_MAX * 2];
module_sp->GetFileSpec().GetPath(path_with_object,
sizeof(path_with_object));
ConstString archive_object;
const bool must_exist = true;
if (ObjectFile::SplitArchivePathWithObject(
path_with_object, archive_file, archive_object, must_exist)) {
file_size = FileSystem::Instance().GetByteSize(archive_file);
if (file_size > 0) {
file = &archive_file;
module_sp->SetFileSpecAndObjectName(archive_file, archive_object);
// Check if this is a object container by iterating through all
// object container plugin instances and then trying to get an
// object file from the container plugins since we had a name.
// Also, don't read
// ANY data in case there is data cached in the container plug-ins
// (like BSD archives caching the contained objects within an
// file).
for (uint32_t idx = 0;
(create_object_container_callback =
PluginManager::GetObjectContainerCreateCallbackAtIndex(
idx)) != nullptr;
++idx) {
std::unique_ptr<ObjectContainer> object_container_up(
create_object_container_callback(module_sp, data_sp,
data_offset, file,
file_offset, file_size));
if (object_container_up)
object_file_sp = object_container_up->GetObjectFile(file);
if (object_file_sp.get())
return object_file_sp;
}
// We failed to find any cached object files in the container plug-
// ins, so lets read the first 512 bytes and try again below...
data_sp = FileSystem::Instance().CreateDataBuffer(
archive_file.GetPath(), 512, file_offset);
}
}
}
if (data_sp && data_sp->GetByteSize() > 0) {
// Check if this is a normal object file by iterating through all
// object file plugin instances.
ObjectFileCreateInstance create_object_file_callback;
for (uint32_t idx = 0;
(create_object_file_callback =
PluginManager::GetObjectFileCreateCallbackAtIndex(idx)) !=
nullptr;
++idx) {
object_file_sp.reset(create_object_file_callback(
module_sp, data_sp, data_offset, file, file_offset, file_size));
if (object_file_sp.get())
return object_file_sp;
}
// Check if this is a object container by iterating through all object
// container plugin instances and then trying to get an object file
// from the container.
for (uint32_t idx = 0;
(create_object_container_callback =
PluginManager::GetObjectContainerCreateCallbackAtIndex(
idx)) != nullptr;
++idx) {
std::unique_ptr<ObjectContainer> object_container_up(
create_object_container_callback(module_sp, data_sp, data_offset,
file, file_offset, file_size));
if (object_container_up)
object_file_sp = object_container_up->GetObjectFile(file);
if (object_file_sp.get())
return object_file_sp;
}
}
}
}
// We didn't find it, so clear our shared pointer in case it contains
// anything and return an empty shared pointer
object_file_sp.reset();
return object_file_sp;
}
ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp,
const ProcessSP &process_sp,
lldb::addr_t header_addr,
DataBufferSP &data_sp) {
ObjectFileSP object_file_sp;
if (module_sp) {
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat,
"ObjectFile::FindPlugin (module = "
"%s, process = %p, header_addr = "
"0x%" PRIx64 ")",
module_sp->GetFileSpec().GetPath().c_str(),
static_cast<void *>(process_sp.get()), header_addr);
uint32_t idx;
// Check if this is a normal object file by iterating through all object
// file plugin instances.
ObjectFileCreateMemoryInstance create_callback;
for (idx = 0;
(create_callback =
PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(idx)) !=
nullptr;
++idx) {
object_file_sp.reset(
create_callback(module_sp, data_sp, process_sp, header_addr));
if (object_file_sp.get())
return object_file_sp;
}
}
// We didn't find it, so clear our shared pointer in case it contains
// anything and return an empty shared pointer
object_file_sp.reset();
return object_file_sp;
}
size_t ObjectFile::GetModuleSpecifications(const FileSpec &file,
lldb::offset_t file_offset,
lldb::offset_t file_size,
ModuleSpecList &specs) {
DataBufferSP data_sp =
FileSystem::Instance().CreateDataBuffer(file.GetPath(), 512, file_offset);
if (data_sp) {
if (file_size == 0) {
const lldb::offset_t actual_file_size =
FileSystem::Instance().GetByteSize(file);
if (actual_file_size > file_offset)
file_size = actual_file_size - file_offset;
}
return ObjectFile::GetModuleSpecifications(file, // file spec
data_sp, // data bytes
0, // data offset
file_offset, // file offset
file_size, // file length
specs);
}
return 0;
}
size_t ObjectFile::GetModuleSpecifications(
const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, lldb::offset_t file_offset,
lldb::offset_t file_size, lldb_private::ModuleSpecList &specs) {
const size_t initial_count = specs.GetSize();
ObjectFileGetModuleSpecifications callback;
uint32_t i;
// Try the ObjectFile plug-ins
for (i = 0;
(callback =
PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex(
i)) != nullptr;
++i) {
if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
return specs.GetSize() - initial_count;
}
// Try the ObjectContainer plug-ins
for (i = 0;
(callback = PluginManager::
GetObjectContainerGetModuleSpecificationsCallbackAtIndex(i)) !=
nullptr;
++i) {
if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
return specs.GetSize() - initial_count;
}
return 0;
}
ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp,
const FileSpec *file_spec_ptr,
lldb::offset_t file_offset, lldb::offset_t length,
const lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset)
: ModuleChild(module_sp),
m_file(), // This file could be different from the original module's file
m_type(eTypeInvalid), m_strata(eStrataInvalid),
m_file_offset(file_offset), m_length(length), m_data(), m_process_wp(),
m_memory_addr(LLDB_INVALID_ADDRESS), m_sections_up(), m_symtab_up(),
m_synthetic_symbol_idx(0) {
if (file_spec_ptr)
m_file = *file_spec_ptr;
if (data_sp)
m_data.SetData(data_sp, data_offset, length);
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
if (log)
log->Printf("%p ObjectFile::ObjectFile() module = %p (%s), file = %s, "
"file_offset = 0x%8.8" PRIx64 ", size = %" PRIu64,
static_cast<void *>(this), static_cast<void *>(module_sp.get()),
module_sp->GetSpecificationDescription().c_str(),
m_file ? m_file.GetPath().c_str() : "<NULL>", m_file_offset,
m_length);
}
ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp,
const ProcessSP &process_sp, lldb::addr_t header_addr,
DataBufferSP &header_data_sp)
: ModuleChild(module_sp), m_file(), m_type(eTypeInvalid),
m_strata(eStrataInvalid), m_file_offset(0), m_length(0), m_data(),
m_process_wp(process_sp), m_memory_addr(header_addr), m_sections_up(),
m_symtab_up(), m_synthetic_symbol_idx(0) {
if (header_data_sp)
m_data.SetData(header_data_sp, 0, header_data_sp->GetByteSize());
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
if (log)
log->Printf("%p ObjectFile::ObjectFile() module = %p (%s), process = %p, "
"header_addr = 0x%" PRIx64,
static_cast<void *>(this), static_cast<void *>(module_sp.get()),
module_sp->GetSpecificationDescription().c_str(),
static_cast<void *>(process_sp.get()), m_memory_addr);
}
ObjectFile::~ObjectFile() {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
if (log)
log->Printf("%p ObjectFile::~ObjectFile ()\n", static_cast<void *>(this));
}
bool ObjectFile::SetModulesArchitecture(const ArchSpec &new_arch) {
ModuleSP module_sp(GetModule());
if (module_sp)
return module_sp->SetArchitecture(new_arch);
return false;
}
AddressClass ObjectFile::GetAddressClass(addr_t file_addr) {
Symtab *symtab = GetSymtab();
if (symtab) {
Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
if (symbol) {
if (symbol->ValueIsAddress()) {
const SectionSP section_sp(symbol->GetAddressRef().GetSection());
if (section_sp) {
const SectionType section_type = section_sp->GetType();
switch (section_type) {
case eSectionTypeInvalid:
return AddressClass::eUnknown;
case eSectionTypeCode:
return AddressClass::eCode;
case eSectionTypeContainer:
return AddressClass::eUnknown;
case eSectionTypeData:
case eSectionTypeDataCString:
case eSectionTypeDataCStringPointers:
case eSectionTypeDataSymbolAddress:
case eSectionTypeData4:
case eSectionTypeData8:
case eSectionTypeData16:
case eSectionTypeDataPointers:
case eSectionTypeZeroFill:
case eSectionTypeDataObjCMessageRefs:
case eSectionTypeDataObjCCFStrings:
case eSectionTypeGoSymtab:
return AddressClass::eData;
case eSectionTypeDebug:
case eSectionTypeDWARFDebugAbbrev:
case eSectionTypeDWARFDebugAbbrevDwo:
case eSectionTypeDWARFDebugAddr:
case eSectionTypeDWARFDebugAranges:
case eSectionTypeDWARFDebugCuIndex:
case eSectionTypeDWARFDebugFrame:
case eSectionTypeDWARFDebugInfo:
case eSectionTypeDWARFDebugInfoDwo:
case eSectionTypeDWARFDebugLine:
case eSectionTypeDWARFDebugLineStr:
case eSectionTypeDWARFDebugLoc:
case eSectionTypeDWARFDebugLocLists:
case eSectionTypeDWARFDebugMacInfo:
case eSectionTypeDWARFDebugMacro:
case eSectionTypeDWARFDebugNames:
case eSectionTypeDWARFDebugPubNames:
case eSectionTypeDWARFDebugPubTypes:
case eSectionTypeDWARFDebugRanges:
case eSectionTypeDWARFDebugRngLists:
case eSectionTypeDWARFDebugStr:
case eSectionTypeDWARFDebugStrDwo:
case eSectionTypeDWARFDebugStrOffsets:
case eSectionTypeDWARFDebugStrOffsetsDwo:
case eSectionTypeDWARFDebugTypes:
case eSectionTypeDWARFAppleNames:
case eSectionTypeDWARFAppleTypes:
case eSectionTypeDWARFAppleNamespaces:
case eSectionTypeDWARFAppleObjC:
case eSectionTypeDWARFGNUDebugAltLink:
return AddressClass::eDebug;
case eSectionTypeEHFrame:
case eSectionTypeARMexidx:
case eSectionTypeARMextab:
case eSectionTypeCompactUnwind:
return AddressClass::eRuntime;
case eSectionTypeELFSymbolTable:
case eSectionTypeELFDynamicSymbols:
case eSectionTypeELFRelocationEntries:
case eSectionTypeELFDynamicLinkInfo:
case eSectionTypeOther:
return AddressClass::eUnknown;
case eSectionTypeAbsoluteAddress:
// In case of absolute sections decide the address class based on
// the symbol type because the section type isn't specify if it is
// a code or a data section.
break;
}
Added more platform support. There are now some new commands: platform status -- gets status information for the selected platform platform create <platform-name> -- creates a new instance of a remote platform platform list -- list all available platforms platform select -- select a platform instance as the current platform (not working yet) When using "platform create" it will create a remote platform and make it the selected platform. For instances for iPhone OS debugging on Mac OS X one can do: (lldb) platform create remote-ios --sdk-version=4.0 Remote platform: iOS platform SDK version: 4.0 SDK path: "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0" Not connected to a remote device. (lldb) file ~/Documents/a.out Current executable set to '~/Documents/a.out' (armv6). (lldb) image list [ 0] /Volumes/work/gclayton/Documents/devb/attach/a.out [ 1] /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0/Symbols/usr/lib/dyld [ 2] /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0/Symbols/usr/lib/libSystem.B.dylib Note that this is all happening prior to running _or_ connecting to a remote platform. Once connected to a remote platform the OS version might change which means we will need to update our dependecies. Also once we run, we will need to match up the actualy binaries with the actualy UUID's to files in the SDK, or download and cache them locally. This is just the start of the remote platforms, but this modification is the first iteration in getting the platforms really doing something. llvm-svn: 127934
2011-03-19 09:12:21 +08:00
}
}
const SymbolType symbol_type = symbol->GetType();
switch (symbol_type) {
case eSymbolTypeAny:
return AddressClass::eUnknown;
case eSymbolTypeAbsolute:
return AddressClass::eUnknown;
case eSymbolTypeCode:
return AddressClass::eCode;
case eSymbolTypeTrampoline:
return AddressClass::eCode;
case eSymbolTypeResolver:
return AddressClass::eCode;
case eSymbolTypeData:
return AddressClass::eData;
case eSymbolTypeRuntime:
return AddressClass::eRuntime;
case eSymbolTypeException:
return AddressClass::eRuntime;
case eSymbolTypeSourceFile:
return AddressClass::eDebug;
case eSymbolTypeHeaderFile:
return AddressClass::eDebug;
case eSymbolTypeObjectFile:
return AddressClass::eDebug;
case eSymbolTypeCommonBlock:
return AddressClass::eDebug;
case eSymbolTypeBlock:
return AddressClass::eDebug;
case eSymbolTypeLocal:
return AddressClass::eData;
case eSymbolTypeParam:
return AddressClass::eData;
case eSymbolTypeVariable:
return AddressClass::eData;
case eSymbolTypeVariableType:
return AddressClass::eDebug;
case eSymbolTypeLineEntry:
return AddressClass::eDebug;
case eSymbolTypeLineHeader:
return AddressClass::eDebug;
case eSymbolTypeScopeBegin:
return AddressClass::eDebug;
case eSymbolTypeScopeEnd:
return AddressClass::eDebug;
case eSymbolTypeAdditional:
return AddressClass::eUnknown;
case eSymbolTypeCompiler:
return AddressClass::eDebug;
case eSymbolTypeInstrumentation:
return AddressClass::eDebug;
case eSymbolTypeUndefined:
return AddressClass::eUnknown;
case eSymbolTypeObjCClass:
return AddressClass::eRuntime;
case eSymbolTypeObjCMetaClass:
return AddressClass::eRuntime;
case eSymbolTypeObjCIVar:
return AddressClass::eRuntime;
case eSymbolTypeReExported:
return AddressClass::eRuntime;
}
Added more platform support. There are now some new commands: platform status -- gets status information for the selected platform platform create <platform-name> -- creates a new instance of a remote platform platform list -- list all available platforms platform select -- select a platform instance as the current platform (not working yet) When using "platform create" it will create a remote platform and make it the selected platform. For instances for iPhone OS debugging on Mac OS X one can do: (lldb) platform create remote-ios --sdk-version=4.0 Remote platform: iOS platform SDK version: 4.0 SDK path: "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0" Not connected to a remote device. (lldb) file ~/Documents/a.out Current executable set to '~/Documents/a.out' (armv6). (lldb) image list [ 0] /Volumes/work/gclayton/Documents/devb/attach/a.out [ 1] /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0/Symbols/usr/lib/dyld [ 2] /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0/Symbols/usr/lib/libSystem.B.dylib Note that this is all happening prior to running _or_ connecting to a remote platform. Once connected to a remote platform the OS version might change which means we will need to update our dependecies. Also once we run, we will need to match up the actualy binaries with the actualy UUID's to files in the SDK, or download and cache them locally. This is just the start of the remote platforms, but this modification is the first iteration in getting the platforms really doing something. llvm-svn: 127934
2011-03-19 09:12:21 +08:00
}
}
return AddressClass::eUnknown;
Added more platform support. There are now some new commands: platform status -- gets status information for the selected platform platform create <platform-name> -- creates a new instance of a remote platform platform list -- list all available platforms platform select -- select a platform instance as the current platform (not working yet) When using "platform create" it will create a remote platform and make it the selected platform. For instances for iPhone OS debugging on Mac OS X one can do: (lldb) platform create remote-ios --sdk-version=4.0 Remote platform: iOS platform SDK version: 4.0 SDK path: "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0" Not connected to a remote device. (lldb) file ~/Documents/a.out Current executable set to '~/Documents/a.out' (armv6). (lldb) image list [ 0] /Volumes/work/gclayton/Documents/devb/attach/a.out [ 1] /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0/Symbols/usr/lib/dyld [ 2] /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0/Symbols/usr/lib/libSystem.B.dylib Note that this is all happening prior to running _or_ connecting to a remote platform. Once connected to a remote platform the OS version might change which means we will need to update our dependecies. Also once we run, we will need to match up the actualy binaries with the actualy UUID's to files in the SDK, or download and cache them locally. This is just the start of the remote platforms, but this modification is the first iteration in getting the platforms really doing something. llvm-svn: 127934
2011-03-19 09:12:21 +08:00
}
DataBufferSP ObjectFile::ReadMemory(const ProcessSP &process_sp,
lldb::addr_t addr, size_t byte_size) {
DataBufferSP data_sp;
if (process_sp) {
std::unique_ptr<DataBufferHeap> data_up(new DataBufferHeap(byte_size, 0));
Status error;
const size_t bytes_read = process_sp->ReadMemory(
addr, data_up->GetBytes(), data_up->GetByteSize(), error);
if (bytes_read == byte_size)
data_sp.reset(data_up.release());
}
return data_sp;
}
size_t ObjectFile::GetData(lldb::offset_t offset, size_t length,
DataExtractor &data) const {
// The entire file has already been mmap'ed into m_data, so just copy from
// there as the back mmap buffer will be shared with shared pointers.
return data.SetData(m_data, offset, length);
}
size_t ObjectFile::CopyData(lldb::offset_t offset, size_t length,
void *dst) const {
// The entire file has already been mmap'ed into m_data, so just copy from
// there Note that the data remains in target byte order.
return m_data.CopyData(offset, length, dst);
}
Added more platform support. There are now some new commands: platform status -- gets status information for the selected platform platform create <platform-name> -- creates a new instance of a remote platform platform list -- list all available platforms platform select -- select a platform instance as the current platform (not working yet) When using "platform create" it will create a remote platform and make it the selected platform. For instances for iPhone OS debugging on Mac OS X one can do: (lldb) platform create remote-ios --sdk-version=4.0 Remote platform: iOS platform SDK version: 4.0 SDK path: "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0" Not connected to a remote device. (lldb) file ~/Documents/a.out Current executable set to '~/Documents/a.out' (armv6). (lldb) image list [ 0] /Volumes/work/gclayton/Documents/devb/attach/a.out [ 1] /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0/Symbols/usr/lib/dyld [ 2] /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0/Symbols/usr/lib/libSystem.B.dylib Note that this is all happening prior to running _or_ connecting to a remote platform. Once connected to a remote platform the OS version might change which means we will need to update our dependecies. Also once we run, we will need to match up the actualy binaries with the actualy UUID's to files in the SDK, or download and cache them locally. This is just the start of the remote platforms, but this modification is the first iteration in getting the platforms really doing something. llvm-svn: 127934
2011-03-19 09:12:21 +08:00
size_t ObjectFile::ReadSectionData(Section *section,
lldb::offset_t section_offset, void *dst,
size_t dst_len) {
assert(section);
section_offset *= section->GetTargetByteSize();
// If some other objectfile owns this data, pass this to them.
if (section->GetObjectFile() != this)
return section->GetObjectFile()->ReadSectionData(section, section_offset,
dst, dst_len);
if (IsInMemory()) {
ProcessSP process_sp(m_process_wp.lock());
if (process_sp) {
Status error;
const addr_t base_load_addr =
section->GetLoadBaseAddress(&process_sp->GetTarget());
if (base_load_addr != LLDB_INVALID_ADDRESS)
return process_sp->ReadMemory(base_load_addr + section_offset, dst,
dst_len, error);
}
} else {
if (!section->IsRelocated())
RelocateSection(section);
const lldb::offset_t section_file_size = section->GetFileSize();
if (section_offset < section_file_size) {
const size_t section_bytes_left = section_file_size - section_offset;
size_t section_dst_len = dst_len;
if (section_dst_len > section_bytes_left)
section_dst_len = section_bytes_left;
return CopyData(section->GetFileOffset() + section_offset,
section_dst_len, dst);
} else {
if (section->GetType() == eSectionTypeZeroFill) {
const uint64_t section_size = section->GetByteSize();
const uint64_t section_bytes_left = section_size - section_offset;
uint64_t section_dst_len = dst_len;
if (section_dst_len > section_bytes_left)
section_dst_len = section_bytes_left;
memset(dst, 0, section_dst_len);
return section_dst_len;
}
}
}
return 0;
}
//----------------------------------------------------------------------
// Get the section data the file on disk
//----------------------------------------------------------------------
size_t ObjectFile::ReadSectionData(Section *section,
DataExtractor &section_data) {
// If some other objectfile owns this data, pass this to them.
if (section->GetObjectFile() != this)
return section->GetObjectFile()->ReadSectionData(section, section_data);
if (IsInMemory()) {
ProcessSP process_sp(m_process_wp.lock());
if (process_sp) {
const addr_t base_load_addr =
section->GetLoadBaseAddress(&process_sp->GetTarget());
if (base_load_addr != LLDB_INVALID_ADDRESS) {
DataBufferSP data_sp(
ReadMemory(process_sp, base_load_addr, section->GetByteSize()));
if (data_sp) {
section_data.SetData(data_sp, 0, data_sp->GetByteSize());
section_data.SetByteOrder(process_sp->GetByteOrder());
section_data.SetAddressByteSize(process_sp->GetAddressByteSize());
return section_data.GetByteSize();
}
}
}
return GetData(section->GetFileOffset(), section->GetFileSize(),
section_data);
} else {
// The object file now contains a full mmap'ed copy of the object file
// data, so just use this
if (!section->IsRelocated())
RelocateSection(section);
return GetData(section->GetFileOffset(), section->GetFileSize(),
section_data);
}
}
bool ObjectFile::SplitArchivePathWithObject(const char *path_with_object,
FileSpec &archive_file,
ConstString &archive_object,
bool must_exist) {
RegularExpression g_object_regex(llvm::StringRef("(.*)\\(([^\\)]+)\\)$"));
RegularExpression::Match regex_match(2);
if (g_object_regex.Execute(llvm::StringRef::withNullAsEmpty(path_with_object),
&regex_match)) {
std::string path;
std::string obj;
if (regex_match.GetMatchAtIndex(path_with_object, 1, path) &&
regex_match.GetMatchAtIndex(path_with_object, 2, obj)) {
archive_file.SetFile(path, FileSpec::Style::native);
archive_object.SetCString(obj.c_str());
return !(must_exist && !FileSystem::Instance().Exists(archive_file));
<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
}
}
return false;
<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
}
void ObjectFile::ClearSymtab() {
ModuleSP module_sp(GetModule());
if (module_sp) {
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
if (log)
log->Printf("%p ObjectFile::ClearSymtab () symtab = %p",
static_cast<void *>(this),
static_cast<void *>(m_symtab_up.get()));
m_symtab_up.reset();
}
}
SectionList *ObjectFile::GetSectionList(bool update_module_section_list) {
if (m_sections_up == nullptr) {
if (update_module_section_list) {
ModuleSP module_sp(GetModule());
if (module_sp) {
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
CreateSections(*module_sp->GetUnifiedSectionList());
}
} else {
SectionList unified_section_list;
CreateSections(unified_section_list);
}
}
return m_sections_up.get();
}
lldb::SymbolType
ObjectFile::GetSymbolTypeFromName(llvm::StringRef name,
lldb::SymbolType symbol_type_hint) {
if (!name.empty()) {
if (name.startswith("_OBJC_")) {
// ObjC
if (name.startswith("_OBJC_CLASS_$_"))
return lldb::eSymbolTypeObjCClass;
if (name.startswith("_OBJC_METACLASS_$_"))
return lldb::eSymbolTypeObjCMetaClass;
if (name.startswith("_OBJC_IVAR_$_"))
return lldb::eSymbolTypeObjCIVar;
} else if (name.startswith(".objc_class_name_")) {
// ObjC v1
return lldb::eSymbolTypeObjCClass;
}
}
return symbol_type_hint;
}
ConstString ObjectFile::GetNextSyntheticSymbolName() {
StreamString ss;
ConstString file_name = GetModule()->GetFileSpec().GetFilename();
ss.Printf("___lldb_unnamed_symbol%u$$%s", ++m_synthetic_symbol_idx,
file_name.GetCString());
return ConstString(ss.GetString());
}
std::vector<ObjectFile::LoadableData>
ObjectFile::GetLoadableData(Target &target) {
std::vector<LoadableData> loadables;
SectionList *section_list = GetSectionList();
if (!section_list)
return loadables;
// Create a list of loadable data from loadable sections
size_t section_count = section_list->GetNumSections(0);
for (size_t i = 0; i < section_count; ++i) {
LoadableData loadable;
SectionSP section_sp = section_list->GetSectionAtIndex(i);
loadable.Dest =
target.GetSectionLoadList().GetSectionLoadAddress(section_sp);
if (loadable.Dest == LLDB_INVALID_ADDRESS)
continue;
// We can skip sections like bss
if (section_sp->GetFileSize() == 0)
continue;
DataExtractor section_data;
section_sp->GetSectionData(section_data);
loadable.Contents = llvm::ArrayRef<uint8_t>(section_data.GetDataStart(),
section_data.GetByteSize());
loadables.push_back(loadable);
}
return loadables;
}
void ObjectFile::RelocateSection(lldb_private::Section *section)
{
}
DataBufferSP ObjectFile::MapFileData(const FileSpec &file, uint64_t Size,
uint64_t Offset) {
return FileSystem::Instance().CreateDataBuffer(file.GetPath(), Size, Offset);
}
Re-commit "Introduce ObjectFileBreakpad" This re-commits r348592, which was reverted due to a failing test on macos. The issue was that I was passing a null pointer for the "CreateMemoryInstance" callback when registering ObjectFileBreakpad, which caused crashes when attemping to load modules from memory. The correct thing to do is to pass a callback which always returns a null pointer (as breakpad files are never loaded in inferior memory). It turns out that there is only one test which exercises this code path, and it's mac-only, so I've create a new test which should run everywhere (except windows, as one cannot delete an executable which is being run). Unfortunately, this test still fails on linux for other reasons, but at least it gives us something to aim for. The original commit message was: This patch adds the scaffolding necessary for lldb to recognise symbol files generated by breakpad. These (textual) files contain just enough information to be able to produce a backtrace from a crash dump. This information includes: - UUID, architecture and name of the module - line tables - list of symbols - unwind information A minimal breakpad file could look like this: MODULE Linux x86_64 0000000024B5D199F0F766FFFFFF5DC30 a.out INFO CODE_ID 00000000B52499D1F0F766FFFFFF5DC3 FILE 0 /tmp/a.c FUNC 1010 10 0 _start 1010 4 4 0 1014 5 5 0 1019 5 6 0 101e 2 7 0 PUBLIC 1010 0 _start STACK CFI INIT 1010 10 .cfa: $rsp 8 + .ra: .cfa -8 + ^ STACK CFI 1011 $rbp: .cfa -16 + ^ .cfa: $rsp 16 + STACK CFI 1014 .cfa: $rbp 16 + Even though this data would normally be considered "symbol" information, in the current lldb infrastructure it is assumed every SymbolFile object is backed by an ObjectFile instance. So, in order to better interoperate with the rest of the code (particularly symbol vendors). In this patch I just parse the breakpad header, which is enough to populate the UUID and architecture fields of the ObjectFile interface. The rough plan for followup patches is to expose the individual parts of the breakpad file as ObjectFile "sections", which can then be used by other parts of the codebase (SymbolFileBreakpad ?) to vend the necessary information. Reviewers: clayborg, zturner, lemo, amccarth Subscribers: mgorny, fedor.sergeev, markmentovai, lldb-commits Differential Revision: https://reviews.llvm.org/D55214 llvm-svn: 348773
2018-12-11 01:16:38 +08:00
void llvm::format_provider<ObjectFile::Type>::format(
const ObjectFile::Type &type, raw_ostream &OS, StringRef Style) {
switch (type) {
case ObjectFile::eTypeInvalid:
OS << "invalid";
break;
case ObjectFile::eTypeCoreFile:
OS << "core file";
break;
case ObjectFile::eTypeExecutable:
OS << "executable";
break;
case ObjectFile::eTypeDebugInfo:
OS << "debug info";
break;
case ObjectFile::eTypeDynamicLinker:
OS << "dynamic linker";
break;
case ObjectFile::eTypeObjectFile:
OS << "object file";
break;
case ObjectFile::eTypeSharedLibrary:
OS << "shared library";
break;
case ObjectFile::eTypeStubLibrary:
OS << "stub library";
break;
case ObjectFile::eTypeJIT:
OS << "jit";
break;
case ObjectFile::eTypeUnknown:
OS << "unknown";
break;
}
}
void llvm::format_provider<ObjectFile::Strata>::format(
const ObjectFile::Strata &strata, raw_ostream &OS, StringRef Style) {
switch (strata) {
case ObjectFile::eStrataInvalid:
OS << "invalid";
break;
case ObjectFile::eStrataUnknown:
OS << "unknown";
break;
case ObjectFile::eStrataUser:
OS << "user";
break;
case ObjectFile::eStrataKernel:
OS << "kernel";
break;
case ObjectFile::eStrataRawImage:
OS << "raw image";
break;
case ObjectFile::eStrataJIT:
OS << "jit";
break;
}
}