Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1 @@
lldb-mi

View File

@ -0,0 +1,5 @@
LEVEL = ../../make
CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,38 @@
"""
Test lldb-mi -environment-cd command.
"""
from __future__ import print_function
import lldbmi_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class MiEnvironmentCdTestCase(lldbmi_testcase.MiTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfDarwin # Disabled while I investigate the failure on buildbot.
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_environment_cd(self):
"""Test that 'lldb-mi --interpreter' changes working directory for inferior."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# cd to a different directory
self.runCmd("-environment-cd /tmp")
self.expect("\^done")
# Run to the end
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("@\"cwd: /tmp\\r\\n\"", exactly=True)

View File

@ -0,0 +1,94 @@
"""
Test that the lldb-mi driver exits properly.
"""
from __future__ import print_function
import lldbmi_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class MiExitTestCase(lldbmi_testcase.MiTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_gdb_exit(self):
"""Test that '-gdb-exit' terminates local debug session and exits."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test -gdb-exit: try to exit and check that program is finished
self.runCmd("-gdb-exit")
self.expect("\^exit")
import pexpect
self.expect(pexpect.EOF)
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_quit(self):
"""Test that 'quit' exits immediately."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test quit: try to exit and check that program is finished
self.runCmd("quit")
import pexpect
self.expect(pexpect.EOF)
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_q(self):
"""Test that 'q' exits immediately."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test q: try to exit and check that program is finished
self.runCmd("q")
import pexpect
self.expect(pexpect.EOF)

View File

@ -0,0 +1,83 @@
"""
Test lldb-mi -file-xxx commands.
"""
from __future__ import print_function
import lldbmi_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class MiFileTestCase(lldbmi_testcase.MiTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_file_exec_and_symbols_file(self):
"""Test that 'lldb-mi --interpreter' works for -file-exec-and-symbols exe."""
self.spawnLldbMi(args=None)
# Test that -file-exec-and-symbols works for filename
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Run
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"exited-normally\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_file_exec_and_symbols_absolute_path(self):
"""Test that 'lldb-mi --interpreter' works for -file-exec-and-symbols fullpath/exe."""
self.spawnLldbMi(args=None)
# Test that -file-exec-and-symbols works for absolute path
import os
path = os.path.join(os.getcwd(), self.myexe)
self.runCmd("-file-exec-and-symbols \"%s\"" % path)
self.expect("\^done")
# Run
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"exited-normally\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_file_exec_and_symbols_relative_path(self):
"""Test that 'lldb-mi --interpreter' works for -file-exec-and-symbols relpath/exe."""
self.spawnLldbMi(args=None)
# Test that -file-exec-and-symbols works for relative path
path = "./%s" % self.myexe
self.runCmd("-file-exec-and-symbols %s" % path)
self.expect("\^done")
# Run
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"exited-normally\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_file_exec_and_symbols_unknown_path(self):
"""Test that 'lldb-mi --interpreter' works for -file-exec-and-symbols badpath/exe."""
self.spawnLldbMi(args=None)
# Test that -file-exec-and-symbols fails on unknown path
path = "unknown_dir/%s" % self.myexe
self.runCmd("-file-exec-and-symbols %s" % path)
self.expect("\^error")

View File

@ -0,0 +1,260 @@
"""
Test lldb-mi -gdb-set and -gdb-show commands.
"""
from __future__ import print_function
import unittest2
import lldbmi_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_gdb_set_target_async_default(self):
"""Test that 'lldb-mi --interpreter' switches to async mode by default."""
self.spawnLldbMi(args=None)
# Switch to sync mode
self.runCmd("-gdb-set target-async off")
self.expect("\^done")
self.runCmd("-gdb-show target-async")
self.expect("\^done,value=\"off\"")
# Test that -gdb-set switches to async by default
self.runCmd("-gdb-set target-async")
self.expect("\^done")
self.runCmd("-gdb-show target-async")
self.expect("\^done,value=\"on\"")
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@expectedFlakeyLinux("llvm.org/pr26028") # Fails in ~1% of cases
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_gdb_set_target_async_on(self):
"""Test that 'lldb-mi --interpreter' can execute commands in async mode."""
self.spawnLldbMi(args=None)
# Switch to sync mode
self.runCmd("-gdb-set target-async off")
self.expect("\^done")
self.runCmd("-gdb-show target-async")
self.expect("\^done,value=\"off\"")
# Test that -gdb-set can switch to async mode
self.runCmd("-gdb-set target-async on")
self.expect("\^done")
self.runCmd("-gdb-show target-async")
self.expect("\^done,value=\"on\"")
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Test that program is executed in async mode
self.runCmd("-exec-run")
self.expect("\*running")
self.expect("@\"argc=1")
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@expectedFailureAll(
oslist=["linux"],
bugnumber="Failing in ~11/600 dosep runs (build 3120-3122)")
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_gdb_set_target_async_off(self):
"""Test that 'lldb-mi --interpreter' can execute commands in sync mode."""
self.spawnLldbMi(args=None)
# Test that -gdb-set can switch to sync mode
self.runCmd("-gdb-set target-async off")
self.expect("\^done")
self.runCmd("-gdb-show target-async")
self.expect("\^done,value=\"off\"")
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Test that program is executed in async mode
self.runCmd("-exec-run")
unexpected = ["\*running"] # "\*running" is async notification
it = self.expect(unexpected + ["@\"argc=1\\\\r\\\\n"])
if it < len(unexpected):
self.fail("unexpected found: %s" % unexpected[it])
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_gdb_show_target_async(self):
"""Test that 'lldb-mi --interpreter' in async mode by default."""
self.spawnLldbMi(args=None)
# Test that default target-async value is "on"
self.runCmd("-gdb-show target-async")
self.expect("\^done,value=\"on\"")
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_gdb_show_language(self):
"""Test that 'lldb-mi --interpreter' can get current language."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test that -gdb-show language gets current language
self.runCmd("-gdb-show language")
self.expect("\^done,value=\"c\+\+\"")
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
@unittest2.expectedFailure("-gdb-set ignores unknown properties")
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_gdb_set_unknown(self):
"""Test that 'lldb-mi --interpreter' fails when setting an unknown property."""
self.spawnLldbMi(args=None)
# Test that -gdb-set fails if property is unknown
self.runCmd("-gdb-set unknown some_value")
self.expect("\^error")
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
@unittest2.expectedFailure("-gdb-show ignores unknown properties")
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_gdb_show_unknown(self):
"""Test that 'lldb-mi --interpreter' fails when showing an unknown property."""
self.spawnLldbMi(args=None)
# Test that -gdb-show fails if property is unknown
self.runCmd("-gdb-show unknown")
self.expect("\^error")
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr22274: need a pexpect replacement for windows")
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_gdb_set_ouptut_radix(self):
"""Test that 'lldb-mi --interpreter' works for -gdb-set output-radix."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Run to BP_printf
line = line_number('main.cpp', '// BP_printf')
self.runCmd("-break-insert main.cpp:%d" % line)
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Setup variable
self.runCmd("-var-create var_a * a")
self.expect(
"\^done,name=\"var_a\",numchild=\"0\",value=\"10\",type=\"int\",thread-id=\"1\",has_more=\"0\"")
# Test default output
self.runCmd("-var-evaluate-expression var_a")
self.expect("\^done,value=\"10\"")
# Test hex output
self.runCmd("-gdb-set output-radix 16")
self.expect("\^done")
self.runCmd("-var-evaluate-expression var_a")
self.expect("\^done,value=\"0xa\"")
# Test octal output
self.runCmd("-gdb-set output-radix 8")
self.expect("\^done")
self.runCmd("-var-evaluate-expression var_a")
self.expect("\^done,value=\"012\"")
# Test decimal output
self.runCmd("-gdb-set output-radix 10")
self.expect("\^done")
self.runCmd("-var-evaluate-expression var_a")
self.expect("\^done,value=\"10\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
@expectedFailureAll(
bugnumber="llvm.org/pr31485: data-disassemble doesn't follow flavor settings")
def test_lldbmi_gdb_set_disassembly_flavor(self):
"""Test that 'lldb-mi --interpreter' works for -gdb-set disassembly-flavor."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Run to BP_printf
line = line_number('main.cpp', '// BP_printf')
self.runCmd("-break-insert main.cpp:%d" % line)
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\".+addr=\"(0x[0-9a-f]+)\"")
# Get starting and ending address from $pc
pc = int(self.child.match.group(1), base=16)
s_addr, e_addr = pc, pc + 1
# Test default output (att)
self.runCmd("-data-disassemble -s %d -e %d -- 0" % (s_addr, e_addr))
self.expect("movl ")
# Test intel style
self.runCmd("-gdb-set disassembly-flavor intel")
self.expect("\^done")
self.runCmd("-data-disassemble -s %d -e %d -- 0" % (s_addr, e_addr))
self.expect("mov ")
# Test AT&T style
self.runCmd("-gdb-set disassembly-flavor intel")
self.expect("\^done")
self.runCmd("-data-disassemble -s %d -e %d -- 0" % (s_addr, e_addr))
self.expect("movl ")

View File

@ -0,0 +1,59 @@
"""
Test lldb-mi =library-loaded notifications.
"""
from __future__ import print_function
import lldbmi_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class MiLibraryLoadedTestCase(lldbmi_testcase.MiTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_library_loaded(self):
"""Test that 'lldb-mi --interpreter' shows the =library-loaded notifications."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Test =library-loaded
import os
path = os.path.join(os.getcwd(), self.myexe)
symbols_path = os.path.join(
path + ".dSYM",
"Contents",
"Resources",
"DWARF",
self.myexe)
def add_slashes(x): return x.replace(
"\\",
"\\\\").replace(
"\"",
"\\\"").replace(
"\'",
"\\\'").replace(
"\0",
"\\\0")
self.expect(
[
"=library-loaded,id=\"%s\",target-name=\"%s\",host-name=\"%s\",symbols-loaded=\"1\",symbols-path=\"%s\",loaded_addr=\"-\",size=\"[0-9]+\"" %
(add_slashes(path),
add_slashes(path),
add_slashes(path),
add_slashes(symbols_path)),
"=library-loaded,id=\"%s\",target-name=\"%s\",host-name=\"%s\",symbols-loaded=\"0\",loaded_addr=\"-\",size=\"[0-9]+\"" %
(add_slashes(path),
add_slashes(path),
add_slashes(path))])

View File

@ -0,0 +1,58 @@
"""
Test that the lldb-mi driver prints prompt properly.
"""
from __future__ import print_function
import lldbmi_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class MiPromptTestCase(lldbmi_testcase.MiTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_prompt(self):
"""Test that 'lldb-mi --interpreter' echos '(gdb)' after commands and events."""
self.spawnLldbMi(args=None)
# Test that lldb-mi is ready after unknown command
self.runCmd("-unknown-command")
self.expect(
"\^error,msg=\"Driver\. Received command '-unknown-command'\. It was not handled\. Command 'unknown-command' not in Command Factory\"")
self.expect(self.child_prompt, exactly=True)
# Test that lldb-mi is ready after -file-exec-and-symbols
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
self.expect(self.child_prompt, exactly=True)
# Test that lldb-mi is ready after -break-insert
self.runCmd("-break-insert -f main")
self.expect("\^done,bkpt={number=\"1\"")
self.expect(self.child_prompt, exactly=True)
# Test that lldb-mi is ready after -exec-run
self.runCmd("-exec-run")
self.expect("\*running")
self.expect(self.child_prompt, exactly=True)
# Test that lldb-mi is ready after BP hit
self.expect("\*stopped,reason=\"breakpoint-hit\"")
self.expect(self.child_prompt, exactly=True)
# Test that lldb-mi is ready after -exec-continue
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect(self.child_prompt, exactly=True)
# Test that lldb-mi is ready after program exited
self.expect("\*stopped,reason=\"exited-normally\"")
self.expect(self.child_prompt, exactly=True)

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,358 @@
"""
Test lldb-mi -break-xxx commands.
"""
from __future__ import print_function
import unittest2
import lldbmi_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class MiBreakTestCase(lldbmi_testcase.MiTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@expectedFlakeyLinux("llvm.org/pr24717")
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_break_insert_function_pending(self):
"""Test that 'lldb-mi --interpreter' works for pending function breakpoints."""
self.spawnLldbMi(args=None)
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
self.runCmd("-break-insert -f printf")
# FIXME function name is unknown on Darwin, fullname should be ??, line is -1
# self.expect("\^done,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"0xffffffffffffffff\",func=\"printf\",file=\"\?\?\",fullname=\"\?\?\",line=\"-1\",pending=\[\"printf\"\],times=\"0\",original-location=\"printf\"}")
self.expect(
"\^done,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"0xffffffffffffffff\",func=\"\?\?\",file=\"\?\?\",fullname=\"\?\?/\?\?\",line=\"0\",pending=\[\"printf\"\],times=\"0\",original-location=\"printf\"}")
# FIXME function name is unknown on Darwin, fullname should be ??, line -1
# self.expect("=breakpoint-modified,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"0xffffffffffffffff\",func=\"printf\",file=\"\?\?\",fullname=\"\?\?\",line=\"-1\",pending=\[\"printf\"\],times=\"0\",original-location=\"printf\"}")
self.expect(
"=breakpoint-modified,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"0xffffffffffffffff\",func=\"\?\?\",file=\"\?\?\",fullname=\"\?\?/\?\?\",line=\"0\",pending=\[\"printf\"\],times=\"0\",original-location=\"printf\"}")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect(
"=breakpoint-modified,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\".+?\",file=\".+?\",fullname=\".+?\",line=\"(-1|\d+)\",pending=\[\"printf\"\],times=\"0\",original-location=\"printf\"}")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_break_insert_function(self):
"""Test that 'lldb-mi --interpreter' works for function breakpoints."""
self.spawnLldbMi(args=None)
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
self.runCmd("-break-insert -f main")
self.expect(
"\^done,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\",pending=\[\"main\"\],times=\"0\",original-location=\"main\"}")
self.expect(
"=breakpoint-modified,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\",pending=\[\"main\"\],times=\"0\",original-location=\"main\"}")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect(
"=breakpoint-modified,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\",pending=\[\"main\"\],times=\"0\",original-location=\"main\"}")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test that -break-insert can set non-pending BP
self.runCmd("-break-insert printf")
# FIXME function name is unknown on Darwin
# self.expect("\^done,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"printf\",file=\".+?\",fullname=\".+?\",line=\"(-1|\d+)\",times=\"0\",original-location=\"printf\"}")
self.expect(
"\^done,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\".+?\",file=\".+?\",fullname=\".+?\",line=\"(-1|\d+)\",times=\"0\",original-location=\"printf\"}")
# FIXME function name is unknown on Darwin
# self.expect("=breakpoint-modified,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"printf\",file=\".+?\",fullname=\".+?\",line=\"(-1|\d+)\",times=\"0\",original-location=\"printf\"}")
self.expect(
"=breakpoint-modified,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\".+?\",file=\".+?\",fullname=\".+?\",line=\"(-1|\d+)\",times=\"0\",original-location=\"printf\"}")
# FIXME function name is unknown on Darwin
# self.expect("=breakpoint-modified,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"printf\",file=\".+?\",fullname=\".+?\",line=\"(-1|\d+)\",times=\"0\",original-location=\"printf\"}")
self.expect(
"=breakpoint-modified,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\".+?\",file=\".+?\",fullname=\".+?\",line=\"(-1|\d+)\",times=\"0\",original-location=\"printf\"}")
# Test that -break-insert fails if non-pending BP can't be resolved
self.runCmd("-break-insert unknown_func")
self.expect(
"\^error,msg=\"Command 'break-insert'. Breakpoint location 'unknown_func' not found\"")
# Test that non-pending BP was set correctly
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\".*bkptno=\"2\"")
# Test that we can set a BP using the file:func syntax
self.runCmd("-break-insert main.cpp:main")
self.expect("\^done,bkpt={number=\"4\"")
self.runCmd("-break-insert main.cpp:ns::foo1")
self.expect("\^done,bkpt={number=\"5\"")
# FIXME: quotes on filenames aren't handled correctly in lldb-mi.
#self.runCmd("-break-insert \"main.cpp\":main")
# self.expect("\^done,bkpt={number=\"6\"")
# We should hit BP #5 on 'main.cpp:ns::foo1'
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\".*bkptno=\"5\"")
# FIXME: this test is disabled due to lldb bug llvm.org/pr24271.
# Test that we can set a BP using the global namespace token
#self.runCmd("-break-insert ::main")
# self.expect("\^done,bkpt={number=\"7\"")
#self.runCmd("-break-insert main.cpp:::main")
# self.expect("\^done,bkpt={number=\"8\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_break_insert_file_line_pending(self):
"""Test that 'lldb-mi --interpreter' works for pending file:line breakpoints."""
self.spawnLldbMi(args=None)
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Find the line number to break inside main() and set
# pending BP
line = line_number('main.cpp', '// BP_return')
self.runCmd("-break-insert -f main.cpp:%d" % line)
self.expect(
"\^done,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"%d\",pending=\[\"main.cpp:%d\"\],times=\"0\",original-location=\"main.cpp:%d\"}" %
(line,
line,
line))
self.expect(
"=breakpoint-modified,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"%d\",pending=\[\"main.cpp:%d\"\],times=\"0\",original-location=\"main.cpp:%d\"}" %
(line,
line,
line))
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_break_insert_file_line(self):
"""Test that 'lldb-mi --interpreter' works for file:line breakpoints."""
self.spawnLldbMi(args=None)
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
self.runCmd("-break-insert -f main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test that -break-insert can set non-pending BP
line = line_number('main.cpp', '// BP_return')
self.runCmd("-break-insert main.cpp:%d" % line)
self.expect(
"\^done,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"%d\",times=\"0\",original-location=\"main.cpp:%d\"}" %
(line, line))
self.expect(
"=breakpoint-modified,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"%d\",times=\"0\",original-location=\"main.cpp:%d\"}" %
(line, line))
# Test that -break-insert fails if non-pending BP can't be resolved
self.runCmd("-break-insert unknown_file:1")
self.expect(
"\^error,msg=\"Command 'break-insert'. Breakpoint location 'unknown_file:1' not found\"")
# Test that non-pending BP was set correctly
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_break_insert_file_line_absolute_path(self):
"""Test that 'lldb-mi --interpreter' works for file:line breakpoints."""
self.spawnLldbMi(args=None)
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
self.runCmd("-break-insert -f main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
import os
path = os.path.join(os.getcwd(), "main.cpp")
line = line_number('main.cpp', '// BP_return')
self.runCmd("-break-insert %s:%d" % (path, line))
self.expect("\^done,bkpt={number=\"2\"")
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_break_insert_settings(self):
"""Test that 'lldb-mi --interpreter' can set breakpoints accoridng to global options."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Set target.move-to-nearest-code=off and try to set BP #1 that
# shouldn't be hit
self.runCmd(
"-interpreter-exec console \"settings set target.move-to-nearest-code off\"")
self.expect("\^done")
line_decl = line_number('main.cpp', '// BP_main_decl')
line_in = line_number('main.cpp', '// BP_in_main')
self.runCmd("-break-insert -f main.cpp:%d" % line_in)
self.expect("\^done,bkpt={number=\"1\"")
# Test that non-pending BP will not be set on non-existing line if target.move-to-nearest-code=off
# Note: this increases the BP number by 1 even though BP #2 is invalid.
self.runCmd("-break-insert main.cpp:%d" % line_in)
self.expect(
"\^error,msg=\"Command 'break-insert'. Breakpoint location 'main.cpp:%d' not found\"" %
line_in)
# Set target.move-to-nearest-code=on and target.skip-prologue=on and
# set BP #3 & #4
self.runCmd(
"-interpreter-exec console \"settings set target.move-to-nearest-code on\"")
self.runCmd(
"-interpreter-exec console \"settings set target.skip-prologue on\"")
self.expect("\^done")
self.runCmd("-break-insert main.cpp:%d" % line_in)
self.expect("\^done,bkpt={number=\"3\"")
self.runCmd("-break-insert main.cpp:%d" % line_decl)
self.expect("\^done,bkpt={number=\"4\"")
# Set target.skip-prologue=off and set BP #5
self.runCmd(
"-interpreter-exec console \"settings set target.skip-prologue off\"")
self.expect("\^done")
self.runCmd("-break-insert main.cpp:%d" % line_decl)
self.expect("\^done,bkpt={number=\"5\"")
# Test that BP #5 is located before BP #4
self.runCmd("-exec-run")
self.expect("\^running")
self.expect(
"\*stopped,reason=\"breakpoint-hit\",disp=\"del\",bkptno=\"5\"")
# Test that BP #4 is hit
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect(
"\*stopped,reason=\"breakpoint-hit\",disp=\"del\",bkptno=\"4\"")
# Test that BP #3 is hit
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect(
"\*stopped,reason=\"breakpoint-hit\",disp=\"del\",bkptno=\"3\"")
# Test that the target.language=pascal setting works and that BP #6 is
# NOT set
self.runCmd(
"-interpreter-exec console \"settings set target.language c\"")
self.expect("\^done")
self.runCmd("-break-insert ns.foo1")
self.expect("\^error")
# Test that the target.language=c++ setting works and that BP #7 is hit
self.runCmd(
"-interpreter-exec console \"settings set target.language c++\"")
self.expect("\^done")
self.runCmd("-break-insert ns::foo1")
self.expect("\^done,bkpt={number=\"7\"")
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect(
"\*stopped,reason=\"breakpoint-hit\",disp=\"del\",bkptno=\"7\"")
# Test that BP #1 and #2 weren't set by running to program exit
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect("\*stopped,reason=\"exited-normally\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_break_enable_disable(self):
"""Test that 'lldb-mi --interpreter' works for enabling / disabling breakpoints."""
self.spawnLldbMi(args=None)
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
self.runCmd("-break-insert main")
self.expect(
"\^done,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"main\"")
self.expect(
"=breakpoint-modified,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\",times=\"0\",original-location=\"main\"}")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect(
"=breakpoint-modified,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"main\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\",times=\"0\",original-location=\"main\"}")
self.expect(
"\*stopped,reason=\"breakpoint-hit\",disp=\"del\",bkptno=\"1\"")
self.runCmd("-break-insert ns::foo1")
self.expect(
"\^done,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"ns::foo1\(\)\"")
self.expect(
"=breakpoint-modified,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"ns::foo1\(\)\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\",times=\"0\",original-location=\"ns::foo1\"}")
self.runCmd("-break-insert ns::foo2")
self.expect(
"\^done,bkpt={number=\"3\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"ns::foo2\(\)\"")
self.expect(
"=breakpoint-modified,bkpt={number=\"3\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"ns::foo2\(\)\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\",times=\"0\",original-location=\"ns::foo2\"}")
# disable the 2nd breakpoint
self.runCmd("-break-disable 2")
self.expect("\^done")
self.expect(
"=breakpoint-modified,bkpt={number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"n\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"ns::foo1\(\)\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\",times=\"0\",original-location=\"ns::foo1\"}")
# disable the 3rd breakpoint and re-enable
self.runCmd("-break-disable 3")
self.expect("\^done")
self.expect(
"=breakpoint-modified,bkpt={number=\"3\",type=\"breakpoint\",disp=\"keep\",enabled=\"n\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"ns::foo2\(\)\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\",times=\"0\",original-location=\"ns::foo2\"}")
self.runCmd("-break-enable 3")
self.expect("\^done")
self.expect(
"=breakpoint-modified,bkpt={number=\"3\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"(?!0xffffffffffffffff)0x[0-9a-f]+\",func=\"ns::foo2\(\)\",file=\"main\.cpp\",fullname=\".+?main\.cpp\",line=\"\d+\",times=\"0\",original-location=\"ns::foo2\"}")
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect(
"\*stopped,reason=\"breakpoint-hit\",disp=\"del\",bkptno=\"3\"")

View File

@ -0,0 +1,30 @@
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <cstdio>
namespace ns
{
int foo1(void) { printf("In foo1\n"); return 1; }
int foo2(void) { printf("In foo2\n"); return 2; }
}
int x;
int main(int argc, char const *argv[]) { // BP_main_decl
printf("Print a formatted string so that GCC does not optimize this printf call: %s\n", argv[0]);
// This is a long comment with no code inside
// This is a long comment with no code inside
// This is a long comment with no code inside
// BP_in_main
// This is a long comment with no code inside
// This is a long comment with no code inside
// This is a long comment with no code inside
x = ns::foo1() + ns::foo2();
return 0; // BP_return
}

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <cstdio>
void
g_MyFunction(void)
{
printf("g_MyFunction");
}
static void
s_MyFunction(void)
{
g_MyFunction();
printf("s_MyFunction");
}
int
main(int argc, char const *argv[])
{
printf("start");
g_MyFunction();
s_MyFunction();
printf("exit");
return 0;
}

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,406 @@
"""
Test lldb-mi -data-xxx commands.
"""
from __future__ import print_function
import unittest2
import lldbmi_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class MiDataTestCase(lldbmi_testcase.MiTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
def test_lldbmi_data_disassemble(self):
"""Test that 'lldb-mi --interpreter' works for -data-disassemble."""
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 main")
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 main")
self.expect(
"\^done,value=\"0x[0-9a-f]+ \(a.out`main at main.cpp:[0-9]+\)\"")
addr = int(self.child.after.split("\"")[1].split(" ")[0], 16)
# 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)
# Test -data-disassemble without "--"
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]+ \(a.out`hello_world\(\) at main.cpp:[0-9]+\)\"")
addr = int(self.child.after.split("\"")[1].split(" ")[0], 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:
# Darwin: {address="0x0000000100000f18",func-name="hello_world()",offset="8",size="7",inst="leaq 0x65(%rip), %rdi; \"Hello, World!\\n\""},
# Linux: {address="0x0000000000400642",func-name="hello_world()",offset="18",size="5",inst="callq 0x4004d0; symbol stub for: printf"}
# 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
# The MIPS disassembler never prints stub name
if self.isMIPS():
self.expect(["{address=\"0x[0-9a-f]+\",func-name=\"hello_world\(\)\",offset=\"[0-9]+\",size=\"[0-9]+\",inst=\".+?; \\\\\"Hello, World!\\\\\\\\n\\\\\"\"}",
"{address=\"0x[0-9a-f]+\",func-name=\"hello_world\(\)\",offset=\"[0-9]+\",size=\"[0-9]+\",inst=\".+?\"}"])
else:
self.expect(["{address=\"0x[0-9a-f]+\",func-name=\"hello_world\(\)\",offset=\"[0-9]+\",size=\"[0-9]+\",inst=\".+?; \\\\\"Hello, World!\\\\\\\\n\\\\\"\"}",
"{address=\"0x[0-9a-f]+\",func-name=\"hello_world\(\)\",offset=\"[0-9]+\",size=\"[0-9]+\",inst=\".+?; symbol stub for: printf\"}"])
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
def test_lldbmi_data_read_memory_bytes_global(self):
"""Test that -data-read-memory-bytes can access global buffers."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Get address of char[] (global)
self.runCmd("-data-evaluate-expression &g_CharArray")
self.expect("\^done,value=\"0x[0-9a-f]+\"")
addr = int(self.child.after.split("\"")[1], 16)
size = 5
# Test that -data-read-memory-bytes works for char[] type (global)
self.runCmd("-data-read-memory-bytes %#x %d" % (addr, size))
self.expect(
"\^done,memory=\[{begin=\"0x0*%x\",offset=\"0x0+\",end=\"0x0*%x\",contents=\"1011121300\"}\]" %
(addr, addr + size))
# Get address of static char[]
self.runCmd("-data-evaluate-expression &s_CharArray")
self.expect("\^done,value=\"0x[0-9a-f]+\"")
addr = int(self.child.after.split("\"")[1], 16)
size = 5
# Test that -data-read-memory-bytes works for static char[] type
self.runCmd("-data-read-memory-bytes %#x %d" % (addr, size))
self.expect(
"\^done,memory=\[{begin=\"0x0*%x\",offset=\"0x0+\",end=\"0x0*%x\",contents=\"2021222300\"}\]" %
(addr, addr + size))
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
def test_lldbmi_data_read_memory_bytes_local(self):
"""Test that -data-read-memory-bytes can access local buffers."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd('-file-exec-and-symbols %s' % self.myexe)
self.expect(r'\^done')
# Run to BP_local_array_test_inner
line = line_number('main.cpp', '// BP_local_array_test_inner')
self.runCmd('-break-insert main.cpp:%d' % line)
self.expect(r'\^done,bkpt=\{number="1"')
self.runCmd('-exec-run')
self.expect(r'\^running')
self.expect(r'\*stopped,reason="breakpoint-hit"')
# Get address of local char[]
self.runCmd('-data-evaluate-expression "(void *)&array"')
self.expect(r'\^done,value="0x[0-9a-f]+"')
addr = int(self.child.after.split('"')[1], 16)
size = 4
# Test that an unquoted hex literal address works
self.runCmd('-data-read-memory-bytes %#x %d' % (addr, size))
self.expect(
r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="01020304"\}\]' %
(addr, addr + size))
# Test that a double-quoted hex literal address works
self.runCmd('-data-read-memory-bytes "%#x" %d' % (addr, size))
self.expect(
r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="01020304"\}\]' %
(addr, addr + size))
# Test that unquoted expressions work
self.runCmd('-data-read-memory-bytes &array %d' % size)
self.expect(
r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="01020304"\}\]' %
(addr, addr + size))
# This doesn't work, and perhaps that makes sense, but it does work on
# GDB
self.runCmd('-data-read-memory-bytes array 4')
self.expect(r'\^error')
#self.expect(r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="01020304"\}\]' % (addr, addr + size))
self.runCmd('-data-read-memory-bytes &array[2] 2')
self.expect(
r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="0304"\}\]' %
(addr + 2, addr + size))
self.runCmd('-data-read-memory-bytes first_element_ptr %d' % size)
self.expect(
r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="01020304"\}\]' %
(addr, addr + size))
# Test that double-quoted expressions work
self.runCmd('-data-read-memory-bytes "&array" %d' % size)
self.expect(
r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="01020304"\}\]' %
(addr, addr + size))
self.runCmd('-data-read-memory-bytes "&array[0] + 1" 3')
self.expect(
r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="020304"\}\]' %
(addr + 1, addr + size))
self.runCmd('-data-read-memory-bytes "first_element_ptr + 1" 3')
self.expect(
r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="020304"\}\]' %
(addr + 1, addr + size))
# Test the -o (offset) option
self.runCmd('-data-read-memory-bytes -o 1 &array 3')
self.expect(
r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="020304"\}\]' %
(addr + 1, addr + size))
# Test the --thread option
self.runCmd('-data-read-memory-bytes --thread 1 &array 4')
self.expect(
r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="01020304"\}\]' %
(addr, addr + size))
# Test the --thread option with an invalid value
self.runCmd('-data-read-memory-bytes --thread 999 &array 4')
self.expect(r'\^error')
# Test the --frame option (current frame)
self.runCmd('-data-read-memory-bytes --frame 0 &array 4')
self.expect(
r'\^done,memory=\[\{begin="0x0*%x",offset="0x0+",end="0x0*%x",contents="01020304"\}\]' %
(addr, addr + size))
# Test the --frame option (outer frame)
self.runCmd('-data-read-memory-bytes --frame 1 &array 4')
self.expect(
r'\^done,memory=\[\{begin="0x[0-9a-f]+",offset="0x0+",end="0x[0-9a-f]+",contents="05060708"\}\]')
# Test the --frame option with an invalid value
self.runCmd('-data-read-memory-bytes --frame 999 &array 4')
self.expect(r'\^error')
# Test all the options at once
self.runCmd(
'-data-read-memory-bytes --thread 1 --frame 1 -o 2 &array 2')
self.expect(
r'\^done,memory=\[\{begin="0x[0-9a-f]+",offset="0x0+",end="0x[0-9a-f]+",contents="0708"\}\]')
# Test that an expression that references undeclared variables doesn't
# work
self.runCmd(
'-data-read-memory-bytes "&undeclared_array1 + undeclared_array2[1]" 2')
self.expect(r'\^error')
# Test that the address argument is required
self.runCmd('-data-read-memory-bytes')
self.expect(r'\^error')
# Test that the count argument is required
self.runCmd('-data-read-memory-bytes &array')
self.expect(r'\^error')
# Test that the address and count arguments are required when other
# options are present
self.runCmd('-data-read-memory-bytes --thread 1')
self.expect(r'\^error')
self.runCmd('-data-read-memory-bytes --thread 1 --frame 0')
self.expect(r'\^error')
# Test that the count argument is required when other options are
# present
self.runCmd('-data-read-memory-bytes --thread 1 &array')
self.expect(r'\^error')
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
def test_lldbmi_data_list_register_names(self):
"""Test that 'lldb-mi --interpreter' works for -data-list-register-names."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test -data-list-register-names: try to get all registers
self.runCmd("-data-list-register-names")
self.expect("\^done,register-names=\[\".+?\",")
# Test -data-list-register-names: try to get specified registers
self.runCmd("-data-list-register-names 0")
self.expect("\^done,register-names=\[\".+?\"\]")
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
def test_lldbmi_data_list_register_values(self):
"""Test that 'lldb-mi --interpreter' works for -data-list-register-values."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test -data-list-register-values: try to get all registers
self.runCmd("-data-list-register-values x")
self.expect(
"\^done,register-values=\[{number=\"0\",value=\"0x[0-9a-f]+\"")
# Test -data-list-register-values: try to get specified registers
self.runCmd("-data-list-register-values x 0")
self.expect(
"\^done,register-values=\[{number=\"0\",value=\"0x[0-9a-f]+\"}\]")
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
def test_lldbmi_data_info_line(self):
"""Test that 'lldb-mi --interpreter' works for -data-info-line."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Get the address of main and its line
self.runCmd("-data-evaluate-expression main")
self.expect(
"\^done,value=\"0x[0-9a-f]+ \(a.out`main at main.cpp:[0-9]+\)\"")
addr = int(self.child.after.split("\"")[1].split(" ")[0], 16)
line = line_number('main.cpp', '// FUNC_main')
# Test that -data-info-line works for address
self.runCmd("-data-info-line *%#x" % addr)
self.expect(
"\^done,start=\"0x0*%x\",end=\"0x[0-9a-f]+\",file=\".+?main.cpp\",line=\"%d\"" %
(addr, line))
# Test that -data-info-line works for file:line
self.runCmd("-data-info-line main.cpp:%d" % line)
self.expect(
"\^done,start=\"0x0*%x\",end=\"0x[0-9a-f]+\",file=\".+?main.cpp\",line=\"%d\"" %
(addr, line))
# Test that -data-info-line fails when invalid address is specified
self.runCmd("-data-info-line *0x0")
self.expect(
"\^error,msg=\"Command 'data-info-line'\. Error: The LineEntry is absent or has an unknown format\.\"")
# Test that -data-info-line fails when file is unknown
self.runCmd("-data-info-line unknown_file:1")
self.expect(
"\^error,msg=\"Command 'data-info-line'\. Error: The LineEntry is absent or has an unknown format\.\"")
# Test that -data-info-line fails when line has invalid format
self.runCmd("-data-info-line main.cpp:bad_line")
self.expect(
"\^error,msg=\"error: invalid line number string 'bad_line'")
self.runCmd("-data-info-line main.cpp:0")
self.expect("\^error,msg=\"error: zero is an invalid line number")
@skipIfRemote # We do not currently support remote debugging via the MI.
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
def test_lldbmi_data_evaluate_expression(self):
"""Test that 'lldb-mi --interpreter' works for -data-evaluate-expression."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
line = line_number('main.cpp', '// BP_local_2d_array_test')
self.runCmd('-break-insert main.cpp:%d' % line)
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Check 2d array
self.runCmd("-data-evaluate-expression array2d")
self.expect(
"\^done,value=\"\{\[0\] = \{\[0\] = 1, \[1\] = 2, \[2\] = 3\}, \[1\] = \{\[0\] = 4, \[1\] = 5, \[2\] = 6\}\}\"")

View File

@ -0,0 +1,61 @@
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
const char g_CharArray[] = "\x10\x11\x12\x13";
static const char s_CharArray[] = "\x20\x21\x22\x23";
void
local_array_test_inner()
{
char array[] = { 0x01, 0x02, 0x03, 0x04 };
char *first_element_ptr = &array[0];
char g = g_CharArray[0];
char s = s_CharArray[0];
// BP_local_array_test_inner
return;
}
void
local_array_test()
{
char array[] = { 0x05, 0x06, 0x07, 0x08 };
// BP_local_array_test
local_array_test_inner();
return;
}
void
local_2d_array_test()
{
int array2d[2][3];
array2d[0][0] = 1;
array2d[0][1] = 2;
array2d[0][2] = 3;
array2d[1][0] = 4;
array2d[1][1] = 5;
array2d[1][2] = 6;
return; // BP_local_2d_array_test
}
void
hello_world()
{
printf("Hello, World!\n"); // BP_hello_world
}
int
main(int argc, char const *argv[])
{ // FUNC_main
local_array_test();
hello_world();
local_2d_array_test();
return 0;
}

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
CXX_SOURCES := main.cpp
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,220 @@
"""
Test lldb-mi can interpret CLI commands directly.
"""
from __future__ import print_function
import lldbmi_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class MiCliSupportTestCase(lldbmi_testcase.MiTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_target_create(self):
"""Test that 'lldb-mi --interpreter' can create target by 'target create' command."""
self.spawnLldbMi(args=None)
# Test that "target create" loads executable
self.runCmd("target create \"%s\"" % self.myexe)
self.expect("\^done")
# Test that executable was loaded properly
self.runCmd("-break-insert -f main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_breakpoint_set(self):
"""Test that 'lldb-mi --interpreter' can set breakpoint by 'breakpoint set' command."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Test that "breakpoint set" sets a breakpoint
self.runCmd("breakpoint set --name main")
self.expect("\^done")
self.expect("=breakpoint-created,bkpt={number=\"1\"")
# Test that breakpoint was set properly
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("=breakpoint-modified,bkpt={number=\"1\"")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_settings_set_target_run_args_before(self):
"""Test that 'lldb-mi --interpreter' can set target arguments by 'setting set target.run-args' command before than target was created."""
self.spawnLldbMi(args=None)
# Test that "settings set target.run-args" passes arguments to executable
# FIXME: --arg1 causes an error
self.runCmd(
"setting set target.run-args arg1 \"2nd arg\" third_arg fourth=\"4th arg\"")
self.expect("\^done")
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Run
self.runCmd("-exec-run")
self.expect("\^running")
# Test that arguments were passed properly
self.expect("@\"argc=5\\\\r\\\\n\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_settings_set_target_run_args_after(self):
"""Test that 'lldb-mi --interpreter' can set target arguments by 'setting set target.run-args' command after than target was created."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Test that "settings set target.run-args" passes arguments to executable
# FIXME: --arg1 causes an error
self.runCmd(
"setting set target.run-args arg1 \"2nd arg\" third_arg fourth=\"4th arg\"")
self.expect("\^done")
# Run
self.runCmd("-exec-run")
self.expect("\^running")
# Test that arguments were passed properly
self.expect("@\"argc=5\\\\r\\\\n\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_process_launch(self):
"""Test that 'lldb-mi --interpreter' can launch process by "process launch" command."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Set breakpoint
self.runCmd("-break-insert -f main")
self.expect("\^done,bkpt={number=\"1\"")
# Test that "process launch" launches executable
self.runCmd("process launch")
self.expect("\^done")
# Test that breakpoint hit
self.expect("\*stopped,reason=\"breakpoint-hit\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_thread_step_in(self):
"""Test that 'lldb-mi --interpreter' can step in by "thread step-in" command."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test that "thread step-in" steps into (or not) printf depending on debug info
# Note that message is different in Darwin and Linux:
# Darwin: "*stopped,reason=\"end-stepping-range\",frame={addr=\"0x[0-9a-f]+\",func=\"main\",args=[{name=\"argc\",value=\"1\"},{name=\"argv\",value="0x[0-9a-f]+\"}],file=\"main.cpp\",fullname=\".+main.cpp\",line=\"\d\"},thread-id=\"1\",stopped-threads=\"all\"
# Linux:
# "*stopped,reason=\"end-stepping-range\",frame={addr="0x[0-9a-f]+\",func=\"__printf\",args=[{name=\"format\",value=\"0x[0-9a-f]+\"}],file=\"printf.c\",fullname=\".+printf.c\",line="\d+"},thread-id=\"1\",stopped-threads=\"all\"
self.runCmd("thread step-in")
self.expect("\^done")
it = self.expect(["@\"argc=1\\\\r\\\\n\"",
"\*stopped,reason=\"end-stepping-range\".+?func=\"(?!main).+?\""])
if it == 0:
self.expect(
"\*stopped,reason=\"end-stepping-range\".+?func=\"main\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_thread_step_over(self):
"""Test that 'lldb-mi --interpreter' can step over by "thread step-over" command."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test that "thread step-over" steps over
self.runCmd("thread step-over")
self.expect("\^done")
self.expect("@\"argc=1\\\\r\\\\n\"")
self.expect("\*stopped,reason=\"end-stepping-range\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_thread_continue(self):
"""Test that 'lldb-mi --interpreter' can continue execution by "thread continue" command."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test that "thread continue" continues execution
self.runCmd("thread continue")
self.expect("\^done")
self.expect("@\"argc=1\\\\r\\\\n")
self.expect("\*stopped,reason=\"exited-normally\"")

View File

@ -0,0 +1,247 @@
"""
Test lldb-mi -interpreter-exec command.
"""
from __future__ import print_function
import lldbmi_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class MiInterpreterExecTestCase(lldbmi_testcase.MiTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_target_create(self):
"""Test that 'lldb-mi --interpreter' can create target by 'target create' command."""
self.spawnLldbMi(args=None)
# Test that "target create" loads executable
self.runCmd(
"-interpreter-exec console \"target create \\\"%s\\\"\"" %
self.myexe)
self.expect("\^done")
# Test that executable was loaded properly
self.runCmd("-break-insert -f main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_breakpoint_set(self):
"""Test that 'lldb-mi --interpreter' can set breakpoint by 'breakpoint set' command."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Test that "breakpoint set" sets a breakpoint
self.runCmd("-interpreter-exec console \"breakpoint set --name main\"")
self.expect("\^done")
self.expect("=breakpoint-created,bkpt={number=\"1\"")
# Test that breakpoint was set properly
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("=breakpoint-modified,bkpt={number=\"1\"")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@expectedFlakeyLinux(bugnumber="llvm.org/pr25470")
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_settings_set_target_run_args_before(self):
"""Test that 'lldb-mi --interpreter' can set target arguments by 'setting set target.run-args' command before than target was created."""
self.spawnLldbMi(args=None)
# Test that "settings set target.run-args" passes arguments to executable
# FIXME: --arg1 causes an error
self.runCmd(
"-interpreter-exec console \"setting set target.run-args arg1 \\\"2nd arg\\\" third_arg fourth=\\\"4th arg\\\"\"")
self.expect("\^done")
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Run
self.runCmd("-exec-run")
self.expect("\^running")
# Test that arguments were passed properly
self.expect("@\"argc=5\\\\r\\\\n\"")
self.expect("@\"argv.0.=.*lldb-mi")
self.expect("@\"argv.1.=arg1\\\\r\\\\n\"")
self.expect("@\"argv.2.=2nd arg\\\\r\\\\n\"")
self.expect("@\"argv.3.=third_arg\\\\r\\\\n\"")
self.expect("@\"argv.4.=fourth=4th arg\\\\r\\\\n\"")
# Test that program exited normally
self.expect("\*stopped,reason=\"exited-normally\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@expectedFailureAll(
oslist=["linux"],
bugnumber="Failing in ~9/600 dosep runs (build 3120-3122)")
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_settings_set_target_run_args_after(self):
"""Test that 'lldb-mi --interpreter' can set target arguments by 'setting set target.run-args' command after than target was created."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Test that "settings set target.run-args" passes arguments to executable
# FIXME: --arg1 causes an error
self.runCmd(
"-interpreter-exec console \"setting set target.run-args arg1 \\\"2nd arg\\\" third_arg fourth=\\\"4th arg\\\"\"")
self.expect("\^done")
# Run to BP_printf
line = line_number('main.cpp', '// BP_printf')
self.runCmd("-break-insert main.cpp:%d" % line)
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Run to BP_return
line = line_number('main.cpp', '// BP_return')
self.runCmd("-break-insert main.cpp:%d" % line)
self.expect("\^done,bkpt={number=\"2\"")
self.runCmd("-exec-continue")
self.expect("\^running")
# Test that arguments were passed properly
self.expect("@\"argc=5\\\\r\\\\n\"")
self.expect("@\"argv.0.=.*lldb-mi")
self.expect("@\"argv.1.=arg1\\\\r\\\\n\"")
self.expect("@\"argv.2.=2nd arg\\\\r\\\\n\"")
self.expect("@\"argv.3.=third_arg\\\\r\\\\n\"")
self.expect("@\"argv.4.=fourth=4th arg\\\\r\\\\n\"")
# Hit BP_return
self.expect("\*stopped,reason=\"breakpoint-hit\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_process_launch(self):
"""Test that 'lldb-mi --interpreter' can launch process by "process launch" command."""
self.spawnLldbMi(args=None)
# Load executable
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
self.expect("\^done")
# Set breakpoint
self.runCmd("-break-insert -f main")
self.expect("\^done,bkpt={number=\"1\"")
# Test that "process launch" launches executable
self.runCmd("-interpreter-exec console \"process launch\"")
self.expect("\^done")
# Test that breakpoint hit
self.expect("\*stopped,reason=\"breakpoint-hit\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_thread_step_in(self):
"""Test that 'lldb-mi --interpreter' can step in by "thread step-in" command."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test that "thread step-in" steps into (or not) printf depending on debug info
# Note that message is different in Darwin and Linux:
# Darwin: "*stopped,reason=\"end-stepping-range\",frame={addr=\"0x[0-9a-f]+\",func=\"main\",args=[{name=\"argc\",value=\"1\"},{name=\"argv\",value="0x[0-9a-f]+\"}],file=\"main.cpp\",fullname=\".+main.cpp\",line=\"\d\"},thread-id=\"1\",stopped-threads=\"all\"
# Linux:
# "*stopped,reason=\"end-stepping-range\",frame={addr="0x[0-9a-f]+\",func=\"__printf\",args=[{name=\"format\",value=\"0x[0-9a-f]+\"}],file=\"printf.c\",fullname=\".+printf.c\",line="\d+"},thread-id=\"1\",stopped-threads=\"all\"
self.runCmd("-interpreter-exec console \"thread step-in\"")
self.expect("\^done")
it = self.expect(["@\"argc=1\\\\r\\\\n\"",
"\*stopped,reason=\"end-stepping-range\".+?func=\"(?!main).+?\""])
if it == 0:
self.expect(
"\*stopped,reason=\"end-stepping-range\".+?func=\"main\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_thread_step_over(self):
"""Test that 'lldb-mi --interpreter' can step over by "thread step-over" command."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test that "thread step-over" steps over
self.runCmd("-interpreter-exec console \"thread step-over\"")
self.expect("\^done")
self.expect("@\"argc=1\\\\r\\\\n\"")
self.expect("\*stopped,reason=\"end-stepping-range\"")
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@expectedFlakeyLinux("llvm.org/pr25470")
@skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_thread_continue(self):
"""Test that 'lldb-mi --interpreter' can continue execution by "thread continue" command."""
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 main")
self.expect("\^done,bkpt={number=\"1\"")
self.runCmd("-exec-run")
self.expect("\^running")
self.expect("\*stopped,reason=\"breakpoint-hit\"")
# Test that "thread continue" continues execution
self.runCmd("-interpreter-exec console \"thread continue\"")
self.expect("\^done")
self.expect("@\"argc=1\\\\r\\\\n")
self.expect("\*stopped,reason=\"exited-normally\"")

Some files were not shown because too many files have changed in this diff Show More