aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectPlatform.cpp
diff options
context:
space:
mode:
authorRaphael Isemann <teemperor@gmail.com>2020-07-01 17:00:12 +0200
committerRaphael Isemann <teemperor@gmail.com>2020-07-01 17:19:31 +0200
commit9010cef2af0affdef774a721f6adb52a40041da5 (patch)
tree422ca0deeed452b262b6ac85e0d4004505a2c4a0 /lldb/source/Commands/CommandObjectPlatform.cpp
parenta61fa1a4b9d247e34ea5541422f7040a37baf6e7 (diff)
downloadllvm-9010cef2af0affdef774a721f6adb52a40041da5.zip
llvm-9010cef2af0affdef774a721f6adb52a40041da5.tar.gz
llvm-9010cef2af0affdef774a721f6adb52a40041da5.tar.bz2
[lldb] Replace StringConvert with llvm::to_integer when parsing integer values in CommandObjects
Summary: This replaces the current use of LLDB's own `StringConvert` with LLVM's `to_integer` which has a less error-prone API and doesn't use special 'error values' to designate parsing problems. Where needed I also added missing error handling code that prints a parsing error instead of continuing with the error value returned from `StringConvert` (which either gave a cryptic error message or just took the error value performed an incorrect action with it. For example, `frame recognizer delete -1` just deleted the frame recognizer at index 0). Reviewers: #lldb, labath Reviewed By: labath Subscribers: labath, abidh, JDevlieghere Differential Revision: https://reviews.llvm.org/D82297
Diffstat (limited to 'lldb/source/Commands/CommandObjectPlatform.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 1fa9c2c2..fcc8af6 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -11,7 +11,6 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandOptionValidators.h"
#include "lldb/Interpreter/CommandReturnObject.h"
@@ -546,8 +545,13 @@ public:
if (platform_sp) {
std::string cmd_line;
args.GetCommandString(cmd_line);
- const lldb::user_id_t fd =
- StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
+ lldb::user_id_t fd;
+ if (!llvm::to_integer(cmd_line, fd)) {
+ result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.\n",
+ cmd_line);
+ result.SetStatus(eReturnStatusFailed);
+ return result.Succeeded();
+ }
Status error;
bool success = platform_sp->CloseFile(fd, error);
if (success) {
@@ -586,8 +590,13 @@ public:
if (platform_sp) {
std::string cmd_line;
args.GetCommandString(cmd_line);
- const lldb::user_id_t fd =
- StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
+ lldb::user_id_t fd;
+ if (!llvm::to_integer(cmd_line, fd)) {
+ result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.\n",
+ cmd_line);
+ result.SetStatus(eReturnStatusFailed);
+ return result.Succeeded();
+ }
std::string buffer(m_options.m_count, 0);
Status error;
uint32_t retcode = platform_sp->ReadFile(
@@ -674,8 +683,13 @@ public:
std::string cmd_line;
args.GetCommandString(cmd_line);
Status error;
- const lldb::user_id_t fd =
- StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
+ lldb::user_id_t fd;
+ if (!llvm::to_integer(cmd_line, fd)) {
+ result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.",
+ cmd_line);
+ result.SetStatus(eReturnStatusFailed);
+ return result.Succeeded();
+ }
uint32_t retcode =
platform_sp->WriteFile(fd, m_options.m_offset, &m_options.m_data[0],
m_options.m_data.size(), error);