diff options
author | Sean Callanan <scallanan@apple.com> | 2015-12-11 19:10:04 +0000 |
---|---|---|
committer | Sean Callanan <scallanan@apple.com> | 2015-12-11 19:10:04 +0000 |
commit | d38f4d288fda2bfee5757909097f26cbc45822ef (patch) | |
tree | 069faefd7e552b3cc2078f77b5883eeb11d94fd0 /lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp | |
parent | 2992563b9349cd9229e868ef96a25f22507a70b8 (diff) | |
download | llvm-d38f4d288fda2bfee5757909097f26cbc45822ef.zip llvm-d38f4d288fda2bfee5757909097f26cbc45822ef.tar.gz llvm-d38f4d288fda2bfee5757909097f26cbc45822ef.tar.bz2 |
DisassemblerLLVMC now gets the disassembler comments for an instruction
and appends them to our list of comments (which can additionally include
things like decoded addresses).
llvm-svn: 255358
Diffstat (limited to 'lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp')
-rw-r--r-- | lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp index a909ed3..6d124b6 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp +++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp @@ -280,7 +280,8 @@ public: if (m_opcode.GetData(data)) { - char out_string[512]; + std::string out_string; + std::string comment_string; DisassemblerLLVMC &llvm_disasm = GetDisassemblerLLVMC(); @@ -331,7 +332,12 @@ public: if (inst_size > 0) { mc_disasm_ptr->SetStyle(use_hex_immediates, hex_style); - mc_disasm_ptr->PrintMCInst(inst, out_string, sizeof(out_string)); + mc_disasm_ptr->PrintMCInst(inst, out_string, comment_string); + + if (!comment_string.empty()) + { + AppendComment(comment_string); + } } llvm_disasm.Unlock(); @@ -413,10 +419,10 @@ public: RegularExpression::Match matches(3); - if (s_regex.Execute(out_string, &matches)) + if (s_regex.Execute(out_string.c_str(), &matches)) { - matches.GetMatchAtIndex(out_string, 1, m_opcode_name); - matches.GetMatchAtIndex(out_string, 2, m_mnemonics); + matches.GetMatchAtIndex(out_string.c_str(), 1, m_opcode_name); + matches.GetMatchAtIndex(out_string.c_str(), 2, m_mnemonics); } } } @@ -543,21 +549,25 @@ DisassemblerLLVMC::LLVMCDisassembler::GetMCInst (const uint8_t *opcode_data, return 0; } -uint64_t +void DisassemblerLLVMC::LLVMCDisassembler::PrintMCInst (llvm::MCInst &mc_inst, - char *dst, - size_t dst_len) + std::string &inst_string, + std::string &comments_string) { - llvm::StringRef unused_annotations; - llvm::SmallString<64> inst_string; - llvm::raw_svector_ostream inst_stream(inst_string); - m_instr_printer_ap->printInst (&mc_inst, inst_stream, unused_annotations, - *m_subtarget_info_ap); - const size_t output_size = std::min(dst_len - 1, inst_string.size()); - std::memcpy(dst, inst_string.data(), output_size); - dst[output_size] = '\0'; - - return output_size; + llvm::raw_string_ostream inst_stream(inst_string); + llvm::raw_string_ostream comments_stream(comments_string); + + m_instr_printer_ap->setCommentStream(comments_stream); + m_instr_printer_ap->printInst (&mc_inst, inst_stream, llvm::StringRef(), *m_subtarget_info_ap); + m_instr_printer_ap->setCommentStream(llvm::nulls()); + comments_stream.flush(); + + static std::string g_newlines("\r\n"); + + for (size_t newline_pos = 0; (newline_pos = comments_string.find_first_of(g_newlines, newline_pos)) != comments_string.npos; /**/) + { + comments_string.replace(comments_string.begin() + newline_pos, comments_string.begin() + newline_pos + 1, 1, ' '); + } } void |