Skip to content

Commit 43bc2f3

Browse files
committed
[lldb] Make MockGDBServerResponder return consistent types
It used return either: * str * The RESPONSE_DISCONNECT class * The RESPONSE_NONE class * A list of the above three it now returns: * A list of str or SpecialResponse instances
1 parent 3e2d2ba commit 43bc2f3

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

lldb/packages/Python/lldbsuite/test/gdbclientutils.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import threading
66
import socket
77
import traceback
8+
from enum import Enum
89
from lldbsuite.support import seven
9-
from typing import Optional, List, Tuple, Literal
10+
from typing import Optional, List, Tuple, Literal, Union, Sequence
1011

1112

1213
def checksum(message):
@@ -90,21 +91,29 @@ class MockGDBServerResponder:
9091

9192
registerCount: int = 40
9293

93-
class RESPONSE_DISCONNECT:
94-
pass
94+
class SpecialResponse(Enum):
95+
RESPONSE_DISCONNECT = 0
96+
RESPONSE_NONE = 1
9597

96-
class RESPONSE_NONE:
97-
pass
98+
RESPONSE_DISCONNECT = SpecialResponse.RESPONSE_DISCONNECT
99+
RESPONSE_NONE = SpecialResponse.RESPONSE_NONE
100+
type Response = Union[str, SpecialResponse]
98101

99102
def __init__(self):
100103
self.packetLog: List[str] = []
101104

102-
def respond(self, packet):
105+
def respond(self, packet: str) -> Sequence[Response]:
103106
"""
104107
Return the unframed packet data that the server should issue in response
105108
to the given packet received from the client.
106109
"""
107110
self.packetLog.append(packet)
111+
response = self._respond_impl(packet)
112+
if not isinstance(response, list):
113+
response = [response]
114+
return response
115+
116+
def _respond_impl(self, packet) -> Union[Response, List[Response]]:
108117
if packet is MockGDBServer.PACKET_INTERRUPT:
109118
return self.interrupt()
110119
if packet == "c":
@@ -668,24 +677,28 @@ def _handlePacket(self, packet):
668677
# adding validation code to make sure the client only sends ACKs
669678
# when it's supposed to.
670679
return
671-
response = ""
680+
response = [""]
672681
# We'll handle the ack stuff here since it's not something any of the
673682
# tests will be concerned about, and it'll get turned off quickly anyway.
674683
if self._shouldSendAck:
675684
self._socket.sendall(seven.bitcast_to_bytes("+"))
676685
if packet == "QStartNoAckMode":
677686
self._shouldSendAck = False
678-
response = "OK"
687+
response = ["OK"]
679688
elif self.responder is not None:
680689
# Delegate everything else to our responder
681690
response = self.responder.respond(packet)
691+
# MockGDBServerResponder no longer returns non-lists but others like
692+
# ReverseTestBase still do
682693
if not isinstance(response, list):
683694
response = [response]
684695
for part in response:
685696
if part is MockGDBServerResponder.RESPONSE_NONE:
686697
continue
687698
if part is MockGDBServerResponder.RESPONSE_DISCONNECT:
688699
raise self.TerminateConnectionException()
700+
# Should have handled the non-str's above
701+
assert isinstance(part, str)
689702
self._sendPacket(part)
690703

691704
PACKET_ACK = object()

0 commit comments

Comments
 (0)