From 6f14adc55864818ec3754460f5df4150c2addf42 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 7 Apr 2018 14:03:12 -0400 Subject: [PATCH] Replace make_cleanup_restore_current_traceframe with RAII class I put the constructor in tracepoint.c because it needs to read traceframe_number, and I prefer to do that than to expose traceframe_number. gdb/ChangeLog: * tracepoint.c (struct current_traceframe_cleanup): Remove. (do_restore_current_traceframe_cleanup): Remove. (restore_current_traceframe_cleanup_dtor): Remove. (make_cleanup_restore_current_traceframe): Remove. (scoped_restore_current_traceframe::scoped_restore_current_traceframe): New. * tracepoint.h (struct scoped_restore_current_traceframe): New. * infrun.c (fetch_inferior_event): Use scoped_restore_current_traceframe. --- gdb/ChangeLog | 12 ++++++++++++ gdb/infrun.c | 3 ++- gdb/tracepoint.c | 40 +++------------------------------------- gdb/tracepoint.h | 17 ++++++++++++++++- 4 files changed, 33 insertions(+), 39 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9c7cc149fa3..fc95d7632fd 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +2018-04-07 Simon Marchi + + * tracepoint.c (struct current_traceframe_cleanup): Remove. + (do_restore_current_traceframe_cleanup): Remove. + (restore_current_traceframe_cleanup_dtor): Remove. + (make_cleanup_restore_current_traceframe): Remove. + (scoped_restore_current_traceframe::scoped_restore_current_traceframe): + New. + * tracepoint.h (struct scoped_restore_current_traceframe): New. + * infrun.c (fetch_inferior_event): Use + scoped_restore_current_traceframe. + 2018-04-07 Simon Marchi * dwarf2read.h (struct dwarf2_per_objfile) : diff --git a/gdb/infrun.c b/gdb/infrun.c index 6648698df6f..d89f8137f4a 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -3877,9 +3877,10 @@ fetch_inferior_event (void *client_data) debugging. If we're looking at traceframes while the target is running, we're going to need to get back to that mode after handling the event. */ + gdb::optional maybe_restore_traceframe; if (non_stop) { - make_cleanup_restore_current_traceframe (); + maybe_restore_traceframe.emplace (); set_current_traceframe (-1); } diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index f66cc686b8e..a2f1376c5c0 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -3012,43 +3012,9 @@ set_current_traceframe (int num) clear_traceframe_info (); } -/* A cleanup used when switching away and back from tfind mode. */ - -struct current_traceframe_cleanup -{ - /* The traceframe we were inspecting. */ - int traceframe_number; -}; - -static void -do_restore_current_traceframe_cleanup (void *arg) -{ - struct current_traceframe_cleanup *old - = (struct current_traceframe_cleanup *) arg; - - set_current_traceframe (old->traceframe_number); -} - -static void -restore_current_traceframe_cleanup_dtor (void *arg) -{ - struct current_traceframe_cleanup *old - = (struct current_traceframe_cleanup *) arg; - - xfree (old); -} - -struct cleanup * -make_cleanup_restore_current_traceframe (void) -{ - struct current_traceframe_cleanup *old = - XNEW (struct current_traceframe_cleanup); - - old->traceframe_number = traceframe_number; - - return make_cleanup_dtor (do_restore_current_traceframe_cleanup, old, - restore_current_traceframe_cleanup_dtor); -} +scoped_restore_current_traceframe::scoped_restore_current_traceframe () +: m_traceframe_number (traceframe_number) +{} /* Given a number and address, return an uploaded tracepoint with that number, creating if necessary. */ diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h index 8613cb2dd69..02f4bf70890 100644 --- a/gdb/tracepoint.h +++ b/gdb/tracepoint.h @@ -321,7 +321,22 @@ extern int get_tracepoint_number (void); etc.). */ extern void set_current_traceframe (int num); -struct cleanup *make_cleanup_restore_current_traceframe (void); +struct scoped_restore_current_traceframe +{ + scoped_restore_current_traceframe (); + + ~scoped_restore_current_traceframe () + { + set_current_traceframe (m_traceframe_number); + } + + DISABLE_COPY_AND_ASSIGN (scoped_restore_current_traceframe); + +private: + + /* The traceframe we were inspecting. */ + int m_traceframe_number; +}; void free_actions (struct breakpoint *); -- 2.30.2