From patchwork Tue Feb 13 14:36:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinevere Larsen X-Patchwork-Id: 85665 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A07F385828F for ; Tue, 13 Feb 2024 14:36:53 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 5BA2B3858C52 for ; Tue, 13 Feb 2024 14:36:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BA2B3858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5BA2B3858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707834992; cv=none; b=W2bEo7G+3iLWIo6Ye92TpSt37WlltNU362f0Z+mLZK8Dppc5/d65O2jPKT+V6zn3w9rtw0DVagpMduDXF8wnA98MpG0cpsnDTQylvu78ZTjAV/9T4EcioaMNQZ/jtGQrEJ2G+YmqHu56gYYe1+Jvu0C4HFVJNWsLSexzulJcg9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707834992; c=relaxed/simple; bh=5Sv7J9y12xpbxzdqrGOD+Gs+eWZmPAhMj0ALE1EONdM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JyvupfB7/a5JWjeI4eZ7PnlUMgxxTkagpvInoUoTruerRvOJvogxA2CmxoaHWh0ixf4sd1LwFmHUsKoa42lev7zFHwTwXbPNIIm+wXlJVZG25ZcZZ66pzJOVPJ+jF3LSEc4VNqUeeaAXIVG5Q2xQLAVz8TsWWSMUSN0Dsz1NYJA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707834990; 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; bh=82rU8KiUC6pX4pEnfXlLn+7q0lB7MjeU6n5NcLDFe/c=; b=Pm7UiCNYnasNvoX+ylThUr5LtDrcydCRAEOohp4DgNGayllePPvL2eXlWFyev7tyxx+i9/ QAgyQecc+Qj/EABOmR6s+jJ0lO2B0P3FNuhTGGcFo9tihXrYA6dQShikfuSWAzrvzp4R8a AyWXc8Z2Cnu5UgpdTqvmPD6w5SOEUik= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-224-qh0pbOS-PkKOFvJ4YSts7g-1; Tue, 13 Feb 2024 09:36:27 -0500 X-MC-Unique: qh0pbOS-PkKOFvJ4YSts7g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4E028185A785; Tue, 13 Feb 2024 14:36:27 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.39.194.217]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F3842166B4F; Tue, 13 Feb 2024 14:36:26 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb: Change "list ." command's error when no debuginfo is available Date: Tue, 13 Feb 2024 15:36:23 +0100 Message-ID: <20240213143624.140852-1-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org 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 a difference a user should concern themselves with. This commit changes it so that the error is always: (gdb) list . No debug information available to print source lines at current PC (0x55555555511d). or (gdb) list . No debug information available to print 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 --- gdb/cli/cli-cmds.c | 48 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index df11f956245..31f0b6d9907 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1236,37 +1236,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); @@ -1275,25 +1277,43 @@ 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 + (_("No debug information available to print 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 (_("No debug information available to print source " + "lines at default location")); + } + cursal.emplace (get_current_source_symtab_and_line ()); + + // Not sure if always true, just guessing. + 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)