From: Simon Marchi <simark@simark.ca>
To: Gregori Mignerot <gregori.mignerot@laposte.net>,
gdb-patches@sourceware.org
Subject: Re: [PATCH v2] [gdb] Support default locations in DWARF5 loclists
Date: Sun, 26 Apr 2026 23:12:56 -0400 [thread overview]
Message-ID: <ac041e7a-5fe3-4342-b97e-90cd0408b7cb@simark.ca> (raw)
In-Reply-To: <20260426115337.1245133-2-gregori.mignerot@laposte.net>
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 <dot><space><space>:
/* 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 <dot><space><space>.
> + 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 <http://www.gnu.org/licenses/>.
> +
> +# 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
prev parent reply other threads:[~2026-04-27 3:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-26 11:40 Gregori Mignerot
2026-04-27 3:12 ` Simon Marchi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ac041e7a-5fe3-4342-b97e-90cd0408b7cb@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=gregori.mignerot@laposte.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox