1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
import gdbremote_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class TestGdbRemoteFork(gdbremote_testcase.GdbRemoteTestCaseBase):
mydir = TestBase.compute_mydir(__file__)
@add_test_categories(["fork"])
def test_fork_multithreaded(self):
self.build()
self.prep_debug_monitor_and_inferior(inferior_args=["thread:new"]*2 + ["fork"])
self.add_qSupported_packets(["multiprocess+", "fork-events+"])
ret = self.expect_gdbremote_sequence()
self.assertIn("fork-events+", ret["qSupported_response"])
self.reset_test_sequence()
# continue and expect fork
fork_regex = "[$]T.*;fork:p([0-9a-f]+)[.]([0-9a-f]+).*"
self.test_sequence.add_log_lines([
"read packet: $c#00",
{"direction": "send", "regex": fork_regex,
"capture": {1: "pid", 2: "tid"}},
], True)
ret = self.expect_gdbremote_sequence()
pid = int(ret["pid"], 16)
self.reset_test_sequence()
# detach the forked child
self.test_sequence.add_log_lines([
"read packet: $D;{:x}#00".format(pid),
{"direction": "send", "regex": r"[$]OK#.*"},
], True)
ret = self.expect_gdbremote_sequence()
self.reset_test_sequence()
# resume the parent
self.test_sequence.add_log_lines([
"read packet: $k#00",
], True)
self.expect_gdbremote_sequence()
def fork_and_detach_test(self, variant):
self.build()
self.prep_debug_monitor_and_inferior(inferior_args=[variant])
self.add_qSupported_packets(["multiprocess+",
"{}-events+".format(variant)])
ret = self.expect_gdbremote_sequence()
self.assertIn("{}-events+".format(variant), ret["qSupported_response"])
self.reset_test_sequence()
# continue and expect fork
fork_regex = "[$]T.*;{}:p([0-9a-f]+)[.]([0-9a-f]+).*".format(variant)
self.test_sequence.add_log_lines([
"read packet: $c#00",
{"direction": "send", "regex": fork_regex,
"capture": {1: "pid", 2: "tid"}},
], True)
ret = self.expect_gdbremote_sequence()
pid = int(ret["pid"], 16)
self.reset_test_sequence()
# detach the forked child
self.test_sequence.add_log_lines([
"read packet: $D;{:x}#00".format(pid),
{"direction": "send", "regex": r"[$]OK#.*"},
], True)
ret = self.expect_gdbremote_sequence()
self.reset_test_sequence()
@add_test_categories(["fork"])
def test_fork(self):
self.fork_and_detach_test("fork")
# resume the parent
self.test_sequence.add_log_lines([
"read packet: $c#00",
{"direction": "send", "regex": r"[$]W00#.*"},
], True)
self.expect_gdbremote_sequence()
@add_test_categories(["fork"])
def test_vfork(self):
self.fork_and_detach_test("vfork")
# resume the parent
self.test_sequence.add_log_lines([
"read packet: $c#00",
{"direction": "send", "regex": r"[$]T.*vforkdone.*"},
"read packet: $c#00",
{"direction": "send", "regex": r"[$]W00#.*"},
], True)
self.expect_gdbremote_sequence()
def fork_and_follow_test(self, variant):
self.build()
self.prep_debug_monitor_and_inferior(inferior_args=[variant])
self.add_qSupported_packets(["multiprocess+",
"{}-events+".format(variant)])
ret = self.expect_gdbremote_sequence()
self.assertIn("{}-events+".format(variant), ret["qSupported_response"])
self.reset_test_sequence()
# continue and expect fork
procinfo_regex = "[$]pid:([0-9a-f]+);.*"
fork_regex = "[$]T.*;{}:p([0-9a-f]+)[.]([0-9a-f]+).*".format(variant)
self.test_sequence.add_log_lines([
"read packet: $qProcessInfo#00",
{"direction": "send", "regex": procinfo_regex,
"capture": {1: "parent_pid"}},
"read packet: $c#00",
{"direction": "send", "regex": fork_regex,
"capture": {1: "pid", 2: "tid"}},
], True)
ret = self.expect_gdbremote_sequence()
parent_pid, pid, tid = (int(ret[x], 16) for x
in ("parent_pid", "pid", "tid"))
self.reset_test_sequence()
# switch to the forked child
self.test_sequence.add_log_lines([
"read packet: $Hgp{:x}.{:x}#00".format(pid, tid),
{"direction": "send", "regex": r"[$]OK#.*"},
"read packet: $Hcp{:x}.{:x}#00".format(pid, tid),
{"direction": "send", "regex": r"[$]OK#.*"},
], True)
# detach the parent
self.test_sequence.add_log_lines([
"read packet: $D;{:x}#00".format(parent_pid),
{"direction": "send", "regex": r"[$]OK#.*"},
], True)
ret = self.expect_gdbremote_sequence()
self.reset_test_sequence()
# resume the child
self.test_sequence.add_log_lines([
"read packet: $c#00",
{"direction": "send", "regex": r"[$]W00#.*"},
], True)
self.expect_gdbremote_sequence()
@add_test_categories(["fork"])
def test_fork_follow(self):
self.fork_and_follow_test("fork")
@add_test_categories(["fork"])
def test_vfork_follow(self):
self.fork_and_follow_test("vfork")
@add_test_categories(["fork"])
def test_select_wrong_pid(self):
self.build()
self.prep_debug_monitor_and_inferior()
self.add_qSupported_packets(["multiprocess+"])
ret = self.expect_gdbremote_sequence()
self.assertIn("multiprocess+", ret["qSupported_response"])
self.reset_test_sequence()
# get process pid
procinfo_regex = "[$]pid:([0-9a-f]+);.*"
self.test_sequence.add_log_lines([
"read packet: $qProcessInfo#00",
{"direction": "send", "regex": procinfo_regex,
"capture": {1: "pid"}},
"read packet: $qC#00",
{"direction": "send", "regex": "[$]QC([0-9a-f]+)#.*",
"capture": {1: "tid"}},
], True)
ret = self.expect_gdbremote_sequence()
pid, tid = (int(ret[x], 16) for x in ("pid", "tid"))
self.reset_test_sequence()
# try switching to correct pid
self.test_sequence.add_log_lines([
"read packet: $Hgp{:x}.{:x}#00".format(pid, tid),
{"direction": "send", "regex": r"[$]OK#.*"},
"read packet: $Hcp{:x}.{:x}#00".format(pid, tid),
{"direction": "send", "regex": r"[$]OK#.*"},
], True)
ret = self.expect_gdbremote_sequence()
# try switching to invalid tid
self.test_sequence.add_log_lines([
"read packet: $Hgp{:x}.{:x}#00".format(pid, tid+1),
{"direction": "send", "regex": r"[$]E15#.*"},
"read packet: $Hcp{:x}.{:x}#00".format(pid, tid+1),
{"direction": "send", "regex": r"[$]E15#.*"},
], True)
ret = self.expect_gdbremote_sequence()
# try switching to invalid pid
self.test_sequence.add_log_lines([
"read packet: $Hgp{:x}.{:x}#00".format(pid+1, tid),
{"direction": "send", "regex": r"[$]Eff#.*"},
"read packet: $Hcp{:x}.{:x}#00".format(pid+1, tid),
{"direction": "send", "regex": r"[$]Eff#.*"},
], True)
ret = self.expect_gdbremote_sequence()
@add_test_categories(["fork"])
def test_detach_current(self):
self.build()
self.prep_debug_monitor_and_inferior()
self.add_qSupported_packets(["multiprocess+"])
ret = self.expect_gdbremote_sequence()
self.assertIn("multiprocess+", ret["qSupported_response"])
self.reset_test_sequence()
# get process pid
procinfo_regex = "[$]pid:([0-9a-f]+);.*"
self.test_sequence.add_log_lines([
"read packet: $qProcessInfo#00",
{"direction": "send", "regex": procinfo_regex,
"capture": {1: "pid"}},
], True)
ret = self.expect_gdbremote_sequence()
pid = int(ret["pid"], 16)
self.reset_test_sequence()
# detach the process
self.test_sequence.add_log_lines([
"read packet: $D;{:x}#00".format(pid),
{"direction": "send", "regex": r"[$]OK#.*"},
"read packet: $qC#00",
{"direction": "send", "regex": r"[$]E44#.*"},
], True)
ret = self.expect_gdbremote_sequence()
|