[Lldb-commits] [lldb] 71e66da - [Process/elf-core] Read PID from FreeBSD prpsinfo

Michał Górny via lldb-commits lldb-commits at lists.llvm.org
Wed May 12 02:51:49 PDT 2021


Author: Michał Górny
Date: 2021-05-12T11:51:37+02:00
New Revision: 71e66da04cf15cf47045b5d1482803197a24a75d

URL: https://github.com/llvm/llvm-project/commit/71e66da04cf15cf47045b5d1482803197a24a75d
DIFF: https://github.com/llvm/llvm-project/commit/71e66da04cf15cf47045b5d1482803197a24a75d.diff

LOG: [Process/elf-core] Read PID from FreeBSD prpsinfo

Add a function to read NT_PRPSINFO note from FreeBSD core dumps.  This
is necessary to get the process ID (NT_PRSTATUS has only thread ID).
Move the lp64 check from NT_PRSTATUS parsing to the parseFreeBSDNotes()
to avoid repeating it.

Differential Revision: https://reviews.llvm.org/D101893

Added: 
    

Modified: 
    lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 9896638fa8ff..78edd69d9aef 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -404,12 +404,8 @@ lldb::addr_t ProcessElfCore::GetImageInfoAddress() {
 // Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
 static void ParseFreeBSDPrStatus(ThreadData &thread_data,
                                  const DataExtractor &data,
-                                 const ArchSpec &arch) {
+                                 bool lp64) {
   lldb::offset_t offset = 0;
-  bool lp64 = (arch.GetMachine() == llvm::Triple::aarch64 ||
-               arch.GetMachine() == llvm::Triple::mips64 ||
-               arch.GetMachine() == llvm::Triple::ppc64 ||
-               arch.GetMachine() == llvm::Triple::x86_64);
   int pr_version = data.GetU32(&offset);
 
   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
@@ -433,6 +429,27 @@ static void ParseFreeBSDPrStatus(ThreadData &thread_data,
   thread_data.gpregset = DataExtractor(data, offset, len);
 }
 
+// Parse a FreeBSD NT_PRPSINFO note - see FreeBSD sys/procfs.h for details.
+static void ParseFreeBSDPrPsInfo(ProcessElfCore &process,
+                                 const DataExtractor &data,
+                                 bool lp64) {
+  lldb::offset_t offset = 0;
+  int pr_version = data.GetU32(&offset);
+
+  Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
+  if (log) {
+    if (pr_version > 1)
+      LLDB_LOGF(log, "FreeBSD PRPSINFO unexpected version %d", pr_version);
+  }
+
+  // Skip pr_psinfosz, pr_fname, pr_psargs
+  offset += 108;
+  if (lp64)
+    offset += 4;
+
+  process.SetID(data.GetU32(&offset)); // pr_pid
+}
+
 static llvm::Error ParseNetBSDProcInfo(const DataExtractor &data,
                                        uint32_t &cpi_nlwps,
                                        uint32_t &cpi_signo,
@@ -512,6 +529,11 @@ ProcessElfCore::parseSegment(const DataExtractor &segment) {
 }
 
 llvm::Error ProcessElfCore::parseFreeBSDNotes(llvm::ArrayRef<CoreNote> notes) {
+  ArchSpec arch = GetArchitecture();
+  bool lp64 = (arch.GetMachine() == llvm::Triple::aarch64 ||
+               arch.GetMachine() == llvm::Triple::mips64 ||
+               arch.GetMachine() == llvm::Triple::ppc64 ||
+               arch.GetMachine() == llvm::Triple::x86_64);
   bool have_prstatus = false;
   bool have_prpsinfo = false;
   ThreadData thread_data;
@@ -532,10 +554,11 @@ llvm::Error ProcessElfCore::parseFreeBSDNotes(llvm::ArrayRef<CoreNote> notes) {
     switch (note.info.n_type) {
     case ELF::NT_PRSTATUS:
       have_prstatus = true;
-      ParseFreeBSDPrStatus(thread_data, note.data, GetArchitecture());
+      ParseFreeBSDPrStatus(thread_data, note.data, lp64);
       break;
     case ELF::NT_PRPSINFO:
       have_prpsinfo = true;
+      ParseFreeBSDPrPsInfo(*this, note.data, lp64);
       break;
     case ELF::NT_FREEBSD_THRMISC: {
       lldb::offset_t offset = 0;


        


More information about the lldb-commits mailing list