Skip to content

Commit 3370a82

Browse files
committed
[lldb] Add option to show internal stop hooks
Add option to the existing "print list of stop hooks" command to show the internal stop hooks instead: ``` target stop-hook list --internal ```
1 parent eae8479 commit 3370a82

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-6
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,10 @@ class Target : public std::enable_shared_from_this<Target>,
15521552

15531553
void SetAllStopHooksActiveState(bool active_state);
15541554

1555+
const std::vector<StopHookSP> &GetInternalStopHooks() const {
1556+
return m_internal_stop_hooks;
1557+
}
1558+
15551559
size_t GetNumStopHooks() const { return m_stop_hooks.size(); }
15561560

15571561
StopHookSP GetStopHookAtIndex(size_t index) {

lldb/source/Commands/CommandObjectBreakpoint.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,7 @@ class CommandObjectBreakpointList : public CommandObjectParsed {
11141114
CommandObjectBreakpointList(CommandInterpreter &interpreter)
11151115
: CommandObjectParsed(
11161116
interpreter, "breakpoint list",
1117-
"List some or all breakpoints at configurable levels of detail.",
1118-
nullptr) {
1119-
CommandArgumentData bp_id_arg;
1117+
"List some or all breakpoints at configurable levels of detail.") {
11201118

11211119
// Define the first (and only) variant of this arg.
11221120
AddSimpleArgumentList(eArgTypeBreakpointID, eArgRepeatOptional);

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5223,19 +5223,65 @@ class CommandObjectTargetStopHookEnableDisable : public CommandObjectParsed {
52235223
#pragma mark CommandObjectTargetStopHookList
52245224

52255225
// CommandObjectTargetStopHookList
5226+
#define LLDB_OPTIONS_target_stop_hook_list
5227+
#include "CommandOptions.inc"
52265228

52275229
class CommandObjectTargetStopHookList : public CommandObjectParsed {
52285230
public:
52295231
CommandObjectTargetStopHookList(CommandInterpreter &interpreter)
52305232
: CommandObjectParsed(interpreter, "target stop-hook list",
5231-
"List all stop-hooks.", "target stop-hook list") {}
5233+
"List all stop-hooks.") {}
52325234

52335235
~CommandObjectTargetStopHookList() override = default;
52345236

5237+
Options *GetOptions() override { return &m_options; }
5238+
5239+
class CommandOptions : public Options {
5240+
public:
5241+
CommandOptions() = default;
5242+
~CommandOptions() override = default;
5243+
5244+
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
5245+
ExecutionContext *execution_context) override {
5246+
Status error;
5247+
const int short_option = m_getopt_table[option_idx].val;
5248+
5249+
switch (short_option) {
5250+
case 'i':
5251+
m_internal = true;
5252+
break;
5253+
default:
5254+
llvm_unreachable("Unimplemented option");
5255+
}
5256+
5257+
return error;
5258+
}
5259+
5260+
void OptionParsingStarting(ExecutionContext *execution_context) override {
5261+
m_internal = false;
5262+
}
5263+
5264+
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
5265+
return llvm::ArrayRef(g_target_stop_hook_list_options);
5266+
}
5267+
5268+
// Instance variables to hold the values for command options.
5269+
bool m_internal = false;
5270+
};
5271+
52355272
protected:
52365273
void DoExecute(Args &command, CommandReturnObject &result) override {
52375274
Target &target = GetTarget();
52385275

5276+
if (m_options.m_internal) {
5277+
for (auto &hook : target.GetInternalStopHooks()) {
5278+
hook->GetDescription(result.GetOutputStream(), eDescriptionLevelFull);
5279+
result.GetOutputStream().PutCString("\n");
5280+
}
5281+
result.SetStatus(eReturnStatusSuccessFinishResult);
5282+
return;
5283+
}
5284+
52395285
size_t num_hooks = target.GetNumStopHooks();
52405286
if (num_hooks == 0) {
52415287
result.GetOutputStream().PutCString("No stop hooks.\n");
@@ -5250,6 +5296,9 @@ class CommandObjectTargetStopHookList : public CommandObjectParsed {
52505296
}
52515297
result.SetStatus(eReturnStatusSuccessFinishResult);
52525298
}
5299+
5300+
private:
5301+
CommandOptions m_options;
52535302
};
52545303

52555304
#pragma mark CommandObjectMultiwordTargetStopHooks

lldb/source/Commands/Options.td

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ let Command = "breakpoint list" in {
7777
// FIXME: We need to add an "internal" command, and then add this sort of
7878
// thing to it. But I need to see it for now, and don't want to wait.
7979
def blist_internal : Option<"internal", "i">,
80-
Desc<"Show debugger ${i}nternal breakpoints">;
80+
Desc<"Show debugger ${i}nternal breakpoints.">;
8181
def blist_brief : Option<"brief", "b">,
8282
Group<1>,
8383
Desc<"Give a ${b}rief description of the breakpoint (no "
@@ -1686,7 +1686,7 @@ let Command = "target modules lookup" in {
16861686
"match, if a best match is available.">;
16871687
}
16881688

1689-
let Command = "target stop hook add" in {
1689+
let Command = "target stop_hook add" in {
16901690
def target_stop_hook_add_one_liner
16911691
: Option<"one-liner", "o">,
16921692
GroupRange<1, 3>,
@@ -1762,6 +1762,12 @@ let Command = "target stop hook add" in {
17621762
"Defaults to true.">;
17631763
}
17641764

1765+
let Command = "target stop_hook list" in {
1766+
def target_stop_hook_list_internal
1767+
: Option<"internal", "i">,
1768+
Desc<"Show debugger ${i}nternal stop hooks.">;
1769+
}
1770+
17651771
let Command = "thread backtrace" in {
17661772
def thread_backtrace_count : Option<"count", "c">,
17671773
Group<1>,

0 commit comments

Comments
 (0)