17#if LLDB_ENABLE_FBSDVMCORE
20#if defined(__FreeBSD__)
31#if LLDB_ENABLE_FBSDVMCORE
37 ~ProcessFreeBSDKernelFVC();
45 const char *GetError();
49#if defined(__FreeBSD__)
55 ~ProcessFreeBSDKernelKVM();
63 const char *GetError();
77 ModuleSP executable = target_sp->GetExecutableModule();
78 if (crash_file && !can_connect && executable) {
79#if LLDB_ENABLE_FBSDVMCORE
81 fvc_open(executable->GetFileSpec().GetPath().c_str(),
82 crash_file->
GetPath().c_str(),
nullptr,
nullptr,
nullptr);
84 return std::make_shared<ProcessFreeBSDKernelFVC>(target_sp, listener_sp,
88#if defined(__FreeBSD__)
90 kvm_open2(executable->GetFileSpec().GetPath().c_str(),
91 crash_file->
GetPath().c_str(), O_RDONLY,
nullptr,
nullptr);
93 return std::make_shared<ProcessFreeBSDKernelKVM>(target_sp, listener_sp,
101 static llvm::once_flag g_once_flag;
103 llvm::call_once(g_once_flag, []() {
116 bool plugin_specified_by_name) {
124 if (old_thread_list.
GetSize(
false) == 0) {
131 switch (
GetTarget().GetArchitecture().GetMachine()) {
132 case llvm::Triple::aarch64:
133 case llvm::Triple::x86:
134 case llvm::Triple::x86_64:
146 int32_t offset_p_pid =
165 if (offset_p_list == -1 || offset_p_pid == -1 || offset_p_threads == -1 ||
166 offset_p_comm == -1 || offset_td_tid == -1 || offset_td_plist == -1 ||
167 offset_td_pcb == -1 || offset_td_oncpu == -1 || offset_td_name == -1)
183 constexpr size_t fbsd_maxcomlen = 19;
195 char comm[fbsd_maxcomlen + 1];
212 char thread_name[fbsd_maxcomlen + 1];
214 sizeof(thread_name),
error);
220 std::string thread_desc = llvm::formatv(
"(pid {0}) {1}", pid, comm);
221 if (*thread_name && strcmp(thread_name, comm)) {
223 thread_desc += thread_name;
230 if (tid == dumptid) {
233 thread_desc +=
" (crashed)";
234 }
else if (oncpu != -1) {
238 pcb_addr = stoppcbs + oncpu * pcbsize;
241 thread_desc += llvm::formatv(
" (on CPU {0})", oncpu);
250 const uint32_t num_threads = old_thread_list.
GetSize(
false);
251 for (uint32_t i = 0; i < num_threads; ++i)
254 return new_thread_list.
GetSize(
false) > 0;
275#if LLDB_ENABLE_FBSDVMCORE
277ProcessFreeBSDKernelFVC::ProcessFreeBSDKernelFVC(
lldb::TargetSP target_sp,
282ProcessFreeBSDKernelFVC::~ProcessFreeBSDKernelFVC() {
287size_t ProcessFreeBSDKernelFVC::DoReadMemory(
lldb::addr_t addr,
void *buf,
290 rd = fvc_read(m_fvc, addr, buf, size);
291 if (rd < 0 ||
static_cast<size_t>(rd) != size) {
292 error.SetErrorStringWithFormat(
"Reading memory failed: %s", GetError());
293 return rd > 0 ? rd : 0;
298const char *ProcessFreeBSDKernelFVC::GetError() {
return fvc_geterr(m_fvc); }
302#if defined(__FreeBSD__)
304ProcessFreeBSDKernelKVM::ProcessFreeBSDKernelKVM(
lldb::TargetSP target_sp,
309ProcessFreeBSDKernelKVM::~ProcessFreeBSDKernelKVM() {
314size_t ProcessFreeBSDKernelKVM::DoReadMemory(
lldb::addr_t addr,
void *buf,
317 rd = kvm_read2(m_kvm, addr, buf, size);
318 if (rd < 0 ||
static_cast<size_t>(rd) != size) {
319 error.SetErrorStringWithFormat(
"Reading memory failed: %s", GetError());
320 return rd > 0 ? rd : 0;
325const char *ProcessFreeBSDKernelKVM::GetError() {
return kvm_geterr(m_kvm); }
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_PLUGIN_DEFINE(PluginName)
static llvm::StringRef GetPluginNameStatic()
lldb_private::Status DoLoadCore() override
bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list) override
Update the thread list following process plug-in's specific logic.
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
ProcessFreeBSDKernel(lldb::TargetSP target_sp, lldb::ListenerSP listener)
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
lldb::addr_t FindSymbol(const char *name)
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
static llvm::StringRef GetPluginNameStatic()
lldb_private::Status DoDestroy() override
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener, const lldb_private::FileSpec *crash_file_path, bool can_connect)
static llvm::StringRef GetPluginDescriptionStatic()
A uniqued constant string class.
A plug-in interface definition class for dynamic loaders.
static DynamicLoader * FindPlugin(Process *process, llvm::StringRef plugin_name)
Find a dynamic loader plugin for a given process.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
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...
int64_t ReadSignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, int64_t fail_value, Status &error)
size_t ReadCStringFromMemory(lldb::addr_t vm_addr, char *cstr, size_t cstr_max_len, Status &error)
Read a NULL terminated C string from memory.
lldb::DynamicLoaderUP m_dyld_up
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)=0
Actually do the reading of memory from a process.
Target & GetTarget()
Get the target object pointer for this module.
lldb::addr_t GetLoadAddress(Target *target) const
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
void AddThread(const lldb::ThreadSP &thread_sp)
uint32_t GetSize(bool can_update=true)
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Listener > ListenerSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP