[Lldb-commits] [lldb] r255358 - DisassemblerLLVMC now gets the disassembler comments for an instruction

Sean Callanan via lldb-commits lldb-commits at lists.llvm.org
Fri Dec 11 11:10:04 PST 2015


Author: spyffe
Date: Fri Dec 11 13:10:04 2015
New Revision: 255358

URL: http://llvm.org/viewvc/llvm-project?rev=255358&view=rev
Log:
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).

Modified:
    lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
    lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h

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=255358&r1=255357&r2=255358&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp Fri Dec 11 13:10:04 2015
@@ -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::Ge
         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';
+    llvm::raw_string_ostream inst_stream(inst_string);
+    llvm::raw_string_ostream comments_stream(comments_string);
 
-    return output_size;
+    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

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=255358&r1=255357&r2=255358&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h Fri Dec 11 13:10:04 2015
@@ -51,7 +51,7 @@ class DisassemblerLLVMC : public lldb_pr
         ~LLVMCDisassembler();
 
         uint64_t GetMCInst (const uint8_t *opcode_data, size_t opcode_data_len, lldb::addr_t pc, llvm::MCInst &mc_inst);
-        uint64_t PrintMCInst (llvm::MCInst &mc_inst, char *output_buffer, size_t out_buffer_len);
+        void PrintMCInst (llvm::MCInst &mc_inst, std::string &inst_string, std::string &comments_string);
         void     SetStyle (bool use_hex_immed, HexImmediateStyle hex_style);
         bool     CanBranch (llvm::MCInst &mc_inst);
         bool     HasDelaySlot (llvm::MCInst &mc_inst);




More information about the lldb-commits mailing list