From af009451ec439593554f03bc714e46ad2cd41738 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 1 Mar 2024 11:06:58 -0800 Subject: [lldb] Fix `thread backtrace --count` (#83602) The help output for `thread backtrace` specifies that you can pass -1 to `--count` to display all the frames. ``` -c ( --count ) How many frames to display (-1 for all) ``` However, that doesn't work: ``` (lldb) thread backtrace --count -1 error: invalid integer value for option 'c' ``` The problem is that we store the option value as an unsigned and the code to parse the string correctly rejects it. There's two ways to fix this: 1. Make `m_count` a signed value so that it accepts negative values and appease the parser. The function that prints the frames takes an unsigned so a negative value will just become a really large positive value, which is what the current implementation relies on. 2. Keep `m_count` unsigned and instead use 0 the magic value to show all frames. I don't really see a point in not showing any frames at all, plus that's already broken (`error: error displaying backtrace for thread: "0x0001"`). This patch implements (2) and at the same time improve the error reporting so that we print the invalid value when we cannot parse it. rdar://123881767 --- lldb/source/Commands/CommandObjectThread.cpp | 33 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'lldb/source/Commands/CommandObjectThread.cpp') diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp index 9cfff059d6bf..6d84315a471d 100644 --- a/lldb/source/Commands/CommandObjectThread.cpp +++ b/lldb/source/Commands/CommandObjectThread.cpp @@ -67,13 +67,18 @@ public: 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; @@ -81,7 +86,8 @@ public: 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"); @@ -228,9 +234,9 @@ protected: 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); } } @@ -272,8 +278,9 @@ public: 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; } @@ -284,8 +291,9 @@ public: 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; } @@ -293,8 +301,9 @@ public: 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': { -- cgit v1.2.3