[PATCH v3 6/7] QUIT processing w/ explicit throw for gdb_exception_forced_quit

Pedro Alves pedro@palves.net
Thu Mar 3 21:26:30 GMT 2022


On 2022-02-27 00:00, Kevin Buettner wrote:
> --- a/gdb/tui/tui-io.c
> +++ b/gdb/tui/tui-io.c
> @@ -1259,6 +1259,10 @@ tui_getc (FILE *fp)
>      {
>        return tui_getc_1 (fp);
>      }
> +  catch (const gdb_exception_forced_quit &ex)
> +    {
> +      throw;
> +    }
>    catch (const gdb_exception &ex)
>      {
>        /* Just in case, don't ever let an exception escape to readline.

This one's incorrect.  Note the comment in the context above, and also the comment
at the top of the function:

/* Get a character from the command window.  This is called from the
   readline package.  */

static int
tui_getc (FILE *fp)
{
  try
    {
      return tui_getc_1 (fp);
    }
  catch (const gdb_exception &ex)
    {
      /* Just in case, don't ever let an exception escape to readline.
	 This shouldn't ever happen, but if it does, print the
	 exception instead of just crashing GDB.  */
      exception_print (gdb_stderr, ex);

      /* If we threw an exception, it's because we recognized the
	 character.  */
      return 0;
    }
}


we really must not let a C++ exception propagate out to readline.  It will kill gdb
in configurations/architectures that don't default to -fasynchronous-unwind-tables.

As the comment says, this try/catch here is really just in case, I don't
think it is reachable.  But if we want to make it right for quits too,
just in case, then I think we instead need to swallow the exception, and call
set_quit_flag() / set sync_quit_force_run.



I'll continue auditing, and may come back to the same patches...


More information about the Gdb-patches mailing list