@@ -3033,15 +3033,9 @@ bool Target::RunStopHooks() {
3033
3033
if (m_stop_hooks.empty ())
3034
3034
return false ;
3035
3035
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)
3036
+ bool no_active_hooks =
3037
+ llvm::none_of (m_stop_hooks, [](auto &p) { return p.second ->IsActive (); });
3038
+ if (no_active_hooks)
3045
3039
return false ;
3046
3040
3047
3041
// Make sure we check that we are not stopped because of us running a user
@@ -3075,13 +3069,13 @@ bool Target::RunStopHooks() {
3075
3069
return false ;
3076
3070
3077
3071
StreamSP output_sp = m_debugger.GetAsyncOutputStream ();
3072
+ auto on_exit = llvm::make_scope_exit ([output_sp] { output_sp->Flush (); });
3078
3073
3079
- bool auto_continue = false ;
3080
- bool hooks_ran = false ;
3081
3074
bool print_hook_header = (m_stop_hooks.size () != 1 );
3082
3075
bool print_thread_header = (num_exe_ctx != 1 );
3076
+ bool auto_continue = false ;
3083
3077
bool should_stop = false ;
3084
- bool somebody_restarted = false ;
3078
+ bool requested_continue = false ;
3085
3079
3086
3080
for (auto stop_entry : m_stop_hooks) {
3087
3081
StopHookSP cur_hook_sp = stop_entry.second ;
@@ -3090,21 +3084,13 @@ bool Target::RunStopHooks() {
3090
3084
3091
3085
bool any_thread_matched = false ;
3092
3086
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
3087
if (!cur_hook_sp->ExecutionContextPasses (exc_ctx))
3099
3088
continue ;
3100
3089
3101
3090
// We only consult the auto-continue for a stop hook if it matched the
3102
3091
// specifier.
3103
3092
auto_continue |= cur_hook_sp->GetAutoContinue ();
3104
3093
3105
- if (!hooks_ran)
3106
- hooks_ran = true ;
3107
-
3108
3094
if (print_hook_header && !any_thread_matched) {
3109
3095
StreamString s;
3110
3096
cur_hook_sp->GetDescription (s, eDescriptionLevelBrief);
@@ -3120,59 +3106,38 @@ bool Target::RunStopHooks() {
3120
3106
output_sp->Printf (" -- Thread %d\n " ,
3121
3107
exc_ctx.GetThreadPtr ()->GetIndexID ());
3122
3108
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) {
3109
+ auto result = cur_hook_sp->HandleStop (exc_ctx, output_sp);
3110
+ switch (result) {
3128
3111
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
-
3112
+ should_stop = true ;
3136
3113
break ;
3137
3114
case StopHook::StopHookResult::RequestContinue:
3138
- this_should_stop = false ;
3115
+ requested_continue = true ;
3116
+ break ;
3117
+ case StopHook::StopHookResult::NoPreference:
3118
+ // Do nothing
3139
3119
break ;
3140
3120
case StopHook::StopHookResult::AlreadyContinued:
3141
3121
// We don't have a good way to prohibit people from restarting the
3142
3122
// 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.
3123
+ // gentle suggestion here and back out of the hook processing.
3144
3124
output_sp->Printf (" \n Aborting stop hooks, hook %" PRIu64
3145
3125
" set the program running.\n "
3146
3126
" Consider using '-G true' to make "
3147
3127
" stop hooks auto-continue.\n " ,
3148
3128
cur_hook_sp->GetID ());
3149
- somebody_restarted = true ;
3150
- break ;
3129
+ // FIXME: if we are doing non-stop mode for real, we would have to
3130
+ // check that OUR thread was restarted, otherwise we should keep
3131
+ // processing stop hooks.
3132
+ return true ;
3151
3133
}
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
3134
}
3163
3135
}
3164
3136
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) {
3137
+ // Resume iff:
3138
+ // 1) At least one hook requested to continue and no hook asked to stop, or
3139
+ // 2) at least one hook had auto continue on.
3140
+ if ((requested_continue && !should_stop) || auto_continue) {
3176
3141
Log *log = GetLog (LLDBLog::Process);
3177
3142
Status error = m_process_sp->PrivateResume ();
3178
3143
if (error.Success ()) {
0 commit comments