//---------------------------------------------------------------------- // Assign the data for this object to be a subrange of the shared data in // "data_sp" starting "data_offset" bytes into "data_sp" and ending // "data_length" bytes later. If "data_offset" is not a valid offset into // "data_sp", then this object will contain no bytes. If "data_offset" is // within "data_sp" yet "data_length" is too large, the length will be capped // at the number of bytes remaining in "data_sp". A ref counted pointer to the // data in "data_sp" will be made in this object IF the number of bytes this // object refers to in greater than zero (if at least one byte was available // starting at "data_offset") to ensure the data stays around as long as it is // needed. The address size and endian swap settings will remain unchanged from // their current settings. //---------------------------------------------------------------------- uint32_t DataEncoder::SetData(const DataBufferSP &data_sp, uint32_t data_offset, uint32_t data_length) { m_start = m_end = nullptr; if (data_length > 0) { m_data_sp = data_sp; if (data_sp) { const size_t data_size = data_sp->GetByteSize(); if (data_offset < data_size) { m_start = data_sp->GetBytes() + data_offset; const size_t bytes_left = data_size - data_offset; // Cap the length of we asked for too many if (data_length <= bytes_left) m_end = m_start + data_length; // We got all the bytes we wanted else m_end = m_start + bytes_left; // Not all the bytes requested were // available in the shared data } } } uint32_t new_size = GetByteSize(); // Don't hold a shared pointer to the data buffer if we don't share any valid // bytes in the shared buffer. if (new_size == 0) m_data_sp.reset(); return new_size; }
bool RegisterContextPOSIXProcessMonitor_x86_64::ReadAllRegisterValues(DataBufferSP &data_sp) { bool success = false; data_sp.reset (new DataBufferHeap (REG_CONTEXT_SIZE, 0)); if (data_sp && ReadGPR () && ReadFPR ()) { uint8_t *dst = data_sp->GetBytes(); success = dst != 0; if (success) { ::memcpy (dst, &m_gpr, GetGPRSize()); dst += GetGPRSize(); } if (GetFPRType() == eFXSAVE) ::memcpy (dst, &m_fpr.xstate.fxsave, sizeof(m_fpr.xstate.fxsave)); if (GetFPRType() == eXSAVE) { ByteOrder byte_order = GetByteOrder(); // Assemble the YMM register content from the register halves. for (uint32_t reg = fpu_ymm0; success && reg <= fpu_ymm15; ++reg) success = CopyXSTATEtoYMM(reg, byte_order); if (success) { // Copy the extended register state including the assembled ymm registers. ::memcpy (dst, &m_fpr, sizeof(m_fpr)); } } } return success; }
Error File::Read (size_t &num_bytes, off_t &offset, bool null_terminate, DataBufferSP &data_buffer_sp) { Error error; if (num_bytes > 0) { int fd = GetDescriptor(); if (fd != kInvalidDescriptor) { struct stat file_stats; if (::fstat (fd, &file_stats) == 0) { if (file_stats.st_size > offset) { const size_t bytes_left = file_stats.st_size - offset; if (num_bytes > bytes_left) num_bytes = bytes_left; size_t num_bytes_plus_nul_char = num_bytes + (null_terminate ? 1 : 0); std::unique_ptr<DataBufferHeap> data_heap_ap; data_heap_ap.reset(new DataBufferHeap()); data_heap_ap->SetByteSize(num_bytes_plus_nul_char); if (data_heap_ap.get()) { error = Read (data_heap_ap->GetBytes(), num_bytes, offset); if (error.Success()) { // Make sure we read exactly what we asked for and if we got // less, adjust the array if (num_bytes_plus_nul_char < data_heap_ap->GetByteSize()) data_heap_ap->SetByteSize(num_bytes_plus_nul_char); data_buffer_sp.reset(data_heap_ap.release()); return error; } } } else error.SetErrorString("file is empty"); } else error.SetErrorToErrno(); } else error.SetErrorString("invalid file handle"); } else error.SetErrorString("invalid file handle"); num_bytes = 0; data_buffer_sp.reset(); return error; }
bool RegisterContextPOSIXProcessMonitor_powerpc::ReadAllRegisterValues( DataBufferSP &data_sp) { bool success = false; data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE, 0)); if (data_sp && ReadGPR() && ReadFPR()) { uint8_t *dst = data_sp->GetBytes(); success = dst != 0; if (success) { ::memcpy(dst, &m_gpr_powerpc, GetGPRSize()); dst += GetGPRSize(); } } return success; }
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_unwind_table (*this), m_process_wp (process_sp), m_memory_addr (header_addr), m_sections_ap (), m_symtab_ap (), m_symtab_unified_ap (), m_symtab_unified_revisionid (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, this, module_sp.get(), module_sp->GetSpecificationDescription().c_str(), process_sp.get(), m_memory_addr); } }
bool RegisterContextMemory::WriteAllRegisterValues (const DataBufferSP &data_sp) { if (m_reg_data_addr != LLDB_INVALID_ADDRESS) { ProcessSP process_sp (CalculateProcess()); if (process_sp) { Error error; SetAllRegisterValid (false); if (process_sp->WriteMemory(m_reg_data_addr, data_sp->GetBytes(), data_sp->GetByteSize(), error) == data_sp->GetByteSize()) return true; } } return false; }
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_offset (header_addr), m_length (0), m_data (), m_unwind_table (*this), m_process_wp (process_sp), m_memory_addr (header_addr) { if (header_data_sp) m_data.SetData (header_data_sp, 0, header_data_sp->GetByteSize()); LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); if (log) { log->Printf ("%p ObjectFile::ObjectFile () module = %s/%s, process = %p, header_addr = 0x%llx\n", this, module_sp->GetFileSpec().GetDirectory().AsCString(), module_sp->GetFileSpec().GetFilename().AsCString(), process_sp.get(), m_offset); } }
Error AdbClient::SendSyncRequest (const char *request_id, const uint32_t data_len, const void *data) { const DataBufferSP data_sp (new DataBufferHeap (kSyncPacketLen, 0)); DataEncoder encoder (data_sp, eByteOrderLittle, sizeof (void*)); auto offset = encoder.PutData (0, request_id, strlen(request_id)); encoder.PutU32 (offset, data_len); Error error; ConnectionStatus status; m_conn.Write (data_sp->GetBytes (), kSyncPacketLen, status, &error); if (error.Fail ()) return error; if (data) m_conn.Write (data, data_len, status, &error); return error; }
bool RegisterContextPOSIXProcessMonitor_powerpc::WriteAllRegisterValues( const DataBufferSP &data_sp) { bool success = false; if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE) { uint8_t *src = data_sp->GetBytes(); if (src) { ::memcpy(&m_gpr_powerpc, src, GetGPRSize()); if (WriteGPR()) { src += GetGPRSize(); ::memcpy(&m_fpr_powerpc, src, sizeof(m_fpr_powerpc)); success = WriteFPR(); } } } return success; }
bool RegisterContextPOSIXProcessMonitor_x86_64::WriteAllRegisterValues(const DataBufferSP &data_sp) { bool success = false; if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE) { uint8_t *src = data_sp->GetBytes(); if (src) { ::memcpy (&m_gpr, src, GetGPRSize()); if (WriteGPR()) { src += GetGPRSize(); if (GetFPRType() == eFXSAVE) ::memcpy (&m_fpr.xstate.fxsave, src, sizeof(m_fpr.xstate.fxsave)); if (GetFPRType() == eXSAVE) ::memcpy (&m_fpr.xstate.xsave, src, sizeof(m_fpr.xstate.xsave)); success = WriteFPR(); if (success) { success = true; if (GetFPRType() == eXSAVE) { ByteOrder byte_order = GetByteOrder(); // Parse the YMM register content from the register halves. for (uint32_t reg = fpu_ymm0; success && reg <= fpu_ymm15; ++reg) success = CopyYMMtoXSTATE(reg, byte_order); } } } } } return success; }
static DWARFExpression MakeLocationExpressionInternal(lldb::ModuleSP module, StreamWriter &&writer) { const ArchSpec &architecture = module->GetArchitecture(); ByteOrder byte_order = architecture.GetByteOrder(); uint32_t address_size = architecture.GetAddressByteSize(); uint32_t byte_size = architecture.GetDataByteSize(); if (byte_order == eByteOrderInvalid || address_size == 0) return DWARFExpression(nullptr); RegisterKind register_kind = eRegisterKindDWARF; StreamBuffer<32> stream(Stream::eBinary, address_size, byte_order); if (!writer(stream, register_kind)) return DWARFExpression(nullptr); DataBufferSP buffer = std::make_shared<DataBufferHeap>(stream.GetData(), stream.GetSize()); DataExtractor extractor(buffer, byte_order, address_size, byte_size); DWARFExpression result(module, extractor, nullptr, 0, buffer->GetByteSize()); result.SetRegisterKind(register_kind); return result; }
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) { Timer scoped_timer (__PRETTY_FUNCTION__, "ObjectFile::FindPlugin (module = %s, file = %p, file_offset = 0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")", module_sp->GetFileSpec().GetPath().c_str(), file, (uint64_t) file_offset, (uint64_t) file_size); if (file) { FileSpec archive_file; ObjectContainerCreateInstance create_object_container_callback; const bool file_exists = file->Exists(); 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)) != NULL; ++idx) { std::unique_ptr<ObjectContainer> object_container_ap(create_object_container_callback(module_sp, data_sp, data_offset, file, file_offset, file_size)); if (object_container_ap.get()) object_file_sp = object_container_ap->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 = file->ReadFileContents(file_offset, std::min<size_t>(512, file_size)); 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 = archive_file.GetByteSize(); 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)) != NULL; ++idx) { std::unique_ptr<ObjectContainer> object_container_ap(create_object_container_callback(module_sp, data_sp, data_offset, file, file_offset, file_size)); if (object_container_ap.get()) object_file_sp = object_container_ap->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 = archive_file.ReadFileContents(file_offset, 512); } } } 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)) != NULL; ++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)) != NULL; ++idx) { std::unique_ptr<ObjectContainer> object_container_ap(create_object_container_callback(module_sp, data_sp, data_offset, file, file_offset, file_size)); if (object_container_ap.get()) object_file_sp = object_container_ap->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 FileSpec* file, addr_t file_offset, addr_t file_size, DataBufferSP &file_data_sp) { ObjectFileSP object_file_sp; if (module_sp) { Timer scoped_timer (__PRETTY_FUNCTION__, "ObjectFile::FindPlugin (module = %s/%s, file = %p, file_offset = 0x%8.8llx, file_size = 0x%8.8llx)", module_sp->GetFileSpec().GetDirectory().AsCString(), module_sp->GetFileSpec().GetFilename().AsCString(), file, (uint64_t) file_offset, (uint64_t) file_size); if (file) { // Memory map the entire file contents if (!file_data_sp && file_size > 0) { assert (file_offset == 0); file_data_sp = file->MemoryMapFileContents(file_offset, file_size); } if (!file_data_sp || file_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)); FileSpec archive_file; ConstString archive_object; if (ObjectFile::SplitArchivePathWithObject (path_with_object, archive_file, archive_object)) { file_size = archive_file.GetByteSize(); if (file_size > 0) { module_sp->SetFileSpecAndObjectName (archive_file, archive_object); file_data_sp = archive_file.MemoryMapFileContents(file_offset, file_size); } } } if (file_data_sp && file_data_sp->GetByteSize() > 0) { uint32_t idx; // Check if this is a normal object file by iterating through // all object file plugin instances. ObjectFileCreateInstance create_object_file_callback; for (idx = 0; (create_object_file_callback = PluginManager::GetObjectFileCreateCallbackAtIndex(idx)) != NULL; ++idx) { object_file_sp.reset (create_object_file_callback(module_sp, file_data_sp, 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. ObjectContainerCreateInstance create_object_container_callback; for (idx = 0; (create_object_container_callback = PluginManager::GetObjectContainerCreateCallbackAtIndex(idx)) != NULL; ++idx) { std::auto_ptr<ObjectContainer> object_container_ap(create_object_container_callback(module_sp, file_data_sp, file, file_offset, file_size)); if (object_container_ap.get()) object_file_sp = object_container_ap->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; }