From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id RAEVGlXU7mkoqj0AWB0awg (envelope-from ) for ; Sun, 26 Apr 2026 23:13:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1777259605; bh=DUi3nwLuX2+N/i1c3XSJoywLuGQbUP7uG4FfKWzv2ko=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=EJg879ZR/IxkvDiSdR0zqJK4ZMVMSW4cvTHOcnQ7vuRr/BQdWEglvfRLYg4PpfPa2 XuRcj5WNM0Fskobr8Q+9C6j0WCoWs7S2irKzM1OH8XwmaLLvPsMh+5ErMZYr+xq2Vd 0fFbQEaT5fRk1PYfASu708Yu/3Hwx6DGETj6gHzc= Received: by simark.ca (Postfix, from userid 112) id 593C51E093; Sun, 26 Apr 2026 23:13:25 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=c417nu4C; dkim-atps=neutral Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 12A261E093 for ; Sun, 26 Apr 2026 23:13:24 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 8EC044BB3BAD for ; Mon, 27 Apr 2026 03:13:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EC044BB3BAD Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=c417nu4C Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 936714BAE7F7 for ; Mon, 27 Apr 2026 03:12:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 936714BAE7F7 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 936714BAE7F7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777259578; cv=none; b=njbAW+LKPVW+uh/33f3Bu2Z3goQfvA/okMcSebVP8ccrMIJKF2fxk7rquNkJY8UrilnI5pKwPm09qMaoToL5MsgapC1d9RXwXe5lLImJCnI+xTSCZM/PBXUqdibO3jL5zMn0jehsfEKC+KS+exMpbuCYu5I/ZFGmPZ0Crr8QG2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777259578; c=relaxed/simple; bh=DUi3nwLuX2+N/i1c3XSJoywLuGQbUP7uG4FfKWzv2ko=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=wIUf2A61ZSVs9U+Si7GqiPse7zCfNzcMNYuX5zpWvJYyEEn5qBaGcooGnuGs1BxmBRPhILPqFSmcs0f6ZXNVStHY4Sv92Kw9NSaFYXLYbQSZgUn1EDgOn6fa1bJBLQFiFFcTYJ1kzMfAOjGUHVhpy73Tdt6LXpeNV2DtMRGNSHQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 936714BAE7F7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1777259576; bh=DUi3nwLuX2+N/i1c3XSJoywLuGQbUP7uG4FfKWzv2ko=; h=Date:Subject:To:References:From:In-Reply-To:From; b=c417nu4Cjh0nYWZlfyzw+MGwYgGGloWT4Pn7wgLc542KgA6mpHzcLn6Sgf7Aqzuts eeZXdeDQoaelfLOOaLp1zPLAp14i/qEBM9B9n8XTeuTnE7KOE4TJYZJlJ7ZBz5ihrV v1h1hPZnMR98+4SJBmpqaARsCktrVkMeT/CK6IIo= Received: by simark.ca (Postfix) id 7001C1E093; Sun, 26 Apr 2026 23:12:56 -0400 (EDT) Message-ID: Date: Sun, 26 Apr 2026 23:12:56 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] [gdb] Support default locations in DWARF5 loclists To: Gregori Mignerot , gdb-patches@sourceware.org References: <20260426115337.1245133-2-gregori.mignerot@laposte.net> Content-Language: en-US From: Simon Marchi In-Reply-To: <20260426115337.1245133-2-gregori.mignerot@laposte.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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~public-inbox=simark.ca@sourceware.org On 2026-04-26 07:40, Gregori Mignerot wrote: > Add support and a test for default location entries in DWARF5 loclists > (DW_LLE_default_location, section 2.6.2 in the DWARF5 standard) > --- > Applied the review comments and added the test for `info address`, > thanks for the quick feedback ! > >> Just wondering, is this valid DWARF? The spec implies that the default >> location has the be last (if present): >> >> A location list consists of a sequence of zero or more bounded >> location description or base address entries, optionally followed by >> a default location entry, and terminated by an end-of-list entry. >> >> I'm not sure why DWARF 5 requires that, it seems to me like it would >> work just as well if the default location was allowed to be anywhere in >> the list. Do you know about producers that do this? > > I'm not sure either, there isn't a lot of producers or consumers for > this. LLVM and libdwarf don't seem to care about the position of the > default location entry. > I wasn't sure either about that test, it's probably superfluous, removed > it in v2. Are you able to mention some producers that produce default locations, so we can look? If we don't need to support non-conforming implementations, I think we could stick to what the spec says, it would make the code a little bit simpler: when encountering a DW_LLE_default_location, you can return this that expression right away, instead of saving it to a local variable to be returned later. > diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c > index a493a46dcfc..c728fa9c4b1 100644 > --- a/gdb/dwarf2/loc.c > +++ b/gdb/dwarf2/loc.c > @@ -83,6 +83,10 @@ enum debug_loc_kind > the applicable base address. */ > DEBUG_LOC_OFFSET_PAIR = 4, > > + /* This is followed by a normal location expression as in .debug_loc, > + to use when no other entry matches the current PC */ Finish the sentence with : /* This is followed by a normal location expression as in .debug_loc, to use when no other entry matches the current PC. */ The concept of "default location" appeared in DWARF 5, right? If so, I think this comment should say ".debug_loclists" instead of ".debug_loc". > @@ -379,6 +386,11 @@ dwarf2_find_location_expression (const dwarf2_loclist_baton *baton, > unrelocated_addr base_address = baton->base_address; > const gdb_byte *loc_ptr, *buf_end; > > + /* When no DEBUG_LOC_DEFAULT_LOCATION is found > + return NULL with length 0 (= no location found) */ Finish sentence with . > + const gdb_byte *default_loc_ptr = NULL; nullptr (instead of NULL) for new (or modified) code. > @@ -4042,10 +4063,11 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr, > gdb_printf (stream, _(" Base address %s"), > paddress (gdbarch, (CORE_ADDR) base_address)); > continue; > - > + Spurious tab added. > @@ -4057,6 +4079,29 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr, > gdb_assert_not_reached ("bad debug_loc_kind"); > } > > + if (dlbaton->dwarf_version < 5) > + { > + length = extract_unsigned_integer (loc_ptr, 2, byte_order); > + loc_ptr += 2; > + } > + else > + { > + unsigned int bytes_read; > + length = read_unsigned_leb128 (NULL, loc_ptr, &bytes_read); > + loc_ptr += bytes_read; > + } > + > + if (kind == DEBUG_LOC_DEFAULT_LOCATION) > + { > + gdb_printf (stream, _(" Default location: ")); > + locexpr_describe_location_1 (symbol, addr, stream, loc_ptr, length, > + addr_size, offset_size, > + dlbaton->per_cu, per_objfile); Alight the last line with the one before: locexpr_describe_location_1 (symbol, addr, stream, loc_ptr, length, addr_size, offset_size, dlbaton->per_cu, per_objfile); > + gdb_printf(stream, "\n"); Space before parenthesis. > diff --git a/gdb/testsuite/gdb.dwarf2/loclists-default-location.exp b/gdb/testsuite/gdb.dwarf2/loclists-default-location.exp > new file mode 100644 > index 00000000000..091cc0e01ed > --- /dev/null > +++ b/gdb/testsuite/gdb.dwarf2/loclists-default-location.exp > @@ -0,0 +1,130 @@ > +# Copyright 2026 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 . > + > +# Test support for DW_LLE_default_location > + > +load_lib dwarf.exp > + > +require dwarf2_support > + > +# Test with 32-bit and 64-bit DWARF. > +foreach_with_prefix is_64 {false true} { > + if { $is_64 } { > + standard_testfile .c -dw64.S > + set testfile ${testfile}-dw64 > + } else { > + standard_testfile .c -dw32.S > + set testfile ${testfile}-dw32 > + } > + > + # Get the addresses / lengths of func1 and func2. > + lassign [function_range func1 $srcdir/$subdir/$srcfile] func1_addr func1_len > + lassign [function_range func2 $srcdir/$subdir/$srcfile] func2_addr func2_len > + > + set asm_file [standard_output_file $srcfile2] > + Dwarf::assemble $asm_file { > + global func1_addr func1_len > + global func2_addr func2_len > + global is_64 > + > + # The CU uses the DW_FORM_loclistx form to refer to the .debug_loclists > + # section. > + cu { > + version 5 > + is_64 $is_64 > + } { > + declare_labels int_type > + > + DW_TAG_compile_unit { > + DW_AT_loclists_base cu_table DW_FORM_sec_offset > + } { > + int_type: DW_TAG_base_type { > + DW_AT_byte_size 4 DW_FORM_data1 > + DW_AT_encoding @DW_ATE_signed > + DW_AT_name "int" > + } > + > + DW_TAG_variable { > + DW_AT_name "x" > + DW_AT_location 0 DW_FORM_loclistx > + DW_AT_type :$int_type > + } > + > + DW_TAG_subprogram { > + DW_AT_name "func1" > + DW_AT_low_pc $func1_addr > + DW_AT_high_pc $func1_len DW_FORM_udata > + } > + > + DW_TAG_subprogram { > + DW_AT_name "func2" > + DW_AT_low_pc $func2_addr > + DW_AT_high_pc $func2_len DW_FORM_udata > + } > + } > + } > + > + loclists {is-64 $is_64} { > + # The lists in this table are accessed by index (DW_FORM_loclistx). > + table {post-header-label cu_table} { > + # With the default location last in the list (default_last) This comment is stale. Simon