From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3520 invoked by alias); 12 Nov 2012 18:27:34 -0000 Received: (qmail 3504 invoked by uid 22791); 12 Nov 2012 18:27:33 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_TG X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 12 Nov 2012 18:27:25 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qACIRNGr010411 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 12 Nov 2012 13:27:25 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qACI53r0031930 for ; Mon, 12 Nov 2012 13:05:03 -0500 Message-ID: <50A13A4E.3020000@redhat.com> Date: Mon, 12 Nov 2012 18:27:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121029 Thunderbird/16.0.2 MIME-Version: 1.0 To: "gdb@sourceware.org" Subject: Time to expand "Program received signal" ? Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2012-11/txt/msg00010.txt.bz2 Part of the confusion on can be attributed to the fact that: Program received signal SIGUSR1, User defined signal 1. Program received signal SIGUSR1, User defined signal 1. Program received signal SIGUSR1, User defined signal 1. Program received signal SIGUSR1, User defined signal 1. 33 tgkill (getpid (), gettid (), SIGUSR1); /* step-2 */ doesn't give any clue that these were different threads getting the SIGUSR1 signal. I had chickened out before in changing this output, but today I've decided to try raising the issue. :-) So today, for signals, we have: Program received signal SIGUSR1, User defined signal 1. and for "interrupt" (GDB_SIGNAL_0), we get: [Thread 0x7ffff7fd0700 (LWP 15209)] #2 stopped. A patch like the below would result in: Thread 2 [Thread 0x7ffff7fcf700 (LWP 12023) "sigstep-threads"] received signal SIGUSR1, User defined signal 1. Thread 1 [Thread 0x7ffff7fd0740 (LWP 12019) "sigstep-threads"] received signal SIGUSR1, User defined signal 1. And (for "interrupt"): Thread 2 [Thread 0x7ffff7fd0700 (LWP 12077) "threads"] stopped. "Thread" appears twice on this target, but on others it wouldn't. The second "Thread " is responsability of target_pid_to_str (the whole "Thread 0x7ffff7fcf700 (LWP 12023)" in fact), while the first is hard coded. E.g., with some targets, we might see: Thread 1 [process PID] received signal SIGUSR1, User defined signal 1. or: Thread 1 [
] received signal SIGUSR1, User defined signal 1. and if there's target thread extra info, we could see: Thread 1 [Thread 0x7ffff7fd0740 (LWP 12019) "sigstep-threads" (Exiting)] received signal SIGUSR1, User defined signal 1. Roughly, in printf-style, that's: printf (Thread %d [%s "%s" (%s)], gdb-thread-number, target_pid_to_str(), target_extra_thread_info(), target_thread_name()) where the stuff in []'s is exactly the same format as we have in "info threads", e.g.: ... 2 Thread 0x7ffff7fd0700 (LWP 15209) "threads" 0x0000003de92ba6cd in nanosleep () from /lib64/libc.so.6 ... An option to avoid the duplicate "Thread" would be to stick with the current "stopped" output. To recap, for "interrupt" (GDB_SIGNAL_0), we get: [Thread 0x7ffff7fd0700 (LWP 15209)] #2 stopped. The difference is that "Thread N" is not a prefix, but instead we get #N after the target_pid_to_str, etc. Which would make for: [Thread 0x7ffff7fcf700 (LWP 12023) "sigstep-threads"] #2 received signal SIGUSR1, User defined signal 1. [Thread 0x7ffff7fd0740 (LWP 12019) "sigstep-threads"] #1 received signal SIGUSR1, User defined signal 1. Not sure whether people find the #2/#1 confusing/not obvious. Also not sure people find that including thread number, target string, thread name and target extra thread info, too much and too long. OTOH, I like having all the info available (best while looking at logs, where it is too late to do "info threads"). I could think of a lot of alternative variations, with varying amounts of info, and with varying placements of the info on the line... If being verbose with all the thread info is good, then it might be a good idea to expand the "Switching to ..." output to match (and others that might make sense). I count 65 instances of "Program received" in the test suite, and surprisingly, only one relevant in the manual in an example for $_siginfo. diff --git a/gdb/infrun.c b/gdb/infrun.c index 4efc2af..6c8164e 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -5877,32 +5877,57 @@ print_signal_received_reason (enum gdb_signal siggnal) annotate_signal (); - if (siggnal == GDB_SIGNAL_0 && !ui_out_is_mi_like_p (uiout)) + if (!ui_out_is_mi_like_p (uiout)) { struct thread_info *t = inferior_thread (); + char *extra_info, *name, *target_id; + struct cleanup *str_cleanup; + char *contents; + + ui_out_text (uiout, "\nThread "); + ui_out_field_fmt (uiout, "thread-id", "%d [", t->num); + + target_id = target_pid_to_str (t->ptid); + extra_info = target_extra_thread_info (t); + name = t->name ? t->name : target_thread_name (t); + + if (extra_info != NULL && name != NULL) + contents = xstrprintf ("%s \"%s\" (%s)", target_id, + name, extra_info); + else if (extra_info != NULL) + contents = xstrprintf ("%s (%s)", target_id, extra_info); + else if (name) + contents = xstrprintf ("%s \"%s\"", target_id, name); + else + contents = xstrdup (target_id); + str_cleanup = make_cleanup (xfree, contents); + + ui_out_field_string (uiout, "thread-name", contents); + do_cleanups (str_cleanup); + + if (siggnal == GDB_SIGNAL_0) + { + ui_out_text (uiout, "] stopped.\n"); + return; + } - ui_out_text (uiout, "\n["); - ui_out_field_string (uiout, "thread-name", - target_pid_to_str (t->ptid)); - ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num); - ui_out_text (uiout, " stopped"); + ui_out_text (uiout, "] received signal "); } else - { - ui_out_text (uiout, "\nProgram received signal "); - annotate_signal_name (); - if (ui_out_is_mi_like_p (uiout)) - ui_out_field_string + ui_out_text (uiout, "Program received signal "); + + annotate_signal_name (); + if (ui_out_is_mi_like_p (uiout)) + ui_out_field_string (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED)); - ui_out_field_string (uiout, "signal-name", + ui_out_field_string (uiout, "signal-name", gdb_signal_to_name (siggnal)); - annotate_signal_name_end (); - ui_out_text (uiout, ", "); - annotate_signal_string (); - ui_out_field_string (uiout, "signal-meaning", - gdb_signal_to_string (siggnal)); - annotate_signal_string_end (); - } + annotate_signal_name_end (); + ui_out_text (uiout, ", "); + annotate_signal_string (); + ui_out_field_string (uiout, "signal-meaning", + gdb_signal_to_string (siggnal)); + annotate_signal_string_end (); ui_out_text (uiout, ".\n"); } diff --git a/gdb/testsuite/gdb.threads/sigstep-threads.exp b/gdb/testsuite/gdb.threads/sigstep-threads.exp index 484ca37..4397dc2 100644 --- a/gdb/testsuite/gdb.threads/sigstep-threads.exp +++ b/gdb/testsuite/gdb.threads/sigstep-threads.exp @@ -45,7 +45,7 @@ for {set i 0} {$i < 100} {incr i} { # Presume this step failed - as in the case of a timeout. set failed 1 gdb_test_multiple "step" $test { - -re "\r\nProgram received signal SIGUSR1, User defined signal 1.\r\n" { + -re "received signal SIGUSR1, User defined signal 1.\r\n" { exp_continue -continue_timer } -re "step-(\[012\]).*\r\n$gdb_prompt $" {