aboutsummaryrefslogtreecommitdiff
path: root/gdb/guile/scm-symbol.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2019-04-24 06:50:01 -0600
committerTom Tromey <tromey@adacore.com>2019-04-25 12:59:35 -0600
commit680d7fd5fcff860a31021845389d4dfeb7b42e3c (patch)
tree0065f8d560b3148a3a3dceb5e3e34ab724cc7cba /gdb/guile/scm-symbol.c
parentc6fdd8b2052baa9b7a27d4d34f109c9622b53509 (diff)
downloadgdb-680d7fd5fcff860a31021845389d4dfeb7b42e3c.zip
gdb-680d7fd5fcff860a31021845389d4dfeb7b42e3c.tar.gz
gdb-680d7fd5fcff860a31021845389d4dfeb7b42e3c.tar.bz2
Avoid undefined behavior in Guile exception handling
The Guile code will longjmp (via scm_throw) when an object requiring destruction is on the stack. This is undefined behavior. This changes this code to run any destructors in inner scopes, and to pass a POD to gdbscm_throw_gdb_exception. gdb/ChangeLog 2019-04-25 Tom Tromey <tromey@adacore.com> * guile/scm-exception.c (gdbscm_scm_from_gdb_exception) (gdbscm_throw_gdb_exception): Take a gdbscm_gdb_exception. * guile/scm-block.c, guile/scm-breakpoint.c, guile/scm-cmd.c, guile/scm-disasm.c, guile/scm-frame.c, guile/scm-lazy-string.c, guile/scm-math.c, guile/scm-param.c, guile/scm-ports.c, guile/scm-symbol.c, guile/scm-symtab.c, guile/scm-type.c, guile/scm-value.c: Use unpack. * guile/guile-internal.h (gdbscm_scm_from_gdb_exception): Take a gdbscm_gdb_exception. (gdbscm_throw_gdb_exception): Likewise. (struct gdbscm_gdb_exception): New. (unpack): New function. (gdbscm_wrap): Use unpack.
Diffstat (limited to 'gdb/guile/scm-symbol.c')
-rw-r--r--gdb/guile/scm-symbol.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c
index ab39123..7b44b56 100644
--- a/gdb/guile/scm-symbol.c
+++ b/gdb/guile/scm-symbol.c
@@ -486,15 +486,17 @@ gdbscm_symbol_needs_frame_p (SCM self)
struct symbol *symbol = s_smob->symbol;
int result = 0;
+ gdbscm_gdb_exception exc {};
try
{
result = symbol_read_needs_frame (symbol);
}
catch (const gdb_exception &except)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
return scm_from_bool (result);
}
@@ -538,6 +540,7 @@ gdbscm_symbol_value (SCM self, SCM rest)
_("cannot get the value of a typedef"));
}
+ gdbscm_gdb_exception exc {};
try
{
if (f_smob != NULL)
@@ -558,9 +561,10 @@ gdbscm_symbol_value (SCM self, SCM rest)
}
catch (const gdb_exception &except)
{
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ exc = unpack (except);
}
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
return vlscm_scm_from_value (value);
}
@@ -602,6 +606,7 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
{
struct frame_info *selected_frame;
+ gdbscm_gdb_exception exc {};
try
{
selected_frame = get_selected_frame (_("no frame selected"));
@@ -610,11 +615,12 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
catch (const gdb_exception &ex)
{
xfree (name);
- GDBSCM_HANDLE_GDB_EXCEPTION (ex);
+ exc = unpack (ex);
}
+ GDBSCM_HANDLE_GDB_EXCEPTION (exc);
}
- struct gdb_exception except;
+ gdbscm_gdb_exception except {};
try
{
symbol = lookup_symbol (name, block, (domain_enum) domain,
@@ -622,7 +628,7 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
}
catch (const gdb_exception &ex)
{
- except = ex;
+ except = unpack (ex);
}
xfree (name);
@@ -646,7 +652,7 @@ gdbscm_lookup_global_symbol (SCM name_scm, SCM rest)
int domain_arg_pos = -1;
int domain = VAR_DOMAIN;
struct symbol *symbol = NULL;
- struct gdb_exception except;
+ gdbscm_gdb_exception except {};
gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#i",
name_scm, &name, rest,
@@ -658,7 +664,7 @@ gdbscm_lookup_global_symbol (SCM name_scm, SCM rest)
}
catch (const gdb_exception &ex)
{
- except = ex;
+ except = unpack (ex);
}
xfree (name);