[Lldb-commits] [lldb] f5eaa2a - [lldb] Replace std::isprint/isspace with llvm's locale-independent version

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 19 10:18:18 PDT 2020


Author: Raphael Isemann
Date: 2020-06-19T19:17:56+02:00
New Revision: f5eaa2afe2a9faa2d05ca46e006e770d17c32778

URL: https://github.com/llvm/llvm-project/commit/f5eaa2afe2a9faa2d05ca46e006e770d17c32778
DIFF: https://github.com/llvm/llvm-project/commit/f5eaa2afe2a9faa2d05ca46e006e770d17c32778.diff

LOG: [lldb] Replace std::isprint/isspace with llvm's locale-independent version

Summary:
LLVM is using its own isPrint/isSpace implementation that doesn't change depending on the current locale. LLDB should do the same
to prevent that internal logic changes depending on the set locale.

Reviewers: JDevlieghere, labath, mib, totally_not_teemperor

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D82175

Added: 
    

Modified: 
    lldb/include/lldb/Interpreter/Options.h
    lldb/source/Core/DumpDataExtractor.cpp
    lldb/source/Core/IOHandler.cpp
    lldb/source/Core/IOHandlerCursesGUI.cpp
    lldb/source/Interpreter/CommandInterpreter.cpp
    lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
    lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/source/Utility/Args.cpp
    lldb/source/Utility/DataExtractor.cpp
    lldb/source/Utility/Event.cpp
    lldb/source/Utility/StringExtractor.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Interpreter/Options.h b/lldb/include/lldb/Interpreter/Options.h
index a47b194bc681..ebceaea8383d 100644
--- a/lldb/include/lldb/Interpreter/Options.h
+++ b/lldb/include/lldb/Interpreter/Options.h
@@ -43,7 +43,7 @@ typedef std::vector<OptionArgElement> OptionElementVector;
 static inline bool isprint8(int ch) {
   if (ch & 0xffffff00u)
     return false;
-  return isprint(ch);
+  return llvm::isPrint(ch);
 }
 
 /// \class Options Options.h "lldb/Interpreter/Options.h"

diff  --git a/lldb/source/Core/DumpDataExtractor.cpp b/lldb/source/Core/DumpDataExtractor.cpp
index f715e9a16891..233a1b373550 100644
--- a/lldb/source/Core/DumpDataExtractor.cpp
+++ b/lldb/source/Core/DumpDataExtractor.cpp
@@ -284,7 +284,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
 
       const uint64_t ch = DE.GetMaxU64Bitfield(&offset, item_byte_size,
                                                item_bit_size, item_bit_offset);
-      if (isprint(ch))
+      if (llvm::isPrint(ch))
         s->Printf("%c", (char)ch);
       else if (item_format != eFormatCharPrintable) {
         switch (ch) {
@@ -375,7 +375,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
       s->PutChar('\'');
       for (uint32_t i = 0; i < item_byte_size; ++i) {
         uint8_t ch = (uint8_t)(uval64 >> ((item_byte_size - i - 1) * 8));
-        if (isprint(ch))
+        if (llvm::isPrint(ch))
           s->Printf("%c", ch);
         else {
           switch (ch) {
@@ -425,7 +425,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
         s->PutChar('\"');
 
         while (const char c = *cstr) {
-          if (isprint(c)) {
+          if (llvm::isPrint(c)) {
             s->PutChar(c);
           } else {
             switch (c) {

diff  --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp
index c8c5a52c4331..cd9531b17a92 100644
--- a/lldb/source/Core/IOHandler.cpp
+++ b/lldb/source/Core/IOHandler.cpp
@@ -310,7 +310,7 @@ static Optional<std::string> SplitLine(std::string &line_buffer) {
 // If the final line of the file ends without a end-of-line, return
 // it as a line anyway.
 static Optional<std::string> SplitLineEOF(std::string &line_buffer) {
-  if (llvm::all_of(line_buffer, isspace))
+  if (llvm::all_of(line_buffer, llvm::isSpace))
     return None;
   std::string line = std::move(line_buffer);
   line_buffer.clear();

diff  --git a/lldb/source/Core/IOHandlerCursesGUI.cpp b/lldb/source/Core/IOHandlerCursesGUI.cpp
index c5f365973c40..49e93cd11dd1 100644
--- a/lldb/source/Core/IOHandlerCursesGUI.cpp
+++ b/lldb/source/Core/IOHandlerCursesGUI.cpp
@@ -919,7 +919,7 @@ void Menu::DrawMenuTitle(Window &window, bool highlight) {
     const attr_t hilgight_attr = A_REVERSE;
     if (highlight)
       window.AttributeOn(hilgight_attr);
-    if (isprint(shortcut_key)) {
+    if (llvm::isPrint(shortcut_key)) {
       size_t lower_pos = m_name.find(tolower(shortcut_key));
       size_t upper_pos = m_name.find(toupper(shortcut_key));
       const char *name = m_name.c_str();
@@ -948,7 +948,7 @@ void Menu::DrawMenuTitle(Window &window, bool highlight) {
       window.AttributeOff(hilgight_attr);
 
     if (m_key_name.empty()) {
-      if (!underlined_shortcut && isprint(m_key_value)) {
+      if (!underlined_shortcut && llvm::isPrint(m_key_value)) {
         window.AttributeOn(COLOR_PAIR(3));
         window.Printf(" (%c)", m_key_value);
         window.AttributeOff(COLOR_PAIR(3));
@@ -2715,7 +2715,7 @@ static const char *CursesKeyToCString(int ch) {
   case KEY_ESCAPE:
     return "escape";
   default:
-    if (isprint(ch))
+    if (llvm::isPrint(ch))
       snprintf(g_desc, sizeof(g_desc), "%c", ch);
     else
       snprintf(g_desc, sizeof(g_desc), "\\x%2.2x", ch);

diff  --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 2eedfc2e7c61..e55b25500179 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1340,10 +1340,10 @@ static size_t FindArgumentTerminator(const std::string &s) {
     if (pos == std::string::npos)
       break;
     if (pos > 0) {
-      if (isspace(s[pos - 1])) {
+      if (llvm::isSpace(s[pos - 1])) {
         // Check if the string ends "\s--" (where \s is a space character) or
         // if we have "\s--\s".
-        if ((pos + 2 >= s_len) || isspace(s[pos + 2])) {
+        if ((pos + 2 >= s_len) || llvm::isSpace(s[pos + 2])) {
           return pos;
         }
       }

diff  --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 070220e0a574..bfacd41dc1a3 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -763,7 +763,7 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
         if (m_bytes[0] == '$' && total_length > 4) {
           for (size_t i = 0; !binary && i < total_length; ++i) {
             unsigned char c = m_bytes[i];
-            if (isprint(c) == 0 && isspace(c) == 0) {
+            if (!llvm::isPrint(c) && !llvm::isSpace(c)) {
               binary = true;
             }
           }

diff  --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 47aa150152ac..c75d5e106cd0 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -841,7 +841,7 @@ int GDBRemoteCommunicationClient::SendEnvironmentPacket(
     bool send_hex_encoding = false;
     for (const char *p = name_equal_value; *p != '\0' && !send_hex_encoding;
          ++p) {
-      if (isprint(*p)) {
+      if (llvm::isPrint(*p)) {
         switch (*p) {
         case '$':
         case '#':

diff  --git a/lldb/source/Utility/Args.cpp b/lldb/source/Utility/Args.cpp
index 27dcbb822910..27e1811bf5b0 100644
--- a/lldb/source/Utility/Args.cpp
+++ b/lldb/source/Utility/Args.cpp
@@ -546,7 +546,7 @@ void Args::ExpandEscapedCharacters(const char *src, std::string &dst) {
   dst.clear();
   if (src) {
     for (const char *p = src; *p != '\0'; ++p) {
-      if (isprint(*p))
+      if (llvm::isPrint(*p))
         dst.append(1, *p);
       else {
         switch (*p) {

diff  --git a/lldb/source/Utility/DataExtractor.cpp b/lldb/source/Utility/DataExtractor.cpp
index 365ee58bb95b..ac3662a8e3c8 100644
--- a/lldb/source/Utility/DataExtractor.cpp
+++ b/lldb/source/Utility/DataExtractor.cpp
@@ -964,7 +964,7 @@ lldb::offset_t DataExtractor::PutToLog(Log *log, offset_t start_offset,
       break;
     case TypeChar: {
       char ch = GetU8(&offset);
-      sstr.Printf(" %c", isprint(ch) ? ch : ' ');
+      sstr.Printf(" %c", llvm::isPrint(ch) ? ch : ' ');
     } break;
     case TypeUInt16:
       sstr.Printf(" %4.4x", GetU16(&offset));

diff  --git a/lldb/source/Utility/Event.cpp b/lldb/source/Utility/Event.cpp
index 4ae832872e0e..50cc7f061dc6 100644
--- a/lldb/source/Utility/Event.cpp
+++ b/lldb/source/Utility/Event.cpp
@@ -125,7 +125,7 @@ ConstString EventDataBytes::GetFlavor() const {
 
 void EventDataBytes::Dump(Stream *s) const {
   size_t num_printable_chars =
-      std::count_if(m_bytes.begin(), m_bytes.end(), isprint);
+      std::count_if(m_bytes.begin(), m_bytes.end(), llvm::isPrint);
   if (num_printable_chars == m_bytes.size())
     s->Format("\"{0}\"", m_bytes);
   else

diff  --git a/lldb/source/Utility/StringExtractor.cpp b/lldb/source/Utility/StringExtractor.cpp
index bbcf67fcab0d..0553a63a021e 100644
--- a/lldb/source/Utility/StringExtractor.cpp
+++ b/lldb/source/Utility/StringExtractor.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Utility/StringExtractor.h"
+#include "llvm/ADT/StringExtras.h"
 
 #include <tuple>
 
@@ -365,6 +366,6 @@ bool StringExtractor::GetNameColonValue(llvm::StringRef &name,
 
 void StringExtractor::SkipSpaces() {
   const size_t n = m_packet.size();
-  while (m_index < n && isspace(m_packet[m_index]))
+  while (m_index < n && llvm::isSpace(m_packet[m_index]))
     ++m_index;
 }


        


More information about the lldb-commits mailing list