Index: test/tools/lldb-mi/data/TestMiData.py =================================================================== --- test/tools/lldb-mi/data/TestMiData.py +++ test/tools/lldb-mi/data/TestMiData.py @@ -37,6 +37,39 @@ # Test -data-disassemble: try to disassemble some address self.runCmd("-data-disassemble -s %#x -e %#x -- 0" % (addr, addr + 0x10)) self.expect("\^done,asm_insns=\[{address=\"0x0*%x\",func-name=\"main\",offset=\"0\",size=\"[1-9]+\",inst=\".+?\"}," % addr) + + @lldbmi_test + @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows") + @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races + def test_lldbmi_data_disassemble_with_comment(self): + """Test that 'lldb-mi --interpreter' works for -data-disassemble with comments in dissasembly.""" + + self.spawnLldbMi(args = None) + + # Load executable + self.runCmd("-file-exec-and-symbols %s" % self.myexe) + self.expect("\^done") + + # Run to main + self.runCmd("-break-insert -f hello_world") + self.expect("\^done,bkpt={number=\"1\"") + self.runCmd("-exec-run") + self.expect("\^running") + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Get an address for disassembling: use main + self.runCmd("-data-evaluate-expression hello_world") + self.expect("\^done,value=\"0x[0-9a-f]+\"") + addr = int(self.child.after.split("\"")[1], 16) + + # Test -data-disassemble: try to disassemble some address + self.runCmd("-data-disassemble -s %#x -e %#x -- 0" % (addr, addr + 0x10)) + + # This matches a line similar to: + # {address="0x0000000100000f18",func-name="hello_world()",offset="8",size="7",inst="leaq 0x65(%rip), %rdi; \"Hello, World!\\n\""}, + # To match the escaped characters in the ouptut, we must use four backslashes per matches backslash + # See https://docs.python.org/2/howto/regex.html#the-backslash-plague + self.expect("{address=\"0x[0-9a-f]+\",func-name=\"hello_world\(\)\",offset=\"[0-9]+\",size=\"[0-9]+\",inst=\".+?; \\\\\"Hello, World!\\\\\\\\n\\\\\"\"},") @lldbmi_test @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows") Index: test/tools/lldb-mi/data/main.cpp =================================================================== --- test/tools/lldb-mi/data/main.cpp +++ test/tools/lldb-mi/data/main.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +#include + const char g_CharArray[] = "\x10\x11\x12\x13"; static const char s_CharArray[] = "\x20\x21\x22\x23"; @@ -28,9 +30,16 @@ return; } +void +hello_world() +{ + printf("Hello, World!\n"); // BP_hello_world +} + int main(int argc, char const *argv[]) { // FUNC_main local_array_test(); + hello_world(); return 0; } Index: tools/lldb-mi/MICmdCmdData.cpp =================================================================== --- tools/lldb-mi/MICmdCmdData.cpp +++ tools/lldb-mi/MICmdCmdData.cpp @@ -438,7 +438,7 @@ const CMICmnMIValueConst miValueConst4(CMIUtilString::Format("%d", instrtSize)); const CMICmnMIValueResult miValueResult4("size", miValueConst4); miValueTuple.Add(miValueResult4); - const CMICmnMIValueConst miValueConst5(CMIUtilString::Format("%s %s%s", pStrMnemonic, pStrOperands, strComment.c_str())); + const CMICmnMIValueConst miValueConst5(CMIUtilString::Format("%s %s%s", pStrMnemonic, pStrOperands, strComment.Escape(true).c_str())); const CMICmnMIValueResult miValueResult5("inst", miValueConst5); miValueTuple.Add(miValueResult5);