Simon Marchi 28f15782ad gdb/dwarf: read multiple .debug_info.dwo sections
When building with gcc, with flags -gdwarf-5, -gsplit-dwarf and
-fdebug-types-section, the resulting .dwo files contain multiple
.debug_info.dwo sections.  One for each type unit and one for the
compile unit.  This is correct, as per DWARF 5, section F.2.3 ("Contents
of the Split DWARF Object Files"):

    The split DWARF object files each contain the following sections:

        ...
        .debug_info.dwo (for the compilation unit)
        .debug_info.dwo (one COMDAT section for each type unit)
	...

GDB currently assumes that there is a single .debug_info.dwo section,
causing unpredictable behavior.  For example, sometimes this crash:

    ==81781==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x508000007a71 at pc 0x58704d32a59c bp 0x7ffc0acc0bb0 sp 0x7ffc0acc0ba0
    READ of size 1 at 0x508000007a71 thread T0
        #0 0x58704d32a59b in bfd_getl32 /home/smarchi/src/binutils-gdb/bfd/libbfd.c:846
        #1 0x58704ae62dce in read_initial_length(bfd*, unsigned char const*, unsigned int*, bool) /home/smarchi/src/binutils-gdb/gdb/dwarf2/leb.c:92
        #2 0x58704aaf76bf in read_comp_unit_head(comp_unit_head*, unsigned char const*, dwarf2_section_info*, rcuh_kind) /home/smarchi/src/binutils-gdb/gdb/dwarf2/comp-unit-head.c:47
        #3 0x58704aaf8f97 in read_and_check_comp_unit_head(dwarf2_per_objfile*, comp_unit_head*, dwarf2_section_info*, dwarf2_section_info*, unsigned char const*, rcuh_kind) /home/smarchi/src/binutils-gdb/gdb/dwarf2/comp-unit-head.c:193
        #4 0x58704b022908 in create_dwo_unit_hash_tables /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:6233
        #5 0x58704b0334a5 in open_and_init_dwo_file /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:7588
        #6 0x58704b03965a in lookup_dwo_cutu /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:7935
        #7 0x58704b03a5b1 in lookup_dwo_comp_unit /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:8009
        #8 0x58704aff5b70 in lookup_dwo_unit /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:2802

The first time that locate_dwo_sections gets called for a
.debug_info.dwo section, dwo_sections::info gets initialized properly.
The second time it gets called for a .debug_info.dwo section, the size
field in dwo_sections::info gets overwritten with the size of the second
section.  But the buffer remains pointing to the contents of the first
section, because the section is already "read in".  So the size does not
match the buffer.  And even if it did, we would only keep the
information about one .debug_info.dwo, out of the many.

First, add an assert in locate_dwo_sections to make sure we don't
try to fill in a dwo section info twice.  Add the assert to other
functions with the same pattern, while at it.

Then, change dwo_sections::info to be a vector of sections (just like we
do for type sections).  Update locate_dwo_sections to append to that
vector when seeing a new .debug_info.dwo section.  Update
open_and_init_dwo_file to read the units from each section.

The problem can be observed by running some tests with the
dwarf5-fission-debug-types target board.  For example,
gdb.base/condbreak.exp crashes (with the ASan failure shown above)
before the patch and passes after).

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119766

Change-Id: Iedf275768b6057dee4b1542396714f3d89903cf3
Reviewed-By: Tom de Vries <tdevries@suse.de>
2025-04-29 15:45:33 -04:00
2025-01-19 12:09:01 +00:00
2025-04-29 15:10:11 -04:00
2025-03-29 07:03:46 -07:00
2025-03-10 16:15:42 -04:00
2025-04-25 14:38:11 -06:00
2025-02-28 16:06:25 +00:00

		   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.
Description
Unofficial mirror of sourceware binutils-gdb repository. Updated daily.
Readme 1,005 MiB
Languages
C 50.5%
Makefile 22.7%
Assembly 13.2%
C++ 5.9%
Roff 1.5%
Other 5.6%