aboutsummaryrefslogtreecommitdiff
path: root/gdb/guile/scm-symbol.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2018-07-18 22:55:59 +0100
committerPedro Alves <palves@redhat.com>2018-07-18 22:55:59 +0100
commit557e56be2648db13cd5d9876f702ba119ee9e7fd (patch)
treea2da722f2a8bee10199ad77d940bd3f735a1866f /gdb/guile/scm-symbol.c
parent42dc7699a26be0157c438dcaeb89da38287c6d2d (diff)
downloadgdb-557e56be2648db13cd5d9876f702ba119ee9e7fd.zip
gdb-557e56be2648db13cd5d9876f702ba119ee9e7fd.tar.gz
gdb-557e56be2648db13cd5d9876f702ba119ee9e7fd.tar.bz2
Eliminate most remaining cleanups under gdb/guile/
The main complication with the Guile code is that we have two types of exceptions to consider. GDB/C++ exceptions, and Guile/SJLJ exceptions. Code that is facing the Guile interpreter must not throw GDB exceptions, instead Scheme exceptions must be thrown. Also, because Guile exceptions are SJLJ based, Guile-facing code must not use local objects with dtors, unless wrapped in a scope with a TRY/CATCH, because the dtors won't otherwise be run when a Guile exceptions is thrown. This commit adds a new gdbscm_wrap wrapper function than encapsulates a pattern I noticed in many of the functions using GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS. The wrapper is written such that you can pass either a lambda to it, or a function plus a variable number of forwarded args. I used a lambda when its body would be reasonably short, and a separate function in the larger cases. This also convers a few functions that were using GDBSCM_HANDLE_GDB_EXCEPTION to use gdbscm_wrap too because they followed a similar pattern. A few cases of make_cleanup calls are replaced with explicit xfree calls. The make_cleanup/do_cleanups calls in those cases are pointless, because do_cleanups won't be called when a Scheme exception is thrown. We also have a couple cases of Guile-facing code using RAII-type objects to manage memory, but those are incorrect, exactly because their dtor won't be called if a Guile exception is thrown. gdb/ChangeLog: 2018-07-18 Pedro Alves <palves@redhat.com> * guile/guile-internal.h: Add comment about mixing GDB and Scheme exceptions. (GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS): Delete. (gdbscm_wrap): New. * guile/scm-frame.c (gdbscm_frame_read_register): Use xfree directly instead of a cleanup. * guile/scm-math.c (vlscm_unop_gdbthrow): New, factored out from ... (vlscm_unop): ... this. Reimplement using gdbscm_wrap. (vlscm_binop_gdbthrow): New, factored out from ... (vlscm_binop): ... this. Reimplement using gdbscm_wrap. (vlscm_rich_compare): Use gdbscm_wrap. * guile/scm-symbol.c (gdbscm_lookup_symbol): Use xfree directly instead of a cleanup. (gdbscm_lookup_global_symbol): Use xfree directly instead of a cleanup. * guile/scm-type.c (gdbscm_type_field, gdbscm_type_has_field_p): Use xfree directly instead of a cleanup. * guile/scm-value.c (gdbscm_make_value, gdbscm_make_lazy_value): Adjust to use gdbscm_wrap and scoped_value_mark. (gdbscm_value_optimized_out_p): Adjust to use gdbscm_wrap. (gdbscm_value_address, gdbscm_value_dereference) (gdbscm_value_referenced_value): Adjust to use gdbscm_wrap and scoped_value_mark. (gdbscm_value_dynamic_type): Use scoped_value_mark. (vlscm_do_cast, gdbscm_value_field): Adjust to use gdbscm_wrap and scoped_value_mark. (gdbscm_value_subscript, gdbscm_value_call): Adjust to use gdbscm_wrap and scoped_value_mark. (gdbscm_value_to_string): Use xfree directly instead of a cleanup. Move 'buffer' unique_ptr to TRY scope. (gdbscm_value_to_lazy_string): Use xfree directly instead of a cleanup. Move 'buffer' unique_ptr to TRY scope. Use scoped_value_mark. (gdbscm_value_fetch_lazy_x): Use gdbscm_wrap. (gdbscm_parse_and_eval): Adjust to use gdbscm_wrap and scoped_value_mark. (gdbscm_history_ref, gdbscm_history_append_x): Adjust to use gdbscm_wrap.
Diffstat (limited to 'gdb/guile/scm-symbol.c')
-rw-r--r--gdb/guile/scm-symbol.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c
index 8802706..8495ca5 100644
--- a/gdb/guile/scm-symbol.c
+++ b/gdb/guile/scm-symbol.c
@@ -582,16 +582,12 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
int block_arg_pos = -1, domain_arg_pos = -1;
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,
&block_arg_pos, &block_scm,
&domain_arg_pos, &domain);
- cleanups = make_cleanup (xfree, name);
-
if (block_arg_pos >= 0)
{
SCM except_scm;
@@ -600,7 +596,7 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
&except_scm);
if (block == NULL)
{
- do_cleanups (cleanups);
+ xfree (name);
gdbscm_throw (except_scm);
}
}
@@ -615,11 +611,13 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
}
CATCH (except, RETURN_MASK_ALL)
{
- GDBSCM_HANDLE_GDB_EXCEPTION_WITH_CLEANUPS (except, cleanups);
+ xfree (name);
+ GDBSCM_HANDLE_GDB_EXCEPTION (except);
}
END_CATCH
}
+ struct gdb_exception except = exception_none;
TRY
{
symbol = lookup_symbol (name, block, (domain_enum) domain,
@@ -631,7 +629,7 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
}
END_CATCH
- do_cleanups (cleanups);
+ xfree (name);
GDBSCM_HANDLE_GDB_EXCEPTION (except);
if (symbol == NULL)
@@ -652,15 +650,12 @@ gdbscm_lookup_global_symbol (SCM name_scm, SCM rest)
int domain_arg_pos = -1;
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,
&domain_arg_pos, &domain);
- cleanups = make_cleanup (xfree, name);
-
TRY
{
symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol;
@@ -671,7 +666,7 @@ gdbscm_lookup_global_symbol (SCM name_scm, SCM rest)
}
END_CATCH
- do_cleanups (cleanups);
+ xfree (name);
GDBSCM_HANDLE_GDB_EXCEPTION (except);
if (symbol == NULL)