Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Gregori Mignerot <gregori.mignerot@laposte.net>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH] [gdb] Support default locations in DWARF5 loclists
Date: Sun, 26 Apr 2026 00:01:37 -0400	[thread overview]
Message-ID: <e99b1e1d-36d6-44c3-9744-352d50c285ff@simark.ca> (raw)
In-Reply-To: <20260425073939.84434-1-gregori.mignerot@laposte.net>



On 2026-04-25 03:39, Gregori Mignerot wrote:
> @@ -4031,6 +4052,18 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
>  						&low, &high, byte_order,
>  						addr_size, signed_addr_p);
>        loc_ptr = new_ptr;
> +      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;
> +      }
> +

This change doesn't seem right.  It will make it so that we'll read a
length even if the "kind" doesn't imply a length.  That is, when kind is
DEBUG_LOC_END_OF_LIST or DEBUG_LOC_BASE_ADDRESS (or
DEBUG_LOC_BUFFER_OVERFLOW / DEBUG_LOC_INVALID_ENTRY).

> diff --git a/gdb/testsuite/gdb.dwarf2/loclists-default-location.c b/gdb/testsuite/gdb.dwarf2/loclists-default-location.c
> new file mode 100644
> index 00000000000..fc388dcb106
> --- /dev/null
> +++ b/gdb/testsuite/gdb.dwarf2/loclists-default-location.c
> @@ -0,0 +1,37 @@
> +/* Copyright (C) 2026 Free Software Foundation, Inc.
> + *
> + *   This file is part of GDB.
> + *
> + *   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/>.  */

This copyright header is not formatted correctly (there shouldn't be the
leading asterisks.  Copy it from another existing source file in this
directory.

> +	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 first in the list (default_first)
> +		list_ {
> +		    # Applies by default in func2
> +		    default_location {
> +			DW_OP_constu 0x2222
> +			DW_OP_stack_value
> +		    }
> +
> +		    # When in func1.
> +		    start_end $func1_addr "$func1_addr + $func1_len" {
> +			DW_OP_constu 0x1111
> +			DW_OP_stack_value
> +		    }
> +		}

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?

Also, could you add somme checks in the test to exercise
loclist_describe_location?

Simon

      parent reply	other threads:[~2026-04-26  4:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-25  7:39 Gregori Mignerot
2026-04-26  3:21 ` Simon Marchi
2026-04-26  7:47   ` Grégori MIGNEROT
2026-04-26  4:01 ` 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=e99b1e1d-36d6-44c3-9744-352d50c285ff@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