Escape strings in disassembly comments.
authorIlia K <ki.stfu@gmail.com>
Tue, 12 May 2015 05:55:23 +0000 (05:55 +0000)
committerIlia K <ki.stfu@gmail.com>
Tue, 12 May 2015 05:55:23 +0000 (05:55 +0000)
Summary: Patch from chuckr@microsoft.com

Reviewers: abidh, ChuckR

Subscribers: paulmaybee, lldb-commits

Differential Revision: http://reviews.llvm.org/D9544

llvm-svn: 237092

lldb/test/tools/lldb-mi/data/TestMiData.py
lldb/test/tools/lldb-mi/data/main.cpp
lldb/tools/lldb-mi/MICmdCmdData.cpp

index 2c1ade5..517c905 100644 (file)
@@ -38,6 +38,27 @@ class MiDataTestCase(lldbmi_testcase.MiTestCaseBase):
         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)
 
+        # Run to hello_world
+        self.runCmd("-break-insert -f hello_world")
+        self.expect("\^done,bkpt={number=\"2\"")
+        self.runCmd("-exec-continue")
+        self.expect("\^running")
+        self.expect("\*stopped,reason=\"breakpoint-hit\"")
+
+        # Get an address for disassembling: use hello_world
+        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")
     @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
index d264607..5782b4e 100644 (file)
@@ -7,6 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <stdio.h>
+
 const char g_CharArray[] = "\x10\x11\x12\x13";
 static const char s_CharArray[] = "\x20\x21\x22\x23";
 
@@ -28,9 +30,16 @@ local_array_test()
     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 4994619..514c4a8 100644 (file)
@@ -438,7 +438,7 @@ CMICmdCmdDataDisassemble::Execute(void)
         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);