From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id B38983858D20 for ; Fri, 10 May 2024 06:25:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B38983858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B38983858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715322357; cv=none; b=L7gXfInHyf0KFX9KKaxq9HDcQwZ/5C68cQ2M274FnLb2Z1i9stWCH57ERvjKHx0tK6v5mKEbEqU/XbWND7+Gn5XYRYhu/1yUxSh911f9ezmiIDqyY1dtKW3FDo/DaIFaoiCAmpxMJ8U9h9jsasdAUpjW/KmvXksAzEqR+XSUAH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715322357; c=relaxed/simple; bh=dk1TRvhXoLDqczQXlxWmQe+iLH87OMbNPHcAv/8I9nc=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=tXi+ZZvphpk7MZtCZWleud2BMbtZd/W4MmHbpbSmmBt77cGAOGl6uIqfmwW7oxxZNQfZrauX3hvi9Rsyqq7lvz58PucXn8NUGzm1faO5QtK4dE2w5id5dX/QKQHf4M8HuvWYvRysyT4TBPzOSW270EuVtuiZb0HcgCwP9Raqxa4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 51B2561080; Fri, 10 May 2024 06:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1715322352; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ytvZqtgIv2NicrvtPIwm2zc6/aVD0yhllJY+ViJe8FM=; b=YlgP+G3b4vYQOkpEodSMeK1WIXKe+aGi9ouz0KzMVWCHVf9C2KtPY5EL3yq0WMEvI+V7hN Amq+tmSYkuYDTEPGKT32jVSnd/6oiSD8TFJlChmV1Wy96UOHV0mghxNv4QuBUNrvvkjZnP tyo3Zu8yAnqiyCLiFMI7rHanvEKV//w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1715322352; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ytvZqtgIv2NicrvtPIwm2zc6/aVD0yhllJY+ViJe8FM=; b=jc0sVIAs3WYIWqIkrptdYeBL8EyEYblXnPiKP1eqYTcZNalOsadK9egtfZsgGOk1Obx0g6 Uic9aRII2lcx5WAA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1715322351; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ytvZqtgIv2NicrvtPIwm2zc6/aVD0yhllJY+ViJe8FM=; b=DIl8bUE9oWDCxVTawFvendp2xk5wlkDu/wdZrgluTO7n7hjckagfewpKyzNi9qT58O0CYU asn67KCV8PKVRmjRkeyF9T5PktqGydn99ky1t8Y7q4+sKqBUQyXDgkjzuAVHIw4oZYikOy d3OmbUecLdCAJ3NZhaP30kxffwDGRgQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1715322351; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ytvZqtgIv2NicrvtPIwm2zc6/aVD0yhllJY+ViJe8FM=; b=15vHLgX/+27ACaNcDzRNt7MPVex9L6ajJOEXVinUlnve6rW8Wv5/fifnPc+eJXiNWUCE9Y 06rtGMYKyhTTA7Bg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1F3061386E; Fri, 10 May 2024 06:25:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id p6+kBe+9PWalfgAAD6G6ig (envelope-from ); Fri, 10 May 2024 06:25:51 +0000 Message-ID: <254a57c9-1f2d-4eec-a68b-14bf62e77ce6@suse.de> Date: Fri, 10 May 2024 08:26:34 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] gdb: Change "list ." command's error when no debuginfo is available To: Guinevere Larsen , Andrew Burgess , gdb-patches@sourceware.org Cc: Simon Marchi , Eli Zaretskii References: <20240430183557.342813-2-blarsen@redhat.com> <87zft0s7nh.fsf@redhat.com> <6a823587-9b51-47f3-b1df-d7626f65e4dc@redhat.com> Content-Language: en-US From: Tom de Vries In-Reply-To: <6a823587-9b51-47f3-b1df-d7626f65e4dc@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -4.29 X-Spam-Level: X-Spamd-Result: default: False [-4.29 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.991]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_TWO(0.00)[2]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sourceware.org:url,simark.ca:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,gnu.org:url,gnu.org:email] X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 5/8/24 19:13, Guinevere Larsen wrote: > On 5/8/24 11:25, Andrew Burgess wrote: >> Guinevere Larsen writes: >> >>> From: Simon Marchi >>> >>> Currently, when a user tries to list the current location, there are 2 >>> different error messages that can happen, either: >>> >>>      (gdb) list . >>>      No symbol table is loaded.  Use the "file" command. >>> or >>>      (gdb) list . >>>      No debug information available to print source lines. >>> >>> The difference here is if gdb can find any symtabs at all or not, which >>> is not something too important for end-users - and isn't informative at >>> all. This commit changes it so that the error always says that there >>> isn't debug information available, with these two variants: >>> >>>      (gdb) list . >>>      Insufficient debug info for showing source lines at current PC >>> (0x55555555511d). >>> or >>>      (gdb) list . >>>      Insufficient debug info for showing source lines at default >>> location. >>> >>> The difference now is if the inferior has started already, which is >>> controlled by the user and may be useful. >>> >>> Unfortunately, it isn't as easy to differentiate if the symtab found for >>> other list parameters is correct, so other invocations, such as "list +" >>> still retain their original error message. >>> >>> Co-Authored-By: Simon Marchi >>> Reviewed-By: Eli Zaretskii >>> --- >>> Changes for v3: >>>    Changed error message to use Eli's suggestion >>>    Added Eli's RB tag since he approved documentation changes >>> >>> Changes for v2: >>>    Added NEWS entry, should have done that from the start oops. >>>    Added test. This test aims to roughly recreate a situation where the >>>      current function is in a spot with no debuginfo, and being called >>>      from somewhere that has debuginfo. >>> >>> --- >>>   gdb/NEWS                                      |  6 ++ >>>   gdb/cli/cli-cmds.c                            | 47 +++++++++---- >>>   .../gdb.base/list-dot-nodebug-extra.c         | 24 +++++++ >>>   gdb/testsuite/gdb.base/list-dot-nodebug.c     | 33 +++++++++ >>>   gdb/testsuite/gdb.base/list-dot-nodebug.exp   | 67 +++++++++++++++++++ >>>   5 files changed, 163 insertions(+), 14 deletions(-) >>>   create mode 100644 gdb/testsuite/gdb.base/list-dot-nodebug-extra.c >>>   create mode 100644 gdb/testsuite/gdb.base/list-dot-nodebug.c >>>   create mode 100644 gdb/testsuite/gdb.base/list-dot-nodebug.exp >>> >>> diff --git a/gdb/NEWS b/gdb/NEWS >>> index feb3a37393a..99909414796 100644 >>> --- a/gdb/NEWS >>> +++ b/gdb/NEWS >>> @@ -36,6 +36,12 @@ set unwindonsignal on|off >>>   show unwindonsignal >>>     These commands are now aliases for the new set/show >>> unwind-on-signal. >>> +list . >>> +  When using the command "list ." in a location that has no debug >>> information >>> +  or no file loaded, GDB now says that there is no debug information >>> to print >>> +  lines.  This makes it more obvious that there is no information, >>> as opposed >>> +  to implying there is no inferior loaded. >>> + >>>   * New commands >>>   info missing-debug-handler >>> diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c >>> index 3afe2178199..ee3318d7910 100644 >>> --- a/gdb/cli/cli-cmds.c >>> +++ b/gdb/cli/cli-cmds.c >>> @@ -1235,37 +1235,39 @@ list_command (const char *arg, int from_tty) >>>     /* Pull in the current default source line if necessary.  */ >>>     if (arg == NULL || ((arg[0] == '+' || arg[0] == '-' || arg[0] == >>> '.') && arg[1] == '\0')) >>>       { >>> -      set_default_source_symtab_and_line (); >>> -      symtab_and_line cursal = get_current_source_symtab_and_line (); >>> - >>>         /* If this is the first "list" since we've set the current >>>        source line, center the listing around that line.  */ >>>         if (get_first_line_listed () == 0 && (arg == nullptr || >>> arg[0] != '.')) >>>       { >>> -      list_around_line (arg, cursal); >>> +      set_default_source_symtab_and_line (); >>> +      list_around_line (arg, get_current_source_symtab_and_line ()); >>>       } >>>         /* "l" and "l +" lists the next few lines, unless we're >>> listing past >>>        the end of the file.  */ >>>         else if (arg == nullptr || arg[0] == '+') >>>       { >>> +      set_default_source_symtab_and_line (); >>> +      const symtab_and_line cursal = >>> get_current_source_symtab_and_line (); >>>         if (last_symtab_line (cursal.symtab) >= cursal.line) >>>           print_source_lines (cursal.symtab, >>>                   source_lines_range (cursal.line), 0); >>>         else >>> -        { >>> -          error (_("End of the file was already reached, use \"list >>> .\" to" >>> -               " list the current location again")); >>> -        } >>> +        error (_("End of the file was already reached, use \"list >>> .\" to" >>> +             " list the current location again")); >>>       } >>>         /* "l -" lists previous ten lines, the ones before the ten just >>>        listed.  */ >>>         else if (arg[0] == '-') >>>       { >>> +      set_default_source_symtab_and_line (); >>> +      const symtab_and_line cursal = >>> get_current_source_symtab_and_line (); >>> + >>>         if (get_first_line_listed () == 1) >>>           error (_("Already at the start of %s."), >>>              symtab_to_filename_for_display (cursal.symtab)); >>> + >>>         source_lines_range range (get_first_line_listed (), >>>                       source_lines_range::BACKWARD); >>>         print_source_lines (cursal.symtab, range, 0); >>> @@ -1274,25 +1276,42 @@ list_command (const char *arg, int from_tty) >>>         /* "list ." lists the default location again.  */ >>>         else if (arg[0] == '.') >>>       { >>> +      std::optional cursal; >>>         if (target_has_stack ()) >>>           { >>>             /* Find the current line by getting the PC of the currently >>>            selected frame, and finding the line associated to it.  */ >>>             frame_info_ptr frame = get_selected_frame (nullptr); >>>             CORE_ADDR curr_pc = get_frame_pc (frame); >>> -          cursal = find_pc_line (curr_pc, 0); >>> +          cursal.emplace (find_pc_line (curr_pc, 0)); >>> + >>> +          if (cursal->symtab == nullptr) >>> +        error >>> +          (_("Insufficient debug info for showing source lines at " >>> +             "current PC (%s)."), paddress (get_frame_arch (frame), >>> +                            curr_pc)); >>>           } >>>         else >>>           { >>>             /* The inferior is not running, so reset the current source >>>            location to the default (usually the main function).  */ >>>             clear_current_source_symtab_and_line (); >>> -          set_default_source_symtab_and_line (); >>> -          cursal = get_current_source_symtab_and_line (); >>> +          try >>> +        { >>> +          set_default_source_symtab_and_line (); >>> +        } >>> +          catch (const gdb_exception &e) >>> +        { >>> +          error (_("Insufficient debug info for showing source " >>> +               "lines at default location")); >>> +        } >>> +          cursal.emplace (get_current_source_symtab_and_line ()); >>> + >>> +          gdb_assert (cursal->symtab != nullptr); >>>           } >>> -      if (cursal.symtab == nullptr) >>> -        error (_("No debug information available to print source >>> lines.")); >>> -      list_around_line (arg, cursal); >>> + >>> +      list_around_line (arg, *cursal); >>> + >>>         /* Set the repeat args so just pressing "enter" after using >>> "list ." >>>            will print the following lines instead of the same lines >>> again. */ >>>         if (from_tty) >>> diff --git a/gdb/testsuite/gdb.base/list-dot-nodebug-extra.c >>> b/gdb/testsuite/gdb.base/list-dot-nodebug-extra.c >>> new file mode 100644 >>> index 00000000000..c3d2416e70d >>> --- /dev/null >>> +++ b/gdb/testsuite/gdb.base/list-dot-nodebug-extra.c >>> @@ -0,0 +1,24 @@ >>> +/* This testcase is part of GDB, the GNU debugger. >>> + >>> +   Copyright 2024 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 >>> .  */ >>> + >>> +extern void bar(int *); >> Space missing after 'bar' here. >> >>> + >>> +void >>> +foo (int *x) >>> +{ >>> +  bar (x); >>> +} >>> diff --git a/gdb/testsuite/gdb.base/list-dot-nodebug.c >>> b/gdb/testsuite/gdb.base/list-dot-nodebug.c >>> new file mode 100644 >>> index 00000000000..b37c3561c41 >>> --- /dev/null >>> +++ b/gdb/testsuite/gdb.base/list-dot-nodebug.c >>> @@ -0,0 +1,33 @@ >>> +/* This testcase is part of GDB, the GNU debugger. >>> + >>> +   Copyright 2024 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 >>> .  */ >>> + >>> +extern void foo (int *x); >>> + >>> +int x; >>> + >>> +void >>> +bar (int *p) >>> +{ >>> +  *p++; >>> +} >>> + >>> +int >>> +main () >>> +{ >>> +  foo (&x); >>> +  return 0; >>> +} >>> diff --git a/gdb/testsuite/gdb.base/list-dot-nodebug.exp >>> b/gdb/testsuite/gdb.base/list-dot-nodebug.exp >>> new file mode 100644 >>> index 00000000000..7c4144da8ab >>> --- /dev/null >>> +++ b/gdb/testsuite/gdb.base/list-dot-nodebug.exp >>> @@ -0,0 +1,67 @@ >>> +# Copyright 2005-2024 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 . >>> + >>> +# This test is here to confirm that the command "list ." will print the >>> +# same message if GDB detects no debug information at all, or >>> detects some >>> +# but nothing for the current objfile. >>> + >>> +require !use_gdb_stub >>> + >>> +set linkflags [list additional_flags="-static"] >>> + >>> +if { ![gdb_can_simple_compile static-libc \ >>> +       { >>> +           void main (void) { return 0; } >>> +       } \ >>> +       executable $linkflags] } { >>> +    untested "Can't statically link" >>> +    return -1 >>> +} >>> + >>> +standard_testfile .c -extra.c >>> +set objmainfile [standard_output_file ${testfile}-main.o] >>> +set objextrafile [standard_output_file ${testfile}-extra.o] >>> + >>> +if {[gdb_compile "$srcdir/$subdir/$srcfile" $objmainfile object >>> {nodebug}] != "" } { >>> +    untested "couldn't compile main file into object" >>> +    return -1 >>> +} >> The gdb_compile line seems redundant, you recompile the test binary >> within the foreach loop.  With this gone the objmainfile and >> objextrafile variables seem redundant too. >> >>> + >>> +foreach_with_prefix debug {"none" "some"} { >>> + >>> +    set flags "nodebug" >>> +    if {$debug == "some"} { >>> +    set flags "debug" >>> +    } >>> + >>> +    if {[prepare_for_testing_full "failed to prepare" \ >>> +        [list ${testfile}-${debug} $linkflags \ >>> +        $srcfile [list nodebug] \ >>> +        $srcfile2 [list $debug]]]} { >>> +    return -1 >>> +    } >>> + >>> +    gdb_test "list ." \ >>> +    "No debug information available to print source lines.*" \ >> I would replace this pattern with: >> >>     "^Insufficient debug info for showing source lines at default >> location" \ >> >> this extends the text you used in your earlier reply, but avoids using >> '.*'.  I think it's better to avoid '.*' unless it's essential.  With >> this patter we're saying we expect that line, and that line only. >> Absolutely no other output. >> >>> +    "print before start" >>> + >>> +    if { ![runto bar] } { >>> +    return -1 >>> +    } >>> + >>> +    gdb_test "list ." \ >>> +    "No debug information available to print source lines at current >>> PC.*" \ >> And here: >> >>     "^Insufficient debug info for showing source lines at current PC >> \\($::hex\\)\\." \ >> >> With these testsuite fixes, and the other things you changed in your >> earlier reply: >> >> Approved-By: Andrew Burgess > Thanks, pushed! > > I run into fails in the new test-case: ... FAIL: gdb.base/list-dot-nodebug.exp: debug=none: print before start FAIL: gdb.base/list-dot-nodebug.exp: debug=some: print before start ... Filed here ( https://sourceware.org/bugzilla/show_bug.cgi?id=31721 ). Thanks, - Tom