Skip to content

Commit a7c1745

Browse files
labathadrian-prantl
authored andcommitted
[lldb] Only send "posix" error codes through the gdb-remote protocol
The other side has no way of telling which namespace do these codes belong to, so mashing them all together is not very helpful. I'm mainly doing this to simplify some code in a pending patch <https://github.com/llvm/llvm-project/pull/106774/files#r1752628604>, and I've picked the posix error category semi-randomly. If we wanted to be serious about assigning meaning to these error codes, we should create a special error category for "gdb errors".
1 parent e0ad34e commit a7c1745

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,14 @@ GDBRemoteCommunicationServer::SendErrorResponse(uint8_t err) {
103103

104104
GDBRemoteCommunication::PacketResult
105105
GDBRemoteCommunicationServer::SendErrorResponse(const Status &error) {
106+
uint8_t code = error.GetType() == eErrorTypePOSIX ? error.GetError() : 0xff;
106107
if (m_send_error_strings) {
107108
lldb_private::StreamString packet;
108-
packet.Printf("E%2.2x;", static_cast<uint8_t>(error.GetError()));
109+
packet.Printf("E%2.2x;", code);
109110
packet.PutStringAsRawHex8(error.AsCString());
110111
return SendPacketNoLock(packet.GetString());
111-
} else
112-
return SendErrorResponse(error.GetError());
112+
}
113+
return SendErrorResponse(code);
113114
}
114115

115116
GDBRemoteCommunication::PacketResult

lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
1313
#include "lldb/Utility/Connection.h"
1414
#include "lldb/Utility/UnimplementedError.h"
15+
#include "lldb/lldb-enumerations.h"
1516

1617
namespace lldb_private {
1718
namespace process_gdb_remote {
@@ -25,7 +26,7 @@ TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorNumber) {
2526

2627
TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_Status) {
2728
MockServerWithMockConnection server;
28-
Status status(0x42, lldb::eErrorTypeGeneric, "Test error message");
29+
Status status(0x42, lldb::eErrorTypePOSIX, "Test error message");
2930
server.SendErrorResponse(status);
3031

3132
EXPECT_THAT(

0 commit comments

Comments
 (0)