public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "michal.chojnowski at scylladb dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug exp/30271] New: Addresses of static thread_local fields are badly calculated sometimes
Date: Fri, 24 Mar 2023 18:44:23 +0000	[thread overview]
Message-ID: <bug-30271-4717@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=30271

            Bug ID: 30271
           Summary: Addresses of static thread_local fields are badly
                    calculated sometimes
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: exp
          Assignee: unassigned at sourceware dot org
          Reporter: michal.chojnowski at scylladb dot com
  Target Milestone: ---

Created attachment 14779
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14779&action=edit
A patch adding thread_local field handling to value_static_field (possibly in a
wrong manner).

Bottom line:

value_static_field() isn't aware of thread_local fields. It just uses the
address returned by lookup_minimum_symbol() as-is, and for thread_local
variables that's wrong, because in their case the returned value is a TLS
section offset, not the address.

Context:

After we upgraded gdb from 12.1 to 13.1, we noticed that some of our gdb
scripts stopped working because gdb started to evaluate `&a::b` (where `a::b`
is an important `static thread_local` C++ variable) to the TLS offset of `a::b`
instead of its runtime address.
We bisected the problem to commit 3d20b8d99a54382e6e1a6c433e71e0775c6856c6
(`Enable the new DWARF indexer`). When observing the execution of GDB before
and after this patch, we learned that before it the variable would be
successfully looked up via `lookup_symbol_via_quick_fns()`, but after it
`lookup_symbol_via_quick_fns()` doesn't succeed in looking the variable up
(could this be a problem of its own?) and GDB progresses to
`evaluate_expression` -> `value_aggregate_elt` -> `value_static_field` ->
`lookup_minimal_symbol`, and this secondary code path gives the wrong result
because it just can't handle thread_local variables.

I have attached a patch (which I based on some code found in findvars.c) which
fixes our problem. (But I'm clueless about GDB internals, so I can't say
anything about the quality of this patch other than that it solves our
particular case.)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2023-03-24 18:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24 18:44 michal.chojnowski at scylladb dot com [this message]
2023-03-25 16:37 ` [Bug exp/30271] " tromey at sourceware dot org
2023-03-25 16:38 ` tromey at sourceware dot org
2023-03-25 20:28 ` tromey at sourceware dot org
2023-03-26  0:56 ` michal.chojnowski at scylladb dot com
2023-03-26  1:21 ` michal.chojnowski at scylladb dot com
2023-03-31 17:04 ` tromey at sourceware dot org
2023-03-31 17:12 ` tromey at sourceware dot org
2023-03-31 17:54 ` tromey at sourceware dot org
2023-03-31 18:00 ` tromey at sourceware dot org
2023-03-31 18:03 ` tromey at sourceware dot org
2023-05-10 23:28 ` tromey at sourceware dot org
2023-05-15 14:51 ` cvs-commit at gcc dot gnu.org
2023-05-15 15:06 ` michal.chojnowski at scylladb dot com
2023-05-15 15:16 ` cvs-commit at gcc dot gnu.org
2023-05-15 15:17 ` tromey at sourceware dot org

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=bug-30271-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).