2015-10-23 17:04:29 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-11-03 19:20:39 +00:00
|
|
|
|
2016-02-04 23:04:17 +00:00
|
|
|
import sys
|
2015-10-22 20:06:20 +00:00
|
|
|
|
2014-08-26 17:19:10 +00:00
|
|
|
import gdbremote_testcase
|
|
|
|
import lldbgdbserverutils
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test.decorators import *
|
2015-11-03 02:06:18 +00:00
|
|
|
from lldbsuite.test.lldbtest import *
|
2016-02-04 23:04:17 +00:00
|
|
|
from lldbsuite.test import lldbutil
|
2014-08-26 17:19:10 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-08-26 17:19:10 +00:00
|
|
|
class TestGdbRemoteProcessInfo(gdbremote_testcase.GdbRemoteTestCaseBase):
|
|
|
|
|
2015-05-21 18:54:12 +00:00
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
|
|
|
2014-08-26 17:19:10 +00:00
|
|
|
def qProcessInfo_returns_running_process(self):
|
|
|
|
procs = self.prep_debug_monitor_and_inferior()
|
|
|
|
self.add_process_info_collection_packets()
|
|
|
|
|
|
|
|
# Run the stream
|
|
|
|
context = self.expect_gdbremote_sequence()
|
|
|
|
self.assertIsNotNone(context)
|
|
|
|
|
|
|
|
# Gather process info response
|
|
|
|
process_info = self.parse_process_info_response(context)
|
|
|
|
self.assertIsNotNone(process_info)
|
|
|
|
|
|
|
|
# Ensure the process id looks reasonable.
|
|
|
|
pid_text = process_info.get("pid")
|
|
|
|
self.assertIsNotNone(pid_text)
|
|
|
|
pid = int(pid_text, base=16)
|
|
|
|
self.assertNotEqual(0, pid)
|
|
|
|
|
|
|
|
# If possible, verify that the process is running.
|
|
|
|
self.assertTrue(lldbgdbserverutils.process_is_running(pid, True))
|
|
|
|
|
|
|
|
@debugserver_test
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_qProcessInfo_returns_running_process_debugserver(self):
|
2014-08-26 17:19:10 +00:00
|
|
|
self.init_debugserver_test()
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2014-08-26 17:19:10 +00:00
|
|
|
self.qProcessInfo_returns_running_process()
|
|
|
|
|
|
|
|
@llgs_test
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_qProcessInfo_returns_running_process_llgs(self):
|
2014-08-26 17:19:10 +00:00
|
|
|
self.init_llgs_test()
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2014-08-26 17:19:10 +00:00
|
|
|
self.qProcessInfo_returns_running_process()
|
|
|
|
|
|
|
|
def attach_commandline_qProcessInfo_reports_correct_pid(self):
|
|
|
|
procs = self.prep_debug_monitor_and_inferior()
|
|
|
|
self.assertIsNotNone(procs)
|
|
|
|
self.add_process_info_collection_packets()
|
|
|
|
|
|
|
|
# Run the stream
|
2016-09-06 20:57:50 +00:00
|
|
|
context = self.expect_gdbremote_sequence(timeout_seconds=8)
|
2014-08-26 17:19:10 +00:00
|
|
|
self.assertIsNotNone(context)
|
|
|
|
|
|
|
|
# Gather process info response
|
|
|
|
process_info = self.parse_process_info_response(context)
|
|
|
|
self.assertIsNotNone(process_info)
|
|
|
|
|
|
|
|
# Ensure the process id matches what we expected.
|
|
|
|
pid_text = process_info.get('pid', None)
|
|
|
|
self.assertIsNotNone(pid_text)
|
|
|
|
reported_pid = int(pid_text, base=16)
|
|
|
|
self.assertEqual(reported_pid, procs["inferior"].pid)
|
|
|
|
|
|
|
|
@debugserver_test
|
2016-09-06 20:57:50 +00:00
|
|
|
def test_attach_commandline_qProcessInfo_reports_correct_pid_debugserver(
|
|
|
|
self):
|
2014-08-26 17:19:10 +00:00
|
|
|
self.init_debugserver_test()
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2014-08-26 17:19:10 +00:00
|
|
|
self.set_inferior_startup_attach()
|
|
|
|
self.attach_commandline_qProcessInfo_reports_correct_pid()
|
|
|
|
|
|
|
|
@llgs_test
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_attach_commandline_qProcessInfo_reports_correct_pid_llgs(self):
|
2014-08-26 17:19:10 +00:00
|
|
|
self.init_llgs_test()
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2014-08-26 17:19:10 +00:00
|
|
|
self.set_inferior_startup_attach()
|
|
|
|
self.attach_commandline_qProcessInfo_reports_correct_pid()
|
|
|
|
|
|
|
|
def qProcessInfo_reports_valid_endian(self):
|
|
|
|
procs = self.prep_debug_monitor_and_inferior()
|
|
|
|
self.add_process_info_collection_packets()
|
|
|
|
|
|
|
|
# Run the stream
|
|
|
|
context = self.expect_gdbremote_sequence()
|
|
|
|
self.assertIsNotNone(context)
|
|
|
|
|
|
|
|
# Gather process info response
|
|
|
|
process_info = self.parse_process_info_response(context)
|
|
|
|
self.assertIsNotNone(process_info)
|
|
|
|
|
|
|
|
# Ensure the process id looks reasonable.
|
|
|
|
endian = process_info.get("endian")
|
|
|
|
self.assertIsNotNone(endian)
|
|
|
|
self.assertTrue(endian in ["little", "big", "pdp"])
|
|
|
|
|
|
|
|
@debugserver_test
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_qProcessInfo_reports_valid_endian_debugserver(self):
|
2014-08-26 17:19:10 +00:00
|
|
|
self.init_debugserver_test()
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2014-08-26 17:19:10 +00:00
|
|
|
self.qProcessInfo_reports_valid_endian()
|
|
|
|
|
|
|
|
@llgs_test
|
2015-09-30 10:12:40 +00:00
|
|
|
def test_qProcessInfo_reports_valid_endian_llgs(self):
|
2014-08-26 17:19:10 +00:00
|
|
|
self.init_llgs_test()
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2014-08-26 17:19:10 +00:00
|
|
|
self.qProcessInfo_reports_valid_endian()
|
|
|
|
|
2014-08-26 18:21:02 +00:00
|
|
|
def qProcessInfo_contains_keys(self, expected_key_set):
|
|
|
|
procs = self.prep_debug_monitor_and_inferior()
|
|
|
|
self.add_process_info_collection_packets()
|
|
|
|
|
|
|
|
# Run the stream
|
|
|
|
context = self.expect_gdbremote_sequence()
|
|
|
|
self.assertIsNotNone(context)
|
|
|
|
|
|
|
|
# Gather process info response
|
|
|
|
process_info = self.parse_process_info_response(context)
|
|
|
|
self.assertIsNotNone(process_info)
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
# Ensure the expected keys are present and non-None within the process
|
|
|
|
# info.
|
2014-08-26 18:21:02 +00:00
|
|
|
missing_key_set = set()
|
|
|
|
for expected_key in expected_key_set:
|
|
|
|
if expected_key not in process_info:
|
|
|
|
missing_key_set.add(expected_key)
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
self.assertEqual(
|
|
|
|
missing_key_set,
|
|
|
|
set(),
|
|
|
|
"the listed keys are missing in the qProcessInfo result")
|
2014-08-26 18:21:02 +00:00
|
|
|
|
2014-08-26 18:40:56 +00:00
|
|
|
def qProcessInfo_does_not_contain_keys(self, absent_key_set):
|
|
|
|
procs = self.prep_debug_monitor_and_inferior()
|
|
|
|
self.add_process_info_collection_packets()
|
|
|
|
|
|
|
|
# Run the stream
|
|
|
|
context = self.expect_gdbremote_sequence()
|
|
|
|
self.assertIsNotNone(context)
|
|
|
|
|
|
|
|
# Gather process info response
|
|
|
|
process_info = self.parse_process_info_response(context)
|
|
|
|
self.assertIsNotNone(process_info)
|
|
|
|
|
|
|
|
# Ensure the unexpected keys are not present
|
|
|
|
unexpected_key_set = set()
|
|
|
|
for unexpected_key in absent_key_set:
|
|
|
|
if unexpected_key in process_info:
|
|
|
|
unexpected_key_set.add(unexpected_key)
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
self.assertEqual(
|
|
|
|
unexpected_key_set,
|
|
|
|
set(),
|
|
|
|
"the listed keys were present but unexpected in qProcessInfo result")
|
2014-08-26 18:40:56 +00:00
|
|
|
|
2015-03-30 14:12:17 +00:00
|
|
|
@skipUnlessDarwin
|
2014-08-26 18:21:02 +00:00
|
|
|
@debugserver_test
|
|
|
|
def test_qProcessInfo_contains_cputype_cpusubtype_debugserver_darwin(self):
|
|
|
|
self.init_debugserver_test()
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2014-08-26 18:21:02 +00:00
|
|
|
self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype']))
|
|
|
|
|
[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
|
|
|
@skipUnlessDarwin
|
|
|
|
@llgs_test
|
|
|
|
def test_qProcessInfo_contains_cputype_cpusubtype_llgs_darwin(self):
|
|
|
|
self.init_llgs_test()
|
|
|
|
self.build()
|
|
|
|
self.qProcessInfo_contains_keys(set(['cputype', 'cpusubtype']))
|
|
|
|
|
2015-03-30 14:12:17 +00:00
|
|
|
@skipUnlessPlatform(["linux"])
|
2014-08-26 18:21:02 +00:00
|
|
|
@llgs_test
|
|
|
|
def test_qProcessInfo_contains_triple_llgs_linux(self):
|
|
|
|
self.init_llgs_test()
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2014-08-26 18:21:02 +00:00
|
|
|
self.qProcessInfo_contains_keys(set(['triple']))
|
|
|
|
|
2015-03-30 14:12:17 +00:00
|
|
|
@skipUnlessDarwin
|
2014-08-26 18:40:56 +00:00
|
|
|
@debugserver_test
|
|
|
|
def test_qProcessInfo_does_not_contain_triple_debugserver_darwin(self):
|
|
|
|
self.init_debugserver_test()
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2014-08-26 18:40:56 +00:00
|
|
|
# We don't expect to see triple on darwin. If we do, we'll prefer triple
|
|
|
|
# to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup
|
|
|
|
# for the remote Host and Process.
|
|
|
|
self.qProcessInfo_does_not_contain_keys(set(['triple']))
|
|
|
|
|
[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
|
|
|
@skipUnlessDarwin
|
|
|
|
@llgs_test
|
|
|
|
def test_qProcessInfo_does_not_contain_triple_llgs_darwin(self):
|
|
|
|
self.init_llgs_test()
|
|
|
|
self.build()
|
|
|
|
# We don't expect to see triple on darwin. If we do, we'll prefer triple
|
|
|
|
# to cputype/cpusubtype and skip some darwin-based ProcessGDBRemote ArchSpec setup
|
|
|
|
# for the remote Host and Process.
|
|
|
|
self.qProcessInfo_does_not_contain_keys(set(['triple']))
|
|
|
|
|
2015-03-30 14:12:17 +00:00
|
|
|
@skipUnlessPlatform(["linux"])
|
2014-08-26 18:40:56 +00:00
|
|
|
@llgs_test
|
|
|
|
def test_qProcessInfo_does_not_contain_cputype_cpusubtype_llgs_linux(self):
|
|
|
|
self.init_llgs_test()
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
2014-08-26 18:40:56 +00:00
|
|
|
self.qProcessInfo_does_not_contain_keys(set(['cputype', 'cpusubtype']))
|