2020-03-26 23:28:08 +08:00
|
|
|
/* DWARF macro support for GDB.
|
|
|
|
|
2023-01-01 20:49:04 +08:00
|
|
|
Copyright (C) 2003-2023 Free Software Foundation, Inc.
|
2020-03-26 23:28:08 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
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/>. */
|
|
|
|
|
|
|
|
#ifndef GDB_DWARF2_MACRO_H
|
|
|
|
#define GDB_DWARF2_MACRO_H
|
|
|
|
|
|
|
|
struct buildsym_compunit;
|
|
|
|
|
gdb: rename dwarf2_per_objfile variables/fields to per_objfile
While doing the psymtab-sharing patchset, I avoided renaming variables
unnecessarily to avoid adding noise to patches, but I'd like to do it
now. Basically, we have these dwarf2 per-something structures:
- dwarf2_per_objfile
- dwarf2_per_bfd
- dwarf2_per_cu_data
I named the instances of dwarf2_per_bfd `per_bfd` and most of instances
of dwarf2_per_cu_data are called `per_cu`. Most pre-existing instances
of dwarf2_per_objfile are named `dwarf2_per_objfile`. For consistency
with the other type, I'd like to rename them to just `per_objfile`. The
`dwarf2_` prefix is superfluous, since it's already clear we are in
dwarf2 code. It also helps reducing the line wrapping by saving 7
precious columns.
gdb/ChangeLog:
* dwarf2/comp-unit.c, dwarf2/comp-unit.h, dwarf2/index-cache.c,
dwarf2/index-cache.h, dwarf2/index-write.c,
dwarf2/index-write.h, dwarf2/line-header.c,
dwarf2/line-header.h, dwarf2/macro.c, dwarf2/macro.h,
dwarf2/read.c, dwarf2/read.h: Rename struct dwarf2_per_objfile
variables and fields from `dwarf2_per_objfile` to just
`per_objfile` throughout.
Change-Id: I3c45cdcc561265e90df82cbd36b4b4ef2fa73aef
2020-05-30 03:15:10 +08:00
|
|
|
extern void dwarf_decode_macros (dwarf2_per_objfile *per_objfile,
|
2020-03-26 23:28:08 +08:00
|
|
|
buildsym_compunit *builder,
|
2020-03-26 23:28:08 +08:00
|
|
|
const dwarf2_section_info *section,
|
2020-03-26 23:28:08 +08:00
|
|
|
const struct line_header *lh,
|
2020-03-26 23:28:08 +08:00
|
|
|
unsigned int offset_size,
|
|
|
|
unsigned int offset,
|
2020-09-21 01:52:59 +08:00
|
|
|
dwarf2_section_info *str_section,
|
|
|
|
dwarf2_section_info *str_offsets_section,
|
gdb: avoid dereferencing empty str_offsets_base optional in dwarf_decode_macros
Since 4d7188abfdf2 ("gdbsupport: add debug assertions in
gdb::optional::get"), some macro-related tests fail on Ubuntu 20.04 with
the system gcc 9.3.0 compiler when building with _GLIBCXX_DEBUG. For
example, gdb.base/info-macros.exp results in:
(gdb) break -qualified main
/home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb_optional.h:206: internal-error: T& gdb::optional<T>::get() [with T = long unsigned int]: Assertion `this->has_value ()' failed.
The binary contains DWARF 4 debug info and includes a pre-standard
(pre-DWARF 5) .debug_macro section. The CU doesn't have a
DW_AT_str_offsets_base attribute (which doesn't exist in DWARF 4). The
field dwarf2_cu::str_offsets_base is therefore empty. At
dwarf2/read.c:24138, we unconditionally read the value in the optional,
which triggers the assertion shown above.
The same thing happens when building the test program with DWARF 5 with
the same gcc compiler, as that version of gcc doesn't use indirect
string forms, even with DWARF 5. So it still doesn't add a
DW_AT_str_offsets_base attribute on the CU.
Fix that by propagating down a gdb::optional<ULONGEST> for the str
offsets base instead of ULONGEST. That value is only used in
dwarf_decode_macro_bytes, when encountering an "strx" macro operation
(DW_MACRO_define_strx or DW_MACRO_undef_strx). Add a check there that
we indeed have a value in the optional before reading it. This is
unlikely to happen, but could happen in theory with an erroneous file
that uses DW_MACRO_define_strx but does not provide a
DW_AT_str_offsets_base (in practice, some things would probably have
failed before and stopped processing of debug info). I tested the
complaint by inverting the condition and using a clang-compiled binary,
which uses the strx operators. This is the result:
During symbol reading: use of DW_MACRO_define_strx with unknown string offsets base [in module /home/simark/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/info-macros/info-macros]
The test now passes cleanly with the setup mentioned above, and the
testsuite looks on par with how it was before 4d7188abfdf2.
Change-Id: I7ebd2724beb7b9b4178872374c2a177aea696e77
2021-08-03 23:31:13 +08:00
|
|
|
gdb::optional<ULONGEST> str_offsets_base,
|
gdb: Fix issue with Clang CLI macros
Clang up to version 15 (current) adds macros that were defined in the
command line or by "other means", according to the Dwarf specification,
after the last DW_MACRO_end_file, instead of before the first
DW_MACRO_start_file, as the specification dictates. When GDB reads the
macros after the last file is closed, the macros never end up "in scope"
and so we can't print them. This has been submitted as a bug to Clang
developers (https://github.com/llvm/llvm-project/issues/54506), and PR
macros/29034 was opened for GDB to keep track of this.
Seeing as there is no expected date for it to be fixed, add a workaround
for all current versions of Clang. The workaround detects when
the main file would be closed and if the producer is Clang, and turns
that operation into a noop, so we keep a reference to the current_file
as those macros are read.
A test case was added to confirm the functionality, and the KFAIL for
running gdb.base/macro-source-path when using clang.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29034
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2022-04-21 01:41:11 +08:00
|
|
|
int section_is_gnu, struct dwarf2_cu *cu);
|
2020-03-26 23:28:08 +08:00
|
|
|
|
|
|
|
#endif /* GDB_DWARF2_MACRO_H */
|