ProcessMonitor & RegisterContext_i386::GetMonitor() { ProcessSP base = CalculateProcess(); ProcessPOSIX *process = static_cast<ProcessPOSIX*>(base.get()); return process->GetMonitor(); }
ProcessMonitor & RegisterContextPOSIXProcessMonitor_powerpc::GetMonitor() { ProcessSP base = CalculateProcess(); ProcessFreeBSD *process = static_cast<ProcessFreeBSD*>(base.get()); return process->GetMonitor(); }
addr_t Address::GetCallableLoadAddress (Target *target, bool is_indirect) const { addr_t code_addr = LLDB_INVALID_ADDRESS; if (is_indirect && target) { ProcessSP processSP = target->GetProcessSP(); Error error; if (processSP.get()) { code_addr = processSP->ResolveIndirectFunction(this, error); if (!error.Success()) code_addr = LLDB_INVALID_ADDRESS; } } else { code_addr = GetLoadAddress (target); } if (code_addr == LLDB_INVALID_ADDRESS) return code_addr; if (target) return target->GetCallableLoadAddress (code_addr, GetAddressClass()); return code_addr; }
MemoryHistorySP MemoryHistoryASan::CreateInstance (const ProcessSP &process_sp) { if (!process_sp.get()) return NULL; Target & target = process_sp->GetTarget(); const ModuleList &target_modules = target.GetImages(); Mutex::Locker modules_locker(target_modules.GetMutex()); const size_t num_modules = target_modules.GetSize(); for (size_t i = 0; i < num_modules; ++i) { Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i); const Symbol* symbol = module_pointer->FindFirstSymbolWithNameAndType( ConstString("__asan_get_alloc_stack"), lldb::eSymbolTypeAny); if (symbol != nullptr) return MemoryHistorySP(new MemoryHistoryASan(process_sp)); } return MemoryHistorySP(); }
RegisterContextPOSIX_ppc64le::RegisterContextPOSIX_ppc64le( Thread &thread, uint32_t concrete_frame_idx, RegisterInfoInterface *register_info) : RegisterContext(thread, concrete_frame_idx) { m_register_info_ap.reset(register_info); ProcessSP base = CalculateProcess(); if (base.get()->GetPluginName() == ProcessElfCore::GetPluginNameStatic()) return; }
addr_t Address::GetCallableLoadAddress (Target *target, bool is_indirect) const { if (is_indirect && target) { ProcessSP processSP = target->GetProcessSP(); Error error; if (processSP.get()) return processSP->ResolveIndirectFunction(this, error); } addr_t code_addr = GetLoadAddress (target); if (target) return target->GetCallableLoadAddress (code_addr, GetAddressClass()); return code_addr; }
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); } }
Thread::Thread (const ProcessSP &process_sp, lldb::tid_t tid) : ThreadProperties (false), UserID (tid), m_process_wp (process_sp), m_actual_stop_info_sp (), m_index_id (process_sp->GetNextThreadIndexID ()), m_reg_context_sp (), m_state (eStateUnloaded), m_state_mutex (Mutex::eMutexTypeRecursive), m_plan_stack (), m_completed_plan_stack(), m_frame_mutex (Mutex::eMutexTypeRecursive), m_curr_frames_sp (), m_prev_frames_sp (), m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER), m_resume_state (eStateRunning), m_temporary_resume_state (eStateRunning), m_unwinder_ap (), m_destroy_called (false), m_thread_stop_reason_stop_id (0) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); if (log) log->Printf ("%p Thread::Thread(tid = 0x%4.4llx)", this, GetID()); QueueFundamentalPlan(true); }
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); } }
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) { Timer scoped_timer (__PRETTY_FUNCTION__, "ObjectFile::FindPlugin (module = %s, process = %p, header_addr = 0x%" PRIx64 ")", module_sp->GetFileSpec().GetPath().c_str(), 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)) != NULL; ++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; }
SBTarget SBDebugger::FindTargetWithLLDBProcess (const ProcessSP &process_sp) { SBTarget sb_target; if (m_opaque_sp) { // No need to lock, the target list is thread safe sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get())); } return sb_target; }
ThreadGDBRemote::ThreadGDBRemote (const ProcessSP &process_sp, lldb::tid_t tid) : Thread(process_sp, tid), m_thread_name (), m_dispatch_queue_name (), m_thread_dispatch_qaddr (LLDB_INVALID_ADDRESS) { ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD, "%p: ThreadGDBRemote::ThreadGDBRemote (pid = %i, tid = 0x%4.4x)", this, process_sp ? process_sp->GetID() : LLDB_INVALID_PROCESS_ID, GetID()); }
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_ap(new DataBufferHeap(byte_size, 0)); Error error; const size_t bytes_read = process_sp->ReadMemory( addr, data_ap->GetBytes(), data_ap->GetByteSize(), error); if (bytes_read == byte_size) data_sp.reset(data_ap.release()); } return data_sp; }
Status ObjectFile::LoadInMemory(Target &target, bool set_pc) { Status error; ProcessSP process = target.CalculateProcess(); if (!process) return Status("No Process"); if (set_pc && !GetEntryPointAddress().IsValid()) return Status("No entry address in object file"); SectionList *section_list = GetSectionList(); if (!section_list) return Status("No section in object file"); size_t section_count = section_list->GetNumSections(0); for (size_t i = 0; i < section_count; ++i) { SectionSP section_sp = section_list->GetSectionAtIndex(i); addr_t addr = target.GetSectionLoadList().GetSectionLoadAddress(section_sp); if (addr != LLDB_INVALID_ADDRESS) { DataExtractor section_data; // We can skip sections like bss if (section_sp->GetFileSize() == 0) continue; section_sp->GetSectionData(section_data); lldb::offset_t written = process->WriteMemory( addr, section_data.GetDataStart(), section_data.GetByteSize(), error); if (written != section_data.GetByteSize()) return error; } } if (set_pc) { ThreadList &thread_list = process->GetThreadList(); ThreadSP curr_thread(thread_list.GetSelectedThread()); RegisterContextSP reg_context(curr_thread->GetRegisterContext()); Address file_entry = GetEntryPointAddress(); reg_context->SetPC(file_entry.GetLoadAddress(&target)); } return error; }
MemoryHistorySP MemoryHistoryASan::CreateInstance (const ProcessSP &process_sp) { if (!process_sp.get()) return NULL; Target & target = process_sp->GetTarget(); bool found_asan_runtime = false; const ModuleList &target_modules = target.GetImages(); Mutex::Locker modules_locker(target_modules.GetMutex()); const size_t num_modules = target_modules.GetSize(); for (size_t i = 0; i < num_modules; ++i) { Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i); SymbolContextList sc_list; const bool include_symbols = true; const bool append = true; const bool include_inlines = true; size_t num_matches = module_pointer->FindFunctions(ConstString("__asan_get_alloc_stack"), NULL, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); if (num_matches) { found_asan_runtime = true; break; } } if (! found_asan_runtime) return MemoryHistorySP(); return MemoryHistorySP(new MemoryHistoryASan(process_sp)); }
RegisterContextPOSIX_x86::RegisterContextPOSIX_x86( Thread &thread, uint32_t concrete_frame_idx, RegisterInfoInterface *register_info) : RegisterContext(thread, concrete_frame_idx) { m_register_info_ap.reset(register_info); switch (register_info->m_target_arch.GetMachine()) { case llvm::Triple::x86: m_reg_info.num_registers = k_num_registers_i386; m_reg_info.num_gpr_registers = k_num_gpr_registers_i386; m_reg_info.num_fpr_registers = k_num_fpr_registers_i386; m_reg_info.num_avx_registers = k_num_avx_registers_i386; m_reg_info.last_gpr = k_last_gpr_i386; m_reg_info.first_fpr = k_first_fpr_i386; m_reg_info.last_fpr = k_last_fpr_i386; m_reg_info.first_st = lldb_st0_i386; m_reg_info.last_st = lldb_st7_i386; m_reg_info.first_mm = lldb_mm0_i386; m_reg_info.last_mm = lldb_mm7_i386; m_reg_info.first_xmm = lldb_xmm0_i386; m_reg_info.last_xmm = lldb_xmm7_i386; m_reg_info.first_ymm = lldb_ymm0_i386; m_reg_info.last_ymm = lldb_ymm7_i386; m_reg_info.first_dr = lldb_dr0_i386; m_reg_info.gpr_flags = lldb_eflags_i386; break; case llvm::Triple::x86_64: m_reg_info.num_registers = k_num_registers_x86_64; m_reg_info.num_gpr_registers = k_num_gpr_registers_x86_64; m_reg_info.num_fpr_registers = k_num_fpr_registers_x86_64; m_reg_info.num_avx_registers = k_num_avx_registers_x86_64; m_reg_info.last_gpr = k_last_gpr_x86_64; m_reg_info.first_fpr = k_first_fpr_x86_64; m_reg_info.last_fpr = k_last_fpr_x86_64; m_reg_info.first_st = lldb_st0_x86_64; m_reg_info.last_st = lldb_st7_x86_64; m_reg_info.first_mm = lldb_mm0_x86_64; m_reg_info.last_mm = lldb_mm7_x86_64; m_reg_info.first_xmm = lldb_xmm0_x86_64; m_reg_info.last_xmm = lldb_xmm15_x86_64; m_reg_info.first_ymm = lldb_ymm0_x86_64; m_reg_info.last_ymm = lldb_ymm15_x86_64; m_reg_info.first_dr = lldb_dr0_x86_64; m_reg_info.gpr_flags = lldb_rflags_x86_64; break; default: assert(false && "Unhandled target architecture."); break; } // Initialize m_iovec to point to the buffer and buffer size // using the conventions of Berkeley style UIO structures, as required // by PTRACE extensions. m_iovec.iov_base = &m_fpr.xstate.xsave; m_iovec.iov_len = sizeof(m_fpr.xstate.xsave); ::memset(&m_fpr, 0, sizeof(FPR)); // elf-core yet to support ReadFPR() ProcessSP base = CalculateProcess(); if (base.get()->GetPluginName() == ProcessElfCore::GetPluginNameStatic()) return; m_fpr_type = eNotValid; }
void CompactUnwindInfo::ScanIndex (const ProcessSP &process_sp) { std::lock_guard<std::mutex> guard(m_mutex); if (m_indexes_computed == eLazyBoolYes && m_unwindinfo_data_computed) return; // We can't read the index for some reason. if (m_indexes_computed == eLazyBoolNo) { return; } Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_UNWIND)); if (log) m_objfile.GetModule()->LogMessage(log, "Reading compact unwind first-level indexes"); if (m_unwindinfo_data_computed == false) { if (m_section_sp->IsEncrypted()) { // Can't get section contents of a protected/encrypted section until we have a live // process and can read them out of memory. if (process_sp.get() == nullptr) return; m_section_contents_if_encrypted.reset (new DataBufferHeap (m_section_sp->GetByteSize(), 0)); Error error; if (process_sp->ReadMemory ( m_section_sp->GetLoadBaseAddress (&process_sp->GetTarget()), m_section_contents_if_encrypted->GetBytes(), m_section_sp->GetByteSize(), error) == m_section_sp->GetByteSize() && error.Success()) { m_unwindinfo_data.SetAddressByteSize (process_sp->GetTarget().GetArchitecture().GetAddressByteSize()); m_unwindinfo_data.SetByteOrder (process_sp->GetTarget().GetArchitecture().GetByteOrder()); m_unwindinfo_data.SetData (m_section_contents_if_encrypted, 0); } } else { m_objfile.ReadSectionData (m_section_sp.get(), m_unwindinfo_data); } if (m_unwindinfo_data.GetByteSize() != m_section_sp->GetByteSize()) return; m_unwindinfo_data_computed = true; } if (m_unwindinfo_data.GetByteSize() > 0) { offset_t offset = 0; // struct unwind_info_section_header // { // uint32_t version; // UNWIND_SECTION_VERSION // uint32_t commonEncodingsArraySectionOffset; // uint32_t commonEncodingsArrayCount; // uint32_t personalityArraySectionOffset; // uint32_t personalityArrayCount; // uint32_t indexSectionOffset; // uint32_t indexCount; m_unwind_header.version = m_unwindinfo_data.GetU32(&offset); m_unwind_header.common_encodings_array_offset = m_unwindinfo_data.GetU32(&offset); m_unwind_header.common_encodings_array_count = m_unwindinfo_data.GetU32(&offset); m_unwind_header.personality_array_offset = m_unwindinfo_data.GetU32(&offset); m_unwind_header.personality_array_count = m_unwindinfo_data.GetU32(&offset); uint32_t indexSectionOffset = m_unwindinfo_data.GetU32(&offset); uint32_t indexCount = m_unwindinfo_data.GetU32(&offset); if (m_unwind_header.common_encodings_array_offset > m_unwindinfo_data.GetByteSize() || m_unwind_header.personality_array_offset > m_unwindinfo_data.GetByteSize() || indexSectionOffset > m_unwindinfo_data.GetByteSize() || offset > m_unwindinfo_data.GetByteSize()) { Host::SystemLog (Host::eSystemLogError, "error: Invalid offset encountered in compact unwind info, skipping\n"); // don't trust anything from this compact_unwind section if it looks // blatantly invalid data in the header. m_indexes_computed = eLazyBoolNo; return; } // Parse the basic information from the indexes // We wait to scan the second level page info until it's needed // struct unwind_info_section_header_index_entry // { // uint32_t functionOffset; // uint32_t secondLevelPagesSectionOffset; // uint32_t lsdaIndexArraySectionOffset; // }; offset = indexSectionOffset; for (uint32_t idx = 0; idx < indexCount; idx++) { uint32_t function_offset = m_unwindinfo_data.GetU32(&offset); // functionOffset uint32_t second_level_offset = m_unwindinfo_data.GetU32(&offset); // secondLevelPagesSectionOffset uint32_t lsda_offset = m_unwindinfo_data.GetU32(&offset); // lsdaIndexArraySectionOffset if (second_level_offset > m_section_sp->GetByteSize() || lsda_offset > m_section_sp->GetByteSize()) { m_indexes_computed = eLazyBoolNo; } UnwindIndex this_index; this_index.function_offset = function_offset; // this_index.second_level = second_level_offset; this_index.lsda_array_start = lsda_offset; if (m_indexes.size() > 0) { m_indexes[m_indexes.size() - 1].lsda_array_end = lsda_offset; } if (second_level_offset == 0) { this_index.sentinal_entry = true; } m_indexes.push_back (this_index); } m_indexes_computed = eLazyBoolYes; } else { m_indexes_computed = eLazyBoolNo; } }