diff options
author | Tom Tromey <tromey@adacore.com> | 2019-04-24 06:50:01 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2019-04-25 12:59:35 -0600 |
commit | 680d7fd5fcff860a31021845389d4dfeb7b42e3c (patch) | |
tree | 0065f8d560b3148a3a3dceb5e3e34ab724cc7cba /gdb/guile/scm-cmd.c | |
parent | c6fdd8b2052baa9b7a27d4d34f109c9622b53509 (diff) | |
download | binutils-680d7fd5fcff860a31021845389d4dfeb7b42e3c.zip binutils-680d7fd5fcff860a31021845389d4dfeb7b42e3c.tar.gz binutils-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-cmd.c')
-rw-r--r-- | gdb/guile/scm-cmd.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c index 38db7f5..f2fa40e 100644 --- a/gdb/guile/scm-cmd.c +++ b/gdb/guile/scm-cmd.c @@ -758,6 +758,7 @@ gdbscm_register_command_x (SCM self) c_smob->cmd_name = gdbscm_gc_xstrdup (cmd_name); xfree (cmd_name); + gdbscm_gdb_exception exc {}; try { if (c_smob->is_prefix) @@ -778,8 +779,9 @@ gdbscm_register_command_x (SCM self) } catch (const gdb_exception &except) { - GDBSCM_HANDLE_GDB_EXCEPTION (except); + exc = unpack (except); } + GDBSCM_HANDLE_GDB_EXCEPTION (exc); /* Note: At this point the command exists in gdb. So no more errors after this point. */ |