2021-09-30 22:30:30 +02:00
|
|
|
import ctypes
|
2020-09-30 10:47:48 -07:00
|
|
|
import errno
|
2021-09-30 22:30:30 +02:00
|
|
|
import io
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
import threading
|
|
|
|
import socket
|
2019-10-12 02:36:16 +00:00
|
|
|
import traceback
|
2019-02-15 10:47:34 +00:00
|
|
|
from lldbsuite.support import seven
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
|
|
|
|
def checksum(message):
|
|
|
|
"""
|
|
|
|
Calculate the GDB server protocol checksum of the message.
|
|
|
|
|
|
|
|
The GDB server protocol uses a simple modulo 256 sum.
|
|
|
|
"""
|
|
|
|
check = 0
|
|
|
|
for c in message:
|
|
|
|
check += ord(c)
|
|
|
|
return check % 256
|
|
|
|
|
|
|
|
|
|
|
|
def frame_packet(message):
|
|
|
|
"""
|
|
|
|
Create a framed packet that's ready to send over the GDB connection
|
|
|
|
channel.
|
|
|
|
|
|
|
|
Framing includes surrounding the message between $ and #, and appending
|
|
|
|
a two character hex checksum.
|
|
|
|
"""
|
|
|
|
return "$%s#%02x" % (message, checksum(message))
|
|
|
|
|
|
|
|
|
|
|
|
def escape_binary(message):
|
|
|
|
"""
|
|
|
|
Escape the binary message using the process described in the GDB server
|
|
|
|
protocol documentation.
|
|
|
|
|
|
|
|
Most bytes are sent through as-is, but $, #, and { are escaped by writing
|
|
|
|
a { followed by the original byte mod 0x20.
|
|
|
|
"""
|
|
|
|
out = ""
|
|
|
|
for c in message:
|
|
|
|
d = ord(c)
|
|
|
|
if d in (0x23, 0x24, 0x7d):
|
|
|
|
out += chr(0x7d)
|
|
|
|
out += chr(d ^ 0x20)
|
|
|
|
else:
|
|
|
|
out += c
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
def hex_encode_bytes(message):
|
|
|
|
"""
|
|
|
|
Encode the binary message by converting each byte into a two-character
|
|
|
|
hex string.
|
|
|
|
"""
|
|
|
|
out = ""
|
|
|
|
for c in message:
|
|
|
|
out += "%02x" % ord(c)
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
def hex_decode_bytes(hex_bytes):
|
|
|
|
"""
|
|
|
|
Decode the hex string into a binary message by converting each two-character
|
|
|
|
hex string into a single output byte.
|
|
|
|
"""
|
|
|
|
out = ""
|
|
|
|
hex_len = len(hex_bytes)
|
[lldb] Avoid duplicate vdso modules when opening core files
When opening core files (and also in some other situations) we could end
up with two vdso modules. This could happen because the vdso module is
very special, and over the years, we have accumulated various ways to
load it.
In D10800, we added one mechanism for loading it, which took the form of
a generic load-from-memory capability. Unfortunately loading an elf file
from memory is not possible (because the loader never loads the entire
file), and our attempts to do so were causing crashes. So, in D34352, we
partially reverted D10800 and implemented a custom mechanism specific to
the vdso.
Unfortunately, enough of D10800 remained such that, under the right
circumstances, it could end up loading a second (non-functional) copy of
the vdso module. This happened when the process plugin did not support
the extended MemoryRegionInfo query (added in D22219, to workaround a
different bug), which meant that the loader plugin was not able to
recognise that the linux-vdso.so.1 module (this is how the loader calls
it) is in fact the same as the [vdso] module (the name used in
/proc/$PID/maps) we loaded before. This typically happened in a core
file, as they don't store this kind of information.
This patch fixes the issue by completing the revert of D10800 -- the
memory loading code is removed completely. It also reduces the scope of
the hackaround introduced in D22219 -- it isn't completely sound and is
only relevant for fairly old (but still supported) versions of android.
I added the memory loading logic to the wasm dynamic loader, which has
since appeared and is relying on this feature (it even has a test). As
far as I can tell loading wasm modules from memory is possible and
reliable. MachO memory loading is not affected by this patch, as it uses
a completely different code path.
Since the scenarios/patches I described came without test cases, I have
created two new gdb-client tests cases for them. They're not
particularly readable, but right now, this is the best way we can
simulate the behavior (bugs) of a particular dynamic linker.
Differential Revision: https://reviews.llvm.org/D122660
2022-03-29 10:47:32 +02:00
|
|
|
i = 0
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
while i < hex_len - 1:
|
[lldb] Avoid duplicate vdso modules when opening core files
When opening core files (and also in some other situations) we could end
up with two vdso modules. This could happen because the vdso module is
very special, and over the years, we have accumulated various ways to
load it.
In D10800, we added one mechanism for loading it, which took the form of
a generic load-from-memory capability. Unfortunately loading an elf file
from memory is not possible (because the loader never loads the entire
file), and our attempts to do so were causing crashes. So, in D34352, we
partially reverted D10800 and implemented a custom mechanism specific to
the vdso.
Unfortunately, enough of D10800 remained such that, under the right
circumstances, it could end up loading a second (non-functional) copy of
the vdso module. This happened when the process plugin did not support
the extended MemoryRegionInfo query (added in D22219, to workaround a
different bug), which meant that the loader plugin was not able to
recognise that the linux-vdso.so.1 module (this is how the loader calls
it) is in fact the same as the [vdso] module (the name used in
/proc/$PID/maps) we loaded before. This typically happened in a core
file, as they don't store this kind of information.
This patch fixes the issue by completing the revert of D10800 -- the
memory loading code is removed completely. It also reduces the scope of
the hackaround introduced in D22219 -- it isn't completely sound and is
only relevant for fairly old (but still supported) versions of android.
I added the memory loading logic to the wasm dynamic loader, which has
since appeared and is relying on this feature (it even has a test). As
far as I can tell loading wasm modules from memory is possible and
reliable. MachO memory loading is not affected by this patch, as it uses
a completely different code path.
Since the scenarios/patches I described came without test cases, I have
created two new gdb-client tests cases for them. They're not
particularly readable, but right now, this is the best way we can
simulate the behavior (bugs) of a particular dynamic linker.
Differential Revision: https://reviews.llvm.org/D122660
2022-03-29 10:47:32 +02:00
|
|
|
out += chr(int(hex_bytes[i:i + 2], 16))
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
i += 2
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
class MockGDBServerResponder:
|
|
|
|
"""
|
2018-05-14 21:04:24 +00:00
|
|
|
A base class for handling client packets and issuing server responses for
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
GDB tests.
|
|
|
|
|
|
|
|
This handles many typical situations, while still allowing subclasses to
|
|
|
|
completely customize their responses.
|
|
|
|
|
|
|
|
Most subclasses will be interested in overriding the other() method, which
|
|
|
|
handles any packet not recognized in the common packet handling code.
|
|
|
|
"""
|
|
|
|
|
|
|
|
registerCount = 40
|
|
|
|
packetLog = None
|
2021-11-18 13:56:36 +01:00
|
|
|
class RESPONSE_DISCONNECT: pass
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.packetLog = []
|
|
|
|
|
|
|
|
def respond(self, packet):
|
|
|
|
"""
|
|
|
|
Return the unframed packet data that the server should issue in response
|
|
|
|
to the given packet received from the client.
|
|
|
|
"""
|
|
|
|
self.packetLog.append(packet)
|
2018-02-08 10:37:23 +00:00
|
|
|
if packet is MockGDBServer.PACKET_INTERRUPT:
|
|
|
|
return self.interrupt()
|
|
|
|
if packet == "c":
|
|
|
|
return self.cont()
|
2019-06-28 17:57:19 +00:00
|
|
|
if packet.startswith("vCont;c"):
|
|
|
|
return self.vCont(packet)
|
2020-02-14 08:33:42 +01:00
|
|
|
if packet[0] == "A":
|
|
|
|
return self.A(packet)
|
2021-04-09 16:18:50 +02:00
|
|
|
if packet[0] == "D":
|
|
|
|
return self.D(packet)
|
2018-10-23 23:45:56 +00:00
|
|
|
if packet[0] == "g":
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
return self.readRegisters()
|
|
|
|
if packet[0] == "G":
|
2019-11-20 14:13:39 -08:00
|
|
|
# Gxxxxxxxxxxx
|
|
|
|
# Gxxxxxxxxxxx;thread:1234;
|
|
|
|
return self.writeRegisters(packet[1:].split(';')[0])
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
if packet[0] == "p":
|
2018-10-23 23:45:56 +00:00
|
|
|
regnum = packet[1:].split(';')[0]
|
|
|
|
return self.readRegister(int(regnum, 16))
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
if packet[0] == "P":
|
|
|
|
register, value = packet[1:].split("=")
|
2019-11-07 10:38:25 +01:00
|
|
|
return self.writeRegister(int(register, 16), value)
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
if packet[0] == "m":
|
|
|
|
addr, length = [int(x, 16) for x in packet[1:].split(',')]
|
|
|
|
return self.readMemory(addr, length)
|
|
|
|
if packet[0] == "M":
|
|
|
|
location, encoded_data = packet[1:].split(":")
|
|
|
|
addr, length = [int(x, 16) for x in location.split(',')]
|
|
|
|
return self.writeMemory(addr, encoded_data)
|
|
|
|
if packet[0:7] == "qSymbol":
|
|
|
|
return self.qSymbol(packet[8:])
|
|
|
|
if packet[0:10] == "qSupported":
|
|
|
|
return self.qSupported(packet[11:].split(";"))
|
|
|
|
if packet == "qfThreadInfo":
|
|
|
|
return self.qfThreadInfo()
|
2018-10-23 23:45:56 +00:00
|
|
|
if packet == "qsThreadInfo":
|
|
|
|
return self.qsThreadInfo()
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
if packet == "qC":
|
|
|
|
return self.qC()
|
2018-04-18 11:56:21 +00:00
|
|
|
if packet == "QEnableErrorStrings":
|
|
|
|
return self.QEnableErrorStrings()
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
if packet == "?":
|
|
|
|
return self.haltReason()
|
2018-09-12 21:35:02 +00:00
|
|
|
if packet == "s":
|
|
|
|
return self.haltReason()
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
if packet[0] == "H":
|
2021-04-11 13:08:05 +02:00
|
|
|
tid = packet[2:]
|
|
|
|
if "." in tid:
|
|
|
|
assert tid.startswith("p")
|
|
|
|
# TODO: do we want to do anything with PID?
|
|
|
|
tid = tid.split(".", 1)[1]
|
|
|
|
return self.selectThread(packet[1], int(tid, 16))
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
if packet[0:6] == "qXfer:":
|
|
|
|
obj, read, annex, location = packet[6:].split(":")
|
|
|
|
offset, length = [int(x, 16) for x in location.split(',')]
|
|
|
|
data, has_more = self.qXferRead(obj, annex, offset, length)
|
|
|
|
if data is not None:
|
|
|
|
return self._qXferResponse(data, has_more)
|
|
|
|
return ""
|
2018-04-18 11:56:21 +00:00
|
|
|
if packet.startswith("vAttach;"):
|
|
|
|
pid = packet.partition(';')[2]
|
|
|
|
return self.vAttach(int(pid, 16))
|
2018-02-08 10:37:23 +00:00
|
|
|
if packet[0] == "Z":
|
|
|
|
return self.setBreakpoint(packet)
|
2018-09-12 21:35:02 +00:00
|
|
|
if packet.startswith("qThreadStopInfo"):
|
|
|
|
threadnum = int (packet[15:], 16)
|
|
|
|
return self.threadStopInfo(threadnum)
|
2018-10-23 23:45:56 +00:00
|
|
|
if packet == "QThreadSuffixSupported":
|
|
|
|
return self.QThreadSuffixSupported()
|
|
|
|
if packet == "QListThreadsInStopReply":
|
|
|
|
return self.QListThreadsInStopReply()
|
|
|
|
if packet.startswith("qMemoryRegionInfo:"):
|
2021-06-20 12:19:50 -07:00
|
|
|
return self.qMemoryRegionInfo(int(packet.split(':')[1], 16))
|
2019-10-12 02:36:16 +00:00
|
|
|
if packet == "qQueryGDBServer":
|
|
|
|
return self.qQueryGDBServer()
|
|
|
|
if packet == "qHostInfo":
|
|
|
|
return self.qHostInfo()
|
|
|
|
if packet == "qGetWorkingDir":
|
|
|
|
return self.qGetWorkingDir()
|
2020-02-13 14:30:04 +01:00
|
|
|
if packet == "qOffsets":
|
|
|
|
return self.qOffsets();
|
[lldb] Avoid duplicate vdso modules when opening core files
When opening core files (and also in some other situations) we could end
up with two vdso modules. This could happen because the vdso module is
very special, and over the years, we have accumulated various ways to
load it.
In D10800, we added one mechanism for loading it, which took the form of
a generic load-from-memory capability. Unfortunately loading an elf file
from memory is not possible (because the loader never loads the entire
file), and our attempts to do so were causing crashes. So, in D34352, we
partially reverted D10800 and implemented a custom mechanism specific to
the vdso.
Unfortunately, enough of D10800 remained such that, under the right
circumstances, it could end up loading a second (non-functional) copy of
the vdso module. This happened when the process plugin did not support
the extended MemoryRegionInfo query (added in D22219, to workaround a
different bug), which meant that the loader plugin was not able to
recognise that the linux-vdso.so.1 module (this is how the loader calls
it) is in fact the same as the [vdso] module (the name used in
/proc/$PID/maps) we loaded before. This typically happened in a core
file, as they don't store this kind of information.
This patch fixes the issue by completing the revert of D10800 -- the
memory loading code is removed completely. It also reduces the scope of
the hackaround introduced in D22219 -- it isn't completely sound and is
only relevant for fairly old (but still supported) versions of android.
I added the memory loading logic to the wasm dynamic loader, which has
since appeared and is relying on this feature (it even has a test). As
far as I can tell loading wasm modules from memory is possible and
reliable. MachO memory loading is not affected by this patch, as it uses
a completely different code path.
Since the scenarios/patches I described came without test cases, I have
created two new gdb-client tests cases for them. They're not
particularly readable, but right now, this is the best way we can
simulate the behavior (bugs) of a particular dynamic linker.
Differential Revision: https://reviews.llvm.org/D122660
2022-03-29 10:47:32 +02:00
|
|
|
if packet == "qProcessInfo":
|
|
|
|
return self.qProcessInfo()
|
2019-10-12 02:36:16 +00:00
|
|
|
if packet == "qsProcessInfo":
|
|
|
|
return self.qsProcessInfo()
|
|
|
|
if packet.startswith("qfProcessInfo"):
|
|
|
|
return self.qfProcessInfo(packet)
|
2020-08-24 17:34:32 +02:00
|
|
|
if packet.startswith("qPathComplete:"):
|
|
|
|
return self.qPathComplete()
|
2021-07-28 20:37:52 +02:00
|
|
|
if packet.startswith("vFile:"):
|
|
|
|
return self.vFile(packet)
|
2021-08-11 22:58:11 +02:00
|
|
|
if packet.startswith("vRun;"):
|
|
|
|
return self.vRun(packet)
|
|
|
|
if packet.startswith("qLaunchSuccess"):
|
|
|
|
return self.qLaunchSuccess()
|
2021-08-12 17:01:30 +02:00
|
|
|
if packet.startswith("QEnvironment:"):
|
|
|
|
return self.QEnvironment(packet)
|
|
|
|
if packet.startswith("QEnvironmentHexEncoded:"):
|
|
|
|
return self.QEnvironmentHexEncoded(packet)
|
2021-10-09 18:02:08 +02:00
|
|
|
if packet.startswith("qRegisterInfo"):
|
|
|
|
regnum = int(packet[len("qRegisterInfo"):], 16)
|
|
|
|
return self.qRegisterInfo(regnum)
|
2021-11-04 13:23:12 +01:00
|
|
|
if packet == "k":
|
|
|
|
return self.k()
|
2018-10-23 23:45:56 +00:00
|
|
|
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
return self.other(packet)
|
|
|
|
|
2019-10-12 02:36:16 +00:00
|
|
|
def qsProcessInfo(self):
|
|
|
|
return "E04"
|
|
|
|
|
|
|
|
def qfProcessInfo(self, packet):
|
|
|
|
return "E04"
|
|
|
|
|
|
|
|
def qGetWorkingDir(self):
|
|
|
|
return "2f"
|
|
|
|
|
2020-02-13 14:30:04 +01:00
|
|
|
def qOffsets(self):
|
|
|
|
return ""
|
|
|
|
|
[lldb] Avoid duplicate vdso modules when opening core files
When opening core files (and also in some other situations) we could end
up with two vdso modules. This could happen because the vdso module is
very special, and over the years, we have accumulated various ways to
load it.
In D10800, we added one mechanism for loading it, which took the form of
a generic load-from-memory capability. Unfortunately loading an elf file
from memory is not possible (because the loader never loads the entire
file), and our attempts to do so were causing crashes. So, in D34352, we
partially reverted D10800 and implemented a custom mechanism specific to
the vdso.
Unfortunately, enough of D10800 remained such that, under the right
circumstances, it could end up loading a second (non-functional) copy of
the vdso module. This happened when the process plugin did not support
the extended MemoryRegionInfo query (added in D22219, to workaround a
different bug), which meant that the loader plugin was not able to
recognise that the linux-vdso.so.1 module (this is how the loader calls
it) is in fact the same as the [vdso] module (the name used in
/proc/$PID/maps) we loaded before. This typically happened in a core
file, as they don't store this kind of information.
This patch fixes the issue by completing the revert of D10800 -- the
memory loading code is removed completely. It also reduces the scope of
the hackaround introduced in D22219 -- it isn't completely sound and is
only relevant for fairly old (but still supported) versions of android.
I added the memory loading logic to the wasm dynamic loader, which has
since appeared and is relying on this feature (it even has a test). As
far as I can tell loading wasm modules from memory is possible and
reliable. MachO memory loading is not affected by this patch, as it uses
a completely different code path.
Since the scenarios/patches I described came without test cases, I have
created two new gdb-client tests cases for them. They're not
particularly readable, but right now, this is the best way we can
simulate the behavior (bugs) of a particular dynamic linker.
Differential Revision: https://reviews.llvm.org/D122660
2022-03-29 10:47:32 +02:00
|
|
|
def qProcessInfo(self):
|
|
|
|
return ""
|
|
|
|
|
2019-10-12 02:36:16 +00:00
|
|
|
def qHostInfo(self):
|
|
|
|
return "ptrsize:8;endian:little;"
|
|
|
|
|
|
|
|
def qQueryGDBServer(self):
|
|
|
|
return "E04"
|
|
|
|
|
2018-02-08 10:37:23 +00:00
|
|
|
def interrupt(self):
|
|
|
|
raise self.UnexpectedPacketException()
|
|
|
|
|
|
|
|
def cont(self):
|
|
|
|
raise self.UnexpectedPacketException()
|
|
|
|
|
2019-06-28 17:57:19 +00:00
|
|
|
def vCont(self, packet):
|
|
|
|
raise self.UnexpectedPacketException()
|
2019-10-12 02:36:16 +00:00
|
|
|
|
2020-02-14 08:33:42 +01:00
|
|
|
def A(self, packet):
|
|
|
|
return ""
|
|
|
|
|
2021-04-09 16:18:50 +02:00
|
|
|
def D(self, packet):
|
|
|
|
return "OK"
|
|
|
|
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
def readRegisters(self):
|
|
|
|
return "00000000" * self.registerCount
|
|
|
|
|
|
|
|
def readRegister(self, register):
|
|
|
|
return "00000000"
|
|
|
|
|
|
|
|
def writeRegisters(self, registers_hex):
|
|
|
|
return "OK"
|
|
|
|
|
|
|
|
def writeRegister(self, register, value_hex):
|
|
|
|
return "OK"
|
|
|
|
|
|
|
|
def readMemory(self, addr, length):
|
|
|
|
return "00" * length
|
|
|
|
|
|
|
|
def writeMemory(self, addr, data_hex):
|
|
|
|
return "OK"
|
|
|
|
|
|
|
|
def qSymbol(self, symbol_args):
|
|
|
|
return "OK"
|
|
|
|
|
|
|
|
def qSupported(self, client_supported):
|
2018-02-10 01:13:34 +00:00
|
|
|
return "qXfer:features:read+;PacketSize=3fff;QStartNoAckMode+"
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
|
|
|
|
def qfThreadInfo(self):
|
|
|
|
return "l"
|
|
|
|
|
2018-10-23 23:45:56 +00:00
|
|
|
def qsThreadInfo(self):
|
|
|
|
return "l"
|
|
|
|
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
def qC(self):
|
|
|
|
return "QC0"
|
|
|
|
|
2018-04-18 11:56:21 +00:00
|
|
|
def QEnableErrorStrings(self):
|
|
|
|
return "OK"
|
|
|
|
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
def haltReason(self):
|
|
|
|
# SIGINT is 2, return type is 2 digit hex string
|
|
|
|
return "S02"
|
|
|
|
|
|
|
|
def qXferRead(self, obj, annex, offset, length):
|
|
|
|
return None, False
|
|
|
|
|
|
|
|
def _qXferResponse(self, data, has_more):
|
|
|
|
return "%s%s" % ("m" if has_more else "l", escape_binary(data))
|
|
|
|
|
2018-04-18 11:56:21 +00:00
|
|
|
def vAttach(self, pid):
|
|
|
|
raise self.UnexpectedPacketException()
|
|
|
|
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
def selectThread(self, op, thread_id):
|
|
|
|
return "OK"
|
|
|
|
|
2018-02-08 10:37:23 +00:00
|
|
|
def setBreakpoint(self, packet):
|
|
|
|
raise self.UnexpectedPacketException()
|
|
|
|
|
2018-09-12 21:35:02 +00:00
|
|
|
def threadStopInfo(self, threadnum):
|
|
|
|
return ""
|
|
|
|
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
def other(self, packet):
|
|
|
|
# empty string means unsupported
|
|
|
|
return ""
|
|
|
|
|
2018-10-23 23:45:56 +00:00
|
|
|
def QThreadSuffixSupported(self):
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def QListThreadsInStopReply(self):
|
|
|
|
return ""
|
|
|
|
|
2021-06-20 12:19:50 -07:00
|
|
|
def qMemoryRegionInfo(self, addr):
|
2018-10-23 23:45:56 +00:00
|
|
|
return ""
|
|
|
|
|
2020-08-24 17:34:32 +02:00
|
|
|
def qPathComplete(self):
|
|
|
|
return ""
|
|
|
|
|
2021-07-28 20:37:52 +02:00
|
|
|
def vFile(self, packet):
|
|
|
|
return ""
|
|
|
|
|
2021-08-11 22:58:11 +02:00
|
|
|
def vRun(self, packet):
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def qLaunchSuccess(self):
|
|
|
|
return ""
|
|
|
|
|
2021-08-12 17:01:30 +02:00
|
|
|
def QEnvironment(self, packet):
|
|
|
|
return "OK"
|
|
|
|
|
|
|
|
def QEnvironmentHexEncoded(self, packet):
|
|
|
|
return "OK"
|
|
|
|
|
2021-10-09 18:02:08 +02:00
|
|
|
def qRegisterInfo(self, num):
|
|
|
|
return ""
|
|
|
|
|
2021-11-04 13:23:12 +01:00
|
|
|
def k(self):
|
2021-11-18 13:56:36 +01:00
|
|
|
return ["W01", self.RESPONSE_DISCONNECT]
|
2021-11-04 13:23:12 +01:00
|
|
|
|
2018-02-08 10:37:23 +00:00
|
|
|
"""
|
|
|
|
Raised when we receive a packet for which there is no default action.
|
|
|
|
Override the responder class to implement behavior suitable for the test at
|
|
|
|
hand.
|
|
|
|
"""
|
|
|
|
class UnexpectedPacketException(Exception):
|
|
|
|
pass
|
|
|
|
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
|
[lldb] Introduce PlatformQemuUser
This adds a new platform class, whose job is to enable running
(debugging) executables under qemu.
(For general information about qemu, I recommend reading the RFC thread
on lldb-dev
<https://lists.llvm.org/pipermail/lldb-dev/2021-October/017106.html>.)
This initial patch implements the necessary boilerplate as well as the
minimal amount of functionality needed to actually be able to do
something useful (which, in this case means debugging a fully statically
linked executable).
The knobs necessary to emulate dynamically linked programs, as well as
to control other aspects of qemu operation (the emulated cpu, for
instance) will be added in subsequent patches. Same goes for the ability
to automatically bind to the executables of the emulated architecture.
Currently only two settings are available:
- architecture: the architecture that we should emulate
- emulator-path: the path to the emulator
Even though this patch is relatively small, it doesn't lack subtleties
that are worth calling out explicitly:
- named sockets: qemu supports tcp and unix socket connections, both of
them in the "forward connect" mode (qemu listening, lldb connecting).
Forward TCP connections are impossible to realise in a race-free way.
This is the reason why I chose unix sockets as they have larger, more
structured names, which can guarantee that there are no collisions
between concurrent connection attempts.
- the above means that this code will not work on windows. I don't think
that's an issue since user mode qemu does not support windows anyway.
- Right now, I am leaving the code enabled for windows, but maybe it
would be better to disable it (otoh, disabling it means windows
developers can't check they don't break it)
- qemu-user also does not support macOS, so one could contemplate
disabling it there too. However, macOS does support named sockets, so
one can even run the (mock) qemu tests there, and I think it'd be a
shame to lose that.
Differential Revision: https://reviews.llvm.org/D114509
2021-11-11 19:54:39 +01:00
|
|
|
class ServerChannel:
|
2021-09-30 22:30:30 +02:00
|
|
|
"""
|
|
|
|
A wrapper class for TCP or pty-based server.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get_connect_address(self):
|
|
|
|
"""Get address for the client to connect to."""
|
|
|
|
|
|
|
|
def get_connect_url(self):
|
|
|
|
"""Get URL suitable for process connect command."""
|
|
|
|
|
|
|
|
def close_server(self):
|
|
|
|
"""Close all resources used by the server."""
|
|
|
|
|
|
|
|
def accept(self):
|
|
|
|
"""Accept a single client connection to the server."""
|
|
|
|
|
|
|
|
def close_connection(self):
|
|
|
|
"""Close all resources used by the accepted connection."""
|
|
|
|
|
|
|
|
def recv(self):
|
|
|
|
"""Receive a data packet from the connected client."""
|
|
|
|
|
|
|
|
def sendall(self, data):
|
|
|
|
"""Send the data to the connected client."""
|
|
|
|
|
|
|
|
|
[lldb] Introduce PlatformQemuUser
This adds a new platform class, whose job is to enable running
(debugging) executables under qemu.
(For general information about qemu, I recommend reading the RFC thread
on lldb-dev
<https://lists.llvm.org/pipermail/lldb-dev/2021-October/017106.html>.)
This initial patch implements the necessary boilerplate as well as the
minimal amount of functionality needed to actually be able to do
something useful (which, in this case means debugging a fully statically
linked executable).
The knobs necessary to emulate dynamically linked programs, as well as
to control other aspects of qemu operation (the emulated cpu, for
instance) will be added in subsequent patches. Same goes for the ability
to automatically bind to the executables of the emulated architecture.
Currently only two settings are available:
- architecture: the architecture that we should emulate
- emulator-path: the path to the emulator
Even though this patch is relatively small, it doesn't lack subtleties
that are worth calling out explicitly:
- named sockets: qemu supports tcp and unix socket connections, both of
them in the "forward connect" mode (qemu listening, lldb connecting).
Forward TCP connections are impossible to realise in a race-free way.
This is the reason why I chose unix sockets as they have larger, more
structured names, which can guarantee that there are no collisions
between concurrent connection attempts.
- the above means that this code will not work on windows. I don't think
that's an issue since user mode qemu does not support windows anyway.
- Right now, I am leaving the code enabled for windows, but maybe it
would be better to disable it (otoh, disabling it means windows
developers can't check they don't break it)
- qemu-user also does not support macOS, so one could contemplate
disabling it there too. However, macOS does support named sockets, so
one can even run the (mock) qemu tests there, and I think it'd be a
shame to lose that.
Differential Revision: https://reviews.llvm.org/D114509
2021-11-11 19:54:39 +01:00
|
|
|
class ServerSocket(ServerChannel):
|
|
|
|
def __init__(self, family, type, proto, addr):
|
2021-09-30 22:30:30 +02:00
|
|
|
self._server_socket = socket.socket(family, type, proto)
|
|
|
|
self._connection = None
|
|
|
|
|
|
|
|
self._server_socket.bind(addr)
|
|
|
|
self._server_socket.listen(1)
|
|
|
|
|
|
|
|
def close_server(self):
|
|
|
|
self._server_socket.close()
|
|
|
|
|
|
|
|
def accept(self):
|
|
|
|
assert self._connection is None
|
|
|
|
# accept() is stubborn and won't fail even when the socket is
|
|
|
|
# shutdown, so we'll use a timeout
|
|
|
|
self._server_socket.settimeout(30.0)
|
|
|
|
client, client_addr = self._server_socket.accept()
|
|
|
|
# The connected client inherits its timeout from self._socket,
|
|
|
|
# but we'll use a blocking socket for the client
|
|
|
|
client.settimeout(None)
|
|
|
|
self._connection = client
|
|
|
|
|
|
|
|
def close_connection(self):
|
|
|
|
assert self._connection is not None
|
|
|
|
self._connection.close()
|
|
|
|
self._connection = None
|
|
|
|
|
|
|
|
def recv(self):
|
|
|
|
assert self._connection is not None
|
|
|
|
return self._connection.recv(4096)
|
|
|
|
|
|
|
|
def sendall(self, data):
|
|
|
|
assert self._connection is not None
|
|
|
|
return self._connection.sendall(data)
|
|
|
|
|
|
|
|
|
[lldb] Introduce PlatformQemuUser
This adds a new platform class, whose job is to enable running
(debugging) executables under qemu.
(For general information about qemu, I recommend reading the RFC thread
on lldb-dev
<https://lists.llvm.org/pipermail/lldb-dev/2021-October/017106.html>.)
This initial patch implements the necessary boilerplate as well as the
minimal amount of functionality needed to actually be able to do
something useful (which, in this case means debugging a fully statically
linked executable).
The knobs necessary to emulate dynamically linked programs, as well as
to control other aspects of qemu operation (the emulated cpu, for
instance) will be added in subsequent patches. Same goes for the ability
to automatically bind to the executables of the emulated architecture.
Currently only two settings are available:
- architecture: the architecture that we should emulate
- emulator-path: the path to the emulator
Even though this patch is relatively small, it doesn't lack subtleties
that are worth calling out explicitly:
- named sockets: qemu supports tcp and unix socket connections, both of
them in the "forward connect" mode (qemu listening, lldb connecting).
Forward TCP connections are impossible to realise in a race-free way.
This is the reason why I chose unix sockets as they have larger, more
structured names, which can guarantee that there are no collisions
between concurrent connection attempts.
- the above means that this code will not work on windows. I don't think
that's an issue since user mode qemu does not support windows anyway.
- Right now, I am leaving the code enabled for windows, but maybe it
would be better to disable it (otoh, disabling it means windows
developers can't check they don't break it)
- qemu-user also does not support macOS, so one could contemplate
disabling it there too. However, macOS does support named sockets, so
one can even run the (mock) qemu tests there, and I think it'd be a
shame to lose that.
Differential Revision: https://reviews.llvm.org/D114509
2021-11-11 19:54:39 +01:00
|
|
|
class TCPServerSocket(ServerSocket):
|
|
|
|
def __init__(self):
|
|
|
|
family, type, proto, _, addr = socket.getaddrinfo(
|
|
|
|
"localhost", 0, proto=socket.IPPROTO_TCP)[0]
|
|
|
|
super().__init__(family, type, proto, addr)
|
|
|
|
|
|
|
|
def get_connect_address(self):
|
|
|
|
return "[{}]:{}".format(*self._server_socket.getsockname())
|
|
|
|
|
|
|
|
def get_connect_url(self):
|
|
|
|
return "connect://" + self.get_connect_address()
|
|
|
|
|
|
|
|
|
|
|
|
class UnixServerSocket(ServerSocket):
|
|
|
|
def __init__(self, addr):
|
|
|
|
super().__init__(socket.AF_UNIX, socket.SOCK_STREAM, 0, addr)
|
|
|
|
|
|
|
|
def get_connect_address(self):
|
|
|
|
return self._server_socket.getsockname()
|
|
|
|
|
|
|
|
def get_connect_url(self):
|
|
|
|
return "unix-connect://" + self.get_connect_address()
|
|
|
|
|
|
|
|
|
|
|
|
class PtyServerSocket(ServerChannel):
|
2021-09-30 22:30:30 +02:00
|
|
|
def __init__(self):
|
2021-10-01 15:24:49 +02:00
|
|
|
import pty
|
|
|
|
import tty
|
2021-11-10 08:50:14 -06:00
|
|
|
primary, secondary = pty.openpty()
|
|
|
|
tty.setraw(primary)
|
|
|
|
self._primary = io.FileIO(primary, 'r+b')
|
|
|
|
self._secondary = io.FileIO(secondary, 'r+b')
|
2021-09-30 22:30:30 +02:00
|
|
|
|
|
|
|
def get_connect_address(self):
|
|
|
|
libc = ctypes.CDLL(None)
|
|
|
|
libc.ptsname.argtypes = (ctypes.c_int,)
|
|
|
|
libc.ptsname.restype = ctypes.c_char_p
|
2021-11-10 08:50:14 -06:00
|
|
|
return libc.ptsname(self._primary.fileno()).decode()
|
2021-09-30 22:30:30 +02:00
|
|
|
|
|
|
|
def get_connect_url(self):
|
2021-10-07 23:14:23 +02:00
|
|
|
return "serial://" + self.get_connect_address()
|
2021-09-30 22:30:30 +02:00
|
|
|
|
|
|
|
def close_server(self):
|
2021-11-10 08:50:14 -06:00
|
|
|
self._secondary.close()
|
|
|
|
self._primary.close()
|
2021-09-30 22:30:30 +02:00
|
|
|
|
|
|
|
def recv(self):
|
|
|
|
try:
|
2021-11-10 08:50:14 -06:00
|
|
|
return self._primary.read(4096)
|
2021-09-30 22:30:30 +02:00
|
|
|
except OSError as e:
|
|
|
|
# closing the pty results in EIO on Linux, convert it to EOF
|
|
|
|
if e.errno == errno.EIO:
|
|
|
|
return b''
|
|
|
|
raise
|
|
|
|
|
|
|
|
def sendall(self, data):
|
2021-11-10 08:50:14 -06:00
|
|
|
return self._primary.write(data)
|
2021-09-30 22:30:30 +02:00
|
|
|
|
|
|
|
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
class MockGDBServer:
|
|
|
|
"""
|
|
|
|
A simple TCP-based GDB server that can test client behavior by receiving
|
|
|
|
commands and issuing custom-tailored responses.
|
|
|
|
|
|
|
|
Responses are generated via the .responder property, which should be an
|
|
|
|
instance of a class based on MockGDBServerResponder.
|
|
|
|
"""
|
|
|
|
|
|
|
|
responder = None
|
|
|
|
_socket = None
|
|
|
|
_thread = None
|
|
|
|
_receivedData = None
|
|
|
|
_receivedDataOffset = None
|
|
|
|
_shouldSendAck = True
|
|
|
|
|
2021-11-18 13:52:44 +01:00
|
|
|
def __init__(self, socket):
|
|
|
|
self._socket = socket
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
self.responder = MockGDBServerResponder()
|
|
|
|
|
|
|
|
def start(self):
|
2020-11-02 16:11:47 +01:00
|
|
|
# Start a thread that waits for a client connection.
|
2021-11-18 13:52:44 +01:00
|
|
|
self._thread = threading.Thread(target=self.run)
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
self._thread.start()
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
self._thread.join()
|
|
|
|
self._thread = None
|
|
|
|
|
2020-11-02 16:11:47 +01:00
|
|
|
def get_connect_address(self):
|
2021-09-30 22:30:30 +02:00
|
|
|
return self._socket.get_connect_address()
|
|
|
|
|
|
|
|
def get_connect_url(self):
|
|
|
|
return self._socket.get_connect_url()
|
2020-11-02 16:11:47 +01:00
|
|
|
|
2021-11-18 13:52:44 +01:00
|
|
|
def run(self):
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
# For testing purposes, we only need to worry about one client
|
|
|
|
# connecting just one time.
|
|
|
|
try:
|
2021-09-30 22:30:30 +02:00
|
|
|
self._socket.accept()
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
except:
|
[lldb] Introduce PlatformQemuUser
This adds a new platform class, whose job is to enable running
(debugging) executables under qemu.
(For general information about qemu, I recommend reading the RFC thread
on lldb-dev
<https://lists.llvm.org/pipermail/lldb-dev/2021-October/017106.html>.)
This initial patch implements the necessary boilerplate as well as the
minimal amount of functionality needed to actually be able to do
something useful (which, in this case means debugging a fully statically
linked executable).
The knobs necessary to emulate dynamically linked programs, as well as
to control other aspects of qemu operation (the emulated cpu, for
instance) will be added in subsequent patches. Same goes for the ability
to automatically bind to the executables of the emulated architecture.
Currently only two settings are available:
- architecture: the architecture that we should emulate
- emulator-path: the path to the emulator
Even though this patch is relatively small, it doesn't lack subtleties
that are worth calling out explicitly:
- named sockets: qemu supports tcp and unix socket connections, both of
them in the "forward connect" mode (qemu listening, lldb connecting).
Forward TCP connections are impossible to realise in a race-free way.
This is the reason why I chose unix sockets as they have larger, more
structured names, which can guarantee that there are no collisions
between concurrent connection attempts.
- the above means that this code will not work on windows. I don't think
that's an issue since user mode qemu does not support windows anyway.
- Right now, I am leaving the code enabled for windows, but maybe it
would be better to disable it (otoh, disabling it means windows
developers can't check they don't break it)
- qemu-user also does not support macOS, so one could contemplate
disabling it there too. However, macOS does support named sockets, so
one can even run the (mock) qemu tests there, and I think it'd be a
shame to lose that.
Differential Revision: https://reviews.llvm.org/D114509
2021-11-11 19:54:39 +01:00
|
|
|
traceback.print_exc()
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
return
|
|
|
|
self._shouldSendAck = True
|
|
|
|
self._receivedData = ""
|
|
|
|
self._receivedDataOffset = 0
|
|
|
|
data = None
|
2021-11-18 13:56:36 +01:00
|
|
|
try:
|
|
|
|
while True:
|
2021-09-30 22:30:30 +02:00
|
|
|
data = seven.bitcast_to_string(self._socket.recv())
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
if data is None or len(data) == 0:
|
|
|
|
break
|
2018-05-14 21:04:24 +00:00
|
|
|
self._receive(data)
|
2021-11-18 13:56:36 +01:00
|
|
|
except self.TerminateConnectionException:
|
|
|
|
pass
|
|
|
|
except Exception as e:
|
|
|
|
print("An exception happened when receiving the response from the gdb server. Closing the client...")
|
|
|
|
traceback.print_exc()
|
|
|
|
finally:
|
|
|
|
self._socket.close_connection()
|
|
|
|
self._socket.close_server()
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
|
|
|
|
def _receive(self, data):
|
|
|
|
"""
|
|
|
|
Collects data, parses and responds to as many packets as exist.
|
|
|
|
Any leftover data is kept for parsing the next time around.
|
|
|
|
"""
|
|
|
|
self._receivedData += data
|
2021-11-18 13:56:36 +01:00
|
|
|
packet = self._parsePacket()
|
|
|
|
while packet is not None:
|
|
|
|
self._handlePacket(packet)
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
packet = self._parsePacket()
|
|
|
|
|
|
|
|
def _parsePacket(self):
|
|
|
|
"""
|
|
|
|
Reads bytes from self._receivedData, returning:
|
|
|
|
- a packet's contents if a valid packet is found
|
|
|
|
- the PACKET_ACK unique object if we got an ack
|
|
|
|
- None if we only have a partial packet
|
|
|
|
|
|
|
|
Raises an InvalidPacketException if unexpected data is received
|
|
|
|
or if checksums fail.
|
|
|
|
|
|
|
|
Once a complete packet is found at the front of self._receivedData,
|
|
|
|
its data is removed form self._receivedData.
|
|
|
|
"""
|
|
|
|
data = self._receivedData
|
|
|
|
i = self._receivedDataOffset
|
|
|
|
data_len = len(data)
|
|
|
|
if data_len == 0:
|
|
|
|
return None
|
|
|
|
if i == 0:
|
|
|
|
# If we're looking at the start of the received data, that means
|
|
|
|
# we're looking for the start of a new packet, denoted by a $.
|
|
|
|
# It's also possible we'll see an ACK here, denoted by a +
|
|
|
|
if data[0] == '+':
|
|
|
|
self._receivedData = data[1:]
|
|
|
|
return self.PACKET_ACK
|
2018-02-08 10:37:23 +00:00
|
|
|
if ord(data[0]) == 3:
|
|
|
|
self._receivedData = data[1:]
|
|
|
|
return self.PACKET_INTERRUPT
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
if data[0] == '$':
|
|
|
|
i += 1
|
|
|
|
else:
|
|
|
|
raise self.InvalidPacketException(
|
2018-05-14 21:04:24 +00:00
|
|
|
"Unexpected leading byte: %s" % data[0])
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
|
|
|
|
# If we're looking beyond the start of the received data, then we're
|
|
|
|
# looking for the end of the packet content, denoted by a #.
|
|
|
|
# Note that we pick up searching from where we left off last time
|
|
|
|
while i < data_len and data[i] != '#':
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
# If there isn't enough data left for a checksum, just remember where
|
|
|
|
# we left off so we can pick up there the next time around
|
|
|
|
if i > data_len - 3:
|
|
|
|
self._receivedDataOffset = i
|
|
|
|
return None
|
|
|
|
|
|
|
|
# If we have enough data remaining for the checksum, extract it and
|
|
|
|
# compare to the packet contents
|
|
|
|
packet = data[1:i]
|
|
|
|
i += 1
|
|
|
|
try:
|
|
|
|
check = int(data[i:i + 2], 16)
|
|
|
|
except ValueError:
|
|
|
|
raise self.InvalidPacketException("Checksum is not valid hex")
|
|
|
|
i += 2
|
|
|
|
if check != checksum(packet):
|
|
|
|
raise self.InvalidPacketException(
|
|
|
|
"Checksum %02x does not match content %02x" %
|
|
|
|
(check, checksum(packet)))
|
|
|
|
# remove parsed bytes from _receivedData and reset offset so parsing
|
|
|
|
# can start on the next packet the next time around
|
|
|
|
self._receivedData = data[i:]
|
|
|
|
self._receivedDataOffset = 0
|
|
|
|
return packet
|
|
|
|
|
2021-11-18 13:56:36 +01:00
|
|
|
def _sendPacket(self, packet):
|
|
|
|
self._socket.sendall(seven.bitcast_to_bytes(frame_packet(packet)))
|
|
|
|
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
def _handlePacket(self, packet):
|
|
|
|
if packet is self.PACKET_ACK:
|
2018-02-01 11:29:06 +00:00
|
|
|
# Ignore ACKs from the client. For the future, we can consider
|
|
|
|
# adding validation code to make sure the client only sends ACKs
|
|
|
|
# when it's supposed to.
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
return
|
|
|
|
response = ""
|
|
|
|
# We'll handle the ack stuff here since it's not something any of the
|
2018-05-14 21:04:24 +00:00
|
|
|
# tests will be concerned about, and it'll get turned off quickly anyway.
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
if self._shouldSendAck:
|
2021-09-30 22:30:30 +02:00
|
|
|
self._socket.sendall(seven.bitcast_to_bytes('+'))
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
if packet == "QStartNoAckMode":
|
|
|
|
self._shouldSendAck = False
|
|
|
|
response = "OK"
|
|
|
|
elif self.responder is not None:
|
|
|
|
# Delegate everything else to our responder
|
|
|
|
response = self.responder.respond(packet)
|
2021-11-18 13:56:36 +01:00
|
|
|
if not isinstance(response, list):
|
|
|
|
response = [response]
|
|
|
|
for part in response:
|
|
|
|
if part is MockGDBServerResponder.RESPONSE_DISCONNECT:
|
|
|
|
raise self.TerminateConnectionException()
|
|
|
|
self._sendPacket(part)
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
|
|
|
|
PACKET_ACK = object()
|
2018-02-08 10:37:23 +00:00
|
|
|
PACKET_INTERRUPT = object()
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
|
2021-11-18 13:56:36 +01:00
|
|
|
class TerminateConnectionException(Exception):
|
[lldb] Generic base for testing gdb-remote behavior
Summary:
Adds new utilities that make it easier to write test cases for lldb acting as a client over a gdb-remote connection.
- A GDBRemoteTestBase class that starts a mock GDB server and provides an easy way to check client packets
- A MockGDBServer that, via MockGDBServerResponder, can be made to issue server responses that test client behavior.
- Utility functions for handling common data encoding/decoding
- Utility functions for creating dummy targets from YAML files
----
Split from the review at https://reviews.llvm.org/D42145, which was a new feature that necessitated the new testing capabilities.
Reviewers: clayborg, labath
Reviewed By: clayborg, labath
Subscribers: hintonda, davide, jingham, krytarowski, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D42195
Patch by Owen Shaw <llvm@owenpshaw.net>
llvm-svn: 323636
2018-01-29 10:02:40 +00:00
|
|
|
pass
|
|
|
|
|
2021-11-18 13:56:36 +01:00
|
|
|
class InvalidPacketException(Exception):
|
|
|
|
pass
|