Skip to content

Commit

Permalink
[lldb] Move StringConvert inside debugserver
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mgorny committed Sep 27, 2021
1 parent b1695c2 commit 9da2fa2
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 56 deletions.
1 change: 0 additions & 1 deletion lldb/include/lldb/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -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 * }
Expand Down
1 change: 0 additions & 1 deletion lldb/source/Host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lldb/tools/debugserver/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lldb/tools/debugserver/source/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -91,5 +58,5 @@ double ToDouble(const char *s, double fail_value, bool *success_ptr) {
*success_ptr = false;
return fail_value;
}
}
}

} // namespace StringConvert
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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

0 comments on commit 9da2fa2

Please sign in to comment.