Author: Michał Górny
Date: 2021-09-27T14:32:42+02:00
New Revision: 9da2fa277e818e94e45b836a3d416623c838e02a

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

LOG: [lldb] Move StringConvert inside debugserver

The StringConvert API is no longer used anywhere but in debugserver.
Since debugserver does not use LLVM API, we cannot replace it with
llvm::to_integer() and llvm::to_float() there.  Let's just move
the sources into debugserver.

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

Added: 
    lldb/tools/debugserver/source/StringConvert.cpp
    lldb/tools/debugserver/source/StringConvert.h

Modified: 
    lldb/include/lldb/module.modulemap
    lldb/source/Host/CMakeLists.txt
    lldb/tools/debugserver/source/CMakeLists.txt
    lldb/tools/debugserver/source/JSON.cpp

Removed: 
    lldb/include/lldb/Host/StringConvert.h
    lldb/source/Host/common/StringConvert.cpp


################################################################################
diff  --git a/lldb/include/lldb/module.modulemap 
b/lldb/include/lldb/module.modulemap
index 1ddaa1fb737d..c0d467a6505e 100644
--- a/lldb/include/lldb/module.modulemap
+++ b/lldb/include/lldb/module.modulemap
@@ -48,7 +48,6 @@ module lldb_Host {
   module SafeMachO { header "Host/SafeMachO.h" export * }
   module SocketAddress { header "Host/SocketAddress.h" export * }
   module Socket { header "Host/Socket.h" export * }
-  module StringConvert { textual header "Host/StringConvert.h" export * }
   module Terminal { header "Host/Terminal.h" export * }
   module ThreadLauncher { header "Host/ThreadLauncher.h" export * }
   module Time { header "Host/Time.h" export * }

diff  --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index c18e8ce004b0..4374abca0506 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -37,7 +37,6 @@ add_host_subdirectory(common
   common/PseudoTerminal.cpp
   common/SocketAddress.cpp
   common/Socket.cpp
-  common/StringConvert.cpp
   common/TCPSocket.cpp
   common/Terminal.cpp
   common/ThreadLauncher.cpp

diff  --git a/lldb/tools/debugserver/source/CMakeLists.txt 
b/lldb/tools/debugserver/source/CMakeLists.txt
index 98c79d9f7349..588df7f65355 100644
--- a/lldb/tools/debugserver/source/CMakeLists.txt
+++ b/lldb/tools/debugserver/source/CMakeLists.txt
@@ -206,8 +206,8 @@ set(lldbDebugserverCommonSources
   DNBThreadResumeActions.cpp
   JSON.cpp
   StdStringExtractor.cpp
+  StringConvert.cpp
   # JSON reader depends on the following LLDB-common files
-  ${LLDB_SOURCE_DIR}/source/Host/common/StringConvert.cpp
   ${LLDB_SOURCE_DIR}/source/Host/common/SocketAddress.cpp
   # end JSON reader dependencies
   libdebugserver.cpp

diff  --git a/lldb/tools/debugserver/source/JSON.cpp 
b/lldb/tools/debugserver/source/JSON.cpp
index 5eff683a080b..315c52aafc93 100644
--- a/lldb/tools/debugserver/source/JSON.cpp
+++ b/lldb/tools/debugserver/source/JSON.cpp
@@ -13,12 +13,10 @@
 #include <climits>
 
 // C++ includes
-#include "lldb/Host/StringConvert.h"
+#include "StringConvert.h"
 #include <iomanip>
 #include <sstream>
 
-using namespace lldb_private;
-
 std::string JSONString::json_string_quote_metachars(const std::string &s) {
   if (s.find('"') == std::string::npos)
     return s;

diff  --git a/lldb/source/Host/common/StringConvert.cpp 
b/lldb/tools/debugserver/source/StringConvert.cpp
similarity index 62%
rename from lldb/source/Host/common/StringConvert.cpp
rename to lldb/tools/debugserver/source/StringConvert.cpp
index b4eb92755367..fac7525c1980 100644
--- a/lldb/source/Host/common/StringConvert.cpp
+++ b/lldb/tools/debugserver/source/StringConvert.cpp
@@ -8,43 +8,10 @@
 
 #include <cstdlib>
 
-#include "lldb/Host/StringConvert.h"
+#include "StringConvert.h"
 
-namespace lldb_private {
 namespace StringConvert {
 
-int32_t ToSInt32(const char *s, int32_t fail_value, int base,
-                 bool *success_ptr) {
-  if (s && s[0]) {
-    char *end = nullptr;
-    const long sval = ::strtol(s, &end, base);
-    if (*end == '\0') {
-      if (success_ptr)
-        *success_ptr = ((sval <= INT32_MAX) && (sval >= INT32_MIN));
-      return (int32_t)sval; // All characters were used, return the result
-    }
-  }
-  if (success_ptr)
-    *success_ptr = false;
-  return fail_value;
-}
-
-uint32_t ToUInt32(const char *s, uint32_t fail_value, int base,
-                  bool *success_ptr) {
-  if (s && s[0]) {
-    char *end = nullptr;
-    const unsigned long uval = ::strtoul(s, &end, base);
-    if (*end == '\0') {
-      if (success_ptr)
-        *success_ptr = (uval <= UINT32_MAX);
-      return (uint32_t)uval; // All characters were used, return the result
-    }
-  }
-  if (success_ptr)
-    *success_ptr = false;
-  return fail_value;
-}
-
 int64_t ToSInt64(const char *s, int64_t fail_value, int base,
                  bool *success_ptr) {
   if (s && s[0]) {
@@ -91,5 +58,5 @@ double ToDouble(const char *s, double fail_value, bool 
*success_ptr) {
     *success_ptr = false;
   return fail_value;
 }
-}
-}
+
+} // namespace StringConvert

diff  --git a/lldb/include/lldb/Host/StringConvert.h 
b/lldb/tools/debugserver/source/StringConvert.h
similarity index 61%
rename from lldb/include/lldb/Host/StringConvert.h
rename to lldb/tools/debugserver/source/StringConvert.h
index 33608a85ff42..524a0ca40513 100644
--- a/lldb/include/lldb/Host/StringConvert.h
+++ b/lldb/tools/debugserver/source/StringConvert.h
@@ -6,24 +6,13 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#ifndef LLDB_HOST_STRINGCONVERT_H
-#define LLDB_HOST_STRINGCONVERT_H
+#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_STRINGCONVERT_H
+#define LLDB_TOOLS_DEBUGSERVER_SOURCE_STRINGCONVERT_H
 
 #include <cstdint>
 
-namespace lldb_private {
-
 namespace StringConvert {
 
-/// \namespace StringConvert StringConvert.h "lldb/Host/StringConvert.h"
-/// Utility classes for converting strings into Integers
-
-int32_t ToSInt32(const char *s, int32_t fail_value = 0, int base = 0,
-                 bool *success_ptr = nullptr);
-
-uint32_t ToUInt32(const char *s, uint32_t fail_value = 0, int base = 0,
-                  bool *success_ptr = nullptr);
-
 int64_t ToSInt64(const char *s, int64_t fail_value = 0, int base = 0,
                  bool *success_ptr = nullptr);
 
@@ -32,7 +21,7 @@ uint64_t ToUInt64(const char *s, uint64_t fail_value = 0, int 
base = 0,
 
 double ToDouble(const char *s, double fail_value = 0.0,
                 bool *success_ptr = nullptr);
+
 } // namespace StringConvert
-} // namespace lldb_private
 
 #endif


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

Reply via email to