public inbox for gdb-prs@sourceware.org help / color / mirror / Atom feed
From: "vries at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org> To: gdb-prs@sourceware.org Subject: [Bug exp/31693] New: [gdb/exp] cast not handled correctly by indirection Date: Thu, 02 May 2024 12:55:50 +0000 [thread overview] Message-ID: <bug-31693-4717@http.sourceware.org/bugzilla/> (raw) https://sourceware.org/bugzilla/show_bug.cgi?id=31693 Bug ID: 31693 Summary: [gdb/exp] cast not handled correctly by indirection Product: gdb Version: HEAD Status: NEW Severity: normal Priority: P2 Component: exp Assignee: unassigned at sourceware dot org Reporter: vries at gcc dot gnu.org Target Milestone: --- I was reviewing this patch ( https://sourceware.org/pipermail/gdb-patches/2024-May/208737.html ) and came across this description: ... + # On Linux, using -g3, which causes macro information to + # be included in the debuginfo, errno might be defined as + # follows: + # + # #define errno (*__errno_location ()) + # + # So, when we do "ptype errno", due to macro expansion, + # this ends up being "ptype (*__errno_location ())". So + # the call to __errno_location (or something similar on + # other OSes) is the call mentioned in the error message. + # + # For the test "print (int) errno", we're casting the + # result of the expression, which includes both the call + # along with a dereferencing operation. + # + # This will sometimes produce the right answer, but it's + # also just as likely to fail. E.g. on x86_64, if the + # address being returned as a 32-bit int is the same as + # that which would have been returned as a 64-bit pointer, + # then the test might pass. Otherwise, it will almost + # certainly fail, which is why we XFAIL it here. But do + # expect to see the occasional XPASS for this case. ... I tried to reproduce this (in a fedora rawhide container with the check-errno-macros exec) and got: ... (gdb) p errno '__errno_location' has unknown return type; cast the call to its declared return type (gdb) ptype errno '__errno_location' has unknown return type; cast the call to its declared return type (gdb) p __errno_location $9 = {<text variable, no debug info>} 0x7ffff7d10540 <__errno_location> (gdb) ptype __errno_location type = <unknown return type> () (gdb) p __errno_location () '__errno_location' has unknown return type; cast the call to its declared return type (gdb) p *__errno_location () '__errno_location' has unknown return type; cast the call to its declared return type (gdb) p (*__errno_location ()) '__errno_location' has unknown return type; cast the call to its declared return type (gdb) p (int)(*__errno_location ()) Cannot access memory at address 0xfffffffff7ce36c8 (gdb) p (int)(*(int *)__errno_location ()) $10 = 42 (gdb) p /x &(int)*__errno_location () $11 = 0xfffffffff7ce36c8 (gdb) p /x &(int)*(int *)__errno_location () $12 = 0x7ffff7ce36c8 (gdb) p /x &(int)*(int)__errno_location () $3 = 0xfffffffff7ce36c8 ... We known that __errno_location has an unknown return type. We ask for it to be cast before using it. But then when using it nested in a expression we cast it to int. Probably there's a bug in this code expop.h at unop_ind_base_operation: ... value *evaluate (struct type *expect_type, struct expression *exp, enum noside noside) override { if (expect_type != nullptr && expect_type->code () == TYPE_CODE_PTR) expect_type = check_typedef (expect_type)->target_type (); value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside); return eval_op_ind (expect_type, exp, noside, val); } ... We enter with expect_type "int", we should we execute the call with expect_type "int*", but instead we do so with "int". -- You are receiving this mail because: You are on the CC list for the bug.
next reply other threads:[~2024-05-02 12:55 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-05-02 12:55 vries at gcc dot gnu.org [this message] 2024-05-02 12:56 ` [Bug exp/31693] " vries at gcc dot gnu.org 2024-05-02 13:35 ` vries at gcc dot gnu.org 2024-05-02 14:32 ` vries at gcc dot gnu.org 2024-05-02 15:34 ` kevinb at redhat dot com 2024-05-02 15:49 ` vries at gcc dot gnu.org 2024-05-02 15:49 ` tromey at sourceware dot org 2024-05-02 15:54 ` vries at gcc dot gnu.org 2024-05-02 15:57 ` vries at gcc dot gnu.org 2024-05-03 7:37 ` cvs-commit at gcc dot gnu.org 2024-05-03 7:38 ` vries at gcc dot gnu.org 2024-05-04 4:22 ` sam at gentoo 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-31693-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: linkBe 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).