forked from Imagelibrary/binutils-gdb
should_validate_memtags uses value_as_address to evalute
whether an address for a value is tagged. The comments for
that function simply say, "Extract a value as a C pointer."
While that sounds innoncuous, that function calls coerce_array,
which will dereference any references. This is not what is
desired here.
This can be demonstrated on an MTE-enabled host, such as aarch64-
based Ampere (example taken from tests introduced in this patch):
(gdb) p b.get_foo ()
Could not validate memory tag: Value can't be converted to integer.
$2 = (const foo &) @0xffffffffed88: {m_a = 42}
While the command completes, gdb didn't actually attempt to
evaluate any memory tags.
Fix this by using unpack_pointer instead.
Tested on x86_64 Fedora 40 and aarch64 RHEL 9.6.
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
/* This testcase is part of GDB, the GNU debugger.
|
|
|
|
Copyright 2025 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 that we can access class method/data member via reference. */
|
|
|
|
struct foo
|
|
{
|
|
foo () : m_a (42) {}
|
|
int get_a () const { return m_a; }
|
|
int m_a;
|
|
};
|
|
|
|
struct bar
|
|
{
|
|
bar () : m_foo () {}
|
|
const foo &get_foo () const { return m_foo; }
|
|
foo m_foo;
|
|
};
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
bar b;
|
|
const foo &ref = b.get_foo ();
|
|
int ret = ref.m_a; // breakpoint here
|
|
ret += ref.get_a ();
|
|
return ret;
|
|
} |