From patchwork Mon Feb 9 23:20:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 5004 Received: (qmail 13781 invoked by alias); 9 Feb 2015 23:22:02 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 13709 invoked by uid 89); 9 Feb 2015 23:22:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 09 Feb 2015 23:21:56 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t19NLtS5011857 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 9 Feb 2015 18:21:55 -0500 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t19NKkuw026307 for ; Mon, 9 Feb 2015 18:21:54 -0500 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 33/36] TRY_CATCH -> TRY+CATCH+END_CATCH, the manual conversions Date: Mon, 9 Feb 2015 23:20:43 +0000 Message-Id: <1423524046-20605-34-git-send-email-palves@redhat.com> In-Reply-To: <1423524046-20605-1-git-send-email-palves@redhat.com> References: <1423524046-20605-1-git-send-email-palves@redhat.com> This fixes the cases where we're using the exception object outside of a the CATCH block, and cases where we were using "else" after a CATCH. I originally planned on doing these changes in the preparatory patch that normalizes TRY_CATCH (the one just before the wholesale scripted conversion patch), but then that feels like it'd make the resulting patch harder to read and not as clear. It's a lot less work this way too. :-) I can still do that if people prefer though. Otherwise, I plan to squash this with the previous patch, and push it all together. --- gdb/ada-typeprint.c | 4 +- gdb/breakpoint.c | 44 +++++++++------------- gdb/c-varobj.c | 5 +-- gdb/cp-support.c | 14 ++++--- gdb/exceptions.c | 4 +- gdb/frame.c | 4 +- gdb/gcore.c | 13 ++++--- gdb/gdbserver/server.c | 28 ++++++-------- gdb/gnu-v3-abi.c | 7 ++-- gdb/guile/guile.c | 4 +- gdb/guile/scm-breakpoint.c | 8 +++- gdb/guile/scm-frame.c | 12 ++++-- gdb/guile/scm-math.c | 4 +- gdb/guile/scm-param.c | 4 +- gdb/guile/scm-symbol.c | 8 +++- gdb/guile/scm-value.c | 6 ++- gdb/inf-loop.c | 3 +- gdb/infcall.c | 11 ++++-- gdb/infrun.c | 3 +- gdb/main.c | 8 ++-- gdb/mi/mi-cmd-stack.c | 10 ++--- gdb/mi/mi-main.c | 2 +- gdb/python/py-breakpoint.c | 4 +- gdb/python/py-finishbreakpoint.c | 2 +- gdb/python/py-frame.c | 4 +- gdb/python/py-gdb-readline.c | 9 ++--- gdb/python/py-inferior.c | 8 +++- gdb/python/py-type.c | 7 ++-- gdb/python/py-value.c | 8 +++- gdb/python/python.c | 9 ++++- gdb/record-btrace.c | 19 ++-------- gdb/remote.c | 5 +-- gdb/solib.c | 12 +++--- gdb/stack.c | 80 +++++++++++++++++++--------------------- gdb/varobj.c | 15 ++++---- 35 files changed, 200 insertions(+), 188 deletions(-) diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c index cd481b6..fd85138 100644 --- a/gdb/ada-typeprint.c +++ b/gdb/ada-typeprint.c @@ -160,6 +160,7 @@ print_range (struct type *type, struct ui_file *stream, { struct type *target_type; LONGEST lo = 0, hi = 0; /* init for gcc -Wall */ + int got_error = 0; target_type = TYPE_TARGET_TYPE (type); if (target_type == NULL) @@ -178,10 +179,11 @@ print_range (struct type *type, struct ui_file *stream, when the user is using the "ptype" command on a type. Print the range as an unbounded range. */ fprintf_filtered (stream, "<>"); + got_error = 1; } END_CATCH - else + if (!got_error) { ada_print_scalar (target_type, lo, stream); fprintf_filtered (stream, " .. "); diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 67870f5..b5a9704 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -2429,18 +2429,17 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) format_start, format_end - format_start, fpieces, nargs, argvec); } - - do_cleanups (old_cleanups); - CATCH (ex, RETURN_MASK_ERROR) { /* If we got here, it means the command could not be parsed to a valid bytecode expression and thus can't be evaluated on the target's side. It's no use iterating through the other commands. */ - return NULL; + aexpr = NULL; } END_CATCH + do_cleanups (old_cleanups); + /* We have a valid agent expression, return it. */ return aexpr; } @@ -9996,23 +9995,12 @@ create_breakpoint (struct gdbarch *gdbarch, ops->create_sals_from_address (&arg, &canonical, type_wanted, addr_start, ©_arg); } - CATCH (e, RETURN_MASK_ALL) - { - } - END_CATCH - - /* If caller is interested in rc value from parse, set value. */ - switch (e.reason) + CATCH (e, RETURN_MASK_ERROR) { - case GDB_NO_ERROR: - if (VEC_empty (linespec_sals, canonical.sals)) - return 0; - break; - case RETURN_ERROR: - switch (e.error) + /* If caller is interested in rc value from parse, set + value. */ + if (e.error == NOT_FOUND_ERROR) { - case NOT_FOUND_ERROR: - /* If pending breakpoint support is turned off, throw error. */ @@ -10043,14 +10031,14 @@ create_breakpoint (struct gdbarch *gdbarch, pending = 1; VEC_safe_push (linespec_sals, canonical.sals, &lsal); } - break; - default: - throw_exception (e); } - break; - default: - throw_exception (e); + else + throw_exception (e); } + END_CATCH + + if (VEC_empty (linespec_sals, canonical.sals)) + return 0; /* Create a chain of things that always need to be cleaned up. */ old_chain = make_cleanup_destroy_linespec_result (&canonical); @@ -14547,6 +14535,7 @@ addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) { char *s; struct symtabs_and_lines sals = {0}; + struct gdb_exception exception = exception_none; gdb_assert (b->ops != NULL); s = addr_string; @@ -14558,6 +14547,9 @@ addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) CATCH (e, RETURN_MASK_ERROR) { int not_found_and_ok = 0; + + exception = e; + /* For pending breakpoints, it's expected that parsing will fail until the right shared library is loaded. User has already told to create pending breakpoints and don't need @@ -14586,7 +14578,7 @@ addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) } END_CATCH - if (e.reason == 0 || e.error != NOT_FOUND_ERROR) + if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) { int i; diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c index fd0751f..98775be 100644 --- a/gdb/c-varobj.c +++ b/gdb/c-varobj.c @@ -267,10 +267,7 @@ value_struct_element_index (struct value *value, int type_index) } END_CATCH - else - { - return result; - } + return result; } /* Obtain the information about child INDEX of the variable diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 9530070..4bbee94 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -172,16 +172,18 @@ inspect_type (struct demangle_parse_info *info, } sym = NULL; + TRY - { - sym = lookup_symbol (name, 0, VAR_DOMAIN, 0); - } + { + sym = lookup_symbol (name, 0, VAR_DOMAIN, 0); + } CATCH (except, RETURN_MASK_ALL) { + return 0; } END_CATCH - if (except.reason >= 0 && sym != NULL) + if (sym != NULL) { struct type *otype = SYMBOL_TYPE (sym); @@ -450,7 +452,7 @@ replace_typedefs (struct demangle_parse_info *info, if (local_name != NULL) { - struct symbol *sym; + struct symbol *sym = NULL; sym = NULL; TRY @@ -464,7 +466,7 @@ replace_typedefs (struct demangle_parse_info *info, xfree (local_name); - if (except.reason >= 0 && sym != NULL) + if (sym != NULL) { struct type *otype = SYMBOL_TYPE (sym); const char *new_name = (*finder) (otype, data); diff --git a/gdb/exceptions.c b/gdb/exceptions.c index ba97ad5..623e8e0 100644 --- a/gdb/exceptions.c +++ b/gdb/exceptions.c @@ -228,6 +228,7 @@ int catch_errors (catch_errors_ftype *func, void *func_args, char *errstring, return_mask mask) { + struct gdb_exception exception = exception_none; volatile int val = 0; struct ui_out *saved_uiout; @@ -238,8 +239,9 @@ catch_errors (catch_errors_ftype *func, void *func_args, char *errstring, { val = func (func_args); } - CATCH (exception, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + exception = ex; } END_CATCH diff --git a/gdb/frame.c b/gdb/frame.c index a9d8c3f..b3cbf23 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -786,6 +786,7 @@ frame_unwind_pc (struct frame_info *this_frame) { struct gdbarch *prev_gdbarch; CORE_ADDR pc = 0; + int pc_p = 0; /* The right way. The `pure' way. The one true way. This method depends solely on the register-unwind code to @@ -808,6 +809,7 @@ frame_unwind_pc (struct frame_info *this_frame) TRY { pc = gdbarch_unwind_pc (prev_gdbarch, this_frame); + pc_p = 1; } CATCH (ex, RETURN_MASK_ERROR) { @@ -836,7 +838,7 @@ frame_unwind_pc (struct frame_info *this_frame) } END_CATCH - else + if (pc_p) { this_frame->prev_pc.value = pc; this_frame->prev_pc.status = CC_VALUE; diff --git a/gdb/gcore.c b/gdb/gcore.c index 8ab386f..c308af8 100644 --- a/gdb/gcore.c +++ b/gdb/gcore.c @@ -114,6 +114,7 @@ write_gcore_file_1 (bfd *obfd) void write_gcore_file (bfd *obfd) { + struct gdb_exception except = exception_none; target_prepare_to_generate_core (); @@ -121,14 +122,16 @@ write_gcore_file (bfd *obfd) { write_gcore_file_1 (obfd); } - - target_done_generating_core (); - - CATCH (except, RETURN_MASK_ALL) + CATCH (e, RETURN_MASK_ALL) { - throw_exception (except); + except = e; } END_CATCH + + target_done_generating_core (); + + if (except.reason < 0) + throw_exception (except); } static void diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index ec783ca..8b7a1f2 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -3433,17 +3433,13 @@ captured_main (int argc, char *argv[]) } CATCH (exception, RETURN_MASK_ERROR) { - } - END_CATCH - - if (exception.reason == RETURN_ERROR) - { if (response_needed) { write_enn (own_buf); putpkt (own_buf); } } + END_CATCH } } @@ -3459,21 +3455,19 @@ main (int argc, char *argv[]) } CATCH (exception, RETURN_MASK_ALL) { - } - END_CATCH - - /* captured_main should never return. */ - gdb_assert (exception.reason < 0); + if (exception.reason == RETURN_ERROR) + { + fflush (stdout); + fprintf (stderr, "%s\n", exception.message); + fprintf (stderr, "Exiting\n"); + exit_code = 1; + } - if (exception.reason == RETURN_ERROR) - { - fflush (stdout); - fprintf (stderr, "%s\n", exception.message); - fprintf (stderr, "Exiting\n"); - exit_code = 1; + exit (exit_code); } + END_CATCH - exit (exit_code); + gdb_assert_not_reached ("captured_main should never return"); } /* Skip PACKET until the next semi-colon (or end of string). */ diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c index 2677716..39a333c 100644 --- a/gdb/gnu-v3-abi.c +++ b/gdb/gnu-v3-abi.c @@ -901,8 +901,8 @@ print_one_vtable (struct gdbarch *gdbarch, struct value *value, for (i = 0; i <= max_voffset; ++i) { - /* Initialize it just to avoid a GCC false warning. */ - CORE_ADDR addr = 0; + CORE_ADDR addr; + int got_error = 0; struct value *vfn; printf_filtered ("[%d]: ", i); @@ -921,10 +921,11 @@ print_one_vtable (struct gdbarch *gdbarch, struct value *value, CATCH (ex, RETURN_MASK_ERROR) { printf_filtered (_(""), ex.message); + got_error = 1; } END_CATCH - else + if (!got_error) print_function_pointer_address (opts, gdbarch, addr, gdb_stdout); printf_filtered ("\n"); } diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c index 03ae53a..16d15b7 100644 --- a/gdb/guile/guile.c +++ b/gdb/guile/guile.c @@ -314,6 +314,7 @@ gdbscm_execute_gdb_command (SCM command_scm, SCM rest) char *command; char *result = NULL; struct cleanup *cleanups; + struct gdb_exception except = exception_none; gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#tt", command_scm, &command, rest, @@ -345,8 +346,9 @@ gdbscm_execute_gdb_command (SCM command_scm, SCM rest) do_cleanups (inner_cleanups); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c index f438e01..ad853ed 100644 --- a/gdb/guile/scm-breakpoint.c +++ b/gdb/guile/scm-breakpoint.c @@ -407,6 +407,7 @@ gdbscm_register_breakpoint_x (SCM self) { breakpoint_smob *bp_smob = bpscm_get_breakpoint_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); + struct gdb_exception except = exception_none; /* We only support registering breakpoints created with make-breakpoint. */ if (!bp_smob->is_scheme_bkpt) @@ -454,8 +455,9 @@ gdbscm_register_breakpoint_x (SCM self) gdb_assert_not_reached ("invalid breakpoint type"); } } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH @@ -878,6 +880,7 @@ gdbscm_set_breakpoint_condition_x (SCM self, SCM newvalue) breakpoint_smob *bp_smob = bpscm_get_valid_breakpoint_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); char *exp; + struct gdb_exception except = exception_none; SCM_ASSERT_TYPE (scm_is_string (newvalue) || gdbscm_is_false (newvalue), newvalue, SCM_ARG2, FUNC_NAME, @@ -892,8 +895,9 @@ gdbscm_set_breakpoint_condition_x (SCM self, SCM newvalue) { set_breakpoint_condition (bp_smob->bp, exp ? exp : "", 0); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c index 09f79b6..6189802 100644 --- a/gdb/guile/scm-frame.c +++ b/gdb/guile/scm-frame.c @@ -426,6 +426,7 @@ gdbscm_frame_name (SCM self) enum language lang = language_minimal; struct frame_info *frame = NULL; SCM result; + struct gdb_exception except = exception_none; f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME); @@ -435,12 +436,13 @@ gdbscm_frame_name (SCM self) if (frame != NULL) find_frame_funname (frame, &name, &lang, NULL); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { - xfree (name); + except = ex; } END_CATCH + xfree (name); GDBSCM_HANDLE_GDB_EXCEPTION (except); if (frame == NULL) @@ -835,6 +837,7 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest) char *var_name; const struct block *block = NULL; struct cleanup *cleanup; + struct gdb_exception except = exception_none; if (! SCM_UNBNDP (block_scm)) { @@ -858,12 +861,13 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest) block = get_frame_block (frame, NULL); var = lookup_symbol (var_name, block, VAR_DOMAIN, NULL); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { - do_cleanups (cleanup); + except = ex; } END_CATCH + do_cleanups (cleanup); GDBSCM_HANDLE_GDB_EXCEPTION (except); if (var == NULL) diff --git a/gdb/guile/scm-math.c b/gdb/guile/scm-math.c index 03baa3f..4b6bb5d 100644 --- a/gdb/guile/scm-math.c +++ b/gdb/guile/scm-math.c @@ -447,6 +447,7 @@ vlscm_rich_compare (int op, SCM x, SCM y, const char *func_name) int result = 0; SCM except_scm; struct cleanup *cleanups; + struct gdb_exception except = exception_none; cleanups = make_cleanup_value_free_to_mark (value_mark ()); @@ -492,8 +493,9 @@ vlscm_rich_compare (int op, SCM x, SCM y, const char *func_name) gdb_assert_not_reached ("invalid comparison"); } } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH diff --git a/gdb/guile/scm-param.c b/gdb/guile/scm-param.c index c229d46..508bcb9 100644 --- a/gdb/guile/scm-param.c +++ b/gdb/guile/scm-param.c @@ -1066,6 +1066,7 @@ gdbscm_parameter_value (SCM self) const char *arg; char *newarg; int found = -1; + struct gdb_exception except = exception_none; name = gdbscm_scm_to_host_string (self, NULL, &except_scm); if (name == NULL) @@ -1075,8 +1076,9 @@ gdbscm_parameter_value (SCM self) { found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c index 0bce7d1..99ef928 100644 --- a/gdb/guile/scm-symbol.c +++ b/gdb/guile/scm-symbol.c @@ -578,6 +578,7 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest) struct field_of_this_result is_a_field_of_this; struct symbol *symbol = NULL; struct cleanup *cleanups; + struct gdb_exception except = exception_none; gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#Oi", name_scm, &name, rest, @@ -618,8 +619,9 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest) { symbol = lookup_symbol (name, block, domain, &is_a_field_of_this); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH @@ -645,6 +647,7 @@ gdbscm_lookup_global_symbol (SCM name_scm, SCM rest) int domain = VAR_DOMAIN; struct symbol *symbol = NULL; struct cleanup *cleanups; + struct gdb_exception except = exception_none; gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#i", name_scm, &name, rest, @@ -656,8 +659,9 @@ gdbscm_lookup_global_symbol (SCM name_scm, SCM rest) { symbol = lookup_global_symbol (name, NULL, domain); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c index 0509a9c..b10460d 100644 --- a/gdb/guile/scm-value.c +++ b/gdb/guile/scm-value.c @@ -446,7 +446,7 @@ gdbscm_value_address (SCM self) } END_CATCH - else + if (res_val != NULL) address = vlscm_scm_from_value (res_val); do_cleanups (cleanup); @@ -1198,6 +1198,7 @@ gdbscm_value_to_lazy_string (SCM self, SCM rest) int length = -1; SCM result = SCM_BOOL_F; /* -Wall */ struct cleanup *cleanups; + struct gdb_exception except = exception_none; /* The sequencing here, as everywhere else, is important. We can't have existing cleanups when a Scheme exception is thrown. */ @@ -1221,8 +1222,9 @@ gdbscm_value_to_lazy_string (SCM self, SCM rest) do_cleanups (inner_cleanup); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH diff --git a/gdb/inf-loop.c b/gdb/inf-loop.c index 8c99752..429cd73 100644 --- a/gdb/inf-loop.c +++ b/gdb/inf-loop.c @@ -123,10 +123,9 @@ inferior_event_handler (enum inferior_event_type event_type, } CATCH (e, RETURN_MASK_ALL) { + exception_print (gdb_stderr, e); } END_CATCH - - exception_print (gdb_stderr, e); } break; diff --git a/gdb/infcall.c b/gdb/infcall.c index 187b5c7..705e377 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -383,6 +383,7 @@ get_function_name (CORE_ADDR funaddr, char *buf, int buf_size) static struct gdb_exception run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc) { + struct gdb_exception caught_error = exception_none; int saved_in_infcall = call_thread->control.in_infcall; ptid_t call_thread_ptid = call_thread->ptid; int saved_sync_execution = sync_execution; @@ -422,6 +423,11 @@ run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc) async_disable_stdin (); } } + CATCH (e, RETURN_MASK_ALL) + { + caught_error = e; + } + END_CATCH /* At this point the current thread may have changed. Refresh CALL_THREAD as it could be invalid if its thread has exited. */ @@ -434,19 +440,18 @@ run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc) If all error()s out of proceed ended up calling normal_stop (and perhaps they should; it already does in the special case of error out of resume()), then we wouldn't need this. */ - CATCH (e, RETURN_MASK_ALL) + if (caught_error.reason < 0) { if (call_thread != NULL) breakpoint_auto_delete (call_thread->control.stop_bpstat); } - END_CATCH if (call_thread != NULL) call_thread->control.in_infcall = saved_in_infcall; sync_execution = saved_sync_execution; - return e; + return caught_error; } /* A cleanup function that calls delete_std_terminate_breakpoint. */ diff --git a/gdb/infrun.c b/gdb/infrun.c index 04af8a1..b6a90dd 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -5941,8 +5941,6 @@ insert_exception_resume_breakpoint (struct thread_info *tp, struct frame_info *frame, struct symbol *sym) { - - /* We want to ignore errors here. */ TRY { struct symbol *vsym; @@ -5974,6 +5972,7 @@ insert_exception_resume_breakpoint (struct thread_info *tp, } CATCH (e, RETURN_MASK_ERROR) { + /* We want to ignore errors here. */ } END_CATCH } diff --git a/gdb/main.c b/gdb/main.c index c56d263..ceca807 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -364,7 +364,6 @@ static int catch_command_errors (catch_command_errors_ftype *command, char *arg, int from_tty) { - TRY { int was_sync = sync_execution; @@ -375,10 +374,11 @@ catch_command_errors (catch_command_errors_ftype *command, } CATCH (e, RETURN_MASK_ALL) { + return handle_command_errors (e); } END_CATCH - return handle_command_errors (e); + return 1; } /* Type of the command callback passed to catch_command_errors_const. */ @@ -391,7 +391,6 @@ static int catch_command_errors_const (catch_command_errors_const_ftype *command, const char *arg, int from_tty) { - TRY { int was_sync = sync_execution; @@ -402,10 +401,11 @@ catch_command_errors_const (catch_command_errors_const_ftype *command, } CATCH (e, RETURN_MASK_ALL) { + return handle_command_errors (e); } END_CATCH - return handle_command_errors (e); + return 1; } /* Type of this option. */ diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c index d45cede..1b863eb 100644 --- a/gdb/mi/mi-cmd-stack.c +++ b/gdb/mi/mi-cmd-stack.c @@ -537,13 +537,12 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what, if (arg->val || arg->error) { + const char *error_message = NULL; if (arg->error) - except.message = arg->error; + error_message = arg->error; else { - /* TRY_CATCH has two statements, wrap it in a block. */ - TRY { struct value_print_options opts; @@ -555,12 +554,13 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what, } CATCH (except, RETURN_MASK_ERROR) { + error_message = except.message; } END_CATCH } - if (except.message) + if (error_message != NULL) fprintf_filtered (stb, _(""), - except.message); + error_message); ui_out_field_stream (uiout, "value", stb); } diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 980b558..acbdb55 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -2099,7 +2099,7 @@ mi_execute_command (const char *cmd, int from_tty) } END_CATCH - else + if (command != NULL) { ptid_t previous_ptid = inferior_ptid; diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 2eefed3..dcf1d5a 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -441,6 +441,7 @@ bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure) { char *exp; gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self; + struct gdb_exception except = exception_none; BPPY_SET_REQUIRE_VALID (self_bp); @@ -463,8 +464,9 @@ bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure) { set_breakpoint_condition (self_bp->bp, exp, 0); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c index cf1642a..34e9643 100644 --- a/gdb/python/py-finishbreakpoint.c +++ b/gdb/python/py-finishbreakpoint.c @@ -218,7 +218,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs) } END_CATCH - else if (PyErr_Occurred ()) + if (PyErr_Occurred ()) return -1; thread = pid_to_thread_id (inferior_ptid); diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index fd1541b..cd6e859 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -135,15 +135,13 @@ frapy_name (PyObject *self, PyObject *args) find_frame_funname (frame, &name, &lang, NULL); } - CATCH (except, RETURN_MASK_ALL) { xfree (name); + GDB_PY_HANDLE_EXCEPTION (except); } END_CATCH - GDB_PY_HANDLE_EXCEPTION (except); - if (name) { result = PyUnicode_Decode (name, strlen (name), host_charset (), NULL); diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c index 02e6d09..0cf4dfd 100644 --- a/gdb/python/py-gdb-readline.c +++ b/gdb/python/py-gdb-readline.c @@ -42,14 +42,13 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout, { p = command_line_input (prompt, 0, "python"); } - - /* Detect user interrupt (Ctrl-C). */ - if (except.reason == RETURN_QUIT) - return NULL; - /* Handle errors by raising Python exceptions. */ CATCH (except, RETURN_MASK_ALL) { + /* Detect user interrupt (Ctrl-C). */ + if (except.reason == RETURN_QUIT) + return NULL; + /* The thread state is nulled during gdbpy_readline_wrapper, with the original value saved in the following undocumented variable (see Python's Parser/myreadline.c and diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 56b79cf..fe8a705 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -562,6 +562,7 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw) static PyObject * infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw) { + struct gdb_exception except = exception_none; Py_ssize_t buf_len; const char *buffer; CORE_ADDR addr, length; @@ -596,8 +597,9 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw) { write_memory_with_notification (addr, (gdb_byte *) buffer, length); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH @@ -710,6 +712,7 @@ get_char_buffer (PyObject *self, Py_ssize_t segment, char **ptrptr) static PyObject * infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw) { + struct gdb_exception except = exception_none; CORE_ADDR start_addr, length; static char *keywords[] = { "address", "length", "pattern", NULL }; PyObject *start_addr_obj, *length_obj; @@ -774,8 +777,9 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw) buffer, pattern_size, &found_addr); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 4ca379e..31b7e07 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -1067,12 +1067,11 @@ typy_richcompare (PyObject *self, PyObject *other, int op) } CATCH (except, RETURN_MASK_ALL) { + /* If there is a GDB exception, a comparison is not capable + (or trusted), so exit. */ + GDB_PY_HANDLE_EXCEPTION (except); } END_CATCH - - /* If there is a GDB exception, a comparison is not capable - (or trusted), so exit. */ - GDB_PY_HANDLE_EXCEPTION (except); } if (op == (result ? Py_EQ : Py_NE)) diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 1c8245b..6622d11 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -612,6 +612,7 @@ get_field_type (PyObject *field) static PyObject * valpy_getitem (PyObject *self, PyObject *key) { + struct gdb_exception except = exception_none; value_object *self_value = (value_object *) self; char *field = NULL; struct type *base_class_type = NULL, *field_type = NULL; @@ -743,8 +744,9 @@ valpy_getitem (PyObject *self, PyObject *key) result = value_to_value_object (res_val); do_cleanups (cleanup); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH @@ -1207,6 +1209,7 @@ valpy_absolute (PyObject *self) static int valpy_nonzero (PyObject *self) { + struct gdb_exception except = exception_none; value_object *self_value = (value_object *) self; struct type *type; int nonzero = 0; /* Appease GCC warning. */ @@ -1227,8 +1230,9 @@ valpy_nonzero (PyObject *self) /* All other values are True. */ nonzero = 1; } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH diff --git a/gdb/python/python.c b/gdb/python/python.c index e9bcadb..79896d4 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -564,6 +564,7 @@ gdbpy_parameter_value (enum var_types type, void *var) PyObject * gdbpy_parameter (PyObject *self, PyObject *args) { + struct gdb_exception except = exception_none; struct cmd_list_element *alias, *prefix, *cmd; const char *arg; char *newarg; @@ -578,8 +579,9 @@ gdbpy_parameter (PyObject *self, PyObject *args) { found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd); } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH @@ -717,6 +719,7 @@ gdbpy_solib_name (PyObject *self, PyObject *args) static PyObject * gdbpy_decode_line (PyObject *self, PyObject *args) { + struct gdb_exception except = exception_none; struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to appease gcc. */ struct symtab_and_line sal; @@ -733,6 +736,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args) cleanups = make_cleanup (null_cleanup, NULL); sals.sals = NULL; + TRY { if (arg) @@ -749,8 +753,9 @@ gdbpy_decode_line (PyObject *self, PyObject *args) sals.nelts = 1; } } - CATCH (except, RETURN_MASK_ALL) + CATCH (ex, RETURN_MASK_ALL) { + except = ex; } END_CATCH diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index d98472a..1cbbd3e 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -139,18 +139,15 @@ require_btrace (void) static void record_btrace_enable_warn (struct thread_info *tp) { - TRY { btrace_enable (tp, &record_btrace_conf); } CATCH (error, RETURN_MASK_ERROR) { + warning ("%s", error.message); } END_CATCH - - if (error.message != NULL) - warning ("%s", error.message); } /* Callback function to disable branch tracing for one thread. */ @@ -2237,14 +2234,10 @@ cmd_record_btrace_bts_start (char *args, int from_tty) } CATCH (exception, RETURN_MASK_ALL) { - } - END_CATCH - - if (exception.error != 0) - { record_btrace_conf.format = BTRACE_FORMAT_NONE; throw_exception (exception); } + END_CATCH } /* Alias for "target record". */ @@ -2264,14 +2257,10 @@ cmd_record_btrace_start (char *args, int from_tty) } CATCH (exception, RETURN_MASK_ALL) { + record_btrace_conf.format = BTRACE_FORMAT_NONE; + throw_exception (exception); } END_CATCH - - if (exception.error == 0) - return; - - record_btrace_conf.format = BTRACE_FORMAT_NONE; - throw_exception (exception); } /* The "set record btrace" command. */ diff --git a/gdb/remote.c b/gdb/remote.c index 3cdbe54..d664842 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -11483,12 +11483,11 @@ remote_enable_btrace (struct target_ops *self, ptid_t ptid, } CATCH (err, RETURN_MASK_ERROR) { + if (err.message != NULL) + warning ("%s", err.message); } END_CATCH - if (err.message != NULL) - warning ("%s", err.message); - return tinfo; } diff --git a/gdb/solib.c b/gdb/solib.c index 99263d2..8417f88 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -637,8 +637,9 @@ solib_read_symbols (struct so_list *so, int flags) NULL); so->objfile->addr_low = so->addr_low; free_section_addr_info (sap); - } + so->symbols_loaded = 1; + } CATCH (e, RETURN_MASK_ERROR) { exception_fprintf (gdb_stderr, e, _("Error while reading shared" @@ -647,8 +648,6 @@ solib_read_symbols (struct so_list *so, int flags) } END_CATCH - else - so->symbols_loaded = 1; return 1; } @@ -1325,6 +1324,7 @@ reload_shared_libraries_1 (int from_tty) && (!was_loaded || filename_cmp (found_pathname, so->so_name) != 0)) { + int got_error = 0; TRY { @@ -1336,11 +1336,13 @@ reload_shared_libraries_1 (int from_tty) exception_fprintf (gdb_stderr, e, _("Error while mapping " "shared library sections:\n")); + got_error = 1; } END_CATCH - else if (auto_solib_add || was_loaded || libpthread_solib_p (so)) - solib_read_symbols (so, flags); + if (!got_error + && (auto_solib_add || was_loaded || libpthread_solib_p (so))) + solib_read_symbols (so, flags); } } diff --git a/gdb/stack.c b/gdb/stack.c index 4cd45d4..76a2360 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -215,6 +215,7 @@ print_frame_arg (const struct frame_arg *arg) struct ui_out *uiout = current_uiout; struct cleanup *old_chain; struct ui_file *stb; + const char *error_message = NULL; stb = mem_fileopen (); old_chain = make_cleanup_ui_file_delete (stb); @@ -252,11 +253,9 @@ print_frame_arg (const struct frame_arg *arg) else { if (arg->error) - except.message = arg->error; + error_message = arg->error; else { - /* TRY_CATCH has two statements, wrap it in a block. */ - TRY { const struct language_defn *language; @@ -288,12 +287,13 @@ print_frame_arg (const struct frame_arg *arg) } CATCH (except, RETURN_MASK_ERROR) { + error_message = except.message; } END_CATCH } - if (except.message) + if (error_message != NULL) fprintf_filtered (stb, _(""), - except.message); + error_message); } ui_out_field_stream (uiout, "value", stb); @@ -314,18 +314,19 @@ read_frame_local (struct symbol *sym, struct frame_info *frame, { struct value *val = NULL; + argp->sym = sym; + argp->val = NULL; + argp->error = NULL; + TRY { - val = read_var_value (sym, frame); + argp->val = read_var_value (sym, frame); } CATCH (except, RETURN_MASK_ERROR) { + argp->error = xstrdup (except.message); } END_CATCH - - argp->error = (val == NULL) ? xstrdup (except.message) : NULL; - argp->sym = sym; - argp->val = val; } /* Read in inferior function parameter SYM at FRAME into ARGP. Caller is @@ -349,14 +350,10 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame, } CATCH (except, RETURN_MASK_ERROR) { - } - END_CATCH - - if (!val) - { val_error = alloca (strlen (except.message) + 1); strcpy (val_error, except.message); } + END_CATCH } if (SYMBOL_COMPUTED_OPS (sym) != NULL @@ -374,21 +371,16 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame, } CATCH (except, RETURN_MASK_ERROR) { + if (except.error != NO_ENTRY_VALUE_ERROR) + { + entryval_error = (char *) alloca (strlen (except.message) + 1); + strcpy (entryval_error, except.message); + } } END_CATCH - if (!entryval) - { - entryval_error = alloca (strlen (except.message) + 1); - strcpy (entryval_error, except.message); - } - - if (except.error == NO_ENTRY_VALUE_ERROR - || (entryval && value_optimized_out (entryval))) - { - entryval = NULL; - entryval_error = NULL; - } + if (entryval != NULL && value_optimized_out (entryval)) + entryval = NULL; if (print_entry_values == print_entry_values_compact || print_entry_values == print_entry_values_default) @@ -437,21 +429,21 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame, } CATCH (except, RETURN_MASK_ERROR) { + /* If the dereferenced content could not be + fetched do not display anything. */ + if (except.error == NO_ENTRY_VALUE_ERROR) + val_equal = 1; + else if (except.message != NULL) + { + entryval_error = (char *) alloca (strlen (except.message) + 1); + strcpy (entryval_error, except.message); + } } END_CATCH /* Value was not a reference; and its content matches. */ if (val == val_deref) val_equal = 1; - /* If the dereferenced content could not be fetched do not - display anything. */ - else if (except.error == NO_ENTRY_VALUE_ERROR) - val_equal = 1; - else if (except.message) - { - entryval_error = alloca (strlen (except.message) + 1); - strcpy (entryval_error, except.message); - } if (val_equal) entryval = NULL; @@ -477,20 +469,18 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame, { if (print_entry_values == print_entry_values_preferred) { + gdb_assert (val == NULL); + TRY { val = read_var_value (sym, frame); } CATCH (except, RETURN_MASK_ERROR) { - } - END_CATCH - - if (!val) - { val_error = alloca (strlen (except.message) + 1); strcpy (val_error, except.message); } + END_CATCH } if (print_entry_values == print_entry_values_only || print_entry_values == print_entry_values_both @@ -1441,6 +1431,7 @@ frame_info (char *addr_exp, int from_tty) int frame_pc_p; /* Initialize it to avoid "may be used uninitialized" warning. */ CORE_ADDR caller_pc = 0; + int caller_pc_p = 0; fi = parse_frame_specification_1 (addr_exp, "No stack.", &selected_frame_p); gdbarch = get_frame_arch (fi); @@ -1531,6 +1522,7 @@ frame_info (char *addr_exp, int from_tty) TRY { caller_pc = frame_unwind_caller_pc (fi); + caller_pc_p = 1; } CATCH (ex, RETURN_MASK_ERROR) { @@ -1549,7 +1541,7 @@ frame_info (char *addr_exp, int from_tty) } END_CATCH - else + if (caller_pc_p) fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout); printf_filtered ("\n"); @@ -2604,6 +2596,7 @@ get_frame_language (void) if (frame) { CORE_ADDR pc = 0; + int pc_p = 0; /* We determine the current frame language by looking up its associated symtab. To retrieve this symtab, we use the frame @@ -2617,6 +2610,7 @@ get_frame_language (void) TRY { pc = get_frame_address_in_block (frame); + pc_p = 1; } CATCH (ex, RETURN_MASK_ERROR) { @@ -2625,7 +2619,7 @@ get_frame_language (void) } END_CATCH - else + if (pc_p) { struct compunit_symtab *cust = find_pc_compunit_symtab (pc); diff --git a/gdb/varobj.c b/gdb/varobj.c index 1b735d3..646df0a 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -392,7 +392,6 @@ varobj_create (char *objname, { value = evaluate_expression (var->root->exp); } - CATCH (except, RETURN_MASK_ERROR) { /* Error getting the value. Try to at least get the @@ -403,14 +402,14 @@ varobj_create (char *objname, } END_CATCH - else - { - int real_type_found = 0; + if (value != NULL) + { + int real_type_found = 0; - var->type = value_actual_type (value, 0, &real_type_found); - if (real_type_found) - value = value_cast (var->type, value); - } + var->type = value_actual_type (value, 0, &real_type_found); + if (real_type_found) + value = value_cast (var->type, value); + } /* Set language info */ var->root->lang_ops = var->root->exp->language_defn->la_varobj_ops;