[RFC,1/5] Catch gdb_exception_quit in munmap_list::~munmap_list

Message ID 20221025111945.23886-2-tdevries@suse.de
State New
Headers
Series Catch rethrow exception slicing |

Commit Message

Tom de Vries Oct. 25, 2022, 11:19 a.m. UTC
  I tried out adding this exception slicing detection code in
munmap_list::~munmap_list () in gdb/compile/compile-object-load.c:
...
       try
         {
	   ...
         }
       catch (const gdb_exception_error &ex)
         {
           /* There's not much the user can do, so just ignore
              this.  */
         }
+      catch (const gdb_exception_quit &ex)
+        {
+          throw;
+        }
+      catch (const gdb_exception &ex)
+        {
+          gdb_assert (0);
+        }
...
and ran into:
...
gdb/compile/compile-object-load.c: In destructor ‘munmap_list::~munmap_list()’:
gdb/compile/compile-object-load.c:64:4: error: \
  throw will always call terminate() [-Werror=terminate]
    throw;
    ^~~~~
gdb/compile/compile-object-load.c:64:4: note: \
  in C++11 destructors default to noexcept
...

This raises the question of how a gdb_exception_quit should be handled in the
destructor.

Currently it's handled implicitly, and will result in std::terminate, which in
absense of a std::set_terminate should call abort, after printing the type
of the current exception, in other words gdb_exception_quit.

We have a couple of choices to handle this explicitly:
- std::terminate (no change in behaviour),
- gdb_assert (false) (also calls abort, but with more info), or
- ignore (as we do for gdb_exception_error)

It seems to me that a gdb_exception_quit should not cause an abort, so handle
explicitly by ignoring:
...
-      catch (const gdb_exception_error &ex)
+      catch (const gdb_exception &ex)
...

Tested on x86_64-linux (though I don't have a setup with libcc1).
---
 gdb/compile/compile-object-load.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index 4c94ec53899..ca58775880b 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -54,7 +54,7 @@  munmap_list::~munmap_list ()
 	{
 	  gdbarch_infcall_munmap (target_gdbarch (), item.addr, item.size);
 	}
-      catch (const gdb_exception_error &ex)
+      catch (const gdb_exception &ex)
 	{
 	  /* There's not much the user can do, so just ignore
 	     this.  */