Go to file
Kevin Buettner d65befc152 Permit DW_OP_GNU_uninit to be used with DW_OP_piece
This commit implements a fix for a bug reported against GDB on
Fedora bugzilla...

https://bugzilla.redhat.com/show_bug.cgi?id=2166796

The test case in that bug report involved running gdb against the 'jq'
program (which is a command-line JSON processor) on Fedora 37.  Since
the debug info is compiler (and compile-time option) dependent, it
won't necessarily show up in other distributions or even past or
future versions of Fedora.  (E.g. when trying the example shown below
on Fedora 38, GDB says that the value of 'value' has been optimized
out.  I.e. it does not demonstrate the same DWARF error that can be
see when using Fedora 37.)

That said, on Fedora 37, the bug could be reproduced as follows:

[kev@f37-1 ~]$ gdb jq -q -ex 'b src/util.c:415' -ex 'r </dev/null'
Reading symbols from jq...

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.fedoraproject.org/>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Reading symbols from /home/kev/.cache/debuginfod_client/9d3c8b4197350a190a74972d481de32abf641aa4/debuginfo...
No source file named src/util.c.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (src/util.c:415) pending.
Starting program: /usr/bin/jq </dev/null
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Breakpoint 1, jq_util_input_next_input (state=0x55555555d7f0) at src/util.c:416
416	    if (state->parser == NULL) {
(gdb) p value
DWARF-2 expression error: DW_OP_GNU_uninit must always be the very last op.

This is undesirable - rather than output an error about the DWARF
info, we'd prefer to see a value, even if it is uninitialized.

Examination of the debuginfo showed the following:

 <1><468f1>: Abbrev Number: 112 (DW_TAG_subprogram)
    <468f2>   DW_AT_external    : 1
    <468f2>   DW_AT_name        : (indirect string, offset: 0x4781): jq_util_input_next_input
    <468f6>   DW_AT_decl_file   : 10
    <468f6>   DW_AT_decl_line   : 411
    <468f8>   DW_AT_decl_column : 4
    <468f9>   DW_AT_prototyped  : 1
    <468f9>   DW_AT_type        : <0x3f2>
    <468fd>   DW_AT_sibling     : <0x4692e>
...
 <2><46921>: Abbrev Number: 102 (DW_TAG_variable)
    <46922>   DW_AT_name        : (indirect string, offset: 0x8cb): value
    <46926>   DW_AT_decl_file   : 10
    <46926>   DW_AT_decl_line   : 414
    <46928>   DW_AT_decl_column : 6
    <46929>   DW_AT_type        : <0x3f2>

Note that there's no DW_AT_location, so I looked for an abstract origin entry:

 <2><2dfa0>: Abbrev Number: 90 (DW_TAG_variable)
    <2dfa1>   DW_AT_abstract_origin: <0x46921>
    <2dfa5>   DW_AT_location    : 0x27cf1 (location list)
    <2dfa9>   DW_AT_GNU_locviews: 0x27ce1

(Note that the DW_AT_abstract_origin attribute's value is 0x46921 which
is the DIE for the local variable "value".)

Looking at the location list, I see:

    00027cf1 v000000000000000 v000000000000000 views at 00027ce1 for:
             000000000002f8fe 000000000002f92e (DW_OP_reg13 (r13); DW_OP_GNU_uninit; DW_OP_piece: 8; DW_OP_reg12 (r12); DW_OP_GNU_uninit; DW_OP_piece: 8)

While DW_OP_GNU_uninit is not the very last op, it is the last op
prior to DW_OP_piece.  The fix involved changing the DW_OP_GNU_uninit
case in dwarf_expr_context::execute_stack_op in gdb/dwarf2/expr.c so
that DW_OP_GNU_uninit may appear just before DW_OP_piece.

With the fix in place, attempting to print 'value' now looks like
this:

(gdb) p value
$1 =  [uninitialized] {kind_flags = 0 '\000', pad_ = 0 '\000', offset = 0,
  size = 0, u = {ptr = 0x0, number = 0}}

Note that "[uninitialized]" is part of the output.  (But also note
that there's an extra space character.)

I've made a new test case,
gdb.dwarf2/DW_OP_piece_with_DW_OP_GNU_uninit.exp, by adapting an
existing one, gdb.dwarf2/opt-out-not-implptr.exp.  Since it uses the
DWARF assembler, the test case does not depend on a specific compiler
version or compiler options.

Tested on Fedora 37 and Fedora 38.
2023-06-11 15:41:42 -07:00
bfd Automatic date update in version.in 2023-06-11 00:00:09 +00:00
binutils readelf/objdump remember_state memory leaks 2023-06-09 12:56:12 +09:30
config Merge config/picflag.m4 from gcc 2023-01-04 13:23:54 +10:30
contrib Import mklog.py from gcc repo 2020-09-25 10:24:44 -04:00
cpu cpu/mem.opc whitespace tidy 2023-03-16 17:30:19 +10:30
elfcpp Update year range in copyright notice of binutils files 2023-01-01 21:50:11 +10:30
etc Update year range in gprofng copyright notices 2023-01-01 23:26:30 +10:30
gas ecoff find_nearest_line and final link leaks 2023-06-09 12:56:12 +09:30
gdb Permit DW_OP_GNU_uninit to be used with DW_OP_piece 2023-06-11 15:41:42 -07:00
gdbserver [gdb] Fix more typos 2023-06-05 12:53:15 +02:00
gdbsupport Move unrelocated_addr to common-types.h 2023-06-05 09:59:18 -06:00
gnulib Update copyright year range in header of all files managed by GDB 2023-01-01 17:01:16 +04:00
gold MIPS: support mips*64 as CPU and gnuabi64 as ABI 2023-04-23 14:32:43 +08:00
gprof Updated Hungarian translation for the gprof directory 2023-04-19 10:37:33 +01:00
gprofng gprofng: Fix -Wsign-compare warning 2023-05-31 11:46:22 -07:00
include ecoff find_nearest_line and final link leaks 2023-06-09 12:56:12 +09:30
intl egrep in binutils 2022-09-28 13:37:31 +09:30
ld Add extra linker warning message about discrepancies between normal and common symbols. 2023-06-07 14:30:13 +01:00
libbacktrace Ensure that libbacktrace/allocfail.sh is not deleted when creating release tarballs. 2023-01-12 13:39:03 +00:00
libctf libctf, link: fix CU-mapped links with CTF_LINK_EMPTY_CU_MAPPINGS 2023-04-08 16:07:17 +01:00
libdecnumber Merge config/ changes from GCC, to enable DFP on AArch64 2022-05-24 10:47:29 +01:00
libiberty Merge config/picflag.m4 from gcc 2023-01-04 13:23:54 +10:30
libsframe libsframe: testsuite: add sframe_find_fre tests for pltN entries 2023-06-09 11:24:25 -07:00
opcodes MIPS: sync oprand char usage between mips and micromips 2023-06-05 11:14:49 +08:00
readline [readline] Fix double free in _rl_scxt_dispose 2023-05-28 10:17:57 +02:00
sim sim: bpf: update to new BPF relocations 2023-04-26 19:22:14 +02:00
texinfo
zlib Regenerate with automake-1.15.1 2022-07-09 20:10:47 +09:30
.cvsignore
.editorconfig Add top-level .editorconfig file 2022-01-28 08:25:42 -05:00
.gitattributes binutils-gdb/git: highlight whitespace errors in source files 2022-07-25 14:35:41 +01:00
.gitignore Add gnu global outputs to .gitignore 2020-12-02 10:00:27 -05:00
ar-lib
ChangeLog Add a SECURITY.txt file describing the GNU Binutils' project's stance on security related bugs. 2023-04-20 16:52:11 +01:00
compile
config-ml.in
config.guess Update the config.guess and config.sub files from the master repository and regenerate files. 2022-01-17 16:21:22 +00:00
config.rpath
config.sub Update the config.guess and config.sub files from the master repository and regenerate files. 2022-01-17 16:21:22 +00:00
configure configure: remove dependencies on gmp and mpfr when gdb is disabled 2023-01-06 09:32:07 +01:00
configure.ac configure: remove dependencies on gmp and mpfr when gdb is disabled 2023-01-06 09:32:07 +01:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.LIBGLOSS
COPYING.NEWLIB
depcomp
djunpack.bat
install-sh
libtool.m4 libtool.m4: fix the NM="/nm/over/here -B/option/with/path" case 2022-03-25 12:02:35 +00:00
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS: Update path to readline config.{sub,guess} files 2021-05-24 18:11:49 +02:00
Makefile.def toplevel: Makefile.def: add install-strip dependency on libsframe 2023-01-18 23:17:49 -08:00
Makefile.in toplevel: Makefile.def: add install-strip dependency on libsframe 2023-01-18 23:17:49 -08:00
Makefile.tpl Pass PKG_CONFIG_PATH down from top-level Makefile 2022-04-08 10:56:41 -04:00
makefile.vms
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
README-maintainer-mode Note that at least dejagnu version 1.5.3 is required in order to be ale to run the testsuites. 2022-10-04 10:54:19 +01:00
SECURITY.txt Add a SECURITY.txt file describing the GNU Binutils' project's stance on security related bugs. 2023-04-20 16:52:11 +01:00
setup.com
src-release.sh Add a SECURITY.txt file describing the GNU Binutils' project's stance on security related bugs. 2023-04-20 16:52:11 +01:00
symlink-tree
test-driver
ylwrap

		   README for GNU development tools

This directory contains various GNU compilers, assemblers, linkers, 
debuggers, etc., plus their support routines, definitions, and documentation.

If you are receiving this as part of a GDB release, see the file gdb/README.
If with a binutils release, see binutils/README;  if with a libg++ release,
see libg++/README, etc.  That'll give you info about this
package -- supported targets, how to use it, how to report bugs, etc.

It is now possible to automatically configure and build a variety of
tools with one command.  To build all of the tools contained herein,
run the ``configure'' script here, e.g.:

	./configure 
	make

To install them (by default in /usr/local/bin, /usr/local/lib, etc),
then do:
	make install

(If the configure script can't determine your type of computer, give it
the name as an argument, for instance ``./configure sun4''.  You can
use the script ``config.sub'' to test whether a name is recognized; if
it is, config.sub translates it to a triplet specifying CPU, vendor,
and OS.)

If you have more than one compiler on your system, it is often best to
explicitly set CC in the environment before running configure, and to
also set CC when running make.  For example (assuming sh/bash/ksh):

	CC=gcc ./configure
	make

A similar example using csh:

	setenv CC gcc
	./configure
	make

Much of the code and documentation enclosed is copyright by
the Free Software Foundation, Inc.  See the file COPYING or
COPYING.LIB in the various directories, for a description of the
GNU General Public License terms under which you can copy the files.

REPORTING BUGS: Again, see gdb/README, binutils/README, etc., for info
on where and how to report problems.