https://github.com/walter-erquinigo created 
https://github.com/llvm/llvm-project/pull/152170

…rotocol

When writing a custom gdb-remote server I realized that the encoder and decoder 
of register formats is incomplete.

- Add the encoder on the server side and add an llvm_unreachable is there's a 
missing case.
- Add a decoder on the client side that doesn't fail. We have to keep it 
flexible.

I couldn't figure out an easy way to test this but the changes seem very 
straightforward to me.

>From fc01de0db2b9244d8a697fcb40912edc9baac1f2 Mon Sep 17 00:00:00 2001
From: Walter Erquinigo <werquin...@nvidia.com>
Date: Tue, 5 Aug 2025 09:19:38 -0700
Subject: [PATCH] [LLDB] Complete a missing register format mapping in the
 gdb-remote protocol

When writing a custom gdb-remote server I realized that the encoder and
decoder of register formats is incomplete.

- Add the encoder on the server side and add an llvm_unreachable is
  there's a missing case.
- Add a decoder on the client side that doesn't fail. We have to keep it
  flexible.

I couldn't figure out an easy way to test this but the changes seem very
straightforward to me.
---
 .../GDBRemoteCommunicationServerLLGS.cpp      | 59 ++++++++++++++++++-
 .../Process/gdb-remote/ProcessGDBRemote.cpp   | 27 +++++++++
 2 files changed, 85 insertions(+), 1 deletion(-)

diff --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 89d2730cfccd0..04786afedc184 100644
--- 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -41,6 +41,7 @@
 #include "lldb/Utility/StreamString.h"
 #include "lldb/Utility/UnimplementedError.h"
 #include "lldb/Utility/UriParser.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/TargetParser/Triple.h"
@@ -536,14 +537,54 @@ static llvm::StringRef GetEncodingNameOrEmpty(const 
RegisterInfo &reg_info) {
 
 static llvm::StringRef GetFormatNameOrEmpty(const RegisterInfo &reg_info) {
   switch (reg_info.format) {
+  case eFormatDefault:
+    return "";
+  case eFormatBoolean:
+    return "boolean";
   case eFormatBinary:
     return "binary";
+  case eFormatBytes:
+    return "bytes";
+  case eFormatBytesWithASCII:
+    return "bytes-with-ascii";
+  case eFormatChar:
+    return "char";
+  case eFormatCharPrintable:
+    return "char-printable";
+  case eFormatComplex:
+    return "complex";
+  case eFormatCString:
+    return "cstring";
   case eFormatDecimal:
     return "decimal";
+  case eFormatEnum:
+    return "enum";
   case eFormatHex:
     return "hex";
+  case eFormatHexUppercase:
+    return "hex-uppercase";
   case eFormatFloat:
     return "float";
+  case eFormatOctal:
+    return "octal";
+  case eFormatOSType:
+    return "ostype";
+  case eFormatUnicode16:
+    return "unicode16";
+  case eFormatUnicode32:
+    return "unicode32";
+  case eFormatUnsigned:
+    return "unsigned";
+  case eFormatPointer:
+    return "pointer";
+  case eFormatVectorOfChar:
+    return "vector-char";
+  case eFormatVectorOfSInt64:
+    return "vector-sint64";
+  case eFormatVectorOfFloat16:
+    return "vector-float16";
+  case eFormatVectorOfFloat64:
+    return "vector-float64";
   case eFormatVectorOfSInt8:
     return "vector-sint8";
   case eFormatVectorOfUInt8:
@@ -562,8 +603,24 @@ static llvm::StringRef GetFormatNameOrEmpty(const 
RegisterInfo &reg_info) {
     return "vector-uint64";
   case eFormatVectorOfUInt128:
     return "vector-uint128";
+  case eFormatComplexInteger:
+    return "complex-integer";
+  case eFormatCharArray:
+    return "char-array";
+  case eFormatAddressInfo:
+    return "address-info";
+  case eFormatHexFloat:
+    return "hex-float";
+  case eFormatInstruction:
+    return "instruction";
+  case eFormatVoid:
+    return "void";
+  case eFormatUnicode8:
+    return "unicode8";
+  case eFormatFloat128:
+    return "float128";
   default:
-    return "";
+    llvm_unreachable("Unkown register format")
   };
 }
 
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index f610422d34169..85e141d41747e 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -481,10 +481,29 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool 
force) {
                     .Success())
               reg_info.format =
                   llvm::StringSwitch<Format>(value)
+                      .Case("boolean", eFormatBoolean)
                       .Case("binary", eFormatBinary)
+                      .Case("bytes", eFormatBytes)
+                      .Case("bytes-with-ascii", eFormatBytesWithASCII)
+                      .Case("char", eFormatChar)
+                      .Case("char-printable", eFormatCharPrintable)
+                      .Case("complex", eFormatComplex)
+                      .Case("cstring", eFormatCString)
                       .Case("decimal", eFormatDecimal)
+                      .Case("enum", eFormatEnum)
                       .Case("hex", eFormatHex)
+                      .Case("hex-uppercase", eFormatHexUppercase)
                       .Case("float", eFormatFloat)
+                      .Case("octal", eFormatOctal)
+                      .Case("ostype", eFormatOSType)
+                      .Case("unicode16", eFormatUnicode16)
+                      .Case("unicode32", eFormatUnicode32)
+                      .Case("unsigned", eFormatUnsigned)
+                      .Case("pointer", eFormatPointer)
+                      .Case("vector-char", eFormatVectorOfChar)
+                      .Case("vector-sint64", eFormatVectorOfSInt64)
+                      .Case("vector-float16", eFormatVectorOfFloat16)
+                      .Case("vector-float64", eFormatVectorOfFloat64)
                       .Case("vector-sint8", eFormatVectorOfSInt8)
                       .Case("vector-uint8", eFormatVectorOfUInt8)
                       .Case("vector-sint16", eFormatVectorOfSInt16)
@@ -494,6 +513,14 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool 
force) {
                       .Case("vector-float32", eFormatVectorOfFloat32)
                       .Case("vector-uint64", eFormatVectorOfUInt64)
                       .Case("vector-uint128", eFormatVectorOfUInt128)
+                      .Case("complex-integer", eFormatComplexInteger)
+                      .Case("char-array", eFormatCharArray)
+                      .Case("address-info", eFormatAddressInfo)
+                      .Case("hex-float", eFormatHexFloat)
+                      .Case("instruction", eFormatInstruction)
+                      .Case("void", eFormatVoid)
+                      .Case("unicode8", eFormatUnicode8)
+                      .Case("float128", eFormatFloat128)
                       .Default(eFormatInvalid);
           } else if (name == "set") {
             reg_info.set_name.SetString(value);

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to