Skip to content

Commit

Permalink
Escape strings in disassembly comments.
Browse files Browse the repository at this point in the history
Summary: Patch from chuckr@microsoft.com

Reviewers: abidh, ChuckR

Subscribers: paulmaybee, lldb-commits

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

llvm-svn: 237092
  • Loading branch information
k15tfu committed May 12, 2015
1 parent c770124 commit f44ab29
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
21 changes: 21 additions & 0 deletions lldb/test/tools/lldb-mi/data/TestMiData.py
Expand Up @@ -38,6 +38,27 @@ def test_lldbmi_data_disassemble(self):
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
Expand Down
9 changes: 9 additions & 0 deletions lldb/test/tools/lldb-mi/data/main.cpp
Expand Up @@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//

#include <stdio.h>

const char g_CharArray[] = "\x10\x11\x12\x13";
static const char s_CharArray[] = "\x20\x21\x22\x23";

Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion lldb/tools/lldb-mi/MICmdCmdData.cpp
Expand Up @@ -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);

Expand Down

0 comments on commit f44ab29

Please sign in to comment.