diff options
author | Pedro Alves <palves@redhat.com> | 2017-05-04 12:46:44 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-05-04 15:18:44 +0100 |
commit | 5ed8105e02d0c6648b7faea9f4e941237b932717 (patch) | |
tree | 67efdcb3d7a9288b1d73449d477368acdd948c37 /gdb/breakpoint.c | |
parent | f6223dbb50b5d8780df633633adf0742c662173d (diff) | |
download | gdb-5ed8105e02d0c6648b7faea9f4e941237b932717.zip gdb-5ed8105e02d0c6648b7faea9f4e941237b932717.tar.gz gdb-5ed8105e02d0c6648b7faea9f4e941237b932717.tar.bz2 |
RAII-fy make_cleanup_restore_current_thread & friends
After all the make_cleanup_restore_current_thread fixing, I thought
I'd convert that and its relatives (which are all cleanups) to RAII
classes.
scoped_restore_current_pspace_and_thread was put in a separate file to
avoid a circular dependency.
Tested on x86-64 Fedora 23, native and gdbserver.
gdb/ChangeLog:
2017-05-04 Pedro Alves <palves@redhat.com>
* Makefile.in (SFILES): Add progspace-and-thread.c.
(HFILES_NO_SRCDIR): Add progspace-and-thread.h.
(COMMON_OBS): Add progspace-and-thread.o.
* breakpoint.c: Include "progspace-and-thread.h".
(update_inserted_breakpoint_locations)
(insert_breakpoint_locations, create_longjmp_master_breakpoint):
Use scoped_restore_current_pspace_and_thread.
(create_std_terminate_master_breakpoint): Use
scoped_restore_current_program_space.
(remove_breakpoint): Use scoped_restore_current_pspace_and_thread.
(print_breakpoint_location): Use
scoped_restore_current_program_space.
(bp_loc_is_permanent): Use
scoped_restore_current_pspace_and_thread.
(resolve_sal_pc): Use scoped_restore_current_pspace_and_thread.
(download_tracepoint_locations): Use
scoped_restore_current_pspace_and_thread.
(breakpoint_re_set): Use scoped_restore_current_pspace_and_thread.
* exec.c (exec_close_1): Use scoped_restore_current_program_space.
(enum step_over_calls_kind): Moved from inferior.h.
(class scoped_restore_current_thread): New class.
* gdbthread.h (make_cleanup_restore_current_thread): Delete
declaration.
(scoped_restore_current_thread): New class.
* infcmd.c: Include "common/gdb_optional.h".
(continue_1, proceed_after_attach): Use
scoped_restore_current_thread.
(notice_new_inferior): Use scoped_restore_current_thread.
* inferior.c: Include "progspace-and-thread.h".
(restore_inferior, save_current_inferior): Delete.
(add_inferior_command, clone_inferior_command): Use
scoped_restore_current_pspace_and_thread.
* inferior.h (scoped_restore_current_inferior): New class.
* infrun.c: Include "progspace-and-thread.h" and
"common/gdb_optional.h".
(follow_fork_inferior): Use
scoped_restore_current_pspace_and_thread.
(scoped_restore_exited_inferior): New class.
(handle_vfork_child_exec_or_exit): Use
scoped_restore_exited_inferior,
scoped_restore_current_pspace_and_thread,
scoped_restore_current_thread and scoped_restore.
(fetch_inferior_event): Use scoped_restore_current_thread.
* linespec.c (decode_line_full, decode_line_1): Use
scoped_restore_current_program_space.
* mi/mi-main.c: Include "progspace-and-thread.h".
(exec_continue): Use scoped_restore_current_thread.
(mi_cmd_exec_run): Use scoped_restore_current_pspace_and_thread.
(mi_cmd_trace_frame_collected): Use scoped_restore_current_thread.
* proc-service.c (ps_pglobal_lookup): Use
scoped_restore_current_program_space.
* progspace-and-thread.c: New file.
* progspace-and-thread.h: New file.
* progspace.c (release_program_space, clone_program_space): Use
scoped_restore_current_program_space.
(restore_program_space, save_current_program_space)
(save_current_space_and_thread): Delete.
(switch_to_program_space_and_thread): Moved to
progspace-and-thread.c.
* progspace.h (save_current_program_space)
(save_current_space_and_thread): Delete declarations.
(scoped_restore_current_program_space): New class.
* remote.c (remote_btrace_maybe_reopen): Use
scoped_restore_current_thread.
* symtab.c: Include "progspace-and-thread.h".
(skip_prologue_sal): Use scoped_restore_current_pspace_and_thread.
* thread.c (print_thread_info_1): Use
scoped_restore_current_thread.
(struct current_thread_cleanup): Delete.
(do_restore_current_thread_cleanup)
(restore_current_thread_cleanup_dtor): Rename/convert both to ...
(scoped_restore_current_thread::~scoped_restore_current_thread):
... this new dtor.
(make_cleanup_restore_current_thread): Rename/convert to ...
(scoped_restore_current_thread::scoped_restore_current_thread):
... this new ctor.
(thread_apply_all_command): Use scoped_restore_current_thread.
(thread_apply_command): Use scoped_restore_current_thread.
* tracepoint.c (tdump_command): Use scoped_restore_current_thread.
* varobj.c (value_of_root_1): Use scoped_restore_current_thread.
Diffstat (limited to 'gdb/breakpoint.c')
-rw-r--r-- | gdb/breakpoint.c | 97 |
1 files changed, 33 insertions, 64 deletions
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index e8d8d09..9d6a2f4 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -80,6 +80,7 @@ #include "mi/mi-common.h" #include "extension.h" #include <algorithm> +#include "progspace-and-thread.h" /* Enums for exception-handling support. */ enum exception_event_kind @@ -3065,7 +3066,7 @@ update_inserted_breakpoint_locations (void) there was an error. */ tmp_error_stream.puts ("Warning:\n"); - struct cleanup *cleanups = save_current_space_and_thread (); + scoped_restore_current_pspace_and_thread restore_pspace_thread; ALL_BP_LOCATIONS (bl, blp_tmp) { @@ -3101,8 +3102,6 @@ update_inserted_breakpoint_locations (void) target_terminal_ours_for_output (); error_stream (tmp_error_stream); } - - do_cleanups (cleanups); } /* Used when starting or continuing the program. */ @@ -3124,7 +3123,7 @@ insert_breakpoint_locations (void) there was an error. */ tmp_error_stream.puts ("Warning:\n"); - struct cleanup *cleanups = save_current_space_and_thread (); + scoped_restore_current_pspace_and_thread restore_pspace_thread; ALL_BP_LOCATIONS (bl, blp_tmp) { @@ -3202,8 +3201,6 @@ You may have requested too many hardware breakpoints/watchpoints.\n"); target_terminal_ours_for_output (); error_stream (tmp_error_stream); } - - do_cleanups (cleanups); } /* Used when the program stops. @@ -3489,9 +3486,8 @@ static void create_longjmp_master_breakpoint (void) { struct program_space *pspace; - struct cleanup *old_chain; - old_chain = save_current_program_space (); + scoped_restore_current_program_space restore_pspace; ALL_PSPACES (pspace) { @@ -3595,8 +3591,6 @@ create_longjmp_master_breakpoint (void) } } } - - do_cleanups (old_chain); } /* Create a master std::terminate breakpoint. */ @@ -3604,10 +3598,9 @@ static void create_std_terminate_master_breakpoint (void) { struct program_space *pspace; - struct cleanup *old_chain; const char *const func_name = "std::terminate()"; - old_chain = save_current_program_space (); + scoped_restore_current_program_space restore_pspace; ALL_PSPACES (pspace) { @@ -3652,8 +3645,6 @@ create_std_terminate_master_breakpoint (void) b->enable_state = bp_disabled; } } - - do_cleanups (old_chain); } /* Install a master breakpoint on the unwinder's debug hook. */ @@ -4077,9 +4068,6 @@ remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) static int remove_breakpoint (struct bp_location *bl) { - int ret; - struct cleanup *old_chain; - /* BL is never in moribund_locations by our callers. */ gdb_assert (bl->owner != NULL); @@ -4087,14 +4075,11 @@ remove_breakpoint (struct bp_location *bl) This should not ever happen. */ gdb_assert (bl->owner->type != bp_none); - old_chain = save_current_space_and_thread (); + scoped_restore_current_pspace_and_thread restore_pspace_thread; switch_to_program_space_and_thread (bl->pspace); - ret = remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); - - do_cleanups (old_chain); - return ret; + return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); } /* Clear the "inserted" flag in all breakpoints. */ @@ -6129,7 +6114,8 @@ print_breakpoint_location (struct breakpoint *b, struct bp_location *loc) { struct ui_out *uiout = current_uiout; - struct cleanup *old_chain = save_current_program_space (); + + scoped_restore_current_program_space restore_pspace; if (loc != NULL && loc->shlib_disabled) loc = NULL; @@ -6194,8 +6180,6 @@ print_breakpoint_location (struct breakpoint *b, bp_location_condition_evaluator (loc)); uiout->text (")"); } - - do_cleanups (old_chain); } static const char * @@ -9071,9 +9055,6 @@ program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) static int bp_loc_is_permanent (struct bp_location *loc) { - struct cleanup *cleanup; - int retval; - gdb_assert (loc != NULL); /* If we have a catchpoint or a watchpoint, just return 0. We should not @@ -9083,14 +9064,9 @@ bp_loc_is_permanent (struct bp_location *loc) if (!breakpoint_address_is_meaningful (loc->owner)) return 0; - cleanup = save_current_space_and_thread (); + scoped_restore_current_pspace_and_thread restore_pspace_thread; switch_to_program_space_and_thread (loc->pspace); - - retval = program_breakpoint_here_p (loc->gdbarch, loc->address); - - do_cleanups (cleanup); - - return retval; + return program_breakpoint_here_p (loc->gdbarch, loc->address); } /* Build a command list for the dprintf corresponding to the current @@ -9974,16 +9950,12 @@ resolve_sal_pc (struct symtab_and_line *sal) if we have line numbers but no functions (as can happen in assembly source). */ - struct bound_minimal_symbol msym; - struct cleanup *old_chain = save_current_space_and_thread (); - + scoped_restore_current_pspace_and_thread restore_pspace_thread; switch_to_program_space_and_thread (sal->pspace); - msym = lookup_minimal_symbol_by_pc (sal->pc); + bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); if (msym.minsym) sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); - - do_cleanups (old_chain); } } } @@ -12177,10 +12149,9 @@ static void download_tracepoint_locations (void) { struct breakpoint *b; - struct cleanup *old_chain; enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; - old_chain = save_current_space_and_thread (); + scoped_restore_current_pspace_and_thread restore_pspace_thread; ALL_TRACEPOINTS (b) { @@ -12224,8 +12195,6 @@ download_tracepoint_locations (void) if (bp_location_downloaded) observer_notify_breakpoint_modified (b); } - - do_cleanups (old_chain); } /* Swap the insertion/duplication state between two locations. */ @@ -14506,32 +14475,32 @@ breakpoint_re_set (void) struct breakpoint *b, *b_tmp; enum language save_language; int save_input_radix; - struct cleanup *old_chain; save_language = current_language->la_language; save_input_radix = input_radix; - old_chain = save_current_space_and_thread (); - - /* Note: we must not try to insert locations until after all - breakpoints have been re-set. Otherwise, e.g., when re-setting - breakpoint 1, we'd insert the locations of breakpoint 2, which - hadn't been re-set yet, and thus may have stale locations. */ - ALL_BREAKPOINTS_SAFE (b, b_tmp) { - /* Format possible error msg. */ - char *message = xstrprintf ("Error in re-setting breakpoint %d: ", - b->number); - struct cleanup *cleanups = make_cleanup (xfree, message); - catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); - do_cleanups (cleanups); - } - set_language (save_language); - input_radix = save_input_radix; + scoped_restore_current_pspace_and_thread restore_pspace_thread; - jit_breakpoint_re_set (); + /* Note: we must not try to insert locations until after all + breakpoints have been re-set. Otherwise, e.g., when re-setting + breakpoint 1, we'd insert the locations of breakpoint 2, which + hadn't been re-set yet, and thus may have stale locations. */ - do_cleanups (old_chain); + ALL_BREAKPOINTS_SAFE (b, b_tmp) + { + /* Format possible error msg. */ + char *message = xstrprintf ("Error in re-setting breakpoint %d: ", + b->number); + struct cleanup *cleanups = make_cleanup (xfree, message); + catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); + do_cleanups (cleanups); + } + set_language (save_language); + input_radix = save_input_radix; + + jit_breakpoint_re_set (); + } create_overlay_event_breakpoint (); create_longjmp_master_breakpoint (); |