Skip to content

Commit 9179b07

Browse files
[LLDB] Complete a missing register format mapping in the gdb-remote p… (#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.
1 parent b5bf100 commit 9179b07

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "lldb/Utility/StreamString.h"
4242
#include "lldb/Utility/UnimplementedError.h"
4343
#include "lldb/Utility/UriParser.h"
44+
#include "llvm/Support/ErrorHandling.h"
4445
#include "llvm/Support/JSON.h"
4546
#include "llvm/Support/ScopedPrinter.h"
4647
#include "llvm/TargetParser/Triple.h"
@@ -536,14 +537,54 @@ static llvm::StringRef GetEncodingNameOrEmpty(const RegisterInfo &reg_info) {
536537

537538
static llvm::StringRef GetFormatNameOrEmpty(const RegisterInfo &reg_info) {
538539
switch (reg_info.format) {
540+
case eFormatDefault:
541+
return "";
542+
case eFormatBoolean:
543+
return "boolean";
539544
case eFormatBinary:
540545
return "binary";
546+
case eFormatBytes:
547+
return "bytes";
548+
case eFormatBytesWithASCII:
549+
return "bytes-with-ascii";
550+
case eFormatChar:
551+
return "char";
552+
case eFormatCharPrintable:
553+
return "char-printable";
554+
case eFormatComplex:
555+
return "complex";
556+
case eFormatCString:
557+
return "cstring";
541558
case eFormatDecimal:
542559
return "decimal";
560+
case eFormatEnum:
561+
return "enum";
543562
case eFormatHex:
544563
return "hex";
564+
case eFormatHexUppercase:
565+
return "hex-uppercase";
545566
case eFormatFloat:
546567
return "float";
568+
case eFormatOctal:
569+
return "octal";
570+
case eFormatOSType:
571+
return "ostype";
572+
case eFormatUnicode16:
573+
return "unicode16";
574+
case eFormatUnicode32:
575+
return "unicode32";
576+
case eFormatUnsigned:
577+
return "unsigned";
578+
case eFormatPointer:
579+
return "pointer";
580+
case eFormatVectorOfChar:
581+
return "vector-char";
582+
case eFormatVectorOfSInt64:
583+
return "vector-sint64";
584+
case eFormatVectorOfFloat16:
585+
return "vector-float16";
586+
case eFormatVectorOfFloat64:
587+
return "vector-float64";
547588
case eFormatVectorOfSInt8:
548589
return "vector-sint8";
549590
case eFormatVectorOfUInt8:
@@ -562,8 +603,24 @@ static llvm::StringRef GetFormatNameOrEmpty(const RegisterInfo &reg_info) {
562603
return "vector-uint64";
563604
case eFormatVectorOfUInt128:
564605
return "vector-uint128";
606+
case eFormatComplexInteger:
607+
return "complex-integer";
608+
case eFormatCharArray:
609+
return "char-array";
610+
case eFormatAddressInfo:
611+
return "address-info";
612+
case eFormatHexFloat:
613+
return "hex-float";
614+
case eFormatInstruction:
615+
return "instruction";
616+
case eFormatVoid:
617+
return "void";
618+
case eFormatUnicode8:
619+
return "unicode8";
620+
case eFormatFloat128:
621+
return "float128";
565622
default:
566-
return "";
623+
llvm_unreachable("Unkown register format")
567624
};
568625
}
569626

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,29 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
481481
.Success())
482482
reg_info.format =
483483
llvm::StringSwitch<Format>(value)
484+
.Case("boolean", eFormatBoolean)
484485
.Case("binary", eFormatBinary)
486+
.Case("bytes", eFormatBytes)
487+
.Case("bytes-with-ascii", eFormatBytesWithASCII)
488+
.Case("char", eFormatChar)
489+
.Case("char-printable", eFormatCharPrintable)
490+
.Case("complex", eFormatComplex)
491+
.Case("cstring", eFormatCString)
485492
.Case("decimal", eFormatDecimal)
493+
.Case("enum", eFormatEnum)
486494
.Case("hex", eFormatHex)
495+
.Case("hex-uppercase", eFormatHexUppercase)
487496
.Case("float", eFormatFloat)
497+
.Case("octal", eFormatOctal)
498+
.Case("ostype", eFormatOSType)
499+
.Case("unicode16", eFormatUnicode16)
500+
.Case("unicode32", eFormatUnicode32)
501+
.Case("unsigned", eFormatUnsigned)
502+
.Case("pointer", eFormatPointer)
503+
.Case("vector-char", eFormatVectorOfChar)
504+
.Case("vector-sint64", eFormatVectorOfSInt64)
505+
.Case("vector-float16", eFormatVectorOfFloat16)
506+
.Case("vector-float64", eFormatVectorOfFloat64)
488507
.Case("vector-sint8", eFormatVectorOfSInt8)
489508
.Case("vector-uint8", eFormatVectorOfUInt8)
490509
.Case("vector-sint16", eFormatVectorOfSInt16)
@@ -494,6 +513,14 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
494513
.Case("vector-float32", eFormatVectorOfFloat32)
495514
.Case("vector-uint64", eFormatVectorOfUInt64)
496515
.Case("vector-uint128", eFormatVectorOfUInt128)
516+
.Case("complex-integer", eFormatComplexInteger)
517+
.Case("char-array", eFormatCharArray)
518+
.Case("address-info", eFormatAddressInfo)
519+
.Case("hex-float", eFormatHexFloat)
520+
.Case("instruction", eFormatInstruction)
521+
.Case("void", eFormatVoid)
522+
.Case("unicode8", eFormatUnicode8)
523+
.Case("float128", eFormatFloat128)
497524
.Default(eFormatInvalid);
498525
} else if (name == "set") {
499526
reg_info.set_name.SetString(value);

0 commit comments

Comments
 (0)