[Lldb-commits] [lldb] 9010cef - [lldb] Replace StringConvert with llvm::to_integer when parsing integer values in CommandObjects
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 1 08:20:01 PDT 2020
Author: Raphael Isemann
Date: 2020-07-01T17:19:31+02:00
New Revision: 9010cef2af0affdef774a721f6adb52a40041da5
URL: https://github.com/llvm/llvm-project/commit/9010cef2af0affdef774a721f6adb52a40041da5
DIFF: https://github.com/llvm/llvm-project/commit/9010cef2af0affdef774a721f6adb52a40041da5.diff
LOG: [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
Added:
lldb/test/API/commands/platform/file/close/TestPlatformFileClose.py
lldb/test/API/commands/platform/file/read/TestPlatformFileRead.py
lldb/test/API/commands/process/signal/Makefile
lldb/test/API/commands/process/signal/TestProcessSignal.py
lldb/test/API/commands/process/signal/main.cpp
lldb/test/API/commands/target/modules/search-paths/insert/Makefile
lldb/test/API/commands/target/modules/search-paths/insert/TestTargetModulesSearchpathsInsert.py
lldb/test/API/commands/target/modules/search-paths/insert/main.cpp
lldb/test/API/commands/target/select/TestTargetSelect.py
lldb/test/API/commands/target/stop-hook/delete/TestTargetStopHookDelete.py
lldb/test/API/commands/target/stop-hook/disable/TestTargetStopHookDisable.py
lldb/test/API/commands/target/stop-hook/enable/TestTargetStopHookEnable.py
lldb/test/API/commands/thread/select/Makefile
lldb/test/API/commands/thread/select/TestThreadSelect.py
lldb/test/API/commands/thread/select/main.cpp
Modified:
lldb/source/Commands/CommandObjectFrame.cpp
lldb/source/Commands/CommandObjectPlatform.cpp
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Commands/CommandObjectThread.cpp
lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp
index 5677b1612bee..6ebad9b5c488 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -12,7 +12,6 @@
#include "lldb/DataFormatters/ValueObjectPrinter.h"
#include "lldb/Host/Config.h"
#include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/OptionGroupFormat.h"
@@ -986,8 +985,13 @@ class CommandObjectFrameRecognizerDelete : public CommandObjectParsed {
return false;
}
- uint32_t recognizer_id =
- StringConvert::ToUInt32(command.GetArgumentAtIndex(0), 0, 0);
+ uint32_t recognizer_id;
+ if (!llvm::to_integer(command.GetArgumentAtIndex(0), recognizer_id)) {
+ result.AppendErrorWithFormat("'%s' is not a valid recognizer id.\n",
+ command.GetArgumentAtIndex(0));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
StackFrameRecognizerManager::RemoveRecognizerWithID(recognizer_id);
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -1067,6 +1071,15 @@ class CommandObjectFrameRecognizerInfo : public CommandObjectParsed {
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
+ const char *frame_index_str = command.GetArgumentAtIndex(0);
+ uint32_t frame_index;
+ if (!llvm::to_integer(frame_index_str, frame_index)) {
+ result.AppendErrorWithFormat("'%s' is not a valid frame index.",
+ frame_index_str);
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
Process *process = m_exe_ctx.GetProcessPtr();
if (process == nullptr) {
result.AppendError("no process");
@@ -1086,8 +1099,6 @@ class CommandObjectFrameRecognizerInfo : public CommandObjectParsed {
return false;
}
- uint32_t frame_index =
- StringConvert::ToUInt32(command.GetArgumentAtIndex(0), 0, 0);
StackFrameSP frame_sp = thread->GetStackFrameAtIndex(frame_index);
if (!frame_sp) {
result.AppendErrorWithFormat("no frame with index %u", frame_index);
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 1fa9c2c23570..fcc8af6f915c 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 @@ class CommandObjectPlatformFClose : public CommandObjectParsed {
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 @@ class CommandObjectPlatformFRead : public CommandObjectParsed {
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 @@ class CommandObjectPlatformFWrite : public CommandObjectParsed {
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);
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp
index aa90ad61225b..3659f0db832c 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -13,7 +13,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/CommandReturnObject.h"
#include "lldb/Interpreter/OptionArgParser.h"
@@ -1059,10 +1058,10 @@ class CommandObjectProcessSignal : public CommandObjectParsed {
int signo = LLDB_INVALID_SIGNAL_NUMBER;
const char *signal_name = command.GetArgumentAtIndex(0);
- if (::isxdigit(signal_name[0]))
- signo =
- StringConvert::ToSInt32(signal_name, LLDB_INVALID_SIGNAL_NUMBER, 0);
- else
+ if (::isxdigit(signal_name[0])) {
+ if (!llvm::to_integer(signal_name, signo))
+ signo = LLDB_INVALID_SIGNAL_NUMBER;
+ } else
signo = process->GetUnixSignals()->GetSignalNumberFromName(signal_name);
if (signo == LLDB_INVALID_SIGNAL_NUMBER) {
@@ -1410,7 +1409,8 @@ class CommandObjectProcessHandle : public CommandObjectParsed {
real_value = 0;
else {
// If the value isn't 'true' or 'false', it had better be 0 or 1.
- real_value = StringConvert::ToUInt32(option.c_str(), 3);
+ if (!llvm::to_integer(option, real_value))
+ real_value = 3;
if (real_value != 0 && real_value != 1)
okay = false;
}
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 56d8dc8d9c6d..7bb71f4d518c 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -16,7 +16,6 @@
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/DataFormatters/ValueObjectPrinter.h"
#include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/OptionArgParser.h"
@@ -506,11 +505,9 @@ class CommandObjectTargetSelect : public CommandObjectParsed {
protected:
bool DoExecute(Args &args, CommandReturnObject &result) override {
if (args.GetArgumentCount() == 1) {
- bool success = false;
const char *target_idx_arg = args.GetArgumentAtIndex(0);
- uint32_t target_idx =
- StringConvert::ToUInt32(target_idx_arg, UINT32_MAX, 0, &success);
- if (success) {
+ uint32_t target_idx;
+ if (llvm::to_integer(target_idx_arg, target_idx)) {
TargetList &target_list = GetDebugger().GetTargetList();
const uint32_t num_targets = target_list.GetNumTargets();
if (target_idx < num_targets) {
@@ -1176,12 +1173,9 @@ class CommandObjectTargetModulesSearchPathsInsert : public CommandObjectParsed {
size_t argc = command.GetArgumentCount();
// check for at least 3 arguments and an odd number of parameters
if (argc >= 3 && argc & 1) {
- bool success = false;
+ uint32_t insert_idx;
- uint32_t insert_idx = StringConvert::ToUInt32(
- command.GetArgumentAtIndex(0), UINT32_MAX, 0, &success);
-
- if (!success) {
+ if (!llvm::to_integer(command.GetArgumentAtIndex(0), insert_idx)) {
result.AppendErrorWithFormat(
"<index> parameter is not an integer: '%s'.\n",
command.GetArgumentAtIndex(0));
@@ -2748,10 +2742,8 @@ class CommandObjectTargetModulesLoad
const char *load_addr_cstr = args.GetArgumentAtIndex(i + 1);
if (sect_name && load_addr_cstr) {
ConstString const_sect_name(sect_name);
- bool success = false;
- addr_t load_addr = StringConvert::ToUInt64(
- load_addr_cstr, LLDB_INVALID_ADDRESS, 0, &success);
- if (success) {
+ addr_t load_addr;
+ if (llvm::to_integer(load_addr_cstr, load_addr)) {
SectionSP section_sp(
section_list->FindSectionByName(const_sect_name));
if (section_sp) {
@@ -4732,18 +4724,15 @@ class CommandObjectTargetStopHookDelete : public CommandObjectParsed {
target.RemoveAllStopHooks();
}
} else {
- bool success;
for (size_t i = 0; i < num_args; i++) {
- lldb::user_id_t user_id = StringConvert::ToUInt32(
- command.GetArgumentAtIndex(i), 0, 0, &success);
- if (!success) {
+ lldb::user_id_t user_id;
+ if (!llvm::to_integer(command.GetArgumentAtIndex(i), user_id)) {
result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
command.GetArgumentAtIndex(i));
result.SetStatus(eReturnStatusFailed);
return false;
}
- success = target.RemoveStopHookByID(user_id);
- if (!success) {
+ if (!target.RemoveStopHookByID(user_id)) {
result.AppendErrorWithFormat("unknown stop hook id: \"%s\".\n",
command.GetArgumentAtIndex(i));
result.SetStatus(eReturnStatusFailed);
@@ -4781,9 +4770,8 @@ class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed {
target.SetAllStopHooksActiveState(m_enable);
} else {
for (size_t i = 0; i < num_args; i++) {
- lldb::user_id_t user_id = StringConvert::ToUInt32(
- command.GetArgumentAtIndex(i), 0, 0, &success);
- if (!success) {
+ lldb::user_id_t user_id;
+ if (!llvm::to_integer(command.GetArgumentAtIndex(i), user_id)) {
result.AppendErrorWithFormat("invalid stop hook id: \"%s\".\n",
command.GetArgumentAtIndex(i));
result.SetStatus(eReturnStatusFailed);
diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp
index 8e599ed69880..f0ad1798fec6 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -10,7 +10,6 @@
#include "lldb/Core/ValueObject.h"
#include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/OptionArgParser.h"
@@ -109,11 +108,8 @@ class CommandObjectIterateOverThreads : public CommandObjectParsed {
process->GetThreadList().GetMutex());
for (size_t i = 0; i < num_args; i++) {
- bool success;
-
- uint32_t thread_idx = StringConvert::ToUInt32(
- command.GetArgumentAtIndex(i), 0, 0, &success);
- if (!success) {
+ uint32_t thread_idx;
+ if (!llvm::to_integer(command.GetArgumentAtIndex(i), thread_idx)) {
result.AppendErrorWithFormat("invalid thread specification: \"%s\"\n",
command.GetArgumentAtIndex(i));
result.SetStatus(eReturnStatusFailed);
@@ -565,9 +561,9 @@ class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
}
} else {
const char *thread_idx_cstr = command.GetArgumentAtIndex(0);
- uint32_t step_thread_idx =
- StringConvert::ToUInt32(thread_idx_cstr, LLDB_INVALID_INDEX32);
- if (step_thread_idx == LLDB_INVALID_INDEX32) {
+ uint32_t step_thread_idx;
+
+ if (!llvm::to_integer(thread_idx_cstr, step_thread_idx)) {
result.AppendErrorWithFormat("invalid thread index '%s'.\n",
thread_idx_cstr);
result.SetStatus(eReturnStatusFailed);
@@ -1095,9 +1091,7 @@ class CommandObjectThreadUntil : public CommandObjectParsed {
size_t num_args = command.GetArgumentCount();
for (size_t i = 0; i < num_args; i++) {
uint32_t line_number;
- line_number = StringConvert::ToUInt32(command.GetArgumentAtIndex(i),
- UINT32_MAX);
- if (line_number == UINT32_MAX) {
+ if (!llvm::to_integer(command.GetArgumentAtIndex(i), line_number)) {
result.AppendErrorWithFormat("invalid line number: '%s'.\n",
command.GetArgumentAtIndex(i));
result.SetStatus(eReturnStatusFailed);
@@ -1321,8 +1315,13 @@ class CommandObjectThreadSelect : public CommandObjectParsed {
return false;
}
- uint32_t index_id =
- StringConvert::ToUInt32(command.GetArgumentAtIndex(0), 0, 0);
+ uint32_t index_id;
+ if (!llvm::to_integer(command.GetArgumentAtIndex(0), index_id)) {
+ result.AppendErrorWithFormat("Invalid thread index '%s'",
+ command.GetArgumentAtIndex(0));
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
Thread *new_thread =
process->GetThreadList().FindThreadByIndexID(index_id).get();
@@ -1989,10 +1988,8 @@ class CommandObjectThreadPlanDiscard : public CommandObjectParsed {
return false;
}
- bool success;
- uint32_t thread_plan_idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), 0, 0, &success);
- if (!success) {
+ uint32_t thread_plan_idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), thread_plan_idx)) {
result.AppendErrorWithFormat(
"Invalid thread index: \"%s\" - should be unsigned int.",
args.GetArgumentAtIndex(0));
@@ -2066,11 +2063,8 @@ class CommandObjectThreadPlanPrune : public CommandObjectParsed {
process->GetThreadList().GetMutex());
for (size_t i = 0; i < num_args; i++) {
- bool success;
-
- lldb::tid_t tid = StringConvert::ToUInt64(
- args.GetArgumentAtIndex(i), 0, 0, &success);
- if (!success) {
+ lldb::tid_t tid;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(i), tid)) {
result.AppendErrorWithFormat("invalid thread specification: \"%s\"\n",
args.GetArgumentAtIndex(i));
result.SetStatus(eReturnStatusFailed);
diff --git a/lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py b/lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
index 04b940049496..218c7e85aae7 100644
--- a/lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
+++ b/lldb/test/API/commands/frame/recognizer/TestFrameRecognizer.py
@@ -144,3 +144,25 @@ def test_frame_recognizer_multi_symbol(self):
self.expect("frame recognizer info 0",
substrs=['frame 0 is recognized by recognizer.MyFrameRecognizer'])
+
+ @no_debug_info_test
+ def test_frame_recognizer_delete_invalid_arg(self):
+ self.expect("frame recognizer delete a", error=True,
+ substrs=["error: 'a' is not a valid recognizer id."])
+ self.expect("frame recognizer delete \"\"", error=True,
+ substrs=["error: '' is not a valid recognizer id."])
+ self.expect("frame recognizer delete -1", error=True,
+ substrs=["error: '-1' is not a valid recognizer id."])
+ self.expect("frame recognizer delete 4294967297", error=True,
+ substrs=["error: '4294967297' is not a valid recognizer id."])
+
+ @no_debug_info_test
+ def test_frame_recognizer_info_invalid_arg(self):
+ self.expect("frame recognizer info a", error=True,
+ substrs=["error: 'a' is not a valid frame index."])
+ self.expect("frame recognizer info \"\"", error=True,
+ substrs=["error: '' is not a valid frame index."])
+ self.expect("frame recognizer info -1", error=True,
+ substrs=["error: '-1' is not a valid frame index."])
+ self.expect("frame recognizer info 4294967297", error=True,
+ substrs=["error: '4294967297' is not a valid frame index."])
diff --git a/lldb/test/API/commands/platform/file/close/TestPlatformFileClose.py b/lldb/test/API/commands/platform/file/close/TestPlatformFileClose.py
new file mode 100644
index 000000000000..f440b674517e
--- /dev/null
+++ b/lldb/test/API/commands/platform/file/close/TestPlatformFileClose.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @no_debug_info_test
+ def test_file_close_invalid_arg(self):
+ self.expect("platform file close y", error=True,
+ substrs=["'y' is not a valid file descriptor."])
+ self.expect("platform file close -1", error=True,
+ substrs=["'-1' is not a valid file descriptor."])
diff --git a/lldb/test/API/commands/platform/file/read/TestPlatformFileRead.py b/lldb/test/API/commands/platform/file/read/TestPlatformFileRead.py
new file mode 100644
index 000000000000..a1f963a0e065
--- /dev/null
+++ b/lldb/test/API/commands/platform/file/read/TestPlatformFileRead.py
@@ -0,0 +1,16 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @no_debug_info_test
+ def test_file_close_invalid_arg(self):
+ self.expect("platform file read y", error=True,
+ substrs=["'y' is not a valid file descriptor."])
+ # 'file read' takes an option, so this will be treated as an option.
+ self.expect("platform file read -1", error=True,
+ substrs=["unknown or ambiguous option"])
diff --git a/lldb/test/API/commands/process/signal/Makefile b/lldb/test/API/commands/process/signal/Makefile
new file mode 100644
index 000000000000..99998b20bcb0
--- /dev/null
+++ b/lldb/test/API/commands/process/signal/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/commands/process/signal/TestProcessSignal.py b/lldb/test/API/commands/process/signal/TestProcessSignal.py
new file mode 100644
index 000000000000..389732385c5f
--- /dev/null
+++ b/lldb/test/API/commands/process/signal/TestProcessSignal.py
@@ -0,0 +1,17 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test.decorators import *
+
+class TestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @no_debug_info_test
+ def test_invalid_arg(self):
+ self.build()
+
+ lldbutil.run_to_source_breakpoint(self, '// break here', lldb.SBFileSpec("main.cpp"))
+ self.expect("process signal az", error=True, startstr="error: Invalid signal argument 'az'.")
+ self.expect("process signal 0x1ffffffff", error=True, startstr="error: Invalid signal argument '0x1ffffffff'.")
+ self.expect("process signal 0xffffffff", error=True, startstr="error: Invalid signal argument '0xffffffff'.")
diff --git a/lldb/test/API/commands/process/signal/main.cpp b/lldb/test/API/commands/process/signal/main.cpp
new file mode 100644
index 000000000000..ba45ee316cd4
--- /dev/null
+++ b/lldb/test/API/commands/process/signal/main.cpp
@@ -0,0 +1,3 @@
+int main() {
+ return 0; // break here
+}
diff --git a/lldb/test/API/commands/target/modules/search-paths/insert/Makefile b/lldb/test/API/commands/target/modules/search-paths/insert/Makefile
new file mode 100644
index 000000000000..99998b20bcb0
--- /dev/null
+++ b/lldb/test/API/commands/target/modules/search-paths/insert/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/commands/target/modules/search-paths/insert/TestTargetModulesSearchpathsInsert.py b/lldb/test/API/commands/target/modules/search-paths/insert/TestTargetModulesSearchpathsInsert.py
new file mode 100644
index 000000000000..169b32b97442
--- /dev/null
+++ b/lldb/test/API/commands/target/modules/search-paths/insert/TestTargetModulesSearchpathsInsert.py
@@ -0,0 +1,20 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+import lldbsuite.test.lldbutil as lldbutil
+
+class TestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @no_debug_info_test
+ def test_invalid_arg(self):
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+
+ self.expect("target create %s" % (exe))
+ self.expect("target modules search-paths insert -1 a b", error=True,
+ startstr="error: <index> parameter is not an integer: '-1'.")
+
+ self.expect("target modules search-paths insert abcdefx a b", error=True,
+ startstr="error: <index> parameter is not an integer: 'abcdefx'.")
diff --git a/lldb/test/API/commands/target/modules/search-paths/insert/main.cpp b/lldb/test/API/commands/target/modules/search-paths/insert/main.cpp
new file mode 100644
index 000000000000..76e8197013aa
--- /dev/null
+++ b/lldb/test/API/commands/target/modules/search-paths/insert/main.cpp
@@ -0,0 +1 @@
+int main() { return 0; }
diff --git a/lldb/test/API/commands/target/select/TestTargetSelect.py b/lldb/test/API/commands/target/select/TestTargetSelect.py
new file mode 100644
index 000000000000..e53745ee2163
--- /dev/null
+++ b/lldb/test/API/commands/target/select/TestTargetSelect.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @no_debug_info_test
+ def test_invalid_arg(self):
+ self.expect("target select -1", error=True,
+ startstr="error: invalid index string value '-1'")
+ self.expect("target select abcdfx", error=True,
+ startstr="error: invalid index string value 'abcdfx'")
diff --git a/lldb/test/API/commands/target/stop-hook/delete/TestTargetStopHookDelete.py b/lldb/test/API/commands/target/stop-hook/delete/TestTargetStopHookDelete.py
new file mode 100644
index 000000000000..35b718b93f61
--- /dev/null
+++ b/lldb/test/API/commands/target/stop-hook/delete/TestTargetStopHookDelete.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @no_debug_info_test
+ def test_invalid_arg(self):
+ self.expect("target stop-hook delete -1", error=True,
+ startstr="error: invalid stop hook id: \"-1\".")
+ self.expect("target stop-hook delete abcdfx", error=True,
+ startstr="error: invalid stop hook id: \"abcdfx\".")
diff --git a/lldb/test/API/commands/target/stop-hook/disable/TestTargetStopHookDisable.py b/lldb/test/API/commands/target/stop-hook/disable/TestTargetStopHookDisable.py
new file mode 100644
index 000000000000..5e665a87c344
--- /dev/null
+++ b/lldb/test/API/commands/target/stop-hook/disable/TestTargetStopHookDisable.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @no_debug_info_test
+ def test_invalid_arg(self):
+ self.expect("target stop-hook disable -1", error=True,
+ startstr="error: invalid stop hook id: \"-1\".")
+ self.expect("target stop-hook disable abcdfx", error=True,
+ startstr="error: invalid stop hook id: \"abcdfx\".")
diff --git a/lldb/test/API/commands/target/stop-hook/enable/TestTargetStopHookEnable.py b/lldb/test/API/commands/target/stop-hook/enable/TestTargetStopHookEnable.py
new file mode 100644
index 000000000000..5c1dcf4b2c00
--- /dev/null
+++ b/lldb/test/API/commands/target/stop-hook/enable/TestTargetStopHookEnable.py
@@ -0,0 +1,15 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @no_debug_info_test
+ def test_invalid_arg(self):
+ self.expect("target stop-hook enable -1", error=True,
+ startstr="error: invalid stop hook id: \"-1\".")
+ self.expect("target stop-hook enable abcdfx", error=True,
+ startstr="error: invalid stop hook id: \"abcdfx\".")
diff --git a/lldb/test/API/commands/thread/select/Makefile b/lldb/test/API/commands/thread/select/Makefile
new file mode 100644
index 000000000000..99998b20bcb0
--- /dev/null
+++ b/lldb/test/API/commands/thread/select/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/commands/thread/select/TestThreadSelect.py b/lldb/test/API/commands/thread/select/TestThreadSelect.py
new file mode 100644
index 000000000000..4650fae518dd
--- /dev/null
+++ b/lldb/test/API/commands/thread/select/TestThreadSelect.py
@@ -0,0 +1,18 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test.decorators import *
+
+class TestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def test_invalid_arg(self):
+ self.build()
+
+ lldbutil.run_to_source_breakpoint(self, '// break here', lldb.SBFileSpec("main.cpp"))
+
+ self.expect("thread select -1", error=True, startstr="error: Invalid thread index '-1'")
+ self.expect("thread select 0x1ffffffff", error=True, startstr="error: Invalid thread index '0x1ffffffff'")
+ # Parses but not a valid thread id.
+ self.expect("thread select 0xffffffff", error=True, startstr="error: invalid thread #0xffffffff.")
diff --git a/lldb/test/API/commands/thread/select/main.cpp b/lldb/test/API/commands/thread/select/main.cpp
new file mode 100644
index 000000000000..ba45ee316cd4
--- /dev/null
+++ b/lldb/test/API/commands/thread/select/main.cpp
@@ -0,0 +1,3 @@
+int main() {
+ return 0; // break here
+}
More information about the lldb-commits
mailing list