[Lldb-commits] [lldb] r143772 - in /lldb/trunk/source/Plugins/Process/Linux: ProcessLinux.cpp ProcessLinux.h ProcessMonitor.cpp

Greg Clayton gclayton at apple.com
Fri Nov 4 18:09:16 PDT 2011


Author: gclayton
Date: Fri Nov  4 20:09:16 2011
New Revision: 143772

URL: http://llvm.org/viewvc/llvm-project?rev=143772&view=rev
Log:
Patch from Dragos Tatulea which was a modified version of a patch from
Joel Dillon that fixed 64 debugging for Linux.

I also added a patch to fix up the ProcessLinux::DoLaunch() to be up to date.
I wasn't able to verify it compiles, but it should b really close.


Modified:
    lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp
    lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h
    lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp

Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp?rev=143772&r1=143771&r2=143772&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp Fri Nov  4 20:09:16 2011
@@ -87,10 +87,16 @@
       m_in_limbo(false),
       m_exit_now(false)
 {
+
+#if 0
     // FIXME: Putting this code in the ctor and saving the byte order in a
     // member variable is a hack to avoid const qual issues in GetByteOrder.
     ObjectFile *obj_file = GetTarget().GetExecutableModule()->GetObjectFile();
     m_byte_order = obj_file->GetByteOrder();
+#else
+    // XXX: Will work only for local processes.
+    m_byte_order = lldb::endian::InlHostByteOrder();
+#endif
 }
 
 ProcessLinux::~ProcessLinux()
@@ -138,23 +144,48 @@
 }
 
 Error
-ProcessLinux::DoLaunch(Module *module,
-                       char const *argv[],
-                       char const *envp[],
-                       uint32_t launch_flags,
-                       const char *stdin_path,
-                       const char *stdout_path,
-                       const char *stderr_path,
-                       const char *working_directory)
+ProcessLinux::DoLaunch (Module *module,
+                       const ProcessLaunchInfo &launch_info)
 {
     Error error;
     assert(m_monitor == NULL);
 
     SetPrivateState(eStateLaunching);
-    m_monitor = new ProcessMonitor(this, module,
-                                   argv, envp,
-                                   stdin_path, stdout_path, stderr_path,
-                                   error);
+
+    uint32_t launch_flags = launch_info.GetFlags().Get();
+    const char *stdin_path = NULL;
+    const char *stdout_path = NULL;
+    const char *stderr_path = NULL;
+    const char *working_dir = launch_info.GetWorkingDirectory();
+
+    const ProcessLaunchInfo::FileAction *file_action;
+    file_action = launch_info.GetFileActionForFD (STDIN_FILENO);
+    if (file_action)
+    {
+        if (file_action->GetAction () == ProcessLaunchInfo::FileAction::eFileActionOpen)
+            stdin_path = file_action->GetPath();
+    }
+    file_action = launch_info.GetFileActionForFD (STDOUT_FILENO);
+    if (file_action)
+    {
+        if (file_action->GetAction () == ProcessLaunchInfo::FileAction::eFileActionOpen)
+            stdout_path = file_action->GetPath();
+    }
+    file_action = launch_info.GetFileActionForFD (STDERR_FILENO);
+    if (file_action)
+    {
+        if (file_action->GetAction () == ProcessLaunchInfo::FileAction::eFileActionOpen)
+            stderr_path = file_action->GetPath();
+    }
+
+    m_monitor = new ProcessMonitor (this, 
+                                    module,
+                                    launch_info.GetArguments().GetConstArgumentVector(), 
+                                    launch_info.GetEnvironmentEntries().GetConstArgumentVector(),
+                                    stdin_path, 
+                                    stdout_path, 
+                                    stderr_path,
+                                    error);
 
     m_module = module;
 

Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h?rev=143772&r1=143771&r2=143772&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h Fri Nov  4 20:09:16 2011
@@ -67,14 +67,8 @@
     DoAttachToProcessWithID(lldb::pid_t pid);
 
     virtual lldb_private::Error
-    DoLaunch(lldb_private::Module *module,
-             char const *argv[],
-             char const *envp[],
-             uint32_t launch_flags,
-             const char *stdin_path,
-             const char *stdout_path,
-             const char *stderr_path,
-             const char *working_directory);
+    DoLaunch (lldb_private::Module *exe_module, 
+              const lldb_private::ProcessLaunchInfo &launch_info);
 
     virtual void
     DidLaunch();

Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp?rev=143772&r1=143771&r2=143772&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp Fri Nov  4 20:09:16 2011
@@ -34,6 +34,8 @@
 #include "ProcessMonitor.h"
 
 
+#define DEBUG_PTRACE_MAXBYTES 20
+
 using namespace lldb_private;
 
 // FIXME: this code is host-dependent with respect to types and
@@ -46,21 +48,91 @@
 // avoid the additional indirection and checks.
 #ifndef LLDB_CONFIGURATION_BUILDANDINTEGRATION
 
+static void
+DisplayBytes (lldb_private::StreamString &s, void *bytes, uint32_t count)
+{
+    uint8_t *ptr = (uint8_t *)bytes;
+    const uint32_t loop_count = std::min<uint32_t>(DEBUG_PTRACE_MAXBYTES, count);
+    for(uint32_t i=0; i<loop_count; i++)
+    {
+        s.Printf ("[%x]", *ptr);
+        ptr++;
+    }
+}
+
+static void PtraceDisplayBytes(__ptrace_request &req, void *data)
+{
+    StreamString buf;
+    LogSP verbose_log (ProcessLinuxLog::GetLogIfAllCategoriesSet (
+                                        LINUX_LOG_PTRACE | LINUX_LOG_VERBOSE));
+
+    if (verbose_log)
+    {
+        switch(req)
+        {
+        case PTRACE_POKETEXT:
+            {
+                DisplayBytes(buf, &data, 8);
+                verbose_log->Printf("PTRACE_POKETEXT %s", buf.GetData());
+                break;
+            }
+        case PTRACE_POKEDATA: 
+            {
+                DisplayBytes(buf, &data, 8);
+                verbose_log->Printf("PTRACE_POKEDATA %s", buf.GetData());
+                break;
+            }
+        case PTRACE_POKEUSER: 
+            {
+                DisplayBytes(buf, &data, 8);
+                verbose_log->Printf("PTRACE_POKEUSER %s", buf.GetData());
+                break;
+            }
+        case PTRACE_SETREGS: 
+            {
+                DisplayBytes(buf, data, sizeof(user_regs_struct));
+                verbose_log->Printf("PTRACE_SETREGS %s", buf.GetData());
+                break;
+            }
+        case PTRACE_SETFPREGS:
+            {
+                DisplayBytes(buf, data, sizeof(user_fpregs_struct));
+                verbose_log->Printf("PTRACE_SETFPREGS %s", buf.GetData());
+                break;
+            }
+        case PTRACE_SETSIGINFO: 
+            {
+                DisplayBytes(buf, data, sizeof(siginfo_t));
+                verbose_log->Printf("PTRACE_SETSIGINFO %s", buf.GetData());
+                break;
+            }
+        default:
+            {
+            }
+        }
+    }
+}
+
 // Wrapper for ptrace to catch errors and log calls.
 extern long
 PtraceWrapper(__ptrace_request req, pid_t pid, void *addr, void *data,
               const char* reqName, const char* file, int line)
 {
-    int result;
+    long int result;
 
     LogSP log (ProcessLinuxLog::GetLogIfAllCategoriesSet (LINUX_LOG_PTRACE));
+
     if (log)
         log->Printf("ptrace(%s, %u, %p, %p) called from file %s line %d",
                     reqName, pid, addr, data, file, line);
+    
+    PtraceDisplayBytes(req, data);
 
     errno = 0;
     result = ptrace(req, pid, addr, data);
 
+    PtraceDisplayBytes(req, data);
+
     if (log && (result == -1 || errno != 0))
     {
         const char* str;
@@ -352,7 +424,7 @@
 
     // Set errno to zero so that we can detect a failed peek.
     errno = 0;
-    uint32_t data = PTRACE(PTRACE_PEEKUSER, pid, (void*)m_offset, NULL);
+    lldb::addr_t data = PTRACE(PTRACE_PEEKUSER, pid, (void*)m_offset, NULL);
     if (data == -1UL && errno)
         m_result = false;
     else





More information about the lldb-commits mailing list