Don't throw Scheme exceptions with live std::vector objects
authorPedro Alves <palves@redhat.com>
Tue, 21 Aug 2018 15:48:30 +0000 (16:48 +0100)
committerPedro Alves <palves@redhat.com>
Tue, 21 Aug 2018 15:48:30 +0000 (16:48 +0100)
commit4895f384b47628c8c354dccbb0bfab45b8c33984
tree234161ab89a377ef079869d8663b41f4a2719202
parentae19acf3201ee0b921cde8e70e278fe123e82105
Don't throw Scheme exceptions with live std::vector objects

A complication with the Guile code is that we have two types of
exceptions to consider: GDB/C++ exceptions, and Guile/SJLJ exceptions.

Because Guile exceptions are SJLJ based, we must make sure to not have
live local variables of types with non-trivial dtors when a Guile
exception is thrown, because the dtors won't be run when a Guile
exceptions is thrown.

gdbscm_parse_function_args currently violates this:

 void
 gdbscm_parse_function_args (const char *func_name,
     int beginning_arg_pos,
     const SCM *keywords,
     const char *format, ...)
 {
 ...
   /* Keep track of malloc'd strings.  We need to free them upon error.  */
   std::vector<char *> allocated_strings;
 ...
   for (char *ptr : allocated_strings)
     xfree (ptr);
   gdbscm_throw (status); /// dtor of "allocated_strings" is not run!
 }

This commit fixes the above making using of gdbscm_wrap.

It would be nice if we had a way to make it impossible to write such
code.  PR guile/23429 has an idea for that, if someone's interested.

gdb/ChangeLog:
2018-08-21  Pedro Alves  <palves@redhat.com>

* guile/scm-utils.c (gdbscm_parse_function_args_1): New, factored
out from gdbscm_parse_function_args.
(gdbscm_parse_function_args): Rework to use gdbscm_wrap and
gdbscm_parse_function_args_1.
gdb/ChangeLog
gdb/guile/scm-utils.c
This page took 0.025262 seconds and 4 git commands to generate.