From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 35FB93858D28 for ; Tue, 27 Jun 2023 11:35:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35FB93858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687865705; h=from:from:reply-to:subject:subject: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=RSmtrp0HHbfhdvbR2cBLEqDxLnAxxhkveECgzEpxc2k=; b=L+TH8XsH48NFT1O+1Fl7tI77RZWFz6V5VBeL8ny+VwGDFok5q2jUg/FX+foIvxPRmOYGH1 LkqhdSBZwlEm5hbQmx63MBuB08PkSCd5bm4fRm0bdh2q5p91MWddJHwGHMgzi7yLq60zR0 /2l4/sAgiwYLAVTo9MNFQDpCbq30I3M= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-352-i7kBof1mOReI49nNY8ieEw-1; Tue, 27 Jun 2023 07:35:04 -0400 X-MC-Unique: i7kBof1mOReI49nNY8ieEw-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2b6b75f7bc1so1486131fa.1 for ; Tue, 27 Jun 2023 04:35:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687865703; x=1690457703; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7QoK0rSX7D6R21AU2/vB6Bqgl7E0hAL/llY76SaYPR8=; b=EfkFBia7feMtpqm56OXvX8tiIaWIelOqjvon5DHCY0nX6KER8e2jFObDPPp+19I4QU Gv/86cv4QubMw5ps3zuNgpXsvyui+sR9imKGjdbs+PNB2HGlutJ7rDm6ohzjGwIW2vJw uwFyTS3C2qPuZmKtzd2x4R8fiZGB6NWxe852JpIy7Wv9zeFPsTJHxN40EGOoAViSzNZy DwOCq+5LBdl9lpg0e7uuxA+vEeDAXd82Jodgp28fbqqmL3OYmnzW2gStgYP7IcVHxAZS 1/8KFTedwpzxiZwch/+uwy8fgtci35q02dVL3hjuJHq3zQDklzreJ7+hW45c/WEvMEWj PVqw== X-Gm-Message-State: AC+VfDwT6ff6HqZVE6WWFH2NpeLLLYv3GbgIxMSwJYY/LTM1Q/j2HnTK kmUQ9cNrrAmhggQ2rGr7ygUF0yhxI/LBxMit/B0VkR3g3DOmwVlvyfbGi8bfC20Jho8WGxt8oo3 Nzy1ldfqtVNHzZo/VuYfpPg== X-Received: by 2002:a2e:8241:0:b0:2b5:84fb:5939 with SMTP id j1-20020a2e8241000000b002b584fb5939mr11485589ljh.30.1687865703038; Tue, 27 Jun 2023 04:35:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4w5u6vCTQR+PyM5UQaWDP+U6xXNXoxn2P2OrZBqVONp1HXxBlm+nrUrXEr3tukAdK8bHvNJQ== X-Received: by 2002:a2e:8241:0:b0:2b5:84fb:5939 with SMTP id j1-20020a2e8241000000b002b584fb5939mr11485578ljh.30.1687865702581; Tue, 27 Jun 2023 04:35:02 -0700 (PDT) Received: from [192.168.0.129] (ip-94-112-225-44.bb.vodafone.cz. [94.112.225.44]) by smtp.gmail.com with ESMTPSA id u7-20020a170906654700b009875a6d28b0sm4425005ejn.51.2023.06.27.04.35.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Jun 2023 04:35:02 -0700 (PDT) Message-ID: Date: Tue, 27 Jun 2023 13:35:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v3 2/4] gdb/cli: Improve UX when using list with no args To: Andrew Burgess , Bruno Larsen via Gdb-patches Cc: Eli Zaretskii References: <20230621104545.2530552-1-blarsen@redhat.com> <20230621104545.2530552-3-blarsen@redhat.com> <878rcbtxro.fsf@redhat.com> From: Bruno Larsen In-Reply-To: <878rcbtxro.fsf@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIM_INVALID,DKIM_SIGNED,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 22/06/2023 15:46, Andrew Burgess wrote: > Bruno Larsen via Gdb-patches writes: > >> When using "list" with no arguments, GDB will first print the lines >> around where the inferior is stopped, then print the next N lines until >> reaching the end of file, at which point it wanrs the user "Line X out >> of range, file Y only has X-1 lines.". This is usually desireable, but >> if the user can no longer see the original line, they may have forgotten >> the current line or that a list command was used at all, making GDB's >> error message look cryptic. It was reported in bugzilla as PR cli/30497. >> >> This commit improves the user experince by changing the behavior of >> "list" slightly when a user passes no arguments. If the line that would >> be printed is past the end of the file, GDB will now warn that the >> previous list command has reached the end of file, and the current line >> wil be listed again. > -1 from me. I don't like the idea of this auto-wrap around. > > I don't feel like this really addresses the original complain anyway. > The complaint seems to be: > > 1. User does 'list' and sees the current location, > > 2. User runs "other commands" which scrolls the list contents off the > screen, > > 3. User does 'list', but is now unsure what the current location is. > > The only way this change helps is if the user keeps "list"-ing until > they wrap around, at which point they can find the current location. > > Also, I don't understand what's so cryptic about the error message. As > far as I can tell, GDB's auto-repeat system only auto-repeats if the > last command is repeatable. So in order to see the error message at all > the last command typed _must_ have been a 'list' command, so why > wouldn't the error message apply to that command? > > I guess maybe the cryptic nature comes from, why is GDB trying to list > line number X at all? But surely that should suggest to the user that > if they don't want to see like X, they should try 'list NN' instead? > > Maybe the right thing to do here is provide more helpful text when > reaching the end of the file? Or maybe extend the 'help list' text to > give more guidance to users on how to return to the current location? > > I did see Keith's suggestion for relisting the last few lines. I think > I'm neutral on that idea, I wouldn't object to it, but the current just > a warning makes it clear GDB has stopped progressing, which I think > could be useful. I'm reworking the patch already, but I wanted to document my thoughts so you have context for the next version. You hit the nail on the head that it isn't the command erroring out that is the problem, but rather that the user will think "why is GDB trying to list a line that doesn't exist when I requested the current one?". And while it is easy to figure out that "list NN" is the answer, figuring out what N should be is not obvious, it either requires that the user use some other command to find the current line (such as frame or bt 1), or that they know about convenience registers/using registers in GDB and use "list *$pc" as you suggested in patch 3 of this series. I dont think we should tie functionality of one command to knowledge of unrelated things. So a reasonable way to meet you in the middle, I think, is to have the error for the no-arg invocation of list continue erroring out, but reference using "list ." to go back to the current location in the warning message. Does that sound reasonable? -- Cheers, Bruno > Thanks, > Andrew > >> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30497 >> Reviewed-By: Eli Zaretskii >> --- >> gdb/NEWS | 7 +++++++ >> gdb/cli/cli-cmds.c | 36 +++++++++++++++++++++++++++++++-- >> gdb/doc/gdb.texinfo | 7 +++++-- >> gdb/source.c | 18 +++++++++++++++++ >> gdb/source.h | 4 ++++ >> gdb/testsuite/gdb.base/list.exp | 8 ++++---- >> 6 files changed, 72 insertions(+), 8 deletions(-) >> >> diff --git a/gdb/NEWS b/gdb/NEWS >> index fd42864c692..348e73dd15f 100644 >> --- a/gdb/NEWS >> +++ b/gdb/NEWS >> @@ -77,6 +77,13 @@ >> as the array would be printed by the 'print' command. This >> functionality is also available for dprintf when dprintf-style is >> 'gdb'. >> + >> +* Using the 'list' command with no arguments in a situation where the >> + command would attempt to list past the end of the file now warns the >> + user that the end of file has been reached, and prints the default >> + location. Previously, it would error out. The default location for >> + this purpose is the last solitary line printed, if there was one, >> + else the lines around the main function. >> >> * New commands >> >> diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c >> index b0b9c08c2ec..5973aebfad3 100644 >> --- a/gdb/cli/cli-cmds.c >> +++ b/gdb/cli/cli-cmds.c >> @@ -1244,8 +1244,40 @@ list_command (const char *arg, int from_tty) >> list_around_line (arg, cursal); >> } >> >> - /* "l" or "l +" lists next ten lines. */ >> - else if (arg == NULL || arg[0] == '+') >> + /* "l" lists the next few lines, unless we're listing past the end of >> + the file. If it would be past the end, re-print the current line. */ >> + else if (arg == nullptr) >> + { >> + if (can_print_line (cursal.symtab, cursal.line)) >> + print_source_lines (cursal.symtab, >> + source_lines_range (cursal.line), 0); >> + else >> + { >> + warning (_("previous list command has already reached the end " >> + "of the file. Listing default location again")); >> + try >> + { >> + /* 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); >> + } >> + catch (const gdb_exception &e) >> + { >> + /* If there was an exception above, it means the inferior >> + is not running, so reset the current source location to >> + the default. */ >> + clear_current_source_symtab_and_line (); >> + set_default_source_symtab_and_line (); >> + cursal = get_current_source_symtab_and_line (); >> + } >> + list_around_line (arg, cursal); >> + } >> + } >> + >> + /* "l +" always lists next few lines. */ >> + else if (arg[0] == '+') >> print_source_lines (cursal.symtab, >> source_lines_range (cursal.line), 0); >> >> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo >> index b10c06ae91f..55010f69a1c 100644 >> --- a/gdb/doc/gdb.texinfo >> +++ b/gdb/doc/gdb.texinfo >> @@ -9142,9 +9142,12 @@ Print lines centered around the beginning of function >> @item list >> Print more lines. If the last lines printed were printed with a >> @code{list} command, this prints lines following the last lines >> -printed; however, if the last line printed was a solitary line printed >> +printed; however, if those lines are past the end of the source >> +file, or if the last line printed was a solitary line printed >> as part of displaying a stack frame (@pxref{Stack, ,Examining the >> -Stack}), this prints lines centered around that line. >> +Stack}), this prints lines centered around that line. If no >> +@code{list} command has been used and no solitary line was printed, >> +it prints the lines around the function @code{main}. >> >> @item list - >> Print lines just before the lines last printed. >> diff --git a/gdb/source.c b/gdb/source.c >> index 9997cccb31b..1aa08c6e080 100644 >> --- a/gdb/source.c >> +++ b/gdb/source.c >> @@ -1484,6 +1484,24 @@ print_source_lines (struct symtab *s, source_lines_range line_range, >> line_range.stopline (), flags); >> } >> >> +/* See source.h. */ >> + >> +bool >> +can_print_line (struct symtab *s, int line) >> +{ >> + const std::vector *offset_p; >> + >> + /* If we can't get the offsets, we definitely can't print the line. */ >> + if (!g_source_cache.get_line_charpos (s, &offset_p)) >> + return false; >> + if (offset_p == nullptr) >> + return false; >> + >> + /* Otherwise we are able to print LINE if there are at least that many >> + lines in the symtab. */ >> + return line <= offset_p->size (); >> +} >> + >> >> >> /* Print info on range of pc's in a specified line. */ >> diff --git a/gdb/source.h b/gdb/source.h >> index 8fbc365680d..ae6764322d0 100644 >> --- a/gdb/source.h >> +++ b/gdb/source.h >> @@ -192,6 +192,10 @@ class source_lines_range >> int m_stopline; >> }; >> >> +/* Check if the line LINE can be found in the symtab S, so that it can be >> + printed. */ >> +extern bool can_print_line (struct symtab *s, int line); >> + >> /* Variation of previous print_source_lines that takes a range instead of a >> start and end line number. */ >> extern void print_source_lines (struct symtab *s, source_lines_range r, >> diff --git a/gdb/testsuite/gdb.base/list.exp b/gdb/testsuite/gdb.base/list.exp >> index 18ecd13ac0f..35e099ebaff 100644 >> --- a/gdb/testsuite/gdb.base/list.exp >> +++ b/gdb/testsuite/gdb.base/list.exp >> @@ -175,8 +175,8 @@ proc_with_prefix test_list_forward {} { >> "list 25-34" >> gdb_test "list" "35\[ \t\]+foo \\(.*\\);.*${last_line_re}" \ >> "list 35-42" >> - gdb_test "list" "Line number 44 out of range; \[^\r\n\]+ has 43 lines\." \ >> - "end of file error after \"list\" command" >> + gdb_test "list" "warning: previous list command has already reached the end of the file. Listing default location again.*1\[ \t\]+#include \"list0.h\".*" \ >> + "list past end of file" >> } >> >> # Test that repeating the list linenum command doesn't print the same >> @@ -194,8 +194,8 @@ proc_with_prefix test_repeat_list_command {} { >> "list 25-34" >> gdb_test " " "35\[ \t\]+foo \\(.*\\);.*${last_line_re}" \ >> "list 35-42" >> - gdb_test "list" "Line number 44 out of range; \[^\r\n\]+ has 43 lines\." \ >> - "end of file error after using 'return' to repeat the list command" >> + gdb_test "list" "warning: previous list command has already reached the end of the file. Listing default location again.*1\[ \t\]+#include \"list0.h\".*" \ >> + "list past end of file" >> } >> >> proc_with_prefix test_list_backwards {} { >> -- >> 2.40.1