29#define LLDB_PROPERTIES_processfreebsdkernelcore
30#include "ProcessFreeBSDKernelCoreProperties.inc"
33#define LLDB_PROPERTIES_processfreebsdkernelcore
34#include "ProcessFreeBSDKernelCorePropertiesEnum.inc"
39 static llvm::StringRef GetSettingName() {
43 PluginProperties() : Properties() {
44 m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
45 m_collection_sp->Initialize(g_processfreebsdkernelcore_properties_def);
48 ~PluginProperties()
override =
default;
50 bool GetReadOnly()
const {
51 const uint32_t idx = ePropertyReadOnly;
52 return GetPropertyAtIndexAs<bool>(idx,
true);
59 static PluginProperties g_settings;
76 const FileSpec *crash_file,
bool can_connect) {
77 ModuleSP executable = target_sp->GetExecutableModule();
78 if (crash_file && !can_connect && executable) {
80 kvm_open2(executable->GetFileSpec().GetPath().c_str(),
81 crash_file->
GetPath().c_str(), O_RDONLY,
nullptr,
nullptr);
83 return std::make_shared<ProcessFreeBSDKernelCore>(target_sp, listener_sp,
97 debugger, PluginProperties::GetSettingName())) {
98 const bool is_global_setting =
true;
101 "Properties for the freebsd-kernel process plug-in.",
111 bool plugin_specified_by_name) {
139 const void *buf,
size_t size,
143 "Memory writes are currently disabled. You can enable them with "
144 "`settings set plugin.process.freebsd-kernel-core.read-only false`.");
149 rd = kvm_write(
m_kvm, addr, buf, size);
150 if (rd < 0 ||
static_cast<size_t>(rd) != size) {
153 return rd > 0 ? rd : 0;
160 if (old_thread_list.
GetSize(
false) == 0) {
167 switch (
GetTarget().GetArchitecture().GetMachine()) {
168 case llvm::Triple::arm:
169 case llvm::Triple::aarch64:
170 case llvm::Triple::ppc64le:
171 case llvm::Triple::riscv64:
172 case llvm::Triple::x86:
173 case llvm::Triple::x86_64:
185 int32_t offset_p_pid =
204 if (offset_p_list == -1 || offset_p_pid == -1 || offset_p_threads == -1 ||
205 offset_p_comm == -1 || offset_td_tid == -1 || offset_td_plist == -1 ||
206 offset_td_pcb == -1 || offset_td_oncpu == -1 || offset_td_name == -1)
223 uint32_t mp_maxid = 0;
234 uint32_t long_bit = long_size_bytes * 8;
236 if (
auto type_system_or_err =
242 long_size_bytes = *size;
243 long_bit = long_size_bytes * 8;
245 llvm::consumeError(type_system_or_err.takeError());
248 constexpr size_t fbsd_maxcomlen = 19;
254 std::vector<lldb::addr_t> process_addrs;
260 process_addrs.push_back(proc);
265 for (
auto proc_it = process_addrs.rbegin(); proc_it != process_addrs.rend();
271 char comm[fbsd_maxcomlen + 1];
288 char thread_name[fbsd_maxcomlen + 1];
290 sizeof(thread_name),
error);
296 std::string thread_desc = llvm::formatv(
"(pid {0}) {1}", pid, comm);
297 if (*thread_name && strcmp(thread_name, comm)) {
299 thread_desc += thread_name;
306 if (tid == dumptid) {
309 thread_desc +=
" (crashed)";
310 }
else if (oncpu != -1) {
313 bool is_stopped =
false;
314 if (oncpu >= 0 &&
static_cast<uint32_t
>(oncpu) <= mp_maxid &&
316 uint32_t
bit = oncpu % long_bit;
317 uint32_t word = oncpu / long_bit;
318 lldb::addr_t mask_addr = stopped_cpus + word * long_size_bytes;
320 mask_addr, long_size_bytes, 0,
error);
322 is_stopped = (mask & (1ULL <<
bit)) != 0;
328 pcb_addr = stoppcbs + oncpu * pcbsize;
332 thread_desc += llvm::formatv(
" (on CPU {0})", oncpu);
339 thread->SetIsCrashedThread(
true);
345 const uint32_t num_threads = old_thread_list.
GetSize(
false);
346 for (uint32_t i = 0; i < num_threads; ++i)
349 return new_thread_list.
GetSize(
false) > 0;
355 rd = kvm_read2(
m_kvm, addr, buf, size);
356 if (rd < 0 ||
static_cast<size_t>(rd) != size) {
359 return rd > 0 ? rd : 0;
371 kssize_t displacement = kvm_kerndisp(
m_kvm);
373 if (displacement == 0)
378 if (!kernel_module_sp)
381 bool changed =
false;
382 kernel_module_sp->SetLoadAddress(target,
388 loaded_module_list.
Append(kernel_module_sp);
417 uint64_t offset_msg_ptr = 0;
418 uint64_t offset_msg_size = 0;
419 uint64_t offset_msg_wseq = 0;
420 uint64_t offset_msg_rseq = 0;
429 for (uint32_t i = 0; i < num_fields; i++) {
430 std::string field_name;
431 uint64_t field_offset = 0;
436 if (field_name ==
"msg_ptr") {
437 offset_msg_ptr = field_offset / 8;
439 }
else if (field_name ==
"msg_size") {
440 offset_msg_size = field_offset / 8;
442 }
else if (field_name ==
"msg_wseq") {
443 offset_msg_wseq = field_offset / 8;
445 }
else if (field_name ==
"msg_rseq") {
446 offset_msg_rseq = field_offset / 8;
451 if (field_found != 4) {
454 "FreeBSD-Kernel-Core: Could not find all required fields for msgbuf");
467 offset_msg_size = ptr_size + 4;
468 offset_msg_wseq = ptr_size + 8;
469 offset_msg_rseq = ptr_size + 12;
479 if (!
error.Success() || size == 0)
484 if (!
error.Success())
489 if (!
error.Success())
494 uint32_t rseq_pos = rseq % size;
495 uint32_t wseq_pos = wseq % size;
497 if (rseq_pos == wseq_pos)
505 stream_sp->PutCString(
"\nUnread portion of the kernel message buffer:\n");
508 if (rseq_pos < wseq_pos) {
510 size_t len = wseq_pos - rseq_pos;
511 std::string buf(len,
'\0');
513 if (
error.Success() && bytes_read > 0) {
514 buf.resize(bytes_read);
519 size_t len1 = size - rseq_pos;
520 std::string buf1(len1,
'\0');
521 size_t bytes_read1 =
ReadMemory(bufp + rseq_pos, &buf1[0], len1,
error);
522 if (
error.Success() && bytes_read1 > 0) {
523 buf1.resize(bytes_read1);
528 std::string buf2(wseq_pos,
'\0');
530 if (
error.Success() && bytes_read2 > 0) {
531 buf2.resize(bytes_read2);
537 stream_sp->PutChar(
'\n');
static llvm::raw_ostream & error(Stream &strm)
static PluginProperties & GetGlobalPluginProperties()
#define LLDB_LOGF(log,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
static PluginProperties & GetGlobalPluginProperties()
static llvm::StringRef GetPluginNameStatic()
lldb_private::Status DoDestroy() override
static llvm::StringRef GetPluginNameStatic()
void PrintUnreadMessage()
lldb::addr_t FindSymbol(const char *name)
~ProcessFreeBSDKernelCore()
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Actually do the reading of memory from a process.
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener, const lldb_private::FileSpec *crash_file_path, bool can_connect)
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
static void DebuggerInitialize(lldb_private::Debugger &debugger)
static llvm::StringRef GetPluginDescriptionStatic()
lldb_private::Status DoLoadCore() override
void SetKernelDisplacement()
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
ProcessFreeBSDKernelCore(lldb::TargetSP target_sp, lldb::ListenerSP listener, kvm_t *kvm, const lldb_private::FileSpec &core_file)
size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size, lldb_private::Status &error) override
Actually do the writing of memory to a process.
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 m_printed_unread_message
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
Generic representation of a type in a programming language.
CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) const
Create related types using the current type's AST.
CompilerType GetFieldAtIndex(size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) const
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
uint32_t GetNumFields() const
A uniqued constant string class.
CommandInterpreter & GetCommandInterpreter()
lldb::StreamUP GetAsyncOutputStream()
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.
A collection class for Module objects.
void FindTypes(Module *search_first, const TypeQuery &query, lldb_private::TypeResults &results) const
Find types using a type-matching object that contains all search parameters.
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool CreateSettingForProcessPlugin(Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property)
static lldb::OptionValuePropertiesSP GetSettingForProcessPlugin(Debugger &debugger, llvm::StringRef setting_name)
static bool UnregisterPlugin(ABICreateInstance create_callback)
PostMortemProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const FileSpec &core_file)
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
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
uint64_t ReadUnsignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, uint64_t fail_value, Status &error)
Reads an unsigned integer of the specified byte size from process memory.
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
uint32_t GetAddressByteSize() const
friend class DynamicLoader
Target & GetTarget()
Get the target object pointer for this module.
lldb::OptionValuePropertiesSP GetValueProperties() const
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
lldb::addr_t GetLoadAddress(Target *target) const
void ModulesDidLoad(ModuleList &module_list)
This call may preload module symbols, and may do so in parallel depending on the following target set...
Debugger & GetDebugger() const
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
const ModuleList & GetImages() const
Get accessor for the images for this process.
void AddThread(const lldb::ThreadSP &thread_sp)
uint32_t GetSize(bool can_update=true)
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
A class that contains all state required for type lookups.
This class tracks the state and results of a TypeQuery.
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::Thread > ThreadSP
@ eLanguageTypeC
Non-standardized C, such as K&R.
std::shared_ptr< lldb_private::Stream > StreamSP
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