aboutsummaryrefslogtreecommitdiff
path: root/gdb/guile/scm-frame.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/guile/scm-frame.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/guile/scm-frame.c')
-rw-r--r--gdb/guile/scm-frame.c170
1 files changed, 114 insertions, 56 deletions
diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c
index a30c093..6189802 100644
--- a/gdb/guile/scm-frame.c
+++ b/gdb/guile/scm-frame.c
@@ -220,7 +220,6 @@ frscm_scm_from_frame (struct frame_info *frame, struct inferior *inferior)
SCM f_scm;
htab_t htab;
eqable_gdb_smob **slot;
- volatile struct gdb_exception except;
struct frame_id frame_id = null_frame_id;
struct gdbarch *gdbarch = NULL;
int frame_id_is_next = 0;
@@ -234,7 +233,7 @@ frscm_scm_from_frame (struct frame_info *frame, struct inferior *inferior)
if (*slot != NULL)
return (*slot)->containing_scm;
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
/* Try to get the previous frame, to determine if this is the last frame
in a corrupt stack. If so, we need to store the frame_id of the next
@@ -253,8 +252,11 @@ frscm_scm_from_frame (struct frame_info *frame, struct inferior *inferior)
}
gdbarch = get_frame_arch (frame);
}
- if (except.reason < 0)
- return gdbscm_scm_from_gdb_exception (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ return gdbscm_scm_from_gdb_exception (except);
+ }
+ END_CATCH
f_scm = frscm_make_frame_smob ();
f_smob = (frame_smob *) SCM_SMOB_DATA (f_scm);
@@ -396,15 +398,18 @@ gdbscm_frame_valid_p (SCM self)
{
frame_smob *f_smob;
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
return scm_from_bool (frame != NULL);
}
@@ -421,18 +426,23 @@ gdbscm_frame_name (SCM self)
enum language lang = language_minimal;
struct frame_info *frame = NULL;
SCM result;
- volatile struct gdb_exception except;
+ struct gdb_exception except = exception_none;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
if (frame != NULL)
find_frame_funname (frame, &name, &lang, NULL);
}
- if (except.reason < 0)
- xfree (name);
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ except = ex;
+ }
+ END_CATCH
+
+ xfree (name);
GDBSCM_HANDLE_GDB_EXCEPTION (except);
if (frame == NULL)
@@ -461,17 +471,20 @@ gdbscm_frame_type (SCM self)
frame_smob *f_smob;
enum frame_type type = NORMAL_FRAME;
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
if (frame != NULL)
type = get_frame_type (frame);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
if (frame == NULL)
{
@@ -490,15 +503,18 @@ gdbscm_frame_arch (SCM self)
{
frame_smob *f_smob;
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
if (frame == NULL)
{
@@ -517,16 +533,19 @@ gdbscm_frame_unwind_stop_reason (SCM self)
{
frame_smob *f_smob;
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
enum unwind_stop_reason stop_reason;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
if (frame == NULL)
{
@@ -548,17 +567,20 @@ gdbscm_frame_pc (SCM self)
frame_smob *f_smob;
CORE_ADDR pc = 0;
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
if (frame != NULL)
pc = get_frame_pc (frame);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
if (frame == NULL)
{
@@ -578,17 +600,20 @@ gdbscm_frame_block (SCM self)
frame_smob *f_smob;
const struct block *block = NULL, *fn_block;
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
if (frame != NULL)
block = get_frame_block (frame, NULL);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
if (frame == NULL)
{
@@ -626,17 +651,20 @@ gdbscm_frame_function (SCM self)
frame_smob *f_smob;
struct symbol *sym = NULL;
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
if (frame != NULL)
sym = find_pc_function (get_frame_address_in_block (frame));
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
if (frame == NULL)
{
@@ -660,17 +688,20 @@ gdbscm_frame_older (SCM self)
frame_smob *f_smob;
struct frame_info *prev = NULL;
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
if (frame != NULL)
prev = get_prev_frame (frame);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
if (frame == NULL)
{
@@ -694,17 +725,20 @@ gdbscm_frame_newer (SCM self)
frame_smob *f_smob;
struct frame_info *next = NULL;
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
if (frame != NULL)
next = get_next_frame (frame);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
if (frame == NULL)
{
@@ -727,17 +761,20 @@ gdbscm_frame_sal (SCM self)
frame_smob *f_smob;
struct symtab_and_line sal;
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
if (frame != NULL)
find_frame_sal (frame, &sal);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
if (frame == NULL)
{
@@ -767,15 +804,18 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
struct frame_info *frame = NULL;
struct symbol *var = NULL;
struct value *value = NULL;
- volatile struct gdb_exception except;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
if (frame == NULL)
{
@@ -797,7 +837,7 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
char *var_name;
const struct block *block = NULL;
struct cleanup *cleanup;
- volatile struct gdb_exception except;
+ struct gdb_exception except = exception_none;
if (! SCM_UNBNDP (block_scm))
{
@@ -815,14 +855,19 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
/* N.B. Between here and the call to do_cleanups, don't do anything
to cause a Scheme exception without performing the cleanup. */
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
if (block == NULL)
block = get_frame_block (frame, NULL);
var = lookup_symbol (var_name, block, VAR_DOMAIN, NULL);
}
- if (except.reason < 0)
- do_cleanups (cleanup);
+ CATCH (ex, RETURN_MASK_ALL)
+ {
+ except = ex;
+ }
+ END_CATCH
+
+ do_cleanups (cleanup);
GDBSCM_HANDLE_GDB_EXCEPTION (except);
if (var == NULL)
@@ -841,11 +886,15 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
_("gdb:symbol or string"));
}
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
value = read_var_value (var, frame);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
return vlscm_scm_from_value (value);
}
@@ -858,17 +907,20 @@ gdbscm_frame_select (SCM self)
{
frame_smob *f_smob;
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = frscm_frame_smob_to_frame (f_smob);
if (frame != NULL)
select_frame (frame);
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
if (frame == NULL)
{
@@ -886,13 +938,16 @@ static SCM
gdbscm_newest_frame (void)
{
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = get_current_frame ();
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
return frscm_scm_from_frame_unsafe (frame, current_inferior ());
}
@@ -904,13 +959,16 @@ static SCM
gdbscm_selected_frame (void)
{
struct frame_info *frame = NULL;
- volatile struct gdb_exception except;
- TRY_CATCH (except, RETURN_MASK_ALL)
+ TRY
{
frame = get_selected_frame (_("No frame is currently selected"));
}
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ CATCH (except, RETURN_MASK_ALL)
+ {
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ }
+ END_CATCH
return frscm_scm_from_frame_unsafe (frame, current_inferior ());
}