[Lldb-commits] [lldb] r131615 - /lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp

Johnny Chen johnny.chen at apple.com
Wed May 18 18:05:37 PDT 2011


Author: johnny
Date: Wed May 18 20:05:37 2011
New Revision: 131615

URL: http://llvm.org/viewvc/llvm-project?rev=131615&view=rev
Log:
Make InstructionLLVM::Dump() more robust for edis in cases when all the
EDOperandIndexForToken(token) calls fail to return a meaningful operand index,
resulting in both operands and comment being empty.  We will use the raw disassembly
string as output in these cases.

There is still a known bug where llvm:tB (A8.6.16 B Encoding T2) is not being processed
as a branch instruction and therefore the symbolic information is not being dumped for
non-raw mode.

Modified:
    lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp

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=131615&r1=131614&r2=131615&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp Wed May 18 20:05:37 2011
@@ -99,6 +99,16 @@
         s->Printf("%s ", str.c_str());
 }
 
+#include "llvm/ADT/StringRef.h"
+static void
+StripSpaces(llvm::StringRef &Str)
+{
+    while (!Str.empty() && isspace(Str[0]))
+        Str = Str.substr(1);
+    while (!Str.empty() && isspace(Str.back()))
+        Str = Str.substr(0, Str.size()-1);
+}
+
 void
 InstructionLLVM::Dump
 (
@@ -230,7 +240,7 @@
 
         if (printTokenized)
         {
-            bool show_token;
+            bool show_token = false;
 
             for (; tokenIndex < numTokens; ++tokenIndex)
             {
@@ -300,40 +310,42 @@
                 }
             } // for (tokenIndex)
 
-            if (printTokenized)
+            // If both operands and comment are empty, we will just print out
+            // the raw disassembly.
+            if (operands.GetString().empty() && comment.GetString().empty())
             {
-                if (operands.GetString().empty())
-                {
-                    s->PutCString(opcode.GetString().c_str());
-                }
+                const char *str;
+
+                if (EDGetInstString(&str, m_inst))
+                    return;
+                llvm::StringRef raw_disasm(str);
+                StripSpaces(raw_disasm);
+                s->PutCString(raw_disasm.str().c_str());
+            }
+            else
+            {
+                PadString(s, opcode.GetString(), opcodeColumnWidth);
+
+                if (comment.GetString().empty())
+                    s->PutCString(operands.GetString().c_str());
                 else
                 {
-                    PadString(s, opcode.GetString(), opcodeColumnWidth);
+                    PadString(s, operands.GetString(), operandColumnWidth);
 
-                    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())
-            } // printTokenized
-        } // for (tokenIndex)
+                    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))
+        if (EDGetInstString(&str, m_inst)) // 0 on success
             return;
-        else
-            s->Write(str, strlen(str) - 1);
+        s->Write(str, strlen(str) - 1);
     }
 }
 





More information about the lldb-commits mailing list