From be7d3cd5f13196dd070978aa48c2832c351c25b6 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Fri, 11 Aug 2017 09:30:02 +0100 Subject: [PATCH] Reset *THIS_CACHE in frame_unwind_try_unwinder in case of exception It is required that unwinder->sniffer should set *this_cache to NULL if the unwinder is not applicable or exception is thrown, so 78ac5f831692f70b841044961069e50d4ba6a76f adds clear_pointer_cleanup to set *this_cache to NULL in case of exception in order to fix PR 14100. https://sourceware.org/ml/gdb-patches/2012-08/msg00075.html This patch removes that clear_pointer_cleanup, and catch all exception in the caller of unwinder->sniffer. In case of exception, reset *this_case. gdb: 2017-08-11 Yao Qi * dwarf2-frame.c (clear_pointer_cleanup): Remove. (dwarf2_frame_cache): Remove reset_cache_cleanup. (dwarf2_frame_cache): * frame-unwind.c (frame_unwind_try_unwinder): Catch RETURN_MASK_ALL and set *this_case to NULL. * frame-unwind.h: Update comments. --- gdb/ChangeLog | 9 +++++++++ gdb/dwarf2-frame.c | 14 -------------- gdb/frame-unwind.c | 7 ++++++- gdb/frame-unwind.h | 3 ++- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b08f72b4eae..75a1ea80f5f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2017-08-11 Yao Qi + + * dwarf2-frame.c (clear_pointer_cleanup): Remove. + (dwarf2_frame_cache): Remove reset_cache_cleanup. + (dwarf2_frame_cache): + * frame-unwind.c (frame_unwind_try_unwinder): Catch + RETURN_MASK_ALL and set *this_case to NULL. + * frame-unwind.h: Update comments. + 2017-08-11 Yao Qi * dwarf2-frame.c (dwarf2_frame_state_alloc_regs): Remove. diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c index 0cb40d91e50..f8e652237cb 100644 --- a/gdb/dwarf2-frame.c +++ b/gdb/dwarf2-frame.c @@ -960,20 +960,9 @@ struct dwarf2_frame_cache int entry_cfa_sp_offset_p; }; -/* A cleanup that sets a pointer to NULL. */ - -static void -clear_pointer_cleanup (void *arg) -{ - void **ptr = (void **) arg; - - *ptr = NULL; -} - static struct dwarf2_frame_cache * dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache) { - struct cleanup *reset_cache_cleanup; struct gdbarch *gdbarch = get_frame_arch (this_frame); const int num_regs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch); @@ -989,7 +978,6 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache) cache = FRAME_OBSTACK_ZALLOC (struct dwarf2_frame_cache); cache->reg = FRAME_OBSTACK_CALLOC (num_regs, struct dwarf2_frame_state_reg); *this_cache = cache; - reset_cache_cleanup = make_cleanup (clear_pointer_cleanup, this_cache); /* Unwind the PC. @@ -1078,7 +1066,6 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache) if (ex.error == NOT_AVAILABLE_ERROR) { cache->unavailable_retaddr = 1; - discard_cleanups (reset_cache_cleanup); return cache; } @@ -1184,7 +1171,6 @@ incomplete CFI data; unspecified registers (e.g., %s) at %s"), && fs.regs.reg[fs.retaddr_column].how == DWARF2_FRAME_REG_UNDEFINED) cache->undefined_retaddr = 1; - discard_cleanups (reset_cache_cleanup); return cache; } diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c index 4d21349fe6c..3a750130594 100644 --- a/gdb/frame-unwind.c +++ b/gdb/frame-unwind.c @@ -106,8 +106,11 @@ frame_unwind_try_unwinder (struct frame_info *this_frame, void **this_cache, { res = unwinder->sniffer (unwinder, this_frame, this_cache); } - CATCH (ex, RETURN_MASK_ERROR) + CATCH (ex, RETURN_MASK_ALL) { + /* Catch all exceptions, caused by either interrupt or error. + Reset *THIS_CACHE. */ + *this_cache = NULL; if (ex.error == NOT_AVAILABLE_ERROR) { /* This usually means that not even the PC is available, @@ -128,6 +131,8 @@ frame_unwind_try_unwinder (struct frame_info *this_frame, void **this_cache, } else { + /* Don't set *THIS_CACHE to NULL here, because sniffer has to do + so. */ do_cleanups (old_cleanup); return 0; } diff --git a/gdb/frame-unwind.h b/gdb/frame-unwind.h index 4588cef2e73..8226b6db25d 100644 --- a/gdb/frame-unwind.h +++ b/gdb/frame-unwind.h @@ -46,7 +46,8 @@ struct value; the PC and attributes) and if SELF is the applicable unwinder, return non-zero. Possibly also initialize THIS_PROLOGUE_CACHE; but only if returning 1. Initializing THIS_PROLOGUE_CACHE in other - cases (0 return, or exception) is invalid. */ + cases (0 return) is invalid. In case of exception, the caller has + to set *THIS_PROLOGUE_CACHE to NULL. */ typedef int (frame_sniffer_ftype) (const struct frame_unwind *self, struct frame_info *this_frame, -- 2.30.2