File: lldb-minimize-processes.patch

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (85 lines) | stat: -rw-r--r-- 3,643 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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.SetErrorStringWithFormat("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