Files
binutils-gdb/gdb/testsuite/gdb.python/py-sym-artificial.exp
Tom Tromey f78ff4d0dc Treat attributes as code in DWARF assembler
The DWARF assembler treats the 'children' of a DIE as plain Tcl code,
evaluating it in the parent context.

I don't recall why, but when I wrote this code, I didn't do the same
thing for the attributes.  Instead, there I implemented a special
syntax.  I was looking at this today and wondered why I didn't just
use ordinary evaluation as well.

This patch implements this idea.  Attributes are now evaluated as
plain code.  This is a bit less "magical", is slightly shorter due to
lack of braces, and most importantly now allows comments in the
attributes section.

Note that some [subst {}] calls had to be added.  This could be fixed
by changing DWARF expressions to also be plain Tcl code.  I think that
would be a good idea, but I didn't want to tack it on here.

This patch requires the full ("DW_AT_...") name for attributes.  I did
this to avoid any possibility of name clashes.  I've long considered
that my original decision to allow short names for tags and attributes
was a mistake.  It's worth noting that many existing tests already
used the long names here.

Most of this patch was written by script.  The main changes are in
dwarf.exp, but as noted, there were some minor fixups needed in some
tests.

Also, after committing, 'git show' indicated some whitespace issues,
so I've gone through and "tabified" some things, which is why the
patch might be otherwise larger than it should be.  (This was
discussed a bit during the v1 submission.)

v1 was here:

https://inbox.sourceware.org/gdb-patches/20250530183845.2179955-1-tromey@adacore.com/

In v2 I've rebased and fixed up various tests that either changed or
were added since v1.

Regression tested on x86-64 Fedora 41.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-09-16 09:25:44 -06:00

63 lines
1.6 KiB
Plaintext

# Copyright (C) 2024-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 gdb.Symbol.artificial.
load_lib dwarf.exp
load_lib gdb-python.exp
require dwarf2_support allow_python_tests
# Just use a no-op main.
standard_testfile py-arch.c -dw.S
set asm_file [standard_output_file ${srcfile2}]
Dwarf::assemble $asm_file {
cu {} {
compile_unit {
DW_AT_language @DW_LANG_C
DW_AT_name py-sym-artificial.c
} {
declare_labels signed
signed: DW_TAG_base_type {
DW_AT_byte_size 1 DW_FORM_sdata
DW_AT_encoding @DW_ATE_signed
DW_AT_name bool
}
DW_TAG_variable {
DW_AT_name the_variable
DW_AT_type :$signed
DW_AT_artificial 1 DW_FORM_flag_present
}
}
}
}
if {[prepare_for_testing "failed to prepare" ${testfile} \
[list $srcfile $asm_file] {nodebug}]} {
return -1
}
if {![runto_main]} {
return -1
}
gdb_py_test_silent_cmd "python v = gdb.lookup_symbol('the_variable')" \
"get variable" 1
gdb_test "python print(v\[0\].is_artificial)" True \
"variable is artificial"