Files
clang-p2996/lldb/test/API/functionalities/postmortem/FreeBSDKernel/tools/lldb-minimize-processes.patch
Adrian Prantl 0642cd768b [lldb] Turn lldb_private::Status into a value type. (#106163)
This patch removes all of the Set.* methods from Status.

This cleanup is part of a series of patches that make it harder use the
anti-pattern of keeping a long-lives Status object around and updating
it while dropping any errors it contains on the floor.

This patch is largely NFC, the more interesting next steps this enables
is to:
1. remove Status.Clear()
2. assert that Status::operator=() never overwrites an error
3. remove Status::operator=()

Note that step (2) will bring 90% of the benefits for users, and step
(3) will dramatically clean up the error handling code in various
places. In the end my goal is to convert all APIs that are of the form

`    ResultTy DoFoo(Status& error)
`
to

`    llvm::Expected<ResultTy> DoFoo()
`
How to read this patch?

The interesting changes are in Status.h and Status.cpp, all other
changes are mostly

` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git
grep -l SetErrorString lldb/source)
`
plus the occasional manual cleanup.
2024-08-27 10:59:31 -07:00

86 lines
3.6 KiB
Diff

diff --git a/lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp b/lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp
index e3707365a9c3..c4a9c82f3c63 100644
--- a/lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp
+++ b/lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp
@@ -38,6 +38,8 @@ public:
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
lldb_private::Status &error) override;
+ size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf,
+ size_t size, Status &error) override;
private:
fvc_t *m_fvc;
@@ -185,6 +187,7 @@ bool ProcessFreeBSDKernel::DoUpdateThreadList(ThreadList &old_thread_list,
// iterate through a linked list of all processes
// allproc is a pointer to the first list element, p_list field
// (found at offset_p_list) specifies the next element
+ lldb::addr_t prev = 0;
for (lldb::addr_t proc =
ReadPointerFromMemory(FindSymbol("allproc"), error);
proc != 0 && proc != LLDB_INVALID_ADDRESS;
@@ -195,6 +198,8 @@ bool ProcessFreeBSDKernel::DoUpdateThreadList(ThreadList &old_thread_list,
char comm[fbsd_maxcomlen + 1];
ReadCStringFromMemory(proc + offset_p_comm, comm, sizeof(comm), error);
+ bool interesting = false;
+
// iterate through a linked list of all process' threads
// the initial thread is found in process' p_threads, subsequent
// elements are linked via td_plist field
@@ -231,6 +236,7 @@ bool ProcessFreeBSDKernel::DoUpdateThreadList(ThreadList &old_thread_list,
// NB: dumppcb can be LLDB_INVALID_ADDRESS if reading it failed
pcb_addr = dumppcb;
thread_desc += " (crashed)";
+ interesting = true;
} else if (oncpu != -1) {
// if we managed to read stoppcbs and pcb_size, use them to find
// the correct PCB
@@ -239,13 +245,27 @@ bool ProcessFreeBSDKernel::DoUpdateThreadList(ThreadList &old_thread_list,
else
pcb_addr = LLDB_INVALID_ADDRESS;
thread_desc += llvm::formatv(" (on CPU {0})", oncpu);
+ interesting = true;
}
ThreadSP thread_sp{
new ThreadFreeBSDKernel(*this, tid, pcb_addr, thread_desc)};
new_thread_list.AddThread(thread_sp);
}
+
+ if (interesting) {
+ printf("pid %d is interesting\n", pid);
+ if (prev != 0) {
+ printf("will link %d to %d\n", prev, proc);
+ if (!WritePointerToMemory(prev + offset_p_list, proc, error))
+ assert(0 && "write failed");
+ }
+ prev = proc;
+ }
}
+ printf("last: %d\n", prev);
+ if (!WritePointerToMemory(prev + offset_p_list, 0, error))
+ assert(0 && "write failed");
} else {
const uint32_t num_threads = old_thread_list.GetSize(false);
for (uint32_t i = 0; i < num_threads; ++i)
@@ -295,6 +315,18 @@ size_t ProcessFreeBSDKernelFVC::DoReadMemory(lldb::addr_t addr, void *buf,
return rd;
}
+size_t ProcessFreeBSDKernelFVC::DoWriteMemory(lldb::addr_t vm_addr, const void *buf,
+ size_t size, Status &error) {
+ ssize_t rd = 0;
+ rd = fvc_write(m_fvc, vm_addr, buf, size);
+ printf("fvc_write(%p, %p, %d) -> %d\n", vm_addr, buf, size, rd);
+ if (rd < 0 || static_cast<size_t>(rd) != size) {
+ error = Status::FromErrorStringWithFormat("Writing memory failed: %s", GetError());
+ return rd > 0 ? rd : 0;
+ }
+ return rd;
+}
+
const char *ProcessFreeBSDKernelFVC::GetError() { return fvc_geterr(m_fvc); }
#endif // LLDB_ENABLE_FBSDVMCORE