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

Johnny Chen johnny.chen at apple.com
Mon May 23 16:29:23 PDT 2011


Author: johnny
Date: Mon May 23 18:29:23 2011
New Revision: 131937

URL: http://llvm.org/viewvc/llvm-project?rev=131937&view=rev
Log:
Refactor InstructionLLVM::Dump() a little bit to reduce the entropy by introducing
a new file static utility function AddSymbolicInfo() which is called from places
within InstructionLLVM::Dump().

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=131937&r1=131936&r2=131937&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp Mon May 23 18:29:23 2011
@@ -98,16 +98,40 @@
     else
         s->Printf("%s ", str.c_str());
 }
+static void
+AddSymbolicInfo(const ExecutionContext *exe_ctx, ExecutionContextScope *exe_scope,
+                StreamString &comment, uint64_t operand_value, const Address &inst_addr)
+{
+    Address so_addr;
+    if (exe_ctx && exe_ctx->target && !exe_ctx->target->GetSectionLoadList().IsEmpty())
+    {
+        if (exe_ctx->target->GetSectionLoadList().ResolveLoadAddress(operand_value, so_addr))
+            so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
+    }
+    else
+    {
+        Module *module = inst_addr.GetModule();
+        if (module)
+        {
+            if (module->ResolveFileAddress(operand_value, so_addr))
+                so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
+        }
+    }
+}
 
 #include "llvm/ADT/StringRef.h"
-static void
-StripSpaces(llvm::StringRef &Str)
+static inline 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);
 }
+static inline void RStrip(llvm::StringRef &Str, char c)
+{
+    if (!Str.empty() && Str.back() == c)
+        Str = Str.substr(0, Str.size()-1);
+}
 static void
 Align(Stream *s, const char *str, size_t opcodeColWidth, size_t operandColWidth)
 {
@@ -290,21 +314,7 @@
                                         comment.Printf("0x%llx ", operand_value);
                                     }
 
-                                    lldb_private::Address so_addr;
-                                    if (exe_ctx && exe_ctx->target && !exe_ctx->target->GetSectionLoadList().IsEmpty())
-                                    {
-                                        if (exe_ctx->target->GetSectionLoadList().ResolveLoadAddress (operand_value, so_addr))
-                                            so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
-                                    }
-                                    else
-                                    {
-                                        Module *module = GetAddress().GetModule();
-                                        if (module)
-                                        {
-                                            if (module->ResolveFileAddress (operand_value, so_addr))
-                                                so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
-                                        }
-                                    }
+                                    AddSymbolicInfo(exe_ctx, exe_scope, comment, operand_value, GetAddress());
                                 } // EDEvaluateOperand
                             } // EDOperandIsMemory
                         } // EDGetOperand
@@ -331,19 +341,9 @@
                 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%llx ", operand_value);
-
-                    lldb_private::Address so_addr;
-                    if (exe_ctx && exe_ctx->target && !exe_ctx->target->GetSectionLoadList().IsEmpty()) {
-                        if (exe_ctx->target->GetSectionLoadList().ResolveLoadAddress (operand_value, so_addr))
-                            so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
-                    } else {
-                        Module *module = GetAddress().GetModule();
-                        if (module) {
-                            if (module->ResolveFileAddress (operand_value, so_addr))
-                                so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
-                        }
-                    }
+                    AddSymbolicInfo(exe_ctx, exe_scope, comment, operand_value, GetAddress());
                 }
             }
             // Yet more workaround for "bl #..." and "blx #...".
@@ -354,23 +354,13 @@
                 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 comment
+                    // Put the address value into the comment.
                     comment.Printf("0x%llx ", operand_value);
-                    llvm::StringRef string_ref(pos - 1);
-                    llvm::StringRef operand_string_ref = string_ref.split('\n').first;
-                    operands.PutCString(operand_string_ref.str().c_str());
-
-                    lldb_private::Address so_addr;
-                    if (exe_ctx && exe_ctx->target && !exe_ctx->target->GetSectionLoadList().IsEmpty()) {
-                        if (exe_ctx->target->GetSectionLoadList().ResolveLoadAddress (operand_value, so_addr))
-                            so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
-                    } else {
-                        Module *module = GetAddress().GetModule();
-                        if (module) {
-                            if (module->ResolveFileAddress (operand_value, so_addr))
-                                so_addr.Dump(&comment, exe_scope, Address::DumpStyleResolvedDescriptionNoModule, Address::DumpStyleSectionNameOffset);
-                        }
-                    }
+                    // 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, exe_scope, comment, operand_value, GetAddress());
                 }
             }
             // END of workaround.





More information about the lldb-commits mailing list