binutils-gdb/gdb/unittests
Tom de Vries 3d36a6396f [gdb] Fix abort in selftest run_on_main_thread with ^C
When running selftest run_on_main_thread and pressing ^C, we can run into:
...
Running selftest run_on_main_thread.
terminate called without an active exception

Fatal signal: Aborted
...

The selftest function looks like this:
...
static void
run_tests ()
{
  std::thread thread;

  done = false;

  {
    gdb::block_signals blocker;

    thread = std::thread (set_done);
  }

  while (!done && gdb_do_one_event () >= 0)
    ;

  /* Actually the test will just hang, but we want to test
     something.  */
  SELF_CHECK (done);

  thread.join ();
}
...

The error message we see is due to the destructor of thread being called while
thread is joinable.

This is supposed to be taken care of by thread.join (), but the ^C prevents
that one from being called, while the destructor is still called.

Fix this by ensuring thread.join () is called (if indeed required) before the
destructor using SCOPE_EXIT.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29549
2022-09-12 10:05:18 +02:00
..
basic_string_view
optional
array-view-selftests.c
child-path-selftests.c
cli-utils-selftests.c
command-def-selftests.c
common-utils-selftests.c
copy_bitwise-selftests.c
enum-flags-selftests.c
environ-selftests.c
filtered_iterator-selftests.c
format_pieces-selftests.c
function-view-selftests.c Introduce gdb::make_function_view 2022-08-05 16:12:56 +02:00
gdb_tilde_expand-selftests.c
gmp-utils-selftests.c
intrusive_list-selftests.c
lookup_name_info-selftests.c
main-thread-selftests.c [gdb] Fix abort in selftest run_on_main_thread with ^C 2022-09-12 10:05:18 +02:00
memory-map-selftests.c
memrange-selftests.c
mkdir-recursive-selftests.c
observable-selftests.c
offset-type-selftests.c
optional-selftests.c
packed-selftests.c
parallel-for-selftests.c [gdb] Add unit test for gdb::sequential_for_each 2022-08-05 16:12:56 +02:00
parse-connection-spec-selftests.c
path-join-selftests.c
ptid-selftests.c
rsp-low-selftests.c
scoped_fd-selftests.c
scoped_ignore_signal-selftests.c
scoped_mmap-selftests.c
scoped_restore-selftests.c
search-memory-selftests.c
string_view-selftests.c
style-selftests.c
tracepoint-selftests.c
tui-selftests.c
ui-file-selftests.c
unique_xmalloc_ptr_char.c
unpack-selftests.c
utils-selftests.c
vec-utils-selftests.c
xml-utils-selftests.c