Cleaned up the Disassembler code a bit more. You can now request a disassembler
plugin by name on the command line for when there is more than one disassembler
plugin.

Taught the Opcode class to dump itself so that "disassembler -b" will dump
the bytes correctly for each opcode type. Modified all places that were passing
the opcode bytes buffer in so that the bytes could be displayed to just pass
in a bool that indicates if we should dump the opcode bytes since the opcode
now lives inside llvm_private::Instruction.




git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@128290 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp b/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
index 9835dea..9c55042 100644
--- a/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
+++ b/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
@@ -100,8 +100,7 @@
 (
     Stream *s,
     bool show_address,
-    const DataExtractor *bytes,
-    uint32_t bytes_offset,
+    bool show_bytes,
     const lldb_private::ExecutionContext* exe_ctx,
     bool raw
 )
@@ -125,18 +124,20 @@
     }
 
     // If we are supposed to show bytes, "bytes" will be non-NULL.
-    if (bytes)
+    if (show_bytes)
     {
-        uint32_t bytes_dumped = bytes->Dump(s, bytes_offset, eFormatBytes, 1, EDInstByteSize(m_inst), UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0) - bytes_offset;
-        // Allow for 15 bytes of opcodes since this is the max for x86_64.
-        // TOOD: We need to taylor this better for different architectures. For 
-        // ARM we would want to show 16 bit opcodes for Thumb as properly byte
-        // swapped uint16_t values, or 32 bit values swapped values for ARM.
-        const uint32_t default_num_opcode_bytes = 15;
-        if (bytes_dumped * 3 < (default_num_opcode_bytes*3))
+        if (m_opcode.GetType() == Opcode::eTypeBytes)
         {
-            uint32_t indent_level = (default_num_opcode_bytes*3) - (bytes_dumped * 3) + 1;
-            s->Printf("%*.*s", indent_level, indent_level, "");
+            // x86_64 and i386 are the only ones that use bytes right now so
+            // pad out the byte dump to be able to always show 15 bytes (3 chars each) 
+            // plus a space
+            m_opcode.Dump (s, 15 * 3 + 1);
+        }
+        else
+        {
+            // Else, we have ARM which can show up to a uint32_t 0x00000000 (10 spaces)
+            // plus two for padding...
+            m_opcode.Dump (s, 12);
         }
     }
 
@@ -328,12 +329,6 @@
 }
 
 size_t
-DisassemblerLLVM::InstructionLLVM::GetByteSize() const
-{
-    return EDInstByteSize(m_inst);
-}
-
-size_t
 DisassemblerLLVM::InstructionLLVM::Extract (const Disassembler &disassembler, 
                                             const lldb_private::DataExtractor &data,
                                             uint32_t data_offset)
@@ -351,16 +346,21 @@
             break;
 
         case llvm::Triple::arm:
-            assert (byte_size == 4);
-            m_opcode.SetOpcode32 (data.GetU32 (&offset));
-            break;
-
         case llvm::Triple::thumb:
-            assert ((byte_size == 2) || (byte_size == 4));
-            if (byte_size == 2)
-                m_opcode.SetOpcode16 (data.GetU16 (&offset));
-            else
+            switch (byte_size)
+            {
+            case 2: 
+                m_opcode.SetOpcode16 (data.GetU16 (&offset)); 
+                break;
+
+            case 4:
                 m_opcode.SetOpcode32 (data.GetU32 (&offset));
+                break;
+
+            default:
+                assert (!"Invalid ARM opcode size");
+                break;
+            }
             break;
 
         default:
@@ -497,13 +497,13 @@
 const char *
 DisassemblerLLVM::GetPluginNameStatic()
 {
-    return "disassembler.llvm";
+    return "llvm";
 }
 
 const char *
 DisassemblerLLVM::GetPluginDescriptionStatic()
 {
-    return "Disassembler that uses LLVM opcode tables to disassemble i386 and x86_64.";
+    return "Disassembler that uses LLVM opcode tables to disassemble i386, x86_64 and ARM.";
 }
 
 //------------------------------------------------------------------
diff --git a/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h b/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h
index 5ecda3e..9e01bf3 100644
--- a/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h
+++ b/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h
@@ -28,21 +28,17 @@
         virtual
         ~InstructionLLVM();
 
-        void
+        virtual void
         Dump (lldb_private::Stream *s,
               bool show_address,
-              const lldb_private::DataExtractor *bytes,
-              uint32_t bytes_offset,
+              bool show_bytes,
               const lldb_private::ExecutionContext* exe_ctx,
               bool raw);
 
-        bool
+        virtual bool
         DoesBranch () const;
 
-        size_t
-        GetByteSize() const;
-
-        size_t
+        virtual size_t
         Extract (const Disassembler &disassembler,
                  const lldb_private::DataExtractor &data,
                  uint32_t data_offset);