aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Commands/CommandObjectBreakpoint.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2024-07-27 23:34:35 +0000
committerDimitry Andric <dim@FreeBSD.org>2024-10-23 18:26:01 +0000
commit0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583 (patch)
tree6cf5ab1f05330c6773b1f3f64799d56a9c7a1faa /contrib/llvm-project/lldb/source/Commands/CommandObjectBreakpoint.cpp
parent6b9f7133aba44189d9625c352bc2c2a59baf18ef (diff)
parentac9a064cb179f3425b310fa2847f8764ac970a4d (diff)
Diffstat (limited to 'contrib/llvm-project/lldb/source/Commands/CommandObjectBreakpoint.cpp')
-rw-r--r--contrib/llvm-project/lldb/source/Commands/CommandObjectBreakpoint.cpp229
1 files changed, 92 insertions, 137 deletions
diff --git a/contrib/llvm-project/lldb/source/Commands/CommandObjectBreakpoint.cpp b/contrib/llvm-project/lldb/source/Commands/CommandObjectBreakpoint.cpp
index 1661d5d9b743..773f8ed2fa8a 100644
--- a/contrib/llvm-project/lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ b/contrib/llvm-project/lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -64,6 +64,8 @@ public:
Status error;
const int short_option =
g_breakpoint_modify_options[option_idx].short_option;
+ const char *long_option =
+ g_breakpoint_modify_options[option_idx].long_option;
switch (short_option) {
case 'c':
@@ -84,18 +86,17 @@ public:
case 'G': {
bool value, success;
value = OptionArgParser::ToBoolean(option_arg, false, &success);
- if (success) {
+ if (success)
m_bp_opts.SetAutoContinue(value);
- } else
- error.SetErrorStringWithFormat(
- "invalid boolean value '%s' passed for -G option",
- option_arg.str().c_str());
+ else
+ error = CreateOptionParsingError(option_arg, short_option, long_option,
+ g_bool_parsing_error_message);
} break;
case 'i': {
uint32_t ignore_count;
if (option_arg.getAsInteger(0, ignore_count))
- error.SetErrorStringWithFormat("invalid ignore count '%s'",
- option_arg.str().c_str());
+ error = CreateOptionParsingError(option_arg, short_option, long_option,
+ g_int_parsing_error_message);
else
m_bp_opts.SetIgnoreCount(ignore_count);
} break;
@@ -105,27 +106,29 @@ public:
if (success) {
m_bp_opts.SetOneShot(value);
} else
- error.SetErrorStringWithFormat(
- "invalid boolean value '%s' passed for -o option",
- option_arg.str().c_str());
+ error = CreateOptionParsingError(option_arg, short_option, long_option,
+ g_bool_parsing_error_message);
} break;
case 't': {
lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID;
if (option_arg == "current") {
if (!execution_context) {
- error.SetErrorStringWithFormat("No context to determine current "
- "thread");
+ error = CreateOptionParsingError(
+ option_arg, short_option, long_option,
+ "No context to determine current thread");
} else {
ThreadSP ctx_thread_sp = execution_context->GetThreadSP();
if (!ctx_thread_sp || !ctx_thread_sp->IsValid()) {
- error.SetErrorStringWithFormat("No currently selected thread");
+ error =
+ CreateOptionParsingError(option_arg, short_option, long_option,
+ "No currently selected thread");
} else {
thread_id = ctx_thread_sp->GetID();
}
}
} else if (option_arg.getAsInteger(0, thread_id)) {
- error.SetErrorStringWithFormat("invalid thread id string '%s'",
- option_arg.str().c_str());
+ error = CreateOptionParsingError(option_arg, short_option, long_option,
+ g_int_parsing_error_message);
}
if (thread_id != LLDB_INVALID_THREAD_ID)
m_bp_opts.SetThreadID(thread_id);
@@ -139,8 +142,8 @@ public:
case 'x': {
uint32_t thread_index = UINT32_MAX;
if (option_arg.getAsInteger(0, thread_index)) {
- error.SetErrorStringWithFormat("invalid thread index string '%s'",
- option_arg.str().c_str());
+ error = CreateOptionParsingError(option_arg, short_option, long_option,
+ g_int_parsing_error_message);
} else {
m_bp_opts.GetThreadSpec()->SetIndex(thread_index);
}
@@ -263,6 +266,8 @@ public:
Status error;
const int short_option =
g_breakpoint_set_options[option_idx].short_option;
+ const char *long_option =
+ g_breakpoint_set_options[option_idx].long_option;
switch (short_option) {
case 'a': {
@@ -281,13 +286,15 @@ public:
case 'u':
if (option_arg.getAsInteger(0, m_column))
- error.SetErrorStringWithFormat("invalid column number: %s",
- option_arg.str().c_str());
+ error =
+ CreateOptionParsingError(option_arg, short_option, long_option,
+ g_int_parsing_error_message);
break;
case 'E': {
LanguageType language = Language::GetLanguageTypeFromString(option_arg);
+ llvm::StringRef error_context;
switch (language) {
case eLanguageTypeC89:
case eLanguageTypeC:
@@ -301,23 +308,26 @@ public:
case eLanguageTypeC_plus_plus_14:
m_exception_language = eLanguageTypeC_plus_plus;
break;
- case eLanguageTypeObjC:
- m_exception_language = eLanguageTypeObjC;
- break;
case eLanguageTypeObjC_plus_plus:
- error.SetErrorStringWithFormat(
- "Set exception breakpoints separately for c++ and objective-c");
+ error_context =
+ "Set exception breakpoints separately for c++ and objective-c";
break;
case eLanguageTypeUnknown:
- error.SetErrorStringWithFormat(
- "Unknown language type: '%s' for exception breakpoint",
- option_arg.str().c_str());
+ error_context = "Unknown language type for exception breakpoint";
break;
default:
- error.SetErrorStringWithFormat(
- "Unsupported language type: '%s' for exception breakpoint",
- option_arg.str().c_str());
+ if (Language *languagePlugin = Language::FindPlugin(language)) {
+ if (languagePlugin->SupportsExceptionBreakpointsOnThrow() ||
+ languagePlugin->SupportsExceptionBreakpointsOnCatch()) {
+ m_exception_language = language;
+ break;
+ }
+ }
+ error_context = "Unsupported language type for exception breakpoint";
}
+ if (!error_context.empty())
+ error = CreateOptionParsingError(option_arg, short_option,
+ long_option, error_context);
} break;
case 'f':
@@ -333,9 +343,9 @@ public:
bool success;
m_catch_bp = OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
- error.SetErrorStringWithFormat(
- "Invalid boolean value for on-catch option: '%s'",
- option_arg.str().c_str());
+ error =
+ CreateOptionParsingError(option_arg, short_option, long_option,
+ g_bool_parsing_error_message);
} break;
case 'H':
@@ -352,23 +362,24 @@ public:
m_skip_prologue = eLazyBoolNo;
if (!success)
- error.SetErrorStringWithFormat(
- "Invalid boolean value for skip prologue option: '%s'",
- option_arg.str().c_str());
+ error =
+ CreateOptionParsingError(option_arg, short_option, long_option,
+ g_bool_parsing_error_message);
} break;
case 'l':
if (option_arg.getAsInteger(0, m_line_num))
- error.SetErrorStringWithFormat("invalid line number: %s.",
- option_arg.str().c_str());
+ error =
+ CreateOptionParsingError(option_arg, short_option, long_option,
+ g_int_parsing_error_message);
break;
case 'L':
m_language = Language::GetLanguageTypeFromString(option_arg);
if (m_language == eLanguageTypeUnknown)
- error.SetErrorStringWithFormat(
- "Unknown language type: '%s' for breakpoint",
- option_arg.str().c_str());
+ error =
+ CreateOptionParsingError(option_arg, short_option, long_option,
+ g_language_parsing_error_message);
break;
case 'm': {
@@ -381,9 +392,9 @@ public:
m_move_to_nearest_code = eLazyBoolNo;
if (!success)
- error.SetErrorStringWithFormat(
- "Invalid boolean value for move-to-nearest-code option: '%s'",
- option_arg.str().c_str());
+ error =
+ CreateOptionParsingError(option_arg, short_option, long_option,
+ g_bool_parsing_error_message);
break;
}
@@ -401,8 +412,8 @@ public:
if (BreakpointID::StringIsBreakpointName(option_arg, error))
m_breakpoint_names.push_back(std::string(option_arg));
else
- error.SetErrorStringWithFormat("Invalid breakpoint name: %s",
- option_arg.str().c_str());
+ error = CreateOptionParsingError(
+ option_arg, short_option, long_option, "Invalid breakpoint name");
break;
}
@@ -440,9 +451,9 @@ public:
bool success;
m_throw_bp = OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
- error.SetErrorStringWithFormat(
- "Invalid boolean value for on-throw option: '%s'",
- option_arg.str().c_str());
+ error =
+ CreateOptionParsingError(option_arg, short_option, long_option,
+ g_bool_parsing_error_message);
} break;
case 'X':
@@ -454,9 +465,8 @@ public:
OptionValueFileColonLine value;
Status fcl_err = value.SetValueFromString(option_arg);
if (!fcl_err.Success()) {
- error.SetErrorStringWithFormat(
- "Invalid value for file:line specifier: %s",
- fcl_err.AsCString());
+ error = CreateOptionParsingError(option_arg, short_option,
+ long_option, fcl_err.AsCString());
} else {
m_filenames.AppendIfUnique(value.GetFileSpec());
m_line_num = value.GetLineNumber();
@@ -774,8 +784,8 @@ private:
} else {
const SymbolContext &sc =
cur_frame->GetSymbolContext(eSymbolContextLineEntry);
- if (sc.line_entry.file) {
- file = sc.line_entry.file;
+ if (sc.line_entry.GetFile()) {
+ file = sc.line_entry.GetFile();
} else {
result.AppendError("Can't find the file for the selected frame to "
"use as the default file.");
@@ -807,12 +817,7 @@ public:
"With the exception of -e, -d and -i, passing an "
"empty argument clears the modification.",
nullptr) {
- CommandArgumentEntry arg;
- CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
- eArgTypeBreakpointIDRange);
- // Add the entry for the first argument for this command to the object's
- // arguments vector.
- m_arguments.push_back(arg);
+ CommandObject::AddIDsArgumentData(eBreakpointArgs);
m_options.Append(&m_bp_opts,
LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3,
@@ -884,12 +889,7 @@ public:
"Enable the specified disabled breakpoint(s). If "
"no breakpoints are specified, enable all of them.",
nullptr) {
- CommandArgumentEntry arg;
- CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
- eArgTypeBreakpointIDRange);
- // Add the entry for the first argument for this command to the object's
- // arguments vector.
- m_arguments.push_back(arg);
+ CommandObject::AddIDsArgumentData(eBreakpointArgs);
}
~CommandObjectBreakpointEnable() override = default;
@@ -996,12 +996,7 @@ execution will NOT stop at location 1.1. To achieve that, type:
"The first command disables all locations for breakpoint 1, \
the second re-enables the first location.");
- CommandArgumentEntry arg;
- CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
- eArgTypeBreakpointIDRange);
- // Add the entry for the first argument for this command to the object's
- // arguments vector.
- m_arguments.push_back(arg);
+ CommandObject::AddIDsArgumentData(eBreakpointArgs);
}
~CommandObjectBreakpointDisable() override = default;
@@ -1092,15 +1087,7 @@ public:
CommandArgumentData bp_id_arg;
// Define the first (and only) variant of this arg.
- bp_id_arg.arg_type = eArgTypeBreakpointID;
- bp_id_arg.arg_repetition = eArgRepeatOptional;
-
- // There is only one variant this argument could be; put it into the
- // argument entry.
- arg.push_back(bp_id_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back(arg);
+ AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);
}
~CommandObjectBreakpointList() override = default;
@@ -1366,12 +1353,7 @@ public:
"Delete the specified breakpoint(s). If no "
"breakpoints are specified, delete them all.",
nullptr) {
- CommandArgumentEntry arg;
- CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
- eArgTypeBreakpointIDRange);
- // Add the entry for the first argument for this command to the object's
- // arguments vector.
- m_arguments.push_back(arg);
+ CommandObject::AddIDsArgumentData(eBreakpointArgs);
}
~CommandObjectBreakpointDelete() override = default;
@@ -1485,9 +1467,8 @@ protected:
for (auto breakpoint_sp : breakpoints.Breakpoints()) {
if (!breakpoint_sp->IsEnabled() && breakpoint_sp->AllowDelete()) {
BreakpointID bp_id(breakpoint_sp->GetID());
- size_t pos = 0;
- if (!excluded_bp_ids.FindBreakpointID(bp_id, &pos))
- valid_bp_ids.AddBreakpointID(breakpoint_sp->GetID());
+ if (!excluded_bp_ids.Contains(bp_id))
+ valid_bp_ids.AddBreakpointID(bp_id);
}
}
if (valid_bp_ids.GetSize() == 0) {
@@ -1555,6 +1536,7 @@ public:
ExecutionContext *execution_context) override {
Status error;
const int short_option = g_breakpoint_name_options[option_idx].short_option;
+ const char *long_option = g_breakpoint_name_options[option_idx].long_option;
switch (short_option) {
case 'N':
@@ -1564,15 +1546,13 @@ public:
break;
case 'B':
if (m_breakpoint.SetValueFromString(option_arg).Fail())
- error.SetErrorStringWithFormat(
- "unrecognized value \"%s\" for breakpoint",
- option_arg.str().c_str());
+ error = CreateOptionParsingError(option_arg, short_option, long_option,
+ g_int_parsing_error_message);
break;
case 'D':
if (m_use_dummy.SetValueFromString(option_arg).Fail())
- error.SetErrorStringWithFormat(
- "unrecognized value \"%s\" for use-dummy",
- option_arg.str().c_str());
+ error = CreateOptionParsingError(option_arg, short_option, long_option,
+ g_bool_parsing_error_message);
break;
case 'H':
m_help_string.SetValueFromString(option_arg);
@@ -1615,6 +1595,8 @@ public:
Status error;
const int short_option =
g_breakpoint_access_options[option_idx].short_option;
+ const char *long_option =
+ g_breakpoint_access_options[option_idx].long_option;
switch (short_option) {
case 'L': {
@@ -1623,9 +1605,8 @@ public:
if (success) {
m_permissions.SetAllowList(value);
} else
- error.SetErrorStringWithFormat(
- "invalid boolean value '%s' passed for -L option",
- option_arg.str().c_str());
+ error = CreateOptionParsingError(option_arg, short_option, long_option,
+ g_bool_parsing_error_message);
} break;
case 'A': {
bool value, success;
@@ -1633,9 +1614,8 @@ public:
if (success) {
m_permissions.SetAllowDisable(value);
} else
- error.SetErrorStringWithFormat(
- "invalid boolean value '%s' passed for -L option",
- option_arg.str().c_str());
+ error = CreateOptionParsingError(option_arg, short_option, long_option,
+ g_bool_parsing_error_message);
} break;
case 'D': {
bool value, success;
@@ -1643,9 +1623,8 @@ public:
if (success) {
m_permissions.SetAllowDelete(value);
} else
- error.SetErrorStringWithFormat(
- "invalid boolean value '%s' passed for -L option",
- option_arg.str().c_str());
+ error = CreateOptionParsingError(option_arg, short_option, long_option,
+ g_bool_parsing_error_message);
} break;
default:
llvm_unreachable("Unimplemented option");
@@ -1674,14 +1653,7 @@ public:
"on the name.",
"breakpoint name configure <command-options> "
"<breakpoint-name-list>") {
- // Create the first variant for the first (and only) argument for this
- // command.
- CommandArgumentEntry arg1;
- CommandArgumentData id_arg;
- id_arg.arg_type = eArgTypeBreakpointName;
- id_arg.arg_repetition = eArgRepeatOptional;
- arg1.push_back(id_arg);
- m_arguments.push_back(arg1);
+ AddSimpleArgumentList(eArgTypeBreakpointName, eArgRepeatOptional);
m_option_group.Append(&m_bp_opts, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
m_option_group.Append(&m_access_options, LLDB_OPT_SET_ALL,
@@ -1767,14 +1739,7 @@ public:
: CommandObjectParsed(
interpreter, "add", "Add a name to the breakpoints provided.",
"breakpoint name add <command-options> <breakpoint-id-list>") {
- // Create the first variant for the first (and only) argument for this
- // command.
- CommandArgumentEntry arg1;
- CommandArgumentData id_arg;
- id_arg.arg_type = eArgTypeBreakpointID;
- id_arg.arg_repetition = eArgRepeatOptional;
- arg1.push_back(id_arg);
- m_arguments.push_back(arg1);
+ AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);
m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
m_option_group.Finalize();
@@ -1848,14 +1813,7 @@ public:
interpreter, "delete",
"Delete a name from the breakpoints provided.",
"breakpoint name delete <command-options> <breakpoint-id-list>") {
- // Create the first variant for the first (and only) argument for this
- // command.
- CommandArgumentEntry arg1;
- CommandArgumentData id_arg;
- id_arg.arg_type = eArgTypeBreakpointID;
- id_arg.arg_repetition = eArgRepeatOptional;
- arg1.push_back(id_arg);
- m_arguments.push_back(arg1);
+ AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);
m_option_group.Append(&m_name_options, LLDB_OPT_SET_1, LLDB_OPT_SET_ALL);
m_option_group.Finalize();
@@ -2139,6 +2097,8 @@ public:
ExecutionContext *execution_context) override {
Status error;
const int short_option = m_getopt_table[option_idx].val;
+ const char *long_option =
+ m_getopt_table[option_idx].definition->long_option;
switch (short_option) {
case 'f':
@@ -2148,8 +2108,8 @@ public:
Status name_error;
if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(option_arg),
name_error)) {
- error.SetErrorStringWithFormat("Invalid breakpoint name: %s",
- name_error.AsCString());
+ error = CreateOptionParsingError(option_arg, short_option,
+ long_option, name_error.AsCString());
}
m_names.push_back(std::string(option_arg));
break;
@@ -2303,12 +2263,7 @@ public:
"be read in with \"breakpoint read\". "
"If given no arguments, writes all breakpoints.",
nullptr) {
- CommandArgumentEntry arg;
- CommandObject::AddIDsArgumentData(arg, eArgTypeBreakpointID,
- eArgTypeBreakpointIDRange);
- // Add the entry for the first argument for this command to the object's
- // arguments vector.
- m_arguments.push_back(arg);
+ CommandObject::AddIDsArgumentData(eBreakpointArgs);
}
~CommandObjectBreakpointWrite() override = default;