From f44ab29e05a3a3dc32e004fe0c87131349253720 Mon Sep 17 00:00:00 2001 From: Ilia K Date: Tue, 12 May 2015 05:55:23 +0000 Subject: [PATCH] Escape strings in disassembly comments. 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 | 21 +++++++++++++++++++++ lldb/test/tools/lldb-mi/data/main.cpp | 9 +++++++++ lldb/tools/lldb-mi/MICmdCmdData.cpp | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lldb/test/tools/lldb-mi/data/TestMiData.py b/lldb/test/tools/lldb-mi/data/TestMiData.py index 2c1ade5..517c9055 100644 --- a/lldb/test/tools/lldb-mi/data/TestMiData.py +++ b/lldb/test/tools/lldb-mi/data/TestMiData.py @@ -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 diff --git a/lldb/test/tools/lldb-mi/data/main.cpp b/lldb/test/tools/lldb-mi/data/main.cpp index d264607..5782b4e 100644 --- a/lldb/test/tools/lldb-mi/data/main.cpp +++ b/lldb/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 @@ 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; } diff --git a/lldb/tools/lldb-mi/MICmdCmdData.cpp b/lldb/tools/lldb-mi/MICmdCmdData.cpp index 4994619..514c4a8 100644 --- a/lldb/tools/lldb-mi/MICmdCmdData.cpp +++ b/lldb/tools/lldb-mi/MICmdCmdData.cpp @@ -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); -- 2.7.4