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.129.124]) by sourceware.org (Postfix) with ESMTPS id E622E38582BE for ; Wed, 6 Mar 2024 13:38:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E622E38582BE 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 E622E38582BE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709732292; cv=none; b=qz+kLnkTkAVbO7+pgW6GvUhu8Mow+I6dS2WJ7DoEAlsnthRJ/+HDnZFWEk3Z3JqXprwUwV2Uac1t5fTqP2/oxbMBexNDmK68Aliuy5W53RuFp5PYaorVIVVyoEoxNY0kENEwesBwOJVKzA8osYahxiExN3VS7UJYSvF5+pxH1sM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709732292; c=relaxed/simple; bh=O/tgTq5RW1I5bbGk3JWDwuv2wrjybpq+IRPvjdOQ/Ow=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=gLZS7TQT8kG08hynVCr1DeZbrjI6KR0MQOH9mkKe63xlTsout2y9bAK6nSCUS9jFtryWHf0Vf6oxxMi/vwz+jy4ig9ZPyJwm9TnWMe5Kd9z+kBDKMNpqnxM4Hgc7oeAX4npfNPcoxGQQUskV4gObUKL+8UyHCIjNjXcaMmiTMJI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709732289; 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=RBe6b8ZGKrAB1BS6wzMAsOtPFBHc2LLy15i0cZmcqtg=; b=h8Ugl4Jm4Eq2N/xkaJBY3bpHL/a3U78Z+KT9QjyCZoW8tCm3wRbfbPfPeMOpuBLtLp5fmz KhEgyLk0GUwTO74deGM6NZ7yy28UGvX9WlVXdeegbJkNEI0mta2bopOcbFbV7/LuXlHkLd iDOrF5mfnr0uri+9Q3rpbEPa6EHm1xI= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-597-SLxgiIwMMW2ABcwJu13OBg-1; Wed, 06 Mar 2024 08:38:08 -0500 X-MC-Unique: SLxgiIwMMW2ABcwJu13OBg-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-33d8b4175dbso2993960f8f.0 for ; Wed, 06 Mar 2024 05:38:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709732287; x=1710337087; 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=RBe6b8ZGKrAB1BS6wzMAsOtPFBHc2LLy15i0cZmcqtg=; b=fLgk1i4Q/cZxZNjFRXpqEfCOgFpzBZpCU6+UjAt/oSLdpJL/68BXLfbBK+T1kEB/uK IGio+042V4V1tv4L/1HY9KQTmpwo2sv+pnU6yDEGuhSjf3mTgeYLaO3UBC1ndRiQGDPe +okYiLrye3sS9uR8EWTrOSIcD0A85Jq2oBxsxz1jlDh4oTbqvpEjIt6U280jy9b9J2m4 cejnIryvIBj7whHzBRIyyIQ3udrCWd866jfAjxllvIdl/bcbRFm4QlTq3hlwFPSW8a3q YO5yj30EPrbq9Rmy48ldNE3CpQbvd870LjXlVs8NMI1bRM2HfJAXD0gEIzZJTbCbXmFA QISA== X-Forwarded-Encrypted: i=1; AJvYcCXItcVC4o+oHOx/NXRz0aUbN/1kyFw6yIN9rTrszpK8ysklxQC3coA/kXLdslINQy2L/FpqM1/1B+9PpOu+JsvjMQ7L+9NTaKE3lQ== X-Gm-Message-State: AOJu0YxQU8nIeAvoTwulUfXtd9p+6OX2rU/3JQUdBCGtmbMN+l6haHAB zBOlPa4yjguU2MLi38bLR6sy1q34vXeqg2lat99h24B90hIDoMxvGTOoaxuLlKX9fduxoSLHDQ9 aH7QQqlWHzeoVUI/ygIjt6b7j5dkhhepj4J9ec2DLXdHA6k66N0RNGGZ1DfM= X-Received: by 2002:a5d:4446:0:b0:33d:fe8f:8c44 with SMTP id x6-20020a5d4446000000b0033dfe8f8c44mr10369854wrr.46.1709732287150; Wed, 06 Mar 2024 05:38:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHtuNhoO1PR2mBHRY3ppqZb94CGqHMBNfX7DV6Lz6M9QSqdFqrRYrNypGiDkpxNPKSOeuhOCw== X-Received: by 2002:a5d:4446:0:b0:33d:fe8f:8c44 with SMTP id x6-20020a5d4446000000b0033dfe8f8c44mr10369839wrr.46.1709732286637; Wed, 06 Mar 2024 05:38:06 -0800 (PST) Received: from [192.168.0.129] (ip-94-112-227-180.bb.vodafone.cz. [94.112.227.180]) by smtp.gmail.com with ESMTPSA id j11-20020a5d604b000000b0033d9ee09b7asm17622351wrt.107.2024.03.06.05.38.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Mar 2024 05:38:05 -0800 (PST) Message-ID: Date: Wed, 6 Mar 2024 14:38:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb: Change "list ." command's error when no debuginfo is available To: Andrew Burgess , gdb-patches@sourceware.org Cc: Simon Marchi References: <20240213143624.140852-1-blarsen@redhat.com> <871q8nbit2.fsf@redhat.com> From: Guinevere Larsen In-Reply-To: <871q8nbit2.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=-10.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,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 06/03/2024 14:18, 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 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? The situation where I see the second message pops up is when we're, for example, in the main function and there are symbols for libc. I may be misunderstanding something, but I don't think that debug information covers the address the inferior is in. The situation that we were specifically thinking about was that > > 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. That's a good point... Do you know how I'd be able to get a test running with no symbols whatsoever, even if the system that is doing the testing has libc symbols? -- Cheers, Guinevere Larsen She/Her/Hers > > 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