summaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/tools
diff options
context:
space:
mode:
Diffstat (limited to 'packages/Python/lldbsuite/test/tools')
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/TestMiEnvironmentCd.py1
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/TestMiExit.py3
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/TestMiFile.py4
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/TestMiGdbSetShow.py9
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/TestMiLibraryLoaded.py1
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/TestMiPrompt.py1
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/TestMiBreak.py44
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/main.cpp13
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/control/TestMiExec.py14
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/data/TestMiData.py8
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/interpreter/TestMiCliSupport.py8
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/interpreter/TestMiInterpreterExec.py8
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/Makefile5
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/TestMiLexicalScope.py68
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/main.cpp33
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/signal/TestMiSignal.py4
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/symbol/TestMiSymbol.py1
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/syntax/TestMiSyntax.py4
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/target/TestMiTarget.py3
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py1
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py3
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiVar.py6
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/.clang-format1
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteHostInfo.py (renamed from packages/Python/lldbsuite/test/tools/lldb-server/host-info/TestGdbRemoteHostInfo.py)0
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py119
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py60
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/exit-code/main.cpp630
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py18
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/main.cpp50
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/main.cpp639
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/main.cpp7
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/Makefile5
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/TestGdbRemote_QPassSignals.py115
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/main.cpp37
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/thread-name/Makefile (renamed from packages/Python/lldbsuite/test/tools/lldb-server/host-info/Makefile)4
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py41
-rw-r--r--packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp22
37 files changed, 1247 insertions, 743 deletions
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiEnvironmentCd.py b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiEnvironmentCd.py
index 786c842bb5141..d62224d976c9a 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiEnvironmentCd.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiEnvironmentCd.py
@@ -18,6 +18,7 @@ class MiEnvironmentCdTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiExit.py b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiExit.py
index 0cc50370b1643..4f3562d42de83 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiExit.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiExit.py
@@ -18,6 +18,7 @@ class MiExitTestCase(lldbmi_testcase.MiTestCaseBase):
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."""
@@ -44,6 +45,7 @@ class MiExitTestCase(lldbmi_testcase.MiTestCaseBase):
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."""
@@ -69,6 +71,7 @@ class MiExitTestCase(lldbmi_testcase.MiTestCaseBase):
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."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiFile.py b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiFile.py
index 7a99ecf7d1e5b..1eea89f4fff4e 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiFile.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiFile.py
@@ -17,6 +17,7 @@ class MiFileTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -33,6 +34,7 @@ class MiFileTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -51,6 +53,7 @@ class MiFileTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -68,6 +71,7 @@ class MiFileTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiGdbSetShow.py b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiGdbSetShow.py
index 9b575c49bcb0a..6bb7619e60b8d 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiGdbSetShow.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiGdbSetShow.py
@@ -20,6 +20,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
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."""
@@ -42,6 +43,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
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."""
@@ -75,6 +77,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -101,6 +104,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
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."""
@@ -114,6 +118,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
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."""
@@ -138,6 +143,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
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."""
@@ -151,6 +157,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
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."""
@@ -165,6 +172,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
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."""
@@ -211,6 +219,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
@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):
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiLibraryLoaded.py b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiLibraryLoaded.py
index 68d670c9cd1e9..a597ae1397ad7 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiLibraryLoaded.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiLibraryLoaded.py
@@ -17,6 +17,7 @@ class MiLibraryLoadedTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiPrompt.py b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiPrompt.py
index b853673211bb2..20e48ac8dc7c9 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiPrompt.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiPrompt.py
@@ -17,6 +17,7 @@ class MiPromptTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/TestMiBreak.py b/packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/TestMiBreak.py
index 38c6b1f0b179c..16f71fe8130c0 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/TestMiBreak.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/TestMiBreak.py
@@ -19,6 +19,7 @@ class MiBreakTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -45,6 +46,7 @@ class MiBreakTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -113,6 +115,7 @@ class MiBreakTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -142,6 +145,7 @@ class MiBreakTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -179,6 +183,7 @@ class MiBreakTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -206,6 +211,7 @@ class MiBreakTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -220,38 +226,47 @@ class MiBreakTestCase(lldbmi_testcase.MiTestCaseBase):
self.runCmd(
"-interpreter-exec console \"settings set target.move-to-nearest-code off\"")
self.expect("\^done")
- line = line_number('main.cpp', '// BP_before_main')
- self.runCmd("-break-insert -f main.cpp:%d" % line)
+ 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)
+ self.runCmd("-break-insert main.cpp:%d" % line_in)
self.expect(
"\^error,msg=\"Command 'break-insert'. Breakpoint location 'main.cpp:%d' not found\"" %
- line)
+ line_in)
# Set target.move-to-nearest-code=on and target.skip-prologue=on and
- # set BP #3
+ # 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)
+ 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 #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)
- self.expect("\^done,bkpt={number=\"4\"")
+ self.runCmd("-break-insert main.cpp:%d" % line_decl)
+ self.expect("\^done,bkpt={number=\"5\"")
- # Test that BP #4 is located before BP #3
+ # 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
@@ -260,7 +275,7 @@ class MiBreakTestCase(lldbmi_testcase.MiTestCaseBase):
self.expect(
"\*stopped,reason=\"breakpoint-hit\",disp=\"del\",bkptno=\"3\"")
- # Test that the target.language=pascal setting works and that BP #5 is
+ # 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\"")
@@ -268,16 +283,16 @@ class MiBreakTestCase(lldbmi_testcase.MiTestCaseBase):
self.runCmd("-break-insert ns.foo1")
self.expect("\^error")
- # Test that the target.language=c++ setting works and that BP #6 is hit
+ # 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=\"6\"")
+ self.expect("\^done,bkpt={number=\"7\"")
self.runCmd("-exec-continue")
self.expect("\^running")
self.expect(
- "\*stopped,reason=\"breakpoint-hit\",disp=\"del\",bkptno=\"6\"")
+ "\*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")
@@ -286,6 +301,7 @@ class MiBreakTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/main.cpp b/packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/main.cpp
index 9416a0d01c7db..366c53c3143fe 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/main.cpp
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/breakpoint/main.cpp
@@ -15,13 +15,16 @@ namespace ns
int foo2(void) { printf("In foo2\n"); return 2; }
}
-// BP_before_main
-
int x;
-int
-main(int argc, char const *argv[])
-{
+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
}
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/control/TestMiExec.py b/packages/Python/lldbsuite/test/tools/lldb-mi/control/TestMiExec.py
index 2c0de4238c38e..b4e90c71721c2 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/control/TestMiExec.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/control/TestMiExec.py
@@ -260,7 +260,7 @@ class MiExecTestCase(lldbmi_testcase.MiTestCaseBase):
self.expect("\^running")
# Depending on compiler, it can stop at different line
self.expect(
- "\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"(29|30|31)\"")
+ "\*stopped,reason=\"end-stepping-range\".+?main\.cpp\",line=\"(28|29|30|31)\"")
# Test that an invalid --thread is handled
self.runCmd("-exec-next-instruction --thread 0")
@@ -382,7 +382,17 @@ class MiExecTestCase(lldbmi_testcase.MiTestCaseBase):
# Test that -exec-step-instruction steps into g_MyFunction
# instruction (and that --thread is optional)
- self.runCmd("-exec-step-instruction --frame 0")
+
+ # In case of MIPS, there might be more than one instruction
+ # before actual call instruction (like load, move and call instructions).
+ # The -exec-step-instruction would step one assembly instruction.
+ # Thus we may not enter into g_MyFunction function. The -exec-step would definitely
+ # step into the function.
+
+ if self.isMIPS():
+ self.runCmd("-exec-step --frame 0")
+ else:
+ self.runCmd("-exec-step-instruction --frame 0")
self.expect("\^running")
self.expect(
"\*stopped,reason=\"end-stepping-range\".+?func=\"g_MyFunction.*?\"")
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/data/TestMiData.py b/packages/Python/lldbsuite/test/tools/lldb-mi/data/TestMiData.py
index 7281ae305dbeb..0b521812384e4 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/data/TestMiData.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/data/TestMiData.py
@@ -77,7 +77,13 @@ class MiDataTestCase(lldbmi_testcase.MiTestCaseBase):
# 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
- self.expect(["{address=\"0x[0-9a-f]+\",func-name=\"hello_world\(\)\",offset=\"[0-9]+\",size=\"[0-9]+\",inst=\".+?; \\\\\"Hello, World!\\\\\\\\n\\\\\"\"}",
+
+ # 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\"}"])
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/interpreter/TestMiCliSupport.py b/packages/Python/lldbsuite/test/tools/lldb-mi/interpreter/TestMiCliSupport.py
index 24b3881c1be14..7a28f297a1c8a 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/interpreter/TestMiCliSupport.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/interpreter/TestMiCliSupport.py
@@ -17,6 +17,7 @@ class MiCliSupportTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -36,6 +37,7 @@ class MiCliSupportTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -59,6 +61,7 @@ class MiCliSupportTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -84,6 +87,7 @@ class MiCliSupportTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -109,6 +113,7 @@ class MiCliSupportTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -132,6 +137,7 @@ class MiCliSupportTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -164,6 +170,7 @@ class MiCliSupportTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -189,6 +196,7 @@ class MiCliSupportTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/interpreter/TestMiInterpreterExec.py b/packages/Python/lldbsuite/test/tools/lldb-mi/interpreter/TestMiInterpreterExec.py
index 23da825d591b6..2f207928db7df 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/interpreter/TestMiInterpreterExec.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/interpreter/TestMiInterpreterExec.py
@@ -17,6 +17,7 @@ class MiInterpreterExecTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -37,6 +38,7 @@ class MiInterpreterExecTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -60,6 +62,7 @@ class MiInterpreterExecTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -95,6 +98,7 @@ class MiInterpreterExecTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -138,6 +142,7 @@ class MiInterpreterExecTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -160,6 +165,7 @@ class MiInterpreterExecTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -191,6 +197,7 @@ class MiInterpreterExecTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
@@ -216,6 +223,7 @@ class MiInterpreterExecTestCase(lldbmi_testcase.MiTestCaseBase):
@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."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/Makefile b/packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/Makefile
new file mode 100644
index 0000000000000..314f1cb2f077b
--- /dev/null
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/TestMiLexicalScope.py b/packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/TestMiLexicalScope.py
new file mode 100644
index 0000000000000..a4186fdc4d01f
--- /dev/null
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/TestMiLexicalScope.py
@@ -0,0 +1,68 @@
+"""
+Test lldb-mi -stack-list-locals -stack-list-variables and -var-create commands
+for variables with the same name in sibling lexical scopes.
+"""
+
+from __future__ import print_function
+
+
+import lldbmi_testcase
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class MiLexicalScopeTestCase(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_var_create_in_sibling_scope(self):
+ """Test that 'lldb-mi --interpreter' works with sibling lexical scopes."""
+
+ self.spawnLldbMi(args=None)
+
+ # Load executable
+ self.runCmd("-file-exec-and-symbols %s" % self.myexe)
+ self.expect("\^done")
+
+ # Breakpoint inside first scope
+ line = line_number('main.cpp', '// BP_first')
+ self.runCmd("-break-insert --file main.cpp:%d" % line)
+ self.expect("\^done,bkpt={number=\"\d+\"")
+
+ # Breakpoint inside second scope
+ line = line_number('main.cpp', '// BP_second')
+ self.runCmd("-break-insert --file main.cpp:%d" % line)
+ self.expect("\^done,bkpt={number=\"\d+\"")
+
+ # Run to the first scope
+ self.runCmd("-exec-run")
+ self.expect("\^running")
+ self.expect("\*stopped,reason=\"breakpoint-hit\"")
+
+ # Check that only variables a and b exist with expected values
+ self.runCmd("-stack-list-locals --thread 1 --frame 0 --all-values")
+ self.expect("\^done,locals=\[{name=\"a\",value=\"1\"},{name=\"b\",value=\"2\"}\]")
+
+ # Create variable object for local variable b
+ self.runCmd("-var-create - * \"b\"")
+ self.expect(
+ "\^done,name=\"var\d+\",numchild=\"0\",value=\"2\",type=\"int\",thread-id=\"1\",has_more=\"0\"")
+
+ # Run to the second scope
+ self.runCmd("-exec-continue")
+ self.expect("\^running")
+ self.expect("\*stopped,reason=\"breakpoint-hit\"")
+
+ # Check that only variables a and b exist with expected values,
+ # but variable b is different from previous breakpoint
+ self.runCmd("-stack-list-variables --thread 1 --frame 0 --all-values")
+ self.expect("\^done,variables=\[{name=\"a\",value=\"1\"},{name=\"b\",value=\"3\"}\]")
+
+ # Create variable object for local variable b
+ self.runCmd("-var-create - * \"b\"")
+ self.expect(
+ "\^done,name=\"var\d+\",numchild=\"0\",value=\"3\",type=\"short\",thread-id=\"1\",has_more=\"0\"")
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/main.cpp b/packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/main.cpp
new file mode 100644
index 0000000000000..b9a7bff37af1a
--- /dev/null
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/lexical_scope/main.cpp
@@ -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.
+//
+//===----------------------------------------------------------------------===//
+
+void
+some_func (void)
+{
+}
+
+void test_sibling_scope (void)
+{
+ int a = 1;
+ {
+ int b = 2;
+ some_func(); // BP_first
+ }
+ {
+ short b = 3;
+ some_func(); // BP_second
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ test_sibling_scope();
+ return 0;
+}
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/signal/TestMiSignal.py b/packages/Python/lldbsuite/test/tools/lldb-mi/signal/TestMiSignal.py
index e4cd98b229289..597969dd6c53a 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/signal/TestMiSignal.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/signal/TestMiSignal.py
@@ -17,6 +17,7 @@ class MiSignalTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Fails on FreeBSD apparently due to thread race conditions
+ @skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_stopped_when_interrupt(self):
"""Test that 'lldb-mi --interpreter' interrupt and resume a looping app."""
@@ -56,6 +57,7 @@ class MiSignalTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Fails on FreeBSD apparently due to thread race conditions
@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_stopped_when_stopatentry_local(self):
"""Test that 'lldb-mi --interpreter' notifies after it was stopped on entry (local)."""
@@ -88,6 +90,7 @@ class MiSignalTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipUnlessDarwin
+ @skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_stopped_when_stopatentry_remote(self):
"""Test that 'lldb-mi --interpreter' notifies after it was stopped on entry (remote)."""
@@ -134,6 +137,7 @@ class MiSignalTestCase(lldbmi_testcase.MiTestCaseBase):
@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_stopped_when_segfault_local(self):
"""Test that 'lldb-mi --interpreter' notifies after it was stopped when segfault occurred (local)."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/symbol/TestMiSymbol.py b/packages/Python/lldbsuite/test/tools/lldb-mi/symbol/TestMiSymbol.py
index 23374330ba1fa..6ac9bf8135639 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/symbol/TestMiSymbol.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/symbol/TestMiSymbol.py
@@ -17,6 +17,7 @@ class MiSymbolTestCase(lldbmi_testcase.MiTestCaseBase):
@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(
oslist=["linux"],
bugnumber="new failure after r256863")
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/syntax/TestMiSyntax.py b/packages/Python/lldbsuite/test/tools/lldb-mi/syntax/TestMiSyntax.py
index 8e45c95927bae..93f599317c6cc 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/syntax/TestMiSyntax.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/syntax/TestMiSyntax.py
@@ -18,6 +18,7 @@ class MiSyntaxTestCase(lldbmi_testcase.MiTestCaseBase):
@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_tokens(self):
"""Test that 'lldb-mi --interpreter' prints command tokens."""
@@ -41,6 +42,7 @@ class MiSyntaxTestCase(lldbmi_testcase.MiTestCaseBase):
@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_specialchars(self):
"""Test that 'lldb-mi --interpreter' handles complicated strings."""
@@ -66,6 +68,7 @@ class MiSyntaxTestCase(lldbmi_testcase.MiTestCaseBase):
@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(
oslist=["linux"],
bugnumber="Failing in ~6/600 dosep runs (build 3120-3122)")
@@ -88,6 +91,7 @@ class MiSyntaxTestCase(lldbmi_testcase.MiTestCaseBase):
@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(oslist=["macosx"], bugnumber="rdar://28805064")
def test_lldbmi_output_grammar(self):
"""Test that 'lldb-mi --interpreter' uses standard output syntax."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/target/TestMiTarget.py b/packages/Python/lldbsuite/test/tools/lldb-mi/target/TestMiTarget.py
index 31a05ff402ed8..137408a2bd2b8 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/target/TestMiTarget.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/target/TestMiTarget.py
@@ -17,6 +17,7 @@ class MiTargetTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # cannot attach to process on linux
+ @skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_target_attach_wait_for(self):
"""Test that 'lldb-mi --interpreter' works for -target-attach -n <name> --waitfor."""
@@ -59,6 +60,7 @@ class MiTargetTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # cannot attach to process on linux
+ @skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_target_attach_name(self):
"""Test that 'lldb-mi --interpreter' works for -target-attach -n <name>."""
@@ -95,6 +97,7 @@ class MiTargetTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
@skipIfLinux # cannot attach to process on linux
+ @skipIfRemote # We do not currently support remote debugging via the MI.
def test_lldbmi_target_attach_pid(self):
"""Test that 'lldb-mi --interpreter' works for -target-attach <pid>."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py b/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
index 729674e6e1118..f9830e6d20242 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/threadinfo/TestMiThreadInfo.py
@@ -16,6 +16,7 @@ class MiThreadInfoTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # pthreads not supported 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_info(self):
"""Test that -thread-info prints thread info and the current-thread-id"""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py b/packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
index 61d54cab055a9..4384c79fc8459 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
@@ -34,6 +34,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # llvm.org/pr24452: Get lldb-mi 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_gdb_set_show_print_char_array_as_string(self):
"""Test that 'lldb-mi --interpreter' can print array of chars as string."""
@@ -173,6 +174,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # llvm.org/pr24452: Get lldb-mi working on Windows
@expectedFailureAll(compiler="gcc", bugnumber="llvm.org/pr23357")
@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_show_print_expand_aggregates(self):
"""Test that 'lldb-mi --interpreter' can expand aggregates everywhere."""
@@ -247,6 +249,7 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # llvm.org/pr24452: Get lldb-mi working on Windows
@expectedFailureAll(compiler="gcc", bugnumber="llvm.org/pr23357")
@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_show_print_aggregate_field_names(self):
"""Test that 'lldb-mi --interpreter' can expand aggregates everywhere."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiVar.py b/packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiVar.py
index b76b59ab97e31..d4685d39791af 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiVar.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiVar.py
@@ -17,6 +17,7 @@ class MiVarTestCase(lldbmi_testcase.MiTestCaseBase):
@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_eval(self):
"""Test that 'lldb-mi --interpreter' works for evaluating."""
@@ -158,6 +159,7 @@ class MiVarTestCase(lldbmi_testcase.MiTestCaseBase):
@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_var_update(self):
"""Test that 'lldb-mi --interpreter' works for -var-update."""
@@ -227,6 +229,7 @@ class MiVarTestCase(lldbmi_testcase.MiTestCaseBase):
@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_var_create_register(self):
"""Test that 'lldb-mi --interpreter' works for -var-create $regname."""
@@ -270,6 +273,7 @@ class MiVarTestCase(lldbmi_testcase.MiTestCaseBase):
@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_var_list_children(self):
"""Test that 'lldb-mi --interpreter' works for -var-list-children."""
@@ -389,6 +393,7 @@ class MiVarTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # llvm.org/pr24452: Get lldb-mi 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_var_create_for_stl_types(self):
"""Test that 'lldb-mi --interpreter' print summary for STL types."""
@@ -414,6 +419,7 @@ class MiVarTestCase(lldbmi_testcase.MiTestCaseBase):
@skipIfWindows # llvm.org/pr24452: Get lldb-mi 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_var_create_for_unnamed_objects(self):
"""Test that 'lldb-mi --interpreter' can expand unnamed structures and unions."""
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/.clang-format b/packages/Python/lldbsuite/test/tools/lldb-server/.clang-format
new file mode 100644
index 0000000000000..9b3aa8b7213b2
--- /dev/null
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/.clang-format
@@ -0,0 +1 @@
+BasedOnStyle: LLVM
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/host-info/TestGdbRemoteHostInfo.py b/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteHostInfo.py
index 5089ee85773f5..5089ee85773f5 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-server/host-info/TestGdbRemoteHostInfo.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteHostInfo.py
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py b/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
index 57d4d5ab4bb1c..b361b9e6d9157 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
@@ -1,11 +1,13 @@
from __future__ import print_function
+import json
+import re
+
import gdbremote_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
-
class TestGdbRemoteThreadsInStopReply(
gdbremote_testcase.GdbRemoteTestCaseBase):
@@ -16,7 +18,8 @@ class TestGdbRemoteThreadsInStopReply(
"send packet: $OK#00",
]
- def gather_stop_reply_threads(self, post_startup_log_lines, thread_count):
+ def gather_stop_reply_fields(self, post_startup_log_lines, thread_count,
+ field_names):
# Set up the inferior args.
inferior_args = []
for i in range(thread_count - 1):
@@ -25,6 +28,9 @@ class TestGdbRemoteThreadsInStopReply(
procs = self.prep_debug_monitor_and_inferior(
inferior_args=inferior_args)
+ self.add_register_info_collection_packets()
+ self.add_process_info_collection_packets()
+
# Assumes test_sequence has anything added needed to setup the initial state.
# (Like optionally enabling QThreadsInStopReply.)
if post_startup_log_lines:
@@ -34,6 +40,7 @@ class TestGdbRemoteThreadsInStopReply(
], True)
context = self.expect_gdbremote_sequence()
self.assertIsNotNone(context)
+ hw_info = self.parse_hw_info(context)
# Give threads time to start up, then break.
time.sleep(1)
@@ -77,14 +84,89 @@ class TestGdbRemoteThreadsInStopReply(
kv_dict = self.parse_key_val_dict(key_vals_text)
self.assertIsNotNone(kv_dict)
+ result = dict();
+ result["pc_register"] = hw_info["pc_register"]
+ result["little_endian"] = hw_info["little_endian"]
+ for key_field in field_names:
+ result[key_field] = kv_dict.get(key_field)
+
+ return result
+
+ def gather_stop_reply_threads(self, post_startup_log_lines, thread_count):
# Pull out threads from stop response.
- stop_reply_threads_text = kv_dict.get("threads")
+ stop_reply_threads_text = self.gather_stop_reply_fields(
+ post_startup_log_lines, thread_count, ["threads"])["threads"]
if stop_reply_threads_text:
return [int(thread_id, 16)
for thread_id in stop_reply_threads_text.split(",")]
else:
return []
+ def gather_stop_reply_pcs(self, post_startup_log_lines, thread_count):
+ results = self.gather_stop_reply_fields( post_startup_log_lines,
+ thread_count, ["threads", "thread-pcs"])
+ if not results:
+ return []
+
+ threads_text = results["threads"]
+ pcs_text = results["thread-pcs"]
+ thread_ids = threads_text.split(",")
+ pcs = pcs_text.split(",")
+ self.assertTrue(len(thread_ids) == len(pcs))
+
+ thread_pcs = dict()
+ for i in range(0, len(pcs)):
+ thread_pcs[int(thread_ids[i], 16)] = pcs[i]
+
+ result = dict()
+ result["thread_pcs"] = thread_pcs
+ result["pc_register"] = results["pc_register"]
+ result["little_endian"] = results["little_endian"]
+ return result
+
+ def switch_endian(self, egg):
+ return "".join(reversed(re.findall("..", egg)))
+
+ def parse_hw_info(self, context):
+ self.assertIsNotNone(context)
+ process_info = self.parse_process_info_response(context)
+ endian = process_info.get("endian")
+ reg_info = self.parse_register_info_packets(context)
+ (pc_lldb_reg_index, pc_reg_info) = self.find_pc_reg_info(reg_info)
+
+ hw_info = dict()
+ hw_info["pc_register"] = pc_lldb_reg_index
+ hw_info["little_endian"] = (endian == "little")
+ return hw_info
+
+ def gather_threads_info_pcs(self, pc_register, little_endian):
+ self.reset_test_sequence()
+ self.test_sequence.add_log_lines(
+ [
+ "read packet: $jThreadsInfo#c1",
+ {
+ "direction": "send",
+ "regex": r"^\$(.*)#[0-9a-fA-F]{2}$",
+ "capture": {
+ 1: "threads_info"}},
+ ],
+ True)
+
+ context = self.expect_gdbremote_sequence()
+ self.assertIsNotNone(context)
+ threads_info = context.get("threads_info")
+ register = str(pc_register)
+ # The jThreadsInfo response is not valid JSON data, so we have to
+ # clean it up first.
+ jthreads_info = json.loads(re.sub(r"}]", "}", threads_info))
+ thread_pcs = dict()
+ for thread_info in jthreads_info:
+ tid = thread_info["tid"]
+ pc = thread_info["registers"][register]
+ thread_pcs[tid] = self.switch_endian(pc) if little_endian else pc
+
+ return thread_pcs
+
def QListThreadsInStopReply_supported(self):
procs = self.prep_debug_monitor_and_inferior()
self.test_sequence.add_log_lines(
@@ -183,3 +265,34 @@ class TestGdbRemoteThreadsInStopReply(
self.build()
self.set_inferior_startup_launch()
self.stop_reply_reports_correct_threads(5)
+
+ def stop_reply_contains_thread_pcs(self, thread_count):
+ results = self.gather_stop_reply_pcs(
+ self.ENABLE_THREADS_IN_STOP_REPLY_ENTRIES, thread_count)
+ stop_reply_pcs = results["thread_pcs"]
+ pc_register = results["pc_register"]
+ little_endian = results["little_endian"]
+ self.assertEqual(len(stop_reply_pcs), thread_count)
+
+ threads_info_pcs = self.gather_threads_info_pcs(pc_register,
+ little_endian)
+
+ self.assertEqual(len(threads_info_pcs), thread_count)
+ for thread_id in stop_reply_pcs:
+ self.assertTrue(thread_id in threads_info_pcs)
+ self.assertTrue(int(stop_reply_pcs[thread_id], 16)
+ == int(threads_info_pcs[thread_id], 16))
+
+ @llgs_test
+ def test_stop_reply_contains_thread_pcs_llgs(self):
+ self.init_llgs_test()
+ self.build()
+ self.set_inferior_startup_launch()
+ self.stop_reply_contains_thread_pcs(5)
+
+ @debugserver_test
+ def test_stop_reply_contains_thread_pcs_debugserver(self):
+ self.init_debugserver_test()
+ self.build()
+ self.set_inferior_startup_launch()
+ self.stop_reply_contains_thread_pcs(5)
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py b/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py
index b69ac3f8d2a30..6f36fbea470b0 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py
@@ -1082,7 +1082,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod
self.set_inferior_startup_launch()
self.qMemoryRegionInfo_reports_heap_address_as_readable_writeable()
- def software_breakpoint_set_and_remove_work(self):
+ def breakpoint_set_and_remove_work(self, want_hardware=False):
# Start up the inferior.
procs = self.prep_debug_monitor_and_inferior(
inferior_args=[
@@ -1126,15 +1126,27 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod
self.assertIsNotNone(context.get("function_address"))
function_address = int(context.get("function_address"), 16)
+ # Get current target architecture
+ target_arch = self.getArchitecture()
+
# Set the breakpoint.
- if self.getArchitecture() == "arm":
+ if (target_arch == "arm") or (target_arch == "aarch64"):
# TODO: Handle case when setting breakpoint in thumb code
BREAKPOINT_KIND = 4
else:
BREAKPOINT_KIND = 1
+
+ # Set default packet type to Z0 (software breakpoint)
+ z_packet_type = 0
+
+ # If hardware breakpoint is requested set packet type to Z1
+ if want_hardware == True:
+ z_packet_type = 1
+
self.reset_test_sequence()
self.add_set_breakpoint_packets(
function_address,
+ z_packet_type,
do_continue=True,
breakpoint_kind=BREAKPOINT_KIND)
@@ -1182,13 +1194,15 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod
# Verify that a breakpoint remove and continue gets us the expected
# output.
self.reset_test_sequence()
+
+ # Add breakpoint remove packets
+ self.add_remove_breakpoint_packets(
+ function_address,
+ z_packet_type,
+ breakpoint_kind=BREAKPOINT_KIND)
+
self.test_sequence.add_log_lines(
[
- # Remove the breakpoint.
- "read packet: $z0,{0:x},{1}#00".format(
- function_address, BREAKPOINT_KIND),
- # Verify the stub could unset it.
- "send packet: $OK#00",
# Continue running.
"read packet: $c#63",
# We should now receive the output from the call.
@@ -1209,7 +1223,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod
else:
self.build()
self.set_inferior_startup_launch()
- self.software_breakpoint_set_and_remove_work()
+ self.breakpoint_set_and_remove_work(want_hardware=False)
@llgs_test
@expectedFlakeyLinux("llvm.org/pr25652")
@@ -1221,7 +1235,35 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase, DwarfOpcod
else:
self.build()
self.set_inferior_startup_launch()
- self.software_breakpoint_set_and_remove_work()
+ self.breakpoint_set_and_remove_work(want_hardware=False)
+
+ @debugserver_test
+ @skipUnlessPlatform(oslist=['linux'])
+ @expectedFailureAndroid
+ @skipIf(archs=no_match(['arm', 'aarch64']))
+ def test_hardware_breakpoint_set_and_remove_work_debugserver(self):
+ self.init_debugserver_test()
+ if self.getArchitecture() == "arm":
+ # TODO: Handle case when setting breakpoint in thumb code
+ self.build(dictionary={'CFLAGS_EXTRAS': '-marm'})
+ else:
+ self.build()
+ self.set_inferior_startup_launch()
+ self.breakpoint_set_and_remove_work(want_hardware=True)
+
+ @llgs_test
+ @skipUnlessPlatform(oslist=['linux'])
+ @expectedFailureAndroid
+ @skipIf(archs=no_match(['arm', 'aarch64']))
+ def test_hardware_breakpoint_set_and_remove_work_llgs(self):
+ self.init_llgs_test()
+ if self.getArchitecture() == "arm":
+ # TODO: Handle case when setting breakpoint in thumb code
+ self.build(dictionary={'CFLAGS_EXTRAS': '-marm'})
+ else:
+ self.build()
+ self.set_inferior_startup_launch()
+ self.breakpoint_set_and_remove_work(want_hardware=True)
def qSupported_returns_known_stub_features(self):
# Start up the stub and start/prep the inferior.
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/exit-code/main.cpp b/packages/Python/lldbsuite/test/tools/lldb-server/exit-code/main.cpp
index b97c6ebc18e33..a3691a8d42b90 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-server/exit-code/main.cpp
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/exit-code/main.cpp
@@ -15,22 +15,24 @@
#if defined(__APPLE__)
__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
-int pthread_threadid_np(pthread_t,__uint64_t*);
+int pthread_threadid_np(pthread_t, __uint64_t *);
#elif defined(__linux__)
#include <sys/syscall.h>
+#elif defined(__NetBSD__)
+#include <lwp.h>
#endif
-static const char *const RETVAL_PREFIX = "retval:";
-static const char *const SLEEP_PREFIX = "sleep:";
-static const char *const STDERR_PREFIX = "stderr:";
-static const char *const SET_MESSAGE_PREFIX = "set-message:";
-static const char *const PRINT_MESSAGE_COMMAND = "print-message:";
-static const char *const GET_DATA_ADDRESS_PREFIX = "get-data-address-hex:";
-static const char *const GET_STACK_ADDRESS_COMMAND = "get-stack-address-hex:";
-static const char *const GET_HEAP_ADDRESS_COMMAND = "get-heap-address-hex:";
+static const char *const RETVAL_PREFIX = "retval:";
+static const char *const SLEEP_PREFIX = "sleep:";
+static const char *const STDERR_PREFIX = "stderr:";
+static const char *const SET_MESSAGE_PREFIX = "set-message:";
+static const char *const PRINT_MESSAGE_COMMAND = "print-message:";
+static const char *const GET_DATA_ADDRESS_PREFIX = "get-data-address-hex:";
+static const char *const GET_STACK_ADDRESS_COMMAND = "get-stack-address-hex:";
+static const char *const GET_HEAP_ADDRESS_COMMAND = "get-heap-address-hex:";
-static const char *const GET_CODE_ADDRESS_PREFIX = "get-code-address-hex:";
-static const char *const CALL_FUNCTION_PREFIX = "call-function:";
+static const char *const GET_CODE_ADDRESS_PREFIX = "get-code-address-hex:";
+static const char *const CALL_FUNCTION_PREFIX = "call-function:";
static const char *const THREAD_PREFIX = "thread:";
static const char *const THREAD_COMMAND_NEW = "new";
@@ -50,342 +52,304 @@ static char g_message[256];
static volatile char g_c1 = '0';
static volatile char g_c2 = '1';
-static void
-print_thread_id ()
-{
- // Put in the right magic here for your platform to spit out the thread id (tid) that debugserver/lldb-gdbserver would see as a TID.
- // Otherwise, let the else clause print out the unsupported text so that the unit test knows to skip verifying thread ids.
+static void print_thread_id() {
+// Put in the right magic here for your platform to spit out the thread id (tid)
+// that debugserver/lldb-gdbserver would see as a TID. Otherwise, let the else
+// clause print out the unsupported text so that the unit test knows to skip
+// verifying thread ids.
#if defined(__APPLE__)
- __uint64_t tid = 0;
- pthread_threadid_np(pthread_self(), &tid);
- printf ("%" PRIx64, tid);
-#elif defined (__linux__)
- // This is a call to gettid() via syscall.
- printf ("%" PRIx64, static_cast<uint64_t> (syscall (__NR_gettid)));
+ __uint64_t tid = 0;
+ pthread_threadid_np(pthread_self(), &tid);
+ printf("%" PRIx64, tid);
+#elif defined(__linux__)
+ // This is a call to gettid() via syscall.
+ printf("%" PRIx64, static_cast<uint64_t>(syscall(__NR_gettid)));
+#elif defined(__NetBSD__)
+ // Technically lwpid_t is 32-bit signed integer
+ printf("%" PRIx64, static_cast<uint64_t>(_lwp_self()));
#else
- printf("{no-tid-support}");
+ printf("{no-tid-support}");
#endif
}
-static void
-signal_handler (int signo)
-{
- const char *signal_name = nullptr;
- switch (signo)
- {
- case SIGUSR1: signal_name = "SIGUSR1"; break;
- case SIGSEGV: signal_name = "SIGSEGV"; break;
- default: signal_name = nullptr;
- }
-
- // Print notice that we received the signal on a given thread.
- pthread_mutex_lock (&g_print_mutex);
- if (signal_name)
- printf ("received %s on thread id: ", signal_name);
- else
- printf ("received signo %d (%s) on thread id: ", signo, strsignal (signo));
- print_thread_id ();
- printf ("\n");
- pthread_mutex_unlock (&g_print_mutex);
-
- // Reset the signal handler if we're one of the expected signal handlers.
- switch (signo)
- {
- case SIGSEGV:
- if (g_is_segfaulting)
- {
- // Fix up the pointer we're writing to. This needs to happen if nothing intercepts the SIGSEGV
- // (i.e. if somebody runs this from the command line).
- longjmp(g_jump_buffer, 1);
- }
- break;
- case SIGUSR1:
- if (g_is_segfaulting)
- {
- // Fix up the pointer we're writing to. This is used to test gdb remote signal delivery.
- // A SIGSEGV will be raised when the thread is created, switched out for a SIGUSR1, and
- // then this code still needs to fix the seg fault.
- // (i.e. if somebody runs this from the command line).
- longjmp(g_jump_buffer, 1);
- }
- break;
- }
-
- // Reset the signal handler.
- sig_t sig_result = signal (signo, signal_handler);
- if (sig_result == SIG_ERR)
- {
- fprintf(stderr, "failed to set signal handler: errno=%d\n", errno);
- exit (1);
- }
+static void signal_handler(int signo) {
+ const char *signal_name = nullptr;
+ switch (signo) {
+ case SIGUSR1:
+ signal_name = "SIGUSR1";
+ break;
+ case SIGSEGV:
+ signal_name = "SIGSEGV";
+ break;
+ default:
+ signal_name = nullptr;
+ }
+
+ // Print notice that we received the signal on a given thread.
+ pthread_mutex_lock(&g_print_mutex);
+ if (signal_name)
+ printf("received %s on thread id: ", signal_name);
+ else
+ printf("received signo %d (%s) on thread id: ", signo, strsignal(signo));
+ print_thread_id();
+ printf("\n");
+ pthread_mutex_unlock(&g_print_mutex);
+
+ // Reset the signal handler if we're one of the expected signal handlers.
+ switch (signo) {
+ case SIGSEGV:
+ if (g_is_segfaulting) {
+ // Fix up the pointer we're writing to. This needs to happen if nothing
+ // intercepts the SIGSEGV (i.e. if somebody runs this from the command
+ // line).
+ longjmp(g_jump_buffer, 1);
+ }
+ break;
+ case SIGUSR1:
+ if (g_is_segfaulting) {
+ // Fix up the pointer we're writing to. This is used to test gdb remote
+ // signal delivery. A SIGSEGV will be raised when the thread is created,
+ // switched out for a SIGUSR1, and then this code still needs to fix the
+ // seg fault. (i.e. if somebody runs this from the command line).
+ longjmp(g_jump_buffer, 1);
+ }
+ break;
+ }
+
+ // Reset the signal handler.
+ sig_t sig_result = signal(signo, signal_handler);
+ if (sig_result == SIG_ERR) {
+ fprintf(stderr, "failed to set signal handler: errno=%d\n", errno);
+ exit(1);
+ }
}
-static void
-swap_chars ()
-{
- g_c1 = '1';
- g_c2 = '0';
+static void swap_chars() {
+ g_c1 = '1';
+ g_c2 = '0';
- g_c1 = '0';
- g_c2 = '1';
+ g_c1 = '0';
+ g_c2 = '1';
}
-static void
-hello ()
-{
- pthread_mutex_lock (&g_print_mutex);
- printf ("hello, world\n");
- pthread_mutex_unlock (&g_print_mutex);
+static void hello() {
+ pthread_mutex_lock(&g_print_mutex);
+ printf("hello, world\n");
+ pthread_mutex_unlock(&g_print_mutex);
}
-static void*
-thread_func (void *arg)
-{
- static pthread_mutex_t s_thread_index_mutex = PTHREAD_MUTEX_INITIALIZER;
- static int s_thread_index = 1;
-
- pthread_mutex_lock (&s_thread_index_mutex);
- const int this_thread_index = s_thread_index++;
- pthread_mutex_unlock (&s_thread_index_mutex);
-
- if (g_print_thread_ids)
- {
- pthread_mutex_lock (&g_print_mutex);
- printf ("thread %d id: ", this_thread_index);
- print_thread_id ();
- printf ("\n");
- pthread_mutex_unlock (&g_print_mutex);
- }
-
- if (g_threads_do_segfault)
- {
- // Sleep for a number of seconds based on the thread index.
- // TODO add ability to send commands to test exe so we can
- // handle timing more precisely. This is clunky. All we're
- // trying to do is add predictability as to the timing of
- // signal generation by created threads.
- int sleep_seconds = 2 * (this_thread_index - 1);
- while (sleep_seconds > 0)
- sleep_seconds = sleep(sleep_seconds);
-
- // Test creating a SEGV.
- pthread_mutex_lock (&g_jump_buffer_mutex);
- g_is_segfaulting = true;
- int *bad_p = nullptr;
- if (setjmp(g_jump_buffer) == 0)
- {
- // Force a seg fault signal on this thread.
- *bad_p = 0;
- }
- else
- {
- // Tell the system we're no longer seg faulting.
- // Used by the SIGUSR1 signal handler that we inject
- // in place of the SIGSEGV so it only tries to
- // recover from the SIGSEGV if this seg fault code
- // was in play.
- g_is_segfaulting = false;
- }
- pthread_mutex_unlock (&g_jump_buffer_mutex);
-
- pthread_mutex_lock (&g_print_mutex);
- printf ("thread ");
- print_thread_id ();
- printf (": past SIGSEGV\n");
- pthread_mutex_unlock (&g_print_mutex);
- }
-
- int sleep_seconds_remaining = 60;
- while (sleep_seconds_remaining > 0)
- {
- sleep_seconds_remaining = sleep (sleep_seconds_remaining);
- }
-
- return nullptr;
+static void *thread_func(void *arg) {
+ static pthread_mutex_t s_thread_index_mutex = PTHREAD_MUTEX_INITIALIZER;
+ static int s_thread_index = 1;
+
+ pthread_mutex_lock(&s_thread_index_mutex);
+ const int this_thread_index = s_thread_index++;
+ pthread_mutex_unlock(&s_thread_index_mutex);
+
+ if (g_print_thread_ids) {
+ pthread_mutex_lock(&g_print_mutex);
+ printf("thread %d id: ", this_thread_index);
+ print_thread_id();
+ printf("\n");
+ pthread_mutex_unlock(&g_print_mutex);
+ }
+
+ if (g_threads_do_segfault) {
+ // Sleep for a number of seconds based on the thread index.
+ // TODO add ability to send commands to test exe so we can
+ // handle timing more precisely. This is clunky. All we're
+ // trying to do is add predictability as to the timing of
+ // signal generation by created threads.
+ int sleep_seconds = 2 * (this_thread_index - 1);
+ while (sleep_seconds > 0)
+ sleep_seconds = sleep(sleep_seconds);
+
+ // Test creating a SEGV.
+ pthread_mutex_lock(&g_jump_buffer_mutex);
+ g_is_segfaulting = true;
+ int *bad_p = nullptr;
+ if (setjmp(g_jump_buffer) == 0) {
+ // Force a seg fault signal on this thread.
+ *bad_p = 0;
+ } else {
+ // Tell the system we're no longer seg faulting.
+ // Used by the SIGUSR1 signal handler that we inject
+ // in place of the SIGSEGV so it only tries to
+ // recover from the SIGSEGV if this seg fault code
+ // was in play.
+ g_is_segfaulting = false;
+ }
+ pthread_mutex_unlock(&g_jump_buffer_mutex);
+
+ pthread_mutex_lock(&g_print_mutex);
+ printf("thread ");
+ print_thread_id();
+ printf(": past SIGSEGV\n");
+ pthread_mutex_unlock(&g_print_mutex);
+ }
+
+ int sleep_seconds_remaining = 60;
+ while (sleep_seconds_remaining > 0) {
+ sleep_seconds_remaining = sleep(sleep_seconds_remaining);
+ }
+
+ return nullptr;
}
-int main (int argc, char **argv)
-{
- lldb_enable_attach();
-
- std::vector<pthread_t> threads;
- std::unique_ptr<uint8_t[]> heap_array_up;
- int return_value = 0;
-
- // Set the signal handler.
- sig_t sig_result = signal (SIGALRM, signal_handler);
- if (sig_result == SIG_ERR)
- {
- fprintf(stderr, "failed to set SIGALRM signal handler: errno=%d\n", errno);
- exit (1);
- }
-
- sig_result = signal (SIGUSR1, signal_handler);
- if (sig_result == SIG_ERR)
- {
- fprintf(stderr, "failed to set SIGUSR1 handler: errno=%d\n", errno);
- exit (1);
- }
-
- sig_result = signal (SIGSEGV, signal_handler);
- if (sig_result == SIG_ERR)
- {
- fprintf(stderr, "failed to set SIGUSR1 handler: errno=%d\n", errno);
- exit (1);
- }
-
- // Process command line args.
- for (int i = 1; i < argc; ++i)
- {
- if (std::strstr (argv[i], STDERR_PREFIX))
- {
- // Treat remainder as text to go to stderr.
- fprintf (stderr, "%s\n", (argv[i] + strlen (STDERR_PREFIX)));
- }
- else if (std::strstr (argv[i], RETVAL_PREFIX))
- {
- // Treat as the return value for the program.
- return_value = std::atoi (argv[i] + strlen (RETVAL_PREFIX));
- }
- else if (std::strstr (argv[i], SLEEP_PREFIX))
- {
- // Treat as the amount of time to have this process sleep (in seconds).
- int sleep_seconds_remaining = std::atoi (argv[i] + strlen (SLEEP_PREFIX));
-
- // Loop around, sleeping until all sleep time is used up. Note that
- // signals will cause sleep to end early with the number of seconds remaining.
- for (int i = 0; sleep_seconds_remaining > 0; ++i)
- {
- sleep_seconds_remaining = sleep (sleep_seconds_remaining);
- // std::cout << "sleep result (call " << i << "): " << sleep_seconds_remaining << std::endl;
- }
- }
- else if (std::strstr (argv[i], SET_MESSAGE_PREFIX))
- {
- // Copy the contents after "set-message:" to the g_message buffer.
- // Used for reading inferior memory and verifying contents match expectations.
- strncpy (g_message, argv[i] + strlen (SET_MESSAGE_PREFIX), sizeof (g_message));
-
- // Ensure we're null terminated.
- g_message[sizeof (g_message) - 1] = '\0';
-
- }
- else if (std::strstr (argv[i], PRINT_MESSAGE_COMMAND))
- {
- pthread_mutex_lock (&g_print_mutex);
- printf ("message: %s\n", g_message);
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i], GET_DATA_ADDRESS_PREFIX))
- {
- volatile void *data_p = nullptr;
-
- if (std::strstr (argv[i] + strlen (GET_DATA_ADDRESS_PREFIX), "g_message"))
- data_p = &g_message[0];
- else if (std::strstr (argv[i] + strlen (GET_DATA_ADDRESS_PREFIX), "g_c1"))
- data_p = &g_c1;
- else if (std::strstr (argv[i] + strlen (GET_DATA_ADDRESS_PREFIX), "g_c2"))
- data_p = &g_c2;
-
- pthread_mutex_lock (&g_print_mutex);
- printf ("data address: %p\n", data_p);
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i], GET_HEAP_ADDRESS_COMMAND))
- {
- // Create a byte array if not already present.
- if (!heap_array_up)
- heap_array_up.reset (new uint8_t[32]);
-
- pthread_mutex_lock (&g_print_mutex);
- printf ("heap address: %p\n", heap_array_up.get ());
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i], GET_STACK_ADDRESS_COMMAND))
- {
- pthread_mutex_lock (&g_print_mutex);
- printf ("stack address: %p\n", &return_value);
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i], GET_CODE_ADDRESS_PREFIX))
- {
- void (*func_p)() = nullptr;
-
- if (std::strstr (argv[i] + strlen (GET_CODE_ADDRESS_PREFIX), "hello"))
- func_p = hello;
- else if (std::strstr (argv[i] + strlen (GET_CODE_ADDRESS_PREFIX), "swap_chars"))
- func_p = swap_chars;
-
- pthread_mutex_lock (&g_print_mutex);
- printf ("code address: %p\n", func_p);
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i], CALL_FUNCTION_PREFIX))
- {
- // Defaut to providing the address of main.
- if (std::strcmp (argv[i] + strlen (CALL_FUNCTION_PREFIX), "hello") == 0)
- hello();
- else if (std::strcmp (argv[i] + strlen (CALL_FUNCTION_PREFIX), "swap_chars") == 0)
- swap_chars();
- else
- {
- pthread_mutex_lock (&g_print_mutex);
- printf ("unknown function: %s\n", argv[i] + strlen (CALL_FUNCTION_PREFIX));
- pthread_mutex_unlock (&g_print_mutex);
- }
- }
- else if (std::strstr (argv[i], THREAD_PREFIX))
- {
- // Check if we're creating a new thread.
- if (std::strstr (argv[i] + strlen(THREAD_PREFIX), THREAD_COMMAND_NEW))
- {
- // Create a new thread.
- pthread_t new_thread;
- const int err = ::pthread_create (&new_thread, nullptr, thread_func, nullptr);
- if (err)
- {
- fprintf (stderr, "pthread_create() failed with error code %d\n", err);
- exit (err);
- }
- threads.push_back (new_thread);
- }
- else if (std::strstr (argv[i] + strlen(THREAD_PREFIX), THREAD_COMMAND_PRINT_IDS))
- {
- // Turn on thread id announcing.
- g_print_thread_ids = true;
-
- // And announce us.
- pthread_mutex_lock (&g_print_mutex);
- printf ("thread 0 id: ");
- print_thread_id ();
- printf ("\n");
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i] + strlen(THREAD_PREFIX), THREAD_COMMAND_SEGFAULT))
- {
- g_threads_do_segfault = true;
- }
- else
- {
- // At this point we don't do anything else with threads.
- // Later use thread index and send command to thread.
- }
- }
- else
- {
- // Treat the argument as text for stdout.
- printf("%s\n", argv[i]);
+int main(int argc, char **argv) {
+ lldb_enable_attach();
+
+ std::vector<pthread_t> threads;
+ std::unique_ptr<uint8_t[]> heap_array_up;
+ int return_value = 0;
+
+ // Set the signal handler.
+ sig_t sig_result = signal(SIGALRM, signal_handler);
+ if (sig_result == SIG_ERR) {
+ fprintf(stderr, "failed to set SIGALRM signal handler: errno=%d\n", errno);
+ exit(1);
+ }
+
+ sig_result = signal(SIGUSR1, signal_handler);
+ if (sig_result == SIG_ERR) {
+ fprintf(stderr, "failed to set SIGUSR1 handler: errno=%d\n", errno);
+ exit(1);
+ }
+
+ sig_result = signal(SIGSEGV, signal_handler);
+ if (sig_result == SIG_ERR) {
+ fprintf(stderr, "failed to set SIGUSR1 handler: errno=%d\n", errno);
+ exit(1);
+ }
+
+ // Process command line args.
+ for (int i = 1; i < argc; ++i) {
+ if (std::strstr(argv[i], STDERR_PREFIX)) {
+ // Treat remainder as text to go to stderr.
+ fprintf(stderr, "%s\n", (argv[i] + strlen(STDERR_PREFIX)));
+ } else if (std::strstr(argv[i], RETVAL_PREFIX)) {
+ // Treat as the return value for the program.
+ return_value = std::atoi(argv[i] + strlen(RETVAL_PREFIX));
+ } else if (std::strstr(argv[i], SLEEP_PREFIX)) {
+ // Treat as the amount of time to have this process sleep (in seconds).
+ int sleep_seconds_remaining = std::atoi(argv[i] + strlen(SLEEP_PREFIX));
+
+ // Loop around, sleeping until all sleep time is used up. Note that
+ // signals will cause sleep to end early with the number of seconds
+ // remaining.
+ for (int i = 0; sleep_seconds_remaining > 0; ++i) {
+ sleep_seconds_remaining = sleep(sleep_seconds_remaining);
+ // std::cout << "sleep result (call " << i << "): " <<
+ // sleep_seconds_remaining << std::endl;
+ }
+ } else if (std::strstr(argv[i], SET_MESSAGE_PREFIX)) {
+ // Copy the contents after "set-message:" to the g_message buffer.
+ // Used for reading inferior memory and verifying contents match
+ // expectations.
+ strncpy(g_message, argv[i] + strlen(SET_MESSAGE_PREFIX),
+ sizeof(g_message));
+
+ // Ensure we're null terminated.
+ g_message[sizeof(g_message) - 1] = '\0';
+
+ } else if (std::strstr(argv[i], PRINT_MESSAGE_COMMAND)) {
+ pthread_mutex_lock(&g_print_mutex);
+ printf("message: %s\n", g_message);
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i], GET_DATA_ADDRESS_PREFIX)) {
+ volatile void *data_p = nullptr;
+
+ if (std::strstr(argv[i] + strlen(GET_DATA_ADDRESS_PREFIX), "g_message"))
+ data_p = &g_message[0];
+ else if (std::strstr(argv[i] + strlen(GET_DATA_ADDRESS_PREFIX), "g_c1"))
+ data_p = &g_c1;
+ else if (std::strstr(argv[i] + strlen(GET_DATA_ADDRESS_PREFIX), "g_c2"))
+ data_p = &g_c2;
+
+ pthread_mutex_lock(&g_print_mutex);
+ printf("data address: %p\n", data_p);
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i], GET_HEAP_ADDRESS_COMMAND)) {
+ // Create a byte array if not already present.
+ if (!heap_array_up)
+ heap_array_up.reset(new uint8_t[32]);
+
+ pthread_mutex_lock(&g_print_mutex);
+ printf("heap address: %p\n", heap_array_up.get());
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i], GET_STACK_ADDRESS_COMMAND)) {
+ pthread_mutex_lock(&g_print_mutex);
+ printf("stack address: %p\n", &return_value);
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i], GET_CODE_ADDRESS_PREFIX)) {
+ void (*func_p)() = nullptr;
+
+ if (std::strstr(argv[i] + strlen(GET_CODE_ADDRESS_PREFIX), "hello"))
+ func_p = hello;
+ else if (std::strstr(argv[i] + strlen(GET_CODE_ADDRESS_PREFIX),
+ "swap_chars"))
+ func_p = swap_chars;
+
+ pthread_mutex_lock(&g_print_mutex);
+ printf("code address: %p\n", func_p);
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i], CALL_FUNCTION_PREFIX)) {
+ // Defaut to providing the address of main.
+ if (std::strcmp(argv[i] + strlen(CALL_FUNCTION_PREFIX), "hello") == 0)
+ hello();
+ else if (std::strcmp(argv[i] + strlen(CALL_FUNCTION_PREFIX),
+ "swap_chars") == 0)
+ swap_chars();
+ else {
+ pthread_mutex_lock(&g_print_mutex);
+ printf("unknown function: %s\n",
+ argv[i] + strlen(CALL_FUNCTION_PREFIX));
+ pthread_mutex_unlock(&g_print_mutex);
+ }
+ } else if (std::strstr(argv[i], THREAD_PREFIX)) {
+ // Check if we're creating a new thread.
+ if (std::strstr(argv[i] + strlen(THREAD_PREFIX), THREAD_COMMAND_NEW)) {
+ // Create a new thread.
+ pthread_t new_thread;
+ const int err =
+ ::pthread_create(&new_thread, nullptr, thread_func, nullptr);
+ if (err) {
+ fprintf(stderr, "pthread_create() failed with error code %d\n", err);
+ exit(err);
}
+ threads.push_back(new_thread);
+ } else if (std::strstr(argv[i] + strlen(THREAD_PREFIX),
+ THREAD_COMMAND_PRINT_IDS)) {
+ // Turn on thread id announcing.
+ g_print_thread_ids = true;
+
+ // And announce us.
+ pthread_mutex_lock(&g_print_mutex);
+ printf("thread 0 id: ");
+ print_thread_id();
+ printf("\n");
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i] + strlen(THREAD_PREFIX),
+ THREAD_COMMAND_SEGFAULT)) {
+ g_threads_do_segfault = true;
+ } else {
+ // At this point we don't do anything else with threads.
+ // Later use thread index and send command to thread.
+ }
+ } else {
+ // Treat the argument as text for stdout.
+ printf("%s\n", argv[i]);
}
-
- // If we launched any threads, join them
- for (std::vector<pthread_t>::iterator it = threads.begin (); it != threads.end (); ++it)
- {
- void *thread_retval = nullptr;
- const int err = ::pthread_join (*it, &thread_retval);
- if (err != 0)
- fprintf (stderr, "pthread_join() failed with error code %d\n", err);
- }
-
- return return_value;
+ }
+
+ // If we launched any threads, join them
+ for (std::vector<pthread_t>::iterator it = threads.begin();
+ it != threads.end(); ++it) {
+ void *thread_retval = nullptr;
+ const int err = ::pthread_join(*it, &thread_retval);
+ if (err != 0)
+ fprintf(stderr, "pthread_join() failed with error code %d\n", err);
+ }
+
+ return return_value;
}
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
index ef6a0a21aaeb5..23cb869358572 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -883,12 +883,13 @@ class GdbRemoteTestCaseBase(TestBase):
def add_set_breakpoint_packets(
self,
address,
+ z_packet_type=0,
do_continue=True,
breakpoint_kind=1):
self.test_sequence.add_log_lines(
[ # Set the breakpoint.
- "read packet: $Z0,{0:x},{1}#00".format(
- address, breakpoint_kind),
+ "read packet: $Z{2},{0:x},{1}#00".format(
+ address, breakpoint_kind, z_packet_type),
# Verify the stub could set it.
"send packet: $OK#00",
], True)
@@ -904,11 +905,15 @@ class GdbRemoteTestCaseBase(TestBase):
2: "stop_thread_id"}},
], True)
- def add_remove_breakpoint_packets(self, address, breakpoint_kind=1):
+ def add_remove_breakpoint_packets(
+ self,
+ address,
+ z_packet_type=0,
+ breakpoint_kind=1):
self.test_sequence.add_log_lines(
[ # Remove the breakpoint.
- "read packet: $z0,{0:x},{1}#00".format(
- address, breakpoint_kind),
+ "read packet: $z{2},{0:x},{1}#00".format(
+ address, breakpoint_kind, z_packet_type),
# Verify the stub could unset it.
"send packet: $OK#00",
], True)
@@ -929,7 +934,8 @@ class GdbRemoteTestCaseBase(TestBase):
"qXfer:libraries:read",
"qXfer:libraries-svr4:read",
"qXfer:features:read",
- "qEcho"
+ "qEcho",
+ "QPassSignals"
]
def parse_qSupported_response(self, context):
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/main.cpp b/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/main.cpp
index 69d60071aa455..ced7f7125088e 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/main.cpp
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/main.cpp
@@ -2,38 +2,30 @@
#include <cstring>
#include <iostream>
-namespace
-{
- const char *const SEGFAULT_COMMAND = "segfault";
- const char *const ABORT_COMMAND = "abort";
+namespace {
+const char *const SEGFAULT_COMMAND = "segfault";
+const char *const ABORT_COMMAND = "abort";
}
-int main (int argc, char **argv)
-{
- if (argc < 2)
- {
- std::cout << "expected at least one command provided on the command line" << std::endl;
- }
+int main(int argc, char **argv) {
+ if (argc < 2) {
+ std::cout << "expected at least one command provided on the command line"
+ << std::endl;
+ }
- // Process command line args.
- for (int i = 1; i < argc; ++i)
- {
- const char *const command = argv[i];
- if (std::strstr (command, SEGFAULT_COMMAND))
- {
- // Perform a null pointer access.
- int *const null_int_ptr = nullptr;
- *null_int_ptr = 0xDEAD;
- }
- else if (std::strstr (command, ABORT_COMMAND))
- {
- std::abort();
- }
- else
- {
- std::cout << "Unsupported command: " << command << std::endl;
- }
+ // Process command line args.
+ for (int i = 1; i < argc; ++i) {
+ const char *const command = argv[i];
+ if (std::strstr(command, SEGFAULT_COMMAND)) {
+ // Perform a null pointer access.
+ int *const null_int_ptr = nullptr;
+ *null_int_ptr = 0xDEAD;
+ } else if (std::strstr(command, ABORT_COMMAND)) {
+ std::abort();
+ } else {
+ std::cout << "Unsupported command: " << command << std::endl;
}
+ }
- return 0;
+ return 0;
}
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/main.cpp b/packages/Python/lldbsuite/test/tools/lldb-server/main.cpp
index b97c6ebc18e33..a574b41abf670 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-server/main.cpp
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/main.cpp
@@ -1,3 +1,12 @@
+//===-- 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 <cstdlib>
#include <cstring>
#include <errno.h>
@@ -15,22 +24,24 @@
#if defined(__APPLE__)
__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
-int pthread_threadid_np(pthread_t,__uint64_t*);
+int pthread_threadid_np(pthread_t, __uint64_t *);
#elif defined(__linux__)
#include <sys/syscall.h>
+#elif defined(__NetBSD__)
+#include <lwp.h>
#endif
-static const char *const RETVAL_PREFIX = "retval:";
-static const char *const SLEEP_PREFIX = "sleep:";
-static const char *const STDERR_PREFIX = "stderr:";
-static const char *const SET_MESSAGE_PREFIX = "set-message:";
-static const char *const PRINT_MESSAGE_COMMAND = "print-message:";
-static const char *const GET_DATA_ADDRESS_PREFIX = "get-data-address-hex:";
-static const char *const GET_STACK_ADDRESS_COMMAND = "get-stack-address-hex:";
-static const char *const GET_HEAP_ADDRESS_COMMAND = "get-heap-address-hex:";
+static const char *const RETVAL_PREFIX = "retval:";
+static const char *const SLEEP_PREFIX = "sleep:";
+static const char *const STDERR_PREFIX = "stderr:";
+static const char *const SET_MESSAGE_PREFIX = "set-message:";
+static const char *const PRINT_MESSAGE_COMMAND = "print-message:";
+static const char *const GET_DATA_ADDRESS_PREFIX = "get-data-address-hex:";
+static const char *const GET_STACK_ADDRESS_COMMAND = "get-stack-address-hex:";
+static const char *const GET_HEAP_ADDRESS_COMMAND = "get-heap-address-hex:";
-static const char *const GET_CODE_ADDRESS_PREFIX = "get-code-address-hex:";
-static const char *const CALL_FUNCTION_PREFIX = "call-function:";
+static const char *const GET_CODE_ADDRESS_PREFIX = "get-code-address-hex:";
+static const char *const CALL_FUNCTION_PREFIX = "call-function:";
static const char *const THREAD_PREFIX = "thread:";
static const char *const THREAD_COMMAND_NEW = "new";
@@ -50,342 +61,304 @@ static char g_message[256];
static volatile char g_c1 = '0';
static volatile char g_c2 = '1';
-static void
-print_thread_id ()
-{
- // Put in the right magic here for your platform to spit out the thread id (tid) that debugserver/lldb-gdbserver would see as a TID.
- // Otherwise, let the else clause print out the unsupported text so that the unit test knows to skip verifying thread ids.
+static void print_thread_id() {
+// Put in the right magic here for your platform to spit out the thread id (tid)
+// that debugserver/lldb-gdbserver would see as a TID. Otherwise, let the else
+// clause print out the unsupported text so that the unit test knows to skip
+// verifying thread ids.
#if defined(__APPLE__)
- __uint64_t tid = 0;
- pthread_threadid_np(pthread_self(), &tid);
- printf ("%" PRIx64, tid);
-#elif defined (__linux__)
- // This is a call to gettid() via syscall.
- printf ("%" PRIx64, static_cast<uint64_t> (syscall (__NR_gettid)));
+ __uint64_t tid = 0;
+ pthread_threadid_np(pthread_self(), &tid);
+ printf("%" PRIx64, tid);
+#elif defined(__linux__)
+ // This is a call to gettid() via syscall.
+ printf("%" PRIx64, static_cast<uint64_t>(syscall(__NR_gettid)));
+#elif defined(__NetBSD__)
+ // Technically lwpid_t is 32-bit signed integer
+ printf("%" PRIx64, static_cast<uint64_t>(_lwp_self()));
#else
- printf("{no-tid-support}");
+ printf("{no-tid-support}");
#endif
}
-static void
-signal_handler (int signo)
-{
- const char *signal_name = nullptr;
- switch (signo)
- {
- case SIGUSR1: signal_name = "SIGUSR1"; break;
- case SIGSEGV: signal_name = "SIGSEGV"; break;
- default: signal_name = nullptr;
- }
-
- // Print notice that we received the signal on a given thread.
- pthread_mutex_lock (&g_print_mutex);
- if (signal_name)
- printf ("received %s on thread id: ", signal_name);
- else
- printf ("received signo %d (%s) on thread id: ", signo, strsignal (signo));
- print_thread_id ();
- printf ("\n");
- pthread_mutex_unlock (&g_print_mutex);
-
- // Reset the signal handler if we're one of the expected signal handlers.
- switch (signo)
- {
- case SIGSEGV:
- if (g_is_segfaulting)
- {
- // Fix up the pointer we're writing to. This needs to happen if nothing intercepts the SIGSEGV
- // (i.e. if somebody runs this from the command line).
- longjmp(g_jump_buffer, 1);
- }
- break;
- case SIGUSR1:
- if (g_is_segfaulting)
- {
- // Fix up the pointer we're writing to. This is used to test gdb remote signal delivery.
- // A SIGSEGV will be raised when the thread is created, switched out for a SIGUSR1, and
- // then this code still needs to fix the seg fault.
- // (i.e. if somebody runs this from the command line).
- longjmp(g_jump_buffer, 1);
- }
- break;
- }
-
- // Reset the signal handler.
- sig_t sig_result = signal (signo, signal_handler);
- if (sig_result == SIG_ERR)
- {
- fprintf(stderr, "failed to set signal handler: errno=%d\n", errno);
- exit (1);
- }
+static void signal_handler(int signo) {
+ const char *signal_name = nullptr;
+ switch (signo) {
+ case SIGUSR1:
+ signal_name = "SIGUSR1";
+ break;
+ case SIGSEGV:
+ signal_name = "SIGSEGV";
+ break;
+ default:
+ signal_name = nullptr;
+ }
+
+ // Print notice that we received the signal on a given thread.
+ pthread_mutex_lock(&g_print_mutex);
+ if (signal_name)
+ printf("received %s on thread id: ", signal_name);
+ else
+ printf("received signo %d (%s) on thread id: ", signo, strsignal(signo));
+ print_thread_id();
+ printf("\n");
+ pthread_mutex_unlock(&g_print_mutex);
+
+ // Reset the signal handler if we're one of the expected signal handlers.
+ switch (signo) {
+ case SIGSEGV:
+ if (g_is_segfaulting) {
+ // Fix up the pointer we're writing to. This needs to happen if nothing
+ // intercepts the SIGSEGV (i.e. if somebody runs this from the command
+ // line).
+ longjmp(g_jump_buffer, 1);
+ }
+ break;
+ case SIGUSR1:
+ if (g_is_segfaulting) {
+ // Fix up the pointer we're writing to. This is used to test gdb remote
+ // signal delivery. A SIGSEGV will be raised when the thread is created,
+ // switched out for a SIGUSR1, and then this code still needs to fix the
+ // seg fault. (i.e. if somebody runs this from the command line).
+ longjmp(g_jump_buffer, 1);
+ }
+ break;
+ }
+
+ // Reset the signal handler.
+ sig_t sig_result = signal(signo, signal_handler);
+ if (sig_result == SIG_ERR) {
+ fprintf(stderr, "failed to set signal handler: errno=%d\n", errno);
+ exit(1);
+ }
}
-static void
-swap_chars ()
-{
- g_c1 = '1';
- g_c2 = '0';
+static void swap_chars() {
+ g_c1 = '1';
+ g_c2 = '0';
- g_c1 = '0';
- g_c2 = '1';
+ g_c1 = '0';
+ g_c2 = '1';
}
-static void
-hello ()
-{
- pthread_mutex_lock (&g_print_mutex);
- printf ("hello, world\n");
- pthread_mutex_unlock (&g_print_mutex);
+static void hello() {
+ pthread_mutex_lock(&g_print_mutex);
+ printf("hello, world\n");
+ pthread_mutex_unlock(&g_print_mutex);
}
-static void*
-thread_func (void *arg)
-{
- static pthread_mutex_t s_thread_index_mutex = PTHREAD_MUTEX_INITIALIZER;
- static int s_thread_index = 1;
-
- pthread_mutex_lock (&s_thread_index_mutex);
- const int this_thread_index = s_thread_index++;
- pthread_mutex_unlock (&s_thread_index_mutex);
-
- if (g_print_thread_ids)
- {
- pthread_mutex_lock (&g_print_mutex);
- printf ("thread %d id: ", this_thread_index);
- print_thread_id ();
- printf ("\n");
- pthread_mutex_unlock (&g_print_mutex);
- }
-
- if (g_threads_do_segfault)
- {
- // Sleep for a number of seconds based on the thread index.
- // TODO add ability to send commands to test exe so we can
- // handle timing more precisely. This is clunky. All we're
- // trying to do is add predictability as to the timing of
- // signal generation by created threads.
- int sleep_seconds = 2 * (this_thread_index - 1);
- while (sleep_seconds > 0)
- sleep_seconds = sleep(sleep_seconds);
-
- // Test creating a SEGV.
- pthread_mutex_lock (&g_jump_buffer_mutex);
- g_is_segfaulting = true;
- int *bad_p = nullptr;
- if (setjmp(g_jump_buffer) == 0)
- {
- // Force a seg fault signal on this thread.
- *bad_p = 0;
- }
- else
- {
- // Tell the system we're no longer seg faulting.
- // Used by the SIGUSR1 signal handler that we inject
- // in place of the SIGSEGV so it only tries to
- // recover from the SIGSEGV if this seg fault code
- // was in play.
- g_is_segfaulting = false;
- }
- pthread_mutex_unlock (&g_jump_buffer_mutex);
-
- pthread_mutex_lock (&g_print_mutex);
- printf ("thread ");
- print_thread_id ();
- printf (": past SIGSEGV\n");
- pthread_mutex_unlock (&g_print_mutex);
- }
-
- int sleep_seconds_remaining = 60;
- while (sleep_seconds_remaining > 0)
- {
- sleep_seconds_remaining = sleep (sleep_seconds_remaining);
- }
-
- return nullptr;
+static void *thread_func(void *arg) {
+ static pthread_mutex_t s_thread_index_mutex = PTHREAD_MUTEX_INITIALIZER;
+ static int s_thread_index = 1;
+
+ pthread_mutex_lock(&s_thread_index_mutex);
+ const int this_thread_index = s_thread_index++;
+ pthread_mutex_unlock(&s_thread_index_mutex);
+
+ if (g_print_thread_ids) {
+ pthread_mutex_lock(&g_print_mutex);
+ printf("thread %d id: ", this_thread_index);
+ print_thread_id();
+ printf("\n");
+ pthread_mutex_unlock(&g_print_mutex);
+ }
+
+ if (g_threads_do_segfault) {
+ // Sleep for a number of seconds based on the thread index.
+ // TODO add ability to send commands to test exe so we can
+ // handle timing more precisely. This is clunky. All we're
+ // trying to do is add predictability as to the timing of
+ // signal generation by created threads.
+ int sleep_seconds = 2 * (this_thread_index - 1);
+ while (sleep_seconds > 0)
+ sleep_seconds = sleep(sleep_seconds);
+
+ // Test creating a SEGV.
+ pthread_mutex_lock(&g_jump_buffer_mutex);
+ g_is_segfaulting = true;
+ int *bad_p = nullptr;
+ if (setjmp(g_jump_buffer) == 0) {
+ // Force a seg fault signal on this thread.
+ *bad_p = 0;
+ } else {
+ // Tell the system we're no longer seg faulting.
+ // Used by the SIGUSR1 signal handler that we inject
+ // in place of the SIGSEGV so it only tries to
+ // recover from the SIGSEGV if this seg fault code
+ // was in play.
+ g_is_segfaulting = false;
+ }
+ pthread_mutex_unlock(&g_jump_buffer_mutex);
+
+ pthread_mutex_lock(&g_print_mutex);
+ printf("thread ");
+ print_thread_id();
+ printf(": past SIGSEGV\n");
+ pthread_mutex_unlock(&g_print_mutex);
+ }
+
+ int sleep_seconds_remaining = 60;
+ while (sleep_seconds_remaining > 0) {
+ sleep_seconds_remaining = sleep(sleep_seconds_remaining);
+ }
+
+ return nullptr;
}
-int main (int argc, char **argv)
-{
- lldb_enable_attach();
-
- std::vector<pthread_t> threads;
- std::unique_ptr<uint8_t[]> heap_array_up;
- int return_value = 0;
-
- // Set the signal handler.
- sig_t sig_result = signal (SIGALRM, signal_handler);
- if (sig_result == SIG_ERR)
- {
- fprintf(stderr, "failed to set SIGALRM signal handler: errno=%d\n", errno);
- exit (1);
- }
-
- sig_result = signal (SIGUSR1, signal_handler);
- if (sig_result == SIG_ERR)
- {
- fprintf(stderr, "failed to set SIGUSR1 handler: errno=%d\n", errno);
- exit (1);
- }
-
- sig_result = signal (SIGSEGV, signal_handler);
- if (sig_result == SIG_ERR)
- {
- fprintf(stderr, "failed to set SIGUSR1 handler: errno=%d\n", errno);
- exit (1);
- }
-
- // Process command line args.
- for (int i = 1; i < argc; ++i)
- {
- if (std::strstr (argv[i], STDERR_PREFIX))
- {
- // Treat remainder as text to go to stderr.
- fprintf (stderr, "%s\n", (argv[i] + strlen (STDERR_PREFIX)));
- }
- else if (std::strstr (argv[i], RETVAL_PREFIX))
- {
- // Treat as the return value for the program.
- return_value = std::atoi (argv[i] + strlen (RETVAL_PREFIX));
- }
- else if (std::strstr (argv[i], SLEEP_PREFIX))
- {
- // Treat as the amount of time to have this process sleep (in seconds).
- int sleep_seconds_remaining = std::atoi (argv[i] + strlen (SLEEP_PREFIX));
-
- // Loop around, sleeping until all sleep time is used up. Note that
- // signals will cause sleep to end early with the number of seconds remaining.
- for (int i = 0; sleep_seconds_remaining > 0; ++i)
- {
- sleep_seconds_remaining = sleep (sleep_seconds_remaining);
- // std::cout << "sleep result (call " << i << "): " << sleep_seconds_remaining << std::endl;
- }
- }
- else if (std::strstr (argv[i], SET_MESSAGE_PREFIX))
- {
- // Copy the contents after "set-message:" to the g_message buffer.
- // Used for reading inferior memory and verifying contents match expectations.
- strncpy (g_message, argv[i] + strlen (SET_MESSAGE_PREFIX), sizeof (g_message));
-
- // Ensure we're null terminated.
- g_message[sizeof (g_message) - 1] = '\0';
-
- }
- else if (std::strstr (argv[i], PRINT_MESSAGE_COMMAND))
- {
- pthread_mutex_lock (&g_print_mutex);
- printf ("message: %s\n", g_message);
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i], GET_DATA_ADDRESS_PREFIX))
- {
- volatile void *data_p = nullptr;
-
- if (std::strstr (argv[i] + strlen (GET_DATA_ADDRESS_PREFIX), "g_message"))
- data_p = &g_message[0];
- else if (std::strstr (argv[i] + strlen (GET_DATA_ADDRESS_PREFIX), "g_c1"))
- data_p = &g_c1;
- else if (std::strstr (argv[i] + strlen (GET_DATA_ADDRESS_PREFIX), "g_c2"))
- data_p = &g_c2;
-
- pthread_mutex_lock (&g_print_mutex);
- printf ("data address: %p\n", data_p);
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i], GET_HEAP_ADDRESS_COMMAND))
- {
- // Create a byte array if not already present.
- if (!heap_array_up)
- heap_array_up.reset (new uint8_t[32]);
-
- pthread_mutex_lock (&g_print_mutex);
- printf ("heap address: %p\n", heap_array_up.get ());
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i], GET_STACK_ADDRESS_COMMAND))
- {
- pthread_mutex_lock (&g_print_mutex);
- printf ("stack address: %p\n", &return_value);
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i], GET_CODE_ADDRESS_PREFIX))
- {
- void (*func_p)() = nullptr;
-
- if (std::strstr (argv[i] + strlen (GET_CODE_ADDRESS_PREFIX), "hello"))
- func_p = hello;
- else if (std::strstr (argv[i] + strlen (GET_CODE_ADDRESS_PREFIX), "swap_chars"))
- func_p = swap_chars;
-
- pthread_mutex_lock (&g_print_mutex);
- printf ("code address: %p\n", func_p);
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i], CALL_FUNCTION_PREFIX))
- {
- // Defaut to providing the address of main.
- if (std::strcmp (argv[i] + strlen (CALL_FUNCTION_PREFIX), "hello") == 0)
- hello();
- else if (std::strcmp (argv[i] + strlen (CALL_FUNCTION_PREFIX), "swap_chars") == 0)
- swap_chars();
- else
- {
- pthread_mutex_lock (&g_print_mutex);
- printf ("unknown function: %s\n", argv[i] + strlen (CALL_FUNCTION_PREFIX));
- pthread_mutex_unlock (&g_print_mutex);
- }
- }
- else if (std::strstr (argv[i], THREAD_PREFIX))
- {
- // Check if we're creating a new thread.
- if (std::strstr (argv[i] + strlen(THREAD_PREFIX), THREAD_COMMAND_NEW))
- {
- // Create a new thread.
- pthread_t new_thread;
- const int err = ::pthread_create (&new_thread, nullptr, thread_func, nullptr);
- if (err)
- {
- fprintf (stderr, "pthread_create() failed with error code %d\n", err);
- exit (err);
- }
- threads.push_back (new_thread);
- }
- else if (std::strstr (argv[i] + strlen(THREAD_PREFIX), THREAD_COMMAND_PRINT_IDS))
- {
- // Turn on thread id announcing.
- g_print_thread_ids = true;
-
- // And announce us.
- pthread_mutex_lock (&g_print_mutex);
- printf ("thread 0 id: ");
- print_thread_id ();
- printf ("\n");
- pthread_mutex_unlock (&g_print_mutex);
- }
- else if (std::strstr (argv[i] + strlen(THREAD_PREFIX), THREAD_COMMAND_SEGFAULT))
- {
- g_threads_do_segfault = true;
- }
- else
- {
- // At this point we don't do anything else with threads.
- // Later use thread index and send command to thread.
- }
- }
- else
- {
- // Treat the argument as text for stdout.
- printf("%s\n", argv[i]);
+int main(int argc, char **argv) {
+ lldb_enable_attach();
+
+ std::vector<pthread_t> threads;
+ std::unique_ptr<uint8_t[]> heap_array_up;
+ int return_value = 0;
+
+ // Set the signal handler.
+ sig_t sig_result = signal(SIGALRM, signal_handler);
+ if (sig_result == SIG_ERR) {
+ fprintf(stderr, "failed to set SIGALRM signal handler: errno=%d\n", errno);
+ exit(1);
+ }
+
+ sig_result = signal(SIGUSR1, signal_handler);
+ if (sig_result == SIG_ERR) {
+ fprintf(stderr, "failed to set SIGUSR1 handler: errno=%d\n", errno);
+ exit(1);
+ }
+
+ sig_result = signal(SIGSEGV, signal_handler);
+ if (sig_result == SIG_ERR) {
+ fprintf(stderr, "failed to set SIGUSR1 handler: errno=%d\n", errno);
+ exit(1);
+ }
+
+ // Process command line args.
+ for (int i = 1; i < argc; ++i) {
+ if (std::strstr(argv[i], STDERR_PREFIX)) {
+ // Treat remainder as text to go to stderr.
+ fprintf(stderr, "%s\n", (argv[i] + strlen(STDERR_PREFIX)));
+ } else if (std::strstr(argv[i], RETVAL_PREFIX)) {
+ // Treat as the return value for the program.
+ return_value = std::atoi(argv[i] + strlen(RETVAL_PREFIX));
+ } else if (std::strstr(argv[i], SLEEP_PREFIX)) {
+ // Treat as the amount of time to have this process sleep (in seconds).
+ int sleep_seconds_remaining = std::atoi(argv[i] + strlen(SLEEP_PREFIX));
+
+ // Loop around, sleeping until all sleep time is used up. Note that
+ // signals will cause sleep to end early with the number of seconds
+ // remaining.
+ for (int i = 0; sleep_seconds_remaining > 0; ++i) {
+ sleep_seconds_remaining = sleep(sleep_seconds_remaining);
+ // std::cout << "sleep result (call " << i << "): " <<
+ // sleep_seconds_remaining << std::endl;
+ }
+ } else if (std::strstr(argv[i], SET_MESSAGE_PREFIX)) {
+ // Copy the contents after "set-message:" to the g_message buffer.
+ // Used for reading inferior memory and verifying contents match
+ // expectations.
+ strncpy(g_message, argv[i] + strlen(SET_MESSAGE_PREFIX),
+ sizeof(g_message));
+
+ // Ensure we're null terminated.
+ g_message[sizeof(g_message) - 1] = '\0';
+
+ } else if (std::strstr(argv[i], PRINT_MESSAGE_COMMAND)) {
+ pthread_mutex_lock(&g_print_mutex);
+ printf("message: %s\n", g_message);
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i], GET_DATA_ADDRESS_PREFIX)) {
+ volatile void *data_p = nullptr;
+
+ if (std::strstr(argv[i] + strlen(GET_DATA_ADDRESS_PREFIX), "g_message"))
+ data_p = &g_message[0];
+ else if (std::strstr(argv[i] + strlen(GET_DATA_ADDRESS_PREFIX), "g_c1"))
+ data_p = &g_c1;
+ else if (std::strstr(argv[i] + strlen(GET_DATA_ADDRESS_PREFIX), "g_c2"))
+ data_p = &g_c2;
+
+ pthread_mutex_lock(&g_print_mutex);
+ printf("data address: %p\n", data_p);
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i], GET_HEAP_ADDRESS_COMMAND)) {
+ // Create a byte array if not already present.
+ if (!heap_array_up)
+ heap_array_up.reset(new uint8_t[32]);
+
+ pthread_mutex_lock(&g_print_mutex);
+ printf("heap address: %p\n", heap_array_up.get());
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i], GET_STACK_ADDRESS_COMMAND)) {
+ pthread_mutex_lock(&g_print_mutex);
+ printf("stack address: %p\n", &return_value);
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i], GET_CODE_ADDRESS_PREFIX)) {
+ void (*func_p)() = nullptr;
+
+ if (std::strstr(argv[i] + strlen(GET_CODE_ADDRESS_PREFIX), "hello"))
+ func_p = hello;
+ else if (std::strstr(argv[i] + strlen(GET_CODE_ADDRESS_PREFIX),
+ "swap_chars"))
+ func_p = swap_chars;
+
+ pthread_mutex_lock(&g_print_mutex);
+ printf("code address: %p\n", func_p);
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i], CALL_FUNCTION_PREFIX)) {
+ // Defaut to providing the address of main.
+ if (std::strcmp(argv[i] + strlen(CALL_FUNCTION_PREFIX), "hello") == 0)
+ hello();
+ else if (std::strcmp(argv[i] + strlen(CALL_FUNCTION_PREFIX),
+ "swap_chars") == 0)
+ swap_chars();
+ else {
+ pthread_mutex_lock(&g_print_mutex);
+ printf("unknown function: %s\n",
+ argv[i] + strlen(CALL_FUNCTION_PREFIX));
+ pthread_mutex_unlock(&g_print_mutex);
+ }
+ } else if (std::strstr(argv[i], THREAD_PREFIX)) {
+ // Check if we're creating a new thread.
+ if (std::strstr(argv[i] + strlen(THREAD_PREFIX), THREAD_COMMAND_NEW)) {
+ // Create a new thread.
+ pthread_t new_thread;
+ const int err =
+ ::pthread_create(&new_thread, nullptr, thread_func, nullptr);
+ if (err) {
+ fprintf(stderr, "pthread_create() failed with error code %d\n", err);
+ exit(err);
}
+ threads.push_back(new_thread);
+ } else if (std::strstr(argv[i] + strlen(THREAD_PREFIX),
+ THREAD_COMMAND_PRINT_IDS)) {
+ // Turn on thread id announcing.
+ g_print_thread_ids = true;
+
+ // And announce us.
+ pthread_mutex_lock(&g_print_mutex);
+ printf("thread 0 id: ");
+ print_thread_id();
+ printf("\n");
+ pthread_mutex_unlock(&g_print_mutex);
+ } else if (std::strstr(argv[i] + strlen(THREAD_PREFIX),
+ THREAD_COMMAND_SEGFAULT)) {
+ g_threads_do_segfault = true;
+ } else {
+ // At this point we don't do anything else with threads.
+ // Later use thread index and send command to thread.
+ }
+ } else {
+ // Treat the argument as text for stdout.
+ printf("%s\n", argv[i]);
}
-
- // If we launched any threads, join them
- for (std::vector<pthread_t>::iterator it = threads.begin (); it != threads.end (); ++it)
- {
- void *thread_retval = nullptr;
- const int err = ::pthread_join (*it, &thread_retval);
- if (err != 0)
- fprintf (stderr, "pthread_join() failed with error code %d\n", err);
- }
-
- return return_value;
+ }
+
+ // If we launched any threads, join them
+ for (std::vector<pthread_t>::iterator it = threads.begin();
+ it != threads.end(); ++it) {
+ void *thread_retval = nullptr;
+ const int err = ::pthread_join(*it, &thread_retval);
+ if (err != 0)
+ fprintf(stderr, "pthread_join() failed with error code %d\n", err);
+ }
+
+ return return_value;
}
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/main.cpp b/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/main.cpp
index 70ae5094fde77..c7ebe0759a403 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/main.cpp
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/main.cpp
@@ -1,7 +1,6 @@
#include <cstdio>
-int main (int argc, char **argv)
-{
- printf("argc: %d\n", argc);
- return argv[0][0];
+int main(int argc, char **argv) {
+ printf("argc: %d\n", argc);
+ return argv[0][0];
}
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/Makefile b/packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/Makefile
new file mode 100644
index 0000000000000..314f1cb2f077b
--- /dev/null
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/TestGdbRemote_QPassSignals.py b/packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/TestGdbRemote_QPassSignals.py
new file mode 100644
index 0000000000000..7105bcb078bc6
--- /dev/null
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/TestGdbRemote_QPassSignals.py
@@ -0,0 +1,115 @@
+# This test makes sure that lldb-server supports and properly handles
+# QPassSignals GDB protocol package.
+from __future__ import print_function
+
+import gdbremote_testcase
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestGdbRemote_QPassSignals(gdbremote_testcase.GdbRemoteTestCaseBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def expect_signal(self, expected_signo):
+ self.test_sequence.add_log_lines(["read packet: $vCont;c#a8",
+ {"direction": "send",
+ "regex": r"^\$T([0-9a-fA-F]{2}).*#[0-9a-fA-F]{2}$",
+ "capture": {1: "hex_exit_code"}},
+ ],
+ True)
+
+ context = self.expect_gdbremote_sequence()
+ self.assertIsNotNone(context)
+
+ hex_exit_code = context.get("hex_exit_code")
+ self.assertIsNotNone(hex_exit_code)
+ self.assertEqual(int(hex_exit_code, 16), expected_signo)
+
+ def expect_exit_code(self, exit_code):
+ self.test_sequence.add_log_lines(
+ ["read packet: $vCont;c#a8",
+ "send packet: $W{0:02x}#00".format(exit_code)],
+ True)
+ self.expect_gdbremote_sequence()
+
+
+ def ignore_signals(self, signals):
+ def signal_name_to_hex(signame):
+ return format(lldbutil.get_signal_number(signame), 'x')
+ signals_str = ";".join(map(signal_name_to_hex, signals))
+
+ self.test_sequence.add_log_lines(["read packet: $QPassSignals:"
+ + signals_str + " #00",
+ "send packet: $OK#00"],
+ True)
+
+ context = self.expect_gdbremote_sequence()
+ self.assertIsNotNone(context)
+
+ @llgs_test
+ @skipUnlessPlatform(["linux", "android"])
+ def test_q_pass_signals(self):
+ self.init_llgs_test()
+ self.build()
+ self.set_inferior_startup_launch()
+ procs = self.prep_debug_monitor_and_inferior()
+ expected_signals = ["SIGSEGV",
+ "SIGALRM", "SIGFPE", "SIGBUS", "SIGINT", "SIGHUP"]
+ signals_to_ignore = ["SIGUSR1", "SIGUSR2"]
+ self.ignore_signals(signals_to_ignore)
+ for signal_name in expected_signals:
+ signo = lldbutil.get_signal_number(signal_name)
+ self.expect_signal(signo)
+ self.expect_exit_code(len(signals_to_ignore))
+
+ @llgs_test
+ @skipUnlessPlatform(["linux", "android"])
+ def test_change_signals_at_runtime(self):
+ self.init_llgs_test()
+ self.build()
+ self.set_inferior_startup_launch()
+ procs = self.prep_debug_monitor_and_inferior()
+ expected_signals = ["SIGSEGV", "SIGUSR1", "SIGUSR2",
+ "SIGALRM", "SIGHUP"]
+ signals_to_ignore = ["SIGFPE", "SIGBUS", "SIGINT"]
+
+ for signal_name in expected_signals:
+ signo = lldbutil.get_signal_number(signal_name)
+ self.expect_signal(signo)
+ if signal_name == "SIGALRM":
+ self.ignore_signals(signals_to_ignore)
+ self.expect_exit_code(len(signals_to_ignore))
+
+ @llgs_test
+ def test_default_signals_behavior(self):
+ self.init_llgs_test()
+ self.build()
+ self.set_inferior_startup_launch()
+ procs = self.prep_debug_monitor_and_inferior()
+ expected_signals = ["SIGSEGV", "SIGUSR1", "SIGUSR2",
+ "SIGALRM", "SIGFPE", "SIGBUS", "SIGINT", "SIGHUP"]
+ for signal_name in expected_signals:
+ signo = lldbutil.get_signal_number(signal_name)
+ self.expect_signal(signo)
+ self.expect_exit_code(0)
+
+
+ @llgs_test
+ @skipUnlessPlatform(["linux", "android"])
+ def test_support_q_pass_signals(self):
+ self.init_llgs_test()
+ self.build()
+
+ # Start up the stub and start/prep the inferior.
+ self.set_inferior_startup_launch()
+ procs = self.prep_debug_monitor_and_inferior()
+ self.add_qSupported_packets()
+
+ # Run the packet stream.
+ context = self.expect_gdbremote_sequence()
+ self.assertIsNotNone(context)
+
+ # Retrieve the qSupported features and check QPassSignals+
+ supported_dict = self.parse_qSupported_response(context)
+ self.assertEqual(supported_dict["QPassSignals"], "+")
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/main.cpp b/packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/main.cpp
new file mode 100644
index 0000000000000..4991259fe46ed
--- /dev/null
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/signal-filtering/main.cpp
@@ -0,0 +1,37 @@
+//===-- 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 <signal.h>
+#include <stdio.h>
+#include <vector>
+
+static int signal_counter = 0;
+
+static void count_signal(int signo) {
+ ++signal_counter;
+ printf("Signal %d\n", signo);
+}
+
+static void raise_signals() {
+ std::vector<int> signals(
+ {SIGSEGV, SIGUSR1, SIGUSR2, SIGALRM, SIGFPE, SIGBUS, SIGINT, SIGHUP});
+
+ for (int signal_num : signals) {
+ signal(signal_num, count_signal);
+ }
+
+ for (int signal_num : signals) {
+ raise(signal_num);
+ }
+}
+
+int main() {
+ raise_signals();
+ return signal_counter;
+}
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/host-info/Makefile b/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/Makefile
index 1370b53b5a67a..8817fff55e8c0 100644
--- a/packages/Python/lldbsuite/test/tools/lldb-server/host-info/Makefile
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/Makefile
@@ -1,10 +1,6 @@
LEVEL = ../../../make
-VPATH = ..
-
-override CFLAGS_EXTRAS += -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS
ENABLE_THREADS := YES
CXX_SOURCES := main.cpp
-MAKE_DSYM :=NO
include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py b/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py
new file mode 100644
index 0000000000000..5bfcd660c2ace
--- /dev/null
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/TestGdbRemoteThreadName.py
@@ -0,0 +1,41 @@
+from __future__ import print_function
+
+import gdbremote_testcase
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestGdbRemoteThreadName(gdbremote_testcase.GdbRemoteTestCaseBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def run_and_check_name(self, expected_name):
+ self.test_sequence.add_log_lines(["read packet: $vCont;c#a8",
+ {"direction": "send",
+ "regex":
+ r"^\$T([0-9a-fA-F]{2})([^#]+)#[0-9a-fA-F]{2}$",
+ "capture": {
+ 1: "signal",
+ 2: "key_vals_text"}},
+ ],
+ True)
+
+ context = self.expect_gdbremote_sequence()
+ self.assertIsNotNone(context)
+
+ sigint = lldbutil.get_signal_number("SIGINT")
+ self.assertEqual(sigint, int(context.get("signal"), 16))
+ kv_dict = self.parse_key_val_dict(context.get("key_vals_text"))
+ self.assertEqual(expected_name, kv_dict.get("name"))
+
+ @llgs_test
+ def test(self):
+ """ Make sure lldb-server can retrieve inferior thread name"""
+ self.init_llgs_test()
+ self.build()
+ self.set_inferior_startup_launch()
+ procs = self.prep_debug_monitor_and_inferior()
+
+ self.run_and_check_name("hello world")
+ self.run_and_check_name("goodbye world")
diff --git a/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp b/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp
new file mode 100644
index 0000000000000..0403031143ba5
--- /dev/null
+++ b/packages/Python/lldbsuite/test/tools/lldb-server/thread-name/main.cpp
@@ -0,0 +1,22 @@
+#include <pthread.h>
+#include <signal.h>
+
+void set_thread_name(const char *name) {
+#if defined(__APPLE__)
+ ::pthread_setname_np(name);
+#elif defined(__FreeBSD__)
+ ::pthread_set_name_np(::pthread_self(), name);
+#elif defined(__linux__)
+ ::pthread_setname_np(::pthread_self(), name);
+#elif defined(__NetBSD__)
+ ::pthread_setname_np(::pthread_self(), "%s", name);
+#endif
+}
+
+int main() {
+ set_thread_name("hello world");
+ raise(SIGINT);
+ set_thread_name("goodbye world");
+ raise(SIGINT);
+ return 0;
+}