From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A498F3851ABD; Fri, 24 Mar 2023 18:44:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A498F3851ABD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679683463; bh=v3NL7rKv5+tDWOGa1X5Lx5OijhD3XZzwkv/VCuk675s=; h=From:To:Subject:Date:From; b=Wk7VNAA8XJEhMVJUDGk0Q3dmhDjH8Zw45EVaegck1FdtX+b2imDCWc43UlG0WUK04 VD1oMlNTTelRs0SIL/fdPCHxdMTvgBqixnSMvD7NDDjfqMQI+zREWhoZNlzU94YHr/ Ztv/0uEkY7O7JsWSMvio7L6naH+ytNp16FG84yXM= From: "michal.chojnowski at scylladb dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: exp X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: michal.chojnowski at scylladb dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30271 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=3D14779&action=3Ded= it 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) wh= ich 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.) --=20 You are receiving this mail because: You are on the CC list for the bug.=