LLDB mainline
ProcessTrace.cpp
Go to the documentation of this file.
1//===-- ProcessTrace.cpp --------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11#include <memory>
12
13#include "lldb/Core/Module.h"
15#include "lldb/Core/Section.h"
16#include "lldb/Target/ABI.h"
18#include "lldb/Target/Target.h"
19
20using namespace lldb;
21using namespace lldb_private;
22
24
25llvm::StringRef ProcessTrace::GetPluginDescriptionStatic() {
26 return "Trace process plug-in.";
27}
28
31}
32
34 ListenerSP listener_sp,
35 const FileSpec *crash_file,
36 bool can_connect) {
37 if (can_connect)
38 return nullptr;
39 return std::make_shared<ProcessTrace>(target_sp, listener_sp, *crash_file);
40}
41
42bool ProcessTrace::CanDebug(TargetSP target_sp, bool plugin_specified_by_name) {
43 return plugin_specified_by_name;
44}
45
47 const FileSpec &core_file)
48 : PostMortemProcess(target_sp, listener_sp, core_file) {}
49
51 Clear();
52 // We need to call finalize on the process before destroying ourselves to
53 // make sure all of the broadcaster cleanup goes as planned. If we destruct
54 // this class, then Process::~Process() might have problems trying to fully
55 // destroy the broadcaster.
56 Finalize(true /* destructing */);
57}
58
59void ProcessTrace::DidAttach(ArchSpec &process_arch) {
60 ListenerSP listener_sp(
61 Listener::MakeListener("lldb.process_trace.did_attach_listener"));
62 HijackProcessEvents(listener_sp);
63
64 SetCanJIT(false);
67
68 EventSP event_sp;
69 WaitForProcessToStop(std::nullopt, &event_sp, true, listener_sp);
70
72
73 Process::DidAttach(process_arch);
74}
75
77 ThreadList &new_thread_list) {
78 return false;
79}
80
82
84
85size_t ProcessTrace::ReadMemory(addr_t addr, void *buf, size_t size,
86 Status &error) {
87 if (const ABISP &abi = GetABI())
88 addr = abi->FixAnyAddress(addr);
89
90 // Don't allow the caching that lldb_private::Process::ReadMemory does since
91 // we have it all cached in the trace files.
92 return DoReadMemory(addr, buf, size, error);
93}
94
96
98 static llvm::once_flag g_once_flag;
99
100 llvm::call_once(g_once_flag, []() {
103 });
104}
105
107 return GetTarget().GetArchitecture();
108}
109
111 info.Clear();
112 info.SetProcessID(GetID());
114 ModuleSP module_sp = GetTarget().GetExecutableModule();
115 if (module_sp) {
116 const bool add_exe_file_as_first_arg = false;
117 info.SetExecutableFile(GetTarget().GetExecutableModule()->GetFileSpec(),
118 add_exe_file_as_first_arg);
119 }
120 return true;
121}
122
123size_t ProcessTrace::DoReadMemory(addr_t addr, void *buf, size_t size,
124 Status &error) {
125 Address resolved_address;
126 GetTarget().GetSectionLoadList().ResolveLoadAddress(addr, resolved_address);
127
128 return GetTarget().ReadMemoryFromFileCache(resolved_address, buf, size,
129 error);
130}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:32
A section + offset based address class.
Definition: Address.h:62
An architecture specification class.
Definition: ArchSpec.h:31
A file utility class.
Definition: FileSpec.h:56
static lldb::ListenerSP MakeListener(const char *name)
Definition: Listener.cpp:376
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
Base class for all processes that don't represent a live process, such as coredumps or processes trac...
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
Definition: ProcessInfo.cpp:65
void SetArchitecture(const ArchSpec &arch)
Definition: ProcessInfo.h:66
void SetProcessID(lldb::pid_t pid)
Definition: ProcessInfo.h:70
Class that represents a defunct process loaded on memory via the "trace load" command.
Definition: ProcessTrace.h:20
static llvm::StringRef GetPluginNameStatic()
Definition: ProcessTrace.h:26
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
bool GetProcessInfo(ProcessInstanceInfo &info) override
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, Status &error) override
Actually do the reading of memory from a process.
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
static llvm::StringRef GetPluginDescriptionStatic()
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const FileSpec *crash_file_path, bool can_connect)
bool DoUpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list) override
Update the thread list following process plug-in's specific logic.
Status DoDestroy() override
size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size, Status &error) override
Read of memory from a process.
void DidAttach(ArchSpec &process_arch) override
Called after attaching a process.
ProcessTrace(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const FileSpec &core_file)
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
Definition: Process.h:540
void SetCanJIT(bool can_jit)
Sets whether executing JIT-compiled code in this process is possible.
Definition: Process.cpp:2499
bool StartPrivateStateThread(bool is_secondary_thread=false)
Definition: Process.cpp:3758
lldb::StateType WaitForProcessToStop(const Timeout< std::micro > &timeout, lldb::EventSP *event_sp_ptr=nullptr, bool wait_always=true, lldb::ListenerSP hijack_listener=lldb::ListenerSP(), Stream *stream=nullptr, bool use_run_lock=true, SelectMostRelevant select_most_relevant=DoNoSelectMostRelevantFrame)
Definition: Process.cpp:684
virtual void DidAttach(ArchSpec &process_arch)
Called after attaching a process.
Definition: Process.h:1050
void RestoreProcessEvents()
Restores the process event broadcasting to its normal state.
Definition: Process.cpp:994
void SetPrivateState(lldb::StateType state)
Definition: Process.cpp:1454
virtual void Finalize(bool destructing)
This object is about to be destroyed, do any necessary cleanup.
Definition: Process.cpp:555
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition: Process.h:3113
bool HijackProcessEvents(lldb::ListenerSP listener_sp)
If you need to ensure that you and only you will hear about some public event, then make a new listen...
Definition: Process.cpp:986
const lldb::ABISP & GetABI()
Definition: Process.cpp:1531
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1285
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, bool allow_section_end=false) const
An error handling class.
Definition: Status.h:44
SectionLoadList & GetSectionLoadList()
Definition: Target.h:1143
size_t ReadMemoryFromFileCache(const Address &addr, void *dst, size_t dst_len, Status &error)
Definition: Target.cpp:1797
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition: Target.cpp:1423
const ArchSpec & GetArchitecture() const
Definition: Target.h:1028
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ABI > ABISP
Definition: lldb-forward.h:315
@ eStateStopped
Process or thread is stopped and can be examined.
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
std::shared_ptr< lldb_private::Event > EventSP
Definition: lldb-forward.h:343
std::shared_ptr< lldb_private::Listener > ListenerSP
Definition: lldb-forward.h:366
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:444
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:371
Definition: Debugger.h:54