From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id A057B3858D1E; Mon, 11 Jul 2022 18:50:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A057B3858D1E Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Always emit =thread-exited notifications, even if silent X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: 5d067f3d4193de1b3809a5480f3eec9228445ab9 X-Git-Newrev: a78ef8757418105c35685c5d82b9fdf79459321b Message-Id: <20220711185056.A057B3858D1E@sourceware.org> Date: Mon, 11 Jul 2022 18:50:56 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jul 2022 18:50:56 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da78ef8757418= 105c35685c5d82b9fdf79459321b commit a78ef8757418105c35685c5d82b9fdf79459321b Author: Pedro Alves Date: Wed Jun 22 18:10:00 2022 +0100 Always emit =3Dthread-exited notifications, even if silent =20 [Note: the testcased added by this commit depends on https://sourceware.org/pipermail/gdb-patches/2022-June/190259.html, otherwise GDB just crashes when detaching the core] =20 Currently, in MI, =3Dthread-created are always emitted, like: =20 =3Dthread-group-started,id=3D"i1",pid=3D"195680" =3Dthread-created,id=3D"1",group-id=3D"i1" ... =20 but on teardown, if the target uses exit_inferior_silent, then you'll only see the inferior exit notification (thread-group-exited), no notification for threads. =20 The core target is one of the few targets that use exit_inferior_silent. Here's an example session: =20 -target-select core $corefile =3Dthread-group-started,id=3D"i1",pid=3D"195680" =3Dthread-created,id=3D"1",group-id=3D"i1" ... ^connected,frame=3D.... (gdb) -target-detach =3Dthread-group-exited,id=3D"i1" ^done (gdb) =20 This imbalance of emitting =3Dthread-created but then not =3Dthread-exi= ted seems off to me. (And, it complicates changes I want to do to centralize emitting thread exit notifications for the CLI, which is why I'm looking at this.) =20 And then, since most other targets use exit_inferior instead of exit_inferior_silent, MI is already emitting =3Dthread-exited notifications when tearing down an inferior, for most targets. =20 This commit makes MI always emit the =3Dthread-exited notifications, even for exit_inferior_silent. =20 Afterwards, when debugging a core, MI outputs: =20 (gdb) -target-detach =3Dthread-exited,id=3D"1",group-id=3D"i1" << new line =3Dthread-group-exited,id=3D"i1" ^done (gdb) =20 Surprisingly, there's no MI testcase debugging a core file. This commit adds the first. =20 Change-Id: I5100501a46f07b6bbad3e04d120c2562a51c93a4 Diff: --- gdb/mi/mi-interp.c | 3 -- gdb/testsuite/gdb.mi/mi-corefile.c | 27 ++++++++++++++ gdb/testsuite/gdb.mi/mi-corefile.exp | 69 ++++++++++++++++++++++++++++++++= ++++ 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index 8d6e0334a90..937a3d9d6f5 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -358,9 +358,6 @@ mi_new_thread (struct thread_info *t) static void mi_thread_exit (struct thread_info *t, int silent) { - if (silent) - return; - SWITCH_THRU_ALL_UIS () { struct mi_interp *mi =3D as_mi_interp (top_level_interpreter ()); diff --git a/gdb/testsuite/gdb.mi/mi-corefile.c b/gdb/testsuite/gdb.mi/mi-c= orefile.c new file mode 100644 index 00000000000..58e6f35a61a --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-corefile.c @@ -0,0 +1,27 @@ +/* Copyright 2022 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . = */ + +/* Simple little program that just generates a core dump. */ + +#include + +int +main (int argc, char **argv) +{ + abort (); + return 0; +} diff --git a/gdb/testsuite/gdb.mi/mi-corefile.exp b/gdb/testsuite/gdb.mi/mi= -corefile.exp new file mode 100644 index 00000000000..d8ca6b3b34f --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-corefile.exp @@ -0,0 +1,69 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test loading and unloading a core file. + +load_lib mi-support.exp +set MIFLAGS "-i=3Dmi" + +if ![isnative] then { + return +} + +standard_testfile + +if {[build_executable $testfile.exp $testfile $srcfile debug] =3D=3D -1} { + untested "failed to compile" + return -1 +} + +set corefile [core_find $binfile {}] +if {$corefile =3D=3D ""} { + return 0 +} + +if [mi_gdb_start] { + return +} + +# Test loading and unloading a core file. + +proc test_core_file {} { + mi_delete_breakpoints + mi_gdb_reinitialize_dir $::srcdir/$::subdir + mi_gdb_load ${::binfile} + + # This also tests that MI emits paired =3Dthread-created and + # =3Dthread-exited notifications when loading and unloading the + # core. At some point, GDB emitted =3Dthread-created notifications, + # but not =3Dthread-exited notifications. + + mi_gdb_test \ + "-target-select core $::corefile" \ + [multi_line \ + "=3Dthread-group-started,id=3D\"i1\",.*" \ + "=3Dthread-created,id=3D\"1\",group-id=3D\"i1\"" \ + ".*\\^connected,frame=3D.*"] \ + "-target-select core \$corefile" + + mi_gdb_test \ + "-target-detach" \ + [multi_line \ + "=3Dthread-exited,id=3D\"1\",group-id=3D\"i1\"" \ + "=3Dthread-group-exited,id=3D\"i1\"" \ + ".*\\^done"] +} + +test_core_file