Files
llvm-project/lldb/test/Shell/ExecControl/StopHook/stop-hook-list.test
Julian Lettner 10a975be0f [lldb] Introduce internal stop hooks (#164506)
Introduce the concept of internal stop hooks.
These are similar to LLDB's internal breakpoints:
LLDB itself will add them and users of LLDB will
not be able to add or remove them.

This change adds the following 3
independently-useful concepts:
* Maintain a list of internal stop hooks that will be populated by LLDB
and cannot be added to or removed from by users. They are managed in a
separate list in `Target::m_internal_stop_hooks`.
* `StopHookKind:CodeBased` and `StopHookCoded` represent a stop hook
defined by a C++ code callback (instead of command line expressions or a
Python class).
* Stop hooks that do not print any output can now also suppress the
printing of their header and description when they are hit via
`StopHook::GetSuppressOutput`.

Combining these 3 concepts we can model "internal
stop hooks" which serve the same function as
LLDB's internal breakpoints: executing built-in,
LLDB-defined behavior, leveraging the existing
mechanism of stop hooks.

This change also simplifies
`Target::RunStopHooks`.  We already have to
materialize a new list for combining internal and
user stop hooks. Filter and only add active hooks to this list to avoid
the need for "isActive?"
checks later on.
2025-10-24 17:08:25 -07:00

71 lines
1.7 KiB
Plaintext

# Test stop hook user ID assignment, ordering, and printing.
#
# RUN: %lldb -b -s %s | FileCheck %s
# Create some stop hooks
target stop-hook add -o 'print "Hello"'
target stop-hook add -o 'print "world,"'
target stop-hook add -o 'print "nice"'
target stop-hook add -o 'print "weather"'
target stop-hook add -o 'print "today!"'
# Print hooks
target stop-hook list
# CHECK: (lldb) target stop-hook list
# CHECK: Hook: 1
# CHECK: "Hello"
# CHECK: Hook: 2
# CHECK: "world,"
# CHECK: Hook: 3
# CHECK: "nice"
# CHECK: Hook: 4
# CHECK: "weather"
# CHECK: Hook: 5
# CHECK: "today!"
# Delete last hook, then add new one
target stop-hook delete 5
target stop-hook add -o 'print "Sunshine,"'
# Stop hook gets new user ID (it is not reused)
# CHECK: (lldb) target stop-hook add -o 'print "Sunshine,"'
# CHECK: Stop hook #6 added.
target stop-hook list
# CHECK: (lldb) target stop-hook list
# CHECK: Hook: 4
# CHECK-NOT: Hook: 5
# CHECK: Hook: 6
# Add a few more hooks
target stop-hook add -o 'print "rain,"'
target stop-hook add -o 'print "and wind!"'
target stop-hook add -o 'print "It is all okay!"'
# CHECK: Stop hook #7 added.
# CHECK: Stop hook #8 added.
# CHECK: Stop hook #9 added.
# Delete a few hooks
target stop-hook delete 1
target stop-hook delete 3
target stop-hook delete 7
target stop-hook delete 9
# Check that the list is still well-ordered
target stop-hook list
# CHECK: (lldb) target stop-hook list
# CHECK-NOT: Hook: 1
# CHECK: Hook: 2
# CHECK: "world,"
# CHECK-NOT: Hook: 3
# CHECK: Hook: 4
# CHECK: "weather"
# CHECK-NOT: Hook: 5
# CHECK: Hook: 6
# CHECK: "Sunshine,"
# CHECK-NOT: Hook: 7
# CHECK: Hook: 8
# CHECK: "and wind!"
# CHECK-NOT: Hook: 9