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 return "Trace process plug-in.";
25}
26
29}
30
31ProcessSP ProcessTrace::CreateInstance(TargetSP target_sp,
32 ListenerSP listener_sp,
33 const FileSpec *crash_file,
34 bool can_connect) {
35 if (can_connect)
36 return nullptr;
37 return std::make_shared<ProcessTrace>(target_sp, listener_sp);
38}
39
40bool ProcessTrace::CanDebug(TargetSP target_sp, bool plugin_specified_by_name) {
41 return plugin_specified_by_name;
42}
43
44ProcessTrace::ProcessTrace(TargetSP target_sp, ListenerSP listener_sp)
45 : PostMortemProcess(target_sp, listener_sp) {}
46
48 Clear();
49 // We need to call finalize on the process before destroying ourselves to
50 // make sure all of the broadcaster cleanup goes as planned. If we destruct
51 // this class, then Process::~Process() might have problems trying to fully
52 // destroy the broadcaster.
53 Finalize();
54}
55
56void ProcessTrace::DidAttach(ArchSpec &process_arch) {
57 ListenerSP listener_sp(
58 Listener::MakeListener("lldb.process_trace.did_attach_listener"));
59 HijackProcessEvents(listener_sp);
60
61 SetCanJIT(false);
64
65 EventSP event_sp;
66 WaitForProcessToStop(std::nullopt, &event_sp, true, listener_sp);
67
69
70 Process::DidAttach(process_arch);
71}
72
74 ThreadList &new_thread_list) {
75 return false;
76}
77
79
81
82size_t ProcessTrace::ReadMemory(addr_t addr, void *buf, size_t size,
83 Status &error) {
84 if (const ABISP &abi = GetABI())
85 addr = abi->FixAnyAddress(addr);
86
87 // Don't allow the caching that lldb_private::Process::ReadMemory does since
88 // we have it all cached in the trace files.
89 return DoReadMemory(addr, buf, size, error);
90}
91
93
95 static llvm::once_flag g_once_flag;
96
97 llvm::call_once(g_once_flag, []() {
100 });
101}
102
104 return GetTarget().GetArchitecture();
105}
106
108 info.Clear();
109 info.SetProcessID(GetID());
111 ModuleSP module_sp = GetTarget().GetExecutableModule();
112 if (module_sp) {
113 const bool add_exe_file_as_first_arg = false;
114 info.SetExecutableFile(GetTarget().GetExecutableModule()->GetFileSpec(),
115 add_exe_file_as_first_arg);
116 }
117 return true;
118}
119
120size_t ProcessTrace::DoReadMemory(addr_t addr, void *buf, size_t size,
121 Status &error) {
122 Address resolved_address;
123 GetTarget().GetSectionLoadList().ResolveLoadAddress(addr, resolved_address);
124
125 return GetTarget().ReadMemoryFromFileCache(resolved_address, buf, size,
126 error);
127}
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition: Address.h:59
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:461
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:65
void SetProcessID(lldb::pid_t pid)
Definition: ProcessInfo.h:69
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
ProcessTrace(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp)
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.
virtual void Finalize()
This object is about to be destroyed, do any necessary cleanup.
Definition: Process.cpp:525
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:530
void SetCanJIT(bool can_jit)
Sets whether executing JIT-compiled code in this process is possible.
Definition: Process.cpp:2344
bool StartPrivateStateThread(bool is_secondary_thread=false)
Definition: Process.cpp:3562
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:660
virtual void DidAttach(ArchSpec &process_arch)
Called after attaching a process.
Definition: Process.h:989
void RestoreProcessEvents()
Restores the process event broadcasting to its normal state.
Definition: Process.cpp:969
void SetPrivateState(lldb::StateType state)
Definition: Process.cpp:1431
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition: Process.h:2946
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:961
const lldb::ABISP & GetABI()
Definition: Process.cpp:1502
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1224
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:1109
size_t ReadMemoryFromFileCache(const Address &addr, void *dst, size_t dst_len, Status &error)
Definition: Target.cpp:1750
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition: Target.cpp:1373
const ArchSpec & GetArchitecture() const
Definition: Target.h:996
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
@ eStateStopped
Process or thread is stopped and can be examined.
uint64_t addr_t
Definition: lldb-types.h:79