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 89BD2385843A for ; Wed, 6 Mar 2024 13:18:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89BD2385843A 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 89BD2385843A 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=1709731088; cv=none; b=Jp7iPwsyGCJTXQcgtPdudsTKXZ9mqTTYwqcPTJmjOSzoZRvdLM3c/YBRJIajbWBqyhFEVAOkJMc/nsr2ia+UgtfQ1ynOjJ4gRsCr8r9AKSdjCzr+PHt+S+uoeBhQbQ9+f0OKrkL4z7uLYPrrzQmabFfYjIMVuEHspgQH280Nn2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709731088; c=relaxed/simple; bh=+HYsztiOOY7H53/byehmq1aBe8IpYxJdrNN0d+JF9vU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=b6fUCzOON0JvxgQAo5xbZptB04DzMsaW5R7uj33Yh8W8jNIpTndx53OQ7H798EVaA/V1dIngsgLxyJ8YTyG6jt1oucAs5ZsTB1OOnyZu8uVsJC+r3B5YYM0g6AJn/6e9EEsxVcon3FrLC4j4Vep7SXWGbUxtRacssnQdAyVrsYA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709731086; 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: in-reply-to:in-reply-to:references:references; bh=/qsDMGMPkzDU/COT+Z2tdE8U1pZFr4IWj7G6QdmHakY=; b=K2g+a9skIkIQn20xi3UoVDx5iFkL2sHqRn097nH94NccgG4fvaBn4JIgsTB9RKZSJEYb9x 7gYgpJBUHZ8jCvxeCGXNS311bj4yMcFEQZv9TtANyWRcKQWouW6xRcMpCtv3hAUr9dEnz4 Hcyw8Yq1BjbR+bpTlzUn/HZHrQUIEKQ= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-634-U9CxPpjrNWeGFY4G8saaiA-1; Wed, 06 Mar 2024 08:18:04 -0500 X-MC-Unique: U9CxPpjrNWeGFY4G8saaiA-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-558aafe9bf2so7159087a12.1 for ; Wed, 06 Mar 2024 05:18:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709731084; x=1710335884; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/qsDMGMPkzDU/COT+Z2tdE8U1pZFr4IWj7G6QdmHakY=; b=tJa9tgGEJqVwHDq76FBAJChfDLOYcXX0odULpvcD/4qfxPYp/SEG3Dr4ADh3tFkKCs K9AHD3uV1xaPSaji8gpVFUJF5CW9Gmd1T1ffyBF+1HHhB7bCmR2ORwGHvWgpUyrJfmTZ LnMcezKJ0ugbRxe4xuI3pk7zYCOJv/FpIwn10POST1i9Ym7h8sCiqgGry8QeA9sSQbVs 9EMwHaQsbJ5elYbnMU4jpTR1Qtp9J9aVWueITWF4yVijpHtp9drv/MQL/kWMS0N4K/76 LTKUm7QKJjUA6xAYoNZFSg8C9SU7ezliz3cFVB2XEcvyeekypyd+PbzB4I5GSHIKOryb kjkA== X-Forwarded-Encrypted: i=1; AJvYcCUEt35bi519++oNHJN2vwk42sXTPQmZdiuaw3wgsW0XxaCdFvgy9ct7NJO8olMTxS0sqhiUGcq4CF9aE8OM7KukxdC/Vn2EBzKRSQ== X-Gm-Message-State: AOJu0YzNeTN4qlx2MLy90JGX4aJUqb4OWho4lHZ/NU43zpgw7lT/QM1O 819AbFUpImiWV1ULi6ocZrqXm6I4qoYKW2vMhTiGdu+r4UCddJErKOnr54i2loqjQMbHdorsVdK GuhtHKpPaM0CQD/jvkEKO7vJEueJZEmNg9f6QdoepuzHSy2Tn931oWEGupXI= X-Received: by 2002:a05:6402:5c2:b0:567:6a66:d101 with SMTP id n2-20020a05640205c200b005676a66d101mr5438891edx.31.1709731083508; Wed, 06 Mar 2024 05:18:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCdirmTxUHlk1iZ0+Xx3iR6E0k9SnagMKA86LQ1zzPbXA2fBpTr7g+pL1O4Vtlra1vVTLU9Q== X-Received: by 2002:a05:6402:5c2:b0:567:6a66:d101 with SMTP id n2-20020a05640205c200b005676a66d101mr5438869edx.31.1709731082860; Wed, 06 Mar 2024 05:18:02 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id k8-20020a05640212c800b00567216c1e9bsm4434164edx.88.2024.03.06.05.18.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 05:18:02 -0800 (PST) From: Andrew Burgess To: Guinevere Larsen , gdb-patches@sourceware.org Cc: Simon Marchi Subject: Re: [PATCH] gdb: Change "list ." command's error when no debuginfo is available In-Reply-To: <20240213143624.140852-1-blarsen@redhat.com> References: <20240213143624.140852-1-blarsen@redhat.com> Date: Wed, 06 Mar 2024 13:18:01 +0000 Message-ID: <871q8nbit2.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.2 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 List-Id: 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 a difference a user should concern themselves with. Why not? Maybe "No symbol table is loaded" isn't the clearest, maybe "No debug information is loaded" might be better, but the first message tells me that there is no debug information, maybe GDB failed to find it, or maybe I need to provide it. The second tells me that GDB did find debug information that covers this address, but it lacks the required detail to help, maybe I forgot -g when compiling? I'm not 100% against this change, I just don't find the motivation super compelling. > 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 ++++++++++++++++++++++++++++++++-------------- For sure this patch should have an associated test change. Thanks, Andrew > 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) > -- > 2.43.0