diff options
author | Tom Tromey <tom@tromey.com> | 2018-03-07 15:55:01 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-03-08 21:57:14 -0700 |
commit | fdf07f3aeba5906fec462fba33801c173862f241 (patch) | |
tree | fd68e3d0ab16ad5ce80e87f998f4f5db71d8d845 /gdb/thread.c | |
parent | 0089daceaba4338046932e65a1b5882065416633 (diff) | |
download | gdb-fdf07f3aeba5906fec462fba33801c173862f241.zip gdb-fdf07f3aeba5906fec462fba33801c173862f241.tar.gz gdb-fdf07f3aeba5906fec462fba33801c173862f241.tar.bz2 |
Change enable_thread_stack_temporaries to an RAII class
This started as a patch to change enable_thread_stack_temporaries to
be an RAII class, but then I noticed that this code used a VEC, so I
went ahead and did a bit more C++-ification, changing
stack_temporaries_enabled to a bool and changing stack_temporaries to
a std::vector.
Regression tested by the buildbot.
gdb/ChangeLog
2018-03-08 Tom Tromey <tom@tromey.com>
* infcall.c (struct call_return_meta_info)
<stack_temporaries_enabled>: Remove.
(get_call_return_value, call_function_by_hand_dummy): Update.
* thread.c (disable_thread_stack_temporaries): Remove.
(enable_thread_stack_temporaries): Remove.
(thread_stack_temporaries_enabled_p): Return bool.
(push_thread_stack_temporary, value_in_thread_stack_temporaries)
(get_last_thread_stack_temporary): Update.
* eval.c (evaluate_subexp): Update.
* gdbthread.h (class enable_thread_stack_temporaries): Now a
class, not a function.
(value_ptr, value_vec): Remove typedefs.
(class thread_info) <stack_temporaries_enabled>: Now bool.
<stack_temporaries>: Now a std::vector.
(thread_stack_temporaries_enabled_p)
(value_in_thread_stack_temporaries): Return bool.
Diffstat (limited to 'gdb/thread.c')
-rw-r--r-- | gdb/thread.c | 71 |
1 files changed, 13 insertions, 58 deletions
diff --git a/gdb/thread.c b/gdb/thread.c index 36cfcdd..a99fbdc 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -749,55 +749,16 @@ delete_exited_threads (void) } } -/* Disable storing stack temporaries for the thread whose id is - stored in DATA. */ - -static void -disable_thread_stack_temporaries (void *data) -{ - ptid_t *pd = (ptid_t *) data; - struct thread_info *tp = find_thread_ptid (*pd); - - if (tp != NULL) - { - tp->stack_temporaries_enabled = 0; - VEC_free (value_ptr, tp->stack_temporaries); - } - - xfree (pd); -} - -/* Enable storing stack temporaries for thread with id PTID and return a - cleanup which can disable and clear the stack temporaries. */ - -struct cleanup * -enable_thread_stack_temporaries (ptid_t ptid) -{ - struct thread_info *tp = find_thread_ptid (ptid); - ptid_t *data; - struct cleanup *c; - - gdb_assert (tp != NULL); - - tp->stack_temporaries_enabled = 1; - tp->stack_temporaries = NULL; - data = XNEW (ptid_t); - *data = ptid; - c = make_cleanup (disable_thread_stack_temporaries, data); - - return c; -} - -/* Return non-zero value if stack temporaies are enabled for the thread +/* Return true value if stack temporaies are enabled for the thread with id PTID. */ -int +bool thread_stack_temporaries_enabled_p (ptid_t ptid) { struct thread_info *tp = find_thread_ptid (ptid); if (tp == NULL) - return 0; + return false; else return tp->stack_temporaries_enabled; } @@ -810,29 +771,23 @@ push_thread_stack_temporary (ptid_t ptid, struct value *v) struct thread_info *tp = find_thread_ptid (ptid); gdb_assert (tp != NULL && tp->stack_temporaries_enabled); - VEC_safe_push (value_ptr, tp->stack_temporaries, v); + tp->stack_temporaries.push_back (v); } -/* Return 1 if VAL is among the stack temporaries of the thread - with id PTID. Return 0 otherwise. */ +/* Return true if VAL is among the stack temporaries of the thread + with id PTID. Return false otherwise. */ -int +bool value_in_thread_stack_temporaries (struct value *val, ptid_t ptid) { struct thread_info *tp = find_thread_ptid (ptid); gdb_assert (tp != NULL && tp->stack_temporaries_enabled); - if (!VEC_empty (value_ptr, tp->stack_temporaries)) - { - struct value *v; - int i; + for (struct value *v : tp->stack_temporaries) + if (v == val) + return true; - for (i = 0; VEC_iterate (value_ptr, tp->stack_temporaries, i, v); i++) - if (v == val) - return 1; - } - - return 0; + return false; } /* Return the last of the stack temporaries for thread with id PTID. @@ -845,8 +800,8 @@ get_last_thread_stack_temporary (ptid_t ptid) struct thread_info *tp = find_thread_ptid (ptid); gdb_assert (tp != NULL); - if (!VEC_empty (value_ptr, tp->stack_temporaries)) - lastval = VEC_last (value_ptr, tp->stack_temporaries); + if (!tp->stack_temporaries.empty ()) + lastval = tp->stack_temporaries.back (); return lastval; } |