LLDB mainline
ProcessFreeBSDKernelCore.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
9#include "lldb/Core/Module.h"
14#include "lldb/Symbol/Type.h"
17#include "lldb/Utility/Log.h"
19
23
24using namespace lldb;
25using namespace lldb_private;
26
28
29namespace {
30
31#define LLDB_PROPERTIES_processfreebsdkernelcore
32#include "ProcessFreeBSDKernelCoreProperties.inc"
33
34enum {
35#define LLDB_PROPERTIES_processfreebsdkernelcore
36#include "ProcessFreeBSDKernelCorePropertiesEnum.inc"
37};
38
39class PluginProperties : public Properties {
40public:
41 static llvm::StringRef GetSettingName() {
43 }
44
45 PluginProperties() : Properties() {
46 m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
47 m_collection_sp->Initialize(g_processfreebsdkernelcore_properties_def);
48 }
49
50 ~PluginProperties() override = default;
51
52 bool GetReadOnly() const {
53 const uint32_t idx = ePropertyReadOnly;
54 return GetPropertyAtIndexAs<bool>(idx, true);
55 }
56};
57
58} // namespace
59
60static PluginProperties &GetGlobalPluginProperties() {
61 static PluginProperties g_settings;
62 return g_settings;
63}
64
66 : public CommandObjectParsed {
67public:
69 CommandInterpreter &interpreter)
71 interpreter, "process plugin refresh-threads",
72 "Refresh the thread list from the FreeBSD kernel core. The thread "
73 "list and related data structures may be being read from live "
74 "memory (/dev/mem), which may have changed since the last refresh. "
75 "This command clears LLDB's thread list and memory cache then "
76 "re-reads the kernel's allproc/zombie lists to rebuild the thread "
77 "list from scratch.",
78 "process plugin refresh-threads",
79 eCommandRequiresProcess | eCommandTryTargetAPILock) {}
80
82
83protected:
84 void DoExecute(Args &command, CommandReturnObject &result) override {
85 // TODO: Return early for elf-core based implementation.
86
87 auto process = static_cast<ProcessFreeBSDKernelCore *>(
88 m_interpreter.GetExecutionContext().GetProcessPtr());
89
90 // Clear the memory cache so DoUpdateThreadList() will re-read allproc,
91 // zombproc, and all thread/proc structures fresh from the core dump instead
92 // of getting stale cached values.
93 process->m_memory_cache.Clear();
94
95 // Clear both thread lists to guarantee that UpdateThreadListIfNeeded() sees
96 // size == 0 and enters the rebuild path regardless of stop-ID state.
97 // UpdateThreadListIfNeeded() passes m_thread_list_real as old_thread_list
98 // to DoUpdateThreadList(), and DoUpdateThreadList() only rebuilds from
99 // scratch when old_thread_list is empty. m_thread_list is the public copy
100 // that is sync'd from m_thread_list_real afterwards.
101 process->m_thread_list_real.Clear();
102 process->m_thread_list.Clear();
103
104 // This calls UpdateThreadListIfNeeded() to rebuild the process thread list.
105 const uint32_t num_threads =
106 process->GetThreadList().GetSize(/*can_update=*/true);
108 "Thread list refreshed, {0} thread{1} found.", num_threads,
109 num_threads == 1 ? "" : "s");
111 }
112};
113
115 ListenerSP listener_sp,
116 const FileSpec &core_file)
117 : PostMortemProcess(target_sp, listener_sp, core_file) {}
118
120 m_thread_list.Clear();
121
122 // We need to call finalize on the process before destroying ourselves to
123 // make sure all of the broadcaster cleanup goes as planned. If we destruct
124 // this class, then Process::~Process() might have problems trying to fully
125 // destroy the broadcaster.
126 Finalize(/*destructing=*/true);
127}
128
130 lldb::TargetSP target_sp, ListenerSP listener_sp,
131 const FileSpec *crash_file, bool can_connect) {
132 ModuleSP executable = target_sp->GetExecutableModule();
133 if (crash_file && !can_connect && executable) {
134 char errbuf[_POSIX2_LINE_MAX];
135 kvm_t *kvm =
136 kvm_open2(executable->GetFileSpec().GetPath().c_str(),
137 crash_file->GetPath().c_str(), O_RDONLY, errbuf, nullptr);
138 if (kvm) {
139 kvm_close(kvm);
140 return std::make_shared<ProcessFreeBSDKernelCore>(target_sp, listener_sp,
141 *crash_file);
142 }
143 LLDB_LOGF(GetLog(LLDBLog::Process), "FreeBSD-Kernel-Core: %s", errbuf);
144 }
145 return nullptr;
146}
147
153
156 debugger, PluginProperties::GetSettingName())) {
157 const bool is_global_setting = true;
160 "Properties for the freebsd-kernel process plug-in.",
161 is_global_setting);
162 }
163}
164
168
170 bool plugin_specified_by_name) {
171 return true;
172}
173
175 if (!m_command_sp) {
176 CommandInterpreter &interp =
178 m_command_sp = std::make_unique<CommandObjectMultiword>(
179 interp, "process plugin",
180 "Commands for the FreeBSD kernel process plug-in.",
181 "process plugin <subcommand> [<subcommand-options>]");
182 m_command_sp->LoadSubCommand(
183 "refresh-threads",
186 }
187 return m_command_sp.get();
188}
189
191 ModuleSP executable = GetTarget().GetExecutableModule();
192 if (!executable)
194 "ProcessFreeBSDKernelCore: no executable module set on target");
195
196 char errbuf[_POSIX2_LINE_MAX];
197 m_kvm = kvm_open2(executable->GetFileSpec().GetPath().c_str(),
198 GetCoreFile().GetPath().c_str(), O_RDWR, errbuf, nullptr);
199
200 if (!m_kvm) {
201 LLDB_LOGF(GetLog(LLDBLog::Process), "FreeBSD-Kernel-Core: %s", errbuf);
203 "ProcessFreeBSDKernelCore: kvm_open2 failed for core '%s' "
204 "with kernel '%s'",
205 GetCoreFile().GetPath().c_str(),
206 executable->GetFileSpec().GetPath().c_str());
207 }
208
210
211 return Status();
212}
213
220
222 if (!m_kvm)
223 return Status::FromErrorString("kvm file descriptor is not set.");
224
225 kvm_close(m_kvm);
226 return Status();
227}
228
235
237 const void *buf, size_t size,
238 Status &error) {
239 if (GetGlobalPluginProperties().GetReadOnly()) {
241 "Memory writes are currently disabled. You can enable them with "
242 "`settings set plugin.process.freebsd-kernel-core.read-only false`.");
243 return 0;
244 }
245
246 ssize_t rd = 0;
247 rd = kvm_write(m_kvm, addr, buf, size);
248 if (rd < 0 || static_cast<size_t>(rd) != size) {
249 error = Status::FromErrorStringWithFormat("Writing memory failed: %s",
250 GetError());
251 return rd > 0 ? rd : 0;
252 }
253 return rd;
254}
255
257 ThreadList &new_thread_list) {
258 if (old_thread_list.GetSize(false) == 0) {
259 // Make up the thread the first time this is called so we can set our one
260 // and only core thread state up.
261
262 // We cannot construct a thread without a register context as that crashes
263 // LLDB but we can construct a process without threads to provide minimal
264 // memory reading support.
265 switch (GetTarget().GetArchitecture().GetMachine()) {
266 case llvm::Triple::arm:
267 case llvm::Triple::aarch64:
268 case llvm::Triple::ppc64le:
269 case llvm::Triple::riscv64:
270 case llvm::Triple::x86:
271 case llvm::Triple::x86_64:
272 break;
273 default:
274 return false;
275 }
276
278
279 // struct field offsets are written as symbols so that we don't have
280 // to figure them out ourselves
281 // Process-related offsets:
282 int32_t offset_p_list = ReadSignedIntegerFromMemory(
283 FindSymbol("proc_off_p_list"), 4, -1, error);
284 if (error.Fail())
285 return false;
286
287 int32_t offset_p_pid =
288 ReadSignedIntegerFromMemory(FindSymbol("proc_off_p_pid"), 4, -1, error);
289 if (error.Fail())
290 return false;
291
292 int32_t offset_p_threads = ReadSignedIntegerFromMemory(
293 FindSymbol("proc_off_p_threads"), 4, -1, error);
294 if (error.Fail())
295 return false;
296
297 int32_t offset_p_comm = ReadSignedIntegerFromMemory(
298 FindSymbol("proc_off_p_comm"), 4, -1, error);
299 if (error.Fail())
300 return false;
301
302 // Thread-related offsets:
303 int32_t offset_td_tid = ReadSignedIntegerFromMemory(
304 FindSymbol("thread_off_td_tid"), 4, -1, error);
305 if (error.Fail())
306 return false;
307
308 int32_t offset_td_plist = ReadSignedIntegerFromMemory(
309 FindSymbol("thread_off_td_plist"), 4, -1, error);
310 if (error.Fail())
311 return false;
312
313 int32_t offset_td_pcb = ReadSignedIntegerFromMemory(
314 FindSymbol("thread_off_td_pcb"), 4, -1, error);
315 if (error.Fail())
316 return false;
317
318 int32_t offset_td_oncpu = ReadSignedIntegerFromMemory(
319 FindSymbol("thread_off_td_oncpu"), 4, -1, error);
320 if (error.Fail())
321 return false;
322
323 int32_t offset_td_name = ReadSignedIntegerFromMemory(
324 FindSymbol("thread_off_td_name"), 4, -1, error);
325 if (error.Fail())
326 return false;
327
328 // Fail if we were not able to read any of the offsets.
329 if (offset_p_list == -1 || offset_p_pid == -1 || offset_p_threads == -1 ||
330 offset_p_comm == -1 || offset_td_tid == -1 || offset_td_plist == -1 ||
331 offset_td_pcb == -1 || offset_td_oncpu == -1 || offset_td_name == -1)
332 return false;
333
334 // dumptid contains the thread-id of the crashing thread
335 // dumppcb contains its PCB
336 int32_t dumptid =
337 ReadSignedIntegerFromMemory(FindSymbol("dumptid"), 4, -1, error);
338 if (error.Fail())
339 return false;
340
341 lldb::addr_t dumppcb = FindSymbol("dumppcb");
342
343 // stoppcbs is an array of PCBs on all CPUs.
344 // Each element is of size pcb_size.
345 int32_t pcbsize =
346 ReadSignedIntegerFromMemory(FindSymbol("pcb_size"), 4, -1, error);
347 if (error.Fail())
348 return false;
349
350 lldb::addr_t stoppcbs = FindSymbol("stoppcbs");
351
352 // Read stopped_cpus bitmask and mp_maxid for CPU validation.
353 lldb::addr_t stopped_cpus = FindSymbol("stopped_cpus");
354 uint32_t mp_maxid = 0;
355
356 if (stopped_cpus != LLDB_INVALID_ADDRESS) {
357 // https://cgit.freebsd.org/src/tree/sys/kern/subr_smp.c
358 mp_maxid =
359 ReadSignedIntegerFromMemory(FindSymbol("mp_maxid"), 4, 0, error);
360 if (error.Fail())
361 stopped_cpus = LLDB_INVALID_ADDRESS;
362 }
363
364 uint32_t long_size_bytes = GetAddressByteSize();
365 uint32_t long_bit = long_size_bytes * 8;
366
367 if (auto type_system_or_err =
368 GetTarget().GetScratchTypeSystemForLanguage(eLanguageTypeC)) {
369 CompilerType long_type =
370 (*type_system_or_err)->GetBasicTypeFromAST(eBasicTypeLong);
371 if (long_type.IsValid())
372 if (auto size = long_type.GetByteSize(nullptr))
373 long_size_bytes = *size;
374 long_bit = long_size_bytes * 8;
375 } else
376 llvm::consumeError(type_system_or_err.takeError());
377
378 // https://cgit.freebsd.org/src/tree/sys/sys/param.h
379 constexpr size_t fbsd_maxcomlen = 19;
380
381 // Iterate through a linked list of all processes then order incrementally
382 // by pid. Though new processes are added to the head of this list, process
383 // ids may be reused as well. So we cannot rely on it being in a particular
384 // order.
385 const lldb::addr_t allproc_addr = FindSymbol("allproc");
386 if (allproc_addr == LLDB_INVALID_ADDRESS)
387 return false;
388
389 std::vector<std::pair<lldb::addr_t, int32_t>> process_addrs;
390 for (lldb::addr_t proc = ReadPointerFromMemory(allproc_addr, error);
391 error.Success() && proc != 0 && proc != LLDB_INVALID_ADDRESS;
392 proc = ReadPointerFromMemory(proc + offset_p_list, error)) {
393 int32_t pid =
394 ReadSignedIntegerFromMemory(proc + offset_p_pid, 4, -1, error);
395 if (error.Fail())
396 return false;
397 process_addrs.emplace_back(proc, pid);
398 }
399
400 if (error.Fail())
401 return false;
402
403 std::sort(process_addrs.begin(), process_addrs.end(),
404 [](const auto &a, const auto &b) { return a.second < b.second; });
405
406 for (auto [proc, pid] : process_addrs) {
407 // process' command-line string
408 char comm[fbsd_maxcomlen + 1];
409 ReadCStringFromMemory(proc + offset_p_comm, comm, sizeof(comm), error);
410 if (error.Fail())
411 continue;
412
413 // Iterate through a linked list of all process' threads
414 // the initial thread is found in process' p_threads, subsequent
415 // elements are linked via td_plist field.
416 // If reading memory fails, skip to the next thread.
417 for (lldb::addr_t td =
418 ReadPointerFromMemory(proc + offset_p_threads, error);
419 error.Success() && td != 0;
420 td = ReadPointerFromMemory(td + offset_td_plist, error)) {
421 int32_t tid =
422 ReadSignedIntegerFromMemory(td + offset_td_tid, 4, -1, error);
423 if (error.Fail())
424 continue;
425
426 lldb::addr_t pcb_addr =
427 ReadPointerFromMemory(td + offset_td_pcb, error);
428 if (error.Fail())
429 continue;
430
431 // whether process was on CPU (-1 if not, otherwise CPU number)
432 int32_t oncpu =
433 ReadSignedIntegerFromMemory(td + offset_td_oncpu, 4, -2, error);
434 if (error.Fail())
435 continue;
436
437 // thread name
438 char thread_name[fbsd_maxcomlen + 1];
439 ReadCStringFromMemory(td + offset_td_name, thread_name,
440 sizeof(thread_name), error);
441 if (error.Fail())
442 continue;
443
444 // If we failed to read TID, ignore this thread.
445 if (tid == -1)
446 continue;
447
448 std::string thread_desc = llvm::formatv("(pid {0}) {1}", pid, comm);
449 if (*thread_name && strcmp(thread_name, comm)) {
450 thread_desc += '/';
451 thread_desc += thread_name;
452 }
453
454 // Roughly:
455 // 1. if the thread crashed, its PCB is going to be at "dumppcb"
456 // 2. if the thread was on CPU, its PCB is going to be on the CPU
457 // 3. otherwise, its PCB is in the thread struct
458 if (tid == dumptid) {
459 // NB: dumppcb can be LLDB_INVALID_ADDRESS if reading it failed
460 pcb_addr = dumppcb;
461 thread_desc += " (crashed)";
462 } else if (oncpu != -1) {
463 // Verify the CPU is actually in the stopped set before using
464 // its stoppcbs entry.
465 bool is_stopped = false;
466 if (oncpu >= 0 && static_cast<uint32_t>(oncpu) <= mp_maxid &&
467 stopped_cpus != LLDB_INVALID_ADDRESS) {
468 uint32_t bit = oncpu % long_bit;
469 uint32_t word = oncpu / long_bit;
470 lldb::addr_t mask_addr = stopped_cpus + word * long_size_bytes;
471 uint64_t mask = ReadUnsignedIntegerFromMemory(
472 mask_addr, long_size_bytes, 0, error);
473 if (error.Success())
474 is_stopped = (mask & (1ULL << bit)) != 0;
475 }
476
477 // If we managed to read stoppcbs and pcb_size and the cpu is marked
478 // as stopped, use them to find the correct PCB.
479 if (is_stopped && stoppcbs != LLDB_INVALID_ADDRESS && pcbsize > 0) {
480 pcb_addr = stoppcbs + oncpu * pcbsize;
481 } else {
482 pcb_addr = LLDB_INVALID_ADDRESS;
483 }
484 thread_desc += llvm::formatv(" (on CPU {0})", oncpu);
485 }
486
487 auto thread =
488 new ThreadFreeBSDKernelCore(*this, tid, pcb_addr, thread_desc);
489
490 if (tid == dumptid)
491 thread->SetIsCrashedThread(true);
492
493 new_thread_list.AddThread(static_cast<ThreadSP>(thread));
494 }
495
496 // If reading thread list has failed, return with false.
497 if (error.Fail())
498 return false;
499 }
500 } else {
501 const uint32_t num_threads = old_thread_list.GetSize(false);
502 for (uint32_t i = 0; i < num_threads; ++i)
503 new_thread_list.AddThread(old_thread_list.GetThreadAtIndex(i, false));
504 }
505 return new_thread_list.GetSize(false) > 0;
506}
507
509 size_t size, Status &error) {
510 ssize_t rd = 0;
511 rd = kvm_read2(m_kvm, addr, buf, size);
512 if (rd < 0 || static_cast<size_t>(rd) != size) {
513 error = Status::FromErrorStringWithFormat("Reading memory failed: %s",
514 GetError());
515 return rd > 0 ? rd : 0;
516 }
517 return rd;
518}
519
522 const Symbol *sym = mod_sp->FindFirstSymbolWithNameAndType(ConstString(name));
523 return sym ? sym->GetLoadAddress(&GetTarget()) : LLDB_INVALID_ADDRESS;
524}
525
527 kssize_t displacement = kvm_kerndisp(m_kvm);
528
529 if (displacement == 0)
530 return;
531
532 Target &target = GetTarget();
533 lldb::ModuleSP kernel_module_sp = target.GetExecutableModule();
534 if (!kernel_module_sp)
535 return;
536
537 bool changed = false;
538 kernel_module_sp->SetLoadAddress(target,
539 static_cast<lldb::addr_t>(displacement),
540 /*value_is_offset=*/true, changed);
541
542 if (changed) {
543 ModuleList loaded_module_list;
544 loaded_module_list.Append(kernel_module_sp);
545 target.ModulesDidLoad(loaded_module_list);
546 }
547}
548
550 Target &target = GetTarget();
551 Debugger &debugger = target.GetDebugger();
552
554
555 // Find msgbufp symbol (pointer to message buffer)
556 lldb::addr_t msgbufp_addr = FindSymbol("msgbufp");
557 if (msgbufp_addr == LLDB_INVALID_ADDRESS)
558 return;
559
560 // Read the pointer value
561 lldb::addr_t msgbufp = ReadPointerFromMemory(msgbufp_addr, error);
562 if (error.Fail() || msgbufp == LLDB_INVALID_ADDRESS)
563 return;
564
565 // Get the type information for struct msgbuf from DWARF
566 TypeQuery query("msgbuf");
567 TypeResults results;
568 target.GetImages().FindTypes(nullptr, query, results);
569
570 uint64_t offset_msg_ptr = 0;
571 uint64_t offset_msg_size = 0;
572 uint64_t offset_msg_wseq = 0;
573 uint64_t offset_msg_rseq = 0;
574
575 if (results.GetTypeMap().GetSize() > 0) {
576 // Found type info - use it to get field offsets
577 CompilerType msgbuf_type =
578 results.GetTypeMap().GetTypeAtIndex(0)->GetForwardCompilerType();
579
580 uint32_t num_fields = msgbuf_type.GetNumFields();
581 int field_found = 0;
582 for (uint32_t i = 0; i < num_fields; i++) {
583 std::string field_name;
584 uint64_t field_offset = 0;
585
586 msgbuf_type.GetFieldAtIndex(i, field_name, &field_offset, nullptr,
587 nullptr);
588
589 if (field_name == "msg_ptr") {
590 offset_msg_ptr = field_offset / 8; // Convert bits to bytes
591 field_found++;
592 } else if (field_name == "msg_size") {
593 offset_msg_size = field_offset / 8;
594 field_found++;
595 } else if (field_name == "msg_wseq") {
596 offset_msg_wseq = field_offset / 8;
597 field_found++;
598 } else if (field_name == "msg_rseq") {
599 offset_msg_rseq = field_offset / 8;
600 field_found++;
601 }
602 }
603
604 if (field_found != 4) {
605 LLDB_LOGF(
607 "FreeBSD-Kernel-Core: Could not find all required fields for msgbuf");
608 return;
609 }
610 } else {
611 // Fallback: use hardcoded offsets based on struct layout
612 // struct msgbuf layout (from sys/sys/msgbuf.h):
613 // char *msg_ptr; - offset 0
614 // u_int msg_magic; - offset ptr_size
615 // u_int msg_size; - offset ptr_size + 4
616 // u_int msg_wseq; - offset ptr_size + 8
617 // u_int msg_rseq; - offset ptr_size + 12
618 uint32_t ptr_size = GetAddressByteSize();
619 offset_msg_ptr = 0;
620 offset_msg_size = ptr_size + 4;
621 offset_msg_wseq = ptr_size + 8;
622 offset_msg_rseq = ptr_size + 12;
623 }
624
625 // Read struct msgbuf fields
626 lldb::addr_t bufp = ReadPointerFromMemory(msgbufp + offset_msg_ptr, error);
627 if (error.Fail() || bufp == LLDB_INVALID_ADDRESS)
628 return;
629
630 uint32_t size =
631 ReadUnsignedIntegerFromMemory(msgbufp + offset_msg_size, 4, 0, error);
632 if (error.Fail() || size == 0)
633 return;
634
635 uint32_t wseq =
636 ReadUnsignedIntegerFromMemory(msgbufp + offset_msg_wseq, 4, 0, error);
637 if (error.Fail())
638 return;
639
640 uint32_t rseq =
641 ReadUnsignedIntegerFromMemory(msgbufp + offset_msg_rseq, 4, 0, error);
642 if (error.Fail())
643 return;
644
645 // Convert sequences to positions
646 // MSGBUF_SEQ_TO_POS macro in FreeBSD: ((seq) % (size))
647 uint32_t rseq_pos = rseq % size;
648 uint32_t wseq_pos = wseq % size;
649
650 if (rseq_pos == wseq_pos)
651 return;
652
653 // Print crash info at once using stream
654 lldb::StreamSP stream_sp = debugger.GetAsyncOutputStream();
655 if (!stream_sp)
656 return;
657
658 stream_sp->PutCString("\nUnread portion of the kernel message buffer:\n");
659
660 // Read ring buffer in at most two chunks
661 if (rseq_pos < wseq_pos) {
662 // No wrap: read from rseq_pos to wseq_pos
663 size_t len = wseq_pos - rseq_pos;
664 std::string buf(len, '\0');
665 size_t bytes_read = ReadMemory(bufp + rseq_pos, &buf[0], len, error);
666 if (error.Success() && bytes_read > 0) {
667 buf.resize(bytes_read);
668 *stream_sp << buf;
669 }
670 } else {
671 // Wrap around: read from rseq_pos to end, then from start to wseq_pos
672 size_t len1 = size - rseq_pos;
673 std::string buf1(len1, '\0');
674 size_t bytes_read1 = ReadMemory(bufp + rseq_pos, &buf1[0], len1, error);
675 if (error.Success() && bytes_read1 > 0) {
676 buf1.resize(bytes_read1);
677 *stream_sp << buf1;
678 }
679
680 if (wseq_pos > 0) {
681 std::string buf2(wseq_pos, '\0');
682 size_t bytes_read2 = ReadMemory(bufp, &buf2[0], wseq_pos, error);
683 if (error.Success() && bytes_read2 > 0) {
684 buf2.resize(bytes_read2);
685 *stream_sp << buf2;
686 }
687 }
688 }
689
690 stream_sp->PutChar('\n');
691 stream_sp->Flush();
692}
693
694const char *ProcessFreeBSDKernelCore::GetError() { return kvm_geterr(m_kvm); }
static llvm::raw_ostream & error(Stream &strm)
#define bit
static PluginProperties & GetGlobalPluginProperties()
#define LLDB_LOGF(log,...)
Definition Log.h:378
#define LLDB_PLUGIN_DEFINE(PluginName)
static PluginProperties & GetGlobalPluginProperties()
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectProcessFreeBSDKernelCoreRefreshThreads(CommandInterpreter &interpreter)
~CommandObjectProcessFreeBSDKernelCoreRefreshThreads() override=default
static llvm::StringRef GetPluginNameStatic()
lldb_private::Status DoDestroy() override
static llvm::StringRef GetPluginNameStatic()
ProcessFreeBSDKernelCore(lldb::TargetSP target_sp, lldb::ListenerSP listener, const lldb_private::FileSpec &core_file)
lldb::addr_t FindSymbol(const char *name)
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
lldb_private::CommandObject * GetPluginCommandObject() override
Return a multi-word command object that can be used to expose plug-in specific commands.
friend class CommandObjectProcessFreeBSDKernelCoreRefreshThreads
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
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 CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
std::unique_ptr< lldb_private::CommandObjectMultiword > m_command_sp
A command line argument class.
Definition Args.h:33
CommandObjectParsed(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
CommandInterpreter & m_interpreter
void SetStatus(lldb::ReturnStatus status)
void void AppendMessageWithFormatv(const char *format, Args &&...args)
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.
Definition ConstString.h:40
CommandInterpreter & GetCommandInterpreter()
Definition Debugger.h:182
lldb::StreamUP GetAsyncOutputStream()
static DynamicLoader * FindPlugin(Process *process, llvm::StringRef plugin_name)
Find a dynamic loader plugin for a given process.
A file utility class.
Definition FileSpec.h:57
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
void Clear(bool clear_invalid_ranges=false)
Definition Memory.cpp:32
A collection class for Module objects.
Definition ModuleList.h:125
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)
FileSpec GetCoreFile() const override
Provide a way to retrieve the core dump file that is loaded for debugging.
int64_t ReadSignedIntegerFromMemory(lldb::addr_t load_addr, size_t byte_size, int64_t fail_value, Status &error)
Definition Process.cpp:2366
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.
Definition Process.cpp:2197
lldb::DynamicLoaderUP m_dyld_up
Definition Process.h:3448
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition Process.cpp:1911
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.
Definition Process.cpp:2316
lldb::addr_t ReadPointerFromMemory(lldb::addr_t vm_addr, Status &error)
Definition Process.cpp:2377
friend class Target
Definition Process.h:361
MemoryCache m_memory_cache
Definition Process.h:3471
uint32_t GetAddressByteSize() const
Definition Process.cpp:3774
virtual void Finalize(bool destructing)
This object is about to be destroyed, do any necessary cleanup.
Definition Process.cpp:542
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition Process.h:3421
friend class DynamicLoader
Definition Process.h:358
friend class Debugger
Definition Process.h:357
friend class ThreadList
Definition Process.h:362
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1253
lldb::OptionValuePropertiesSP GetValueProperties() const
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
lldb::addr_t GetLoadAddress(Target *target) const
Definition Symbol.cpp:504
void ModulesDidLoad(ModuleList &module_list)
This call may preload module symbols, and may do so in parallel depending on the following target set...
Definition Target.cpp:1844
Debugger & GetDebugger() const
Definition Target.h:1249
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition Target.cpp:1528
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1166
void AddThread(const lldb::ThreadSP &thread_sp)
uint32_t GetSize(bool can_update=true)
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
uint32_t GetSize() const
Definition TypeMap.cpp:51
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
Definition TypeMap.cpp:59
A class that contains all state required for type lookups.
Definition Type.h:104
This class tracks the state and results of a TypeQuery.
Definition Type.h:344
TypeMap & GetTypeMap()
Definition Type.h:386
#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.
Definition Log.h:327
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
@ eLanguageTypeC
Non-standardized C, such as K&R.
std::shared_ptr< lldb_private::Stream > StreamSP
std::shared_ptr< lldb_private::Process > ProcessSP
@ eReturnStatusSuccessFinishResult
std::shared_ptr< lldb_private::Listener > ListenerSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP