[Lldb-commits] [lldb] [lldb] Add support for changing char in Scalar::SetValueFromCString (PR #67784)
    Pavel Kosov via lldb-commits 
    lldb-commits at lists.llvm.org
       
    Fri Sep 29 03:20:22 PDT 2023
    
    
  
https://github.com/kpdev created https://github.com/llvm/llvm-project/pull/67784
When we trying to change not the whole string,
but single character in it - lldb's ValueObject fits in Scalar and therefore lldb trying to update it as a Scalar value which is currently only support numbers, so characters support added.
~~
Huawei RRI, OS Lab
>From 55dbf63ab7a052859fc7b297f699f0957484d3bf Mon Sep 17 00:00:00 2001
From: Pavel Kosov <kpdev42 at gmail.com>
Date: Fri, 29 Sep 2023 12:04:16 +0300
Subject: [PATCH] [lldb] Add support for changing char in
 Scalar::SetValueFromCString
When we trying to change not the whole string,
but single character in it - lldb's ValueObject fits in Scalar
and therefore lldb trying to update it as a Scalar value
which is currently only support numbers, so characters support added.
~~
Huawei RRI, OS Lab
---
 lldb/source/Utility/Scalar.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index 791c0fb74352913..33d0b832bfd9be6 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -18,6 +18,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 
+#include <cctype> // for std::isalpha
 #include <cinttypes>
 #include <cstdio>
 
@@ -646,7 +647,15 @@ Status Scalar::SetValueFromCString(const char *value_str, Encoding encoding,
     bool is_signed = encoding == eEncodingSint;
     bool is_negative = is_signed && str.consume_front("-");
     APInt integer;
-    if (str.getAsInteger(0, integer)) {
+    if (str.size() == 1 && std::isalpha(static_cast<unsigned char>(str[0]))) {
+      // We can represent single character as Scalar -
+      // this is useful when working with symbols in string
+      // NOTE: it is okay to consider char size as 8-bit since we only have
+      // `SetValueFrom C String` api, not the `C Wstring` or something like
+      // that. If we can ever get wide characters here - we have to modify this
+      // behaviour somehow.
+      integer = APInt(8, static_cast<uint64_t>(str[0]));
+    } else if (str.getAsInteger(0, integer)) {
       error.SetErrorStringWithFormatv(
           "'{0}' is not a valid integer string value", value_str);
       break;
    
    
More information about the lldb-commits
mailing list