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.
This commit is contained in:
Tom Tromey
2019-04-24 06:50:01 -06:00
parent c6fdd8b205
commit 680d7fd5fc
16 changed files with 235 additions and 82 deletions

View File

@ -680,6 +680,7 @@ gdbscm_lookup_block (SCM pc_scm)
gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, NULL, "U", pc_scm, &pc);
gdbscm_gdb_exception exc {};
try
{
cust = find_pc_compunit_symtab (pc);
@ -689,9 +690,10 @@ gdbscm_lookup_block (SCM pc_scm)
}
catch (const gdb_exception &except)
{
GDBSCM_HANDLE_GDB_EXCEPTION (except);
exc = unpack (except);
}
GDBSCM_HANDLE_GDB_EXCEPTION (exc);
if (cust == NULL || COMPUNIT_OBJFILE (cust) == NULL)
{
gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, pc_scm,