Todd Fiala e77fce0a50 [NFC] Darwin llgs support from Week of Code
This code represents the Week of Code work I did on bringing up
lldb-server LLGS support for Darwin.  It does not include the
Xcode project changes needed, as we don't want to throw that switch
until more support is implemented (i.e. this change is inert, no
build systems use it yet.  I've verified on Ubuntu 16.04, macOS
Xcode and macOS cmake builds).

This change does some minimal refactoring of code that is shared
with the Linux LLGS portion, moving it from NativeProcessLinux into
NativeProcessProtocol.  That code is also used by NativeProcessDarwin.

Current state on Darwin:
* Process launching is implemented.  (Attach is not).
  Launching on devices has not yet been tested (FBS/BKS might
  need a bit of work).
* Inferior waitpid monitoring and communication of exit status
  via MainLoop callback is implemented.
* Memory read/write, breakpoints, thread register context, etc.
  are not yet implemented.  This impacts process stop/resume, as
  the initial launch suspended immediately starts the process
  up and running because it doesn't know it is supposed to remain
  stopped.
* I implemented the equivalent of MachThreadList as
  NativeThreadListDarwin, in anticipation that we might want to
  factor out common parts into NativeThreadList{Protocol} and share
  some code here.  After writing it, though, the fallout from merging
  Mach Task/Process into a single concept plus some other minor
  changes makes the whole NativeThreadListDarwin concept nothing more
  than dead weight.  I am likely going to get rid of this class and
  just manage it directly in NativeProcessDarwin, much like I did
  for NativeProcessLinux.
* There is a stub-out call for starting a STDIO thread.  That will
  go away and adopt the MainLoop pselect-based IOObject reading.

I am developing the fully-integrated changes in the following repo,
which contains the necessary Xcode bits and the glue that enables
lldb-debugserver on a macOS system:

  https://github.com/tfiala/lldb/tree/llgs-darwin

This change also breaks out a few of the lldb-server tests into
their own directory, and adds some $qHostInfo tests (not sure why
I didn't write those tests back when I initially implemented that
on the Linux side).

llvm-svn: 280604
2016-09-04 00:18:56 +00:00

125 lines
3.7 KiB
Python

from __future__ import print_function
# lldb test suite imports
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import TestBase
# gdb-remote-specific imports
import lldbgdbserverutils
from gdbremote_testcase import GdbRemoteTestCaseBase
class TestGdbRemoteExitCode(GdbRemoteTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
FAILED_LAUNCH_CODE = "E08"
def get_launch_fail_reason(self):
self.reset_test_sequence()
self.test_sequence.add_log_lines(
["read packet: $qLaunchSuccess#00"],
True)
self.test_sequence.add_log_lines(
[{"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$",
"capture": {1: "launch_result"}}],
True)
context = self.expect_gdbremote_sequence()
self.assertIsNotNone(context)
return context.get("launch_result")[1:]
def start_inferior(self):
launch_args = self.install_and_create_launch_args()
server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)
self.add_no_ack_remote_stream()
self.test_sequence.add_log_lines(
["read packet: %s" % lldbgdbserverutils.build_gdbremote_A_packet(
launch_args)],
True)
self.test_sequence.add_log_lines(
[{"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$",
"capture": {1: "A_result"}}],
True)
context = self.expect_gdbremote_sequence()
self.assertIsNotNone(context)
launch_result = context.get("A_result")
self.assertIsNotNone(launch_result)
if launch_result == self.FAILED_LAUNCH_CODE:
fail_reason = self.get_launch_fail_reason()
self.fail("failed to launch inferior: " + fail_reason)
@debugserver_test
def test_start_inferior_debugserver(self):
self.init_debugserver_test()
self.build()
self.start_inferior()
@llgs_test
def test_start_inferior_llgs(self):
self.init_llgs_test()
self.build()
self.start_inferior()
def inferior_exit_0(self):
launch_args = self.install_and_create_launch_args()
server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)
self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
self.test_sequence.add_log_lines(
["read packet: $vCont;c#a8",
"send packet: $W00#00"],
True)
self.expect_gdbremote_sequence()
@debugserver_test
def test_inferior_exit_0_debugserver(self):
self.init_debugserver_test()
self.build()
self.inferior_exit_0()
@llgs_test
def test_inferior_exit_0_llgs(self):
self.init_llgs_test()
self.build()
self.inferior_exit_0()
def inferior_exit_42(self):
launch_args = self.install_and_create_launch_args()
server = self.connect_to_debug_monitor()
self.assertIsNotNone(server)
RETVAL = 42
# build launch args
launch_args += ["retval:%d" % RETVAL]
self.add_no_ack_remote_stream()
self.add_verified_launch_packets(launch_args)
self.test_sequence.add_log_lines(
["read packet: $vCont;c#a8",
"send packet: $W{0:02x}#00".format(RETVAL)],
True)
self.expect_gdbremote_sequence()
@debugserver_test
def test_inferior_exit_42_debugserver(self):
self.init_debugserver_test()
self.build()
self.inferior_exit_42()
@llgs_test
def test_inferior_exit_42_llgs(self):
self.init_llgs_test()
self.build()
self.inferior_exit_42()