aboutsummaryrefslogtreecommitdiff
path: root/gdb/breakpoint.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2015-03-07 15:14:14 +0000
committerPedro Alves <palves@redhat.com>2015-03-07 15:14:14 +0000
commit492d29ea1c9a8b2c7d5193908119a4e27c045687 (patch)
treeea592a514ec482e6c57020670e9bc447f827e298 /gdb/breakpoint.c
parentece957c859c00fbea7152a2275674d7061dc468a (diff)
downloadgdb-492d29ea1c9a8b2c7d5193908119a4e27c045687.zip
gdb-492d29ea1c9a8b2c7d5193908119a4e27c045687.tar.gz
gdb-492d29ea1c9a8b2c7d5193908119a4e27c045687.tar.bz2
Split TRY_CATCH into TRY + CATCH
This patch splits the TRY_CATCH macro into three, so that we go from this: ~~~ volatile gdb_exception ex; TRY_CATCH (ex, RETURN_MASK_ERROR) { } if (ex.reason < 0) { } ~~~ to this: ~~~ TRY { } CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH ~~~ Thus, we'll be getting rid of the local volatile exception object, and declaring the caught exception in the catch block. This allows reimplementing TRY/CATCH in terms of C++ exceptions when building in C++ mode, while still allowing to build GDB in C mode (using setjmp/longjmp), as a transition step. TBC, after this patch, is it _not_ valid to have code between the TRY and the CATCH blocks, like: TRY { } // some code here. CATCH (ex, RETURN_MASK_ERROR) { } END_CATCH Just like it isn't valid to do that with C++'s native try/catch. By switching to creating the exception object inside the CATCH block scope, we can get rid of all the explicitly allocated volatile exception objects all over the tree, and map the CATCH block more directly to C++'s catch blocks. The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was done with a script, rerun from scratch at every rebase, no manual editing involved. After the mechanical conversion, a few places needed manual intervention, to fix preexisting cases where we were using the exception object outside of the TRY_CATCH block, and cases where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH after this patch]. The result was folded into this patch so that GDB still builds at each incremental step. END_CATCH is necessary for two reasons: First, because we name the exception object in the CATCH block, which requires creating a scope, which in turn must be closed somewhere. Declaring the exception variable in the initializer field of a for block, like: #define CATCH(EXCEPTION, mask) \ for (struct gdb_exception EXCEPTION; \ exceptions_state_mc_catch (&EXCEPTION, MASK); \ EXCEPTION = exception_none) would avoid needing END_CATCH, but alas, in C mode, we build with C90, which doesn't allow mixed declarations and code. Second, because when TRY/CATCH are wired to real C++ try/catch, as long as we need to handle cleanup chains, even if there's no CATCH block that wants to catch the exception, we need for stop at every frame in the unwind chain and run cleanups, then rethrow. That will be done in END_CATCH. After we require C++, we'll still need TRY/CATCH/END_CATCH until cleanups are completely phased out -- TRY/CATCH in C++ mode will save/restore the current cleanup chain, like in C mode, and END_CATCH catches otherwise uncaugh exceptions, runs cleanups and rethrows, so that C++ cleanups and exceptions can coexist. IMO, this still makes the TRY/CATCH code look a bit more like a newcomer would expect, so IMO worth it even if we weren't considering C++. gdb/ChangeLog. 2015-03-07 Pedro Alves <palves@redhat.com> * common/common-exceptions.c (struct catcher) <exception>: No longer a pointer to volatile exception. Now an exception value. <mask>: Delete field. (exceptions_state_mc_init): Remove all parameters. Adjust. (exceptions_state_mc): No longer pop the catcher here. (exceptions_state_mc_catch): New function. (throw_exception): Adjust. * common/common-exceptions.h (exceptions_state_mc_init): Remove all parameters. (exceptions_state_mc_catch): Declare. (TRY_CATCH): Rename to ... (TRY): ... this. Remove EXCEPTION and MASK parameters. (CATCH, END_CATCH): New. All callers adjusted. gdb/gdbserver/ChangeLog: 2015-03-07 Pedro Alves <palves@redhat.com> Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH instead.
Diffstat (limited to 'gdb/breakpoint.c')
-rw-r--r--gdb/breakpoint.c116
1 files changed, 60 insertions, 56 deletions
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index d85f271..0e59638 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2221,25 +2221,25 @@ static struct agent_expr *
parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
{
struct agent_expr *aexpr = NULL;
- volatile struct gdb_exception ex;
if (!cond)
return NULL;
/* We don't want to stop processing, so catch any errors
that may show up. */
- TRY_CATCH (ex, RETURN_MASK_ERROR)
+ TRY
{
aexpr = gen_eval_for_expr (scope, cond);
}
- if (ex.reason < 0)
+ CATCH (ex, RETURN_MASK_ERROR)
{
/* If we got here, it means the condition 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 conditions. */
return NULL;
}
+ END_CATCH
/* We have a valid agent expression. */
return aexpr;
@@ -2361,7 +2361,6 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
struct cleanup *old_cleanups = 0;
struct expression *expr, **argvec;
struct agent_expr *aexpr = NULL;
- volatile struct gdb_exception ex;
const char *cmdrest;
const char *format_start, *format_end;
struct format_piece *fpieces;
@@ -2420,22 +2419,22 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
/* We don't want to stop processing, so catch any errors
that may show up. */
- TRY_CATCH (ex, RETURN_MASK_ERROR)
+ TRY
{
aexpr = gen_printf (scope, gdbarch, 0, 0,
format_start, format_end - format_start,
fpieces, nargs, argvec);
}
-
- do_cleanups (old_cleanups);
-
- if (ex.reason < 0)
+ 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;
@@ -2572,7 +2571,6 @@ insert_bp_location (struct bp_location *bl,
{
enum errors bp_err = GDB_NO_ERROR;
const char *bp_err_message = NULL;
- volatile struct gdb_exception e;
if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update))
return 0;
@@ -2675,7 +2673,7 @@ insert_bp_location (struct bp_location *bl,
|| !(section_is_overlay (bl->section)))
{
/* No overlay handling: just set the breakpoint. */
- TRY_CATCH (e, RETURN_MASK_ALL)
+ TRY
{
int val;
@@ -2683,11 +2681,12 @@ insert_bp_location (struct bp_location *bl,
if (val)
bp_err = GENERIC_ERROR;
}
- if (e.reason < 0)
+ CATCH (e, RETURN_MASK_ALL)
{
bp_err = e.error;
bp_err_message = e.message;
}
+ END_CATCH
}
else
{
@@ -2710,7 +2709,7 @@ insert_bp_location (struct bp_location *bl,
bl->overlay_target_info.reqstd_address = addr;
/* No overlay handling: just set the breakpoint. */
- TRY_CATCH (e, RETURN_MASK_ALL)
+ TRY
{
int val;
@@ -2719,11 +2718,12 @@ insert_bp_location (struct bp_location *bl,
if (val)
bp_err = GENERIC_ERROR;
}
- if (e.reason < 0)
+ CATCH (e, RETURN_MASK_ALL)
{
bp_err = e.error;
bp_err_message = e.message;
}
+ END_CATCH
if (bp_err != GDB_NO_ERROR)
fprintf_unfiltered (tmp_error_stream,
@@ -2736,7 +2736,7 @@ insert_bp_location (struct bp_location *bl,
if (section_is_mapped (bl->section))
{
/* Yes. This overlay section is mapped into memory. */
- TRY_CATCH (e, RETURN_MASK_ALL)
+ TRY
{
int val;
@@ -2744,11 +2744,12 @@ insert_bp_location (struct bp_location *bl,
if (val)
bp_err = GENERIC_ERROR;
}
- if (e.reason < 0)
+ CATCH (e, RETURN_MASK_ALL)
{
bp_err = e.error;
bp_err_message = e.message;
}
+ END_CATCH
}
else
{
@@ -10004,7 +10005,6 @@ create_breakpoint (struct gdbarch *gdbarch,
int from_tty, int enabled, int internal,
unsigned flags)
{
- volatile struct gdb_exception e;
char *copy_arg = NULL;
char *addr_start = arg;
struct linespec_result canonical;
@@ -10018,24 +10018,17 @@ create_breakpoint (struct gdbarch *gdbarch,
init_linespec_result (&canonical);
- TRY_CATCH (e, RETURN_MASK_ALL)
+ TRY
{
ops->create_sals_from_address (&arg, &canonical, type_wanted,
addr_start, &copy_arg);
}
-
- /* 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. */
@@ -10066,14 +10059,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);
@@ -11343,7 +11336,6 @@ static void
watch_command_1 (const char *arg, int accessflag, int from_tty,
int just_location, int internal)
{
- volatile struct gdb_exception e;
struct breakpoint *b, *scope_breakpoint = NULL;
struct expression *exp;
const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL;
@@ -11655,17 +11647,18 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
if (!just_location)
value_free_to_mark (mark);
- TRY_CATCH (e, RETURN_MASK_ALL)
+ TRY
{
/* Finally update the new watchpoint. This creates the locations
that should be inserted. */
update_watchpoint (w, 1);
}
- if (e.reason < 0)
+ CATCH (e, RETURN_MASK_ALL)
{
delete_breakpoint (b);
throw_exception (e);
}
+ END_CATCH
install_breakpoint (internal, b, 1);
do_cleanups (back_to);
@@ -13011,10 +13004,15 @@ breakpoint_retire_moribund (void)
static void
update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
{
- volatile struct gdb_exception e;
- TRY_CATCH (e, RETURN_MASK_ERROR)
- update_global_location_list (insert_mode);
+ TRY
+ {
+ update_global_location_list (insert_mode);
+ }
+ CATCH (e, RETURN_MASK_ERROR)
+ {
+ }
+ END_CATCH
}
/* Clear BKP from a BPS. */
@@ -14485,22 +14483,22 @@ update_breakpoint_locations (struct breakpoint *b,
if (b->cond_string != NULL)
{
const char *s;
- volatile struct gdb_exception e;
s = b->cond_string;
- TRY_CATCH (e, RETURN_MASK_ERROR)
+ TRY
{
new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc,
block_for_pc (sals.sals[i].pc),
0);
}
- if (e.reason < 0)
+ CATCH (e, RETURN_MASK_ERROR)
{
warning (_("failed to reevaluate condition "
"for breakpoint %d: %s"),
b->number, e.message);
new_loc->enabled = 0;
}
+ END_CATCH
}
if (sals_end.nelts)
@@ -14564,18 +14562,21 @@ addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
{
char *s;
struct symtabs_and_lines sals = {0};
- volatile struct gdb_exception e;
+ struct gdb_exception exception = exception_none;
gdb_assert (b->ops != NULL);
s = addr_string;
- TRY_CATCH (e, RETURN_MASK_ERROR)
+ TRY
{
b->ops->decode_linespec (b, &s, &sals);
}
- if (e.reason < 0)
+ 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
@@ -14602,8 +14603,9 @@ addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found)
throw_exception (e);
}
}
+ END_CATCH
- if (e.reason == 0 || e.error != NOT_FOUND_ERROR)
+ if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
{
int i;
@@ -15094,9 +15096,8 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
{
/* Initialize it just to avoid a GCC false warning. */
enum enable_state orig_enable_state = 0;
- volatile struct gdb_exception e;
- TRY_CATCH (e, RETURN_MASK_ALL)
+ TRY
{
struct watchpoint *w = (struct watchpoint *) bpt;
@@ -15104,13 +15105,14 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
bpt->enable_state = bp_enabled;
update_watchpoint (w, 1 /* reparse */);
}
- if (e.reason < 0)
+ CATCH (e, RETURN_MASK_ALL)
{
bpt->enable_state = orig_enable_state;
exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
bpt->number);
return;
}
+ END_CATCH
}
bpt->enable_state = bp_enabled;
@@ -15924,19 +15926,21 @@ save_breakpoints (char *filename, int from_tty,
if (tp->type != bp_dprintf && tp->commands)
{
- volatile struct gdb_exception ex;
fprintf_unfiltered (fp, " commands\n");
ui_out_redirect (current_uiout, fp);
- TRY_CATCH (ex, RETURN_MASK_ALL)
+ TRY
{
print_command_lines (current_uiout, tp->commands->commands, 2);
}
ui_out_redirect (current_uiout, NULL);
- if (ex.reason < 0)
- throw_exception (ex);
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ throw_exception (ex);
+ }
+ END_CATCH
fprintf_unfiltered (fp, " end\n");
}