69
69
#include " llvm/ADT/SetVector.h"
70
70
#include " llvm/Support/ThreadPool.h"
71
71
72
+ #include < algorithm>
72
73
#include < memory>
73
74
#include < mutex>
74
75
#include < optional>
@@ -3033,15 +3034,9 @@ bool Target::RunStopHooks() {
3033
3034
if (m_stop_hooks.empty ())
3034
3035
return false ;
3035
3036
3036
- // If there aren't any active stop hooks, don't bother either.
3037
- bool any_active_hooks = false ;
3038
- for (auto hook : m_stop_hooks) {
3039
- if (hook.second ->IsActive ()) {
3040
- any_active_hooks = true ;
3041
- break ;
3042
- }
3043
- }
3044
- if (!any_active_hooks)
3037
+ bool no_active = std::none_of (m_stop_hooks.cbegin (), m_stop_hooks.cend (),
3038
+ [](auto &p) { return p.second ->IsActive (); });
3039
+ if (no_active)
3045
3040
return false ;
3046
3041
3047
3042
// Make sure we check that we are not stopped because of us running a user
@@ -3075,13 +3070,13 @@ bool Target::RunStopHooks() {
3075
3070
return false ;
3076
3071
3077
3072
StreamSP output_sp = m_debugger.GetAsyncOutputStream ();
3073
+ auto on_exit = llvm::make_scope_exit ([output_sp] { output_sp->Flush (); });
3078
3074
3079
- bool auto_continue = false ;
3080
- bool hooks_ran = false ;
3081
3075
bool print_hook_header = (m_stop_hooks.size () != 1 );
3082
3076
bool print_thread_header = (num_exe_ctx != 1 );
3077
+ bool auto_continue = false ;
3083
3078
bool should_stop = false ;
3084
- bool somebody_restarted = false ;
3079
+ bool requested_continue = false ;
3085
3080
3086
3081
for (auto stop_entry : m_stop_hooks) {
3087
3082
StopHookSP cur_hook_sp = stop_entry.second ;
@@ -3090,21 +3085,13 @@ bool Target::RunStopHooks() {
3090
3085
3091
3086
bool any_thread_matched = false ;
3092
3087
for (auto exc_ctx : exc_ctx_with_reasons) {
3093
- // We detect somebody restarted in the stop-hook loop, and broke out of
3094
- // that loop back to here. So break out of here too.
3095
- if (somebody_restarted)
3096
- break ;
3097
-
3098
3088
if (!cur_hook_sp->ExecutionContextPasses (exc_ctx))
3099
3089
continue ;
3100
3090
3101
3091
// We only consult the auto-continue for a stop hook if it matched the
3102
3092
// specifier.
3103
3093
auto_continue |= cur_hook_sp->GetAutoContinue ();
3104
3094
3105
- if (!hooks_ran)
3106
- hooks_ran = true ;
3107
-
3108
3095
if (print_hook_header && !any_thread_matched) {
3109
3096
StreamString s;
3110
3097
cur_hook_sp->GetDescription (s, eDescriptionLevelBrief);
@@ -3120,59 +3107,38 @@ bool Target::RunStopHooks() {
3120
3107
output_sp->Printf (" -- Thread %d\n " ,
3121
3108
exc_ctx.GetThreadPtr ()->GetIndexID ());
3122
3109
3123
- StopHook::StopHookResult this_result =
3124
- cur_hook_sp->HandleStop (exc_ctx, output_sp);
3125
- bool this_should_stop = true ;
3126
-
3127
- switch (this_result) {
3110
+ auto result = cur_hook_sp->HandleStop (exc_ctx, output_sp);
3111
+ switch (result) {
3128
3112
case StopHook::StopHookResult::KeepStopped:
3129
- // If this hook is set to auto-continue that should override the
3130
- // HandleStop result...
3131
- if (cur_hook_sp->GetAutoContinue ())
3132
- this_should_stop = false ;
3133
- else
3134
- this_should_stop = true ;
3135
-
3113
+ should_stop = true ;
3136
3114
break ;
3137
3115
case StopHook::StopHookResult::RequestContinue:
3138
- this_should_stop = false ;
3116
+ requested_continue = true ;
3117
+ break ;
3118
+ case StopHook::StopHookResult::NoPreference:
3119
+ // Do nothing
3139
3120
break ;
3140
3121
case StopHook::StopHookResult::AlreadyContinued:
3141
3122
// We don't have a good way to prohibit people from restarting the
3142
3123
// target willy nilly in a stop hook. If the hook did so, give a
3143
- // gentle suggestion here and bag out if the hook processing.
3124
+ // gentle suggestion here and back out of the hook processing.
3144
3125
output_sp->Printf (" \n Aborting stop hooks, hook %" PRIu64
3145
3126
" set the program running.\n "
3146
3127
" Consider using '-G true' to make "
3147
3128
" stop hooks auto-continue.\n " ,
3148
3129
cur_hook_sp->GetID ());
3149
- somebody_restarted = true ;
3150
- break ;
3130
+ // FIXME: if we are doing non-stop mode for real, we would have to
3131
+ // check that OUR thread was restarted, otherwise we should keep
3132
+ // processing stop hooks.
3133
+ return true ;
3151
3134
}
3152
- // If we're already restarted, stop processing stop hooks.
3153
- // FIXME: if we are doing non-stop mode for real, we would have to
3154
- // check that OUR thread was restarted, otherwise we should keep
3155
- // processing stop hooks.
3156
- if (somebody_restarted)
3157
- break ;
3158
-
3159
- // If anybody wanted to stop, we should all stop.
3160
- if (!should_stop)
3161
- should_stop = this_should_stop;
3162
3135
}
3163
3136
}
3164
3137
3165
- output_sp->Flush ();
3166
-
3167
- // If one of the commands in the stop hook already restarted the target,
3168
- // report that fact.
3169
- if (somebody_restarted)
3170
- return true ;
3171
-
3172
- // Finally, if auto-continue was requested, do it now:
3173
- // We only compute should_stop against the hook results if a hook got to run
3174
- // which is why we have to do this conjoint test.
3175
- if ((hooks_ran && !should_stop) || auto_continue) {
3138
+ // Resume iff:
3139
+ // 1) At least one hook requested to continue and no hook asked to stop, or
3140
+ // 2) at least one hook had auto continue on.
3141
+ if ((requested_continue && !should_stop) || auto_continue) {
3176
3142
Log *log = GetLog (LLDBLog::Process);
3177
3143
Status error = m_process_sp->PrivateResume ();
3178
3144
if (error.Success ()) {
0 commit comments