[Lldb-commits] Implement Linux GetProcessCPUTypeFromExecutable, return architecture for "platform process list"

Michael Sartain mikesart at valvesoftware.com
Thu May 16 17:45:45 PDT 2013


Will look like this now:

(lldb) platform process list
...
5920   5917   mikesart   6       x86_64--linux tee
5923   1      mikesart   6       x86_64--linux wineserver
6004   1      mikesart   6       x86_64--linux wine64-preloader
6049   1      mikesart   4       i386--linux wine-preloader

I'll check in after this is ok'd. Thanks!
 -Mike

Index: source/Host/linux/Host.cpp
===================================================================
--- source/Host/linux/Host.cpp    (revision 182064)
+++ source/Host/linux/Host.cpp    (working copy)
@@ -18,6 +18,8 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
+#include "llvm/Support/ELF.h"
+
 #include "lldb/Core/Error.h"
 #include "lldb/Target/Process.h"

@@ -25,6 +27,9 @@
 #include "lldb/Core/DataBufferHeap.h"
 #include "lldb/Core/DataExtractor.h"

+#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Symbol/ObjectFile.h"
+
 using namespace lldb;
 using namespace lldb_private;

@@ -47,7 +52,6 @@
 // Get the process info with additional information from /proc/$PID/stat
(like process state, and tracer pid).
 static bool GetProcessAndStatInfo (lldb::pid_t pid, ProcessInstanceInfo
&process_info, ProcessStatInfo &stat_info, lldb::pid_t &tracerpid);

-
 namespace
 {

@@ -293,6 +297,37 @@
 }

 static bool
+GetProcessCPUTypeFromExecutable (const char *exe_path, ProcessInstanceInfo
&process_info)
+{
+    // Clear the architecture.
+    process_info.GetArchitecture().Clear();
+
+    ModuleSpecList specs;
+    FileSpec filespec (exe_path, false);
+    const size_t num_specs = ObjectFile::GetModuleSpecifications
(filespec, 0, specs);
+    assert(num_specs == 1 && "Linux plugin supports only a single
architecture");
+    if (num_specs == 1)
+    {
+        ModuleSpec module_spec;
+        if (specs.GetModuleSpecAtIndex (0, module_spec) &&
module_spec.GetArchitecture().IsValid())
+        {
+            const llvm::Triple &host_triple = Host::GetArchitecture
(Host::eSystemDefaultArchitecture).GetTriple();
+            llvm::Triple &module_triple =
module_spec.GetArchitecture().GetTriple();
+
+            // If the vendor or OS is unknown, use the host information.
The ArchType has to come from the executable.
+            if (module_triple.getVendor() == llvm::Triple::UnknownVendor)
+                module_triple.setVendorName (host_triple.getVendorName());
+            if (module_triple.getOS() == llvm::Triple::UnknownOS)
+                module_triple.setOSName (host_triple.getOSName());
+
+            process_info.GetArchitecture () =
module_spec.GetArchitecture();
+            return true;
+        }
+    }
+    return false;
+}
+
+static bool
 GetProcessAndStatInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info,
ProcessStatInfo &stat_info, lldb::pid_t &tracerpid)
 {
     tracerpid = 0;
@@ -300,9 +335,6 @@
     ::memset (&stat_info, 0, sizeof(stat_info));
     stat_info.ppid = LLDB_INVALID_PROCESS_ID;

-    // Architecture is intentionally omitted because that's better resolved
-    // in other places (see ProcessPOSIX::DoAttachWithID().
-
     // Use special code here because proc/[pid]/exe is a symbolic link.
     char link_path[PATH_MAX];
     char exe_path[PATH_MAX] = "";
@@ -324,6 +356,10 @@
     {
         exe_path[len - deleted_len] = 0;
     }
+    else
+    {
+        GetProcessCPUTypeFromExecutable (exe_path, process_info);
+    }

     process_info.SetProcessID(pid);
     process_info.GetExecutableFile().SetFile(exe_path, false);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20130516/fdb71e72/attachment.html>


More information about the lldb-commits mailing list