Skip to content

[lldb] Fix thread backtrace --count #83602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions lldb/source/Commands/CommandObjectThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,27 @@ class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads {
if (option_arg.getAsInteger(0, m_count)) {
m_count = UINT32_MAX;
error.SetErrorStringWithFormat(
"invalid integer value for option '%c'", short_option);
"invalid integer value for option '%c': %s", short_option,
option_arg.data());
}
// A count of 0 means all frames.
if (m_count == 0)
m_count = UINT32_MAX;
break;
case 's':
if (option_arg.getAsInteger(0, m_start))
error.SetErrorStringWithFormat(
"invalid integer value for option '%c'", short_option);
"invalid integer value for option '%c': %s", short_option,
option_arg.data());
break;
case 'e': {
bool success;
m_extended_backtrace =
OptionArgParser::ToBoolean(option_arg, false, &success);
if (!success)
error.SetErrorStringWithFormat(
"invalid boolean value for option '%c'", short_option);
"invalid boolean value for option '%c': %s", short_option,
option_arg.data());
} break;
default:
llvm_unreachable("Unimplemented option");
Expand Down Expand Up @@ -228,9 +234,9 @@ class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads {
thread->GetIndexID());
return false;
}
if (m_options.m_extended_backtrace) {
if (!INTERRUPT_REQUESTED(GetDebugger(),
"Interrupt skipped extended backtrace")) {
if (m_options.m_extended_backtrace) {
if (!INTERRUPT_REQUESTED(GetDebugger(),
"Interrupt skipped extended backtrace")) {
DoExtendedBacktrace(thread, result);
}
}
Expand Down Expand Up @@ -272,8 +278,9 @@ class ThreadStepScopeOptionGroup : public OptionGroup {
bool avoid_no_debug =
OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error.SetErrorStringWithFormat("invalid boolean value for option '%c'",
short_option);
error.SetErrorStringWithFormat(
"invalid boolean value for option '%c': %s", short_option,
option_arg);
else {
m_step_in_avoid_no_debug = avoid_no_debug ? eLazyBoolYes : eLazyBoolNo;
}
Expand All @@ -284,17 +291,19 @@ class ThreadStepScopeOptionGroup : public OptionGroup {
bool avoid_no_debug =
OptionArgParser::ToBoolean(option_arg, true, &success);
if (!success)
error.SetErrorStringWithFormat("invalid boolean value for option '%c'",
short_option);
error.SetErrorStringWithFormat(
"invalid boolean value for option '%c': %s", short_option,
option_arg);
else {
m_step_out_avoid_no_debug = avoid_no_debug ? eLazyBoolYes : eLazyBoolNo;
}
} break;

case 'c':
if (option_arg.getAsInteger(0, m_step_count))
error.SetErrorStringWithFormat("invalid step count '%s'",
option_arg.str().c_str());
error.SetErrorStringWithFormat(
"invalid integer value for option '%c': %s", short_option,
option_arg.data());
break;

case 'm': {
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Commands/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ let Command = "script add" in {
def script_add_function : Option<"function", "f">, Group<1>,
Arg<"PythonFunction">,
Desc<"Name of the Python function to bind to this command name.">;
def script_add_class : Option<"class", "c">, Groups<[2,3]>,
def script_add_class : Option<"class", "c">, Groups<[2,3]>,
Arg<"PythonClass">,
Desc<"Name of the Python class to bind to this command name.">;
def script_add_help : Option<"help", "h">, Group<1>, Arg<"HelpText">,
Expand All @@ -816,7 +816,7 @@ let Command = "script add" in {
EnumArg<"ScriptedCommandSynchronicity">,
Desc<"Set the synchronicity of this command's executions with regard to "
"LLDB event system.">;
def script_add_completion_type : Option<"completion-type", "C">,
def script_add_completion_type : Option<"completion-type", "C">,
Groups<[1,2]>, EnumArg<"CompletionType">,
Desc<"Specify which completion type the command should use - if none is "
"specified, the command won't use auto-completion.">;
Expand Down Expand Up @@ -1037,7 +1037,7 @@ let Command = "target stop hook add" in {

let Command = "thread backtrace" in {
def thread_backtrace_count : Option<"count", "c">, Group<1>, Arg<"Count">,
Desc<"How many frames to display (-1 for all)">;
Desc<"How many frames to display (0 for all)">;
def thread_backtrace_start : Option<"start", "s">, Group<1>,
Arg<"FrameIndex">, Desc<"Frame in which to start the backtrace">;
def thread_backtrace_extended : Option<"extended", "e">, Group<1>,
Expand Down
14 changes: 14 additions & 0 deletions lldb/test/Shell/Commands/command-thread-backtrace.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# RUN: %clang_host -g %S/Inputs/main.c -o %t

# RUN: not %lldb %t -b -o 'b foo' -o 'r' -o 'thread backtrace --count -1' 2>&1 | FileCheck %s --check-prefix COUNT
# COUNT: error: invalid integer value for option 'c': -1

# RUN: not %lldb %t -b -o 'b foo' -o 'r' -o 'thread backtrace --extended nah' 2>&1 | FileCheck %s --check-prefix EXTENDED
# EXTENDED: error: invalid boolean value for option 'e': nah

# RUN: not %lldb %t -b -o 'b foo' -o 'r' -o 'thread backtrace --start -1' 2>&1 | FileCheck %s --check-prefix START
# START: error: invalid integer value for option 's': -1

# RUN: %lldb %t -b -o 'b foo' -o 'r' -o 'thread backtrace --count 0' | FileCheck %s
# CHECK: frame #0:
# CHECK: frame #1: