17#if LLDB_ENABLE_FBSDVMCORE
20#if defined(__FreeBSD__)
31#if LLDB_ENABLE_FBSDVMCORE
35 fvc_t *fvc,
const FileSpec &core_file);
37 ~ProcessFreeBSDKernelFVC();
45 const char *GetError();
49#if defined(__FreeBSD__)
53 kvm_t *fvc,
const FileSpec &core_file);
55 ~ProcessFreeBSDKernelKVM();
63 const char *GetError();
78 ModuleSP executable = target_sp->GetExecutableModule();
79 if (crash_file && !can_connect && executable) {
80#if LLDB_ENABLE_FBSDVMCORE
82 fvc_open(executable->GetFileSpec().GetPath().c_str(),
83 crash_file->
GetPath().c_str(),
nullptr,
nullptr,
nullptr);
85 return std::make_shared<ProcessFreeBSDKernelFVC>(target_sp, listener_sp,
89#if defined(__FreeBSD__)
91 kvm_open2(executable->GetFileSpec().GetPath().c_str(),
92 crash_file->
GetPath().c_str(), O_RDONLY,
nullptr,
nullptr);
94 return std::make_shared<ProcessFreeBSDKernelKVM>(target_sp, listener_sp,
102 static llvm::once_flag g_once_flag;
104 llvm::call_once(g_once_flag, []() {
117 bool plugin_specified_by_name) {
125 if (old_thread_list.
GetSize(
false) == 0) {
132 switch (
GetTarget().GetArchitecture().GetMachine()) {
133 case llvm::Triple::aarch64:
134 case llvm::Triple::x86:
135 case llvm::Triple::x86_64:
147 int32_t offset_p_pid =
166 if (offset_p_list == -1 || offset_p_pid == -1 || offset_p_threads == -1 ||
167 offset_p_comm == -1 || offset_td_tid == -1 || offset_td_plist == -1 ||
168 offset_td_pcb == -1 || offset_td_oncpu == -1 || offset_td_name == -1)
184 constexpr size_t fbsd_maxcomlen = 19;
196 char comm[fbsd_maxcomlen + 1];
213 char thread_name[fbsd_maxcomlen + 1];
215 sizeof(thread_name),
error);
221 std::string thread_desc = llvm::formatv(
"(pid {0}) {1}", pid, comm);
222 if (*thread_name && strcmp(thread_name, comm)) {
224 thread_desc += thread_name;
231 if (tid == dumptid) {
234 thread_desc +=
" (crashed)";
235 }
else if (oncpu != -1) {
239 pcb_addr = stoppcbs + oncpu * pcbsize;
242 thread_desc += llvm::formatv(
" (on CPU {0})", oncpu);
251 const uint32_t num_threads = old_thread_list.
GetSize(
false);
252 for (uint32_t i = 0; i < num_threads; ++i)
255 return new_thread_list.
GetSize(
false) > 0;
276#if LLDB_ENABLE_FBSDVMCORE
278ProcessFreeBSDKernelFVC::ProcessFreeBSDKernelFVC(
lldb::TargetSP target_sp,
284ProcessFreeBSDKernelFVC::~ProcessFreeBSDKernelFVC() {
289size_t ProcessFreeBSDKernelFVC::DoReadMemory(
lldb::addr_t addr,
void *buf,
292 rd = fvc_read(m_fvc, addr, buf, size);
293 if (rd < 0 ||
static_cast<size_t>(rd) != size) {
296 return rd > 0 ? rd : 0;
301const char *ProcessFreeBSDKernelFVC::GetError() {
return fvc_geterr(m_fvc); }
305#if defined(__FreeBSD__)
307ProcessFreeBSDKernelKVM::ProcessFreeBSDKernelKVM(
lldb::TargetSP target_sp,
313ProcessFreeBSDKernelKVM::~ProcessFreeBSDKernelKVM() {
318size_t ProcessFreeBSDKernelKVM::DoReadMemory(
lldb::addr_t addr,
void *buf,
321 rd = kvm_read2(m_kvm, addr, buf, size);
322 if (rd < 0 ||
static_cast<size_t>(rd) != size) {
325 return rd > 0 ? rd : 0;
330const 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.
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.
ProcessFreeBSDKernel(lldb::TargetSP target_sp, lldb::ListenerSP listener, const lldb_private::FileSpec &core_file)
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.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
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