[Lldb-commits] [lldb] r201457 - Simplify core file register context handling

Ed Maste emaste at freebsd.org
Fri Feb 14 18:31:22 PST 2014


Author: emaste
Date: Fri Feb 14 20:31:22 2014
New Revision: 201457

URL: http://llvm.org/viewvc/llvm-project?rev=201457&view=rev
Log:
Simplify core file register context handling

This seems like a more straightforward approach for instantiating the
appropriate RegisterContext* class, made possible by Michael Sartain's
cleanup of the POSIX RegisterContext class hierarchy in r190647.

Better (user-facing) error handling is still needed.

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

Modified: lldb/trunk/source/Plugins/Process/elf-core/ThreadElfCore.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/elf-core/ThreadElfCore.cpp?rev=201457&r1=201456&r2=201457&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/elf-core/ThreadElfCore.cpp (original)
+++ lldb/trunk/source/Plugins/Process/elf-core/ThreadElfCore.cpp Fri Feb 14 20:31:22 2014
@@ -86,61 +86,66 @@ ThreadElfCore::CreateRegisterContextForF
 
         ProcessElfCore *process = static_cast<ProcessElfCore *>(GetProcess().get());
         ArchSpec arch = process->GetArchitecture();
-        switch (arch.GetMachine())
+        RegisterInfoInterface *reg_interface = NULL;
+
+        switch (arch.GetTriple().getOS())
         {
-            case llvm::Triple::mips64:
-                switch (arch.GetTriple().getOS())
+            case llvm::Triple::FreeBSD:
+            {
+                switch (arch.GetMachine())
                 {
-                    case llvm::Triple::FreeBSD:
-                        m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_mips64 (*this, new RegisterContextFreeBSD_mips64(arch), m_gpregset_data, m_fpregset_data));
+                    case llvm::Triple::mips64:
+                        reg_interface = new RegisterContextFreeBSD_mips64(arch);
+                        break;
+                    case llvm::Triple::x86:
+                        reg_interface = new RegisterContextFreeBSD_i386(arch);
+                        break;
+                    case llvm::Triple::x86_64:
+                        reg_interface = new RegisterContextFreeBSD_x86_64(arch);
                         break;
                     default:
-                        if (log)
-                            log->Printf ("elf-core::%s:: OS(%d) not supported",
-                                         __FUNCTION__, arch.GetTriple().getOS());
-                        assert (false && "OS not supported");
                         break;
                 }
                 break;
-
-            case llvm::Triple::x86:
-                switch (arch.GetTriple().getOS())
+            }
+ 
+            case llvm::Triple::Linux:
+            {
+                switch (arch.GetMachine())
                 {
-                    case llvm::Triple::FreeBSD:
-                        m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64 (*this, new RegisterContextFreeBSD_i386(arch), m_gpregset_data, m_fpregset_data));
+                    case llvm::Triple::x86_64:
+                        reg_interface = new RegisterContextLinux_x86_64(arch);
                         break;
                     default:
-                        if (log)
-                            log->Printf ("elf-core::%s:: OS(%d) not supported",
-                                         __FUNCTION__, arch.GetTriple().getOS());
-                        assert (false && "OS not supported");
                         break;
                 }
                 break;
+            }
+
+            default:
+                break;
+        }
+
+        if (!reg_interface) {
+            if (log)
+                log->Printf ("elf-core::%s:: Architecture(%d) or OS(%d) not supported",
+                             __FUNCTION__, arch.GetMachine(), arch.GetTriple().getOS());
+                assert (false && "Architecture or OS not supported");
+        }
 
+        switch (arch.GetMachine())
+        {
+            case llvm::Triple::mips64:
+                m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_mips64 (*this, reg_interface, m_gpregset_data, m_fpregset_data));
+                break;
+            case llvm::Triple::x86:
             case llvm::Triple::x86_64:
-                switch (arch.GetTriple().getOS())
-                {
-                    case llvm::Triple::FreeBSD:
-                        m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64 (*this, new RegisterContextFreeBSD_x86_64(arch), m_gpregset_data, m_fpregset_data));
-                        break;
-                    case llvm::Triple::Linux:
-                        m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64 (*this, new RegisterContextLinux_x86_64(arch), m_gpregset_data, m_fpregset_data));
-                        break;
-                    default:
-                        if (log)
-                            log->Printf ("elf-core::%s:: OS(%d) not supported",
-                                         __FUNCTION__, arch.GetTriple().getOS());
-                        assert (false && "OS not supported");
-                        break;
-                }
+                m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64 (*this, reg_interface, m_gpregset_data, m_fpregset_data));
                 break;
             default:
-                if (log)
-                    log->Printf ("elf-core::%s:: Architecture(%d) not supported",
-                                 __FUNCTION__, arch.GetMachine());
-                assert (false && "Architecture not supported");
+                break;
         }
+
         reg_ctx_sp = m_thread_reg_ctx_sp;
     }
     else if (m_unwinder_ap.get())





More information about the lldb-commits mailing list