[Lldb-commits] [lldb] r156532 - in /lldb/trunk: include/lldb/Core/ lldb.xcodeproj/xcshareddata/xcschemes/ source/API/ source/Core/ source/Expression/ source/Plugins/Disassembler/llvm/ source/Plugins/UnwindAssembly/InstEmulation/ source/Symbol/ source/Target/

Greg Clayton gclayton at apple.com
Wed May 9 19:52:24 PDT 2012


Author: gclayton
Date: Wed May  9 21:52:23 2012
New Revision: 156532

URL: http://llvm.org/viewvc/llvm-project?rev=156532&view=rev
Log:
<rdar://problem/11330621>

Fixed the DisassemblerLLVMC disassembler to parse more efficiently instead of parsing opcodes over and over. The InstructionLLVMC class now only reads the opcode in the InstructionLLVMC::Decode function. This can be done very efficiently for ARM and architectures that have fixed opcode sizes. For x64 it still calls the disassembler to get the byte size.

Moved the lldb_private::Instruction::Dump(...) function up into the lldb_private::Instruction class and it now uses the function that gets the mnemonic, operandes and comments so that all disassembly is using the same code.

Added StreamString::FillLastLineToColumn() to allow filling a line up to a column with a character (which is used by the lldb_private::Instruction::Dump(...) function).

Modified the Opcode::GetData() fucntion to "do the right thing" for thumb instructions.


Modified:
    lldb/trunk/include/lldb/Core/Disassembler.h
    lldb/trunk/include/lldb/Core/Opcode.h
    lldb/trunk/include/lldb/Core/StreamString.h
    lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme
    lldb/trunk/source/API/SBInstruction.cpp
    lldb/trunk/source/API/SBInstructionList.cpp
    lldb/trunk/source/Core/Disassembler.cpp
    lldb/trunk/source/Core/Opcode.cpp
    lldb/trunk/source/Core/StreamString.cpp
    lldb/trunk/source/Expression/ClangExpressionParser.cpp
    lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
    lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h
    lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
    lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h
    lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
    lldb/trunk/source/Symbol/SymbolContext.cpp
    lldb/trunk/source/Target/ThreadPlanTracer.cpp

Modified: lldb/trunk/include/lldb/Core/Disassembler.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Disassembler.h?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Disassembler.h (original)
+++ lldb/trunk/include/lldb/Core/Disassembler.h Wed May  9 21:52:23 2012
@@ -42,27 +42,27 @@
     }
     
     const char *
-    GetMnemonic (ExecutionContextScope *exe_scope)
+    GetMnemonic (const ExecutionContext* exe_ctx)
     {
-        CalculateMnemonicOperandsAndCommentIfNeeded (exe_scope);
+        CalculateMnemonicOperandsAndCommentIfNeeded (exe_ctx);
         return m_opcode_name.c_str();
     }
     const char *
-    GetOperands (ExecutionContextScope *exe_scope)
+    GetOperands (const ExecutionContext* exe_ctx)
     {
-        CalculateMnemonicOperandsAndCommentIfNeeded (exe_scope);
+        CalculateMnemonicOperandsAndCommentIfNeeded (exe_ctx);
         return m_mnemocics.c_str();
     }
     
     const char *
-    GetComment (ExecutionContextScope *exe_scope)
+    GetComment (const ExecutionContext* exe_ctx)
     {
-        CalculateMnemonicOperandsAndCommentIfNeeded (exe_scope);
+        CalculateMnemonicOperandsAndCommentIfNeeded (exe_ctx);
         return m_comment.c_str();
     }
 
     virtual void
-    CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe_scope) = 0;
+    CalculateMnemonicOperandsAndComment (const ExecutionContext* exe_ctx) = 0;
     
     lldb::AddressClass
     GetAddressClass ();
@@ -81,8 +81,7 @@
           uint32_t max_opcode_byte_size,
           bool show_address,
           bool show_bytes,
-          const ExecutionContext *exe_ctx, 
-          bool raw) = 0;
+          const ExecutionContext* exe_ctx);
     
     virtual bool
     DoesBranch () const = 0;
@@ -121,6 +120,9 @@
     {
         return m_opcode;
     }
+    
+    uint32_t
+    GetData (DataExtractor &data);
 
 protected:
     Address m_address; // The section offset address of this instruction
@@ -130,7 +132,9 @@
     // The usual value will be eAddressClassCode, but often when
     // disassembling memory, you might run into data. This can
     // help us to disassemble appropriately.
-    lldb::AddressClass m_address_class;
+private:
+    lldb::AddressClass m_address_class; // Use GetAddressClass () accessor function!
+protected:
     Opcode m_opcode; // The opcode for this instruction
     std::string m_opcode_name;
     std::string m_mnemocics;
@@ -138,12 +142,12 @@
     bool m_calculated_strings;
 
     void
-    CalculateMnemonicOperandsAndCommentIfNeeded (ExecutionContextScope *exe_scope)
+    CalculateMnemonicOperandsAndCommentIfNeeded (const ExecutionContext* exe_ctx)
     {
         if (!m_calculated_strings)
         {
             m_calculated_strings = true;
-            CalculateMnemonicOperandsAndComment(exe_scope);
+            CalculateMnemonicOperandsAndComment(exe_ctx);
         }
     }
 };
@@ -200,19 +204,11 @@
      virtual
      ~PseudoInstruction ();
      
-    virtual void
-    Dump (Stream *s,
-          uint32_t max_opcode_byte_size,
-          bool show_address,
-          bool show_bytes,
-          const ExecutionContext* exe_ctx,
-          bool raw);
-    
     virtual bool
     DoesBranch () const;
 
     virtual void
-    CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe_scope)
+    CalculateMnemonicOperandsAndComment (const ExecutionContext* exe_ctx)
     {
         // TODO: fill this in and put opcode name into Instruction::m_opcode_name,
         // mnemonic into Instruction::m_mnemonics, and any comment into 

Modified: lldb/trunk/include/lldb/Core/Opcode.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Opcode.h?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Opcode.h (original)
+++ lldb/trunk/include/lldb/Core/Opcode.h Wed May  9 21:52:23 2012
@@ -67,6 +67,11 @@
             SetOpcodeBytes (bytes, length);
         }
 
+        void
+        Clear()
+        {
+            m_type = Opcode::eTypeInvalid;
+        }
         Opcode::Type
         GetType () const
         {
@@ -205,9 +210,10 @@
             return 0;
         }
         
+        // Get the opcode exactly as it would be laid out in memory.
         uint32_t
-        GetData (DataExtractor &data) const;
-
+        GetData (DataExtractor &data,
+                 lldb::AddressClass address_class) const;
 
     protected:
 
@@ -240,8 +246,8 @@
             uint64_t inst64;
             struct 
             {
-                uint8_t length;
                 uint8_t bytes[16]; // This must be big enough to handle any opcode for any supported target.
+                uint8_t length;
             } inst;
         } m_data;
     };

Modified: lldb/trunk/include/lldb/Core/StreamString.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/StreamString.h?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/StreamString.h (original)
+++ lldb/trunk/include/lldb/Core/StreamString.h Wed May  9 21:52:23 2012
@@ -49,6 +49,9 @@
     const std::string &
     GetString() const;
 
+    void
+    FillLastLineToColumn (uint32_t column, char fill_char);
+
 protected:
     std::string m_packet;
 

Modified: lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme (original)
+++ lldb/trunk/lldb.xcodeproj/xcshareddata/xcschemes/lldb-tool.xcscheme Wed May  9 21:52:23 2012
@@ -106,8 +106,8 @@
             isEnabled = "NO">
          </CommandLineArgument>
          <CommandLineArgument
-            argument = "/Volumes/work/gclayton/Documents/devb/attach/a.out"
-            isEnabled = "NO">
+            argument = "~/Documents/src/args/a.out"
+            isEnabled = "YES">
          </CommandLineArgument>
          <CommandLineArgument
             argument = "/bin/cat"

Modified: lldb/trunk/source/API/SBInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstruction.cpp?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/API/SBInstruction.cpp (original)
+++ lldb/trunk/source/API/SBInstruction.cpp Wed May  9 21:52:23 2012
@@ -82,7 +82,7 @@
             target_sp->CalculateExecutionContext (exe_ctx);
             exe_ctx.SetProcessSP(target_sp->GetProcessSP());
         }
-        return m_opaque_sp->GetMnemonic(exe_ctx.GetBestExecutionContextScope());
+        return m_opaque_sp->GetMnemonic(&exe_ctx);
     }
     return NULL;
 }
@@ -101,7 +101,7 @@
             target_sp->CalculateExecutionContext (exe_ctx);
             exe_ctx.SetProcessSP(target_sp->GetProcessSP());
         }
-        return m_opaque_sp->GetOperands(exe_ctx.GetBestExecutionContextScope());
+        return m_opaque_sp->GetOperands(&exe_ctx);
     }
     return NULL;
 }
@@ -120,7 +120,7 @@
             target_sp->CalculateExecutionContext (exe_ctx);
             exe_ctx.SetProcessSP(target_sp->GetProcessSP());
         }
-        return m_opaque_sp->GetComment(exe_ctx.GetBestExecutionContextScope());
+        return m_opaque_sp->GetComment(&exe_ctx);
     }
     return NULL;
 }
@@ -140,7 +140,7 @@
     if (m_opaque_sp)
     {
         DataExtractorSP data_extractor_sp (new DataExtractor());
-        if (m_opaque_sp->GetOpcode().GetData (*data_extractor_sp))
+        if (m_opaque_sp->GetData (*data_extractor_sp))
         {
             sb_data.SetOpaque (data_extractor_sp);
         }
@@ -171,7 +171,7 @@
     {
         // Use the "ref()" instead of the "get()" accessor in case the SBStream 
         // didn't have a stream already created, one will get created...
-        m_opaque_sp->Dump (&s.ref(), 0, true, false, NULL, false);
+        m_opaque_sp->Dump (&s.ref(), 0, true, false, NULL);
         return true;
     }
     return false;
@@ -186,7 +186,7 @@
     if (m_opaque_sp)
     {
         StreamFile out_stream (out, false);
-        m_opaque_sp->Dump (&out_stream, 0, true, false, NULL, false);
+        m_opaque_sp->Dump (&out_stream, 0, true, false, NULL);
     }
 }
 

Modified: lldb/trunk/source/API/SBInstructionList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBInstructionList.cpp?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/API/SBInstructionList.cpp (original)
+++ lldb/trunk/source/API/SBInstructionList.cpp Wed May  9 21:52:23 2012
@@ -105,7 +105,7 @@
                 Instruction *inst = m_opaque_sp->GetInstructionList().GetInstructionAtIndex (i).get();
                 if (inst == NULL)
                     break;
-                inst->Dump (&sref, max_opcode_byte_size, true, false, NULL, false);
+                inst->Dump (&sref, max_opcode_byte_size, true, false, NULL);
                 sref.EOL();
             }
             return true;

Modified: lldb/trunk/source/Core/Disassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Disassembler.cpp?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/Core/Disassembler.cpp (original)
+++ lldb/trunk/source/Core/Disassembler.cpp Wed May  9 21:52:23 2012
@@ -448,8 +448,7 @@
                 strm.PutCString(inst_is_at_pc ? "-> " : "   ");
             }
             const bool show_bytes = (options & eOptionShowBytes) != 0;
-            const bool raw = (options & eOptionRawOuput) != 0;
-            inst->Dump(&strm, max_opcode_byte_size, true, show_bytes, &exe_ctx, raw);
+            inst->Dump(&strm, max_opcode_byte_size, true, show_bytes, &exe_ctx);
             strm.EOL();            
         }
         else
@@ -529,6 +528,69 @@
     return m_address_class;
 }
 
+void
+Instruction::Dump (lldb_private::Stream *s,
+                   uint32_t max_opcode_byte_size,
+                   bool show_address,
+                   bool show_bytes,
+                   const ExecutionContext* exe_ctx)
+{
+    const size_t opcode_column_width = 7;
+    const size_t operand_column_width = 25;
+    
+    CalculateMnemonicOperandsAndCommentIfNeeded (exe_ctx);
+
+    StreamString ss;
+    
+    if (show_address)
+    {
+        m_address.Dump(&ss,
+                       exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL,
+                       Address::DumpStyleLoadAddress,
+                       Address::DumpStyleModuleWithFileAddress,
+                       0);
+        
+        ss.PutCString(":  ");
+    }
+    
+    if (show_bytes)
+    {
+        if (m_opcode.GetType() == Opcode::eTypeBytes)
+        {
+            // 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
+            if (max_opcode_byte_size > 0)
+                m_opcode.Dump (&ss, max_opcode_byte_size * 3 + 1);
+            else
+                m_opcode.Dump (&ss, 15 * 3 + 1);
+        }
+        else
+        {
+            // Else, we have ARM which can show up to a uint32_t 0x00000000 (10 spaces)
+            // plus two for padding...
+            if (max_opcode_byte_size > 0)
+                m_opcode.Dump (&ss, max_opcode_byte_size * 3 + 1);
+            else
+                m_opcode.Dump (&ss, 12);
+        }        
+    }
+    
+    const size_t opcode_pos = ss.GetSize();
+    
+    ss.PutCString (m_opcode_name.c_str());
+    ss.FillLastLineToColumn (opcode_pos + opcode_column_width, ' ');
+    ss.PutCString (m_mnemocics.c_str());
+    
+    if (!m_comment.empty())
+    {
+        ss.FillLastLineToColumn (opcode_pos + opcode_column_width + operand_column_width, ' ');        
+        ss.PutCString (" ; ");
+        ss.PutCString (m_comment.c_str());
+    }
+    s->Write (ss.GetData(), ss.GetSize());
+}
+
 bool
 Instruction::DumpEmulation (const ArchSpec &arch)
 {
@@ -828,6 +890,13 @@
     return false;
 }
 
+
+uint32_t
+Instruction::GetData (DataExtractor &data)
+{
+    return m_opcode.GetData(data, GetAddressClass ());
+}
+
 InstructionList::InstructionList() :
     m_instructions()
 {
@@ -884,7 +953,7 @@
     {
         if (pos != begin)
             s->EOL();
-        (*pos)->Dump(s, max_opcode_byte_size, show_address, show_bytes, exe_ctx, false);
+        (*pos)->Dump(s, max_opcode_byte_size, show_address, show_bytes, exe_ctx);
     }
 }
 
@@ -1065,27 +1134,6 @@
 {
 }
      
-void
-PseudoInstruction::Dump (lldb_private::Stream *s,
-                        uint32_t max_opcode_byte_size,
-                        bool show_address,
-                        bool show_bytes,
-                        const lldb_private::ExecutionContext* exe_ctx,
-                        bool raw)
-{
-    if (!s)
-        return;
-        
-    if (show_bytes)
-        m_opcode.Dump (s, max_opcode_byte_size);
-    
-    if (m_description.size() > 0)
-        s->Printf ("%s", m_description.c_str());
-    else
-        s->Printf ("<unknown>");
-        
-}
-    
 bool
 PseudoInstruction::DoesBranch () const
 {

Modified: lldb/trunk/source/Core/Opcode.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Opcode.cpp?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/Core/Opcode.cpp (original)
+++ lldb/trunk/source/Core/Opcode.cpp Wed May  9 21:52:23 2012
@@ -1,4 +1,4 @@
-//===-- Baton.cpp -----------------------------------------------*- C++ -*-===//
+//===-- Opcode.cpp ----------------------------------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -12,12 +12,15 @@
 // C Includes
 // C++ Includes
 // Other libraries and framework includes
+#include "llvm/ADT/Triple.h"
 // Project includes
+#include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/DataBufferHeap.h"
 #include "lldb/Core/DataExtractor.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Host/Endian.h"
 
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -82,9 +85,10 @@
 }
 
 uint32_t
-Opcode::GetData (DataExtractor &data) const
+Opcode::GetData (DataExtractor &data, lldb::AddressClass address_class) const
 {
     uint32_t byte_size = GetByteSize ();
+    
     DataBufferSP buffer_sp;
     if (byte_size > 0)
     {
@@ -95,7 +99,27 @@
                 
             case Opcode::eType8:    buffer_sp.reset (new DataBufferHeap (&m_data.inst8,  byte_size)); break;
             case Opcode::eType16:   buffer_sp.reset (new DataBufferHeap (&m_data.inst16, byte_size)); break;
-            case Opcode::eType32:   buffer_sp.reset (new DataBufferHeap (&m_data.inst32, byte_size)); break;
+            case Opcode::eType32:
+                {
+                    // The only thing that uses eAddressClassCodeAlternateISA currently
+                    // is Thumb. If this ever changes, we will need to pass in more
+                    // information like an additional "const ArchSpec &arch". For now
+                    // this will do
+                    if (address_class == eAddressClassCodeAlternateISA)
+                    {
+                        // 32 bit thumb instruction, we need to sizzle this a bit
+                        uint8_t buf[4];
+                        buf[0] = m_data.inst.bytes[2];
+                        buf[1] = m_data.inst.bytes[3];
+                        buf[2] = m_data.inst.bytes[0];
+                        buf[3] = m_data.inst.bytes[1];
+                        buffer_sp.reset (new DataBufferHeap (buf, byte_size));
+                        break;
+                    }
+                    buffer_sp.reset (new DataBufferHeap (&m_data.inst32, byte_size));
+                }
+                break;
+
             case Opcode::eType64:   buffer_sp.reset (new DataBufferHeap (&m_data.inst64, byte_size)); break;
             case Opcode::eTypeBytes:buffer_sp.reset (new DataBufferHeap (GetOpcodeBytes(), byte_size)); break;
                 break;

Modified: lldb/trunk/source/Core/StreamString.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StreamString.cpp?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/Core/StreamString.cpp (original)
+++ lldb/trunk/source/Core/StreamString.cpp Wed May  9 21:52:23 2012
@@ -71,3 +71,24 @@
     return m_packet;
 }
 
+void
+StreamString::FillLastLineToColumn (uint32_t column, char fill_char)
+{
+    const size_t length = m_packet.size();
+    size_t last_line_begin_pos = m_packet.find_last_of("\r\n");
+    if (last_line_begin_pos == std::string::npos)
+    {
+        last_line_begin_pos = 0;
+    }
+    else
+    {
+        ++last_line_begin_pos;
+    }
+    
+    const size_t line_columns = length - last_line_begin_pos;
+    if (column > line_columns)
+    {
+        m_packet.append(column - line_columns, fill_char);
+    }
+}
+

Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Wed May  9 21:52:23 2012
@@ -793,8 +793,7 @@
                            max_opcode_byte_size,
                            true,
                            true,
-                           &exe_ctx, 
-                           true);
+                           &exe_ctx);
         stream.PutChar('\n');
     }
     

Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp Wed May  9 21:52:23 2012
@@ -165,285 +165,9 @@
 }
 
 #define AlignPC(pc_val) (pc_val & 0xFFFFFFFC)
-void
-InstructionLLVM::Dump
-(
-    Stream *s,
-    uint32_t max_opcode_byte_size,
-    bool show_address,
-    bool show_bytes,
-    const ExecutionContext* exe_ctx,
-    bool raw
-)
-{
-    const size_t opcodeColumnWidth = 7;
-    const size_t operandColumnWidth = 25;
-
-    ExecutionContextScope *exe_scope = NULL;
-    if (exe_ctx)
-        exe_scope = exe_ctx->GetBestExecutionContextScope();
-
-    // If we have an address, print it out
-    if (GetAddress().IsValid() && show_address)
-    {
-        if (GetAddress().Dump (s, 
-                               exe_scope, 
-                               Address::DumpStyleLoadAddress, 
-                               Address::DumpStyleModuleWithFileAddress,
-                               0))
-            s->PutCString(":  ");
-    }
-
-    // If we are supposed to show bytes, "bytes" will be non-NULL.
-    if (show_bytes)
-    {
-        if (m_opcode.GetType() == Opcode::eTypeBytes)
-        {
-            // 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
-            if (max_opcode_byte_size > 0)
-                m_opcode.Dump (s, max_opcode_byte_size * 3 + 1);
-            else
-                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...
-            if (max_opcode_byte_size > 0)
-                m_opcode.Dump (s, max_opcode_byte_size * 3 + 1);
-            else
-                m_opcode.Dump (s, 12);
-        }
-    }
-
-    int numTokens = -1;
-    
-    // FIXME!!!
-    /* Remove the following section of code related to force_raw .... */
-    /*
-    bool force_raw = m_arch_type == llvm::Triple::arm ||
-                     m_arch_type == llvm::Triple::thumb;
-    if (!raw)
-        raw = force_raw;
-    */
-    /* .... when we fix the edis for arm/thumb. */
-
-    if (!raw)
-        numTokens = EDNumTokens(m_inst);
-
-    int currentOpIndex = -1;
-
-    bool printTokenized = false;
-
-    if (numTokens != -1 && !raw)
-    {
-        addr_t base_addr = LLDB_INVALID_ADDRESS;
-        uint32_t addr_nibble_size = 8;
-        Target *target = NULL;
-        if (exe_ctx)
-            target = exe_ctx->GetTargetPtr();
-        if (target)
-        {
-            if (!target->GetSectionLoadList().IsEmpty())
-                base_addr = GetAddress().GetLoadAddress (target);
-            addr_nibble_size = target->GetArchitecture().GetAddressByteSize() * 2;
-        }
-        if (base_addr == LLDB_INVALID_ADDRESS)
-            base_addr = GetAddress().GetFileAddress ();
-                    
-        lldb::addr_t PC = base_addr + EDInstByteSize(m_inst);
-
-        // When executing an ARM instruction, PC reads as the address of the
-        // current instruction plus 8.  And for Thumb, it is plus 4.
-        if (m_arch_type == llvm::Triple::arm)
-          PC = base_addr + 8;
-        else if (m_arch_type == llvm::Triple::thumb)
-          PC = base_addr + 4;
-
-        RegisterReaderArg rra(PC, m_disassembler);
-        
-        printTokenized = true;
-
-        // Handle the opcode column.
-
-        StreamString opcode;
-
-        int tokenIndex = 0;
-
-        EDTokenRef token;
-        const char *tokenStr;
-
-        if (EDGetToken(&token, m_inst, tokenIndex)) // 0 on success
-            printTokenized = false;
-        else if (!EDTokenIsOpcode(token))
-            printTokenized = false;
-        else if (EDGetTokenString(&tokenStr, token)) // 0 on success
-            printTokenized = false;
-
-        if (printTokenized)
-        {
-            // Put the token string into our opcode string
-            opcode.PutCString(tokenStr);
-
-            // If anything follows, it probably starts with some whitespace.  Skip it.
-            if (++tokenIndex < numTokens)
-            {
-                if (EDGetToken(&token, m_inst, tokenIndex)) // 0 on success
-                    printTokenized = false;
-                else if (!EDTokenIsWhitespace(token))
-                    printTokenized = false;
-            }
-
-            ++tokenIndex;
-        }
-
-        // Handle the operands and the comment.
-        StreamString operands;
-        StreamString comment;
-
-        if (printTokenized)
-        {
-            bool show_token = false;
-
-            for (; tokenIndex < numTokens; ++tokenIndex)
-            {
-                if (EDGetToken(&token, m_inst, tokenIndex))
-                    return;
-
-                int operandIndex = EDOperandIndexForToken(token);
-
-                if (operandIndex >= 0)
-                {
-                    if (operandIndex != currentOpIndex)
-                    {
-                        show_token = true;
-
-                        currentOpIndex = operandIndex;
-                        EDOperandRef operand;
-
-                        if (!EDGetOperand(&operand, m_inst, currentOpIndex))
-                        {
-                            if (EDOperandIsMemory(operand))
-                            {
-                                uint64_t operand_value;
-
-                                if (!EDEvaluateOperand(&operand_value, operand, IPRegisterReader, &rra))
-                                {
-                                    if (EDInstIsBranch(m_inst))
-                                    {
-                                        operands.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);
-                                        show_token = false;
-                                    }
-                                    else
-                                    {
-                                        // Put the address value into the comment
-                                        comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);
-                                    }
-
-                                    AddSymbolicInfo(exe_ctx, comment, operand_value, GetAddress());
-                                } // EDEvaluateOperand
-                            } // EDOperandIsMemory
-                        } // EDGetOperand
-                    } // operandIndex != currentOpIndex
-                } // operandIndex >= 0
-
-                if (show_token)
-                {
-                    if (EDGetTokenString(&tokenStr, token))
-                    {
-                        printTokenized = false;
-                        break;
-                    }
-
-                    operands.PutCString(tokenStr);
-                }
-            } // for (tokenIndex)
-
-            // FIXME!!!
-            // Workaround for llvm::tB's operands not properly parsed by ARMAsmParser.
-            if (m_arch_type == llvm::Triple::thumb && opcode.GetString() == "b") {
-                const char *inst_str;
-                const char *pos = NULL;
-                operands.Clear(); comment.Clear();
-                if (EDGetInstString(&inst_str, m_inst) == 0 && (pos = strstr(inst_str, "#")) != NULL) {
-                    uint64_t operand_value = PC + atoi(++pos);
-                    // Put the address value into the operands.
-                    operands.Printf("0x%8.8llx ", operand_value);
-                    AddSymbolicInfo(exe_ctx, comment, operand_value, GetAddress());
-                }
-            }
-            // Yet more workaround for "bl #..." and "blx #...".
-            if ((m_arch_type == llvm::Triple::arm || m_arch_type == llvm::Triple::thumb) &&
-                (opcode.GetString() == "bl" || opcode.GetString() == "blx")) {
-                const char *inst_str;
-                const char *pos = NULL;
-                operands.Clear(); comment.Clear();
-                if (EDGetInstString(&inst_str, m_inst) == 0 && (pos = strstr(inst_str, "#")) != NULL) {
-                    if (m_arch_type == llvm::Triple::thumb && opcode.GetString() == "blx") {
-                        // A8.6.23 BLX (immediate)
-                        // Target Address = Align(PC,4) + offset value
-                        PC = AlignPC(PC);
-                    }
-                    uint64_t operand_value = PC + atoi(++pos);
-                    // Put the address value into the comment.
-                    comment.Printf("0x%8.8llx ", operand_value);
-                    // And the original token string into the operands.
-                    llvm::StringRef Str(pos - 1);
-                    RStrip(Str, '\n');
-                    operands.PutCString(Str.str().c_str());
-                    AddSymbolicInfo(exe_ctx, comment, operand_value, GetAddress());
-                }
-            }
-            // END of workaround.
-
-            // If both operands and comment are empty, we will just print out
-            // the raw disassembly.
-            if (operands.GetString().empty() && comment.GetString().empty())
-            {
-                const char *str;
-
-                if (EDGetInstString(&str, m_inst))
-                    return;
-                Align(s, str, opcodeColumnWidth, operandColumnWidth);
-            }
-            else
-            {
-                PadString(s, opcode.GetString(), opcodeColumnWidth);
-
-                if (comment.GetString().empty())
-                    s->PutCString(operands.GetString().c_str());
-                else
-                {
-                    PadString(s, operands.GetString(), operandColumnWidth);
-
-                    s->PutCString("; ");
-                    s->PutCString(comment.GetString().c_str());
-                } // else (comment.GetString().empty())
-            } // else (operands.GetString().empty() && comment.GetString().empty())
-        } // printTokenized
-    } // numTokens != -1
-
-    if (!printTokenized)
-    {
-        const char *str;
-
-        if (EDGetInstString(&str, m_inst)) // 0 on success
-            return;
-        if (raw)
-          s->Write(str, strlen(str) - 1);
-        else
-        {
-            // EDis fails to parse the tokens of this inst.  Need to align this
-            // raw disassembly's opcode with the rest of output.
-            Align(s, str, opcodeColumnWidth, operandColumnWidth);
-        }
-    }
-}
 
 void
-InstructionLLVM::CalculateMnemonicOperandsAndComment (ExecutionContextScope *exe_scope)
+InstructionLLVM::CalculateMnemonicOperandsAndComment (const ExecutionContext* exe_ctx)
 {
     const int num_tokens = EDNumTokens(m_inst);
     if (num_tokens > 0)
@@ -453,8 +177,7 @@
         StreamString comment;
         uint32_t addr_nibble_size = 8;
         addr_t base_addr = LLDB_INVALID_ADDRESS;
-        ExecutionContext exe_ctx (exe_scope);
-        Target *target = exe_ctx.GetTargetPtr();
+        Target *target = exe_ctx ? exe_ctx->GetTargetPtr() : NULL;
         if (target && !target->GetSectionLoadList().IsEmpty())
             base_addr = GetAddress().GetLoadAddress (target);
         if (base_addr == LLDB_INVALID_ADDRESS)
@@ -506,7 +229,7 @@
                                 if (!EDEvaluateOperand(&operand_value, operand, IPRegisterReader, &rra))
                                 {
                                     comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);                                    
-                                    AddSymbolicInfo (&exe_ctx, comment, operand_value, GetAddress());
+                                    AddSymbolicInfo (exe_ctx, comment, operand_value, GetAddress());
                                 }
                             }
                         }
@@ -531,7 +254,7 @@
                 uint64_t operand_value = PC + atoi(++pos);
                 // Put the address value into the operands.
                 comment.Printf("0x%*.*llx ", addr_nibble_size, addr_nibble_size, operand_value);
-                AddSymbolicInfo (&exe_ctx, comment, operand_value, GetAddress());
+                AddSymbolicInfo (exe_ctx, comment, operand_value, GetAddress());
             }
         }
         // Yet more workaround for "bl #..." and "blx #...".
@@ -556,7 +279,7 @@
 //                llvm::StringRef Str(pos - 1);
 //                RStrip(Str, '\n');
 //                operands.PutCString(Str.str().c_str());
-                AddSymbolicInfo (&exe_ctx, comment, operand_value, GetAddress());
+                AddSymbolicInfo (exe_ctx, comment, operand_value, GetAddress());
             }
         }
         // END of workaround.

Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.h Wed May  9 21:52:23 2012
@@ -27,14 +27,6 @@
     virtual
     ~InstructionLLVM();
     
-    virtual void
-    Dump (lldb_private::Stream *s,
-          uint32_t max_opcode_byte_size,
-          bool show_address,
-          bool show_bytes,
-          const lldb_private::ExecutionContext* exe_ctx,
-          bool raw);
-    
     virtual bool
     DoesBranch () const;
     
@@ -44,7 +36,7 @@
             uint32_t data_offset);
     
     virtual void
-    CalculateMnemonicOperandsAndComment (lldb_private::ExecutionContextScope *exe_scope);
+    CalculateMnemonicOperandsAndComment (const lldb_private::ExecutionContext* exe_ctx);
     
 protected:
     EDDisassemblerRef m_disassembler;

Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp Wed May  9 21:52:23 2012
@@ -36,8 +36,6 @@
         Instruction(address, addr_class),
         m_is_valid(false),
         m_disasm(disasm),
-        m_no_comments(true),
-        m_comment_stream(),
         m_does_branch(eLazyBoolCalculate)
     {
     }
@@ -58,137 +56,266 @@
             ss.Printf("%*s", new_width - old_width, "");
         }
     }
-    
-    virtual void
-    Dump (lldb_private::Stream *s,
-          uint32_t max_opcode_byte_size,
-          bool show_address,
-          bool show_bytes,
-          const lldb_private::ExecutionContext* exe_ctx,
-          bool raw)
-    {
-        const size_t opcode_column_width = 7;
-        const size_t operand_column_width = 25;
-             
-        StreamString ss;
         
-        ExecutionContextScope *exe_scope = NULL;
+    virtual bool
+    DoesBranch () const
+    {
+        return m_does_branch == eLazyBoolYes;
+    }
+    
+    virtual size_t
+    Decode (const lldb_private::Disassembler &disassembler,
+            const lldb_private::DataExtractor &data,
+            uint32_t data_offset)
+    {
+        // All we have to do is read the opcode which can be easy for some
+        // architetures
+        bool got_op = false;
+        const ArchSpec &arch = m_disasm.GetArchitecture();
         
-        if ((!raw) && exe_ctx)
+        const uint32_t min_op_byte_size = arch.GetMinimumOpcodeByteSize();
+        const uint32_t max_op_byte_size = arch.GetMaximumOpcodeByteSize();
+        if (min_op_byte_size == max_op_byte_size)
         {
-            exe_scope = exe_ctx->GetBestExecutionContextScope();
+            // Fixed size instructions, just read that amount of data.
+            if (!data.ValidOffsetForDataOfSize(data_offset, min_op_byte_size))
+                return false;
+            
+            switch (min_op_byte_size)
+            {
+                case 1:
+                    m_opcode.SetOpcode8  (data.GetU8  (&data_offset));
+                    got_op = true;
+                    break;
+
+                case 2:
+                    m_opcode.SetOpcode16 (data.GetU16 (&data_offset));
+                    got_op = true;
+                    break;
+
+                case 4:
+                    m_opcode.SetOpcode32 (data.GetU32 (&data_offset));
+                    got_op = true;
+                    break;
+
+                case 8:
+                    m_opcode.SetOpcode64 (data.GetU64 (&data_offset));
+                    got_op = true;
+                    break;
 
-            DataExtractor extractor(m_raw_bytes.data(),
-                                    m_raw_bytes.size(),
-                                    m_disasm.GetArchitecture().GetByteOrder(),
-                                    m_disasm.GetArchitecture().GetAddressByteSize());
-            
-            Parse <true> (m_address,
-                          m_address_class,
-                          extractor,
-                          0,
-                          exe_scope);
+                default:
+                    m_opcode.SetOpcodeBytes(data.PeekData(data_offset, min_op_byte_size), min_op_byte_size);
+                    got_op = true;
+                    break;
+            }
         }
-        
-        if (show_address)
+        if (!got_op)
         {
-            m_address.Dump(&ss,
-                           exe_scope,
-                           Address::DumpStyleLoadAddress,
-                           Address::DumpStyleModuleWithFileAddress,
-                           0);
+            ::LLVMDisasmContextRef disasm_context = m_disasm.m_disasm_context;
             
-            ss.PutCString(":  ");
-        }
-        
-        if (show_bytes)
-        {
-            if (m_opcode.GetType() == Opcode::eTypeBytes)
+            bool is_altnernate_isa = false;
+            if (m_disasm.m_alternate_disasm_context)
+            {
+                const AddressClass address_class = GetAddressClass ();
+            
+                if (address_class == eAddressClassCodeAlternateISA)
+                {
+                    disasm_context = m_disasm.m_alternate_disasm_context;
+                    is_altnernate_isa = true;
+                }
+            }
+            const llvm::Triple::ArchType machine = arch.GetMachine();
+            if (machine == llvm::Triple::arm || machine == llvm::Triple::thumb)
             {
-                // 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
-                if (max_opcode_byte_size > 0)
-                    m_opcode.Dump (&ss, max_opcode_byte_size * 3 + 1);
+                if (machine == llvm::Triple::thumb || is_altnernate_isa)
+                {
+                    uint32_t thumb_opcode = data.GetU16(&data_offset);
+                    if ((thumb_opcode & 0xe000) != 0xe000 || ((thumb_opcode & 0x1800u) == 0))
+                    {
+                        m_opcode.SetOpcode16 (thumb_opcode);
+                    }
+                    else
+                    {
+                        thumb_opcode <<= 16;
+                        thumb_opcode |= data.GetU16(&data_offset);
+                        m_opcode.SetOpcode32 (thumb_opcode);
+                        m_is_valid = true;
+                    }
+                }
                 else
-                    m_opcode.Dump (&ss, 15 * 3 + 1);
+                {
+                    m_opcode.SetOpcode32 (data.GetU32(&data_offset));
+                }
             }
             else
             {
-                // Else, we have ARM which can show up to a uint32_t 0x00000000 (10 spaces)
-                // plus two for padding...
-                if (max_opcode_byte_size > 0)
-                    m_opcode.Dump (&ss, max_opcode_byte_size * 3 + 1);
+                // The opcode isn't evenly sized, so we need to actually use the llvm
+                // disassembler to parse it and get the size.
+                char out_string[512];
+                m_disasm.Lock(this, NULL);
+                uint8_t *opcode_data = const_cast<uint8_t *>(data.PeekData (data_offset, 1));
+                const size_t opcode_data_len = data.GetByteSize() - data_offset;
+                const addr_t pc = m_address.GetFileAddress();
+                const size_t inst_size = ::LLVMDisasmInstruction (disasm_context,
+                                                                  opcode_data,
+                                                                  opcode_data_len,
+                                                                  pc, // PC value
+                                                                  out_string,
+                                                                  sizeof(out_string));
+                // The address lookup function could have caused us to fill in our comment
+                m_comment.clear();
+                m_disasm.Unlock();
+                if (inst_size == 0)
+                    m_opcode.Clear();
                 else
-                    m_opcode.Dump (&ss, 12);
-            }        
-        }
-        
-        int size_before_inst = ss.GetSize();
-        
-        ss.PutCString(m_opcode_name.c_str());
-        
-        PadToWidth(ss, size_before_inst + opcode_column_width);
-        
-        ss.PutCString(m_mnemocics.c_str());
-        
-        PadToWidth(ss, size_before_inst + opcode_column_width + operand_column_width);
-        
-        if (!m_comment.empty())
-        {
-            ss.PutCString(" ; ");
-            ss.PutCString(m_comment.c_str());
+                {
+                    m_opcode.SetOpcodeBytes(opcode_data, inst_size);
+                    m_is_valid = true;
+                }
+            }
         }
-        
-        ss.Flush();
-        
-        s->PutCString(ss.GetData());
-    }
-    
-    virtual bool
-    DoesBranch () const
-    {
-        return m_does_branch == eLazyBoolYes;
-    }
-    
-    virtual size_t
-    Decode (const lldb_private::Disassembler &disassembler,
-            const lldb_private::DataExtractor &data,
-            uint32_t data_offset)
-    {
-        Parse <false> (m_address, 
-                       m_address_class, 
-                       data,
-                       data_offset,
-                       NULL);
-        
         return m_opcode.GetByteSize();
     }
     
     void
-    AddReferencedAddress (std::string &description)
+    AppendComment (std::string &description)
     {
-        if (m_no_comments)
-            m_comment_stream.PutCString(", ");
+        if (m_comment.empty())
+            m_comment.swap (description);
         else
-            m_no_comments = true;
-        
-        m_comment_stream.PutCString(description.c_str());
+        {
+            m_comment.append(", ");
+            m_comment.append(description);
+        }
     }
     
     virtual void
-    CalculateMnemonicOperandsAndComment (lldb_private::ExecutionContextScope *exe_scope)
+    CalculateMnemonicOperandsAndComment (const lldb_private::ExecutionContext *exe_ctx)
     {
-        DataExtractor extractor(m_raw_bytes.data(),
-                                m_raw_bytes.size(),
-                                m_disasm.GetArchitecture().GetByteOrder(),
-                                m_disasm.GetArchitecture().GetAddressByteSize());
-        
-        Parse <true> (m_address,
-                      m_address_class,
-                      extractor,
-                      0,
-                      exe_scope);
+        DataExtractor data;
+        const AddressClass address_class = GetAddressClass ();
+
+        if (m_opcode.GetData(data, address_class))
+        {
+            char out_string[512];
+            
+            ::LLVMDisasmContextRef disasm_context;
+            
+            if (address_class == eAddressClassCodeAlternateISA)
+                disasm_context = m_disasm.m_alternate_disasm_context;
+            else
+                disasm_context = m_disasm.m_disasm_context;
+            
+            lldb::addr_t pc = LLDB_INVALID_ADDRESS;
+            
+            if (exe_ctx)
+            {
+                Target *target = exe_ctx->GetTargetPtr();
+                if (target)
+                    pc = m_address.GetLoadAddress(target);
+            }
+            
+            if (pc == LLDB_INVALID_ADDRESS)
+                pc = m_address.GetFileAddress();
+            
+            m_disasm.Lock(this, exe_ctx);
+            uint8_t *opcode_data = const_cast<uint8_t *>(data.PeekData (0, 1));
+            const size_t opcode_data_len = data.GetByteSize();
+            size_t inst_size = ::LLVMDisasmInstruction (disasm_context,
+                                                        opcode_data,
+                                                        opcode_data_len,
+                                                        pc,
+                                                        out_string,
+                                                        sizeof(out_string));
+            
+            m_disasm.Unlock();
+            
+            if (inst_size == 0)
+            {
+                m_comment.assign ("unknown opcode");
+                inst_size = m_opcode.GetByteSize();
+                StreamString mnemonic_strm;
+                uint32_t offset = 0;
+                switch (inst_size)
+                {
+                    case 1:
+                        {
+                            const uint8_t uval8 = data.GetU8 (&offset);
+                            m_opcode.SetOpcode8 (uval8);
+                            m_opcode_name.assign (".byte");
+                            mnemonic_strm.Printf("0x%2.2x", uval8);
+                        }
+                        break;
+                    case 2:
+                        {
+                            const uint16_t uval16 = data.GetU16(&offset);
+                            m_opcode.SetOpcode16(uval16);
+                            m_opcode_name.assign (".short");
+                            mnemonic_strm.Printf("0x%4.4x", uval16);
+                        }
+                        break;
+                    case 4:
+                        {
+                            const uint32_t uval32 = data.GetU32(&offset);
+                            m_opcode.SetOpcode32(uval32);
+                            m_opcode_name.assign (".long");
+                            mnemonic_strm.Printf("0x%8.8x", uval32);
+                        }
+                        break;
+                    case 8:
+                        {
+                            const uint64_t uval64 = data.GetU64(&offset);
+                            m_opcode.SetOpcode64(uval64);
+                            m_opcode_name.assign (".quad");
+                            mnemonic_strm.Printf("0x%16.16llx", uval64);
+                        }
+                        break;
+                    default:
+                        if (inst_size == 0)
+                            return;
+                        else
+                        {
+                            const uint8_t *bytes = data.PeekData(offset, inst_size);
+                            if (bytes == NULL)
+                                return;
+                            m_opcode_name.assign (".byte");
+                            m_opcode.SetOpcodeBytes(bytes, inst_size);
+                            mnemonic_strm.Printf("0x%2.2x", bytes[0]);
+                            for (uint32_t i=1; i<inst_size; ++i)
+                                mnemonic_strm.Printf(" 0x%2.2x", bytes[i]);
+                        }
+                        break;
+                }
+                m_mnemocics.swap(mnemonic_strm.GetString());
+                return;
+            }
+            else
+            {
+                if (m_does_branch == eLazyBoolCalculate)
+                {
+                    if (StringRepresentsBranch (out_string, strlen(out_string)))
+                        m_does_branch = eLazyBoolYes;
+                    else
+                        m_does_branch = eLazyBoolNo;
+                }
+            }
+            
+            if (!s_regex_compiled)
+            {
+                ::regcomp(&s_regex, "[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?", REG_EXTENDED);
+                s_regex_compiled = true;
+            }
+            
+            ::regmatch_t matches[3];
+            
+            if (!::regexec(&s_regex, out_string, sizeof(matches) / sizeof(::regmatch_t), matches, 0))
+            {
+                if (matches[1].rm_so != -1)
+                    m_opcode_name.assign(out_string + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
+                if (matches[2].rm_so != -1)
+                    m_mnemocics.assign(out_string + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so);
+            }
+        }
     }
     
     bool
@@ -203,69 +330,6 @@
         return m_opcode.GetByteSize();
     }
 protected:
-    void PopulateOpcode (const DataExtractor &extractor,
-                         uint32_t offset,
-                         size_t inst_size)
-    {
-        const ArchSpec &arch = m_disasm.GetArchitecture();
-        llvm::Triple::ArchType machine = arch.GetMachine();
-        
-        switch (machine)
-        {
-        case llvm::Triple::x86:
-        case llvm::Triple::x86_64:
-            m_opcode.SetOpcodeBytes(extractor.PeekData(offset, inst_size), inst_size);
-            return;
-
-        case llvm::Triple::arm:
-        case llvm::Triple::thumb:
-            switch (inst_size)
-            {
-                case 2:
-                    m_opcode.SetOpcode16 (extractor.GetU16 (&offset));
-                    break;
-                case 4:
-                    if (machine == llvm::Triple::arm && m_address_class == eAddressClassCodeAlternateISA)
-                    {
-                        // If it is a 32-bit THUMB instruction, we need to swap the upper & lower halves.
-                        uint32_t orig_bytes = extractor.GetU32 (&offset);
-                        uint16_t upper_bits = (orig_bytes >> 16) & ((1u << 16) - 1);
-                        uint16_t lower_bits = orig_bytes & ((1u << 16) - 1);
-                        uint32_t swapped = (lower_bits << 16) | upper_bits;
-                        m_opcode.SetOpcode32 (swapped);
-                    }
-                    else
-                    {
-                        m_opcode.SetOpcode32 (extractor.GetU32 (&offset));
-                    }
-                    break;
-                default:
-                    assert (!"Invalid ARM opcode size");
-                    break;
-            }
-            return;
-
-        default:
-            break;
-        }
-        // Handle the default cases here.
-        const uint32_t min_op_byte_size = arch.GetMinimumOpcodeByteSize();
-        const uint32_t max_op_byte_size = arch.GetMaximumOpcodeByteSize();
-        if (min_op_byte_size == max_op_byte_size)
-        {
-            assert (inst_size == min_op_byte_size);
-            switch (inst_size)
-            {
-                case 1: m_opcode.SetOpcode8  (extractor.GetU8  (&offset)); return;
-                case 2: m_opcode.SetOpcode16 (extractor.GetU16 (&offset)); return;
-                case 4: m_opcode.SetOpcode32 (extractor.GetU32 (&offset)); return;
-                case 8: m_opcode.SetOpcode64 (extractor.GetU64 (&offset)); return;
-                default:
-                    break;
-            }
-        }
-        m_opcode.SetOpcodeBytes(extractor.PeekData(offset, inst_size), inst_size);
-    }
     
     bool StringRepresentsBranch (const char *data, size_t size)
     {
@@ -349,99 +413,8 @@
         return false;
     }
     
-    template <bool Reparse> bool Parse (const lldb_private::Address &address, 
-                                        AddressClass addr_class,
-                                        const DataExtractor &extractor,
-                                        uint32_t data_offset,
-                                        lldb_private::ExecutionContextScope *exe_scope)
-    {
-        std::vector<char> out_string(256);
-        
-        const uint8_t *data_start = extractor.GetDataStart();
-        
-        m_disasm.Lock(this, exe_scope);
-        
-        ::LLVMDisasmContextRef disasm_context;
-        
-        if (addr_class == eAddressClassCodeAlternateISA)
-            disasm_context = m_disasm.m_alternate_disasm_context;
-        else
-            disasm_context = m_disasm.m_disasm_context;
-        
-        m_comment_stream.Clear();
-        
-        lldb::addr_t pc = LLDB_INVALID_ADDRESS;
-        
-        if (exe_scope)
-            if (TargetSP target_sp = exe_scope->CalculateTarget())
-                pc = m_address.GetLoadAddress(target_sp.get());
-        
-        if (pc == LLDB_INVALID_ADDRESS)
-            pc = m_address.GetFileAddress();
-                              
-        size_t inst_size = ::LLVMDisasmInstruction(disasm_context,
-                                                   const_cast<uint8_t*>(data_start) + data_offset,
-                                                   extractor.GetByteSize() - data_offset,
-                                                   pc, 
-                                                   out_string.data(), 
-                                                   out_string.size());
-        
-        if (m_does_branch == eLazyBoolCalculate)
-            m_does_branch = (StringRepresentsBranch (out_string.data(), out_string.size()) ?
-                             eLazyBoolYes : eLazyBoolNo);
-        
-        m_comment_stream.Flush();
-        m_no_comments = false;
-        
-        m_comment.swap(m_comment_stream.GetString());
-
-        m_disasm.Unlock();
-        
-        if (Reparse)
-        {
-            if (inst_size != m_raw_bytes.size())
-                return false;
-        }
-        else
-        {
-            if (!inst_size)
-                return false;
-        }
-            
-        PopulateOpcode(extractor, data_offset, inst_size);
-        
-        m_raw_bytes.resize(inst_size);
-        memcpy(m_raw_bytes.data(), data_start + data_offset, inst_size);
-        
-        if (!s_regex_compiled)
-        {
-            ::regcomp(&s_regex, "[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?", REG_EXTENDED);
-            s_regex_compiled = true;
-        }
-        
-        ::regmatch_t matches[3];
-        
-        const char *out_data = out_string.data();
-        
-        if (!::regexec(&s_regex, out_data, sizeof(matches) / sizeof(::regmatch_t), matches, 0))
-        {
-            if (matches[1].rm_so != -1)
-                m_opcode_name.assign(out_data + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
-            if (matches[2].rm_so != -1)
-                m_mnemocics.assign(out_data + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so);
-        }
-                    
-        m_is_valid = true;
-    
-        return true;
-    }
-                 
     bool                    m_is_valid;
     DisassemblerLLVMC      &m_disasm;
-    std::vector<uint8_t>    m_raw_bytes;
-    
-    bool                    m_no_comments;
-    StreamString            m_comment_stream;
     LazyBool                m_does_branch;
     
     static bool             s_regex_compiled;
@@ -464,8 +437,10 @@
 
 DisassemblerLLVMC::DisassemblerLLVMC (const ArchSpec &arch) :
     Disassembler(arch),
-    m_disasm_context(NULL),
-    m_alternate_disasm_context(NULL)
+    m_exe_ctx (NULL),
+    m_inst (NULL),
+    m_disasm_context (NULL),
+    m_alternate_disasm_context (NULL)
 {
     m_disasm_context = ::LLVMCreateDisasm(arch.GetTriple().getTriple().c_str(), 
                                           (void*)this, 
@@ -475,7 +450,11 @@
     
     if (arch.GetTriple().getArch() == llvm::Triple::arm)
     {
-        m_alternate_disasm_context = ::LLVMCreateDisasm("thumbv7-apple-darwin", 
+        ArchSpec thumb_arch(arch);
+        thumb_arch.GetTriple().setArchName(llvm::StringRef("thumbv7"));
+        std::string thumb_triple(thumb_arch.GetTriple().getTriple());
+
+        m_alternate_disasm_context = ::LLVMCreateDisasm(thumb_triple.c_str(),
                                                         (void*)this, 
                                                         /*TagType=*/1,
                                                         NULL,
@@ -511,39 +490,33 @@
         return 0;
     
     uint32_t data_cursor = data_offset;
-    size_t data_byte_size = data.GetByteSize();
+    const size_t data_byte_size = data.GetByteSize();
     uint32_t instructions_parsed = 0;
+    Address inst_addr(base_addr);
     
-    uint64_t instruction_pointer = base_addr.GetFileAddress();
-        
-    std::vector<char> out_string(256);
-    
-    while (data_offset < data_byte_size && instructions_parsed < num_instructions)
+    while (data_cursor < data_byte_size && instructions_parsed < num_instructions)
     {
-        Address instr_address = base_addr;
-        instr_address.Slide(data_cursor);
         
-        AddressClass address_class = eAddressClassUnknown;
+        AddressClass address_class = eAddressClassCode;
         
         if (m_alternate_disasm_context)
-            address_class = instr_address.GetAddressClass ();
+            address_class = inst_addr.GetAddressClass ();
         
         InstructionSP inst_sp(new InstructionLLVMC(*this,
-                                                   instr_address, 
+                                                   inst_addr, 
                                                    address_class));
         
         if (!inst_sp)
-            return data_cursor - data_offset;
-            
+            break;
+        
         uint32_t inst_size = inst_sp->Decode(*this, data, data_cursor);
                 
-        if (!inst_size)
-            return data_cursor - data_offset;
-        
+        if (inst_size == 0)
+            break;
+
         m_instruction_list.Append(inst_sp);
-        
-        instruction_pointer += inst_size;
         data_cursor += inst_size;
+        inst_addr.Slide(inst_size);
         instructions_parsed++;
     }
     
@@ -582,73 +555,72 @@
     return "Disassembler that uses LLVM MC to disassemble i386, x86_64 and ARM.";
 }
 
-int DisassemblerLLVMC::OpInfoCallback (void *DisInfo,
-                                       uint64_t PC,
-                                       uint64_t Offset,
-                                       uint64_t Size,
-                                       int TagType,
-                                       void *TagBug)
-{
-    return static_cast<DisassemblerLLVMC*>(DisInfo)->OpInfo(PC,
-                                                            Offset,
-                                                            Size,
-                                                            TagType,
-                                                            TagBug);
-}
-
-const char *DisassemblerLLVMC::SymbolLookupCallback(void *DisInfo,
-                                                    uint64_t ReferenceValue,
-                                                    uint64_t *ReferenceType,
-                                                    uint64_t ReferencePC,
-                                                    const char **ReferenceName)
-{
-    return static_cast<DisassemblerLLVMC*>(DisInfo)->SymbolLookup(ReferenceValue,
-                                                                  ReferenceType,
-                                                                  ReferencePC,
-                                                                  ReferenceName);
+int DisassemblerLLVMC::OpInfoCallback (void *disassembler,
+                                       uint64_t pc,
+                                       uint64_t offset,
+                                       uint64_t size,
+                                       int tag_type,
+                                       void *tag_bug)
+{
+    return static_cast<DisassemblerLLVMC*>(disassembler)->OpInfo (pc,
+                                                                  offset,
+                                                                  size,
+                                                                  tag_type,
+                                                                  tag_bug);
+}
+
+const char *DisassemblerLLVMC::SymbolLookupCallback (void *disassembler,
+                                                     uint64_t value,
+                                                     uint64_t *type,
+                                                     uint64_t pc,
+                                                     const char **name)
+{
+    return static_cast<DisassemblerLLVMC*>(disassembler)->SymbolLookup(value,
+                                                                       type,
+                                                                       pc,
+                                                                       name);
 }
 
 int DisassemblerLLVMC::OpInfo (uint64_t PC,
                                uint64_t Offset,
                                uint64_t Size,
-                               int TagType,
-                               void *TagBug)
+                               int tag_type,
+                               void *tag_bug)
 {
-    switch (TagType)
+    switch (tag_type)
     {
     default:
         break;
     case 1:
-        bzero (TagBug, sizeof(::LLVMOpInfo1));
+        bzero (tag_bug, sizeof(::LLVMOpInfo1));
         break;
     }
     return 0;
 }
 
-const char *DisassemblerLLVMC::SymbolLookup (uint64_t ReferenceValue,
-                                             uint64_t *ReferenceType,
-                                             uint64_t ReferencePC,
-                                             const char **ReferenceName)
-{
-    const char *result_name = NULL;
-    uint64_t result_reference_type = LLVMDisassembler_ReferenceType_InOut_None;
-    const char *result_referred_name = NULL;
-    
-    if (m_exe_scope && m_inst)
-    {        
-        Address reference_address;
-        
-        TargetSP target_sp (m_exe_scope->CalculateTarget());
-        Target *target = target_sp.get();
-        
-        if (target)
-        {
-            if (!target->GetSectionLoadList().ResolveLoadAddress(ReferenceValue, reference_address))
+const char *DisassemblerLLVMC::SymbolLookup (uint64_t value,
+                                             uint64_t *type_ptr,
+                                             uint64_t pc,
+                                             const char **name)
+{
+    if (*type_ptr)
+    {
+        if (m_exe_ctx && m_inst)
+        {        
+            //std::string remove_this_prior_to_checkin;
+            Address reference_address;
+            
+            Target *target = m_exe_ctx ? m_exe_ctx->GetTargetPtr() : NULL;
+            
+            if (target && !target->GetSectionLoadList().IsEmpty())
+                target->GetSectionLoadList().ResolveLoadAddress(value, reference_address);
+            else
             {
-                if (ModuleSP module_sp = m_inst->GetAddress().GetModule())
-                    module_sp->ResolveFileAddress(ReferenceValue, reference_address);
+                ModuleSP module_sp(m_inst->GetAddress().GetModule());
+                if (module_sp)
+                    module_sp->ResolveFileAddress(value, reference_address);
             }
-            
+                
             if (reference_address.IsValid() && reference_address.GetSection())
             {
                 StreamString ss;
@@ -659,15 +631,19 @@
                                         Address::DumpStyleSectionNameOffset);
                 
                 if (!ss.GetString().empty())
-                    m_inst->AddReferencedAddress(ss.GetString());
+                {
+                    //remove_this_prior_to_checkin = ss.GetString();
+                    //if (*type_ptr)
+                    m_inst->AppendComment(ss.GetString());
+                }
             }
+            //printf ("DisassemblerLLVMC::SymbolLookup (value=0x%16.16llx, type=%llu, pc=0x%16.16llx, name=\"%s\") m_exe_ctx=%p, m_inst=%p\n", value, *type_ptr, pc, remove_this_prior_to_checkin.c_str(), m_exe_ctx, m_inst);
         }
     }
-        
-    *ReferenceType = result_reference_type;
-    *ReferenceName = result_referred_name;
-        
-    return result_name;
+
+    *type_ptr = LLVMDisassembler_ReferenceType_InOut_None;
+    *name = NULL;
+    return NULL;
 }
 
 //------------------------------------------------------------------

Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h Wed May  9 21:52:23 2012
@@ -100,27 +100,25 @@
                                             const char **ReferenceName);
     
     void Lock(InstructionLLVMC *inst, 
-              lldb_private::ExecutionContextScope *exe_scope)
+              const lldb_private::ExecutionContext *exe_ctx)
     {
         m_mutex.Lock();
-        
         m_inst = inst;
-        m_exe_scope = exe_scope;
+        m_exe_ctx = exe_ctx;
     }
     
     void Unlock()
     {
-        m_exe_scope = NULL;
         m_inst = NULL;
-        
+        m_exe_ctx = NULL;
         m_mutex.Unlock();
     }
     
-    lldb_private::ExecutionContextScope    *m_exe_scope;
-    InstructionLLVMC                       *m_inst;
-    lldb_private::Mutex                     m_mutex;
-    ::LLVMDisasmContextRef                  m_disasm_context;
-    ::LLVMDisasmContextRef                  m_alternate_disasm_context;
+    const lldb_private::ExecutionContext *m_exe_ctx;
+    InstructionLLVMC *m_inst;
+    lldb_private::Mutex m_mutex;
+    ::LLVMDisasmContextRef m_disasm_context;
+    ::LLVMDisasmContextRef m_alternate_disasm_context;
 };
 
 #endif  // liblldb_DisassemblerLLVM_h_

Modified: lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp (original)
+++ lldb/trunk/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp Wed May  9 21:52:23 2012
@@ -71,7 +71,6 @@
             const uint32_t addr_byte_size = m_arch.GetAddressByteSize();
             const bool show_address = true;
             const bool show_bytes = true;
-            const bool raw = false;
             // Initialize the CFA with a known value. In the 32 bit case
             // it will be 0x80000000, and in the 64 bit case 0x8000000000000000.
             // We use the address byte size to be safe for any future addresss sizes
@@ -107,7 +106,7 @@
                         if (log && log->GetVerbose ())
                         {
                             StreamString strm;
-                            inst->Dump(&strm, inst_list.GetMaxOpcocdeByteSize (), show_address, show_bytes, &exe_ctx, raw);
+                            inst->Dump(&strm, inst_list.GetMaxOpcocdeByteSize (), show_address, show_bytes, NULL);
                             log->PutCString (strm.GetData());
                         }
 

Modified: lldb/trunk/source/Symbol/SymbolContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolContext.cpp?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolContext.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolContext.cpp Wed May  9 21:52:23 2012
@@ -203,6 +203,8 @@
         if (symbol->GetMangled().GetName())
         {
             dumped_something = true;
+            if (symbol->GetType() == eSymbolTypeTrampoline)
+                s->PutCString("symbol stub for: ");
             symbol->GetMangled().GetName().Dump(s);
         }
 

Modified: lldb/trunk/source/Target/ThreadPlanTracer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanTracer.cpp?rev=156532&r1=156531&r2=156532&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadPlanTracer.cpp (original)
+++ lldb/trunk/source/Target/ThreadPlanTracer.cpp Wed May  9 21:52:23 2012
@@ -219,8 +219,7 @@
                                    max_opcode_byte_size,
                                    show_address,
                                    show_bytes,
-                                   NULL, 
-                                   true);
+                                   NULL);
             }
         }
     }





More information about the lldb-commits mailing list