diff options
author | Johnny Chen <johnny.chen@apple.com> | 2011-05-23 23:29:23 +0000 |
---|---|---|
committer | Johnny Chen <johnny.chen@apple.com> | 2011-05-23 23:29:23 +0000 |
commit | 0084527b82d2987e33197b36263ea6da5b13ff08 (patch) | |
tree | d1f3186a38d1bf2350542af7024096c1f8a24003 | |
parent | faaa16ea2ce07150c3da66a9b02328c298657a9c (diff) | |
download | bcm5719-llvm-0084527b82d2987e33197b36263ea6da5b13ff08.tar.gz bcm5719-llvm-0084527b82d2987e33197b36263ea6da5b13ff08.zip |
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().
llvm-svn: 131937
-rw-r--r-- | lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp | 80 |
1 files changed, 35 insertions, 45 deletions
diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp index b5020fd52c3..5e77375596f 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp +++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp @@ -98,16 +98,40 @@ PadString(Stream *s, const std::string &str, size_t width) 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 @@ InstructionLLVM::Dump 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 @@ InstructionLLVM::Dump 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 @@ InstructionLLVM::Dump 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. |