aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.pre-commit-config.yaml6
-rw-r--r--bfd/aout-target.h4
-rw-r--r--bfd/aoutx.h9
-rw-r--r--bfd/coffgen.c18
-rw-r--r--bfd/cofflink.c47
-rw-r--r--bfd/elflink.c11
-rw-r--r--bfd/elfxx-aarch64.c32
-rw-r--r--bfd/elfxx-x86.c20
-rw-r--r--bfd/format.c45
-rw-r--r--bfd/i386aout.c1
-rw-r--r--bfd/libaout.h7
-rw-r--r--bfd/pdp11.c9
-rw-r--r--bfd/version.h2
-rw-r--r--binutils/doc/binutils.texi8
-rw-r--r--binutils/resbin.c768
-rw-r--r--binutils/rescoff.c288
-rw-r--r--binutils/resrc.c9
-rw-r--r--binutils/resres.c42
-rw-r--r--binutils/windres.c30
-rw-r--r--binutils/windres.h6
-rw-r--r--gas/config/loongarch-parse.y32
-rw-r--r--gas/config/tc-aarch64.c2
-rw-r--r--gas/config/tc-aarch64.h2
-rw-r--r--gas/config/tc-i386.c2
-rw-r--r--gas/config/tc-i386.h2
-rw-r--r--gas/config/tc-m68k.c15
-rw-r--r--gas/gen-sframe.c4
-rw-r--r--gas/testsuite/gas/aarch64/pac_ab_key.d2
-rw-r--r--gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.d2
-rw-r--r--gas/testsuite/gas/aarch64/pac_negate_ra_state.d2
-rw-r--r--gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.d21
-rw-r--r--gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.s4
-rw-r--r--gas/testsuite/gas/cfi-sframe/cfi-sframe.exp1
-rw-r--r--gas/testsuite/gas/loongarch/div_zero.l4
-rw-r--r--gas/testsuite/gas/loongarch/div_zero.s2
-rw-r--r--gas/testsuite/gas/loongarch/fix_op.d3
-rw-r--r--gas/testsuite/gas/loongarch/fix_op.s5
-rw-r--r--gas/testsuite/gas/loongarch/insn_alias_32.d3
-rw-r--r--gas/testsuite/gas/loongarch/insn_alias_32.s5
-rw-r--r--gas/testsuite/gas/loongarch/loongarch.exp1
-rw-r--r--gdb/MAINTAINERS1
-rw-r--r--gdb/Makefile.in5
-rw-r--r--gdb/NEWS33
-rw-r--r--gdb/aarch64-linux-tdep.c56
-rw-r--r--gdb/ada-lang.c115
-rw-r--r--gdb/ada-varobj.c14
-rw-r--r--gdb/amd64-linux-tdep.c38
-rw-r--r--gdb/cli/cli-cmds.c2
-rw-r--r--gdb/cli/cli-decode.h2
-rw-r--r--gdb/cli/cli-dump.c2
-rw-r--r--gdb/config/djgpp/README2
-rw-r--r--gdb/config/djgpp/djconfig.sh2
-rwxr-xr-xgdb/configure2
-rw-r--r--gdb/configure.ac2
-rw-r--r--gdb/configure.tgt14
-rwxr-xr-xgdb/contrib/cc-with-tweaks.sh5
-rwxr-xr-xgdb/copyright.py101
-rw-r--r--gdb/corelow.c38
-rw-r--r--gdb/disasm-selftests.c87
-rw-r--r--gdb/disasm-selftests.h32
-rw-r--r--gdb/doc/gdb.texinfo84
-rw-r--r--gdb/doc/python.texi31
-rw-r--r--gdb/dwarf2/attribute.c40
-rw-r--r--gdb/dwarf2/attribute.h32
-rw-r--r--gdb/dwarf2/comp-unit-head.c23
-rw-r--r--gdb/dwarf2/comp-unit-head.h7
-rw-r--r--gdb/dwarf2/cooked-indexer.c4
-rw-r--r--gdb/dwarf2/cu.h9
-rw-r--r--gdb/dwarf2/die.c3
-rw-r--r--gdb/dwarf2/dwz.c193
-rw-r--r--gdb/dwarf2/dwz.h25
-rw-r--r--gdb/dwarf2/macro.c1
-rw-r--r--gdb/dwarf2/read.c485
-rw-r--r--gdb/dwarf2/read.h44
-rw-r--r--gdb/dwarf2/section.h13
-rw-r--r--gdb/eval.c5
-rw-r--r--gdb/findvar.c3
-rw-r--r--gdb/infrun.c27
-rw-r--r--gdb/infrun.h3
-rw-r--r--gdb/linux-tdep.c1
-rw-r--r--gdb/maint.h3
-rw-r--r--gdb/microblaze-linux-tdep.c3
-rw-r--r--gdb/minsyms.c3
-rw-r--r--gdb/pager.h1
-rw-r--r--gdb/ppc-linux-tdep.c63
-rw-r--r--gdb/printcmd.c2
-rw-r--r--gdb/python/lib/gdb/dap/__init__.py1
-rw-r--r--gdb/python/lib/gdb/dap/breakpoint.py4
-rw-r--r--gdb/python/lib/gdb/dap/events.py1
-rw-r--r--gdb/python/lib/gdb/dap/frames.py6
-rw-r--r--gdb/python/lib/gdb/dap/globalvars.py1
-rw-r--r--gdb/python/lib/gdb/dap/launch.py1
-rw-r--r--gdb/python/lib/gdb/dap/scopes.py3
-rw-r--r--gdb/python/lib/gdb/dap/server.py11
-rw-r--r--gdb/python/lib/gdb/dap/sources.py3
-rw-r--r--gdb/python/lib/gdb/dap/varref.py3
-rw-r--r--gdb/python/lib/gdb/styling.py1
-rw-r--r--gdb/python/py-breakpoint.c2
-rw-r--r--gdb/python/py-color.c70
-rw-r--r--gdb/python/py-disasm.c11
-rw-r--r--gdb/python/py-registers.c3
-rw-r--r--gdb/python/py-unwind.c6
-rw-r--r--gdb/python/py-value.c3
-rw-r--r--gdb/remote.c14
-rw-r--r--gdb/riscv-canonicalize-syscall-gen.c358
-rw-r--r--gdb/riscv-linux-tdep.c335
-rw-r--r--gdb/riscv-linux-tdep.h29
-rw-r--r--gdb/riscv-tdep.c686
-rw-r--r--gdb/riscv-tdep.h16
-rw-r--r--gdb/s390-linux-tdep.c44
-rw-r--r--gdb/s390-tdep.c52
-rw-r--r--gdb/solib-svr4.c267
-rw-r--r--gdb/solib-svr4.h12
-rw-r--r--gdb/solib.c269
-rw-r--r--gdb/solist.h4
-rw-r--r--gdb/svr4-tls-tdep.c256
-rw-r--r--gdb/svr4-tls-tdep.h59
-rwxr-xr-xgdb/syscalls/riscv-canonicalize-syscall-gen.py171
-rw-r--r--gdb/target.c16
-rw-r--r--gdb/target.h8
-rwxr-xr-xgdb/testsuite/analyze-racy-logs.py3
-rw-r--r--gdb/testsuite/boards/cc-with-dwz-5.exp28
-rw-r--r--gdb/testsuite/gdb.ada/scalar_storage.exp28
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.c205
-rw-r--r--gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.exp106
-rw-r--r--gdb/testsuite/gdb.base/bg-execution-repeat.c2
-rw-r--r--gdb/testsuite/gdb.base/bg-execution-repeat.exp11
-rw-r--r--gdb/testsuite/gdb.base/break1.c8
-rw-r--r--gdb/testsuite/gdb.base/corefile3.c118
-rw-r--r--gdb/testsuite/gdb.base/corefile3.exp71
-rw-r--r--gdb/testsuite/gdb.base/default.exp2
-rw-r--r--gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c6
-rw-r--r--gdb/testsuite/gdb.base/dlmopen-ns-ids.exp153
-rw-r--r--gdb/testsuite/gdb.base/printcmds.exp7
-rw-r--r--gdb/testsuite/gdb.base/tls-common.exp.tcl50
-rw-r--r--gdb/testsuite/gdb.base/tls-dlobj-lib.c87
-rw-r--r--gdb/testsuite/gdb.base/tls-dlobj.c311
-rw-r--r--gdb/testsuite/gdb.base/tls-dlobj.exp378
-rw-r--r--gdb/testsuite/gdb.base/tls-multiobj.c89
-rw-r--r--gdb/testsuite/gdb.base/tls-multiobj.exp230
-rw-r--r--gdb/testsuite/gdb.base/tls-multiobj1.c26
-rw-r--r--gdb/testsuite/gdb.base/tls-multiobj2.c26
-rw-r--r--gdb/testsuite/gdb.base/tls-multiobj3.c26
-rw-r--r--gdb/testsuite/gdb.base/tls-nothreads.c57
-rw-r--r--gdb/testsuite/gdb.base/tls-nothreads.exp248
-rw-r--r--gdb/testsuite/gdb.cp/cplusfuncs.exp3
-rw-r--r--gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp2
-rw-r--r--gdb/testsuite/gdb.dwarf2/dwzbuildid.exp159
-rw-r--r--gdb/testsuite/gdb.dwarf2/dwzbuildid.tcl184
-rw-r--r--gdb/testsuite/gdb.dwarf2/dwzbuildid5.exp17
-rw-r--r--gdb/testsuite/gdb.dwarf2/dwznolink.exp2
-rw-r--r--gdb/testsuite/gdb.dwarf2/fission-with-type-unit.exp4
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw4.exp71
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw5.exp75
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld234-dw5.exp70
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw4.exp70
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw5.exp81
-rw-r--r--gdb/testsuite/gdb.dwarf2/macro-source-path.exp.tcl (renamed from gdb/testsuite/gdb.dwarf2/macro-source-path.exp)250
-rw-r--r--gdb/testsuite/gdb.dwarf2/no-gnu-debuglink.exp2
-rw-r--r--gdb/testsuite/gdb.python/gdb_leak_detector.py121
-rw-r--r--gdb/testsuite/gdb.python/py-breakpoint.exp2
-rw-r--r--gdb/testsuite/gdb.python/py-color-leak.exp28
-rw-r--r--gdb/testsuite/gdb.python/py-color-leak.py31
-rw-r--r--gdb/testsuite/gdb.python/py-color.exp63
-rw-r--r--gdb/testsuite/gdb.python/py-disasm.exp.tcl5
-rw-r--r--gdb/testsuite/gdb.python/py-disasm.py18
-rw-r--r--gdb/testsuite/gdb.python/py-frame.exp15
-rw-r--r--gdb/testsuite/gdb.python/py-inferior-leak.exp14
-rw-r--r--gdb/testsuite/gdb.python/py-inferior-leak.py107
-rw-r--r--gdb/testsuite/gdb.python/py-read-memory-leak.exp14
-rw-r--r--gdb/testsuite/gdb.python/py-read-memory-leak.py84
-rw-r--r--gdb/testsuite/gdb.python/py-unwind.exp7
-rw-r--r--gdb/testsuite/gdb.python/py-unwind.py20
-rw-r--r--gdb/testsuite/gdb.server/no-thread-db.exp4
-rw-r--r--gdb/testsuite/gdb.threads/clone-attach-detach.exp2
-rw-r--r--gdb/testsuite/gdb.threads/tls.exp2
-rw-r--r--gdb/testsuite/lib/dwarf.exp18
-rw-r--r--gdb/testsuite/lib/gdb-python.exp21
-rw-r--r--gdb/testsuite/lib/gdb.exp3
-rw-r--r--gdb/ui-file.c12
-rw-r--r--gdb/ui-file.h17
-rw-r--r--gdb/ui-style.c17
-rw-r--r--gdb/unittests/remote-arg-selftests.c166
-rw-r--r--gdb/unittests/rsp-low-selftests.c2
-rw-r--r--gdb/utils.c12
-rw-r--r--gdb/valops.c28
-rw-r--r--gdb/value.h5
-rw-r--r--gdbserver/server.cc3
-rw-r--r--gdbsupport/Makefile.am1
-rw-r--r--gdbsupport/Makefile.in14
-rw-r--r--gdbsupport/common-utils.h10
-rw-r--r--gdbsupport/remote-args.cc43
-rw-r--r--gdbsupport/remote-args.h60
-rw-r--r--gprofng/doc/gprofng_ug.texi5
-rw-r--r--gprofng/src/CallStack.cc10
-rw-r--r--gprofng/src/gp-archive.cc3
-rw-r--r--gprofng/src/gp-collect-app.cc3
-rw-r--r--gprofng/src/gp-display-src.cc3
-rw-r--r--gprofng/src/gp-display-text.cc3
-rw-r--r--gprofng/src/gprofng.cc3
-rw-r--r--ld/emultempl/pe.em13
-rw-r--r--ld/emultempl/pep.em19
-rw-r--r--ld/ld.texi11
-rw-r--r--ld/ldlang.c3
-rw-r--r--ld/ldmain.c6
-rw-r--r--ld/ldmisc.c10
-rw-r--r--ld/testsuite/ld-aarch64/protections/bti-and-memory-seal-plt-1-a.d45
-rw-r--r--ld/testsuite/ld-aarch64/protections/bti-and-memory-seal-plt-1-b.d14
-rw-r--r--ld/testsuite/ld-aarch64/protections/bti-plt-1-b.d2
-rw-r--r--ld/testsuite/ld-plugin/lto.exp32
-rw-r--r--ld/testsuite/ld-plugin/pr32846a.c6
-rw-r--r--ld/testsuite/ld-plugin/pr32846b.c4
-rw-r--r--ld/testsuite/ld-plugin/pr32846c.c6
-rw-r--r--ld/testsuite/ld-plugin/pr32846d.c12
-rw-r--r--ld/testsuite/ld-plugin/pr32846e.c4
-rw-r--r--opcodes/i386-gen.c4
-rw-r--r--opcodes/i386-init.h30
-rw-r--r--opcodes/i386-opc.h12
-rw-r--r--opcodes/i386-tbl.h16
-rw-r--r--opcodes/loongarch-opc.c6
-rw-r--r--opcodes/riscv-dis.c6
221 files changed, 8482 insertions, 1907 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 488e781..b55685b 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -46,7 +46,7 @@ repos:
types_or: [file]
files: 'gdb/.*\.py(\.in)?$'
- repo: https://github.com/pycqa/flake8
- rev: 7.1.1
+ rev: 7.2.0
hooks:
- id: flake8
types_or: [file]
@@ -60,7 +60,7 @@ repos:
files: '^gdb/(gdb-gdb\.py\.in|[^/]+\.py|python/.+\.py|testsuite/[^/]+\.py)$'
args: [--config, gdb/setup.cfg]
- repo: https://github.com/pycqa/isort
- rev: 6.0.0
+ rev: 6.0.1
hooks:
- id: isort
types_or: [file]
@@ -69,7 +69,7 @@ repos:
rev: v2.4.1
hooks:
- id: codespell
- files: '^(gdbsupport|gdbserver|gdb/(tui|target|data-directory|po|system-gdbinit|mi|syscalls|arch|regformats|compile|python|guile))/'
+ files: '^(gdbsupport|gdbserver|gdb/(tui|target|data-directory|po|system-gdbinit|mi|syscalls|arch|regformats|compile|python|guile|config|unittests|cli))/'
args: [--config, gdb/contrib/setup.cfg]
- repo: local
hooks:
diff --git a/bfd/aout-target.h b/bfd/aout-target.h
index f513e1b..1b71104 100644
--- a/bfd/aout-target.h
+++ b/bfd/aout-target.h
@@ -286,9 +286,6 @@ MY (set_sizes) (bfd *abfd)
#ifndef MY_add_dynamic_symbols
#define MY_add_dynamic_symbols 0
#endif
-#ifndef MY_add_one_symbol
-#define MY_add_one_symbol 0
-#endif
#ifndef MY_link_dynamic_object
#define MY_link_dynamic_object 0
#endif
@@ -312,7 +309,6 @@ static const struct aout_backend_data MY (backend_data) =
MY_set_sizes,
MY_exec_header_not_counted,
MY_add_dynamic_symbols,
- MY_add_one_symbol,
MY_link_dynamic_object,
MY_write_dynamic_symbol,
MY_check_dynamic_reloc,
diff --git a/bfd/aoutx.h b/bfd/aoutx.h
index 63c654f..81e0804 100644
--- a/bfd/aoutx.h
+++ b/bfd/aoutx.h
@@ -2973,9 +2973,6 @@ NAME (aout, link_hash_table_create) (bfd *abfd)
static bool
aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
{
- bool (*add_one_symbol)
- (struct bfd_link_info *, bfd *, const char *, flagword, asection *,
- bfd_vma, const char *, bool, bool, struct bfd_link_hash_entry **);
struct external_nlist *syms;
bfd_size_type sym_count;
char *strings;
@@ -3013,10 +3010,6 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
return false;
obj_aout_sym_hashes (abfd) = sym_hash;
- add_one_symbol = aout_backend_info (abfd)->add_one_symbol;
- if (add_one_symbol == NULL)
- add_one_symbol = _bfd_generic_link_add_one_symbol;
-
p = syms;
pend = p + sym_count;
for (; p < pend; p++, sym_hash++)
@@ -3167,7 +3160,7 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
break;
}
- if (! ((*add_one_symbol)
+ if (! (_bfd_generic_link_add_one_symbol
(info, abfd, name, flags, section, value, string, copy, false,
(struct bfd_link_hash_entry **) sym_hash)))
return false;
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index f87e54f..ab4d790 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -42,6 +42,7 @@
#include "libbfd.h"
#include "coff/internal.h"
#include "libcoff.h"
+#include "elf-bfd.h"
#include "hashtab.h"
/* Extract a long section name at STRINDEX and copy it to the bfd objstack.
@@ -1270,9 +1271,24 @@ coff_write_alien_symbol (bfd *abfd,
if (c != (coff_symbol_type *) NULL)
native->u.syment.n_flags = bfd_asymbol_bfd (&c->symbol)->flags;
}
+
+ const elf_symbol_type *elfsym = elf_symbol_from (symbol);
+ if (elfsym
+ && (symbol->flags & BSF_FUNCTION)
+ && elfsym->internal_elf_sym.st_size)
+ {
+ /* coff_data (abfd)->local_n_btshft is what ought to be used here,
+ just that it's set only when reading in COFF objects. */
+ native->u.syment.n_type = DT_FCN << 4;
+ native->u.syment.n_numaux = 1;
+ native[1].u.auxent.x_sym.x_misc.x_fsize
+ = elfsym->internal_elf_sym.st_size;
+ /* FIXME .u.auxent.x_sym.x_fcnary.x_fcn.x_endndx would better also
+ be set, which would require updating the field once the next
+ function is seen. */
+ }
}
- native->u.syment.n_type = 0;
if (symbol->flags & BSF_FILE)
native->u.syment.n_sclass = C_FILE;
else if (symbol->flags & BSF_LOCAL)
diff --git a/bfd/cofflink.c b/bfd/cofflink.c
index 501731b..38278e2 100644
--- a/bfd/cofflink.c
+++ b/bfd/cofflink.c
@@ -27,6 +27,7 @@
#include "libbfd.h"
#include "coff/internal.h"
#include "libcoff.h"
+#include "elf-bfd.h"
#include "safe-ctype.h"
static bool coff_link_add_object_symbols (bfd *, struct bfd_link_info *);
@@ -931,14 +932,52 @@ _bfd_coff_final_link (bfd *abfd,
bfd_vma written = 0;
bool rewrite = false;
- if (! (sym->flags & BSF_LOCAL)
- || (sym->flags & (BSF_SECTION_SYM | BSF_DEBUGGING_RELOC
- | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC
- | BSF_SYNTHETIC))
+ if ((sym->flags & (BSF_SECTION_SYM | BSF_DEBUGGING_RELOC
+ | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC
+ | BSF_SYNTHETIC))
|| ((sym->flags & BSF_DEBUGGING)
&& ! (sym->flags & BSF_FILE)))
continue;
+ if (! (sym->flags & BSF_LOCAL))
+ {
+ /* For ELF symbols try to represent their function-ness and
+ size, if available. */
+ if (! (sym->flags & BSF_FUNCTION))
+ continue;
+
+ const elf_symbol_type *elfsym = elf_symbol_from (sym);
+ if (!elfsym)
+ continue;
+
+ struct coff_link_hash_entry *hent
+ = (struct coff_link_hash_entry *) bfd_hash_lookup
+ (&info->hash->table, bfd_asymbol_name (sym),
+ false, false);
+ if (!hent)
+ continue;
+
+ /* coff_data (abfd)->local_n_btshft is what ought to be used
+ here, just that it's set only when reading in COFF
+ objects. */
+ hent->type = DT_FCN << 4;
+ if (!elfsym->internal_elf_sym.st_size)
+ continue;
+
+ hent->aux = bfd_zalloc (abfd, sizeof (*hent->aux));
+ if (!hent->aux)
+ continue;
+
+ hent->numaux = 1;
+ hent->aux->x_sym.x_misc.x_fsize
+ = elfsym->internal_elf_sym.st_size;
+ /* FIXME ->x_sym.x_fcnary.x_fcn.x_endndx would better
+ also be set, yet that would likely need to happen
+ elsewhere anyway. */
+
+ continue;
+ }
+
/* See if we are discarding symbols with this name. */
if ((flaginfo.info->strip == strip_some
&& (bfd_hash_lookup (flaginfo.info->keep_hash,
diff --git a/bfd/elflink.c b/bfd/elflink.c
index a76e8e3..919f2a7 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -6290,8 +6290,8 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
continue;
/* In the pre-LTO-plugin pass we must not mistakenly
- include this archive member if an earlier BFD
- defined this symbol. */
+ include this archive member if an earlier shared
+ library defined this symbol. */
struct elf_link_hash_table *htab = elf_hash_table (info);
if (htab->first_hash)
{
@@ -6299,7 +6299,9 @@ elf_link_add_archive_symbols (bfd *abfd, struct bfd_link_info *info)
= ((struct elf_link_first_hash_entry *)
bfd_hash_lookup (htab->first_hash, symdef->name,
false, false));
- if (e && e->abfd != abfd)
+ if (e
+ && (e->abfd->flags & DYNAMIC) != 0
+ && e->abfd != abfd)
continue;
}
}
@@ -14408,7 +14410,8 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info)
if (o->flags & SEC_GROUP)
{
asection *first = elf_next_in_group (o);
- o->gc_mark = first->gc_mark;
+ if (first != NULL)
+ o->gc_mark = first->gc_mark;
}
if (o->gc_mark)
diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c
index 45a0205..68e004ef 100644
--- a/bfd/elfxx-aarch64.c
+++ b/bfd/elfxx-aarch64.c
@@ -930,28 +930,20 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info)
GNU properties (if found). */
bfd *pbfd = _bfd_elf_link_setup_gnu_properties (info);
- /* If pbfd has any GNU_PROPERTY_AARCH64_FEATURE_1_AND properties, update
- outprop accordingly. */
if (pbfd != NULL)
{
- /* The property list is sorted in order of type. */
- for (elf_property_list *p = elf_properties (pbfd);
- (p != NULL)
- && (GNU_PROPERTY_AARCH64_FEATURE_1_AND <= p->property.pr_type);
- p = p->next)
- {
- /* This merge of features should happen only once as all the identical
- properties are supposed to have been merged at this stage by
- _bfd_elf_link_setup_gnu_properties(). */
- if (p->property.pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
- {
- outprop = (p->property.u.number
- & (GNU_PROPERTY_AARCH64_FEATURE_1_BTI
- | GNU_PROPERTY_AARCH64_FEATURE_1_PAC
- | GNU_PROPERTY_AARCH64_FEATURE_1_GCS));
- break;
- }
- }
+ elf_property_list *p;
+ elf_property_list *plist = elf_properties (pbfd);
+
+ /* If pbfd has any GNU_PROPERTY_AARCH64_FEATURE_1_AND properties, update
+ outprop accordingly. */
+ if ((p = _bfd_elf_find_property (plist,
+ GNU_PROPERTY_AARCH64_FEATURE_1_AND, NULL))
+ != NULL)
+ outprop = p->property.u.number
+ & (GNU_PROPERTY_AARCH64_FEATURE_1_BTI
+ | GNU_PROPERTY_AARCH64_FEATURE_1_PAC
+ | GNU_PROPERTY_AARCH64_FEATURE_1_GCS);
}
tdata->gnu_property_aarch64_feature_1_and = outprop;
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 6ea41f2..bc9bb70 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -609,8 +609,7 @@ _bfd_elf_x86_get_local_sym_hash (struct elf_x86_link_hash_table *htab,
return &ret->elf;
}
-/* Create an entry in a x86 ELF linker hash table. NB: THIS MUST BE IN
- SYNC WITH _bfd_elf_link_hash_newfunc. */
+/* Create an entry in an x86 ELF linker hash table. */
struct bfd_hash_entry *
_bfd_x86_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
@@ -629,27 +628,14 @@ _bfd_x86_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
}
/* Call the allocation method of the superclass. */
- entry = _bfd_link_hash_newfunc (entry, table, string);
+ entry = _bfd_elf_link_hash_newfunc (entry, table, string);
if (entry != NULL)
{
struct elf_x86_link_hash_entry *eh
= (struct elf_x86_link_hash_entry *) entry;
- struct elf_link_hash_table *htab
- = (struct elf_link_hash_table *) table;
- memset (&eh->elf.size, 0,
- (sizeof (struct elf_x86_link_hash_entry)
- - offsetof (struct elf_link_hash_entry, size)));
+ memset (&eh->elf + 1, 0, sizeof (*eh) - sizeof (eh->elf));
/* Set local fields. */
- eh->elf.indx = -1;
- eh->elf.dynindx = -1;
- eh->elf.got = htab->init_got_refcount;
- eh->elf.plt = htab->init_plt_refcount;
- /* Assume that we have been called by a non-ELF symbol reader.
- This flag is then reset by the code which reads an ELF input
- file. This ensures that a symbol created by a non-ELF symbol
- reader will have the flag set correctly. */
- eh->elf.non_elf = 1;
eh->plt_second.offset = (bfd_vma) -1;
eh->plt_got.offset = (bfd_vma) -1;
eh->tlsdesc_got = (bfd_vma) -1;
diff --git a/bfd/format.c b/bfd/format.c
index 7769ad0..a909b70 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -331,6 +331,25 @@ print_and_clear_messages (struct per_xvec_messages *list,
free (iter);
iter = next;
}
+
+ /* Don't retain a pointer to free'd memory. */
+ list->next = NULL;
+}
+
+/* Discard all messages associated with TARG in LIST. Unlike
+ print_and_clear_messages, PER_XVEC_NO_TARGET is not valid for TARG. */
+
+static void
+clear_messages (struct per_xvec_messages *list,
+ const bfd_target *targ)
+{
+ struct per_xvec_messages *iter;
+
+ for (iter = list; iter != NULL; iter = iter->next)
+ {
+ if (iter->targ == targ)
+ clear_warnmsg (&iter->messages);
+ }
}
/* This a copy of lto_section defined in GCC (lto-streamer.h). */
@@ -451,7 +470,18 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
/* Avoid clashes with bfd_cache_close_all running in another
thread. */
if (!bfd_cache_set_uncloseable (abfd, true, &old_in_format_matches))
- return false;
+ {
+ free (matching_vector);
+ return false;
+ }
+
+ /* Locking is required here in order to manage _bfd_section_id. */
+ if (!bfd_lock ())
+ {
+ bfd_cache_set_uncloseable (abfd, old_in_format_matches, NULL);
+ free (matching_vector);
+ return false;
+ }
/* Presume the answer is yes. */
abfd->format = format;
@@ -461,10 +491,6 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
of an archive. */
orig_messages = _bfd_set_error_handler_caching (&messages);
- /* Locking is required here in order to manage _bfd_section_id. */
- if (!bfd_lock ())
- return false;
-
preserve_match.marker = NULL;
if (!bfd_preserve_save (abfd, &preserve, NULL))
goto err_ret;
@@ -545,6 +571,12 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
/* Change BFD's target temporarily. */
abfd->xvec = *target;
+ /* It is possible that targets appear multiple times in
+ bfd_target_vector. If this is the case, then we want to avoid
+ accumulating duplicate messages for a target in MESSAGES, so
+ discard any previous messages associated with this target. */
+ clear_messages (&messages, abfd->xvec);
+
if (bfd_seek (abfd, 0, SEEK_SET) != 0)
goto err_ret;
@@ -754,7 +786,8 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
out:
if (preserve_match.marker != NULL)
bfd_preserve_finish (abfd, &preserve_match);
- bfd_preserve_restore (abfd, &preserve);
+ if (preserve.marker != NULL)
+ bfd_preserve_restore (abfd, &preserve);
_bfd_restore_error_handler_caching (orig_messages);
print_and_clear_messages (&messages, PER_XVEC_NO_TARGET);
bfd_cache_set_uncloseable (abfd, old_in_format_matches, NULL);
diff --git a/bfd/i386aout.c b/bfd/i386aout.c
index fb09597..082ebfb 100644
--- a/bfd/i386aout.c
+++ b/bfd/i386aout.c
@@ -79,7 +79,6 @@ static const struct aout_backend_data MY (backend_data) =
MY (set_sizes),
1, /* Exec header not counted. */
0, /* Add_dynamic_symbols. */
- 0, /* Add_one_symbol. */
0, /* Link_dynamic_object. */
0, /* Write_dynamic_symbol. */
0, /* Check_dynamic_reloc. */
diff --git a/bfd/libaout.h b/bfd/libaout.h
index ca4faec..7628d6a 100644
--- a/bfd/libaout.h
+++ b/bfd/libaout.h
@@ -177,13 +177,6 @@ struct aout_backend_data
(bfd *, struct bfd_link_info *, struct external_nlist **,
bfd_size_type *, char **);
- /* Callback from the add symbols phase of the linker code to handle
- adding a single symbol to the global linker hash table. */
- bool (*add_one_symbol)
- (struct bfd_link_info *, bfd *, const char *, flagword,
- asection *, bfd_vma, const char *, bool, bool,
- struct bfd_link_hash_entry **);
-
/* Called to handle linking a dynamic object. */
bool (*link_dynamic_object)
(struct bfd_link_info *, bfd *);
diff --git a/bfd/pdp11.c b/bfd/pdp11.c
index bdd9fc2..2d12033 100644
--- a/bfd/pdp11.c
+++ b/bfd/pdp11.c
@@ -2839,9 +2839,6 @@ aout_link_check_archive_element (bfd *abfd,
static bool
aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
{
- bool (*add_one_symbol)
- (struct bfd_link_info *, bfd *, const char *, flagword, asection *,
- bfd_vma, const char *, bool, bool, struct bfd_link_hash_entry **);
struct external_nlist *syms;
bfd_size_type sym_count;
char *strings;
@@ -2875,10 +2872,6 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
return false;
obj_aout_sym_hashes (abfd) = sym_hash;
- add_one_symbol = aout_backend_info (abfd)->add_one_symbol;
- if (add_one_symbol == NULL)
- add_one_symbol = _bfd_generic_link_add_one_symbol;
-
p = syms;
pend = p + sym_count;
for (; p < pend; p++, sym_hash++)
@@ -2951,7 +2944,7 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
break;
}
- if (! ((*add_one_symbol)
+ if (! (_bfd_generic_link_add_one_symbol
(info, abfd, name, flags, section, value, string, copy, false,
(struct bfd_link_hash_entry **) sym_hash)))
return false;
diff --git a/bfd/version.h b/bfd/version.h
index 82120ff..90e53a8 100644
--- a/bfd/version.h
+++ b/bfd/version.h
@@ -16,7 +16,7 @@
In releases, the date is not included in either version strings or
sonames. */
-#define BFD_VERSION_DATE 20250409
+#define BFD_VERSION_DATE 20250425
#define BFD_VERSION @bfd_version@
#define BFD_VERSION_STRING @bfd_version_package@ @bfd_version_string@
#define REPORT_BUGS_TO @report_bugs_to@
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index b291670..c74526e 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -2701,6 +2701,14 @@ but the result again may not be as you expect.
For RISC-V, the following options are supported:
@table @code
+@item max
+Disassemble without checking architecture string. This is a best effort mode, so
+for overlapping ISA extensions the first match (possibly incorrect in a given
+context) will be used to decode the instruction. It's useful, if the ELF file
+doesn't expose ISA string, preventing automatic ISA subset deduction, and the
+default fallback ISA string (@code{rv64gc}) doesn't cover all instructions in
+the binary.
+
@item numeric
Print numeric register names, rather than ABI names (e.g., print @code{x2}
instead of @code{sp}).
diff --git a/binutils/resbin.c b/binutils/resbin.c
index 388b016..98dd68b 100644
--- a/binutils/resbin.c
+++ b/binutils/resbin.c
@@ -54,8 +54,8 @@ static rc_res_resource *bin_to_res_group_cursor (windres_bfd *, const bfd_byte *
static rc_res_resource *bin_to_res_group_icon (windres_bfd *, const bfd_byte *, rc_uint_type);
static rc_res_resource *bin_to_res_version (windres_bfd *, const bfd_byte *, rc_uint_type);
static rc_res_resource *bin_to_res_userdata (windres_bfd *, const bfd_byte *, rc_uint_type);
-static rc_res_resource *bin_to_res_toolbar (windres_bfd *, const bfd_byte *);
-static void get_version_header (windres_bfd *, const bfd_byte *, rc_uint_type, const char *,
+static rc_res_resource *bin_to_res_toolbar (windres_bfd *, const bfd_byte *, rc_uint_type);
+static bool get_version_header (windres_bfd *, const bfd_byte *, rc_uint_type, const char *,
unichar **, rc_uint_type *, rc_uint_type *, rc_uint_type *,
rc_uint_type *);
@@ -105,7 +105,7 @@ bin_to_res (windres_bfd *wrbfd, rc_res_id type, const bfd_byte *data,
case RT_VERSION:
return bin_to_res_version (wrbfd, data, length);
case RT_TOOLBAR:
- return bin_to_res_toolbar (wrbfd, data);
+ return bin_to_res_toolbar (wrbfd, data, length);
}
}
@@ -116,7 +116,7 @@ bin_to_res (windres_bfd *wrbfd, rc_res_id type, const bfd_byte *data,
static void
toosmall (const char *msg)
{
- fatal (_("%s: not enough binary data"), msg);
+ non_fatal (_("%s: not enough binary data"), msg);
}
/* Swap in a NULL terminated unicode string. */
@@ -132,13 +132,16 @@ get_unicode (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length,
while (1)
{
if (length < c * 2 + 2)
- toosmall (_("null terminated unicode string"));
+ {
+ toosmall (_("null terminated unicode string"));
+ return NULL;
+ }
if (windres_get_16 (wrbfd, data + c * 2, 2) == 0)
break;
++c;
}
- ret = (unichar *) res_alloc ((c + 1) * sizeof (unichar));
+ ret = res_alloc ((c + 1) * sizeof (unichar));
for (i = 0; i < c; i++)
ret[i] = windres_get_16 (wrbfd, data + i * 2, 2);
@@ -159,13 +162,19 @@ get_resid (windres_bfd *wrbfd, rc_res_id *id, const bfd_byte *data,
rc_uint_type first;
if (length < 2)
- toosmall (_("resource ID"));
+ {
+ toosmall (_("resource ID"));
+ return -1;
+ }
first = windres_get_16 (wrbfd, data, 2);
if (first == 0xffff)
{
if (length < 4)
- toosmall (_("resource ID"));
+ {
+ toosmall (_("resource ID"));
+ return -1;
+ }
id->named = 0;
id->u.id = windres_get_16 (wrbfd, data + 2, 2);
return 4;
@@ -174,6 +183,8 @@ get_resid (windres_bfd *wrbfd, rc_res_id *id, const bfd_byte *data,
{
id->named = 1;
id->u.n.name = get_unicode (wrbfd, data, length, &id->u.n.length);
+ if (id->u.n.name == NULL)
+ return -1;
return id->u.n.length * 2 + 2;
}
}
@@ -187,7 +198,7 @@ bin_to_res_generic (windres_bfd *wrbfd ATTRIBUTE_UNUSED, enum rc_res_type type,
{
rc_res_resource *r;
- r = (rc_res_resource *) res_alloc (sizeof (rc_res_resource));
+ r = res_alloc (sizeof (rc_res_resource));
r->type = type;
r->u.data.data = data;
r->u.data.length = length;
@@ -204,15 +215,18 @@ bin_to_res_cursor (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
rc_res_resource *r;
if (length < 4)
- toosmall (_("cursor"));
+ {
+ toosmall (_("cursor"));
+ return NULL;
+ }
- c = (rc_cursor *) res_alloc (sizeof (rc_cursor));
+ c = res_alloc (sizeof (rc_cursor));
c->xhotspot = windres_get_16 (wrbfd, data, 2);
c->yhotspot = windres_get_16 (wrbfd, data + 2, 2);
c->length = length - 4;
c->data = data + 4;
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_CURSOR;
r->u.cursor = c;
@@ -228,39 +242,58 @@ bin_to_res_menu (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
rc_menu *m;
rc_uint_type version, got;
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_MENU;
- m = (rc_menu *) res_alloc (sizeof (rc_menu));
+ m = res_alloc (sizeof (rc_menu));
r->u.menu = m;
if (length < 2)
- toosmall (_("menu header"));
+ {
+ toosmall (_("menu header"));
+ return NULL;
+ }
version = windres_get_16 (wrbfd, data, 2);
if (version == 0)
{
if (length < 4)
- toosmall (_("menu header"));
+ {
+ toosmall (_("menu header"));
+ return NULL;
+ }
m->help = 0;
m->items = bin_to_res_menuitems (wrbfd, data + 4, length - 4, &got);
+ if (m->items == NULL)
+ return NULL;
}
else if (version == 1)
{
rc_uint_type offset;
if (length < 8)
- toosmall (_("menuex header"));
+ {
+ toosmall (_("menuex header"));
+ return NULL;
+ }
m->help = windres_get_32 (wrbfd, data + 4, 4);
offset = windres_get_16 (wrbfd, data + 2, 2);
if (offset + 4 >= length)
- toosmall (_("menuex offset"));
+ {
+ toosmall (_("menuex offset"));
+ return NULL;
+ }
m->items = bin_to_res_menuexitems (wrbfd, data + 4 + offset,
length - (4 + offset), &got);
+ if (m->items == NULL)
+ return NULL;
}
else
- fatal (_("unsupported menu version %d"), (int) version);
+ {
+ non_fatal (_("unsupported menu version %d"), (int) version);
+ return NULL;
+ }
return r;
}
@@ -268,8 +301,8 @@ bin_to_res_menu (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
/* Convert menu items from binary. */
static rc_menuitem *
-bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length,
- rc_uint_type *got)
+bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length, rc_uint_type *got)
{
rc_menuitem *first, **pp;
@@ -285,9 +318,12 @@ bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type len
rc_menuitem *mi;
if (length < 4)
- toosmall (_("menuitem header"));
+ {
+ toosmall (_("menuitem header"));
+ return NULL;
+ }
- mi = (rc_menuitem *) res_alloc (sizeof *mi);
+ mi = res_alloc (sizeof *mi);
mi->state = 0;
mi->help = 0;
@@ -300,7 +336,10 @@ bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type len
stroff = 2;
if (length < stroff + 2)
- toosmall (_("menuitem header"));
+ {
+ toosmall (_("menuitem header"));
+ return NULL;
+ }
if (windres_get_16 (wrbfd, data + stroff, 2) == 0)
{
@@ -308,7 +347,11 @@ bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type len
mi->text = NULL;
}
else
- mi->text = get_unicode (wrbfd, data + stroff, length - stroff, &slen);
+ {
+ mi->text = get_unicode (wrbfd, data + stroff, length - stroff, &slen);
+ if (mi->text == NULL)
+ return NULL;
+ }
itemlen = stroff + slen * 2 + 2;
@@ -322,8 +365,10 @@ bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type len
rc_uint_type subread;
mi->id = 0;
- mi->popup = bin_to_res_menuitems (wrbfd, data + itemlen, length - itemlen,
- &subread);
+ mi->popup = bin_to_res_menuitems (wrbfd, data + itemlen,
+ length - itemlen, &subread);
+ if (mi->popup == NULL)
+ return NULL;
itemlen += subread;
}
@@ -345,8 +390,8 @@ bin_to_res_menuitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type len
/* Convert menuex items from binary. */
static rc_menuitem *
-bin_to_res_menuexitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length,
- rc_uint_type *got)
+bin_to_res_menuexitems (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length, rc_uint_type *got)
{
rc_menuitem *first, **pp;
@@ -362,9 +407,12 @@ bin_to_res_menuexitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type l
rc_menuitem *mi;
if (length < 16)
- toosmall (_("menuitem header"));
+ {
+ toosmall (_("menuitem header"));
+ return NULL;
+ }
- mi = (rc_menuitem *) res_alloc (sizeof (rc_menuitem));
+ mi = res_alloc (sizeof (rc_menuitem));
mi->type = windres_get_32 (wrbfd, data, 4);
mi->state = windres_get_32 (wrbfd, data + 4, 4);
mi->id = windres_get_32 (wrbfd, data + 8, 4);
@@ -377,7 +425,11 @@ bin_to_res_menuexitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type l
mi->text = NULL;
}
else
- mi->text = get_unicode (wrbfd, data + 14, length - 14, &slen);
+ {
+ mi->text = get_unicode (wrbfd, data + 14, length - 14, &slen);
+ if (mi->text == NULL)
+ return NULL;
+ }
itemlen = 14 + slen * 2 + 2;
itemlen = (itemlen + 3) &~ 3;
@@ -392,12 +444,17 @@ bin_to_res_menuexitems (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type l
rc_uint_type subread;
if (length < itemlen + 4)
- toosmall (_("menuitem"));
+ {
+ toosmall (_("menuitem"));
+ return NULL;
+ }
mi->help = windres_get_32 (wrbfd, data + itemlen, 4);
itemlen += 4;
mi->popup = bin_to_res_menuexitems (wrbfd, data + itemlen,
length - itemlen, &subread);
+ if (mi->popup == NULL)
+ return NULL;
itemlen += subread;
}
@@ -424,14 +481,18 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
rc_uint_type signature;
rc_dialog *d;
rc_uint_type c, sublen, i;
+ int ilen;
rc_uint_type off;
rc_dialog_control **pp;
rc_res_resource *r;
if (length < 18)
- toosmall (_("dialog header"));
+ {
+ toosmall (_("dialog header"));
+ return NULL;
+ }
- d = (rc_dialog *) res_alloc (sizeof (rc_dialog));
+ d = res_alloc (sizeof (rc_dialog));
signature = windres_get_16 (wrbfd, data + 2, 2);
if (signature != 0xffff)
@@ -447,9 +508,12 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
version = windres_get_16 (wrbfd, data, 2);
if (version != 1)
- fatal (_("unexpected DIALOGEX version %d"), version);
+ {
+ non_fatal (_("unexpected DIALOGEX version %d"), version);
+ return NULL;
+ }
- d->ex = (rc_dialog_ex *) res_alloc (sizeof (rc_dialog_ex));
+ d->ex = res_alloc (sizeof (rc_dialog_ex));
d->ex->help = windres_get_32 (wrbfd, data + 4, 4);
d->exstyle = windres_get_32 (wrbfd, data + 8, 4);
d->style = windres_get_32 (wrbfd, data + 12, 4);
@@ -457,7 +521,10 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
}
if (length < off + 10)
- toosmall (_("dialog header"));
+ {
+ toosmall (_("dialog header"));
+ return NULL;
+ }
c = windres_get_16 (wrbfd, data + off, 2);
d->x = windres_get_16 (wrbfd, data + off + 2, 2);
@@ -467,13 +534,19 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
off += 10;
- sublen = get_resid (wrbfd, &d->menu, data + off, length - off);
- off += sublen;
+ ilen = get_resid (wrbfd, &d->menu, data + off, length - off);
+ if (ilen == -1)
+ return NULL;
+ off += ilen;
- sublen = get_resid (wrbfd, &d->class, data + off, length - off);
- off += sublen;
+ ilen = get_resid (wrbfd, &d->class, data + off, length - off);
+ if (ilen == -1)
+ return NULL;
+ off += ilen;
d->caption = get_unicode (wrbfd, data + off, length - off, &sublen);
+ if (d->caption == NULL)
+ return NULL;
off += sublen * 2 + 2;
if (sublen == 0)
d->caption = NULL;
@@ -492,7 +565,10 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
else
{
if (length < off + 2)
- toosmall (_("dialog font point size"));
+ {
+ toosmall (_("dialog font point size"));
+ return NULL;
+ }
d->pointsize = windres_get_16 (wrbfd, data + off, 2);
off += 2;
@@ -500,7 +576,10 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
if (d->ex != NULL)
{
if (length < off + 4)
- toosmall (_("dialogex font information"));
+ {
+ toosmall (_("dialogex font information"));
+ return NULL;
+ }
d->ex->weight = windres_get_16 (wrbfd, data + off, 2);
d->ex->italic = windres_get_8 (wrbfd, data + off + 2, 1);
d->ex->charset = windres_get_8 (wrbfd, data + off + 3, 1);
@@ -508,6 +587,8 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
}
d->font = get_unicode (wrbfd, data + off, length - off, &sublen);
+ if (d->font == NULL)
+ return NULL;
off += sublen * 2 + 2;
}
@@ -521,12 +602,15 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
off = (off + 3) &~ 3;
- dc = (rc_dialog_control *) res_alloc (sizeof (rc_dialog_control));
+ dc = res_alloc (sizeof (rc_dialog_control));
if (d->ex == NULL)
{
if (length < off + 8)
- toosmall (_("dialog control"));
+ {
+ toosmall (_("dialog control"));
+ return NULL;
+ }
dc->style = windres_get_32 (wrbfd, data + off, 4);
dc->exstyle = windres_get_32 (wrbfd, data + off + 4, 4);
@@ -536,7 +620,10 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
else
{
if (length < off + 12)
- toosmall (_("dialogex control"));
+ {
+ toosmall (_("dialogex control"));
+ return NULL;
+ }
dc->help = windres_get_32 (wrbfd, data + off, 4);
dc->exstyle = windres_get_32 (wrbfd, data + off + 4, 4);
dc->style = windres_get_32 (wrbfd, data + off + 8, 4);
@@ -544,7 +631,10 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
}
if (length < off + (d->ex != NULL ? 2 : 0) + 10)
- toosmall (_("dialog control"));
+ {
+ toosmall (_("dialog control"));
+ return NULL;
+ }
dc->x = windres_get_16 (wrbfd, data + off, 2);
dc->y = windres_get_16 (wrbfd, data + off + 2, 2);
@@ -558,14 +648,21 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
off += 10 + (d->ex != NULL ? 2 : 0);
- sublen = get_resid (wrbfd, &dc->class, data + off, length - off);
- off += sublen;
+ ilen = get_resid (wrbfd, &dc->class, data + off, length - off);
+ if (ilen == -1)
+ return NULL;
+ off += ilen;
- sublen = get_resid (wrbfd, &dc->text, data + off, length - off);
- off += sublen;
+ ilen = get_resid (wrbfd, &dc->text, data + off, length - off);
+ if (ilen == -1)
+ return NULL;
+ off += ilen;
if (length < off + 2)
- toosmall (_("dialog control end"));
+ {
+ toosmall (_("dialog control end"));
+ return NULL;
+ }
datalen = windres_get_16 (wrbfd, data + off, 2);
off += 2;
@@ -575,10 +672,12 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
else
{
if (length < off + datalen)
- toosmall (_("dialog control data"));
+ {
+ toosmall (_("dialog control data"));
+ return NULL;
+ }
- dc->data = ((rc_rcdata_item *)
- res_alloc (sizeof (rc_rcdata_item)));
+ dc->data = res_alloc (sizeof (rc_rcdata_item));
dc->data->next = NULL;
dc->data->type = RCDATA_BUFFER;
dc->data->u.buffer.length = datalen;
@@ -592,7 +691,7 @@ bin_to_res_dialog (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
pp = &dc->next;
}
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_DIALOG;
r->u.dialog = d;
@@ -608,14 +707,17 @@ bin_to_res_string (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
int i;
rc_res_resource *r;
- st = (rc_stringtable *) res_alloc (sizeof (rc_stringtable));
+ st = res_alloc (sizeof (rc_stringtable));
for (i = 0; i < 16; i++)
{
unsigned int slen;
if (length < 2)
- toosmall (_("stringtable string length"));
+ {
+ toosmall (_("stringtable string length"));
+ return NULL;
+ }
slen = windres_get_16 (wrbfd, data, 2);
st->strings[i].length = slen;
@@ -625,9 +727,12 @@ bin_to_res_string (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
unsigned int j;
if (length < 2 + 2 * slen)
- toosmall (_("stringtable string"));
+ {
+ toosmall (_("stringtable string"));
+ return NULL;
+ }
- s = (unichar *) res_alloc (slen * sizeof (unichar));
+ s = res_alloc (slen * sizeof (unichar));
st->strings[i].string = s;
for (j = 0; j < slen; j++)
@@ -638,7 +743,7 @@ bin_to_res_string (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
length -= 2 + 2 * slen;
}
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_STRINGTABLE;
r->u.stringtable = st;
@@ -648,14 +753,18 @@ bin_to_res_string (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length
/* Convert a fontdir resource from binary. */
static rc_res_resource *
-bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
+bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length)
{
rc_uint_type c, i;
rc_fontdir *first, **pp;
rc_res_resource *r;
if (length < 2)
- toosmall (_("fontdir header"));
+ {
+ toosmall (_("fontdir header"));
+ return NULL;
+ }
c = windres_get_16 (wrbfd, data, 2);
@@ -669,10 +778,13 @@ bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
unsigned int off;
if (length < 56)
- toosmall (_("fontdir"));
+ {
+ toosmall (_("fontdir"));
+ return NULL;
+ }
bfi = (const struct bin_fontdir_item *) data;
- fd = (rc_fontdir *) res_alloc (sizeof *fd);
+ fd = res_alloc (sizeof *fd);
fd->index = windres_get_16 (wrbfd, bfi->index, 2);
/* To work out the length of the fontdir data, we must get the
@@ -686,13 +798,19 @@ bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
while (off < length && data[off] != '\0')
++off;
if (off >= length)
- toosmall (_("fontdir device name"));
+ {
+ toosmall (_("fontdir device name"));
+ return NULL;
+ }
++off;
while (off < length && data[off] != '\0')
++off;
if (off >= length)
- toosmall (_("fontdir face name"));
+ {
+ toosmall (_("fontdir face name"));
+ return NULL;
+ }
++off;
fd->length = off;
@@ -709,7 +827,7 @@ bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
length -= off;
}
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_FONTDIR;
r->u.fontdir = first;
@@ -719,7 +837,8 @@ bin_to_res_fontdir (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
/* Convert an accelerators resource from binary. */
static rc_res_resource *
-bin_to_res_accelerators (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
+bin_to_res_accelerators (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length)
{
rc_accelerator *first, **pp;
rc_res_resource *r;
@@ -732,9 +851,12 @@ bin_to_res_accelerators (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type
rc_accelerator *a;
if (length < 8)
- toosmall (_("accelerator"));
+ {
+ toosmall (_("accelerator"));
+ return NULL;
+ }
- a = (rc_accelerator *) res_alloc (sizeof (rc_accelerator));
+ a = res_alloc (sizeof (rc_accelerator));
a->flags = windres_get_16 (wrbfd, data, 2);
a->key = windres_get_16 (wrbfd, data + 2, 2);
@@ -751,7 +873,7 @@ bin_to_res_accelerators (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type
length -= 8;
}
- r = (rc_res_resource *) res_alloc (sizeof (rc_res_resource));
+ r = res_alloc (sizeof (rc_res_resource));
r->type = RES_TYPE_ACCELERATOR;
r->u.acc = first;
@@ -767,14 +889,14 @@ bin_to_res_rcdata (windres_bfd *wrbfd ATTRIBUTE_UNUSED, const bfd_byte *data,
rc_rcdata_item *ri;
rc_res_resource *r;
- ri = (rc_rcdata_item *) res_alloc (sizeof (rc_rcdata_item));
+ ri = res_alloc (sizeof (rc_rcdata_item));
ri->next = NULL;
ri->type = RCDATA_BUFFER;
ri->u.buffer.length = length;
ri->u.buffer.data = data;
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = rctyp;
r->u.rcdata = ri;
@@ -784,18 +906,25 @@ bin_to_res_rcdata (windres_bfd *wrbfd ATTRIBUTE_UNUSED, const bfd_byte *data,
/* Convert a group cursor resource from binary. */
static rc_res_resource *
-bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
+bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length)
{
int type, c, i;
rc_group_cursor *first, **pp;
rc_res_resource *r;
if (length < 6)
- toosmall (_("group cursor header"));
+ {
+ toosmall (_("group cursor header"));
+ return NULL;
+ }
type = windres_get_16 (wrbfd, data + 2, 2);
if (type != 2)
- fatal (_("unexpected group cursor type %d"), type);
+ {
+ non_fatal (_("unexpected group cursor type %d"), type);
+ return NULL;
+ }
c = windres_get_16 (wrbfd, data + 4, 2);
@@ -810,9 +939,12 @@ bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type
rc_group_cursor *gc;
if (length < 14)
- toosmall (_("group cursor"));
+ {
+ toosmall (_("group cursor"));
+ return NULL;
+ }
- gc = (rc_group_cursor *) res_alloc (sizeof *gc);
+ gc = res_alloc (sizeof *gc);
gc->width = windres_get_16 (wrbfd, data, 2);
gc->height = windres_get_16 (wrbfd, data + 2, 2);
@@ -829,7 +961,7 @@ bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type
length -= 14;
}
- r = (rc_res_resource *) res_alloc (sizeof (rc_res_resource));
+ r = res_alloc (sizeof (rc_res_resource));
r->type = RES_TYPE_GROUP_CURSOR;
r->u.group_cursor = first;
@@ -839,18 +971,25 @@ bin_to_res_group_cursor (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type
/* Convert a group icon resource from binary. */
static rc_res_resource *
-bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
+bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length)
{
int type, c, i;
rc_group_icon *first, **pp;
rc_res_resource *r;
if (length < 6)
- toosmall (_("group icon header"));
+ {
+ toosmall (_("group icon header"));
+ return NULL;
+ }
type = windres_get_16 (wrbfd, data + 2, 2);
if (type != 1)
- fatal (_("unexpected group icon type %d"), type);
+ {
+ non_fatal (_("unexpected group icon type %d"), type);
+ return NULL;
+ }
c = windres_get_16 (wrbfd, data + 4, 2);
@@ -865,9 +1004,12 @@ bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type le
rc_group_icon *gi;
if (length < 14)
- toosmall (_("group icon"));
+ {
+ toosmall (_("group icon"));
+ return NULL;
+ }
- gi = (rc_group_icon *) res_alloc (sizeof (rc_group_icon));
+ gi = res_alloc (sizeof (rc_group_icon));
gi->width = windres_get_8 (wrbfd, data, 1);
gi->height = windres_get_8 (wrbfd, data + 1, 1);
@@ -885,7 +1027,7 @@ bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type le
length -= 14;
}
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_GROUP_ICON;
r->u.group_icon = first;
@@ -897,14 +1039,17 @@ bin_to_res_group_icon (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type le
sets *LEN to the total length, *VALLEN to the value length, *TYPE
to the type, and *OFF to the offset to the children. */
-static void
-get_version_header (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length,
- const char *key, unichar **pkey,
+static bool
+get_version_header (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length, const char *key, unichar **pkey,
rc_uint_type *len, rc_uint_type *vallen, rc_uint_type *type,
rc_uint_type *off)
{
if (length < 8)
- toosmall (key);
+ {
+ toosmall (key);
+ return false;
+ }
*len = (windres_get_16 (wrbfd, data, 2) + 3) & ~3;
*vallen = windres_get_16 (wrbfd, data + 2, 2);
@@ -920,6 +1065,8 @@ get_version_header (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
rc_uint_type sublen;
*pkey = get_unicode (wrbfd, data, length, &sublen);
+ if (*pkey == NULL)
+ return false;
*off += (sublen + 1) * sizeof (unichar);
}
else
@@ -927,9 +1074,15 @@ get_version_header (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
while (1)
{
if (length < 2)
- toosmall (key);
+ {
+ toosmall (key);
+ return false;
+ }
if (windres_get_16 (wrbfd, data, 2) != (bfd_byte) *key)
- fatal (_("unexpected version string"));
+ {
+ non_fatal (_("unexpected version string"));
+ return false;
+ }
*off += 2;
length -= 2;
@@ -943,12 +1096,14 @@ get_version_header (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
}
*off = (*off + 3) &~ 3;
+ return true;
}
/* Convert a version resource from binary. */
static rc_res_resource *
-bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type length)
+bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length)
{
rc_uint_type verlen, vallen, type, off;
rc_fixed_versioninfo *fi;
@@ -956,18 +1111,26 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
rc_versioninfo *v;
rc_res_resource *r;
- get_version_header (wrbfd, data, length, "VS_VERSION_INFO",
- (unichar **) NULL, &verlen, &vallen, &type, &off);
+ if (!get_version_header (wrbfd, data, length, "VS_VERSION_INFO",
+ (unichar **) NULL, &verlen, &vallen, &type, &off))
+ return NULL;
/* PR 17512: The verlen field does not include padding length. */
if (verlen > length)
- fatal (_("version length %lu greater than resource length %lu"),
- (unsigned long) verlen, (unsigned long) length);
+ {
+ non_fatal (_("version length %lu greater than resource length %lu"),
+ (unsigned long) verlen, (unsigned long) length);
+ return NULL;
+ }
if (type != 0)
- fatal (_("unexpected version type %d"), (int) type);
+ {
+ non_fatal (_("unexpected version type %d"), (int) type);
+ return NULL;
+ }
- /* PR 27686: Ignore any padding bytes after the end of the version structure. */
+ /* PR 27686: Ignore any padding bytes after the end of the version
+ structure. */
length = verlen;
data += off;
@@ -980,20 +1143,33 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
unsigned long signature, fiv;
if (vallen != 52)
- fatal (_("unexpected fixed version information length %ld"), (long) vallen);
+ {
+ non_fatal (_("unexpected fixed version information length %ld"),
+ (long) vallen);
+ return NULL;
+ }
if (length < 52)
- toosmall (_("fixed version info"));
+ {
+ toosmall (_("fixed version info"));
+ return NULL;
+ }
signature = windres_get_32 (wrbfd, data, 4);
if (signature != 0xfeef04bd)
- fatal (_("unexpected fixed version signature %lu"), signature);
+ {
+ non_fatal (_("unexpected fixed version signature %lu"), signature);
+ return NULL;
+ }
fiv = windres_get_32 (wrbfd, data + 4, 4);
if (fiv != 0 && fiv != 0x10000)
- fatal (_("unexpected fixed version info version %lu"), fiv);
+ {
+ non_fatal (_("unexpected fixed version info version %lu"), fiv);
+ return NULL;
+ }
- fi = (rc_fixed_versioninfo *) res_alloc (sizeof (rc_fixed_versioninfo));
+ fi = res_alloc (sizeof (rc_fixed_versioninfo));
fi->file_version_ms = windres_get_32 (wrbfd, data + 8, 4);
fi->file_version_ls = windres_get_32 (wrbfd, data + 12, 4);
@@ -1020,9 +1196,12 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
int ch;
if (length < 8)
- toosmall (_("version var info"));
+ {
+ toosmall (_("version var info"));
+ return NULL;
+ }
- vi = (rc_ver_info *) res_alloc (sizeof (rc_ver_info));
+ vi = res_alloc (sizeof (rc_ver_info));
ch = windres_get_16 (wrbfd, data + 6, 2);
@@ -1032,12 +1211,17 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
vi->type = VERINFO_STRING;
- get_version_header (wrbfd, data, length, "StringFileInfo",
- (unichar **) NULL, &verlen, &vallen, &type,
- &off);
+ if (!get_version_header (wrbfd, data, length, "StringFileInfo",
+ (unichar **) NULL, &verlen, &vallen, &type,
+ &off))
+ return NULL;
if (vallen != 0)
- fatal (_("unexpected stringfileinfo value length %ld"), (long) vallen);
+ {
+ non_fatal (_("unexpected stringfileinfo value length %ld"),
+ (long) vallen);
+ return NULL;
+ }
data += off;
length -= off;
@@ -1054,66 +1238,88 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
rc_ver_stringinfo **ppvs;
if (length < 8)
- toosmall (_("version stringtable"));
+ {
+ toosmall (_("version stringtable"));
+ return NULL;
+ }
- vst = (rc_ver_stringtable *) res_alloc (sizeof (rc_ver_stringtable));
+ vst = res_alloc (sizeof (rc_ver_stringtable));
- get_version_header (wrbfd, data, length, (const char *) NULL,
- &vst->language, &stverlen, &vallen, &type, &off);
+ if (!get_version_header (wrbfd, data, length, (const char *) NULL,
+ &vst->language, &stverlen, &vallen,
+ &type, &off))
+ return NULL;
if (vallen != 0)
- fatal (_("unexpected version stringtable value length %ld"), (long) vallen);
+ {
+ non_fatal (_("unexpected version stringtable value length %ld"),
+ (long) vallen);
+ return NULL;
+ }
data += off;
length -= off;
verlen -= off;
- stverlen -= off;
-
- vst->strings = NULL;
- ppvs = &vst->strings;
-
- while (stverlen > 0)
- {
- rc_ver_stringinfo *vs;
- rc_uint_type sverlen, vslen, valoff;
-
- if (length < 8)
- toosmall (_("version string"));
-
- vs = (rc_ver_stringinfo *) res_alloc (sizeof (rc_ver_stringinfo));
-
- get_version_header (wrbfd, data, length, (const char *) NULL,
- &vs->key, &sverlen, &vallen, &type, &off);
-
- data += off;
- length -= off;
-
- vs->value = get_unicode (wrbfd, data, length, &vslen);
- valoff = vslen * 2 + 2;
- valoff = (valoff + 3) & ~3;
-
- if (off + valoff != sverlen)
- fatal (_("unexpected version string length %ld != %ld + %ld"),
- (long) sverlen, (long) off, (long) valoff);
-
- data += valoff;
- length -= valoff;
-
- if (stverlen < sverlen)
- fatal (_("unexpected version string length %ld < %ld"),
- (long) verlen, (long) sverlen);
- stverlen -= sverlen;
- verlen -= sverlen;
-
- vs->next = NULL;
- *ppvs = vs;
- ppvs = &vs->next;
- }
-
- vst->next = NULL;
- *ppvst = vst;
- ppvst = &vst->next;
+ stverlen -= off;
+
+ vst->strings = NULL;
+ ppvs = &vst->strings;
+
+ while (stverlen > 0)
+ {
+ rc_ver_stringinfo *vs;
+ rc_uint_type sverlen, vslen, valoff;
+
+ if (length < 8)
+ {
+ toosmall (_("version string"));
+ return NULL;
+ }
+
+ vs = res_alloc (sizeof (rc_ver_stringinfo));
+
+ if (!get_version_header (wrbfd, data, length,
+ (const char *) NULL, &vs->key,
+ &sverlen, &vallen, &type, &off))
+ return NULL;
+
+ data += off;
+ length -= off;
+
+ vs->value = get_unicode (wrbfd, data, length, &vslen);
+ if (vs->value == NULL)
+ return NULL;
+ valoff = vslen * 2 + 2;
+ valoff = (valoff + 3) & ~3;
+
+ if (off + valoff != sverlen)
+ {
+ non_fatal (_("unexpected version string length %ld != %ld + %ld"),
+ (long) sverlen, (long) off, (long) valoff);
+ return NULL;
+ }
+
+ data += valoff;
+ length -= valoff;
+
+ if (stverlen < sverlen)
+ {
+ non_fatal (_("unexpected version string length %ld < %ld"),
+ (long) verlen, (long) sverlen);
+ return NULL;
+ }
+ stverlen -= sverlen;
+ verlen -= sverlen;
+
+ vs->next = NULL;
+ *ppvs = vs;
+ ppvs = &vs->next;
+ }
+
+ vst->next = NULL;
+ *ppvst = vst;
+ ppvst = &vst->next;
}
}
else if (ch == 'V')
@@ -1122,18 +1328,25 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
vi->type = VERINFO_VAR;
- get_version_header (wrbfd, data, length, "VarFileInfo",
- (unichar **) NULL, &verlen, &vallen, &type,
- &off);
+ if (!get_version_header (wrbfd, data, length, "VarFileInfo",
+ (unichar **) NULL, &verlen, &vallen,
+ &type, &off))
+ return NULL;
if (vallen != 0)
- fatal (_("unexpected varfileinfo value length %ld"), (long) vallen);
+ {
+ non_fatal (_("unexpected varfileinfo value length %ld"),
+ (long) vallen);
+ return NULL;
+ }
data += off;
length -= off;
- get_version_header (wrbfd, data, length, (const char *) NULL,
- &vi->u.var.key, &verlen, &vallen, &type, &off);
+ if (!get_version_header (wrbfd, data, length, (const char *) NULL,
+ &vi->u.var.key, &verlen, &vallen,
+ &type, &off))
+ return NULL;
data += off;
length -= off;
@@ -1146,9 +1359,12 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
rc_ver_varinfo *vv;
if (length < 4)
- toosmall (_("version varfileinfo"));
+ {
+ toosmall (_("version varfileinfo"));
+ return NULL;
+ }
- vv = (rc_ver_varinfo *) res_alloc (sizeof (rc_ver_varinfo));
+ vv = res_alloc (sizeof (rc_ver_varinfo));
vv->language = windres_get_16 (wrbfd, data, 2);
vv->charset = windres_get_16 (wrbfd, data + 2, 2);
@@ -1161,7 +1377,11 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
length -= 4;
if (vallen < 4)
- fatal (_("unexpected version value length %ld"), (long) vallen);
+ {
+ non_fatal (_("unexpected version value length %ld"),
+ (long) vallen);
+ return NULL;
+ }
vallen -= 4;
}
@@ -1171,21 +1391,25 @@ bin_to_res_version (windres_bfd *wrbfd, const bfd_byte *data, rc_uint_type lengt
if (length == 8)
/* Padding - skip. */
break;
- fatal (_("nul bytes found in version string"));
+ non_fatal (_("nul bytes found in version string"));
+ return NULL;
}
else
- fatal (_("unexpected version string character: %x"), ch);
+ {
+ non_fatal (_("unexpected version string character: %x"), ch);
+ return NULL;
+ }
vi->next = NULL;
*pp = vi;
pp = &vi->next;
}
- v = (rc_versioninfo *) res_alloc (sizeof (rc_versioninfo));
+ v = res_alloc (sizeof (rc_versioninfo));
v->fixed = fi;
v->var = first;
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_VERSIONINFO;
r->u.versioninfo = v;
@@ -1201,14 +1425,14 @@ bin_to_res_userdata (windres_bfd *wrbfd ATTRIBUTE_UNUSED, const bfd_byte *data,
rc_rcdata_item *ri;
rc_res_resource *r;
- ri = (rc_rcdata_item *) res_alloc (sizeof (rc_rcdata_item));
+ ri = res_alloc (sizeof (rc_rcdata_item));
ri->next = NULL;
ri->type = RCDATA_BUFFER;
ri->u.buffer.length = length;
ri->u.buffer.data = data;
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_USERDATA;
r->u.rcdata = ri;
@@ -1216,38 +1440,51 @@ bin_to_res_userdata (windres_bfd *wrbfd ATTRIBUTE_UNUSED, const bfd_byte *data,
}
static rc_res_resource *
-bin_to_res_toolbar (windres_bfd *wrbfd, const bfd_byte *data)
+bin_to_res_toolbar (windres_bfd *wrbfd, const bfd_byte *data,
+ rc_uint_type length)
{
rc_toolbar *ri;
rc_res_resource *r;
rc_uint_type i;
- ri = (rc_toolbar *) res_alloc (sizeof (rc_toolbar));
+ if (length < 12)
+ {
+ toosmall (_("toolbar"));
+ return NULL;
+ }
+ ri = res_alloc (sizeof (rc_toolbar));
ri->button_width = windres_get_32 (wrbfd, data, 4);
ri->button_height = windres_get_32 (wrbfd, data + 4, 4);
ri->nitems = windres_get_32 (wrbfd, data + 8, 4);
ri->items = NULL;
data += 12;
- for (i=0 ; i < ri->nitems; i++)
- {
- rc_toolbar_item *it;
- it = (rc_toolbar_item *) res_alloc (sizeof (rc_toolbar_item));
- it->id.named = 0;
- it->id.u.id = (int) windres_get_32 (wrbfd, data, 4);
- it->prev = it->next = NULL;
- data += 4;
- if(ri->items) {
- rc_toolbar_item *ii = ri->items;
- while (ii->next != NULL)
- ii = ii->next;
- it->prev = ii;
- ii->next = it;
- }
- else
- ri->items = it;
- }
- r = (rc_res_resource *) res_alloc (sizeof *r);
+ length -= 12;
+ for (i = 0; i < ri->nitems; i++)
+ {
+ rc_toolbar_item *it;
+ it = res_alloc (sizeof (rc_toolbar_item));
+ it->id.named = 0;
+ if (length < 4)
+ {
+ toosmall (_("toolbar item"));
+ return NULL;
+ }
+ it->id.u.id = (int) windres_get_32 (wrbfd, data, 4);
+ it->prev = it->next = NULL;
+ data += 4;
+ length -= 4;
+ if(ri->items) {
+ rc_toolbar_item *ii = ri->items;
+ while (ii->next != NULL)
+ ii = ii->next;
+ it->prev = ii;
+ ii->next = it;
+ }
+ else
+ ri->items = it;
+ }
+ r = res_alloc (sizeof *r);
r->type = RES_TYPE_TOOLBAR;
r->u.toolbar = ri;
return r;
@@ -1286,7 +1523,8 @@ res_to_bin (windres_bfd *wrbfd, rc_uint_type off, const rc_res_resource *res)
case RES_TYPE_FONT:
case RES_TYPE_ICON:
case RES_TYPE_MESSAGETABLE:
- return res_to_bin_generic (wrbfd, off, res->u.data.length, res->u.data.data);
+ return res_to_bin_generic (wrbfd, off, res->u.data.length,
+ res->u.data.data);
case RES_TYPE_ACCELERATOR:
return res_to_bin_accelerator (wrbfd, off, res->u.acc);
case RES_TYPE_CURSOR:
@@ -1337,13 +1575,13 @@ resid_to_bin (windres_bfd *wrbfd, rc_uint_type off, rc_res_id id)
rc_uint_type len = (id.u.n.name ? unichar_len (id.u.n.name) : 0);
if (wrbfd)
{
- bfd_byte *d = (bfd_byte *) reswr_alloc ((len + 1) * sizeof (unichar));
+ bfd_byte *d = reswr_alloc ((len + 1) * sizeof (unichar));
rc_uint_type i;
for (i = 0; i < len; i++)
windres_put_16 (wrbfd, d + (i * sizeof (unichar)), id.u.n.name[i]);
windres_put_16 (wrbfd, d + (len * sizeof (unichar)), 0);
set_windres_bfd_content (wrbfd, d, off, (len + 1) * sizeof (unichar));
- }
+ }
off += (rc_uint_type) ((len + 1) * sizeof (unichar));
}
return off;
@@ -1364,7 +1602,7 @@ unicode_to_bin (windres_bfd *wrbfd, rc_uint_type off, const unichar *str)
{
bfd_byte *d;
rc_uint_type i;
- d = (bfd_byte *) reswr_alloc ( (len + 1) * sizeof (unichar));
+ d = reswr_alloc ((len + 1) * sizeof (unichar));
for (i = 0; i < len; i++)
windres_put_16 (wrbfd, d + (i * sizeof (unichar)), str[i]);
windres_put_16 (wrbfd, d + (len * sizeof (unichar)), 0);
@@ -1389,12 +1627,13 @@ res_to_bin_accelerator (windres_bfd *wrbfd, rc_uint_type off,
{
struct bin_accelerator ba;
- windres_put_16 (wrbfd, ba.flags, a->flags | (a->next != NULL ? 0 : ACC_LAST));
+ windres_put_16 (wrbfd, ba.flags,
+ a->flags | (a->next != NULL ? 0 : ACC_LAST));
windres_put_16 (wrbfd, ba.key, a->key);
windres_put_16 (wrbfd, ba.id, a->id);
windres_put_16 (wrbfd, ba.pad, 0);
set_windres_bfd_content (wrbfd, &ba, off, BIN_ACCELERATOR_SIZE);
- }
+ }
off += BIN_ACCELERATOR_SIZE;
}
return off;
@@ -1413,7 +1652,8 @@ res_to_bin_cursor (windres_bfd *wrbfd, rc_uint_type off, const rc_cursor *c)
windres_put_16 (wrbfd, bc.yhotspot, c->yhotspot);
set_windres_bfd_content (wrbfd, &bc, off, BIN_CURSOR_SIZE);
if (c->length)
- set_windres_bfd_content (wrbfd, c->data, off + BIN_CURSOR_SIZE, c->length);
+ set_windres_bfd_content (wrbfd, c->data, off + BIN_CURSOR_SIZE,
+ c->length);
}
off = (off + BIN_CURSOR_SIZE + (rc_uint_type) c->length);
return off;
@@ -1443,8 +1683,9 @@ res_to_bin_group_cursor (windres_bfd *wrbfd, rc_uint_type off,
windres_put_16 (wrbfd, bgci.bits, gc->bits);
windres_put_32 (wrbfd, bgci.bytes, gc->bytes);
windres_put_16 (wrbfd, bgci.index, gc->index);
- set_windres_bfd_content (wrbfd, &bgci, off, BIN_GROUP_CURSOR_ITEM_SIZE);
- }
+ set_windres_bfd_content (wrbfd, &bgci, off,
+ BIN_GROUP_CURSOR_ITEM_SIZE);
+ }
off += BIN_GROUP_CURSOR_ITEM_SIZE;
}
@@ -1477,17 +1718,17 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
if (wrbfd)
{
- if (! dialogex)
- {
+ if (! dialogex)
+ {
windres_put_32 (wrbfd, bd.style, dialog->style);
windres_put_32 (wrbfd, bd.exstyle, dialog->exstyle);
windres_put_16 (wrbfd, bd.x, dialog->x);
windres_put_16 (wrbfd, bd.y, dialog->y);
windres_put_16 (wrbfd, bd.width, dialog->width);
windres_put_16 (wrbfd, bd.height, dialog->height);
- }
- else
- {
+ }
+ else
+ {
windres_put_16 (wrbfd, bdx.sig1, 1);
windres_put_16 (wrbfd, bdx.sig2, 0xffff);
windres_put_32 (wrbfd, bdx.help, (dialog->ex ? dialog->ex->help : 0));
@@ -1520,9 +1761,12 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
{
struct bin_dialogexfont bdxf;
windres_put_16 (wrbfd, bdxf.pointsize, dialog->pointsize);
- windres_put_16 (wrbfd, bdxf.weight, (dialog->ex == NULL ? 0 : dialog->ex->weight));
- windres_put_8 (wrbfd, bdxf.italic, (dialog->ex == NULL ? 0 : dialog->ex->italic));
- windres_put_8 (wrbfd, bdxf.charset, (dialog->ex == NULL ? 1 : dialog->ex->charset));
+ windres_put_16 (wrbfd, bdxf.weight,
+ dialog->ex == NULL ? 0 : dialog->ex->weight);
+ windres_put_8 (wrbfd, bdxf.italic,
+ dialog->ex == NULL ? 0 : dialog->ex->italic);
+ windres_put_8 (wrbfd, bdxf.charset,
+ dialog->ex == NULL ? 1 : dialog->ex->charset);
set_windres_bfd_content (wrbfd, &bdxf, off, BIN_DIALOGEXFONT_SIZE);
}
}
@@ -1536,8 +1780,8 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
off += (4 - ((off - off_delta) & 3)) & 3;
if (wrbfd)
{
- if (! dialogex)
- {
+ if (! dialogex)
+ {
struct bin_dialog_control bdc;
windres_put_32 (wrbfd, bdc.style, dc->style);
@@ -1547,10 +1791,11 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
windres_put_16 (wrbfd, bdc.width, dc->width);
windres_put_16 (wrbfd, bdc.height, dc->height);
windres_put_16 (wrbfd, bdc.id, dc->id);
- set_windres_bfd_content (wrbfd, &bdc, off, BIN_DIALOG_CONTROL_SIZE);
- }
- else
- {
+ set_windres_bfd_content (wrbfd, &bdc, off,
+ BIN_DIALOG_CONTROL_SIZE);
+ }
+ else
+ {
struct bin_dialogex_control bdc;
windres_put_32 (wrbfd, bdc.help, dc->help);
@@ -1561,11 +1806,11 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
windres_put_16 (wrbfd, bdc.width, dc->width);
windres_put_16 (wrbfd, bdc.height, dc->height);
windres_put_32 (wrbfd, bdc.id, dc->id);
- set_windres_bfd_content (wrbfd, &bdc, off, BIN_DIALOGEX_CONTROL_SIZE);
+ set_windres_bfd_content (wrbfd, &bdc, off,
+ BIN_DIALOGEX_CONTROL_SIZE);
}
}
- off += (dialogex != 0 ? BIN_DIALOGEX_CONTROL_SIZE : BIN_DIALOG_CONTROL_SIZE);
-
+ off += dialogex != 0 ? BIN_DIALOGEX_CONTROL_SIZE : BIN_DIALOG_CONTROL_SIZE;
off = resid_to_bin (wrbfd, off, dc->class);
off = resid_to_bin (wrbfd, off, dc->text);
@@ -1607,7 +1852,8 @@ res_to_bin_dialog (windres_bfd *wrbfd, rc_uint_type off, const rc_dialog *dialog
/* Convert a fontdir resource to binary. */
static rc_uint_type
-res_to_bin_fontdir (windres_bfd *wrbfd, rc_uint_type off, const rc_fontdir *fontdirs)
+res_to_bin_fontdir (windres_bfd *wrbfd, rc_uint_type off,
+ const rc_fontdir *fontdirs)
{
rc_uint_type start;
int c;
@@ -1641,7 +1887,8 @@ res_to_bin_fontdir (windres_bfd *wrbfd, rc_uint_type off, const rc_fontdir *font
/* Convert a group icon resource to binary. */
static rc_uint_type
-res_to_bin_group_icon (windres_bfd *wrbfd, rc_uint_type off, const rc_group_icon *group_icons)
+res_to_bin_group_icon (windres_bfd *wrbfd, rc_uint_type off,
+ const rc_group_icon *group_icons)
{
rc_uint_type start;
struct bin_group_icon bgi;
@@ -1691,21 +1938,21 @@ res_to_bin_menu (windres_bfd *wrbfd, rc_uint_type off, const rc_menu *menu)
if (wrbfd)
{
- if (! menuex)
- {
+ if (! menuex)
+ {
struct bin_menu bm;
windres_put_16 (wrbfd, bm.sig1, 0);
windres_put_16 (wrbfd, bm.sig2, 0);
set_windres_bfd_content (wrbfd, &bm, off, BIN_MENU_SIZE);
- }
- else
- {
+ }
+ else
+ {
struct bin_menuex bm;
windres_put_16 (wrbfd, bm.sig1, 1);
windres_put_16 (wrbfd, bm.sig2, 4);
windres_put_32 (wrbfd, bm.help, menu->help);
set_windres_bfd_content (wrbfd, &bm, off, BIN_MENUEX_SIZE);
- }
+ }
}
off += (menuex != 0 ? BIN_MENUEX_SIZE : BIN_MENU_SIZE);
if (! menuex)
@@ -1722,7 +1969,8 @@ res_to_bin_menu (windres_bfd *wrbfd, rc_uint_type off, const rc_menu *menu)
/* Convert menu items to binary. */
static rc_uint_type
-res_to_bin_menuitems (windres_bfd *wrbfd, rc_uint_type off, const rc_menuitem *items)
+res_to_bin_menuitems (windres_bfd *wrbfd, rc_uint_type off,
+ const rc_menuitem *items)
{
const rc_menuitem *mi;
@@ -1740,11 +1988,12 @@ res_to_bin_menuitems (windres_bfd *wrbfd, rc_uint_type off, const rc_menuitem *i
if (wrbfd)
{
windres_put_16 (wrbfd, bmi.flags, flags);
- if (mi->popup == NULL)
+ if (mi->popup == NULL)
windres_put_16 (wrbfd, bmi.id, mi->id);
set_windres_bfd_content (wrbfd, &bmi, off,
- mi->popup == NULL ? BIN_MENUITEM_SIZE
- : BIN_MENUITEM_POPUP_SIZE);
+ (mi->popup == NULL
+ ? BIN_MENUITEM_SIZE
+ : BIN_MENUITEM_POPUP_SIZE));
}
off += (mi->popup == NULL ? BIN_MENUITEM_SIZE : BIN_MENUITEM_POPUP_SIZE);
@@ -1761,7 +2010,8 @@ res_to_bin_menuitems (windres_bfd *wrbfd, rc_uint_type off, const rc_menuitem *i
/* Convert menuex items to binary. */
static rc_uint_type
-res_to_bin_menuexitems (windres_bfd *wrbfd, rc_uint_type off, const rc_menuitem *items)
+res_to_bin_menuexitems (windres_bfd *wrbfd, rc_uint_type off,
+ const rc_menuitem *items)
{
rc_uint_type off_delta = off;
const rc_menuitem *mi;
@@ -1814,7 +2064,8 @@ res_to_bin_menuexitems (windres_bfd *wrbfd, rc_uint_type off, const rc_menuitem
to binary. */
static rc_uint_type
-res_to_bin_rcdata (windres_bfd *wrbfd, rc_uint_type off, const rc_rcdata_item *items)
+res_to_bin_rcdata (windres_bfd *wrbfd, rc_uint_type off,
+ const rc_rcdata_item *items)
{
const rc_rcdata_item *ri;
@@ -1855,22 +2106,23 @@ res_to_bin_rcdata (windres_bfd *wrbfd, rc_uint_type off, const rc_rcdata_item *i
break;
case RCDATA_STRING:
hp = (bfd_byte *) ri->u.string.s;
- break;
- case RCDATA_WSTRING:
- {
+ break;
+ case RCDATA_WSTRING:
+ {
rc_uint_type i;
- hp = (bfd_byte *) reswr_alloc (len);
- for (i = 0; i < ri->u.wstring.length; i++)
- windres_put_16 (wrbfd, hp + i * sizeof (unichar), ri->u.wstring.w[i]);
- }
+ hp = reswr_alloc (len);
+ for (i = 0; i < ri->u.wstring.length; i++)
+ windres_put_16 (wrbfd, hp + i * sizeof (unichar),
+ ri->u.wstring.w[i]);
+ }
break;
- case RCDATA_BUFFER:
+ case RCDATA_BUFFER:
hp = (bfd_byte *) ri->u.buffer.data;
- break;
- }
+ break;
+ }
set_windres_bfd_content (wrbfd, hp, off, len);
- }
+ }
off += len;
}
return off;
@@ -1899,13 +2151,13 @@ res_to_bin_stringtable (windres_bfd *wrbfd, rc_uint_type off,
bfd_byte *hp;
rc_uint_type j;
- hp = (bfd_byte *) reswr_alloc (length);
+ hp = reswr_alloc (length);
windres_put_16 (wrbfd, hp, slen);
- for (j = 0; j < slen; j++)
+ for (j = 0; j < slen; j++)
windres_put_16 (wrbfd, hp + 2 + j * 2, s[j]);
set_windres_bfd_content (wrbfd, hp, off, length);
- }
+ }
off += length;
}
return off;
@@ -1926,7 +2178,7 @@ string_to_unicode_bin (windres_bfd *wrbfd, rc_uint_type off, const char *s)
rc_uint_type i;
bfd_byte *hp;
- hp = (bfd_byte *) reswr_alloc ((len + 1) * sizeof (unichar));
+ hp = reswr_alloc ((len + 1) * sizeof (unichar));
for (i = 0; i < len; i++)
windres_put_16 (wrbfd, hp + i * 2, s[i]);
@@ -1953,7 +2205,7 @@ res_to_bin_toolbar (windres_bfd *wrbfd, rc_uint_type off, rc_toolbar *tb)
bfd_byte *ids;
rc_uint_type i = 0;
- ids = (bfd_byte *) reswr_alloc (tb->nitems * 4);
+ ids = reswr_alloc (tb->nitems * 4);
it=tb->items;
while(it != NULL)
{
@@ -1992,7 +2244,7 @@ res_to_bin_versioninfo (windres_bfd *wrbfd, rc_uint_type off,
struct bin_fixed_versioninfo bfv;
const rc_fixed_versioninfo *fi;
- fi = versioninfo->fixed;
+ fi = versioninfo->fixed;
windres_put_32 (wrbfd, bfv.sig1, 0xfeef04bd);
windres_put_32 (wrbfd, bfv.sig2, 0x10000);
windres_put_32 (wrbfd, bfv.file_version, fi->file_version_ms);
@@ -2119,13 +2371,13 @@ res_to_bin_versioninfo (windres_bfd *wrbfd, rc_uint_type off,
off += 4;
}
if (wrbfd)
- {
+ {
windres_put_16 (wrbfd, bvvd.size, off - vvd_off);
windres_put_16 (wrbfd, bvvd.sig1, off - vvvd_off);
windres_put_16 (wrbfd, bvvd.sig2, 0);
set_windres_bfd_content (wrbfd, &bvvd, vvd_off,
BIN_VER_INFO_SIZE);
- }
+ }
break;
}
@@ -2146,7 +2398,7 @@ res_to_bin_versioninfo (windres_bfd *wrbfd, rc_uint_type off,
windres_put_16 (wrbfd, bvi.size, off - start);
windres_put_16 (wrbfd, bvi.fixed_size,
versioninfo->fixed == NULL ? 0
- : BIN_FIXED_VERSIONINFO_SIZE);
+ : BIN_FIXED_VERSIONINFO_SIZE);
windres_put_16 (wrbfd, bvi.sig2, 0);
set_windres_bfd_content (wrbfd, &bvi, start, BIN_VER_INFO_SIZE);
}
diff --git a/binutils/rescoff.c b/binutils/rescoff.c
index f9a1e70..6031602 100644
--- a/binutils/rescoff.c
+++ b/binutils/rescoff.c
@@ -120,27 +120,41 @@ read_coff_rsrc (const char *filename, const char *target)
struct coff_file_info flaginfo;
if (filename == NULL)
- fatal (_("filename required for COFF input"));
+ {
+ non_fatal (_("filename required for COFF input"));
+ return NULL;
+ }
abfd = bfd_openr (filename, target);
if (abfd == NULL)
- bfd_fatal (filename);
+ {
+ bfd_nonfatal (filename);
+ return NULL;
+ }
if (! bfd_check_format_matches (abfd, bfd_object, &matching))
{
bfd_nonfatal (bfd_get_filename (abfd));
if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
list_matching_formats (matching);
- xexit (1);
+ free (matching);
+ bfd_close (abfd);
+ return NULL;
}
if (bfd_get_flavour (abfd) != bfd_target_coff_flavour
|| !obj_pe (abfd))
- fatal (_("%s: not a PE file"), filename);
+ {
+ non_fatal (_("%s: not a PE file"), filename);
+ bfd_close (abfd);
+ return NULL;
+ }
sec = bfd_get_section_by_name (abfd, ".rsrc");
if (sec == NULL)
{
- fatal (_("%s: no resource section"), filename);
+ non_fatal (_("%s: no resource section"), filename);
+ bfd_close (abfd);
+ return NULL;
}
set_windres_bfd (&wrbfd, abfd, sec, WR_KIND_BFD);
@@ -150,7 +164,11 @@ read_coff_rsrc (const char *filename, const char *target)
but there is no other way to determine if the section size
is reasonable. */
if (size > (bfd_size_type) get_file_size (filename))
- fatal (_("%s: .rsrc section is bigger than the file!"), filename);
+ {
+ non_fatal (_("%s: .rsrc section is bigger than the file!"), filename);
+ bfd_close (abfd);
+ return NULL;
+ }
data = (bfd_byte *) res_alloc (size);
get_windres_bfd_content (&wrbfd, data, 0, size);
@@ -178,7 +196,7 @@ read_coff_rsrc (const char *filename, const char *target)
static void
overrun (const struct coff_file_info *flaginfo, const char *msg)
{
- fatal (_("%s: %s: address out of bounds"), flaginfo->filename, msg);
+ non_fatal (_("%s: %s: address out of bounds"), flaginfo->filename, msg);
}
/* Read a resource directory. */
@@ -199,10 +217,17 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
Microsoft only defines 3 levels. Corrupt files however might
claim to use more. */
if (level > 4)
- fatal (_("%s: resources nest too deep"), flaginfo->filename);
+ {
+ non_fatal (_("%s: resources nest too deep"), flaginfo->filename);
+ return NULL;
+ }
- if ((size_t) (flaginfo->data_end - data) < sizeof (struct extern_res_directory))
- overrun (flaginfo, _("directory"));
+ size_t data_len = flaginfo->data_end - data;
+ if (data_len < sizeof (struct extern_res_directory))
+ {
+ overrun (flaginfo, _("directory"));
+ return NULL;
+ }
erd = (const struct extern_res_directory *) data;
@@ -229,8 +254,12 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
const bfd_byte *ers;
int length, j;
- if ((const bfd_byte *) ere >= flaginfo->data_end)
- overrun (flaginfo, _("named directory entry"));
+ if ((const bfd_byte *) ere > flaginfo->data_end
+ || flaginfo->data_end - (const bfd_byte *) ere < 8)
+ {
+ overrun (flaginfo, _("named directory entry"));
+ return NULL;
+ }
name = windres_get_32 (wrbfd, ere->name, 4);
rva = windres_get_32 (wrbfd, ere->rva, 4);
@@ -238,24 +267,32 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
/* For some reason the high bit in NAME is set. */
name &=~ 0x80000000;
- if (name > (rc_uint_type) (flaginfo->data_end - flaginfo->data))
- overrun (flaginfo, _("directory entry name"));
+ if (name > data_len)
+ {
+ overrun (flaginfo, _("directory entry name"));
+ return NULL;
+ }
ers = flaginfo->data + name;
-
+ if (flaginfo->data_end - ers < 2)
+ {
+ overrun (flaginfo, _("resource name"));
+ return NULL;
+ }
+ length = windres_get_16 (wrbfd, ers, 2);
+ /* PR 17512: file: 05dc4a16. */
+ if (length * 2 + 4 > flaginfo->data_end - ers)
+ {
+ overrun (flaginfo, _("resource name"));
+ return NULL;
+ }
re = (rc_res_entry *) res_alloc (sizeof *re);
re->next = NULL;
re->id.named = 1;
- length = windres_get_16 (wrbfd, ers, 2);
re->id.u.n.length = length;
re->id.u.n.name = (unichar *) res_alloc (length * sizeof (unichar));
for (j = 0; j < length; j++)
- {
- /* PR 17512: file: 05dc4a16. */
- if (length < 0 || ers >= flaginfo->data_end || ers + j * 2 + 4 >= flaginfo->data_end)
- overrun (flaginfo, _("resource name"));
- re->id.u.n.name[j] = windres_get_16 (wrbfd, ers + j * 2 + 2, 2);
- }
+ re->id.u.n.name[j] = windres_get_16 (wrbfd, ers + j * 2 + 2, 2);
if (level == 0)
type = &re->id;
@@ -263,18 +300,25 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
if ((rva & 0x80000000) != 0)
{
rva &=~ 0x80000000;
- if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
- overrun (flaginfo, _("named subdirectory"));
+ if (rva >= data_len)
+ {
+ overrun (flaginfo, _("named subdirectory"));
+ return NULL;
+ }
re->subdir = 1;
- re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo, type,
- level + 1);
+ re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo,
+ type, level + 1);
}
else
{
- if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
- overrun (flaginfo, _("named resource"));
+ if (rva >= data_len)
+ {
+ overrun (flaginfo, _("named resource"));
+ return NULL;
+ }
re->subdir = 0;
- re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva, flaginfo, type);
+ re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva,
+ flaginfo, type);
}
*pp = re;
@@ -286,8 +330,12 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
unsigned long name, rva;
rc_res_entry *re;
- if ((const bfd_byte *) ere >= flaginfo->data_end)
- overrun (flaginfo, _("ID directory entry"));
+ if ((const bfd_byte *) ere > flaginfo->data_end
+ || flaginfo->data_end - (const bfd_byte *) ere < 8)
+ {
+ overrun (flaginfo, _("ID directory entry"));
+ return NULL;
+ }
name = windres_get_32 (wrbfd, ere->name, 4);
rva = windres_get_32 (wrbfd, ere->rva, 4);
@@ -303,18 +351,25 @@ read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
if ((rva & 0x80000000) != 0)
{
rva &=~ 0x80000000;
- if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
- overrun (flaginfo, _("ID subdirectory"));
+ if (rva >= data_len)
+ {
+ overrun (flaginfo, _("ID subdirectory"));
+ return NULL;
+ }
re->subdir = 1;
- re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo, type,
- level + 1);
+ re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo,
+ type, level + 1);
}
else
{
- if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
- overrun (flaginfo, _("ID resource"));
+ if (rva >= data_len)
+ {
+ overrun (flaginfo, _("ID resource"));
+ return NULL;
+ }
re->subdir = 0;
- re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva, flaginfo, type);
+ re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva,
+ flaginfo, type);
}
*pp = re;
@@ -337,10 +392,16 @@ read_coff_data_entry (windres_bfd *wrbfd, const bfd_byte *data,
const bfd_byte *resdata;
if (type == NULL)
- fatal (_("resource type unknown"));
+ {
+ non_fatal (_("resource type unknown"));
+ return NULL;
+ }
if ((size_t) (flaginfo->data_end - data) < sizeof (struct extern_res_data))
- overrun (flaginfo, _("data entry"));
+ {
+ overrun (flaginfo, _("data entry"));
+ return NULL;
+ }
erd = (const struct extern_res_data *) data;
@@ -348,18 +409,26 @@ read_coff_data_entry (windres_bfd *wrbfd, const bfd_byte *data,
rva = windres_get_32 (wrbfd, erd->rva, 4);
if (rva < flaginfo->secaddr
|| rva - flaginfo->secaddr >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
- overrun (flaginfo, _("resource data"));
+ {
+ overrun (flaginfo, _("resource data"));
+ return NULL;
+ }
resdata = flaginfo->data + (rva - flaginfo->secaddr);
if (size > (rc_uint_type) (flaginfo->data_end - resdata))
- overrun (flaginfo, _("resource data size"));
+ {
+ overrun (flaginfo, _("resource data size"));
+ return NULL;
+ }
r = bin_to_res (wrbfd, *type, resdata, size);
-
- memset (&r->res_info, 0, sizeof (rc_res_res_info));
- r->coff_info.codepage = windres_get_32 (wrbfd, erd->codepage, 4);
- r->coff_info.reserved = windres_get_32 (wrbfd, erd->reserved, 4);
+ if (r != NULL)
+ {
+ memset (&r->res_info, 0, sizeof (rc_res_res_info));
+ r->coff_info.codepage = windres_get_32 (wrbfd, erd->codepage, 4);
+ r->coff_info.reserved = windres_get_32 (wrbfd, erd->reserved, 4);
+ }
return r;
}
@@ -422,9 +491,9 @@ struct coff_write_info
static void coff_bin_sizes (const rc_res_directory *, struct coff_write_info *);
static bfd_byte *coff_alloc (struct bindata_build *, rc_uint_type);
-static void coff_to_bin
+static bool coff_to_bin
(const rc_res_directory *, struct coff_write_info *);
-static void coff_res_to_bin
+static bool coff_res_to_bin
(const rc_res_resource *, struct coff_write_info *);
/* Write resources to a COFF file. RESOURCES should already be
@@ -435,7 +504,7 @@ static void coff_res_to_bin
would require doing the basic work of objcopy, just modifying or
adding the .rsrc section. */
-void
+bool
write_coff_file (const char *filename, const char *target,
const rc_res_directory *resources)
{
@@ -448,44 +517,86 @@ write_coff_file (const char *filename, const char *target,
unsigned long length, offset;
if (filename == NULL)
- fatal (_("filename required for COFF output"));
+ {
+ non_fatal (_("filename required for COFF output"));
+ return false;
+ }
abfd = bfd_openw (filename, target);
if (abfd == NULL)
- bfd_fatal (filename);
+ {
+ bfd_nonfatal (filename);
+ return false;
+ }
if (! bfd_set_format (abfd, bfd_object))
- bfd_fatal ("bfd_set_format");
+ {
+ bfd_nonfatal ("bfd_set_format");
+ bfd_close_all_done (abfd);
+ return false;
+ }
#if defined DLLTOOL_SH
if (! bfd_set_arch_mach (abfd, bfd_arch_sh, 0))
- bfd_fatal ("bfd_set_arch_mach(sh)");
+ {
+ bfd_nonfatal ("bfd_set_arch_mach(sh)");
+ bfd_close_all_done (abfd);
+ return false;
+ }
#elif defined DLLTOOL_MIPS
if (! bfd_set_arch_mach (abfd, bfd_arch_mips, 0))
- bfd_fatal ("bfd_set_arch_mach(mips)");
+ {
+ bfd_nonfatal ("bfd_set_arch_mach(mips)");
+ bfd_close_all_done (abfd);
+ return false;
+ }
#elif defined DLLTOOL_ARM
if (! bfd_set_arch_mach (abfd, bfd_arch_arm, 0))
- bfd_fatal ("bfd_set_arch_mach(arm)");
+ {
+ bfd_nonfatal ("bfd_set_arch_mach(arm)");
+ bfd_close_all_done (abfd);
+ return false;
+ }
#elif defined DLLTOOL_AARCH64
if (! bfd_set_arch_mach (abfd, bfd_arch_aarch64, 0))
- bfd_fatal ("bfd_set_arch_mach(aarch64)");
+ {
+ bfd_nonfatal ("bfd_set_arch_mach(aarch64)");
+ bfd_close_all_done (abfd);
+ return false;
+ }
#else
/* FIXME: This is obviously i386 specific. */
if (! bfd_set_arch_mach (abfd, bfd_arch_i386, 0))
- bfd_fatal ("bfd_set_arch_mach(i386)");
+ {
+ bfd_nonfatal ("bfd_set_arch_mach(i386)");
+ bfd_close_all_done (abfd);
+ return false;
+ }
#endif
if (! bfd_set_file_flags (abfd, HAS_SYMS | HAS_RELOC))
- bfd_fatal ("bfd_set_file_flags");
+ {
+ bfd_nonfatal ("bfd_set_file_flags");
+ bfd_close_all_done (abfd);
+ return false;
+ }
sec = bfd_make_section_with_flags (abfd, ".rsrc",
(SEC_HAS_CONTENTS | SEC_ALLOC
| SEC_LOAD | SEC_DATA | SEC_READONLY));
if (sec == NULL)
- bfd_fatal ("bfd_make_section");
+ {
+ bfd_nonfatal ("bfd_make_section");
+ bfd_close_all_done (abfd);
+ return false;
+ }
if (! bfd_set_symtab (abfd, &sec->symbol, 1))
- bfd_fatal ("bfd_set_symtab");
+ {
+ bfd_nonfatal ("bfd_set_symtab");
+ bfd_close_all_done (abfd);
+ return false;
+ }
/* Requiring this is probably a bug in BFD. */
sec->output_section = sec;
@@ -529,7 +640,12 @@ write_coff_file (const char *filename, const char *target,
cwi.dirstrsize = (cwi.dirstrsize + 7) & ~7;
/* Actually convert the resources to binary. */
- coff_to_bin (resources, &cwi);
+ if (!coff_to_bin (resources, &cwi))
+ {
+ bfd_close_all_done (abfd);
+ free (cwi.relocs);
+ return false;
+ }
/* Add another few bytes to the directory strings if needed for
alignment. */
@@ -554,7 +670,12 @@ write_coff_file (const char *filename, const char *target,
+ cwi.resources.length);
if (!bfd_set_section_size (sec, length))
- bfd_fatal ("bfd_set_section_size");
+ {
+ bfd_nonfatal ("bfd_set_section_size");
+ bfd_close_all_done (abfd);
+ free (cwi.relocs);
+ return false;
+ }
bfd_set_reloc (abfd, sec, cwi.relocs, cwi.reloc_count);
@@ -562,7 +683,12 @@ write_coff_file (const char *filename, const char *target,
for (d = cwi.dirs.d; d != NULL; d = d->next)
{
if (! bfd_set_section_contents (abfd, sec, d->data, offset, d->length))
- bfd_fatal ("bfd_set_section_contents");
+ {
+ bfd_nonfatal ("bfd_set_section_contents");
+ bfd_close_all_done (abfd);
+ free (cwi.relocs);
+ return false;
+ }
offset += d->length;
}
for (d = cwi.dirstrs.d; d != NULL; d = d->next)
@@ -577,17 +703,28 @@ write_coff_file (const char *filename, const char *target,
}
for (rd = cwi.resources.d; rd != NULL; rd = rd->next)
{
- res_to_bin (cwi.wrbfd, (rc_uint_type) offset, rd->res);
+ if (res_to_bin (cwi.wrbfd, (rc_uint_type) offset, rd->res)
+ == (rc_uint_type) -1)
+ {
+ bfd_close_all_done (abfd);
+ free (cwi.relocs);
+ return false;
+ }
offset += rd->length;
}
assert (offset == length);
if (! bfd_close (abfd))
- bfd_fatal ("bfd_close");
+ {
+ bfd_nonfatal ("bfd_close");
+ free (cwi.relocs);
+ return false;
+ }
/* We allocated the relocs array using malloc. */
free (cwi.relocs);
+ return true;
}
/* Work out the sizes of the various fixed size resource directory
@@ -640,7 +777,7 @@ coff_alloc (struct bindata_build *bb, rc_uint_type size)
/* Convert the resource directory RESDIR to binary. */
-static void
+static bool
coff_to_bin (const rc_res_directory *resdir, struct coff_write_info *cwi)
{
struct extern_res_directory *erd;
@@ -701,21 +838,24 @@ coff_to_bin (const rc_res_directory *resdir, struct coff_write_info *cwi)
if (e->subdir)
{
windres_put_32 (cwi->wrbfd, ere->rva, 0x80000000 | cwi->dirs.length);
- coff_to_bin (e->u.dir, cwi);
+ if (!coff_to_bin (e->u.dir, cwi))
+ return false;
}
else
{
windres_put_32 (cwi->wrbfd, ere->rva,
- cwi->dirsize + cwi->dirstrsize + cwi->dataents.length);
+ cwi->dirsize + cwi->dirstrsize + cwi->dataents.length);
- coff_res_to_bin (e->u.res, cwi);
+ if (!coff_res_to_bin (e->u.res, cwi))
+ return false;
}
}
+ return true;
}
/* Convert the resource RES to binary. */
-static void
+static bool
coff_res_to_bin (const rc_res_resource *res, struct coff_write_info *cwi)
{
arelent *r;
@@ -735,7 +875,10 @@ coff_res_to_bin (const rc_res_resource *res, struct coff_write_info *cwi)
r->addend = 0;
r->howto = bfd_reloc_type_lookup (WR_BFD (cwi->wrbfd), BFD_RELOC_RVA);
if (r->howto == NULL)
- bfd_fatal (_("can't get BFD_RELOC_RVA relocation type"));
+ {
+ bfd_nonfatal (_("can't get BFD_RELOC_RVA relocation type"));
+ return false;
+ }
cwi->relocs = xrealloc (cwi->relocs,
(cwi->reloc_count + 2) * sizeof (arelent *));
@@ -755,6 +898,8 @@ coff_res_to_bin (const rc_res_resource *res, struct coff_write_info *cwi)
d = (coff_res_data *) reswr_alloc (sizeof (coff_res_data));
d->length = res_to_bin (NULL, (rc_uint_type) 0, res);
+ if (d->length == (rc_uint_type) -1)
+ return false;
d->res = res;
d->next = NULL;
@@ -770,4 +915,5 @@ coff_res_to_bin (const rc_res_resource *res, struct coff_write_info *cwi)
/* Force the next resource to have 64 bit alignment. */
d->length = (d->length + 7) & ~7;
+ return true;
}
diff --git a/binutils/resrc.c b/binutils/resrc.c
index d265818..8f9451b 100644
--- a/binutils/resrc.c
+++ b/binutils/resrc.c
@@ -1938,7 +1938,7 @@ indent (FILE *e, int c)
refer to that file, we use the user-data model for that to express it binary
without the need to store it somewhere externally. */
-void
+bool
write_rc_file (const char *filename, const rc_res_directory *res_dir)
{
FILE *e;
@@ -1950,12 +1950,17 @@ write_rc_file (const char *filename, const rc_res_directory *res_dir)
{
e = fopen (filename, FOPEN_WT);
if (e == NULL)
- fatal (_("can't open `%s' for output: %s"), filename, strerror (errno));
+ {
+ non_fatal (_("can't open `%s' for output: %s"),
+ filename, strerror (errno));
+ return false;
+ }
}
language = (rc_uint_type) ((bfd_signed_vma) -1);
write_rc_directory (e, res_dir, (const rc_res_id *) NULL,
(const rc_res_id *) NULL, &language, 1);
+ return true;
}
/* Write out a directory. E is the file to write to. RD is the
diff --git a/binutils/resres.c b/binutils/resres.c
index ab5aa66..d96fb14 100644
--- a/binutils/resres.c
+++ b/binutils/resres.c
@@ -109,14 +109,14 @@ read_res_file (const char *fn)
}
/* Write resource file */
-void
+bool
write_res_file (const char *fn,const rc_res_directory *resdir)
{
asection *sec;
rc_uint_type language;
bfd *abfd;
windres_bfd wrbfd;
- unsigned long sec_length = 0,sec_length_wrote;
+ rc_uint_type sec_length = 0, sec_length_wrote;
static const bfd_byte sign[] =
{0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
@@ -130,7 +130,10 @@ write_res_file (const char *fn,const rc_res_directory *resdir)
(SEC_HAS_CONTENTS | SEC_ALLOC
| SEC_LOAD | SEC_DATA));
if (sec == NULL)
- bfd_fatal ("bfd_make_section");
+ {
+ bfd_nonfatal ("bfd_make_section");
+ return false;
+ }
/* Requiring this is probably a bug in BFD. */
sec->output_section = sec;
@@ -142,8 +145,13 @@ write_res_file (const char *fn,const rc_res_directory *resdir)
sec_length = write_res_directory ((windres_bfd *) NULL, 0x20UL, resdir,
(const rc_res_id *) NULL,
(const rc_res_id *) NULL, &language, 1);
+ if (sec_length == (rc_uint_type) -1)
+ return false;
if (!bfd_set_section_size (sec, (sec_length + 3) & ~3))
- bfd_fatal ("bfd_set_section_size");
+ {
+ bfd_nonfatal ("bfd_set_section_size");
+ return false;
+ }
if ((sec_length & 3) != 0)
set_windres_bfd_content (&wrbfd, sign, sec_length, 4-(sec_length & 3));
set_windres_bfd_content (&wrbfd, sign, 0, sizeof (sign));
@@ -152,12 +160,16 @@ write_res_file (const char *fn,const rc_res_directory *resdir)
(const rc_res_id *) NULL,
(const rc_res_id *) NULL,
&language, 1);
+ if (sec_length_wrote == (rc_uint_type) -1)
+ return false;
if (sec_length != sec_length_wrote)
- fatal ("res write failed with different sizes (%lu/%lu).",
- (unsigned long) sec_length, (unsigned long) sec_length_wrote);
+ {
+ non_fatal ("res write failed with different sizes (%lu/%lu).",
+ (unsigned long) sec_length, (unsigned long) sec_length_wrote);
+ return false;
+ }
- bfd_close (abfd);
- return;
+ return bfd_close (abfd);
}
/* Read a resource entry, returns 0 when all resources are read */
@@ -252,8 +264,12 @@ write_res_directory (windres_bfd *wrbfd, rc_uint_type off, const rc_res_director
}
if (re->subdir)
- off = write_res_directory (wrbfd, off, re->u.dir, type, name, language,
- level + 1);
+ {
+ off = write_res_directory (wrbfd, off, re->u.dir, type, name, language,
+ level + 1);
+ if (off == (rc_uint_type) -1)
+ return off;
+ }
else
{
if (level == 3)
@@ -265,12 +281,16 @@ write_res_directory (windres_bfd *wrbfd, rc_uint_type off, const rc_res_director
resource itself records if anything. */
off = write_res_resource (wrbfd, off, type, name, re->u.res,
language);
+ if (off == (rc_uint_type) -1)
+ return off;
}
else
{
fprintf (stderr, "// Resource at unexpected level %d\n", level);
off = write_res_resource (wrbfd, off, type, (rc_res_id *) NULL,
re->u.res, language);
+ if (off == (rc_uint_type) -1)
+ return off;
}
}
}
@@ -378,6 +398,8 @@ write_res_bin (windres_bfd *wrbfd, rc_uint_type off, const rc_res_resource *res,
rc_uint_type datasize = 0;
noff = res_to_bin ((windres_bfd *) NULL, off, res);
+ if (noff == (rc_uint_type) -1)
+ return noff;
datasize = noff - off;
off = write_res_header (wrbfd, off, datasize, type, name, resinfo);
diff --git a/binutils/windres.c b/binutils/windres.c
index 18062f5..b41353b 100644
--- a/binutils/windres.c
+++ b/binutils/windres.c
@@ -1056,23 +1056,24 @@ main (int argc, char **argv)
/* Write the output file. */
reswr_init ();
+ bool ok;
switch (output_format)
{
default:
abort ();
case RES_FORMAT_RC:
- write_rc_file (output_filename, resources);
+ ok = write_rc_file (output_filename, resources);
break;
case RES_FORMAT_RES:
- write_res_file (output_filename, resources);
+ ok = write_res_file (output_filename, resources);
break;
case RES_FORMAT_COFF:
- write_coff_file (output_filename, target, resources);
+ ok = write_coff_file (output_filename, target, resources);
break;
}
- xexit (0);
- return 0;
+ xexit (ok ? 0 : 1);
+ return ok ? 0 : 1;
}
static void
@@ -1094,13 +1095,18 @@ windres_open_as_binary (const char *filename, int rdmode)
{
bfd *abfd;
- abfd = (rdmode ? bfd_openr (filename, "binary") : bfd_openw (filename, "binary"));
- if (! abfd)
- fatal ("can't open `%s' for %s", filename, (rdmode ? "input" : "output"));
-
- if (rdmode && ! bfd_check_format (abfd, bfd_object))
- fatal ("can't open `%s' for input.", filename);
-
+ if (rdmode)
+ {
+ abfd = bfd_openr (filename, "binary");
+ if (abfd == NULL || !bfd_check_format (abfd, bfd_object))
+ fatal ("can't open `%s' for input", filename);
+ }
+ else
+ {
+ abfd = bfd_openw (filename, "binary");
+ if (abfd == NULL || !bfd_set_format (abfd, bfd_object))
+ fatal ("can't open `%s' for output", filename);
+ }
return abfd;
}
diff --git a/binutils/windres.h b/binutils/windres.h
index 309564e..15c6ad0 100644
--- a/binutils/windres.h
+++ b/binutils/windres.h
@@ -35,9 +35,9 @@ extern int verbose;
extern rc_res_directory *read_rc_file (const char *, const char *, const char *, int, int);
extern rc_res_directory *read_res_file (const char *);
extern rc_res_directory *read_coff_rsrc (const char *, const char *);
-extern void write_rc_file (const char *, const rc_res_directory *);
-extern void write_res_file (const char *, const rc_res_directory *);
-extern void write_coff_file (const char *, const char *, const rc_res_directory *);
+extern bool write_rc_file (const char *, const rc_res_directory *);
+extern bool write_res_file (const char *, const rc_res_directory *);
+extern bool write_coff_file (const char *, const char *, const rc_res_directory *);
extern rc_res_resource *bin_to_res (windres_bfd *, rc_res_id, const bfd_byte *,
rc_uint_type);
diff --git a/gas/config/loongarch-parse.y b/gas/config/loongarch-parse.y
index 97055fe..b75040c 100644
--- a/gas/config/loongarch-parse.y
+++ b/gas/config/loongarch-parse.y
@@ -207,29 +207,41 @@ emit_bin (int op)
switch (op)
{
case '*':
- opr1 = opr1 * opr2;
+ opr1 = (valueT) opr1 * (valueT) opr2;
break;
case '/':
- opr1 = opr1 / opr2;
+ if (opr2 == 0)
+ {
+ as_warn (_("Divide by zero!"));
+ opr1 = 0;
+ }
+ else
+ opr1 = opr1 / opr2;
break;
case '%':
- opr1 = opr1 % opr2;
+ if (opr2 == 0)
+ {
+ as_warn (_("Divide by zero!"));
+ opr1 = 0;
+ }
+ else
+ opr1 = opr1 % opr2;
break;
case '+':
- opr1 = opr1 + opr2;
+ opr1 = (valueT) opr1 + (valueT) opr2;
break;
case '-':
- opr1 = opr1 - opr2;
+ opr1 = (valueT) opr1 - (valueT) opr2;
break;
case LEFT_OP:
- opr1 = opr1 << opr2;
+ opr1 = (valueT) opr1 << opr2;
break;
case RIGHT_OP:
if (opr1 < 0)
- as_warn(_("Right shift of negative numbers may be changed "
- "from arithmetic right shift to logical right shift!"));
- /* Algorithm right shift. */
- opr1 = (offsetT)opr1 >> (offsetT)opr2;
+ as_warn (_("Right shift of negative numbers may be changed "
+ "from arithmetic right shift to logical right shift!"));
+ /* Arithmetic right shift. */
+ opr1 = opr1 >> opr2;
break;
case '<':
opr1 = opr1 < opr2;
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index e071ad1..75aee15 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -9121,7 +9121,7 @@ aarch64_sframe_cfa_ra_offset (void)
return (offsetT) SFRAME_CFA_FIXED_RA_INVALID;
}
-/* Get the abi/arch indentifier for SFrame. */
+/* Get the abi/arch identifier for SFrame. */
unsigned char
aarch64_sframe_get_abi_arch (void)
diff --git a/gas/config/tc-aarch64.h b/gas/config/tc-aarch64.h
index acf1ce4..c2d0511 100644
--- a/gas/config/tc-aarch64.h
+++ b/gas/config/tc-aarch64.h
@@ -309,7 +309,7 @@ extern bool aarch64_sframe_ra_tracking_p (void);
extern offsetT aarch64_sframe_cfa_ra_offset (void);
#define sframe_cfa_ra_offset aarch64_sframe_cfa_ra_offset
-/* The abi/arch indentifier for SFrame. */
+/* The abi/arch identifier for SFrame. */
unsigned char aarch64_sframe_get_abi_arch (void);
#define sframe_get_abi_arch aarch64_sframe_get_abi_arch
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 2c61353..3e7040a 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -11968,7 +11968,7 @@ x86_sframe_cfa_ra_offset (void)
return (offsetT) -8;
}
-/* The abi/arch indentifier for SFrame. */
+/* The abi/arch identifier for SFrame. */
unsigned char
x86_sframe_get_abi_arch (void)
{
diff --git a/gas/config/tc-i386.h b/gas/config/tc-i386.h
index 3fb7920..19eb0bc 100644
--- a/gas/config/tc-i386.h
+++ b/gas/config/tc-i386.h
@@ -471,7 +471,7 @@ extern bool x86_sframe_ra_tracking_p (void);
extern offsetT x86_sframe_cfa_ra_offset (void);
#define sframe_cfa_ra_offset x86_sframe_cfa_ra_offset
-/* The abi/arch indentifier for SFrame. */
+/* The abi/arch identifier for SFrame. */
extern unsigned char x86_sframe_get_abi_arch (void);
#define sframe_get_abi_arch x86_sframe_get_abi_arch
diff --git a/gas/config/tc-m68k.c b/gas/config/tc-m68k.c
index 0f36741..46b26d4 100644
--- a/gas/config/tc-m68k.c
+++ b/gas/config/tc-m68k.c
@@ -6754,7 +6754,6 @@ s_mri_for (int qual)
struct mri_control_info *n;
char *buf;
char *s;
- char ex[2];
/* The syntax is
FOR.q var = init { TO | DOWNTO } end [ BY by ] DO.e
@@ -6935,12 +6934,14 @@ s_mri_for (int qual)
mri_assemble (buf);
/* bcc bottom. */
- ex[0] = TOLOWER (extent);
- ex[1] = '\0';
- if (up)
- sprintf (buf, "blt%s %s", ex, n->bottom);
- else
- sprintf (buf, "bgt%s %s", ex, n->bottom);
+ s = buf;
+ *s++ = 'b';
+ *s++ = up ? 'l' : 'g';
+ *s++ = 't';
+ if (extent != '\0')
+ *s++ = TOLOWER (extent);
+ *s++ = ' ';
+ strcpy (s, n->bottom);
mri_assemble (buf);
/* Put together the add or sub instruction used by ENDF. */
diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index 5b5e7b1..5c8c7eb 100644
--- a/gas/gen-sframe.c
+++ b/gas/gen-sframe.c
@@ -1038,7 +1038,9 @@ sframe_xlate_do_def_cfa_register (struct sframe_xlate_ctx *xlate_ctx,
return SFRAME_XLATE_ERR_NOTREPRESENTED; /* Not represented. */
}
sframe_fre_set_cfa_base_reg (cur_fre, cfi_insn->u.r);
- sframe_fre_set_cfa_offset (cur_fre, last_fre->cfa_offset);
+ if (last_fre)
+ sframe_fre_set_cfa_offset (cur_fre, last_fre->cfa_offset);
+
cur_fre->merge_candidate = false;
return SFRAME_XLATE_OK;
diff --git a/gas/testsuite/gas/aarch64/pac_ab_key.d b/gas/testsuite/gas/aarch64/pac_ab_key.d
index 4012d14..04d5fa4 100644
--- a/gas/testsuite/gas/aarch64/pac_ab_key.d
+++ b/gas/testsuite/gas/aarch64/pac_ab_key.d
@@ -7,7 +7,7 @@
.+: file .+
-Contents of the .eh_frame section:
+Contents of the \.eh_frame section:
0+ 0+10 0+ CIE
Version: 1
diff --git a/gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.d b/gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.d
index 8e59086..6ef77ae 100644
--- a/gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.d
+++ b/gas/testsuite/gas/aarch64/pac_compat_cfi_window_save.d
@@ -22,7 +22,7 @@
.+: file .+
-Contents of the .eh_frame section:
+Contents of the \.eh_frame section:
0+ 0+10 0+ CIE
Version: 1
diff --git a/gas/testsuite/gas/aarch64/pac_negate_ra_state.d b/gas/testsuite/gas/aarch64/pac_negate_ra_state.d
index f49cebc..fa29c7f 100644
--- a/gas/testsuite/gas/aarch64/pac_negate_ra_state.d
+++ b/gas/testsuite/gas/aarch64/pac_negate_ra_state.d
@@ -4,7 +4,7 @@
.+: file .+
-Contents of the .eh_frame section:
+Contents of the \.eh_frame section:
0+ 0+10 0+ CIE
Version: 1
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.d b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.d
new file mode 100644
index 0000000..d779b6d
--- /dev/null
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.d
@@ -0,0 +1,21 @@
+#as: --gsframe
+#objdump: --sframe=.sframe
+#name: Check .cfi_def_cfa_register with no previous offset
+#...
+Contents of the SFrame section .sframe:
+
+ Header :
+
+ Version: SFRAME_VERSION_2
+ Flags: NONE
+#? CFA fixed FP offset: \-?\d+
+#? CFA fixed RA offset: \-?\d+
+ Num FDEs: 1
+ Num FREs: 1
+
+ Function Index :
+
+ func idx \[0\]: pc = 0x0, size = 0 bytes
+ STARTPC +CFA +FP +RA +
+ 0+0000 +fp\+8 +u +f +
+#pass
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.s b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.s
new file mode 100644
index 0000000..f3f9859
--- /dev/null
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe-x86_64-2.s
@@ -0,0 +1,4 @@
+# Although not a useful construct by itself, ensure graceful handling.
+ .cfi_startproc
+ .cfi_def_cfa_register 6
+ .cfi_endproc
diff --git a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
index a099466..b353e27 100644
--- a/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
+++ b/gas/testsuite/gas/cfi-sframe/cfi-sframe.exp
@@ -90,6 +90,7 @@ if { [istarget "x86_64-*-*"] && [gas_sframe_check] } then {
if { [gas_x86_64_check] } then {
set ASFLAGS "$ASFLAGS --64"
run_dump_test "cfi-sframe-x86_64-1"
+ run_dump_test "cfi-sframe-x86_64-2"
run_dump_test "cfi-sframe-x86_64-empty-1"
run_dump_test "cfi-sframe-x86_64-empty-2"
run_dump_test "cfi-sframe-x86_64-empty-3"
diff --git a/gas/testsuite/gas/loongarch/div_zero.l b/gas/testsuite/gas/loongarch/div_zero.l
new file mode 100644
index 0000000..b30c665
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/div_zero.l
@@ -0,0 +1,4 @@
+#source: div_zero.s
+.*: Assembler messages:
+.*: Warning: Divide by zero!
+.*: Warning: Divide by zero!
diff --git a/gas/testsuite/gas/loongarch/div_zero.s b/gas/testsuite/gas/loongarch/div_zero.s
new file mode 100644
index 0000000..44a5c26
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/div_zero.s
@@ -0,0 +1,2 @@
+addi.w $a0,$a1,2/0
+addi.d $a0,$a1,4%0
diff --git a/gas/testsuite/gas/loongarch/fix_op.d b/gas/testsuite/gas/loongarch/fix_op.d
index 7125f2e..05e7403 100644
--- a/gas/testsuite/gas/loongarch/fix_op.d
+++ b/gas/testsuite/gas/loongarch/fix_op.d
@@ -132,3 +132,6 @@ Disassembly of section .text:
[ ]+1e8:[ ]+00df04a4 [ ]+bstrpick.d[ ]+[ ]+\$a0, \$a1, 0x1f, 0x1
[ ]+1ec:[ ]+00e000a4 [ ]+bstrpick.d[ ]+[ ]+\$a0, \$a1, 0x20, 0x0
[ ]+1f0:[ ]+00ff00a4 [ ]+bstrpick.d[ ]+[ ]+\$a0, \$a1, 0x3f, 0x0
+[ ]+1f4:[ ]+00006004 [ ]+rdcntvl.w[ ]+[ ]+\$a0
+[ ]+1f8:[ ]+000060a0 [ ]+rdcntid.w[ ]+[ ]+\$a1
+[ ]+1fc:[ ]+00006404 [ ]+rdcntvh.w[ ]+[ ]+\$a0
diff --git a/gas/testsuite/gas/loongarch/fix_op.s b/gas/testsuite/gas/loongarch/fix_op.s
index d0523f9..876913b 100644
--- a/gas/testsuite/gas/loongarch/fix_op.s
+++ b/gas/testsuite/gas/loongarch/fix_op.s
@@ -123,3 +123,8 @@ bstrpick.d $r4,$r5,0,0
bstrpick.d $r4,$r5,31,1
bstrpick.d $r4,$r5,32,0
bstrpick.d $r4,$r5,63,0
+
+# LA32R aliases
+rdcntvl.w $r4
+rdcntid.w $r5
+rdcntvh.w $r4
diff --git a/gas/testsuite/gas/loongarch/insn_alias_32.d b/gas/testsuite/gas/loongarch/insn_alias_32.d
index 753eae7..3aa716f 100644
--- a/gas/testsuite/gas/loongarch/insn_alias_32.d
+++ b/gas/testsuite/gas/loongarch/insn_alias_32.d
@@ -17,3 +17,6 @@ Disassembly of section .text:
18: 60000080 blt \$a0, \$zero, 0 # 18 <L1\+0x18>
1c: 64000080 bge \$a0, \$zero, 0 # 1c <L1\+0x1c>
20: 64000004 bge \$zero, \$a0, 0 # 20 <L1\+0x20>
+ 24: 00006004 rdtimel.w \$a0, \$zero
+ 28: 000060a0 rdtimel.w \$zero, \$a1
+ 2c: 00006406 rdtimeh.w \$a2, \$zero
diff --git a/gas/testsuite/gas/loongarch/insn_alias_32.s b/gas/testsuite/gas/loongarch/insn_alias_32.s
index 8027e32..492e52a 100644
--- a/gas/testsuite/gas/loongarch/insn_alias_32.s
+++ b/gas/testsuite/gas/loongarch/insn_alias_32.s
@@ -8,3 +8,8 @@ L1:
bltz $a0,.L1
bgez $a0,.L1
blez $a0,.L1
+
+ # LA32R aliases
+ rdcntvl.w $a0
+ rdcntid.w $a1
+ rdcntvh.w $a2
diff --git a/gas/testsuite/gas/loongarch/loongarch.exp b/gas/testsuite/gas/loongarch/loongarch.exp
index 0e836f7..d2008f4 100644
--- a/gas/testsuite/gas/loongarch/loongarch.exp
+++ b/gas/testsuite/gas/loongarch/loongarch.exp
@@ -37,5 +37,6 @@ if [istarget loongarch*-*-*] {
run_list_test "illegal-operand"
run_list_test "pseudo_op_option_fail"
run_list_test "negative_right_shift"
+ run_list_test "div_zero"
}
}
diff --git a/gdb/MAINTAINERS b/gdb/MAINTAINERS
index 187a1f6..5e1aada 100644
--- a/gdb/MAINTAINERS
+++ b/gdb/MAINTAINERS
@@ -724,6 +724,7 @@ Theodore A. Roth troth@openavr.org
Yvan Roux yvan.roux@foss.st.com
Ian Roxborough irox@redhat.com
Maciej W. Rozycki macro@orcam.me.uk
+Piotr Rudnicki piotr.rudnicki@intel.com
Kamil Rytarowski n54@gmx.com
Grace Sainsbury graces@redhat.com
Kei Sakamoto sakamoto.kei@renesas.com
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 9275f8d..9f21695 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -479,6 +479,7 @@ SELFTESTS_SRCS = \
unittests/ptid-selftests.c \
unittests/main-thread-selftests.c \
unittests/mkdir-recursive-selftests.c \
+ unittests/remote-arg-selftests.c \
unittests/rsp-low-selftests.c \
unittests/scoped_fd-selftests.c \
unittests/scoped_ignore_signal-selftests.c \
@@ -769,6 +770,7 @@ ALL_64_TARGET_OBS = \
mips-sde-tdep.o \
mips-tdep.o \
mips64-obsd-tdep.o \
+ riscv-canonicalize-syscall-gen.o \
riscv-fbsd-tdep.o \
riscv-linux-tdep.o \
riscv-none-tdep.o \
@@ -896,6 +898,7 @@ ALL_TARGET_OBS = \
sparc-ravenscar-thread.o \
sparc-sol2-tdep.o \
sparc-tdep.o \
+ svr4-tls-tdep.o \
symfile-mem.o \
tic6x-linux-tdep.o \
tic6x-tdep.o \
@@ -1520,6 +1523,7 @@ HFILES_NO_SRCDIR = \
stabsread.h \
stack.h \
stap-probe.h \
+ svr4-tls-tdep.h \
symfile.h \
symtab.h \
target.h \
@@ -1883,6 +1887,7 @@ ALLDEPFILES = \
sparc64-obsd-tdep.c \
sparc64-sol2-tdep.c \
sparc64-tdep.c \
+ svr4-tls-tdep.c \
tilegx-linux-nat.c \
tilegx-linux-tdep.c \
tilegx-tdep.c \
diff --git a/gdb/NEWS b/gdb/NEWS
index 99ec392..14d3063 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -40,6 +40,14 @@
namespace into which the library was loaded, if more than one namespace
is active.
+* New built-in convenience variables $_active_linker_namespaces and
+ $_current_linker_namespace. These show the number of active linkage
+ namespaces, and the namespace to which the current location belongs to.
+ In systems that don't support linkage namespaces, these always return 1
+ and [[0]] respectively.
+
+ * Add record full support for rv64gc architectures
+
* New commands
maintenance check psymtabs
@@ -54,6 +62,11 @@ show riscv numeric-register-names
(e.g 'x1') or their abi names (e.g. 'ra').
Defaults to 'off', matching the old behaviour (abi names).
+info linker-namespaces
+info linker-namespaces [[N]]
+ Print information about the given linker namespace (identified as N),
+ or about all the namespaces if no argument is given.
+
* Changed commands
info sharedlibrary
@@ -61,6 +74,26 @@ info sharedlibrary
command are now for the full memory range allocated to the shared
library.
+* GDB-internal Thread Local Storage (TLS) support
+
+ ** Linux targets for the x86_64, aarch64, ppc64, s390x, and riscv
+ architectures now have GDB-internal support for TLS address
+ lookup in addition to that traditionally provided by the
+ libthread_db library. This internal support works for programs
+ linked against either the GLIBC or MUSL C libraries. For
+ programs linked against MUSL, this new internal support provides
+ new debug functionality, allowing access to TLS variables, due to
+ the fact that MUSL does not implement the libthread_db library.
+ Internal TLS support is also useful in cross-debugging
+ situations, debugging statically linked binaries, and debugging
+ programs linked against GLIBC 2.33 and earlier, but which are not
+ linked against libpthread.
+
+ ** The command 'maint set force-internal-tls-address-lookup on' may
+ be used to force the internal TLS lookup mechanisms to be used.
+ Otherwise, TLS lookup via libthread_db will still be preferred,
+ when available.
+
* Python API
** New class gdb.Color for dealing with colors.
diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 9cee355..b6cdcf0 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -24,6 +24,7 @@
#include "gdbarch.h"
#include "glibc-tdep.h"
#include "linux-tdep.h"
+#include "svr4-tls-tdep.h"
#include "aarch64-tdep.h"
#include "aarch64-linux-tdep.h"
#include "osabi.h"
@@ -35,6 +36,7 @@
#include "target/target.h"
#include "expop.h"
#include "auxv.h"
+#include "inferior.h"
#include "regcache.h"
#include "regset.h"
@@ -2701,6 +2703,57 @@ aarch64_use_target_description_from_corefile_notes (gdbarch *gdbarch,
return true;
}
+/* Fetch and return the TLS DTV (dynamic thread vector) address for PTID.
+ Throw a suitable TLS error if something goes wrong. */
+
+static CORE_ADDR
+aarch64_linux_get_tls_dtv_addr (struct gdbarch *gdbarch, ptid_t ptid,
+ svr4_tls_libc libc)
+{
+ /* On aarch64, the thread pointer is found in the TPIDR register.
+ Note that this is the first register in the TLS feature - see
+ features/aarch64-tls.c - and it will always be present. */
+ regcache *regcache
+ = get_thread_arch_regcache (current_inferior (), ptid, gdbarch);
+ aarch64_gdbarch_tdep *tdep = gdbarch_tdep<aarch64_gdbarch_tdep> (gdbarch);
+ target_fetch_registers (regcache, tdep->tls_regnum_base);
+ ULONGEST thr_ptr;
+ if (regcache->cooked_read (tdep->tls_regnum_base, &thr_ptr) != REG_VALID)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to fetch thread pointer"));
+
+ CORE_ADDR dtv_ptr_addr;
+ switch (libc)
+ {
+ case svr4_tls_libc_musl:
+ /* MUSL: The DTV pointer is found at the very end of the pthread
+ struct which is located *before* the thread pointer. I.e.
+ the thread pointer will be just beyond the end of the struct,
+ so the address of the DTV pointer is found one pointer-size
+ before the thread pointer. */
+ dtv_ptr_addr = thr_ptr - (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
+ break;
+ case svr4_tls_libc_glibc:
+ /* GLIBC: The thread pointer (tpidr) points at the TCB (thread control
+ block). On aarch64, this struct (tcbhead_t) is defined to
+ contain two pointers. The first is a pointer to the DTV and
+ the second is a pointer to private data. So the DTV pointer
+ address is the same as the thread pointer. */
+ dtv_ptr_addr = thr_ptr;
+ break;
+ default:
+ throw_error (TLS_GENERIC_ERROR, _("Unknown aarch64 C library"));
+ break;
+ }
+ gdb::byte_vector buf (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
+ if (target_read_memory (dtv_ptr_addr, buf.data (), buf.size ()) != 0)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to fetch DTV address"));
+
+ const struct builtin_type *builtin = builtin_type (gdbarch);
+ CORE_ADDR dtv_addr = gdbarch_pointer_to_address
+ (gdbarch, builtin->builtin_data_ptr, buf.data ());
+ return dtv_addr;
+}
+
static void
aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
@@ -2722,6 +2775,9 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
/* Enable TLS support. */
set_gdbarch_fetch_tls_load_module_address (gdbarch,
svr4_fetch_objfile_link_map);
+ set_gdbarch_get_thread_local_address (gdbarch,
+ svr4_tls_get_thread_local_address);
+ svr4_tls_register_tls_methods (info, gdbarch, aarch64_linux_get_tls_dtv_addr);
/* Shared library handling. */
set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 9d35440..3f5e707 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -36,7 +36,7 @@
#include "objfiles.h"
#include "breakpoint.h"
#include "gdbcore.h"
-#include "hashtab.h"
+#include "gdbsupport/unordered_set.h"
#include "gdbsupport/gdb_obstack.h"
#include "ada-lang.h"
#include "completer.h"
@@ -52,6 +52,7 @@
#include "namespace.h"
#include "cli/cli-style.h"
#include "cli/cli-decode.h"
+#include "gdbsupport/string-set.h"
#include "value.h"
#include "mi/mi-common.h"
@@ -349,56 +350,58 @@ struct cache_entry_search
{
const char *name;
domain_search_flags domain;
+};
+
+/* Hash function for cache entry. */
+
+struct cache_entry_hash
+{
+ using is_transparent = void;
+ using is_avalanching = void;
- hashval_t hash () const
+ /* This implementation works for both cache_entry and
+ cache_entry_search. */
+ template<typename T>
+ uint64_t operator() (const T &entry) const noexcept
{
- /* This must agree with hash_cache_entry, below. */
- return htab_hash_string (name);
+ return ankerl::unordered_dense::hash<std::string_view> () (entry.name);
}
};
-/* Hash function for cache_entry. */
+/* Equality function for cache entry. */
-static hashval_t
-hash_cache_entry (const void *v)
+struct cache_entry_eq
{
- const cache_entry *entry = (const cache_entry *) v;
- return htab_hash_string (entry->name.c_str ());
-}
-
-/* Equality function for cache_entry. */
+ using is_transparent = void;
-static int
-eq_cache_entry (const void *a, const void *b)
-{
- const cache_entry *entrya = (const cache_entry *) a;
- const cache_entry_search *entryb = (const cache_entry_search *) b;
+ /* This implementation works for both cache_entry and
+ cache_entry_search. */
+ template<typename T>
+ bool operator() (const T &lhs, const cache_entry &rhs) const noexcept
+ {
+ return lhs.domain == rhs.domain && lhs.name == rhs.name;
+ }
+};
- return entrya->domain == entryb->domain && entrya->name == entryb->name;
-}
+using cache_entry_set
+ = gdb::unordered_set<cache_entry, cache_entry_hash, cache_entry_eq>;
/* Key to our per-program-space data. */
-static const registry<program_space>::key<htab, htab_deleter>
+static const registry<program_space>::key<cache_entry_set>
ada_pspace_data_handle;
-/* Return this module's data for the given program space (PSPACE).
- If not is found, add a zero'ed one now.
-
- This function always returns a valid object. */
+/* Return this module's data for the given program space (PSPACE). If
+ not is found, one is created. This function always returns a valid
+ object. */
-static htab_t
+static cache_entry_set &
get_ada_pspace_data (struct program_space *pspace)
{
- htab_t data = ada_pspace_data_handle.get (pspace);
+ cache_entry_set *data = ada_pspace_data_handle.get (pspace);
if (data == nullptr)
- {
- data = htab_create_alloc (10, hash_cache_entry, eq_cache_entry,
- htab_delete_entry<cache_entry>,
- xcalloc, xfree);
- ada_pspace_data_handle.set (pspace, data);
- }
+ data = ada_pspace_data_handle.emplace (pspace);
- return data;
+ return *data;
}
/* Utilities */
@@ -1603,7 +1606,7 @@ ada_decode_tests ()
storage leak, it should not be significant unless there are massive
changes in the set of decoded names in successive versions of a
symbol table loaded during a single session. */
-static struct htab *decoded_names_store;
+static gdb::string_set decoded_names_store;
/* Returns the decoded name of GSYMBOL, as for ada_decode, caching it
in the language-specific part of GSYMBOL, if it has not been
@@ -1637,13 +1640,7 @@ ada_decode_symbol (const struct general_symbol_info *arg)
which case, we put the result on the heap. Since we only
decode when needed, we hope this usually does not cause a
significant memory leak (FIXME). */
-
- char **slot = (char **) htab_find_slot (decoded_names_store,
- decoded.c_str (), INSERT);
-
- if (*slot == NULL)
- *slot = xstrdup (decoded.c_str ());
- *resultp = *slot;
+ *resultp = decoded_names_store.insert (decoded);
}
}
@@ -3950,9 +3947,9 @@ ada_type_match (struct type *ftype, struct type *atype)
atype = ada_check_typedef (atype);
if (ftype->code () == TYPE_CODE_REF)
- ftype = ftype->target_type ();
+ ftype = ada_check_typedef (ftype->target_type ());
if (atype->code () == TYPE_CODE_REF)
- atype = atype->target_type ();
+ atype = ada_check_typedef (atype->target_type ());
switch (ftype->code ())
{
@@ -4695,19 +4692,18 @@ static int
lookup_cached_symbol (const char *name, domain_search_flags domain,
struct symbol **sym, const struct block **block)
{
- htab_t tab = get_ada_pspace_data (current_program_space);
+ cache_entry_set &htab = get_ada_pspace_data (current_program_space);
cache_entry_search search;
search.name = name;
search.domain = domain;
- cache_entry *e = (cache_entry *) htab_find_with_hash (tab, &search,
- search.hash ());
- if (e == nullptr)
+ auto iter = htab.find (search);
+ if (iter == htab.end ())
return 0;
if (sym != nullptr)
- *sym = e->sym;
+ *sym = iter->sym;
if (block != nullptr)
- *block = e->block;
+ *block = iter->block;
return 1;
}
@@ -4735,21 +4731,8 @@ cache_symbol (const char *name, domain_search_flags domain,
return;
}
- htab_t tab = get_ada_pspace_data (current_program_space);
- cache_entry_search search;
- search.name = name;
- search.domain = domain;
-
- void **slot = htab_find_slot_with_hash (tab, &search,
- search.hash (), INSERT);
-
- cache_entry *e = new cache_entry;
- e->name = name;
- e->domain = domain;
- e->sym = sym;
- e->block = block;
-
- *slot = e;
+ cache_entry_set &tab = get_ada_pspace_data (current_program_space);
+ tab.insert (cache_entry {name, domain, sym, block});
}
/* Symbol Lookup */
@@ -14049,10 +14032,6 @@ When enabled, the debugger will stop using the DW_AT_GNAT_descriptive_type\n\
DWARF attribute."),
NULL, NULL, &maint_set_ada_cmdlist, &maint_show_ada_cmdlist);
- decoded_names_store = htab_create_alloc (256, htab_hash_string,
- htab_eq_string,
- NULL, xcalloc, xfree);
-
/* The ada-lang observers. */
gdb::observers::new_objfile.attach (ada_new_objfile_observer, "ada-lang");
gdb::observers::all_objfiles_removed.attach (ada_clear_symbol_cache,
diff --git a/gdb/ada-varobj.c b/gdb/ada-varobj.c
index 140fc71..c87e7be 100644
--- a/gdb/ada-varobj.c
+++ b/gdb/ada-varobj.c
@@ -379,16 +379,14 @@ ada_varobj_get_number_of_children (struct value *parent_value,
whose index is CHILD_INDEX:
- If CHILD_NAME is not NULL, then a copy of the child's name
- is saved in *CHILD_NAME. This copy must be deallocated
- with xfree after use.
+ is saved in *CHILD_NAME.
- If CHILD_VALUE is not NULL, then save the child's value
in *CHILD_VALUE. Same thing for the child's type with
CHILD_TYPE if not NULL.
- If CHILD_PATH_EXPR is not NULL, then compute the child's
- path expression. The resulting string must be deallocated
- after use with xfree.
+ path expression.
Computing the child's path expression requires the PARENT_PATH_EXPR
to be non-NULL. Otherwise, PARENT_PATH_EXPR may be null if
@@ -805,9 +803,7 @@ ada_varobj_get_type_of_child (struct value *parent_value,
}
/* Return a string that contains the image of the given VALUE, using
- the print options OPTS as the options for formatting the result.
-
- The resulting string must be deallocated after use with xfree. */
+ the print options OPTS as the options for formatting the result. */
static std::string
ada_varobj_get_value_image (struct value *value,
@@ -825,9 +821,7 @@ ada_varobj_get_value_image (struct value *value,
in the array inside square brackets, but there are situations where
it's useful to add more info.
- OPTS are the print options used when formatting the result.
-
- The result should be deallocated after use using xfree. */
+ OPTS are the print options used when formatting the result. */
static std::string
ada_varobj_get_value_of_array_variable (struct value *value,
diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 494e744..e5a2ab9 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -33,7 +33,9 @@
#include "amd64-linux-tdep.h"
#include "i386-linux-tdep.h"
#include "linux-tdep.h"
+#include "svr4-tls-tdep.h"
#include "gdbsupport/x86-xstate.h"
+#include "inferior.h"
#include "amd64-tdep.h"
#include "solib-svr4.h"
@@ -1832,6 +1834,39 @@ amd64_linux_remove_non_address_bits_watchpoint (gdbarch *gdbarch,
return (addr & amd64_linux_lam_untag_mask ());
}
+/* Fetch and return the TLS DTV (dynamic thread vector) address for PTID.
+ Throw a suitable TLS error if something goes wrong. */
+
+static CORE_ADDR
+amd64_linux_get_tls_dtv_addr (struct gdbarch *gdbarch, ptid_t ptid,
+ enum svr4_tls_libc libc)
+{
+ /* On x86-64, the thread pointer is found in the fsbase register. */
+ regcache *regcache
+ = get_thread_arch_regcache (current_inferior (), ptid, gdbarch);
+ target_fetch_registers (regcache, AMD64_FSBASE_REGNUM);
+ ULONGEST fsbase;
+ if (regcache->cooked_read (AMD64_FSBASE_REGNUM, &fsbase) != REG_VALID)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to fetch thread pointer"));
+
+ /* The thread pointer (fsbase) points at the TCB (thread control
+ block). The first two members of this struct are both pointers,
+ where the first will be a pointer to the TCB (i.e. it points at
+ itself) and the second will be a pointer to the DTV (dynamic
+ thread vector). There are many other fields too, but the one
+ we care about here is the DTV pointer. Compute the address
+ of the DTV pointer, fetch it, and convert it to an address. */
+ CORE_ADDR dtv_ptr_addr = fsbase + gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
+ gdb::byte_vector buf (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
+ if (target_read_memory (dtv_ptr_addr, buf.data (), buf.size ()) != 0)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to fetch DTV address"));
+
+ const struct builtin_type *builtin = builtin_type (gdbarch);
+ CORE_ADDR dtv_addr = gdbarch_pointer_to_address
+ (gdbarch, builtin->builtin_data_ptr, buf.data ());
+ return dtv_addr;
+}
+
static void
amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
int num_disp_step_buffers)
@@ -1862,6 +1897,9 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch,
/* Enable TLS support. */
set_gdbarch_fetch_tls_load_module_address (gdbarch,
svr4_fetch_objfile_link_map);
+ set_gdbarch_get_thread_local_address (gdbarch,
+ svr4_tls_get_thread_local_address);
+ svr4_tls_register_tls_methods (info, gdbarch, amd64_linux_get_tls_dtv_addr);
/* GNU/Linux uses SVR4-style shared libraries. */
set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 7e13ef8..9a5021f 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -833,7 +833,7 @@ echo_command (const char *text, int from_tty)
gdb_printf ("%c", c);
}
- gdb_stdout->reset_style ();
+ gdb_stdout->emit_style_escape (ui_file_style ());
/* Force this output to appear now. */
gdb_flush (gdb_stdout);
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index 217afbc..9be446f 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -62,6 +62,8 @@ struct cmd_list_element
type (not_set_cmd),
doc (doc_)
{
+ gdb_assert (name != nullptr);
+ gdb_assert (doc != nullptr);
memset (&function, 0, sizeof (function));
}
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 0ecc7b0..3055734 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -397,7 +397,7 @@ restore_one_section (bfd *ibfd, asection *isec,
if (sec_end <= load_start
|| (load_end > 0 && sec_start >= load_end))
{
- /* No, no useable data in this section. */
+ /* No, no usable data in this section. */
gdb_printf (_("skipping section %s...\n"),
bfd_section_name (isec));
return;
diff --git a/gdb/config/djgpp/README b/gdb/config/djgpp/README
index 2ae6535..cecc9d0 100644
--- a/gdb/config/djgpp/README
+++ b/gdb/config/djgpp/README
@@ -175,7 +175,7 @@ SOMETHING.tst (where SOMETHING is the name of the failed test). You
should compare each of the *.tst files with the corresponding *.out
file and convince yourself that the differences do not indicate a real
problem. Examples of differences you can disregard are changes in the
-copyright blurb printed by GDB, values of unitialized variables,
+copyright blurb printed by GDB, values of uninitialized variables,
addresses of global variables like argv[] and envp[] (which depend on
the size of your environment), etc.
diff --git a/gdb/config/djgpp/djconfig.sh b/gdb/config/djgpp/djconfig.sh
index 4952a11..05b3bbe 100644
--- a/gdb/config/djgpp/djconfig.sh
+++ b/gdb/config/djgpp/djconfig.sh
@@ -123,7 +123,7 @@ do
done
# Now set the config shell. It is really needed, that the shell
-# points to a shell with full path and also it must conatain the
+# points to a shell with full path and also it must contain the
# .exe suffix. I assume here, that bash is installed. If not,
# install it. Additionally, the pathname must not contain a
# drive letter, so use the /dev/x/foo format supported by versions
diff --git a/gdb/configure b/gdb/configure
index e8a649f..c029c30 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -28991,7 +28991,7 @@ else
fi
-if test "${enable_gdb_compile}" == yes; then
+if test "${enable_gdb_compile}" = yes; then
$as_echo "#define HAVE_COMPILE 1" >>confdefs.h
diff --git a/gdb/configure.ac b/gdb/configure.ac
index e0cc3c8..7ba799b 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1231,7 +1231,7 @@ AC_ARG_ENABLE([gdb-compile],
[GDB_CHECK_YES_NO_VAL([$enableval], [--enable-gdb-compile])],
[enable_gdb_compile=yes])
-if test "${enable_gdb_compile}" == yes; then
+if test "${enable_gdb_compile}" = yes; then
AC_DEFINE(HAVE_COMPILE, 1, [Define if compiling support to gdb compile.])
CONFIG_OBS="$CONFIG_OBS \$(SUBDIR_GCC_COMPILE_OBS)"
else
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index 18a15c0..72cdcee 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -150,7 +150,7 @@ aarch64*-*-linux*)
arch/aarch64-scalable-linux.o \
arch/arm.o arch/arm-linux.o arch/arm-get-next-pcs.o \
arm-tdep.o arm-linux-tdep.o \
- glibc-tdep.o linux-tdep.o solib-svr4.o \
+ glibc-tdep.o linux-tdep.o solib-svr4.o svr4-tls-tdep.o \
symfile-mem.o linux-record.o"
;;
@@ -503,7 +503,7 @@ powerpc-*-aix* | rs6000-*-* | powerpc64-*-aix*)
powerpc*-*-linux*)
# Target: PowerPC running Linux
gdb_target_obs="rs6000-tdep.o ppc-linux-tdep.o ppc-sysv-tdep.o \
- ppc64-tdep.o solib-svr4.o \
+ ppc64-tdep.o solib-svr4.o svr4-tls-tdep.o \
glibc-tdep.o symfile-mem.o linux-tdep.o \
ravenscar-thread.o ppc-ravenscar-thread.o \
linux-record.o \
@@ -524,7 +524,8 @@ powerpc*-*-*)
s390*-*-linux*)
# Target: S390 running Linux
gdb_target_obs="s390-linux-tdep.o s390-tdep.o solib-svr4.o \
- linux-tdep.o linux-record.o symfile-mem.o"
+ linux-tdep.o linux-record.o symfile-mem.o \
+ svr4-tls-tdep.o"
;;
riscv*-*-freebsd*)
@@ -534,8 +535,9 @@ riscv*-*-freebsd*)
riscv*-*-linux*)
# Target: Linux/RISC-V
- gdb_target_obs="riscv-linux-tdep.o glibc-tdep.o \
- linux-tdep.o solib-svr4.o symfile-mem.o linux-record.o"
+ gdb_target_obs="riscv-linux-tdep.o riscv-canonicalize-syscall-gen.o \
+ glibc-tdep.o linux-tdep.o solib-svr4.o symfile-mem.o \
+ linux-record.o svr4-tls-tdep.o"
;;
riscv*-*-*)
@@ -705,7 +707,7 @@ x86_64-*-elf*)
x86_64-*-linux*)
# Target: GNU/Linux x86-64
gdb_target_obs="amd64-linux-tdep.o ${i386_tobjs} \
- i386-linux-tdep.o glibc-tdep.o \
+ i386-linux-tdep.o glibc-tdep.o svr4-tls-tdep.o \
solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o \
arch/i386-linux-tdesc.o arch/amd64-linux-tdesc.o \
arch/x86-linux-tdesc-features.o"
diff --git a/gdb/contrib/cc-with-tweaks.sh b/gdb/contrib/cc-with-tweaks.sh
index de56018..930ba5c 100755
--- a/gdb/contrib/cc-with-tweaks.sh
+++ b/gdb/contrib/cc-with-tweaks.sh
@@ -42,6 +42,7 @@
# -Z invoke objcopy --compress-debug-sections
# -z compress using dwz
# -m compress using dwz -m
+# -5 compress using dwz -m -5
# -i make an index (.gdb_index)
# -c make an index (currently .gdb_index) in a cache dir
# -n make a dwarf5 index (.debug_names)
@@ -88,6 +89,7 @@ want_index=false
index_options=""
want_index_cache=false
want_dwz=false
+dwz_5flag=
want_multi=false
want_dwp=false
want_objcopy_compress=false
@@ -101,6 +103,7 @@ while [ $# -gt 0 ]; do
-n) want_index=true; index_options=-dwarf-5;;
-c) want_index_cache=true ;;
-m) want_multi=true ;;
+ -5) want_multi=true; dwz_5flag=-5 ;;
-p) want_dwp=true ;;
-l) want_gnu_debuglink=true ;;
*) break ;;
@@ -269,7 +272,7 @@ elif [ "$want_multi" = true ]; then
rm -f "$dwz_file"
cp "$output_file" "${output_file}.alt"
- $DWZ -m "$dwz_file" "$output_file" "${output_file}.alt" > /dev/null
+ $DWZ $dwz_5flag -m "$dwz_file" "$output_file" "${output_file}.alt" > /dev/null
rm -f "${output_file}.alt"
# Validate dwz's work by checking if the expected output file exists.
diff --git a/gdb/copyright.py b/gdb/copyright.py
index 5ec9944..bd854dc 100755
--- a/gdb/copyright.py
+++ b/gdb/copyright.py
@@ -30,13 +30,16 @@
#
# This removes the bulk of the changes which are most likely to be correct.
+# pyright: strict
+
import argparse
import locale
import os
import os.path
+import pathlib
import subprocess
import sys
-from typing import List, Optional
+from typing import Iterable
def get_update_list():
@@ -66,24 +69,20 @@ def get_update_list():
.split("\0")
)
- def include_file(filename):
- (dirname, basename) = os.path.split(filename)
- dirbasename = os.path.basename(dirname)
- return not (
- basename in EXCLUDE_ALL_LIST
- or dirbasename in EXCLUDE_ALL_LIST
- or dirname in EXCLUDE_LIST
- or dirname in NOT_FSF_LIST
- or dirname in BY_HAND
- or filename in EXCLUDE_LIST
- or filename in NOT_FSF_LIST
- or filename in BY_HAND
- )
+ full_exclude_list = EXCLUDE_LIST + BY_HAND
+
+ def include_file(filename: str):
+ path = pathlib.Path(filename)
+ for pattern in full_exclude_list:
+ if path.full_match(pattern):
+ return False
+
+ return True
return filter(include_file, result)
-def update_files(update_list):
+def update_files(update_list: Iterable[str]):
"""Update the copyright header of the files in the given list.
We use gnulib's update-copyright script for that.
@@ -128,7 +127,7 @@ def update_files(update_list):
print("*** " + line)
-def may_have_copyright_notice(filename):
+def may_have_copyright_notice(filename: str):
"""Check that the given file does not seem to have a copyright notice.
The filename is relative to the root directory.
@@ -166,7 +165,7 @@ def get_parser() -> argparse.ArgumentParser:
return parser
-def main(argv: List[str]) -> Optional[int]:
+def main(argv: list[str]) -> int | None:
"""The main subprogram."""
parser = get_parser()
_ = parser.parse_args(argv)
@@ -210,8 +209,14 @@ def main(argv: List[str]) -> Optional[int]:
# generated, non-FSF, or otherwise special (e.g. license text,
# or test cases which must be sensitive to line numbering).
#
-# Filenames are relative to the root directory.
+# Entries are treated as glob patterns.
EXCLUDE_LIST = (
+ "**/aclocal.m4",
+ "**/configure",
+ "**/COPYING.LIB",
+ "**/COPYING",
+ "**/fdl.texi",
+ "**/gpl.texi",
"gdb/copying.c",
"gdb/nat/glibc_thread_db.h",
"gdb/CONTRIBUTE",
@@ -219,45 +224,11 @@ EXCLUDE_LIST = (
"gdbsupport/unordered_dense.h",
"gnulib/doc/gendocs_template",
"gnulib/doc/gendocs_template_min",
- "gnulib/import",
+ "gnulib/import/**",
"gnulib/config.in",
"gnulib/Makefile.in",
-)
-
-# Files which should not be modified, either because they are
-# generated, non-FSF, or otherwise special (e.g. license text,
-# or test cases which must be sensitive to line numbering).
-#
-# Matches any file or directory name anywhere. Use with caution.
-# This is mostly for files that can be found in multiple directories.
-# Eg: We want all files named COPYING to be left untouched.
-
-EXCLUDE_ALL_LIST = (
- "COPYING",
- "COPYING.LIB",
- "configure",
- "fdl.texi",
- "gpl.texi",
- "aclocal.m4",
-)
-
-# The list of files to update by hand.
-BY_HAND = (
- # Nothing at the moment :-).
-)
-
-# Files containing multiple copyright headers. This script is only
-# fixing the first one it finds, so we need to finish the update
-# by hand.
-MULTIPLE_COPYRIGHT_HEADERS = (
- "gdb/doc/gdb.texinfo",
- "gdb/doc/refcard.tex",
- "gdb/syscalls/update-netbsd.sh",
-)
-
-# The list of file which have a copyright, but not held by the FSF.
-# Filenames are relative to the root directory.
-NOT_FSF_LIST = (
+ "sim/Makefile.in",
+ # The files below have a copyright, but not held by the FSF.
"gdb/exc_request.defs",
"gdb/gdbtk",
"gdb/testsuite/gdb.gdbtk/",
@@ -294,9 +265,27 @@ NOT_FSF_LIST = (
"sim/mips/sim-main.c",
"sim/moxie/moxie-gdb.dts",
# Not a single file in sim/ppc/ appears to be copyright FSF :-(.
- "sim/ppc",
+ "sim/ppc/**",
"sim/testsuite/mips/mips32-dsp2.s",
)
+# The list of files to update by hand.
+#
+# Entries are treated as glob patterns.
+BY_HAND: tuple[str, ...] = (
+ # Nothing at the moment :-).
+)
+
+# Files containing multiple copyright headers. This script is only
+# fixing the first one it finds, so we need to finish the update
+# by hand.
+#
+# Entries are treated as glob patterns.
+MULTIPLE_COPYRIGHT_HEADERS = (
+ "gdb/doc/gdb.texinfo",
+ "gdb/doc/refcard.tex",
+ "gdb/syscalls/update-netbsd.sh",
+)
+
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
diff --git a/gdb/corelow.c b/gdb/corelow.c
index fc0df25..4518781 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -540,11 +540,41 @@ core_target::build_file_mappings ()
/* If ABFD was opened, but the wrong format, close it now. */
abfd = nullptr;
+ /* When true, this indicates that the mapped contents of this
+ file are available within the core file. When false, some of
+ the mapped contents are not available. If the contents are
+ entirely available within the core file, then we don't need to
+ warn the user if GDB cannot find the file. */
+ bool content_is_in_core_file_p = true;
+
/* Record all regions for this file as unavailable. */
for (const mapped_file::region &region : file_data.regions)
- m_core_unavailable_mappings.emplace_back (region.start,
- region.end
- - region.start);
+ {
+ /* Check to see if the region is available within the core
+ file. */
+ bool found_region_in_core_file = false;
+ for (const target_section &ts : m_core_section_table)
+ {
+ if (ts.addr <= region.start && ts.endaddr >= region.end
+ && (ts.the_bfd_section->flags & SEC_HAS_CONTENTS) != 0)
+ {
+ found_region_in_core_file = true;
+ break;
+ }
+ }
+
+ /* This region is not available within the core file.
+ Without the file available to read from it is not possible
+ for GDB to read this mapping within the inferior. Warn
+ the user about this case. */
+ if (!found_region_in_core_file)
+ content_is_in_core_file_p = false;
+
+ /* Record the unavailable region. */
+ m_core_unavailable_mappings.emplace_back (region.start,
+ region.end
+ - region.start);
+ }
/* And give the user an appropriate warning. */
if (build_id_mismatch)
@@ -564,7 +594,7 @@ core_target::build_file_mappings ()
styled_string (file_name_style.style (),
expanded_fname.get ()));
}
- else
+ else if (!content_is_in_core_file_p)
{
if (expanded_fname == nullptr
|| filename == expanded_fname.get ())
diff --git a/gdb/disasm-selftests.c b/gdb/disasm-selftests.c
index ffd25bd..3ccc174 100644
--- a/gdb/disasm-selftests.c
+++ b/gdb/disasm-selftests.c
@@ -21,6 +21,7 @@
#include "gdbsupport/selftest.h"
#include "selftest-arch.h"
#include "gdbarch.h"
+#include "disasm-selftests.h"
namespace selftests {
@@ -329,6 +330,92 @@ memory_error_test (struct gdbarch *gdbarch)
SELF_CHECK (saw_memory_error);
}
+/* Disassemble INSN (a GDBARCH insn), and return the result. */
+
+static std::string
+disassemble_one_insn_to_string (struct gdbarch *gdbarch,
+ gdb::array_view<const gdb_byte> insn)
+{
+ string_file buffer;
+
+ class gdb_disassembler_test : public gdb_disassembler
+ {
+ public:
+
+ explicit gdb_disassembler_test (struct gdbarch *gdbarch,
+ gdb::array_view<const gdb_byte> insn,
+ string_file &buffer)
+ : gdb_disassembler (gdbarch,
+ &buffer,
+ gdb_disassembler_test::read_memory),
+ m_insn (insn)
+ {
+ }
+
+ int
+ print_insn (CORE_ADDR memaddr)
+ {
+ try
+ {
+ return gdb_disassembler::print_insn (memaddr);
+ }
+ catch (const gdb_exception_error &)
+ {
+ return -1;
+ }
+ }
+
+ private:
+ gdb::array_view<const gdb_byte> m_insn;
+
+ static int read_memory (bfd_vma memaddr, gdb_byte *myaddr,
+ unsigned int len,
+ struct disassemble_info *info) noexcept
+ {
+ gdb_disassembler_test *self
+ = static_cast<gdb_disassembler_test *>(info->application_data);
+
+ if (len > self->m_insn.size ())
+ return -1;
+
+ for (size_t i = 0; i < len; i++)
+ myaddr[i] = self->m_insn[i];
+
+ return 0;
+ }
+ };
+
+ gdb_disassembler_test di (gdbarch, insn, buffer);
+ if (di.print_insn (0) != insn.size ())
+ return "";
+
+ return buffer.string ();
+}
+
+/* See disasm-selftests.h. */
+
+void
+disassemble_insn (gdbarch *gdbarch, gdb::byte_vector &insn,
+ const std::string &expected)
+{
+ std::string buffer
+ = disassemble_one_insn_to_string (gdbarch, insn);
+
+ bool check_ok = buffer == expected;
+
+ if (run_verbose () || !check_ok)
+ {
+ for (gdb_byte b : insn)
+ debug_printf ("0x%02x ", b);
+ debug_printf ("-> %s\n", buffer.c_str ());
+ }
+
+ if (!check_ok)
+ debug_printf ("expected: %s\n", expected.c_str ());
+
+ SELF_CHECK (check_ok);
+}
+
} /* namespace selftests */
void _initialize_disasm_selftests ();
diff --git a/gdb/disasm-selftests.h b/gdb/disasm-selftests.h
new file mode 100644
index 0000000..29acf87
--- /dev/null
+++ b/gdb/disasm-selftests.h
@@ -0,0 +1,32 @@
+/* Copyright (C) 2025 Free Software Foundation, Inc.
+
+ 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_DISASM_SELFTESTS_H
+#define GDB_DISASM_SELFTESTS_H
+
+namespace selftests
+{
+
+/* Check that disassembly of INSN (a GDBARCH insn) matches EXPECTED. */
+
+void
+disassemble_insn (gdbarch *gdbarch, gdb::byte_vector &insn,
+ const std::string &expected);
+
+}
+
+#endif /* GDB_DISASM_SELFTESTS_H */
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index b251c8e..362e6e7 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -4090,6 +4090,56 @@ When @samp{on} @value{GDBN} will print additional messages when
threads are created and deleted.
@end table
+@cindex thread local storage
+@cindex @acronym{TLS}
+For some debugging targets, @value{GDBN} has support for accessing
+variables that reside in Thread Local Storage (@acronym{TLS}).
+@acronym{TLS} variables are similar to global variables, except that
+each thread has its own copy of the variable. While often used in
+multi-threaded programs, @acronym{TLS} variables can also be used in
+programs without threads. The C library variable @var{errno} is,
+perhaps, the most prominent example of a @acronym{TLS} variable that
+is frequently used in non-threaded programs. For targets where
+@value{GDBN} does not have good @acronym{TLS} support, printing or
+changing the value of @var{errno} might not be directly possible.
+
+@sc{gnu}/Linux and FreeBSD targets have support for accessing
+@acronym{TLS} variables. On @sc{gnu}/Linux, the helper library,
+@code{libthread_db}, is used to help resolve the addresses of
+@acronym{TLS} variables. Some FreeBSD and some @sc{gnu}/Linux targets
+also have @value{GDBN}-internal @acronym{TLS} resolution code.
+@sc{gnu}/Linux targets will attempt to use the @acronym{TLS} address
+lookup functionality provided by @code{libthread_db}, but will fall
+back to using its internal @acronym{TLS} support when
+@code{libthread_db} is not available. This can happen in
+cross-debugging scenarios or when debugging programs that are linked
+in such a way that @code{libthread_db} support is unavailable -- this
+includes statically linked programs, linking against @acronym{GLIBC}
+versions earlier than 2.34, but not with @code{libpthread}, and use of
+other (non-@acronym{GLIBC}) C libraries.
+
+@table @code
+@kindex maint set force-internal-tls-address-lookup
+@kindex maint show force-internal-tls-address-lookup
+@cindex internal @acronym{TLS} address lookup
+@item maint set force-internal-tls-address-lookup
+@itemx maint show force-internal-tls-address-lookup
+Turns on or off forced use of @value{GDBN}-internal @acronym{TLS}
+address lookup code. Use @code{on} to enable and @code{off} to
+disable. The default for this setting is @code{off}.
+
+When disabled, @value{GDBN} will attempt to use a helper
+@code{libthread_db} library if possible, but will fall back to use of
+its own internal @acronym{TLS} address lookup mechanisms if necessary.
+
+When enabled, @value{GDBN} will only use @value{GDBN}'s internal
+@acronym{TLS} address lookup mechanisms, if they exist.
+
+This command is only available for @sc{gnu}/Linux targets. Its
+primary use is for testing -- certain tests in the @value{GDBN} test
+suite use this command to force use of internal TLS address lookup.
+@end table
+
@node Forks
@section Debugging Forks
@@ -7807,9 +7857,9 @@ previous instruction; otherwise, it will work in record mode, if the
platform supports reverse execution, or stop if not.
Currently, process record and replay is supported on ARM, Aarch64,
-LoongArch, Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
-GNU/Linux. Process record and replay can be used both when native
-debugging, and when remote debugging via @code{gdbserver}.
+LoongArch, Moxie, PowerPC, PowerPC64, S/390, RISC-V and x86 (i386/amd64)
+running GNU/Linux. Process record and replay can be used both when
+native debugging, and when remote debugging via @code{gdbserver}.
When recording an inferior, @value{GDBN} may print auxiliary information
during stepping commands and commands displaying the execution history.
@@ -13046,6 +13096,18 @@ variable which may be @samp{truecolor} or @samp{24bit}. Other color spaces are
determined by the "Co" termcap which in turn depends on the @env{TERM}
environment variable.
+@vindex $_active_linker_namespaces@r{, convenience variable}
+@item $_active_linker_namespaces
+Number of active linkage namespaces in the inferior. In systems with no
+support for linkage namespaces, this variable will always be set to @samp{1}.
+
+@vindex $_current_linker_namespace@r{, convenience variable}
+@item $_current_linker_namespace
+The namespace which contains the current location in the inferior. This
+returns GDB's internal identifier for namespaces, which is @samp{[[@var{n}]]}
+where @var{n} is a zero-based namespace number. In systems with no support
+for linkage namespaces, this variable will always be set to @samp{[[0]]}.
+
@end table
@node Convenience Funs
@@ -22212,6 +22274,22 @@ less useful than setting a catchpoint, because it does not allow for
conditions or commands as a catchpoint does.
@table @code
+@kindex info linker-namespaces
+@item info linker-namespaces
+@item info linker-namespaces @code{[[@var{n}]]}
+
+With no argument, print the number of linker namespaces which are
+currently active --- that is, namespaces that have libraries loaded
+into them. Then, it prints the number of libraries loaded into each
+namespace, and all the libraries loaded into them, in the same way
+as @code{info sharedlibrary}.
+
+If an argument @code{[[@var{n}]]} is provided, only prints the
+library count and the libraried for the provided namespace @var{n}.
+The surrounding square brackets are optional.
+@end table
+
+@table @code
@item set stop-on-solib-events
@kindex set stop-on-solib-events
This command controls whether @value{GDBN} should give you control
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 50342bb..afbd62f 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -257,7 +257,7 @@ Python code must not override these, or even change the options using
signals, @value{GDBN} will most likely stop working correctly. Note
that it is unfortunately common for GUI toolkits to install a
@code{SIGCHLD} handler. When creating a new Python thread, you can
-use @code{gdb.block_signals} or @code{gdb.Thread} to handle this
+use @code{gdb.blocked_signals} or @code{gdb.Thread} to handle this
correctly; see @ref{Threading in GDB}.
@item
@@ -654,22 +654,22 @@ threads, you must be careful to only call @value{GDBN}-specific
functions in the @value{GDBN} thread. @value{GDBN} provides some
functions to help with this.
-@defun gdb.block_signals ()
+@defun gdb.blocked_signals ()
As mentioned earlier (@pxref{Basic Python}), certain signals must be
-delivered to the @value{GDBN} main thread. The @code{block_signals}
+delivered to the @value{GDBN} main thread. The @code{blocked_signals}
function returns a context manager that will block these signals on
entry. This can be used when starting a new thread to ensure that the
signals are blocked there, like:
@smallexample
-with gdb.block_signals():
+with gdb.blocked_signals():
start_new_thread()
@end smallexample
@end defun
@deftp {class} gdb.Thread
This is a subclass of Python's @code{threading.Thread} class. It
-overrides the @code{start} method to call @code{block_signals}, making
+overrides the @code{start} method to call @code{blocked_signals}, making
this an easy-to-use drop-in replacement for creating threads that will
work well in @value{GDBN}.
@end deftp
@@ -4554,8 +4554,8 @@ registered.
The help text for the new command is taken from the Python
documentation string for the command's class, if there is one. If no
-documentation string is provided, the default value ``This command is
-not documented.'' is used.
+documentation string is provided, the default value @samp{This command
+is not documented.} is used.
@end defun
@cindex don't repeat Python command
@@ -7049,13 +7049,13 @@ writable.
@cindex colors in python
@tindex gdb.Color
-You can assign instance of @code{Color} to the @code{value} of
+You can assign instance of @code{gdb.Color} to the @code{value} of
a @code{Parameter} instance created with @code{PARAM_COLOR}.
-@code{Color} may refer to an index from color palette or contain components
-of a color from some colorspace.
+@code{gdb.Color} may refer to an index from a color palette or contain
+components of a color from some color space.
-@defun Color.__init__ (@r{[}@var{value} @r{[}, @var{color-space}@r{]}@r{]})
+@defun Color.__init__ (@r{[}value @r{[}, color_space@r{]}@r{]})
@var{value} is @code{None} (meaning the terminal's default color),
an integer index of a color in palette, tuple with color components
@@ -7065,8 +7065,9 @@ or one of the following color names:
@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
or @samp{white}.
-@var{color-space} should be one of the @samp{COLORSPACE_} constants. This
-argument tells @value{GDBN} which color space @var{value} belongs.
+@var{color_space} should be one of the @samp{COLORSPACE_} constants
+listed below. This argument tells @value{GDBN} which color space
+@var{value} belongs.
@end defun
@defvar Color.is_none
@@ -7094,7 +7095,7 @@ This attribute exist if @code{is_direct} is @code{True}. Its value is tuple
with integer components of a color.
@end defvar
-@defun Color.escape_sequence (@var{self}, @var{is_foreground})
+@defun Color.escape_sequence (is_foreground)
Returns string to change terminal's color to this.
If @var{is_foreground} is @code{True}, then the returned sequence will change
@@ -7136,6 +7137,8 @@ Direct 24-bit RGB colors.
@end table
+It is not possible to sub-class the @code{Color} class.
+
@node Architectures In Python
@subsubsection Python representation of architectures
@cindex Python architectures
diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 1278f97..8ff0353 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -73,7 +73,8 @@ attribute::form_is_string () const
|| form == DW_FORM_strx3
|| form == DW_FORM_strx4
|| form == DW_FORM_GNU_str_index
- || form == DW_FORM_GNU_strp_alt);
+ || form == DW_FORM_GNU_strp_alt
+ || form == DW_FORM_strp_sup);
}
/* See attribute.h. */
@@ -185,11 +186,43 @@ attribute::unsigned_constant () const
/* See attribute.h. */
+std::optional<LONGEST>
+attribute::signed_constant () const
+{
+ if (form_is_strictly_signed ())
+ return u.snd;
+
+ switch (form)
+ {
+ case DW_FORM_data8:
+ case DW_FORM_udata:
+ /* Not sure if DW_FORM_udata should be handled or not. Anyway
+ for DW_FORM_data8, there's no need to sign-extend. */
+ return u.snd;
+
+ case DW_FORM_data1:
+ return sign_extend (u.unsnd, 8);
+ case DW_FORM_data2:
+ return sign_extend (u.unsnd, 16);
+ case DW_FORM_data4:
+ return sign_extend (u.unsnd, 32);
+ }
+
+ /* For DW_FORM_data16 see attribute::form_is_constant. */
+ complaint (_("Attribute value is not a constant (%s)"),
+ dwarf_form_name (form));
+ return {};
+}
+
+/* See attribute.h. */
+
bool
attribute::form_is_unsigned () const
{
return (form == DW_FORM_ref_addr
|| form == DW_FORM_GNU_ref_alt
+ || form == DW_FORM_ref_sup4
+ || form == DW_FORM_ref_sup8
|| form == DW_FORM_data2
|| form == DW_FORM_data4
|| form == DW_FORM_data8
@@ -293,5 +326,8 @@ attribute::as_boolean () const
return true;
else if (form == DW_FORM_flag)
return u.unsnd != 0;
- return constant_value (0) != 0;
+ /* Using signed_constant here will work even for the weird case
+ where a negative value is provided. Probably doesn't matter but
+ also seems harmless. */
+ return signed_constant ().value_or (0) != 0;
}
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index 70edff3..31ff018 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -114,6 +114,15 @@ struct attribute
returned. */
std::optional<ULONGEST> unsigned_constant () const;
+ /* Return a signed constant value. This only handles constant forms
+ (i.e., form_is_constant -- and not the extended list of
+ "unsigned" forms) and assumes a signed value is desired. This
+ function will sign-extend DW_FORM_data* values.
+
+ If non-constant form is used, then complaint is issued and an
+ empty value is returned. */
+ std::optional<LONGEST> signed_constant () const;
+
/* Return non-zero if ATTR's value falls in the 'constant' class, or
zero otherwise. When this function returns true, you can apply
the constant_value method to it.
@@ -144,7 +153,9 @@ struct attribute
|| form == DW_FORM_ref4
|| form == DW_FORM_ref8
|| form == DW_FORM_ref_udata
- || form == DW_FORM_GNU_ref_alt);
+ || form == DW_FORM_GNU_ref_alt
+ || form == DW_FORM_ref_sup4
+ || form == DW_FORM_ref_sup8);
}
/* Check if the attribute's form is a DW_FORM_block*
@@ -164,10 +175,29 @@ struct attribute
false. */
bool form_is_strictly_signed () const;
+ /* Check if the attribute's form is an unsigned constant form. This
+ only returns true for forms that are strictly unsigned -- that
+ is, for a context-dependent form like DW_FORM_data1, this returns
+ false. */
+ bool form_is_strictly_unsigned () const
+ {
+ return form == DW_FORM_udata;
+ }
+
/* Check if the attribute's form is a form that requires
"reprocessing". */
bool form_requires_reprocessing () const;
+ /* Check if attribute's form refers to the separate "dwz" file.
+ This is only useful for references to the .debug_info section,
+ not to the supplementary .debug_str section. */
+ bool form_is_alt () const
+ {
+ return (form == DW_FORM_GNU_ref_alt
+ || form == DW_FORM_ref_sup4
+ || form == DW_FORM_ref_sup8);
+ }
+
/* Return DIE offset of this attribute. Return 0 with complaint if
the attribute is not of the required kind. */
diff --git a/gdb/dwarf2/comp-unit-head.c b/gdb/dwarf2/comp-unit-head.c
index 8ec8897..a35d664 100644
--- a/gdb/dwarf2/comp-unit-head.c
+++ b/gdb/dwarf2/comp-unit-head.c
@@ -26,7 +26,6 @@
#include "dwarf2/comp-unit-head.h"
#include "dwarf2/leb.h"
-#include "dwarf2/read.h"
#include "dwarf2/section.h"
#include "dwarf2/stringify.h"
#include "dwarf2/error.h"
@@ -149,15 +148,13 @@ read_comp_unit_head (struct comp_unit_head *cu_header,
Perform various error checking on the header. */
static void
-error_check_comp_unit_head (dwarf2_per_objfile *per_objfile,
- struct comp_unit_head *header,
- struct dwarf2_section_info *section,
- struct dwarf2_section_info *abbrev_section)
+error_check_comp_unit_head (comp_unit_head *header,
+ dwarf2_section_info *section,
+ dwarf2_section_info *abbrev_section)
{
const char *filename = section->get_file_name ();
- if (to_underlying (header->abbrev_sect_off)
- >= abbrev_section->get_size (per_objfile->objfile))
+ if (to_underlying (header->abbrev_sect_off) >= abbrev_section->size)
error (_(DWARF_ERROR_PREFIX
"bad offset (%s) in compilation unit header "
"(offset %s + 6) [in module %s]"),
@@ -179,12 +176,10 @@ error_check_comp_unit_head (dwarf2_per_objfile *per_objfile,
/* See comp-unit-head.h. */
const gdb_byte *
-read_and_check_comp_unit_head (dwarf2_per_objfile *per_objfile,
- struct comp_unit_head *header,
- struct dwarf2_section_info *section,
- struct dwarf2_section_info *abbrev_section,
- const gdb_byte *info_ptr,
- rcuh_kind section_kind)
+read_and_check_comp_unit_head (comp_unit_head *header,
+ dwarf2_section_info *section,
+ dwarf2_section_info *abbrev_section,
+ const gdb_byte *info_ptr, rcuh_kind section_kind)
{
const gdb_byte *beg_of_comp_unit = info_ptr;
@@ -194,7 +189,7 @@ read_and_check_comp_unit_head (dwarf2_per_objfile *per_objfile,
header->first_die_cu_offset = (cu_offset) (info_ptr - beg_of_comp_unit);
- error_check_comp_unit_head (per_objfile, header, section, abbrev_section);
+ error_check_comp_unit_head (header, section, abbrev_section);
return info_ptr;
}
diff --git a/gdb/dwarf2/comp-unit-head.h b/gdb/dwarf2/comp-unit-head.h
index 5134893..ea09153 100644
--- a/gdb/dwarf2/comp-unit-head.h
+++ b/gdb/dwarf2/comp-unit-head.h
@@ -129,11 +129,8 @@ extern const gdb_byte *read_comp_unit_head
The contents of the header are stored in HEADER.
The result is a pointer to the start of the first DIE. */
extern const gdb_byte *read_and_check_comp_unit_head
- (dwarf2_per_objfile *per_objfile,
- struct comp_unit_head *header,
- struct dwarf2_section_info *section,
- struct dwarf2_section_info *abbrev_section,
- const gdb_byte *info_ptr,
+ (comp_unit_head *header, dwarf2_section_info *section,
+ dwarf2_section_info *abbrev_section, const gdb_byte *info_ptr,
rcuh_kind section_kind);
#endif /* GDB_DWARF2_COMP_UNIT_HEAD_H */
diff --git a/gdb/dwarf2/cooked-indexer.c b/gdb/dwarf2/cooked-indexer.c
index 1f3a235..b8b66cf 100644
--- a/gdb/dwarf2/cooked-indexer.c
+++ b/gdb/dwarf2/cooked-indexer.c
@@ -222,7 +222,7 @@ cooked_indexer::scan_attributes (dwarf2_per_cu *scanning_per_cu,
case DW_AT_abstract_origin:
case DW_AT_extension:
origin_offset = attr.get_ref_die_offset ();
- origin_is_dwz = attr.form == DW_FORM_GNU_ref_alt;
+ origin_is_dwz = attr.form_is_alt ();
break;
case DW_AT_external:
@@ -423,7 +423,7 @@ cooked_indexer::index_imported_unit (cutu_reader *reader,
if (attr.name == DW_AT_import)
{
sect_off = attr.get_ref_die_offset ();
- is_dwz = (attr.form == DW_FORM_GNU_ref_alt
+ is_dwz = (attr.form_is_alt ()
|| reader->cu ()->per_cu->is_dwz);
}
}
diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h
index 5683291..6eda19b 100644
--- a/gdb/dwarf2/cu.h
+++ b/gdb/dwarf2/cu.h
@@ -99,6 +99,15 @@ struct dwarf2_cu
void add_dependence (dwarf2_per_cu *ref_per_cu)
{ m_dependencies.emplace (ref_per_cu); }
+ /* Find the DIE at section offset SECT_OFF.
+
+ Return nullptr if not found. */
+ die_info *find_die (sect_offset sect_off) const
+ {
+ auto it = die_hash.find (sect_off);
+ return it != die_hash.end () ? *it : nullptr;
+ }
+
/* The header of the compilation unit. */
struct comp_unit_head header;
diff --git a/gdb/dwarf2/die.c b/gdb/dwarf2/die.c
index 8c3d2ca..7ed18bf 100644
--- a/gdb/dwarf2/die.c
+++ b/gdb/dwarf2/die.c
@@ -90,6 +90,8 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
gdb_puts (hex_string (die->attrs[i].as_unsigned ()), f);
break;
case DW_FORM_GNU_ref_alt:
+ case DW_FORM_ref_sup4:
+ case DW_FORM_ref_sup8:
gdb_printf (f, "alt ref address: ");
gdb_puts (hex_string (die->attrs[i].as_unsigned ()), f);
break;
@@ -123,6 +125,7 @@ dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
case DW_FORM_strx:
case DW_FORM_GNU_str_index:
case DW_FORM_GNU_strp_alt:
+ case DW_FORM_strp_sup:
gdb_printf (f, "string: \"%s\" (%s canonicalized)",
die->attrs[i].as_string ()
? die->attrs[i].as_string () : "",
diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c
index e5e18a1..583103b 100644
--- a/gdb/dwarf2/dwz.c
+++ b/gdb/dwarf2/dwz.c
@@ -21,6 +21,7 @@
#include "build-id.h"
#include "debuginfod-support.h"
+#include "dwarf2/leb.h"
#include "dwarf2/read.h"
#include "dwarf2/sect-names.h"
#include "filenames.h"
@@ -34,15 +35,17 @@
const char *
dwz_file::read_string (struct objfile *objfile, LONGEST str_offset)
{
- str.read (objfile);
+ /* This must be true because the sections are read in when the
+ dwz_file is created. */
+ gdb_assert (str.readin);
if (str.buffer == NULL)
- error (_("DW_FORM_GNU_strp_alt used without .debug_str "
+ error (_("supplementary DWARF file missing .debug_str "
"section [in module %s]"),
this->filename ());
if (str_offset >= str.size)
- error (_("DW_FORM_GNU_strp_alt pointing outside of "
- ".debug_str section [in module %s]"),
+ error (_("invalid string reference to supplementary DWARF file "
+ "[in module %s]"),
this->filename ());
gdb_assert (HOST_CHAR_BIT == 8);
if (str.buffer[str_offset] == '\0')
@@ -85,6 +88,139 @@ locate_dwz_sections (struct objfile *objfile, bfd *abfd, asection *sectp,
}
}
+/* Helper that throws an exception when reading the .debug_sup
+ section. */
+
+static void
+debug_sup_failure (const char *text, bfd *abfd)
+{
+ error (_("%s [in modules %s]"), text, bfd_get_filename (abfd));
+}
+
+/* Look for the .debug_sup section and read it. If the section does
+ not exist, this returns false. If the section does exist but fails
+ to parse for some reason, an exception is thrown. Otherwise, if
+ everything goes well, this returns true and fills in the out
+ parameters. */
+
+static bool
+get_debug_sup_info (bfd *abfd,
+ std::string *filename,
+ size_t *buildid_len,
+ gdb::unique_xmalloc_ptr<bfd_byte> *buildid)
+{
+ asection *sect = bfd_get_section_by_name (abfd, ".debug_sup");
+ if (sect == nullptr)
+ return false;
+
+ bfd_byte *contents;
+ if (!bfd_malloc_and_get_section (abfd, sect, &contents))
+ debug_sup_failure (_("could not read .debug_sup section"), abfd);
+
+ gdb::unique_xmalloc_ptr<bfd_byte> content_holder (contents);
+ bfd_size_type size = bfd_section_size (sect);
+
+ /* Version of this section. */
+ if (size < 4)
+ debug_sup_failure (_(".debug_sup section too short"), abfd);
+ unsigned int version = read_2_bytes (abfd, contents);
+ contents += 2;
+ size -= 2;
+ if (version != 5)
+ debug_sup_failure (_(".debug_sup has wrong version number"), abfd);
+
+ /* Skip the is_supplementary value. We already ensured there were
+ enough bytes, above. */
+ ++contents;
+ --size;
+
+ /* The spec says that in the supplementary file, this must be \0,
+ but it doesn't seem very important. */
+ const char *fname = (const char *) contents;
+ size_t len = strlen (fname) + 1;
+ if (filename != nullptr)
+ *filename = fname;
+ contents += len;
+ size -= len;
+
+ if (size == 0)
+ debug_sup_failure (_(".debug_sup section missing ID"), abfd);
+
+ unsigned int bytes_read;
+ *buildid_len = read_unsigned_leb128 (abfd, contents, &bytes_read);
+ contents += bytes_read;
+ size -= bytes_read;
+
+ if (size < *buildid_len)
+ debug_sup_failure (_("extra data after .debug_sup section ID"), abfd);
+
+ if (*buildid_len != 0)
+ buildid->reset ((bfd_byte *) xmemdup (contents, *buildid_len,
+ *buildid_len));
+
+ return true;
+}
+
+/* Validate that ABFD matches the given BUILDID. If DWARF5 is true,
+ then this is done by examining the .debug_sup data. */
+
+static bool
+verify_id (bfd *abfd, size_t len, const bfd_byte *buildid, bool dwarf5)
+{
+ if (!bfd_check_format (abfd, bfd_object))
+ return false;
+
+ if (dwarf5)
+ {
+ size_t new_len;
+ gdb::unique_xmalloc_ptr<bfd_byte> new_id;
+
+ if (!get_debug_sup_info (abfd, nullptr, &new_len, &new_id))
+ return false;
+ return (len == new_len
+ && memcmp (buildid, new_id.get (), len) == 0);
+ }
+ else
+ return build_id_verify (abfd, len, buildid);
+}
+
+/* Find either the .debug_sup or .gnu_debugaltlink section and return
+ its contents. Returns true on success and sets out parameters, or
+ false if nothing is found. */
+
+static bool
+read_alt_info (bfd *abfd, std::string *filename,
+ size_t *buildid_len,
+ gdb::unique_xmalloc_ptr<bfd_byte> *buildid,
+ bool *dwarf5)
+{
+ if (get_debug_sup_info (abfd, filename, buildid_len, buildid))
+ {
+ *dwarf5 = true;
+ return true;
+ }
+
+ bfd_size_type buildid_len_arg;
+ bfd_set_error (bfd_error_no_error);
+ bfd_byte *buildid_out;
+ gdb::unique_xmalloc_ptr<char> new_filename
+ (bfd_get_alt_debug_link_info (abfd, &buildid_len_arg,
+ &buildid_out));
+ if (new_filename == nullptr)
+ {
+ if (bfd_get_error () == bfd_error_no_error)
+ return false;
+ error (_("could not read '.gnu_debugaltlink' section: %s"),
+ bfd_errmsg (bfd_get_error ()));
+ }
+ *filename = new_filename.get ();
+
+ *buildid_len = buildid_len_arg;
+ buildid->reset (buildid_out);
+ *dwarf5 = false;
+ return true;
+}
+
/* Attempt to find a .dwz file (whose full path is represented by
FILENAME) in all of the specified debug file directories provided.
@@ -93,7 +229,7 @@ locate_dwz_sections (struct objfile *objfile, bfd *abfd, asection *sectp,
static gdb_bfd_ref_ptr
dwz_search_other_debugdirs (std::string &filename, bfd_byte *buildid,
- size_t buildid_len)
+ size_t buildid_len, bool dwarf5)
{
/* Let's assume that the path represented by FILENAME has the
"/.dwz/" subpath in it. This is what (most) GNU/Linux
@@ -161,7 +297,7 @@ dwz_search_other_debugdirs (std::string &filename, bfd_byte *buildid,
if (dwz_bfd == nullptr)
continue;
- if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid))
+ if (!verify_id (dwz_bfd.get (), buildid_len, buildid, dwarf5))
{
dwz_bfd.reset (nullptr);
continue;
@@ -177,11 +313,8 @@ dwz_search_other_debugdirs (std::string &filename, bfd_byte *buildid,
/* See dwz.h. */
void
-dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)
+dwz_file::read_dwz_file (dwarf2_per_objfile *per_objfile)
{
- bfd_size_type buildid_len_arg;
- size_t buildid_len;
- bfd_byte *buildid;
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
/* This may query the user via the debuginfod support, so it may
@@ -193,24 +326,17 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)
/* Set this early, so that on error it remains NULL. */
per_bfd->dwz_file.emplace (nullptr);
- bfd_set_error (bfd_error_no_error);
- gdb::unique_xmalloc_ptr<char> data
- (bfd_get_alt_debug_link_info (per_bfd->obfd,
- &buildid_len_arg, &buildid));
- if (data == NULL)
+ size_t buildid_len;
+ gdb::unique_xmalloc_ptr<bfd_byte> buildid;
+ std::string filename;
+ bool dwarf5;
+ if (!read_alt_info (per_bfd->obfd, &filename, &buildid_len, &buildid,
+ &dwarf5))
{
- if (bfd_get_error () == bfd_error_no_error)
- return;
- error (_("could not read '.gnu_debugaltlink' section: %s"),
- bfd_errmsg (bfd_get_error ()));
+ /* Nothing found, nothing to do. */
+ return;
}
- gdb::unique_xmalloc_ptr<bfd_byte> buildid_holder (buildid);
-
- buildid_len = (size_t) buildid_len_arg;
-
- std::string filename = data.get ();
-
if (!IS_ABSOLUTE_PATH (filename.c_str ()))
{
gdb::unique_xmalloc_ptr<char> abs = gdb_realpath (per_bfd->filename ());
@@ -223,25 +349,26 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)
gdb_bfd_ref_ptr dwz_bfd (gdb_bfd_open (filename.c_str (), gnutarget));
if (dwz_bfd != NULL)
{
- if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid))
+ if (!verify_id (dwz_bfd.get (), buildid_len, buildid.get (), dwarf5))
dwz_bfd.reset (nullptr);
}
if (dwz_bfd == NULL)
- dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid);
+ dwz_bfd = build_id_to_debug_bfd (buildid_len, buildid.get ());
if (dwz_bfd == nullptr)
{
/* If the user has provided us with different
debug file directories, we can try them in order. */
- dwz_bfd = dwz_search_other_debugdirs (filename, buildid, buildid_len);
+ dwz_bfd = dwz_search_other_debugdirs (filename, buildid.get (),
+ buildid_len, dwarf5);
}
if (dwz_bfd == nullptr)
{
gdb::unique_xmalloc_ptr<char> alt_filename;
scoped_fd fd
- = debuginfod_debuginfo_query (buildid, buildid_len,
+ = debuginfod_debuginfo_query (buildid.get (), buildid_len,
per_bfd->filename (), &alt_filename);
if (fd.get () >= 0)
@@ -252,16 +379,18 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)
if (dwz_bfd == nullptr)
warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
alt_filename.get ());
- else if (!build_id_verify (dwz_bfd.get (), buildid_len, buildid))
+ else if (!verify_id (dwz_bfd.get (), buildid_len, buildid.get (),
+ dwarf5))
dwz_bfd.reset (nullptr);
}
}
if (dwz_bfd == NULL)
- error (_("could not find '.gnu_debugaltlink' file for %s"),
+ error (_("could not find supplementary DWARF file (%s) for %s"),
+ filename.c_str (),
per_bfd->filename ());
- auto result = std::make_unique<dwz_file> (std::move (dwz_bfd));
+ dwz_file_up result (new dwz_file (std::move (dwz_bfd)));
for (asection *sec : gdb_bfd_sections (result->dwz_bfd))
locate_dwz_sections (per_objfile->objfile, result->dwz_bfd.get (),
diff --git a/gdb/dwarf2/dwz.h b/gdb/dwarf2/dwz.h
index 9f69123..372f7e6 100644
--- a/gdb/dwarf2/dwz.h
+++ b/gdb/dwarf2/dwz.h
@@ -31,10 +31,12 @@ struct dwarf2_per_objfile;
struct dwz_file
{
- dwz_file (gdb_bfd_ref_ptr &&bfd)
- : dwz_bfd (std::move (bfd))
- {
- }
+ /* Open the separate '.dwz' debug file, if needed. This will set
+ the appropriate field in the per-BFD structure. If the DWZ file
+ exists, the relevant sections are read in as well. Throws an
+ exception if the .gnu_debugaltlink or .debug_sup section exists
+ but is invalid or if the file cannot be found. */
+ static void read_dwz_file (dwarf2_per_objfile *per_objfile);
const char *filename () const
{
@@ -64,16 +66,15 @@ struct dwz_file
return a pointer to the string. */
const char *read_string (struct objfile *objfile, LONGEST str_offset);
-};
-using dwz_file_up = std::unique_ptr<dwz_file>;
+private:
-/* Open the separate '.dwz' debug file, if needed. This just sets the
- appropriate field in the per-BFD structure. If the DWZ file
- exists, the relevant sections are read in as well. Throws an error
- if the .gnu_debugaltlink section exists but the file cannot be
- found. */
+ explicit dwz_file (gdb_bfd_ref_ptr &&bfd)
+ : dwz_bfd (std::move (bfd))
+ {
+ }
+};
-extern void dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile);
+using dwz_file_up = std::unique_ptr<dwz_file>;
#endif /* GDB_DWARF2_DWZ_H */
diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c
index 9b8f093..1dc3a9e 100644
--- a/gdb/dwarf2/macro.c
+++ b/gdb/dwarf2/macro.c
@@ -259,6 +259,7 @@ skip_form_bytes (bfd *abfd, const gdb_byte *bytes, const gdb_byte *buffer_end,
case DW_FORM_sec_offset:
case DW_FORM_strp:
case DW_FORM_GNU_strp_alt:
+ case DW_FORM_strp_sup:
bytes += offset_size;
break;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 6e96afe..6b7f2c7 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -622,15 +622,21 @@ struct variant_field
/* A variant can contain other variant parts. */
std::vector<variant_part_builder> variant_parts;
- /* If we see a DW_TAG_variant, then this will be set if this is the
- default branch. */
- bool default_branch = false;
/* If we see a DW_AT_discr_value, then this will be the discriminant
- value. */
- ULONGEST discriminant_value = 0;
+ value. Just the attribute is stored here, because we have to
+ defer deciding whether the value is signed or unsigned until the
+ end. */
+ const attribute *discriminant_attr = nullptr;
/* If we see a DW_AT_discr_list, then this is a pointer to the list
data. */
struct dwarf_block *discr_list_data = nullptr;
+
+ /* If both DW_AT_discr_value and DW_AT_discr_list are absent, then
+ this is the default branch. */
+ bool is_default () const
+ {
+ return discriminant_attr == nullptr && discr_list_data == nullptr;
+ }
};
/* This represents a DW_TAG_variant_part. */
@@ -1039,14 +1045,7 @@ static struct dwo_unit *lookup_dwo_unit_in_dwp
(dwarf2_per_bfd *per_bfd, struct dwp_file *dwp_file,
const char *comp_dir, ULONGEST signature, int is_debug_types);
-static struct dwp_file *get_dwp_file (dwarf2_per_objfile *per_objfile);
-
-static struct dwo_unit *lookup_dwo_comp_unit
- (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
- ULONGEST signature);
-
-static struct dwo_unit *lookup_dwo_type_unit
- (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir);
+static void open_and_init_dwp_file (dwarf2_per_objfile *per_objfile);
static void queue_and_load_all_dwo_tus (dwarf2_cu *cu);
@@ -1289,7 +1288,16 @@ dwarf2_has_info (struct objfile *objfile,
BFD, to avoid races. */
try
{
- dwarf2_read_dwz_file (per_objfile);
+ dwz_file::read_dwz_file (per_objfile);
+ }
+ catch (const gdb_exception_error &err)
+ {
+ warning (_("%s"), err.what ());
+ }
+
+ try
+ {
+ open_and_init_dwp_file (per_objfile);
}
catch (const gdb_exception_error &err)
{
@@ -1632,7 +1640,7 @@ dw2_do_instantiate_symtab (dwarf2_per_cu *per_cu,
&& per_objfile->per_bfd->index_table != NULL
&& !per_objfile->per_bfd->index_table->version_check ()
/* DWP files aren't supported yet. */
- && get_dwp_file (per_objfile) == NULL)
+ && per_objfile->per_bfd->dwp_file == nullptr)
queue_and_load_all_dwo_tus (cu);
}
@@ -2383,16 +2391,16 @@ read_abbrev_offset (dwarf2_per_objfile *per_objfile,
return (sect_offset) read_offset (abfd, info_ptr, offset_size);
}
-/* A helper for create_debug_types_hash_table. Read types from SECTION
+/* A helper for create_dwo_debug_types_hash_table. Read types from SECTION
and fill them into DWO_FILE's type unit hash table. It will process only
type units, therefore DW_UT_type. */
-static void
-create_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
- dwo_file *dwo_file, dwarf2_section_info *section,
- rcuh_kind section_kind)
+void
+cutu_reader::create_dwo_debug_type_hash_table (dwarf2_per_bfd *per_bfd,
+ dwo_file *dwo_file,
+ dwarf2_section_info *section,
+ rcuh_kind section_kind)
{
- struct objfile *objfile = per_objfile->objfile;
struct dwarf2_section_info *abbrev_section;
bfd *abfd;
const gdb_byte *info_ptr, *end_ptr;
@@ -2403,7 +2411,6 @@ create_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
section->get_name (),
abbrev_section->get_file_name ());
- section->read (objfile);
info_ptr = section->buffer;
if (info_ptr == NULL)
@@ -2432,8 +2439,8 @@ create_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
/* We need to read the type's signature in order to build the hash
table, but we don't need anything else just yet. */
- ptr = read_and_check_comp_unit_head (per_objfile, &header, section,
- abbrev_section, ptr, section_kind);
+ ptr = read_and_check_comp_unit_head (&header, section, abbrev_section,
+ ptr, section_kind);
length = header.get_length_with_initial ();
@@ -2447,8 +2454,7 @@ create_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
continue;
}
- dwo_unit *dwo_tu
- = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, dwo_unit);
+ dwo_unit *dwo_tu = OBSTACK_ZALLOC (&per_bfd->obstack, dwo_unit);
dwo_tu->dwo_file = dwo_file;
dwo_tu->signature = header.signature;
dwo_tu->type_offset_in_tu = header.type_cu_offset_in_tu;
@@ -2478,14 +2484,14 @@ create_debug_type_hash_table (dwarf2_per_objfile *per_objfile,
Note: This function processes DWO files only, not DWP files. */
-static void
-create_debug_types_hash_table
- (dwarf2_per_objfile *per_objfile, dwo_file *dwo_file,
+void
+cutu_reader::create_dwo_debug_types_hash_table
+ (dwarf2_per_bfd *per_bfd, dwo_file *dwo_file,
gdb::array_view<dwarf2_section_info> type_sections)
{
for (dwarf2_section_info &section : type_sections)
- create_debug_type_hash_table (per_objfile, dwo_file, &section,
- rcuh_kind::TYPE);
+ create_dwo_debug_type_hash_table (per_bfd, dwo_file, &section,
+ rcuh_kind::TYPE);
}
/* Add an entry for signature SIG to per_bfd->signatured_types. */
@@ -2610,7 +2616,7 @@ lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
{
dwarf2_per_objfile *per_objfile = cu->per_objfile;
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
- struct dwp_file *dwp_file = get_dwp_file (per_objfile);
+ dwp_file *dwp_file = per_objfile->per_bfd->dwp_file.get ();
gdb_assert (cu->dwo_unit);
gdb_assert (dwp_file != NULL);
@@ -2652,7 +2658,7 @@ lookup_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
{
/* We're in a DWO/DWP file, and we're using .gdb_index.
These cases require special processing. */
- if (get_dwp_file (per_objfile) == NULL)
+ if (per_objfile->per_bfd->dwp_file == nullptr)
return lookup_dwo_signatured_type (cu, sig);
else
return lookup_dwp_signatured_type (cu, sig);
@@ -2712,9 +2718,8 @@ cutu_reader::read_cutu_die_from_dwo (dwarf2_cu *cu, dwo_unit *dwo_unit,
die_info *stub_comp_unit_die,
const char *stub_comp_dir)
{
- dwarf2_per_objfile *per_objfile = cu->per_objfile;
dwarf2_per_cu *per_cu = cu->per_cu;
- struct objfile *objfile = per_objfile->objfile;
+ struct objfile *objfile = cu->per_objfile->objfile;
bfd *abfd;
struct dwarf2_section_info *dwo_abbrev_section;
@@ -2790,9 +2795,10 @@ cutu_reader::read_cutu_die_from_dwo (dwarf2_cu *cu, dwo_unit *dwo_unit,
{
signatured_type *sig_type = (struct signatured_type *) per_cu;
- m_info_ptr = read_and_check_comp_unit_head (per_objfile, &cu->header,
- section, dwo_abbrev_section,
+ m_info_ptr = read_and_check_comp_unit_head (&cu->header, section,
+ dwo_abbrev_section,
m_info_ptr, rcuh_kind::TYPE);
+
/* This is not an assert because it can be caused by bad debug info. */
if (sig_type->signature != cu->header.signature)
{
@@ -2818,7 +2824,7 @@ cutu_reader::read_cutu_die_from_dwo (dwarf2_cu *cu, dwo_unit *dwo_unit,
else
{
m_info_ptr
- = read_and_check_comp_unit_head (per_objfile, &cu->header, section,
+ = read_and_check_comp_unit_head (&cu->header, section,
dwo_abbrev_section, m_info_ptr,
rcuh_kind::COMPILE);
gdb_assert (dwo_unit->sect_off == cu->header.sect_off);
@@ -2873,8 +2879,9 @@ lookup_dwo_id (struct dwarf2_cu *cu, struct die_info* comp_unit_die)
Returns nullptr if the specified DWO unit cannot be found. */
-static struct dwo_unit *
-lookup_dwo_unit (dwarf2_cu *cu, die_info *comp_unit_die, const char *dwo_name)
+dwo_unit *
+cutu_reader::lookup_dwo_unit (dwarf2_cu *cu, die_info *comp_unit_die,
+ const char *dwo_name)
{
#if CXX_STD_THREAD
/* We need a lock here to handle the DWO hash table. */
@@ -3047,7 +3054,7 @@ cutu_reader::cutu_reader (dwarf2_per_cu &this_cu,
if (this_cu.is_debug_types)
{
m_info_ptr
- = read_and_check_comp_unit_head (&per_objfile, &cu->header, section,
+ = read_and_check_comp_unit_head (&cu->header, section,
abbrev_section, m_info_ptr,
rcuh_kind::TYPE);
@@ -3070,7 +3077,7 @@ cutu_reader::cutu_reader (dwarf2_per_cu &this_cu,
else
{
m_info_ptr
- = read_and_check_comp_unit_head (&per_objfile, &cu->header, section,
+ = read_and_check_comp_unit_head (&cu->header, section,
abbrev_section, m_info_ptr,
rcuh_kind::COMPILE);
@@ -3204,12 +3211,11 @@ cutu_reader::cutu_reader (dwarf2_per_cu &this_cu,
m_info_ptr = section->buffer + to_underlying (this_cu.sect_off);
const gdb_byte *begin_info_ptr = m_info_ptr;
- m_info_ptr
- = read_and_check_comp_unit_head (&per_objfile, &m_new_cu->header, section,
- abbrev_section, m_info_ptr,
- (this_cu.is_debug_types
- ? rcuh_kind::TYPE
- : rcuh_kind::COMPILE));
+ m_info_ptr = read_and_check_comp_unit_head (&m_new_cu->header, section,
+ abbrev_section, m_info_ptr,
+ (this_cu.is_debug_types
+ ? rcuh_kind::TYPE
+ : rcuh_kind::COMPILE));
m_new_cu->str_offsets_base = parent_cu.str_offsets_base;
m_new_cu->addr_base = parent_cu.addr_base;
@@ -3510,7 +3516,7 @@ process_skeletonless_type_units (dwarf2_per_objfile *per_objfile,
cooked_index_worker_result *storage)
{
/* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
- if (get_dwp_file (per_objfile) == nullptr)
+ if (per_objfile->per_bfd->dwp_file == nullptr)
for (const dwo_file_up &file : per_objfile->per_bfd->dwo_files)
for (dwo_unit *unit : file->tus)
process_skeletonless_type_unit (unit, per_objfile, storage);
@@ -3692,6 +3698,7 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile,
{
const gdb_byte *info_ptr;
struct objfile *objfile = per_objfile->objfile;
+ dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
dwarf_read_debug_printf ("Reading %s for %s",
section->get_name (),
@@ -3708,20 +3715,19 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile,
sect_offset sect_off = (sect_offset) (info_ptr - section->buffer);
comp_unit_head cu_header;
- read_and_check_comp_unit_head (per_objfile, &cu_header, section,
- abbrev_section, info_ptr,
- section_kind);
+ read_and_check_comp_unit_head (&cu_header, section, abbrev_section,
+ info_ptr, section_kind);
unsigned int length = cu_header.get_length_with_initial ();
/* Save the compilation unit for later lookup. */
if (cu_header.unit_type != DW_UT_type)
- this_cu
- = per_objfile->per_bfd->allocate_per_cu (section, sect_off, length, is_dwz);
+ this_cu = per_bfd->allocate_per_cu (section, sect_off, length, is_dwz);
else
{
- auto sig_type = per_objfile->per_bfd->allocate_signatured_type
- (section, sect_off, length, is_dwz, cu_header.signature);
+ auto sig_type
+ = per_bfd->allocate_signatured_type (section, sect_off, length,
+ is_dwz, cu_header.signature);
signatured_type *sig_ptr = sig_type.get ();
sig_type->type_offset_in_tu = cu_header.type_cu_offset_in_tu;
this_cu.reset (sig_type.release ());
@@ -3737,7 +3743,7 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile,
}
info_ptr = info_ptr + this_cu->length ();
- per_objfile->per_bfd->all_units.push_back (std::move (this_cu));
+ per_bfd->all_units.push_back (std::move (this_cu));
}
}
@@ -3896,11 +3902,13 @@ cutu_reader::skip_one_attribute (dwarf_form form, const gdb_byte *info_ptr)
case DW_FORM_data4:
case DW_FORM_ref4:
case DW_FORM_strx4:
+ case DW_FORM_ref_sup4:
return info_ptr + 4;
case DW_FORM_data8:
case DW_FORM_ref8:
case DW_FORM_ref_sig8:
+ case DW_FORM_ref_sup8:
return info_ptr + 8;
case DW_FORM_data16:
@@ -3913,6 +3921,7 @@ cutu_reader::skip_one_attribute (dwarf_form form, const gdb_byte *info_ptr)
case DW_FORM_sec_offset:
case DW_FORM_strp:
case DW_FORM_GNU_strp_alt:
+ case DW_FORM_strp_sup:
return info_ptr + m_cu->header.offset_size;
case DW_FORM_exprloc:
@@ -5023,7 +5032,7 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
if (attr != NULL)
{
sect_offset sect_off = attr->get_ref_die_offset ();
- bool is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
+ bool is_dwz = attr->form_is_alt () || cu->per_cu->is_dwz;
dwarf2_per_objfile *per_objfile = cu->per_objfile;
dwarf2_per_cu *per_cu
= dwarf2_find_containing_comp_unit (sect_off, is_dwz,
@@ -6307,16 +6316,14 @@ lookup_dwo_file (dwarf2_per_bfd *per_bfd, const char *dwo_name,
/* Create the dwo_units for the CUs in a DWO_FILE.
Note: This function processes DWO files only, not DWP files. */
-static void
-create_cus_hash_table (dwarf2_cu *cu, dwo_file &dwo_file)
+void
+cutu_reader::create_dwo_cus_hash_table (dwarf2_cu *cu, dwo_file &dwo_file)
{
dwarf2_per_objfile *per_objfile = cu->per_objfile;
- struct objfile *objfile = per_objfile->objfile;
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
const gdb_byte *info_ptr, *end_ptr;
auto &section = dwo_file.sections.info;
- section.read (objfile);
info_ptr = section.buffer;
if (info_ptr == NULL)
@@ -6342,6 +6349,12 @@ create_cus_hash_table (dwarf2_cu *cu, dwo_file &dwo_file)
if (reader.is_dummy())
continue;
+ /* DWARF 5 .debug_info.dwo sections may contain some type units. Skip
+ everything that is not a compile unit. */
+ if (const auto ut = reader.cu ()->header.unit_type;
+ ut != DW_UT_compile && ut != DW_UT_split_compile)
+ continue;
+
std::optional<ULONGEST> signature
= lookup_dwo_id (reader.cu (), reader.top_level_die ());
if (!signature.has_value ())
@@ -6530,27 +6543,18 @@ create_cus_hash_table (dwarf2_cu *cu, dwo_file &dwo_file)
Note: This function processes DWP files only, not DWO files. */
static struct dwp_hash_table *
-create_dwp_hash_table (dwarf2_per_objfile *per_objfile,
- struct dwp_file *dwp_file, int is_debug_types)
+create_dwp_hash_table (dwarf2_per_bfd *per_bfd, struct dwp_file *dwp_file,
+ dwarf2_section_info &index)
{
- struct objfile *objfile = per_objfile->objfile;
bfd *dbfd = dwp_file->dbfd.get ();
- const gdb_byte *index_ptr, *index_end;
- struct dwarf2_section_info *index;
uint32_t version, nr_columns, nr_units, nr_slots;
struct dwp_hash_table *htab;
- if (is_debug_types)
- index = &dwp_file->sections.tu_index;
- else
- index = &dwp_file->sections.cu_index;
-
- if (index->empty ())
+ if (index.empty ())
return NULL;
- index->read (objfile);
- index_ptr = index->buffer;
- index_end = index_ptr + index->size;
+ const gdb_byte *index_ptr = index.buffer;
+ const gdb_byte *index_end = index_ptr + index.size;
/* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
For now it's safe to just read 4 bytes (particularly as it's difficult to
@@ -6581,7 +6585,7 @@ create_dwp_hash_table (dwarf2_per_objfile *per_objfile,
pulongest (nr_slots), dwp_file->name);
}
- htab = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, struct dwp_hash_table);
+ htab = OBSTACK_ZALLOC (&per_bfd->obstack, struct dwp_hash_table);
htab->version = version;
htab->nr_columns = nr_columns;
htab->nr_units = nr_units;
@@ -7520,9 +7524,9 @@ try_open_dwop_file (dwarf2_per_bfd *per_bfd, const char *file_name, int is_dwp,
Upon success, the canonicalized path of the file is stored in the bfd,
same as symfile_bfd_open. */
-static gdb_bfd_ref_ptr
-open_dwo_file (dwarf2_per_bfd *per_bfd, const char *file_name,
- const char *comp_dir)
+gdb_bfd_ref_ptr
+cutu_reader::open_dwo_file (dwarf2_per_bfd *per_bfd, const char *file_name,
+ const char *comp_dir)
{
if (IS_ABSOLUTE_PATH (file_name))
return try_open_dwop_file (per_bfd, file_name,
@@ -7557,9 +7561,9 @@ open_dwo_file (dwarf2_per_bfd *per_bfd, const char *file_name,
/* This function is mapped across the sections and remembers the offset and
size of each of the DWO debugging sections we are interested in. */
-static void
-dwarf2_locate_dwo_sections (struct objfile *objfile, bfd *abfd,
- asection *sectp, dwo_sections *dwo_sections)
+void
+cutu_reader::locate_dwo_sections (struct objfile *objfile, bfd *abfd,
+ asection *sectp, dwo_sections *dwo_sections)
{
const struct dwop_section_names *names = &dwop_section_names;
@@ -7606,11 +7610,12 @@ dwarf2_locate_dwo_sections (struct objfile *objfile, bfd *abfd,
by PER_CU. This is for the non-DWP case.
The result is NULL if DWO_NAME can't be found. */
-static dwo_file_up
-open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
- const char *comp_dir)
+dwo_file_up
+cutu_reader::open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
+ const char *comp_dir)
{
dwarf2_per_objfile *per_objfile = cu->per_objfile;
+ dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile->per_bfd, dwo_name, comp_dir);
@@ -7627,17 +7632,18 @@ open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
dwo_file->dbfd = std::move (dbfd);
for (asection *sec : gdb_bfd_sections (dwo_file->dbfd))
- dwarf2_locate_dwo_sections (per_objfile->objfile, dwo_file->dbfd.get (),
- sec, &dwo_file->sections);
+ this->locate_dwo_sections (per_objfile->objfile, dwo_file->dbfd.get (), sec,
+ &dwo_file->sections);
- create_cus_hash_table (cu, *dwo_file);
+ create_dwo_cus_hash_table (cu, *dwo_file);
if (cu->header.version < 5)
- create_debug_types_hash_table (per_objfile, dwo_file.get (),
- dwo_file->sections.types);
+ create_dwo_debug_types_hash_table (per_bfd, dwo_file.get (),
+ dwo_file->sections.types);
else
- create_debug_type_hash_table (per_objfile, dwo_file.get (),
- &dwo_file->sections.info, rcuh_kind::COMPILE);
+ create_dwo_debug_type_hash_table (per_bfd, dwo_file.get (),
+ &dwo_file->sections.info,
+ rcuh_kind::COMPILE);
dwarf_read_debug_printf ("DWO file found: %s", dwo_name);
@@ -7803,10 +7809,9 @@ open_dwp_file (dwarf2_per_bfd *per_bfd, const char *file_name)
}
/* Initialize the use of the DWP file for the current objfile.
- By convention the name of the DWP file is ${objfile}.dwp.
- The result is NULL if it can't be found. */
+ By convention the name of the DWP file is ${objfile}.dwp. */
-static dwp_file_up
+static void
open_and_init_dwp_file (dwarf2_per_objfile *per_objfile)
{
struct objfile *objfile = per_objfile->objfile;
@@ -7844,7 +7849,7 @@ open_and_init_dwp_file (dwarf2_per_objfile *per_objfile)
{
dwarf_read_debug_printf ("DWP file not found: %s", dwp_name.c_str ());
- return dwp_file_up ();
+ return;
}
const char *name = bfd_get_filename (dbfd.get ());
@@ -7858,9 +7863,10 @@ open_and_init_dwp_file (dwarf2_per_objfile *per_objfile)
dwarf2_locate_common_dwp_sections (objfile, dwp_file->dbfd.get (), sec,
dwp_file.get ());
- dwp_file->cus = create_dwp_hash_table (per_objfile, dwp_file.get (), 0);
-
- dwp_file->tus = create_dwp_hash_table (per_objfile, dwp_file.get (), 1);
+ dwp_file->cus = create_dwp_hash_table (per_bfd, dwp_file.get (),
+ dwp_file->sections.cu_index);
+ dwp_file->tus = create_dwp_hash_table (per_bfd, dwp_file.get (),
+ dwp_file->sections.tu_index);
/* The DWP file version is stored in the hash table. Oh well. */
if (dwp_file->cus && dwp_file->tus
@@ -7900,20 +7906,8 @@ open_and_init_dwp_file (dwarf2_per_objfile *per_objfile)
bfd_cache_close (dwp_file->dbfd.get ());
- return dwp_file;
-}
-
-/* Wrapper around open_and_init_dwp_file, only open it once. */
-
-static struct dwp_file *
-get_dwp_file (dwarf2_per_objfile *per_objfile)
-{
- if (!per_objfile->per_bfd->dwp_checked)
- {
- per_objfile->per_bfd->dwp_file = open_and_init_dwp_file (per_objfile);
- per_objfile->per_bfd->dwp_checked = 1;
- }
- return per_objfile->per_bfd->dwp_file.get ();
+ /* Everything worked, install this dwp_file in the per_bfd. */
+ per_objfile->per_bfd->dwp_file = std::move (dwp_file);
}
/* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
@@ -7932,22 +7926,23 @@ get_dwp_file (dwarf2_per_objfile *per_objfile)
The result is a pointer to the dwo_unit object or NULL if we didn't find it
(dwo_id mismatch or couldn't find the DWO/DWP file). */
-static struct dwo_unit *
-lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
- ULONGEST signature, int is_debug_types)
+dwo_unit *
+cutu_reader::lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name,
+ const char *comp_dir, ULONGEST signature,
+ int is_debug_types)
{
dwarf2_per_objfile *per_objfile = cu->per_objfile;
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
struct objfile *objfile = per_objfile->objfile;
const char *kind = is_debug_types ? "TU" : "CU";
- struct dwp_file *dwp_file;
/* First see if there's a DWP file.
If we have a DWP file but didn't find the DWO inside it, don't
look for the original DWO file. It makes gdb behave differently
depending on whether one is debugging in the build tree. */
- dwp_file = get_dwp_file (per_objfile);
+ dwp_file *dwp_file = per_objfile->per_bfd->dwp_file.get ();
+
if (dwp_file != NULL)
{
const struct dwp_hash_table *dwp_htab =
@@ -8048,9 +8043,9 @@ lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
/* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
See lookup_dwo_cutu_unit for details. */
-static struct dwo_unit *
-lookup_dwo_comp_unit (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
- ULONGEST signature)
+dwo_unit *
+cutu_reader::lookup_dwo_comp_unit (dwarf2_cu *cu, const char *dwo_name,
+ const char *comp_dir, ULONGEST signature)
{
gdb_assert (!cu->per_cu->is_debug_types);
@@ -8060,8 +8055,9 @@ lookup_dwo_comp_unit (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
/* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
See lookup_dwo_cutu_unit for details. */
-static struct dwo_unit *
-lookup_dwo_type_unit (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir)
+dwo_unit *
+cutu_reader::lookup_dwo_type_unit (dwarf2_cu *cu, const char *dwo_name,
+ const char *comp_dir)
{
gdb_assert (cu->per_cu->is_debug_types);
@@ -8104,7 +8100,7 @@ queue_and_load_all_dwo_tus (dwarf2_cu *cu)
gdb_assert (cu != nullptr);
gdb_assert (!cu->per_cu->is_debug_types);
- gdb_assert (get_dwp_file (cu->per_objfile) == nullptr);
+ gdb_assert (cu->per_objfile->per_bfd->dwp_file == nullptr);
dwo_unit = cu->dwo_unit;
gdb_assert (dwo_unit != NULL);
@@ -9933,7 +9929,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu,
so if we see it, we can assume that a constant form is really
a constant and not a section offset. */
if (attr->form_is_constant ())
- *offset = attr->constant_value (0);
+ *offset = attr->unsigned_constant ().value_or (0);
else if (attr->form_is_section_offset ())
dwarf2_complex_location_expr_complaint ();
else if (attr->form_is_block ()
@@ -9951,7 +9947,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu,
attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
if (attr != nullptr)
{
- *offset = attr->constant_value (0);
+ *offset = attr->unsigned_constant ().value_or (0);
return 1;
}
}
@@ -9973,7 +9969,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu,
{
if (attr->form_is_constant ())
{
- LONGEST offset = attr->constant_value (0);
+ LONGEST offset = attr->unsigned_constant ().value_or (0);
/* Work around this GCC 11 bug, where it would erroneously use -1
data member locations, instead of 0:
@@ -10022,7 +10018,7 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu,
{
attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
if (attr != nullptr)
- field->set_loc_bitpos (attr->constant_value (0));
+ field->set_loc_bitpos (attr->unsigned_constant ().value_or (0));
}
}
@@ -10091,7 +10087,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
/* Get bit size of field (zero if none). */
attr = dwarf2_attr (die, DW_AT_bit_size, cu);
if (attr != nullptr)
- fp->set_bitsize (attr->constant_value (0));
+ fp->set_bitsize (attr->unsigned_constant ().value_or (0));
else
fp->set_bitsize (0);
@@ -10100,6 +10096,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
attr = dwarf2_attr (die, DW_AT_bit_offset, cu);
if (attr != nullptr && attr->form_is_constant ())
{
+ ULONGEST bit_offset = attr->unsigned_constant ().value_or (0);
if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
{
/* For big endian bits, the DW_AT_bit_offset gives the
@@ -10107,7 +10104,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
anonymous object to the MSB of the field. We don't
have to do anything special since we don't need to
know the size of the anonymous object. */
- fp->set_loc_bitpos (fp->loc_bitpos () + attr->constant_value (0));
+ fp->set_loc_bitpos (fp->loc_bitpos () + bit_offset);
}
else
{
@@ -10118,7 +10115,6 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
the field itself. The result is the bit offset of
the LSB of the field. */
int anonymous_size;
- int bit_offset = attr->constant_value (0);
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
if (attr != nullptr && attr->form_is_constant ())
@@ -10126,7 +10122,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
/* The size of the anonymous object containing
the bit field is explicit, so use the
indicated size (in bytes). */
- anonymous_size = attr->constant_value (0);
+ anonymous_size = attr->unsigned_constant ().value_or (0);
}
else
{
@@ -10279,13 +10275,19 @@ convert_variant_range (struct obstack *obstack, const variant_field &variant,
{
std::vector<discriminant_range> ranges;
- if (variant.default_branch)
+ if (variant.is_default ())
return {};
if (variant.discr_list_data == nullptr)
{
- discriminant_range r
- = {variant.discriminant_value, variant.discriminant_value};
+ ULONGEST value;
+
+ if (is_unsigned)
+ value = variant.discriminant_attr->unsigned_constant ().value_or (0);
+ else
+ value = variant.discriminant_attr->signed_constant ().value_or (0);
+
+ discriminant_range r = { value, value };
ranges.push_back (r);
}
else
@@ -11099,7 +11101,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
if (attr != nullptr)
{
if (attr->form_is_constant ())
- type->set_length (attr->constant_value (0));
+ type->set_length (attr->unsigned_constant ().value_or (0));
else
{
struct dynamic_prop prop;
@@ -11244,12 +11246,14 @@ handle_variant (struct die_info *die, struct type *type,
{
discr = dwarf2_attr (die, DW_AT_discr_list, cu);
if (discr == nullptr || discr->as_block ()->size == 0)
- variant.default_branch = true;
+ {
+ /* Nothing to do here -- default branch. */
+ }
else
variant.discr_list_data = discr->as_block ();
}
else
- variant.discriminant_value = discr->constant_value (0);
+ variant.discriminant_attr = discr;
for (die_info *variant_child : die->children ())
handle_struct_member_die (variant_child, type, fi, template_args, cu);
@@ -11575,25 +11579,30 @@ die_byte_order (die_info *die, dwarf2_cu *cu, enum bfd_endian *byte_order)
/* Assuming DIE is an enumeration type, and TYPE is its associated
type, update TYPE using some information only available in DIE's
- children. In particular, the fields are computed. */
+ children. In particular, the fields are computed. If IS_UNSIGNED
+ is set, the enumeration type's sign is already known (a true value
+ means unsigned), and so examining the constants to determine the
+ sign isn't needed; when this is unset, the enumerator constants are
+ read as signed values. */
static void
update_enumeration_type_from_children (struct die_info *die,
struct type *type,
- struct dwarf2_cu *cu)
+ struct dwarf2_cu *cu,
+ std::optional<bool> is_unsigned)
{
- int unsigned_enum = 1;
- int flag_enum = 1;
+ /* This is used to check whether the enum is signed or unsigned; for
+ simplicity, it is always correct regardless of whether
+ IS_UNSIGNED is set. */
+ bool unsigned_enum = is_unsigned.value_or (true);
+ bool flag_enum = true;
- auto_obstack obstack;
std::vector<struct field> fields;
for (die_info *child_die : die->children ())
{
struct attribute *attr;
LONGEST value;
- const gdb_byte *bytes;
- struct dwarf2_locexpr_baton *baton;
const char *name;
if (child_die->tag != DW_TAG_enumerator)
@@ -11607,19 +11616,26 @@ update_enumeration_type_from_children (struct die_info *die,
if (name == NULL)
name = "<anonymous enumerator>";
- dwarf2_const_value_attr (attr, type, name, &obstack, cu,
- &value, &bytes, &baton);
- if (value < 0)
- {
- unsigned_enum = 0;
- flag_enum = 0;
- }
+ /* Can't check UNSIGNED_ENUM here because that is
+ optimistic. */
+ if (is_unsigned.has_value () && *is_unsigned)
+ value = attr->unsigned_constant ().value_or (0);
else
{
- if (count_one_bits_ll (value) >= 2)
- flag_enum = 0;
+ /* Read as signed, either because we don't know the sign or
+ because we know it is definitely signed. */
+ value = attr->signed_constant ().value_or (0);
+
+ if (value < 0)
+ {
+ unsigned_enum = false;
+ flag_enum = false;
+ }
}
+ if (flag_enum && count_one_bits_ll (value) >= 2)
+ flag_enum = false;
+
struct field &field = fields.emplace_back ();
field.set_name (dwarf2_physname (name, child_die, cu));
field.set_loc_enumval (value);
@@ -11628,13 +11644,10 @@ update_enumeration_type_from_children (struct die_info *die,
if (!fields.empty ())
type->copy_fields (fields);
else
- flag_enum = 0;
+ flag_enum = false;
- if (unsigned_enum)
- type->set_is_unsigned (true);
-
- if (flag_enum)
- type->set_is_flag_enum (true);
+ type->set_is_unsigned (unsigned_enum);
+ type->set_is_flag_enum (flag_enum);
}
/* Given a DW_AT_enumeration_type die, set its type. We do not
@@ -11678,7 +11691,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
if (attr != nullptr)
- type->set_length (attr->constant_value (0));
+ type->set_length (attr->unsigned_constant ().value_or (0));
else
type->set_length (0);
@@ -11692,6 +11705,11 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
if (die_is_declaration (die, cu))
type->set_is_stub (true);
+ /* If the underlying type is known, and is unsigned, then we'll
+ assume the enumerator constants are unsigned. Otherwise we have
+ to assume they are signed. */
+ std::optional<bool> is_unsigned;
+
/* If this type has an underlying type that is not a stub, then we
may use its attributes. We always use the "unsigned" attribute
in this situation, because ordinarily we guess whether the type
@@ -11704,7 +11722,8 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
struct type *underlying_type = type->target_type ();
underlying_type = check_typedef (underlying_type);
- type->set_is_unsigned (underlying_type->is_unsigned ());
+ is_unsigned = underlying_type->is_unsigned ();
+ type->set_is_unsigned (*is_unsigned);
if (type->length () == 0)
type->set_length (underlying_type->length ());
@@ -11724,7 +11743,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
Note that, as usual, this must come after set_die_type to avoid
infinite recursion when trying to compute the names of the
enumerators. */
- update_enumeration_type_from_children (die, type, cu);
+ update_enumeration_type_from_children (die, type, cu, is_unsigned);
return type;
}
@@ -12074,7 +12093,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_bit_stride, cu);
if (attr != NULL)
- bit_stride = attr->constant_value (0);
+ bit_stride = attr->unsigned_constant ().value_or (0);
/* Irix 6.2 native cc creates array types without children for
arrays with unspecified length. */
@@ -12298,7 +12317,7 @@ mark_common_block_symbol_computed (struct symbol *sym,
if (member_loc->form_is_constant ())
{
- offset = member_loc->constant_value (0);
+ offset = member_loc->unsigned_constant ().value_or (0);
baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size;
}
else
@@ -12613,7 +12632,8 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu);
if (attr_byte_size)
- byte_size = attr_byte_size->constant_value (cu_header->addr_size);
+ byte_size = (attr_byte_size->unsigned_constant ()
+ .value_or (cu_header->addr_size));
else
byte_size = cu_header->addr_size;
@@ -12725,7 +12745,8 @@ read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu,
type = lookup_reference_type (target_type, refcode);
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
if (attr != nullptr)
- type->set_length (attr->constant_value (cu_header->addr_size));
+ type->set_length (attr->unsigned_constant ()
+ .value_or (cu_header->addr_size));
else
type->set_length (cu_header->addr_size);
@@ -12889,9 +12910,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
len = dwarf2_attr (die, DW_AT_byte_size, cu);
if (len != nullptr && len->form_is_constant ())
{
- /* Pass 0 as the default as we know this attribute is constant
- and the default value will not be returned. */
- LONGEST sz = len->constant_value (0);
+ LONGEST sz = len->unsigned_constant ().value_or (0);
prop_type = objfile_int_type (objfile, sz, true);
}
else
@@ -12910,15 +12929,14 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
else if (attr != nullptr)
{
/* This DW_AT_string_length just contains the length with no
- indirection. There's no need to create a dynamic property in this
- case. Pass 0 for the default value as we know it will not be
- returned in this case. */
- length = attr->constant_value (0);
+ indirection. There's no need to create a dynamic property in
+ this case. */
+ length = attr->unsigned_constant ().value_or (0);
}
else if ((attr = dwarf2_attr (die, DW_AT_byte_size, cu)) != nullptr)
{
/* We don't currently support non-constant byte sizes for strings. */
- length = attr->constant_value (1);
+ length = attr->unsigned_constant ().value_or (1);
}
else
{
@@ -13227,10 +13245,10 @@ get_mpz (struct dwarf2_cu *cu, gdb_mpz *value, struct attribute *attr)
? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE,
true);
}
- else if (attr->form_is_unsigned ())
+ else if (attr->form_is_strictly_unsigned ())
*value = gdb_mpz (attr->as_unsigned ());
else
- *value = gdb_mpz (attr->constant_value (1));
+ *value = gdb_mpz (attr->signed_constant ().value_or (1));
}
/* Assuming DIE is a rational DW_TAG_constant, read the DIE's
@@ -13409,14 +13427,14 @@ finish_fixed_point_type (struct type *type, const char *suffix,
}
else if (attr->name == DW_AT_binary_scale)
{
- LONGEST scale_exp = attr->constant_value (0);
+ LONGEST scale_exp = attr->signed_constant ().value_or (0);
gdb_mpz &num_or_denom = scale_exp > 0 ? scale_num : scale_denom;
num_or_denom <<= std::abs (scale_exp);
}
else if (attr->name == DW_AT_decimal_scale)
{
- LONGEST scale_exp = attr->constant_value (0);
+ LONGEST scale_exp = attr->signed_constant ().value_or (0);
gdb_mpz &num_or_denom = scale_exp > 0 ? scale_num : scale_denom;
num_or_denom = gdb_mpz::pow (10, std::abs (scale_exp));
@@ -13628,7 +13646,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
}
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
if (attr != nullptr)
- bits = attr->constant_value (0) * TARGET_CHAR_BIT;
+ bits = attr->unsigned_constant ().value_or (0) * TARGET_CHAR_BIT;
name = dwarf2_full_name (nullptr, die, cu);
if (!name)
complaint (_("DW_AT_name missing from DW_TAG_base_type"));
@@ -13779,22 +13797,28 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_bit_size, cu);
if (attr != nullptr && attr->form_is_constant ())
{
- unsigned real_bit_size = attr->constant_value (0);
+ unsigned real_bit_size = attr->unsigned_constant ().value_or (0);
if (real_bit_size >= 0 && real_bit_size <= 8 * type->length ())
{
attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
/* Only use the attributes if they make sense together. */
- if (attr == nullptr
- || (attr->form_is_constant ()
- && attr->constant_value (0) >= 0
- && (attr->constant_value (0) + real_bit_size
- <= 8 * type->length ())))
+ std::optional<ULONGEST> bit_offset;
+ if (attr == nullptr)
+ bit_offset = 0;
+ else if (attr->form_is_constant ())
+ {
+ bit_offset = attr->unsigned_constant ();
+ if (bit_offset.has_value ()
+ && *bit_offset + real_bit_size > 8 * type->length ())
+ bit_offset.reset ();
+ }
+ if (bit_offset.has_value ())
{
TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size
= real_bit_size;
if (attr != nullptr)
TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset
- = attr->constant_value (0);
+ = *bit_offset;
}
}
}
@@ -14107,8 +14131,13 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
LONGEST bias = 0;
struct attribute *bias_attr = dwarf2_attr (die, DW_AT_GNU_bias, cu);
- if (bias_attr != nullptr && bias_attr->form_is_constant ())
- bias = bias_attr->constant_value (0);
+ if (bias_attr != nullptr)
+ {
+ if (base_type->is_unsigned ())
+ bias = (LONGEST) bias_attr->unsigned_constant ().value_or (0);
+ else
+ bias = bias_attr->signed_constant ().value_or (0);
+ }
/* Normally, the DWARF producers are expected to use a signed
constant form (Eg. DW_FORM_sdata) to express negative bounds.
@@ -14195,7 +14224,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
if (attr != nullptr)
- range_type->set_length (attr->constant_value (0));
+ range_type->set_length (attr->unsigned_constant ().value_or (0));
maybe_set_alignment (cu, die, range_type);
@@ -14927,10 +14956,12 @@ cutu_reader::read_attribute_value (attribute *attr, unsigned form,
info_ptr += 2;
break;
case DW_FORM_data4:
+ case DW_FORM_ref_sup4:
attr->set_unsigned (read_4_bytes (m_abfd, info_ptr));
info_ptr += 4;
break;
case DW_FORM_data8:
+ case DW_FORM_ref_sup8:
attr->set_unsigned (read_8_bytes (m_abfd, info_ptr));
info_ptr += 8;
break;
@@ -14982,6 +15013,7 @@ cutu_reader::read_attribute_value (attribute *attr, unsigned form,
}
[[fallthrough]];
case DW_FORM_GNU_strp_alt:
+ case DW_FORM_strp_sup:
{
dwz_file *dwz = per_objfile->per_bfd->get_dwz_file (true);
LONGEST str_offset
@@ -17179,13 +17211,10 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
list was that this is unspecified. We choose to always zero-extend
because that is the interpretation long in use by GCC. */
-static gdb_byte *
-dwarf2_const_value_data (const struct attribute *attr, struct obstack *obstack,
- struct dwarf2_cu *cu, LONGEST *value, int bits)
+static void
+dwarf2_const_value_data (const struct attribute *attr, LONGEST *value,
+ int bits)
{
- struct objfile *objfile = cu->per_objfile->objfile;
- enum bfd_endian byte_order = bfd_big_endian (objfile->obfd.get ()) ?
- BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
LONGEST l = attr->constant_value (0);
if (bits < sizeof (*value) * 8)
@@ -17193,16 +17222,8 @@ dwarf2_const_value_data (const struct attribute *attr, struct obstack *obstack,
l &= ((LONGEST) 1 << bits) - 1;
*value = l;
}
- else if (bits == sizeof (*value) * 8)
- *value = l;
else
- {
- gdb_byte *bytes = (gdb_byte *) obstack_alloc (obstack, bits / 8);
- store_unsigned_integer (bytes, bits / 8, byte_order, l);
- return bytes;
- }
-
- return NULL;
+ *value = l;
}
/* Read a constant value from an attribute. Either set *VALUE, or if
@@ -17264,6 +17285,7 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
case DW_FORM_strx:
case DW_FORM_GNU_str_index:
case DW_FORM_GNU_strp_alt:
+ case DW_FORM_strp_sup:
/* The string is already allocated on the objfile obstack, point
directly to it. */
*bytes = (const gdb_byte *) attr->as_string ();
@@ -17287,16 +17309,16 @@ dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
converted to host endianness, so we just need to sign- or
zero-extend it as appropriate. */
case DW_FORM_data1:
- *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 8);
+ dwarf2_const_value_data (attr, value, 8);
break;
case DW_FORM_data2:
- *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 16);
+ dwarf2_const_value_data (attr, value, 16);
break;
case DW_FORM_data4:
- *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 32);
+ dwarf2_const_value_data (attr, value, 32);
break;
case DW_FORM_data8:
- *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 64);
+ dwarf2_const_value_data (attr, value, 64);
break;
case DW_FORM_sdata:
@@ -17470,7 +17492,7 @@ lookup_die_type (struct die_info *die, const struct attribute *attr,
/* First see if we have it cached. */
- if (attr->form == DW_FORM_GNU_ref_alt)
+ if (attr->form_is_alt ())
{
sect_offset sect_off = attr->get_ref_die_offset ();
dwarf2_per_cu *per_cu
@@ -18238,8 +18260,7 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
*ref_cu = target_cu;
- auto it = target_cu->die_hash.find (sect_off);
- return it != target_cu->die_hash.end () ? *it : nullptr;
+ return target_cu->find_die (sect_off);
}
/* Follow reference attribute ATTR of SRC_DIE.
@@ -18254,15 +18275,14 @@ follow_die_ref (struct die_info *src_die, const struct attribute *attr,
struct dwarf2_cu *cu = *ref_cu;
struct die_info *die;
- if (attr->form != DW_FORM_GNU_ref_alt && src_die->sect_off == sect_off)
+ if (!attr->form_is_alt () && src_die->sect_off == sect_off)
{
/* Self-reference, we're done. */
return src_die;
}
die = follow_die_offset (sect_off,
- (attr->form == DW_FORM_GNU_ref_alt
- || cu->per_cu->is_dwz),
+ attr->form_is_alt () || cu->per_cu->is_dwz,
ref_cu);
if (!die)
error (_(DWARF_ERROR_PREFIX
@@ -18473,6 +18493,7 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off,
case DW_FORM_strx:
case DW_FORM_GNU_str_index:
case DW_FORM_GNU_strp_alt:
+ case DW_FORM_strp_sup:
/* The string is already allocated on the objfile obstack, point
directly to it. */
{
@@ -18501,31 +18522,23 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off,
zero-extend it as appropriate. */
case DW_FORM_data1:
type = die_type (die, cu);
- result = dwarf2_const_value_data (attr, obstack, cu, &value, 8);
- if (result == NULL)
- result = write_constant_as_bytes (obstack, byte_order,
- type, value, len);
+ dwarf2_const_value_data (attr, &value, 8);
+ result = write_constant_as_bytes (obstack, byte_order, type, value, len);
break;
case DW_FORM_data2:
type = die_type (die, cu);
- result = dwarf2_const_value_data (attr, obstack, cu, &value, 16);
- if (result == NULL)
- result = write_constant_as_bytes (obstack, byte_order,
- type, value, len);
+ dwarf2_const_value_data (attr, &value, 16);
+ result = write_constant_as_bytes (obstack, byte_order, type, value, len);
break;
case DW_FORM_data4:
type = die_type (die, cu);
- result = dwarf2_const_value_data (attr, obstack, cu, &value, 32);
- if (result == NULL)
- result = write_constant_as_bytes (obstack, byte_order,
- type, value, len);
+ dwarf2_const_value_data (attr, &value, 32);
+ result = write_constant_as_bytes (obstack, byte_order, type, value, len);
break;
case DW_FORM_data8:
type = die_type (die, cu);
- result = dwarf2_const_value_data (attr, obstack, cu, &value, 64);
- if (result == NULL)
- result = write_constant_as_bytes (obstack, byte_order,
- type, value, len);
+ dwarf2_const_value_data (attr, &value, 64);
+ result = write_constant_as_bytes (obstack, byte_order, type, value, len);
break;
case DW_FORM_sdata:
@@ -18615,8 +18628,8 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
gdb_assert (sig_cu != NULL);
gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0);
- if (auto die_it = sig_cu->die_hash.find (sig_type->type_offset_in_section);
- die_it != sig_cu->die_hash.end ())
+ if (die_info *die = sig_cu->find_die (sig_type->type_offset_in_section);
+ die != nullptr)
{
/* For .gdb_index version 7 keep track of included TUs.
http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
@@ -18625,7 +18638,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
(*ref_cu)->per_cu->imported_symtabs.push_back (sig_cu->per_cu);
*ref_cu = sig_cu;
- return *die_it;
+ return die;
}
return NULL;
@@ -19182,7 +19195,7 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
/* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
the section. If so, fall through to the complaint in the
other branch. */
- && attr->as_unsigned () < section->get_size (objfile))
+ && attr->as_unsigned () < section->size)
{
struct dwarf2_loclist_baton *baton;
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 3177b19..f3e043c 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -533,9 +533,9 @@ struct dwarf2_per_bfd
}
/* Return the separate '.dwz' debug file. If there is no
- .gnu_debugaltlink section in the file, then the result depends on
- REQUIRE: if REQUIRE is true, error out; if REQUIRE is false,
- return nullptr. */
+ .gnu_debugaltlink or .debug_sup section in the file, then the
+ result depends on REQUIRE: if REQUIRE is true, error out; if
+ REQUIRE is false, return nullptr. */
struct dwz_file *get_dwz_file (bool require = false)
{
gdb_assert (!require || this->dwz_file.has_value ());
@@ -546,7 +546,7 @@ struct dwarf2_per_bfd
{
result = this->dwz_file->get ();
if (require && result == nullptr)
- error (_("could not read '.gnu_debugaltlink' section"));
+ error (_("could not find supplementary DWARF file"));
}
return result;
@@ -634,9 +634,6 @@ public:
/* Set of dwo_file objects. */
dwo_file_up_set dwo_files;
- /* True if we've checked for whether there is a DWP file. */
- bool dwp_checked = false;
-
/* The DWP file if there is one, or NULL. */
dwp_file_up dwp_file;
@@ -1028,6 +1025,39 @@ private:
const char *read_dwo_str_index (ULONGEST str_index);
+ gdb_bfd_ref_ptr open_dwo_file (dwarf2_per_bfd *per_bfd, const char *file_name,
+ const char *comp_dir);
+
+ dwo_file_up open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
+ const char *comp_dir);
+
+ void locate_dwo_sections (struct objfile *objfile, bfd *abfd, asection *sectp,
+ struct dwo_sections *dwo_sections);
+
+ void create_dwo_cus_hash_table (dwarf2_cu *cu, dwo_file &dwo_file);
+
+ void create_dwo_debug_types_hash_table
+ (dwarf2_per_bfd *per_bfd, dwo_file *dwo_file,
+ gdb::array_view<dwarf2_section_info> type_sections);
+
+ void create_dwo_debug_type_hash_table (dwarf2_per_bfd *per_bfd,
+ dwo_file *dwo_file,
+ dwarf2_section_info *section,
+ rcuh_kind section_kind);
+
+ dwo_unit *lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name,
+ const char *comp_dir, ULONGEST signature,
+ int is_debug_types);
+
+ dwo_unit *lookup_dwo_comp_unit (dwarf2_cu *cu, const char *dwo_name,
+ const char *comp_dir, ULONGEST signature);
+
+ dwo_unit *lookup_dwo_type_unit (dwarf2_cu *cu, const char *dwo_name,
+ const char *comp_dir);
+
+ dwo_unit *lookup_dwo_unit (dwarf2_cu *cu, die_info *comp_unit_die,
+ const char *dwo_name);
+
/* The bfd of die_section. */
bfd *m_abfd;
diff --git a/gdb/dwarf2/section.h b/gdb/dwarf2/section.h
index 85da485..b9d3c31 100644
--- a/gdb/dwarf2/section.h
+++ b/gdb/dwarf2/section.h
@@ -81,19 +81,6 @@ struct dwarf2_section_info
If the section is compressed, uncompress it before returning. */
void read (struct objfile *objfile);
- /* A helper function that returns the size of a section in a safe way.
- If you are positive that the section has been read before using the
- size, then it is safe to refer to the dwarf2_section_info object's
- "size" field directly. In other cases, you must call this
- function, because for compressed sections the size field is not set
- correctly until the section has been read. */
- bfd_size_type get_size (struct objfile *objfile)
- {
- if (!readin)
- read (objfile);
- return size;
- }
-
/* Issue a complaint that something was outside the bounds of this
buffer. */
void overflow_complaint () const;
diff --git a/gdb/eval.c b/gdb/eval.c
index 95d2532..19770ad 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -994,9 +994,10 @@ add_struct_fields (struct type *type, completion_list &output,
output.emplace_back (concat (prefix, type->field (i).name (),
nullptr));
}
- else if (type->field (i).type ()->code () == TYPE_CODE_UNION)
+ else if (type->field (i).type ()->code () == TYPE_CODE_UNION
+ || type->field (i).type ()->code () == TYPE_CODE_STRUCT)
{
- /* Recurse into anonymous unions. */
+ /* Recurse into anonymous unions and structures. */
add_struct_fields (type->field (i).type (),
output, fieldname, namelen, prefix);
}
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 2938931..9da5c48 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -485,7 +485,8 @@ language_defn::read_var_value (struct symbol *var,
/* Determine address of TLS variable. */
if (obj_section
&& (obj_section->the_bfd_section->flags & SEC_THREAD_LOCAL) != 0)
- addr = target_translate_tls_address (obj_section->objfile, addr);
+ addr = target_translate_tls_address (obj_section->objfile, addr,
+ var->print_name ());
}
break;
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 3d5ede8..0b87287 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -3972,7 +3972,8 @@ delete_just_stopped_threads_single_step_breakpoints (void)
void
print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
- const struct target_waitstatus &ws)
+ const struct target_waitstatus &ws,
+ process_stratum_target *proc_target)
{
infrun_debug_printf ("target_wait (%s [%s], status) =",
waiton_ptid.to_string ().c_str (),
@@ -3981,6 +3982,20 @@ print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
result_ptid.to_string ().c_str (),
target_pid_to_str (result_ptid).c_str ());
infrun_debug_printf (" %s", ws.to_string ().c_str ());
+
+ if (proc_target != nullptr)
+ infrun_debug_printf (" from target %d (%s)",
+ proc_target->connection_number,
+ proc_target->shortname ());
+}
+
+/* Wrapper for print_target_wait_results above for convenience. */
+
+static void
+print_target_wait_results (ptid_t waiton_ptid,
+ const execution_control_state &ecs)
+{
+ print_target_wait_results (waiton_ptid, ecs.ptid, ecs.ws, ecs.target);
}
/* Select a thread at random, out of those which are resumed and have
@@ -4332,7 +4347,8 @@ prepare_for_detach (void)
event.ptid = do_target_wait_1 (inf, pid_ptid, &event.ws, 0);
if (debug_infrun)
- print_target_wait_results (pid_ptid, event.ptid, event.ws);
+ print_target_wait_results (pid_ptid, event.ptid, event.ws,
+ event.target);
handle_one (event);
}
@@ -4388,7 +4404,7 @@ wait_for_inferior (inferior *inf)
ecs.target = inf->process_target ();
if (debug_infrun)
- print_target_wait_results (minus_one_ptid, ecs.ptid, ecs.ws);
+ print_target_wait_results (minus_one_ptid, ecs);
/* Now figure out what to do with the result of the result. */
handle_inferior_event (&ecs);
@@ -4669,7 +4685,7 @@ fetch_inferior_event ()
switch_to_target_no_thread (ecs.target);
if (debug_infrun)
- print_target_wait_results (minus_one_ptid, ecs.ptid, ecs.ws);
+ print_target_wait_results (minus_one_ptid, ecs);
/* If an error happens while handling the event, propagate GDB's
knowledge of the executing state to the frontend/user running
@@ -5232,7 +5248,8 @@ poll_one_curr_target (struct target_waitstatus *ws)
event_ptid = target_wait (minus_one_ptid, ws, TARGET_WNOHANG);
if (debug_infrun)
- print_target_wait_results (minus_one_ptid, event_ptid, *ws);
+ print_target_wait_results (minus_one_ptid, event_ptid, *ws,
+ current_inferior ()->process_target ());
return event_ptid;
}
diff --git a/gdb/infrun.h b/gdb/infrun.h
index 2067fd5..b9b64ac 100644
--- a/gdb/infrun.h
+++ b/gdb/infrun.h
@@ -256,7 +256,8 @@ extern void print_stop_event (struct ui_out *uiout, bool displays = true);
/* Pretty print the results of target_wait, for debugging purposes. */
extern void print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
- const struct target_waitstatus &ws);
+ const struct target_waitstatus &ws,
+ process_stratum_target *proc_target);
extern int signal_stop_state (int);
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 141c119..bbffb3d 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -3137,6 +3137,7 @@ VM_DONTDUMP flag (\"dd\" in /proc/PID/smaps) when generating the corefile. For\
more information about this file, refer to the manpage of proc(5) and core(5)."),
NULL, show_dump_excluded_mappings,
&setlist, &showlist);
+
}
/* Fetch (and possibly build) an appropriate `link_map_offsets' for
diff --git a/gdb/maint.h b/gdb/maint.h
index 434d2a9..0ddc62b 100644
--- a/gdb/maint.h
+++ b/gdb/maint.h
@@ -22,6 +22,9 @@
#include "gdbsupport/run-time-clock.h"
#include <chrono>
+struct obj_section;
+struct objfile;
+
extern void set_per_command_time (int);
extern void set_per_command_space (int);
diff --git a/gdb/microblaze-linux-tdep.c b/gdb/microblaze-linux-tdep.c
index 0f2f272..8dcbeaa 100644
--- a/gdb/microblaze-linux-tdep.c
+++ b/gdb/microblaze-linux-tdep.c
@@ -49,6 +49,9 @@ microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
/* Determine appropriate breakpoint contents and size for this address. */
bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
+ /* Make sure we see the memory breakpoints. */
+ scoped_restore restore_memory
+ = make_scoped_restore_show_memory_breakpoints (1);
val = target_read_memory (addr, old_contents, bplen);
/* If our breakpoint is no longer at the address, this means that the
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 649a9f1..9ac3145 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1688,7 +1688,8 @@ find_minsym_type_and_address (minimal_symbol *msymbol,
{
/* Skip translation if caller does not need the address. */
if (address_p != NULL)
- *address_p = target_translate_tls_address (objfile, addr);
+ *address_p = target_translate_tls_address
+ (objfile, addr, bound_msym.minsym->print_name ());
return builtin_type (objfile)->nodebug_tls_symbol;
}
diff --git a/gdb/pager.h b/gdb/pager.h
index 3c4fcdf..052337d 100644
--- a/gdb/pager.h
+++ b/gdb/pager.h
@@ -50,7 +50,6 @@ public:
}
void emit_style_escape (const ui_file_style &style) override;
- void reset_style () override;
void flush () override;
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index 3050a9e..441f317 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -49,6 +49,7 @@
#include "arch-utils.h"
#include "xml-syscall.h"
#include "linux-tdep.h"
+#include "svr4-tls-tdep.h"
#include "linux-record.h"
#include "record-full.h"
#include "infrun.h"
@@ -2071,6 +2072,63 @@ ppc64_linux_gcc_target_options (struct gdbarch *gdbarch)
return "";
}
+/* Fetch and return the TLS DTV (dynamic thread vector) address for PTID.
+ Throw a suitable TLS error if something goes wrong. */
+
+static CORE_ADDR
+ppc64_linux_get_tls_dtv_addr (struct gdbarch *gdbarch, ptid_t ptid,
+ enum svr4_tls_libc libc)
+{
+ /* On ppc64, the thread pointer is found in r13. Fetch this
+ register. */
+ regcache *regcache
+ = get_thread_arch_regcache (current_inferior (), ptid, gdbarch);
+ int thread_pointer_regnum = PPC_R0_REGNUM + 13;
+ target_fetch_registers (regcache, thread_pointer_regnum);
+ ULONGEST thr_ptr;
+ if (regcache->cooked_read (thread_pointer_regnum, &thr_ptr) != REG_VALID)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to fetch thread pointer"));
+
+ /* The thread pointer (r13) is an address that is 0x7000 ahead of
+ the *end* of the TCB (thread control block). The field
+ holding the DTV address is at the very end of the TCB.
+ Therefore, the DTV pointer address can be found by
+ subtracting (0x7000+8) from the thread pointer. Compute the
+ address of the DTV pointer, fetch it, and convert it to an
+ address. */
+ CORE_ADDR dtv_ptr_addr = thr_ptr - 0x7000 - 8;
+ gdb::byte_vector buf (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
+ if (target_read_memory (dtv_ptr_addr, buf.data (), buf.size ()) != 0)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to fetch DTV address"));
+
+ const struct builtin_type *builtin = builtin_type (gdbarch);
+ CORE_ADDR dtv_addr = gdbarch_pointer_to_address
+ (gdbarch, builtin->builtin_data_ptr, buf.data ());
+ return dtv_addr;
+}
+
+/* For internal TLS lookup, return the DTP offset, which is the offset
+ to subtract from a DTV entry, in order to obtain the address of the
+ TLS block. */
+
+static ULONGEST
+ppc_linux_get_tls_dtp_offset (struct gdbarch *gdbarch, ptid_t ptid,
+ svr4_tls_libc libc)
+{
+ if (libc == svr4_tls_libc_musl)
+ {
+ /* This value is DTP_OFFSET, which represents the value to
+ subtract from the DTV entry. For PPC, it can be found in
+ MUSL's arch/powerpc64/pthread_arch.h and
+ arch/powerpc32/pthread_arch.h. (Both values are the same.)
+ It represents the value to subtract from the DTV entry, once
+ it has been fetched from the DTV array. */
+ return 0x8000;
+ }
+ else
+ return 0;
+}
+
static displaced_step_prepare_status
ppc_linux_displaced_step_prepare (gdbarch *arch, thread_info *thread,
CORE_ADDR &displaced_pc)
@@ -2284,6 +2342,11 @@ ppc_linux_init_abi (struct gdbarch_info info,
set_gdbarch_gnu_triplet_regexp (gdbarch, ppc64_gnu_triplet_regexp);
/* Set GCC target options. */
set_gdbarch_gcc_target_options (gdbarch, ppc64_linux_gcc_target_options);
+ /* Internal thread local address support. */
+ set_gdbarch_get_thread_local_address (gdbarch,
+ svr4_tls_get_thread_local_address);
+ svr4_tls_register_tls_methods (info, gdbarch, ppc64_linux_get_tls_dtv_addr,
+ ppc_linux_get_tls_dtp_offset);
}
set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index e8be470..2be5eaa 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2883,7 +2883,7 @@ static void
printf_command (const char *arg, int from_tty)
{
ui_printf (arg, gdb_stdout);
- gdb_stdout->reset_style ();
+ gdb_stdout->emit_style_escape (ui_file_style ());
gdb_stdout->wrap_here (0);
gdb_stdout->flush ();
}
diff --git a/gdb/python/lib/gdb/dap/__init__.py b/gdb/python/lib/gdb/dap/__init__.py
index f908c91..1c3cf8e 100644
--- a/gdb/python/lib/gdb/dap/__init__.py
+++ b/gdb/python/lib/gdb/dap/__init__.py
@@ -96,5 +96,4 @@ def pre_command_loop():
# These are handy for bug reports.
startup.exec_and_log("show version")
startup.exec_and_log("show configuration")
- global server
startup.start_dap(server.main_loop)
diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py
index bfb7bd3..59da120 100644
--- a/gdb/python/lib/gdb/dap/breakpoint.py
+++ b/gdb/python/lib/gdb/dap/breakpoint.py
@@ -51,7 +51,6 @@ def suppress_new_breakpoint_event():
@in_gdb_thread
def _bp_modified(event):
- global _suppress_bp
if not _suppress_bp:
send_event(
"breakpoint",
@@ -64,7 +63,6 @@ def _bp_modified(event):
@in_gdb_thread
def _bp_created(event):
- global _suppress_bp
if not _suppress_bp:
send_event(
"breakpoint",
@@ -77,7 +75,6 @@ def _bp_created(event):
@in_gdb_thread
def _bp_deleted(event):
- global _suppress_bp
if not _suppress_bp:
send_event(
"breakpoint",
@@ -151,7 +148,6 @@ def _remove_entries(table, *names):
# the breakpoint.
@in_gdb_thread
def _set_breakpoints_callback(kind, specs, creator):
- global breakpoint_map
# Try to reuse existing breakpoints if possible.
if kind in breakpoint_map:
saved_map = breakpoint_map[kind]
diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py
index 54caea0..4dc9d65 100644
--- a/gdb/python/lib/gdb/dap/events.py
+++ b/gdb/python/lib/gdb/dap/events.py
@@ -238,7 +238,6 @@ def _on_stop(event):
):
obj["reason"] = "pause"
else:
- global stop_reason_map
obj["reason"] = stop_reason_map[event.details["reason"]]
_expected_pause = False
send_event_maybe_later("stopped", obj)
diff --git a/gdb/python/lib/gdb/dap/frames.py b/gdb/python/lib/gdb/dap/frames.py
index 6433dbe..4dacb87 100644
--- a/gdb/python/lib/gdb/dap/frames.py
+++ b/gdb/python/lib/gdb/dap/frames.py
@@ -53,12 +53,11 @@ gdb.events.cont.connect(_clear_frame_ids)
@in_gdb_thread
def frame_for_id(id):
"""Given a frame identifier ID, return the corresponding frame."""
- global thread_ids
if id in thread_ids:
thread_id = thread_ids[id]
if thread_id != gdb.selected_thread().global_num:
set_thread(thread_id)
- global _all_frames
+
return _all_frames[id]
@@ -103,10 +102,8 @@ def _frame_id_generator():
# Helper function to assign an ID to a frame.
def get_id(frame):
- global _all_frames
num = len(_all_frames)
_all_frames.append(frame)
- global thread_ids
thread_ids[num] = gdb.selected_thread().global_num
return num
@@ -128,7 +125,6 @@ def _frame_id_generator():
@in_gdb_thread
def _get_frame_iterator():
thread_id = gdb.selected_thread().global_num
- global _iter_map
if thread_id not in _iter_map:
_iter_map[thread_id] = _MemoizingIterator(_frame_id_generator())
return _iter_map[thread_id]
diff --git a/gdb/python/lib/gdb/dap/globalvars.py b/gdb/python/lib/gdb/dap/globalvars.py
index 2e4b2a6..9d64d28 100644
--- a/gdb/python/lib/gdb/dap/globalvars.py
+++ b/gdb/python/lib/gdb/dap/globalvars.py
@@ -78,7 +78,6 @@ def get_global_scope(frame):
except RuntimeError:
return None
- global _id_to_scope
block = block.static_block
if block in _id_to_scope:
return _id_to_scope[block]
diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py
index e093e60..8ac4c77 100644
--- a/gdb/python/lib/gdb/dap/launch.py
+++ b/gdb/python/lib/gdb/dap/launch.py
@@ -164,7 +164,6 @@ def attach(
@request("configurationDone", on_dap_thread=True)
def config_done(**args):
# Handle the launch or attach.
- global _launch_or_attach_promise
if _launch_or_attach_promise is None:
raise DAPException("launch or attach not specified")
# Resolve the launch or attach, but only after the
diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/scopes.py
index f499dcb..7ce3a7f 100644
--- a/gdb/python/lib/gdb/dap/scopes.py
+++ b/gdb/python/lib/gdb/dap/scopes.py
@@ -120,7 +120,6 @@ class _FinishScopeReference(_ScopeReference):
def fetch_one_child(self, idx):
assert idx == 0
- global _last_return_value
return ("(return)", _last_return_value)
@@ -145,8 +144,6 @@ class _RegisterReference(_ScopeReference):
@request("scopes")
def scopes(*, frameId: int, **extra):
- global _last_return_value
- global frame_to_scope
if frameId in frame_to_scope:
scopes = frame_to_scope[frameId]
else:
diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py
index d4314e8..c4fa781 100644
--- a/gdb/python/lib/gdb/dap/server.py
+++ b/gdb/python/lib/gdb/dap/server.py
@@ -307,7 +307,6 @@ class Server:
args = {}
def fn():
- global _commands
return _commands[params["command"]](**args)
self.invoke_request(req, result, fn)
@@ -440,7 +439,6 @@ def send_event(event, body=None):
"""Send an event to the DAP client.
EVENT is the name of the event, a string.
BODY is the body of the event, an arbitrary object."""
- global _server
_server.send_event(event, body)
@@ -449,13 +447,11 @@ def send_event_maybe_later(event, body=None):
within the dap thread and that request is configured to delay the event,
wait until the response has been sent until the event is sent back to
the client."""
- global _server
_server.send_event_maybe_later(event, body)
def call_function_later(fn):
"""Call FN later -- after the current request's response has been sent."""
- global _server
_server.call_function_later(fn)
@@ -533,7 +529,6 @@ def request(
if response:
if defer_stop_events:
- global _server
if _server is not None:
with _server.delayed_events_lock:
_server.defer_stop_events = True
@@ -555,7 +550,6 @@ def request(
if expect_stopped:
cmd = _check_not_running(cmd)
- global _commands
assert name not in _commands
_commands[name] = cmd
return cmd
@@ -568,7 +562,6 @@ def capability(name, value=True):
the DAP capability NAME."""
def wrap(func):
- global _capabilities
assert name not in _capabilities
_capabilities[name] = value
return func
@@ -581,7 +574,6 @@ def client_bool_capability(name, default=False):
If the capability was not specified, or did not have boolean type,
DEFAULT is returned. DEFAULT defaults to False."""
- global _server
if name in _server.config and isinstance(_server.config[name], bool):
return _server.config[name]
return default
@@ -589,7 +581,6 @@ def client_bool_capability(name, default=False):
@request("initialize", on_dap_thread=True)
def initialize(**args):
- global _server, _capabilities
_server.config = args
_server.send_event_later("initialized")
global _lines_start_at_1
@@ -705,7 +696,6 @@ def export_line(line: int) -> int:
"""Rewrite LINE according to client capability.
This applies the linesStartAt1 capability as needed,
when sending a line number from gdb to the client."""
- global _lines_start_at_1
if not _lines_start_at_1:
# In gdb, lines start at 1, so we only need to change this if
# the client starts at 0.
@@ -717,7 +707,6 @@ def import_line(line: int) -> int:
"""Rewrite LINE according to client capability.
This applies the linesStartAt1 capability as needed,
when the client sends a line number to gdb."""
- global _lines_start_at_1
if not _lines_start_at_1:
# In gdb, lines start at 1, so we only need to change this if
# the client starts at 0.
diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py
index 938c93a..625c01f 100644
--- a/gdb/python/lib/gdb/dap/sources.py
+++ b/gdb/python/lib/gdb/dap/sources.py
@@ -37,7 +37,6 @@ def make_source(fullname, filename=None):
FILENAME is the base name; if None (the default), then it is
computed from FULLNAME.
"""
- global _source_map
if fullname in _source_map:
result = _source_map[fullname]
else:
@@ -53,7 +52,6 @@ def make_source(fullname, filename=None):
global _next_source
result["sourceReference"] = _next_source
- global _id_map
_id_map[_next_source] = result
_next_source += 1
@@ -71,7 +69,6 @@ def decode_source(source):
if "sourceReference" not in source:
raise DAPException("either 'path' or 'sourceReference' must appear in Source")
ref = source["sourceReference"]
- global _id_map
if ref not in _id_map:
raise DAPException("no sourceReference " + str(ref))
return _id_map[ref]["path"]
diff --git a/gdb/python/lib/gdb/dap/varref.py b/gdb/python/lib/gdb/dap/varref.py
index 42b5302..8a13c51 100644
--- a/gdb/python/lib/gdb/dap/varref.py
+++ b/gdb/python/lib/gdb/dap/varref.py
@@ -69,7 +69,6 @@ class BaseReference(ABC):
NAME is a string or None. None means this does not have a
name, e.g., the result of expression evaluation."""
- global all_variables
all_variables.append(self)
self._ref = len(all_variables)
self._name = name
@@ -267,7 +266,7 @@ class VariableReference(BaseReference):
@in_gdb_thread
def find_variable(ref):
"""Given a variable reference, return the corresponding variable object."""
- global all_variables
+
# Variable references are offset by 1.
ref = ref - 1
if ref < 0 or ref > len(all_variables):
diff --git a/gdb/python/lib/gdb/styling.py b/gdb/python/lib/gdb/styling.py
index e9387e3..60c470f 100644
--- a/gdb/python/lib/gdb/styling.py
+++ b/gdb/python/lib/gdb/styling.py
@@ -80,7 +80,6 @@ try:
# ignore.
pass
- global _asm_lexers
if lexer_type not in _asm_lexers:
_asm_lexers[lexer_type] = lexers.get_lexer_by_name(lexer_type)
_asm_lexers[lexer_type].add_filter(HandleNasmComments())
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 861e9a3..58998f5 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -948,7 +948,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
else
{
PyErr_SetString (PyExc_RuntimeError,
- _("Line keyword should be an integer or a string. "));
+ _("Line keyword should be an integer or a string."));
return -1;
}
}
diff --git a/gdb/python/py-color.c b/gdb/python/py-color.c
index 91ad7ae..e208506 100644
--- a/gdb/python/py-color.c
+++ b/gdb/python/py-color.c
@@ -64,7 +64,8 @@ create_color_object (const ui_file_style::color &color)
bool
gdbpy_is_color (PyObject *obj)
{
- return PyObject_IsInstance (obj, (PyObject *) &colorpy_object_type);
+ gdb_assert (obj != nullptr);
+ return PyObject_TypeCheck (obj, &colorpy_object_type) != 0;
}
/* See py-color.h. */
@@ -80,33 +81,33 @@ gdbpy_get_color (PyObject *obj)
static PyObject *
get_attr (PyObject *obj, PyObject *attr_name)
{
- if (! PyUnicode_Check (attr_name))
+ if (!PyUnicode_Check (attr_name))
return PyObject_GenericGetAttr (obj, attr_name);
colorpy_object *self = (colorpy_object *) obj;
const ui_file_style::color &color = self->color;
- if (! PyUnicode_CompareWithASCIIString (attr_name, "colorspace"))
+ if (!PyUnicode_CompareWithASCIIString (attr_name, "colorspace"))
{
int value = static_cast<int> (color.colorspace ());
return gdb_py_object_from_longest (value).release ();
}
- if (! PyUnicode_CompareWithASCIIString (attr_name, "is_none"))
+ if (!PyUnicode_CompareWithASCIIString (attr_name, "is_none"))
return PyBool_FromLong (color.is_none ());
- if (! PyUnicode_CompareWithASCIIString (attr_name, "is_indexed"))
+ if (!PyUnicode_CompareWithASCIIString (attr_name, "is_indexed"))
return PyBool_FromLong (color.is_indexed ());
- if (! PyUnicode_CompareWithASCIIString (attr_name, "is_direct"))
+ if (!PyUnicode_CompareWithASCIIString (attr_name, "is_direct"))
return PyBool_FromLong (color.is_direct ());
if (color.is_indexed ()
- && ! PyUnicode_CompareWithASCIIString (attr_name, "index"))
+ && !PyUnicode_CompareWithASCIIString (attr_name, "index"))
return gdb_py_object_from_longest (color.get_value ()).release ();
if (color.is_direct ()
- && ! PyUnicode_CompareWithASCIIString (attr_name, "components"))
+ && !PyUnicode_CompareWithASCIIString (attr_name, "components"))
{
uint8_t rgb[3];
color.get_rgb (rgb);
@@ -135,21 +136,21 @@ get_attr (PyObject *obj, PyObject *attr_name)
/* Implementation of Color.escape_sequence (self, is_fg) -> str. */
static PyObject *
-colorpy_escape_sequence (PyObject *self, PyObject *is_fg_obj)
+colorpy_escape_sequence (PyObject *self, PyObject *args, PyObject *kwargs)
{
- if (!gdbpy_is_color (self))
- {
- PyErr_SetString (PyExc_RuntimeError,
- _("Object is not gdb.Color."));
- return nullptr;
- }
+ static const char *keywords[] = { "is_foreground", nullptr };
+ PyObject *is_fg_obj;
- if (! PyBool_Check (is_fg_obj))
- {
- PyErr_SetString (PyExc_RuntimeError,
- _("A boolean argument is required."));
- return nullptr;
- }
+ /* Parse method arguments. */
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "O!", keywords,
+ &PyBool_Type, &is_fg_obj))
+ return nullptr;
+
+ /* Python ensures the type of SELF. */
+ gdb_assert (gdbpy_is_color (self));
+
+ /* The argument parsing ensures we have a bool. */
+ gdb_assert (PyBool_Check (is_fg_obj));
bool is_fg = is_fg_obj == Py_True;
std::string s = gdbpy_get_color (self).to_ansi (is_fg);
@@ -175,17 +176,20 @@ colorpy_init (PyObject *self, PyObject *args, PyObject *kwds)
PyObject *colorspace_obj = nullptr;
color_space colorspace = color_space::MONOCHROME;
- if (! PyArg_ParseTuple (args, "|OO", &value_obj, &colorspace_obj))
+ static const char *keywords[] = { "value", "color_space", nullptr };
+
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kwds, "|OO", keywords,
+ &value_obj, &colorspace_obj))
return -1;
try
{
- if (colorspace_obj)
+ if (colorspace_obj != nullptr)
{
if (PyLong_Check (colorspace_obj))
{
long colorspace_id = -1;
- if (! gdb_py_int_as_long (colorspace_obj, &colorspace_id))
+ if (!gdb_py_int_as_long (colorspace_obj, &colorspace_id))
return -1;
if (!color_space_safe_cast (&colorspace, colorspace_id))
error (_("colorspace %ld is out of range."), colorspace_id);
@@ -201,11 +205,11 @@ colorpy_init (PyObject *self, PyObject *args, PyObject *kwds)
else if (PyLong_Check (value_obj))
{
long value = -1;
- if (! gdb_py_int_as_long (value_obj, &value))
+ if (!gdb_py_int_as_long (value_obj, &value))
return -1;
if (value < 0 || value > INT_MAX)
error (_("value %ld is out of range."), value);
- if (colorspace_obj)
+ if (colorspace_obj != nullptr)
obj->color = ui_file_style::color (colorspace, value);
else
obj->color = ui_file_style::color (value);
@@ -256,7 +260,6 @@ colorpy_init (PyObject *self, PyObject *args, PyObject *kwds)
return gdbpy_handle_gdb_exception (-1, except);
}
- Py_INCREF (self);
return 0;
}
@@ -272,10 +275,10 @@ colorpy_str (PyObject *self)
static int
gdbpy_initialize_color (void)
{
- for (auto & pair : colorspace_constants)
- if (PyModule_AddIntConstant (gdb_module, pair.name,
- static_cast<long> (pair.value)) < 0)
- return -1;
+ for (auto &pair : colorspace_constants)
+ if (PyModule_AddIntConstant (gdb_module, pair.name,
+ static_cast<long> (pair.value)) < 0)
+ return -1;
colorpy_object_type.tp_new = PyType_GenericNew;
return gdbpy_type_ready (&colorpy_object_type, gdb_module);
@@ -285,7 +288,8 @@ gdbpy_initialize_color (void)
static PyMethodDef color_methods[] =
{
- { "escape_sequence", colorpy_escape_sequence, METH_O,
+ { "escape_sequence", (PyCFunction) colorpy_escape_sequence,
+ METH_VARARGS | METH_KEYWORDS,
"escape_sequence (is_foreground) -> str.\n\
Return the ANSI escape sequence for this color.\n\
IS_FOREGROUND indicates whether this is a foreground or background color."},
@@ -313,7 +317,7 @@ PyTypeObject colorpy_object_type =
get_attr, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ Py_TPFLAGS_DEFAULT, /*tp_flags*/
"GDB color object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c
index 9ca8d22..17064dc 100644
--- a/gdb/python/py-disasm.c
+++ b/gdb/python/py-disasm.c
@@ -1311,12 +1311,13 @@ gdbpy_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr,
return {};
}
- /* Check the result is a DisassemblerResult (or a sub-class). */
- if (!PyObject_IsInstance (result.get (),
- (PyObject *) &disasm_result_object_type))
+ /* Check the result is a DisassemblerResult. */
+ if (!PyObject_TypeCheck (result.get (), &disasm_result_object_type))
{
- PyErr_SetString (PyExc_TypeError,
- _("Result is not a DisassemblerResult."));
+ PyErr_Format
+ (PyExc_TypeError,
+ _("Result from Disassembler must be gdb.DisassemblerResult, not %s."),
+ Py_TYPE (result.get ())->tp_name);
gdbpy_print_stack ();
return std::optional<int> (-1);
}
diff --git a/gdb/python/py-registers.c b/gdb/python/py-registers.c
index 78a806c..9be2e3c 100644
--- a/gdb/python/py-registers.c
+++ b/gdb/python/py-registers.c
@@ -403,8 +403,7 @@ gdbpy_parse_register_id (struct gdbarch *gdbarch, PyObject *pyo_reg_id,
PyErr_SetString (PyExc_ValueError, "Bad register");
}
/* The register could be a gdb.RegisterDescriptor object. */
- else if (PyObject_IsInstance (pyo_reg_id,
- (PyObject *) &register_descriptor_object_type))
+ else if (PyObject_TypeCheck (pyo_reg_id, &register_descriptor_object_type))
{
register_descriptor_object *reg
= (register_descriptor_object *) pyo_reg_id;
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index ab34971..d43d7e9 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -929,9 +929,9 @@ frame_unwind_python::sniff (const frame_info_ptr &this_frame,
/* Received UnwindInfo, cache data. */
PyObject *pyo_unwind_info = PyTuple_GET_ITEM (pyo_execute_ret.get (), 0);
- if (PyObject_IsInstance (pyo_unwind_info,
- (PyObject *) &unwind_info_object_type) <= 0)
- error (_("A Unwinder should return gdb.UnwindInfo instance."));
+ if (!PyObject_TypeCheck (pyo_unwind_info, &unwind_info_object_type))
+ error (_("an Unwinder should return gdb.UnwindInfo, not %s."),
+ Py_TYPE (pyo_unwind_info)->tp_name);
{
unwind_info_object *unwind_info =
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 3855bde..8a2e263 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1096,8 +1096,7 @@ valpy_getitem (PyObject *self, PyObject *key)
res_val = value_struct_elt (&tmp, {}, field.get (), NULL,
"struct/class/union");
else if (bitpos >= 0)
- res_val = value_struct_elt_bitpos (&tmp, bitpos, field_type,
- "struct/class/union");
+ res_val = value_struct_elt_bitpos (tmp, bitpos, field_type);
else if (base_class_type != NULL)
{
struct type *val_type;
diff --git a/gdb/remote.c b/gdb/remote.c
index 7dc057c..73dc426 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -80,6 +80,7 @@
#include "async-event.h"
#include "gdbsupport/selftest.h"
#include "cli/cli-style.h"
+#include "gdbsupport/remote-args.h"
/* The remote target. */
@@ -4943,7 +4944,7 @@ remote_target::process_initial_stop_replies (int from_tty)
event_ptid = target_wait (waiton_ptid, &ws, TARGET_WNOHANG);
if (remote_debug)
- print_target_wait_results (waiton_ptid, event_ptid, ws);
+ print_target_wait_results (waiton_ptid, event_ptid, ws, this);
switch (ws.kind ())
{
@@ -10835,16 +10836,15 @@ remote_target::extended_remote_run (const std::string &args)
if (!args.empty ())
{
- int i;
+ std::vector<std::string> split_args = gdb::remote_args::split (args);
- gdb_argv argv (args.c_str ());
- for (i = 0; argv[i] != NULL; i++)
+ for (const auto &a : split_args)
{
- if (strlen (argv[i]) * 2 + 1 + len >= get_remote_packet_size ())
+ if (a.size () * 2 + 1 + len >= get_remote_packet_size ())
error (_("Argument list too long for run packet"));
rs->buf[len++] = ';';
- len += 2 * bin2hex ((gdb_byte *) argv[i], rs->buf.data () + len,
- strlen (argv[i]));
+ len += 2 * bin2hex ((gdb_byte *) a.c_str (), rs->buf.data () + len,
+ a.size ());
}
}
diff --git a/gdb/riscv-canonicalize-syscall-gen.c b/gdb/riscv-canonicalize-syscall-gen.c
new file mode 100644
index 0000000..67e5410
--- /dev/null
+++ b/gdb/riscv-canonicalize-syscall-gen.c
@@ -0,0 +1,358 @@
+/* DO NOT EDIT: Autogenerated by riscv-canonicalize-syscall-gen.py
+
+ Copyright (C) 2024-2025 Free Software Foundation, Inc.
+
+ 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/>. */
+
+#include "defs.h"
+#include "riscv-linux-tdep.h"
+
+/* riscv64_canonicalize_syscall maps from the native riscv 64 Linux set
+ of syscall ids into a canonical set of syscall ids used by
+ process record. */
+
+enum gdb_syscall
+riscv64_canonicalize_syscall (int syscall)
+{
+ switch (syscall)
+ {
+ case 0: return gdb_sys_io_setup;
+ case 1: return gdb_sys_io_destroy;
+ case 2: return gdb_sys_io_submit;
+ case 3: return gdb_sys_io_cancel;
+ case 4: return gdb_sys_io_getevents;
+ case 5: return gdb_sys_setxattr;
+ case 6: return gdb_sys_lsetxattr;
+ case 7: return gdb_sys_fsetxattr;
+ case 8: return gdb_sys_getxattr;
+ case 9: return gdb_sys_lgetxattr;
+ case 10: return gdb_sys_fgetxattr;
+ case 11: return gdb_sys_listxattr;
+ case 12: return gdb_sys_llistxattr;
+ case 13: return gdb_sys_flistxattr;
+ case 14: return gdb_sys_removexattr;
+ case 15: return gdb_sys_lremovexattr;
+ case 16: return gdb_sys_fremovexattr;
+ case 17: return gdb_sys_getcwd;
+ case 18: return gdb_sys_lookup_dcookie;
+ case 19: return gdb_sys_eventfd2;
+ case 20: return gdb_sys_epoll_create1;
+ case 21: return gdb_sys_epoll_ctl;
+ case 22: return gdb_sys_epoll_pwait;
+ case 23: return gdb_sys_dup;
+ case 24: return gdb_sys_dup3;
+ case 25: return gdb_sys_fcntl;
+ case 26: return gdb_sys_inotify_init1;
+ case 27: return gdb_sys_inotify_add_watch;
+ case 28: return gdb_sys_inotify_rm_watch;
+ case 29: return gdb_sys_ioctl;
+ case 30: return gdb_sys_ioprio_set;
+ case 31: return gdb_sys_ioprio_get;
+ case 32: return gdb_sys_flock;
+ case 33: return gdb_sys_mknodat;
+ case 34: return gdb_sys_mkdirat;
+ case 35: return gdb_sys_unlinkat;
+ case 36: return gdb_sys_symlinkat;
+ case 37: return gdb_sys_linkat;
+ /* case 39: return gdb_sys_umount2; */
+ case 40: return gdb_sys_mount;
+ case 41: return gdb_sys_pivot_root;
+ case 42: return gdb_sys_nfsservctl;
+ case 43: return gdb_sys_statfs;
+ case 44: return gdb_sys_fstatfs;
+ case 45: return gdb_sys_truncate;
+ case 46: return gdb_sys_ftruncate;
+ case 47: return gdb_sys_fallocate;
+ case 48: return gdb_sys_faccessat;
+ case 49: return gdb_sys_chdir;
+ case 50: return gdb_sys_fchdir;
+ case 51: return gdb_sys_chroot;
+ case 52: return gdb_sys_fchmod;
+ case 53: return gdb_sys_fchmodat;
+ case 54: return gdb_sys_fchownat;
+ case 55: return gdb_sys_fchown;
+ case 56: return gdb_sys_openat;
+ case 57: return gdb_sys_close;
+ case 58: return gdb_sys_vhangup;
+ case 59: return gdb_sys_pipe2;
+ case 60: return gdb_sys_quotactl;
+ case 61: return gdb_sys_getdents64;
+ case 62: return gdb_sys_lseek;
+ case 63: return gdb_sys_read;
+ case 64: return gdb_sys_write;
+ case 65: return gdb_sys_readv;
+ case 66: return gdb_sys_writev;
+ case 67: return gdb_sys_pread64;
+ case 68: return gdb_sys_pwrite64;
+ /* case 69: return gdb_sys_preadv; */
+ /* case 70: return gdb_sys_pwritev; */
+ case 71: return gdb_sys_sendfile;
+ case 72: return gdb_sys_pselect6;
+ case 73: return gdb_sys_ppoll;
+ /* case 74: return gdb_sys_signalfd4; */
+ case 75: return gdb_sys_vmsplice;
+ case 76: return gdb_sys_splice;
+ case 77: return gdb_sys_tee;
+ case 78: return gdb_sys_readlinkat;
+ case 79: return gdb_sys_newfstatat;
+ case 80: return gdb_sys_fstat;
+ case 81: return gdb_sys_sync;
+ case 82: return gdb_sys_fsync;
+ case 83: return gdb_sys_fdatasync;
+ case 84: return gdb_sys_sync_file_range;
+ /* case 85: return gdb_sys_timerfd_create; */
+ /* case 86: return gdb_sys_timerfd_settime; */
+ /* case 87: return gdb_sys_timerfd_gettime; */
+ /* case 88: return gdb_sys_utimensat; */
+ case 89: return gdb_sys_acct;
+ case 90: return gdb_sys_capget;
+ case 91: return gdb_sys_capset;
+ case 92: return gdb_sys_personality;
+ case 93: return gdb_sys_exit;
+ case 94: return gdb_sys_exit_group;
+ case 95: return gdb_sys_waitid;
+ case 96: return gdb_sys_set_tid_address;
+ case 97: return gdb_sys_unshare;
+ case 98: return gdb_sys_futex;
+ case 99: return gdb_sys_set_robust_list;
+ case 100: return gdb_sys_get_robust_list;
+ case 101: return gdb_sys_nanosleep;
+ case 102: return gdb_sys_getitimer;
+ case 103: return gdb_sys_setitimer;
+ case 104: return gdb_sys_kexec_load;
+ case 105: return gdb_sys_init_module;
+ case 106: return gdb_sys_delete_module;
+ case 107: return gdb_sys_timer_create;
+ case 108: return gdb_sys_timer_gettime;
+ case 109: return gdb_sys_timer_getoverrun;
+ case 110: return gdb_sys_timer_settime;
+ case 111: return gdb_sys_timer_delete;
+ case 112: return gdb_sys_clock_settime;
+ case 113: return gdb_sys_clock_gettime;
+ case 114: return gdb_sys_clock_getres;
+ case 115: return gdb_sys_clock_nanosleep;
+ case 116: return gdb_sys_syslog;
+ case 117: return gdb_sys_ptrace;
+ case 118: return gdb_sys_sched_setparam;
+ case 119: return gdb_sys_sched_setscheduler;
+ case 120: return gdb_sys_sched_getscheduler;
+ case 121: return gdb_sys_sched_getparam;
+ case 122: return gdb_sys_sched_setaffinity;
+ case 123: return gdb_sys_sched_getaffinity;
+ case 124: return gdb_sys_sched_yield;
+ case 125: return gdb_sys_sched_get_priority_max;
+ case 126: return gdb_sys_sched_get_priority_min;
+ case 127: return gdb_sys_sched_rr_get_interval;
+ case 128: return gdb_sys_restart_syscall;
+ case 129: return gdb_sys_kill;
+ case 130: return gdb_sys_tkill;
+ case 131: return gdb_sys_tgkill;
+ case 132: return gdb_sys_sigaltstack;
+ case 133: return gdb_sys_rt_sigsuspend;
+ case 134: return gdb_sys_rt_sigaction;
+ case 135: return gdb_sys_rt_sigprocmask;
+ case 136: return gdb_sys_rt_sigpending;
+ case 137: return gdb_sys_rt_sigtimedwait;
+ case 138: return gdb_sys_rt_sigqueueinfo;
+ case 139: return gdb_sys_rt_sigreturn;
+ case 140: return gdb_sys_setpriority;
+ case 141: return gdb_sys_getpriority;
+ case 142: return gdb_sys_reboot;
+ case 143: return gdb_sys_setregid;
+ case 144: return gdb_sys_setgid;
+ case 145: return gdb_sys_setreuid;
+ case 146: return gdb_sys_setuid;
+ case 147: return gdb_sys_setresuid;
+ case 148: return gdb_sys_getresuid;
+ case 149: return gdb_sys_setresgid;
+ case 150: return gdb_sys_getresgid;
+ case 151: return gdb_sys_setfsuid;
+ case 152: return gdb_sys_setfsgid;
+ case 153: return gdb_sys_times;
+ case 154: return gdb_sys_setpgid;
+ case 155: return gdb_sys_getpgid;
+ case 156: return gdb_sys_getsid;
+ case 157: return gdb_sys_setsid;
+ case 158: return gdb_sys_getgroups;
+ case 159: return gdb_sys_setgroups;
+ case 160: return gdb_sys_uname;
+ case 161: return gdb_sys_sethostname;
+ case 162: return gdb_sys_setdomainname;
+ case 163: return gdb_sys_getrlimit;
+ case 164: return gdb_sys_setrlimit;
+ case 165: return gdb_sys_getrusage;
+ case 166: return gdb_sys_umask;
+ case 167: return gdb_sys_prctl;
+ case 168: return gdb_sys_getcpu;
+ case 169: return gdb_sys_gettimeofday;
+ case 170: return gdb_sys_settimeofday;
+ case 171: return gdb_sys_adjtimex;
+ case 172: return gdb_sys_getpid;
+ case 173: return gdb_sys_getppid;
+ case 174: return gdb_sys_getuid;
+ case 175: return gdb_sys_geteuid;
+ case 176: return gdb_sys_getgid;
+ case 177: return gdb_sys_getegid;
+ case 178: return gdb_sys_gettid;
+ case 179: return gdb_sys_sysinfo;
+ case 180: return gdb_sys_mq_open;
+ case 181: return gdb_sys_mq_unlink;
+ case 182: return gdb_sys_mq_timedsend;
+ case 183: return gdb_sys_mq_timedreceive;
+ case 184: return gdb_sys_mq_notify;
+ case 185: return gdb_sys_mq_getsetattr;
+ case 186: return gdb_sys_msgget;
+ case 187: return gdb_sys_msgctl;
+ case 188: return gdb_sys_msgrcv;
+ case 189: return gdb_sys_msgsnd;
+ case 190: return gdb_sys_semget;
+ case 191: return gdb_sys_semctl;
+ case 192: return gdb_sys_semtimedop;
+ case 193: return gdb_sys_semop;
+ case 194: return gdb_sys_shmget;
+ case 195: return gdb_sys_shmctl;
+ case 196: return gdb_sys_shmat;
+ case 197: return gdb_sys_shmdt;
+ case 198: return gdb_sys_socket;
+ case 199: return gdb_sys_socketpair;
+ case 200: return gdb_sys_bind;
+ case 201: return gdb_sys_listen;
+ case 202: return gdb_sys_accept;
+ case 203: return gdb_sys_connect;
+ case 204: return gdb_sys_getsockname;
+ case 205: return gdb_sys_getpeername;
+ case 206: return gdb_sys_sendto;
+ case 207: return gdb_sys_recvfrom;
+ case 208: return gdb_sys_setsockopt;
+ case 209: return gdb_sys_getsockopt;
+ case 210: return gdb_sys_shutdown;
+ case 211: return gdb_sys_sendmsg;
+ case 212: return gdb_sys_recvmsg;
+ case 213: return gdb_sys_readahead;
+ case 214: return gdb_sys_brk;
+ case 215: return gdb_sys_munmap;
+ case 216: return gdb_sys_mremap;
+ case 217: return gdb_sys_add_key;
+ case 218: return gdb_sys_request_key;
+ case 219: return gdb_sys_keyctl;
+ case 220: return gdb_sys_clone;
+ case 221: return gdb_sys_execve;
+ case 222: return gdb_sys_old_mmap;
+ case 223: return gdb_sys_fadvise64;
+ case 224: return gdb_sys_swapon;
+ case 225: return gdb_sys_swapoff;
+ case 226: return gdb_sys_mprotect;
+ case 227: return gdb_sys_msync;
+ case 228: return gdb_sys_mlock;
+ case 229: return gdb_sys_munlock;
+ case 230: return gdb_sys_mlockall;
+ case 231: return gdb_sys_munlockall;
+ case 232: return gdb_sys_mincore;
+ case 233: return gdb_sys_madvise;
+ case 234: return gdb_sys_remap_file_pages;
+ case 235: return gdb_sys_mbind;
+ case 236: return gdb_sys_get_mempolicy;
+ case 237: return gdb_sys_set_mempolicy;
+ case 238: return gdb_sys_migrate_pages;
+ case 239: return gdb_sys_move_pages;
+ /* case 240: return gdb_sys_rt_tgsigqueueinfo; */
+ /* case 241: return gdb_sys_perf_event_open; */
+ case 242: return gdb_sys_accept4;
+ /* case 243: return gdb_sys_recvmmsg; */
+ /* case 258: return gdb_sys_riscv_hwprobe; */
+ /* case 259: return gdb_sys_riscv_flush_icache; */
+ case 260: return gdb_sys_wait4;
+ /* case 261: return gdb_sys_prlimit64; */
+ /* case 262: return gdb_sys_fanotify_init; */
+ /* case 263: return gdb_sys_fanotify_mark; */
+ /* case 264: return gdb_sys_name_to_handle_at; */
+ /* case 265: return gdb_sys_open_by_handle_at; */
+ /* case 266: return gdb_sys_clock_adjtime; */
+ /* case 267: return gdb_sys_syncfs; */
+ /* case 268: return gdb_sys_setns; */
+ /* case 269: return gdb_sys_sendmmsg; */
+ /* case 270: return gdb_sys_process_vm_readv; */
+ /* case 271: return gdb_sys_process_vm_writev; */
+ /* case 272: return gdb_sys_kcmp; */
+ /* case 273: return gdb_sys_finit_module; */
+ /* case 274: return gdb_sys_sched_setattr; */
+ /* case 275: return gdb_sys_sched_getattr; */
+ /* case 276: return gdb_sys_renameat2; */
+ /* case 277: return gdb_sys_seccomp; */
+ case 278: return gdb_sys_getrandom;
+ /* case 279: return gdb_sys_memfd_create; */
+ /* case 280: return gdb_sys_bpf; */
+ /* case 281: return gdb_sys_execveat; */
+ /* case 282: return gdb_sys_userfaultfd; */
+ /* case 283: return gdb_sys_membarrier; */
+ /* case 284: return gdb_sys_mlock2; */
+ /* case 285: return gdb_sys_copy_file_range; */
+ /* case 286: return gdb_sys_preadv2; */
+ /* case 287: return gdb_sys_pwritev2; */
+ /* case 288: return gdb_sys_pkey_mprotect; */
+ /* case 289: return gdb_sys_pkey_alloc; */
+ /* case 290: return gdb_sys_pkey_free; */
+ case 291: return gdb_sys_statx;
+ /* case 292: return gdb_sys_io_pgetevents; */
+ /* case 293: return gdb_sys_rseq; */
+ /* case 294: return gdb_sys_kexec_file_load; */
+ /* case 424: return gdb_sys_pidfd_send_signal; */
+ /* case 425: return gdb_sys_io_uring_setup; */
+ /* case 426: return gdb_sys_io_uring_enter; */
+ /* case 427: return gdb_sys_io_uring_register; */
+ /* case 428: return gdb_sys_open_tree; */
+ /* case 429: return gdb_sys_move_mount; */
+ /* case 430: return gdb_sys_fsopen; */
+ /* case 431: return gdb_sys_fsconfig; */
+ /* case 432: return gdb_sys_fsmount; */
+ /* case 433: return gdb_sys_fspick; */
+ /* case 434: return gdb_sys_pidfd_open; */
+ /* case 435: return gdb_sys_clone3; */
+ /* case 436: return gdb_sys_close_range; */
+ /* case 437: return gdb_sys_openat2; */
+ /* case 438: return gdb_sys_pidfd_getfd; */
+ /* case 439: return gdb_sys_faccessat2; */
+ /* case 440: return gdb_sys_process_madvise; */
+ /* case 441: return gdb_sys_epoll_pwait2; */
+ /* case 442: return gdb_sys_mount_setattr; */
+ /* case 443: return gdb_sys_quotactl_fd; */
+ /* case 444: return gdb_sys_landlock_create_ruleset; */
+ /* case 445: return gdb_sys_landlock_add_rule; */
+ /* case 446: return gdb_sys_landlock_restrict_self; */
+ /* case 447: return gdb_sys_memfd_secret; */
+ /* case 448: return gdb_sys_process_mrelease; */
+ /* case 449: return gdb_sys_futex_waitv; */
+ /* case 450: return gdb_sys_set_mempolicy_home_node; */
+ /* case 451: return gdb_sys_cachestat; */
+ /* case 452: return gdb_sys_fchmodat2; */
+ /* case 453: return gdb_sys_map_shadow_stack; */
+ /* case 454: return gdb_sys_futex_wake; */
+ /* case 455: return gdb_sys_futex_wait; */
+ /* case 456: return gdb_sys_futex_requeue; */
+ /* case 457: return gdb_sys_statmount; */
+ /* case 458: return gdb_sys_listmount; */
+ /* case 459: return gdb_sys_lsm_get_self_attr; */
+ /* case 460: return gdb_sys_lsm_set_self_attr; */
+ /* case 461: return gdb_sys_lsm_list_modules; */
+ /* case 462: return gdb_sys_mseal; */
+ /* case 463: return gdb_sys_setxattrat; */
+ /* case 464: return gdb_sys_getxattrat; */
+ /* case 465: return gdb_sys_listxattrat; */
+ /* case 466: return gdb_sys_removexattrat; */
+ default:
+ return gdb_sys_no_syscall;
+ }
+}
diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c
index 4c0c65c..e1ea615 100644
--- a/gdb/riscv-linux-tdep.c
+++ b/gdb/riscv-linux-tdep.c
@@ -20,11 +20,18 @@
#include "osabi.h"
#include "glibc-tdep.h"
#include "linux-tdep.h"
+#include "svr4-tls-tdep.h"
#include "solib-svr4.h"
#include "regset.h"
#include "tramp-frame.h"
#include "trad-frame.h"
#include "gdbarch.h"
+#include "record-full.h"
+#include "linux-record.h"
+#include "riscv-linux-tdep.h"
+#include "inferior.h"
+
+extern unsigned int record_debug;
/* The following value is derived from __NR_rt_sigreturn in
<include/uapi/asm-generic/unistd.h> from the Linux source tree. */
@@ -173,6 +180,327 @@ riscv_linux_syscall_next_pc (const frame_info_ptr &frame)
return pc + 4 /* Length of the ECALL insn. */;
}
+/* RISC-V process record-replay constructs: syscall, signal etc. */
+
+static linux_record_tdep riscv_linux_record_tdep;
+
+using regnum_type = int;
+
+/* Record registers from first to last for process-record. */
+
+static bool
+save_registers (struct regcache *regcache, regnum_type first, regnum_type last)
+{
+ gdb_assert (regcache != nullptr);
+
+ for (regnum_type i = first; i != last; ++i)
+ if (record_full_arch_list_add_reg (regcache, i))
+ return false;
+ return true;
+};
+
+/* Record all registers but PC register for process-record. */
+
+static bool
+riscv_all_but_pc_registers_record (struct regcache *regcache)
+{
+ gdb_assert (regcache != nullptr);
+
+ struct gdbarch *gdbarch = regcache->arch ();
+ riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+ const struct riscv_gdbarch_features &features = tdep->isa_features;
+
+ if (!save_registers (regcache, RISCV_ZERO_REGNUM + 1, RISCV_PC_REGNUM))
+ return false;
+
+ if (features.flen
+ && !save_registers (regcache, RISCV_FIRST_FP_REGNUM,
+ RISCV_LAST_FP_REGNUM + 1))
+ return false;
+
+ return true;
+}
+
+/* Handler for riscv system call instruction recording. */
+
+static int
+riscv_linux_syscall_record (struct regcache *regcache,
+ unsigned long svc_number)
+{
+ gdb_assert (regcache != nullptr);
+
+ enum gdb_syscall syscall_gdb = riscv64_canonicalize_syscall (svc_number);
+
+ if (record_debug > 1)
+ gdb_printf (gdb_stdlog, "Made syscall %s.\n", plongest (svc_number));
+
+ if (syscall_gdb == gdb_sys_no_syscall)
+ {
+ warning (_("Process record and replay target doesn't "
+ "support syscall number %s\n"), plongest (svc_number));
+ return -1;
+ }
+
+ if (syscall_gdb == gdb_sys_sigreturn || syscall_gdb == gdb_sys_rt_sigreturn)
+ {
+ if (!riscv_all_but_pc_registers_record (regcache))
+ return -1;
+ return 0;
+ }
+
+ int ret = record_linux_system_call (syscall_gdb, regcache,
+ &riscv_linux_record_tdep);
+ if (ret != 0)
+ return ret;
+
+ /* Record the return value of the system call. */
+ if (record_full_arch_list_add_reg (regcache, RISCV_A0_REGNUM))
+ return -1;
+
+ return 0;
+}
+
+/* Initialize the riscv64_linux_record_tdep. */
+
+static void
+riscv64_linux_record_tdep_init (struct gdbarch *gdbarch,
+ struct linux_record_tdep &
+ riscv_linux_record_tdep)
+{
+ gdb_assert (gdbarch != nullptr);
+
+ /* These values are the size of the type that
+ will be used in a system call. */
+ riscv_linux_record_tdep.size_pointer
+ = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
+ riscv_linux_record_tdep.size__old_kernel_stat = 48;
+ riscv_linux_record_tdep.size_tms = 32;
+ riscv_linux_record_tdep.size_loff_t = 8;
+ riscv_linux_record_tdep.size_flock = 32;
+ riscv_linux_record_tdep.size_oldold_utsname = 45;
+ riscv_linux_record_tdep.size_ustat = 32;
+ riscv_linux_record_tdep.size_old_sigaction = 32;
+ riscv_linux_record_tdep.size_old_sigset_t = 8;
+ riscv_linux_record_tdep.size_rlimit = 16;
+ riscv_linux_record_tdep.size_rusage = 144;
+ riscv_linux_record_tdep.size_timeval = 8;
+ riscv_linux_record_tdep.size_timezone = 8;
+ riscv_linux_record_tdep.size_old_gid_t = 2;
+ riscv_linux_record_tdep.size_old_uid_t = 2;
+ riscv_linux_record_tdep.size_fd_set = 128;
+ riscv_linux_record_tdep.size_old_dirent = 268;
+ riscv_linux_record_tdep.size_statfs = 120;
+ riscv_linux_record_tdep.size_statfs64 = 120;
+ riscv_linux_record_tdep.size_sockaddr = 16;
+ riscv_linux_record_tdep.size_int
+ = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
+ riscv_linux_record_tdep.size_long
+ = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
+ riscv_linux_record_tdep.size_ulong
+ = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
+ riscv_linux_record_tdep.size_msghdr = 104;
+ riscv_linux_record_tdep.size_itimerval = 16;
+ riscv_linux_record_tdep.size_stat = 128;
+ riscv_linux_record_tdep.size_old_utsname = 325;
+ riscv_linux_record_tdep.size_sysinfo = 112;
+ riscv_linux_record_tdep.size_msqid_ds = 104;
+ riscv_linux_record_tdep.size_shmid_ds = 88;
+ riscv_linux_record_tdep.size_new_utsname = 390;
+ riscv_linux_record_tdep.size_timex = 188;
+ riscv_linux_record_tdep.size_mem_dqinfo = 72;
+ riscv_linux_record_tdep.size_if_dqblk = 68;
+ riscv_linux_record_tdep.size_fs_quota_stat = 64;
+ riscv_linux_record_tdep.size_timespec = 16;
+ riscv_linux_record_tdep.size_pollfd = 8;
+ riscv_linux_record_tdep.size_NFS_FHSIZE = 32;
+ riscv_linux_record_tdep.size_knfsd_fh = 36;
+ riscv_linux_record_tdep.size_TASK_COMM_LEN = 4;
+ riscv_linux_record_tdep.size_sigaction = 24;
+ riscv_linux_record_tdep.size_sigset_t = 8;
+ riscv_linux_record_tdep.size_siginfo_t = 128;
+ riscv_linux_record_tdep.size_cap_user_data_t = 8;
+ riscv_linux_record_tdep.size_stack_t = 24;
+ riscv_linux_record_tdep.size_off_t = riscv_linux_record_tdep.size_long;
+ riscv_linux_record_tdep.size_stat64 = 136;
+ riscv_linux_record_tdep.size_gid_t = 4;
+ riscv_linux_record_tdep.size_uid_t = 4;
+ riscv_linux_record_tdep.size_PAGE_SIZE = 4096;
+ riscv_linux_record_tdep.size_flock64 = 32;
+ riscv_linux_record_tdep.size_user_desc = 37;
+ riscv_linux_record_tdep.size_io_event = 32;
+ riscv_linux_record_tdep.size_iocb = 64;
+ riscv_linux_record_tdep.size_epoll_event = 16;
+ riscv_linux_record_tdep.size_itimerspec
+ = riscv_linux_record_tdep.size_timespec * 2;
+ riscv_linux_record_tdep.size_mq_attr = 64;
+ riscv_linux_record_tdep.size_termios = 36;
+ riscv_linux_record_tdep.size_termios2 = 44;
+ riscv_linux_record_tdep.size_pid_t = 4;
+ riscv_linux_record_tdep.size_winsize = 8;
+ riscv_linux_record_tdep.size_serial_struct = 72;
+ riscv_linux_record_tdep.size_serial_icounter_struct = 80;
+ riscv_linux_record_tdep.size_hayes_esp_config = 12;
+ riscv_linux_record_tdep.size_size_t = 8;
+ riscv_linux_record_tdep.size_iovec = 16;
+ riscv_linux_record_tdep.size_time_t = 8;
+
+ /* These values are the second argument of system call "sys_ioctl".
+ They are obtained from Linux Kernel source. */
+ riscv_linux_record_tdep.ioctl_TCGETS = 0x5401;
+ riscv_linux_record_tdep.ioctl_TCSETS = 0x5402;
+ riscv_linux_record_tdep.ioctl_TCSETSW = 0x5403;
+ riscv_linux_record_tdep.ioctl_TCSETSF = 0x5404;
+ riscv_linux_record_tdep.ioctl_TCGETA = 0x5405;
+ riscv_linux_record_tdep.ioctl_TCSETA = 0x5406;
+ riscv_linux_record_tdep.ioctl_TCSETAW = 0x5407;
+ riscv_linux_record_tdep.ioctl_TCSETAF = 0x5408;
+ riscv_linux_record_tdep.ioctl_TCSBRK = 0x5409;
+ riscv_linux_record_tdep.ioctl_TCXONC = 0x540a;
+ riscv_linux_record_tdep.ioctl_TCFLSH = 0x540b;
+ riscv_linux_record_tdep.ioctl_TIOCEXCL = 0x540c;
+ riscv_linux_record_tdep.ioctl_TIOCNXCL = 0x540d;
+ riscv_linux_record_tdep.ioctl_TIOCSCTTY = 0x540e;
+ riscv_linux_record_tdep.ioctl_TIOCGPGRP = 0x540f;
+ riscv_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
+ riscv_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
+ riscv_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
+ riscv_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
+ riscv_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
+ riscv_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
+ riscv_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
+ riscv_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
+ riscv_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
+ riscv_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
+ riscv_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541a;
+ riscv_linux_record_tdep.ioctl_FIONREAD = 0x541b;
+ riscv_linux_record_tdep.ioctl_TIOCINQ
+ = riscv_linux_record_tdep.ioctl_FIONREAD;
+ riscv_linux_record_tdep.ioctl_TIOCLINUX = 0x541c;
+ riscv_linux_record_tdep.ioctl_TIOCCONS = 0x541d;
+ riscv_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541e;
+ riscv_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541f;
+ riscv_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
+ riscv_linux_record_tdep.ioctl_FIONBIO = 0x5421;
+ riscv_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
+ riscv_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
+ riscv_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
+ riscv_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
+ riscv_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
+ riscv_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
+ riscv_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
+ riscv_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
+ riscv_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
+ riscv_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
+ riscv_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
+ riscv_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
+ riscv_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
+ riscv_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
+ riscv_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
+ riscv_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
+ riscv_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
+ riscv_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
+ riscv_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
+ riscv_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
+ riscv_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
+ riscv_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
+ riscv_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
+ riscv_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
+ riscv_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545a;
+ riscv_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545b;
+ riscv_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545c;
+ riscv_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545d;
+ riscv_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545e;
+ riscv_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545f;
+ riscv_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
+
+ /* These values are the second argument of system call "sys_fcntl"
+ and "sys_fcntl64". They are obtained from Linux Kernel source. */
+ riscv_linux_record_tdep.fcntl_F_GETLK = 5;
+ riscv_linux_record_tdep.fcntl_F_GETLK64 = 12;
+ riscv_linux_record_tdep.fcntl_F_SETLK64 = 13;
+ riscv_linux_record_tdep.fcntl_F_SETLKW64 = 14;
+
+ riscv_linux_record_tdep.arg1 = RISCV_A0_REGNUM;
+ riscv_linux_record_tdep.arg2 = RISCV_A1_REGNUM;
+ riscv_linux_record_tdep.arg3 = RISCV_A2_REGNUM;
+ riscv_linux_record_tdep.arg4 = RISCV_A3_REGNUM;
+ riscv_linux_record_tdep.arg5 = RISCV_A4_REGNUM;
+ riscv_linux_record_tdep.arg6 = RISCV_A5_REGNUM;
+}
+
+/* Fetch and return the TLS DTV (dynamic thread vector) address for PTID.
+ Throw a suitable TLS error if something goes wrong. */
+
+static CORE_ADDR
+riscv_linux_get_tls_dtv_addr (struct gdbarch *gdbarch, ptid_t ptid,
+ svr4_tls_libc libc)
+{
+ /* On RISC-V, the thread pointer is found in TP. */
+ regcache *regcache
+ = get_thread_arch_regcache (current_inferior (), ptid, gdbarch);
+ int thread_pointer_regnum = RISCV_TP_REGNUM;
+ target_fetch_registers (regcache, thread_pointer_regnum);
+ ULONGEST thr_ptr;
+ if (regcache->cooked_read (thread_pointer_regnum, &thr_ptr) != REG_VALID)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to fetch thread pointer"));
+
+ CORE_ADDR dtv_ptr_addr;
+ switch (libc)
+ {
+ case svr4_tls_libc_musl:
+ /* MUSL: The DTV pointer is found at the very end of the pthread
+ struct which is located *before* the thread pointer. I.e.
+ the thread pointer will be just beyond the end of the struct,
+ so the address of the DTV pointer is found one pointer-size
+ before the thread pointer. */
+ dtv_ptr_addr
+ = thr_ptr - (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
+ break;
+ case svr4_tls_libc_glibc:
+ /* GLIBC: The thread pointer (TP) points just beyond the end of
+ the TCB (thread control block). On RISC-V, this struct
+ (tcbhead_t) is defined to contain two pointers. The first is
+ a pointer to the DTV and the second is a pointer to private
+ data. So the DTV pointer address is 16 bytes (i.e. the size of
+ two pointers) before thread pointer. */
+
+ dtv_ptr_addr
+ = thr_ptr - 2 * (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
+ break;
+ default:
+ throw_error (TLS_GENERIC_ERROR, _("Unknown RISC-V C library"));
+ break;
+ }
+
+ gdb::byte_vector buf (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
+ if (target_read_memory (dtv_ptr_addr, buf.data (), buf.size ()) != 0)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to fetch DTV address"));
+
+ const struct builtin_type *builtin = builtin_type (gdbarch);
+ CORE_ADDR dtv_addr = gdbarch_pointer_to_address
+ (gdbarch, builtin->builtin_data_ptr, buf.data ());
+ return dtv_addr;
+}
+
+/* For internal TLS lookup, return the DTP offset, which is the offset
+ to subtract from a DTV entry, in order to obtain the address of the
+ TLS block. */
+
+static ULONGEST
+riscv_linux_get_tls_dtp_offset (struct gdbarch *gdbarch, ptid_t ptid,
+ svr4_tls_libc libc)
+{
+ if (libc == svr4_tls_libc_musl)
+ {
+ /* This value is DTP_OFFSET in MUSL's arch/riscv64/pthread_arch.h.
+ It represents the value to subtract from the DTV entry, once
+ it has been loaded. */
+ return 0x800;
+ }
+ else
+ return 0;
+}
+
/* Initialize RISC-V Linux ABI info. */
static void
@@ -198,6 +526,10 @@ riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
/* Enable TLS support. */
set_gdbarch_fetch_tls_load_module_address (gdbarch,
svr4_fetch_objfile_link_map);
+ set_gdbarch_get_thread_local_address (gdbarch,
+ svr4_tls_get_thread_local_address);
+ svr4_tls_register_tls_methods (info, gdbarch, riscv_linux_get_tls_dtv_addr,
+ riscv_linux_get_tls_dtp_offset);
set_gdbarch_iterate_over_regset_sections
(gdbarch, riscv_linux_iterate_over_regset_sections);
@@ -205,6 +537,9 @@ riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
tramp_frame_prepend_unwinder (gdbarch, &riscv_linux_sigframe);
tdep->syscall_next_pc = riscv_linux_syscall_next_pc;
+ tdep->riscv_syscall_record = riscv_linux_syscall_record;
+
+ riscv64_linux_record_tdep_init (gdbarch, riscv_linux_record_tdep);
}
/* Initialize RISC-V Linux target support. */
diff --git a/gdb/riscv-linux-tdep.h b/gdb/riscv-linux-tdep.h
new file mode 100644
index 0000000..9dd9e37
--- /dev/null
+++ b/gdb/riscv-linux-tdep.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 2024-2025 Free Software Foundation, Inc.
+
+ 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_RISCV_LINUX_TDEP_H
+#define GDB_RISCV_LINUX_TDEP_H
+
+#include "linux-record.h"
+
+/* riscv64_canonicalize_syscall maps from the native riscv Linux set
+ of syscall ids into a canonical set of syscall ids used by
+ process record. */
+
+extern enum gdb_syscall riscv64_canonicalize_syscall (int syscall);
+
+#endif /* GDB_RISCV_LINUX_TDEP_H */
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 91f6dff..a735c09 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -54,9 +54,12 @@
#include "observable.h"
#include "prologue-value.h"
#include "arch/riscv.h"
+#include "record-full.h"
#include "riscv-ravenscar-thread.h"
#include "gdbsupport/gdb-safe-ctype.h"
+#include <vector>
+
/* The stack must be 16-byte aligned. */
#define SP_ALIGNMENT 16
@@ -1669,6 +1672,11 @@ public:
int imm_signed () const
{ return m_imm.s; }
+ /* Fetch instruction from target memory at ADDR, return the content of
+ the instruction, and update LEN with the instruction length. */
+ static ULONGEST fetch_instruction (struct gdbarch *gdbarch,
+ CORE_ADDR addr, int *len);
+
private:
/* Extract 5 bit register field at OFFSET from instruction OPCODE. */
@@ -1814,11 +1822,6 @@ private:
m_rs2 = decode_register_index_short (ival, OP_SH_CRS2S);
}
- /* Fetch instruction from target memory at ADDR, return the content of
- the instruction, and update LEN with the instruction length. */
- static ULONGEST fetch_instruction (struct gdbarch *gdbarch,
- CORE_ADDR addr, int *len);
-
/* The length of the instruction in bytes. Should be 2 or 4. */
int m_length;
@@ -4433,6 +4436,9 @@ riscv_gdbarch_init (struct gdbarch_info info,
set_gdbarch_stap_register_indirection_suffixes
(gdbarch, stap_register_indirection_suffixes);
+ /* Process record-replay */
+ set_gdbarch_process_record (gdbarch, riscv_process_record);
+
/* Hook in OS ABI-specific overrides, if they have been registered. */
gdbarch_init_osabi (info, gdbarch);
@@ -4866,3 +4872,673 @@ equivalent change in the disassembler output."),
&setriscvcmdlist,
&showriscvcmdlist);
}
+
+/* A wrapper to read register under number regnum to address addr.
+ Returns false if error happened and makes warning. */
+
+static bool
+try_read (struct regcache *regcache, int regnum, ULONGEST &addr)
+{
+ gdb_assert (regcache != nullptr);
+
+ if (regcache->raw_read (regnum, &addr)
+ != register_status::REG_VALID)
+ {
+ warning (_("Can not read at address %lx"), addr);
+ return false;
+ }
+ return true;
+}
+
+/* Helper class to record instruction. */
+
+class riscv_recorded_insn final
+{
+public:
+ /* Type for saved register. */
+ using regnum_type = int;
+ /* Type for saved memory. First is address, second is length. */
+ using memory_type = std::pair<CORE_ADDR, int>;
+
+ /* Enum class that represents which type does recording belong to. */
+ enum class record_type
+ {
+ UNKNOWN,
+ ORDINARY,
+
+ /* Corner cases. */
+ ECALL,
+ EBREAK,
+ };
+
+private:
+ /* Type for set of registers that need to be saved. */
+ using recorded_regs = std::vector<regnum_type>;
+ /* Type for set of memory records that need to be saved. */
+ using recorded_mems = std::vector<memory_type>;
+
+ /* Type for memory address, extracted from memory_type. */
+ using mem_addr = decltype (std::declval<memory_type> ().first);
+ /* Type for memory length, extracted from memory_type. */
+ using mem_len = decltype (std::declval<memory_type> ().second);
+
+ /* Record type of current instruction. */
+ record_type m_record_type = record_type::UNKNOWN;
+
+ /* Flag that represents was there an error in current recording. */
+ bool m_error_occured = false;
+
+ /* Set of registers that need to be recorded. */
+ recorded_regs m_regs;
+ /* Set of memory chunks that need to be recorded. */
+ recorded_mems m_mems;
+
+ /* Width in bytes of the general purpose registers for GDBARCH,
+ where recording is happening. */
+ int m_xlen = 0;
+
+ /* Helper for decode 16-bit instruction RS1. */
+ static regnum_type
+ decode_crs1_short (ULONGEST opcode) noexcept
+ {
+ return ((opcode >> OP_SH_CRS1S) & OP_MASK_CRS1S) + 8;
+ }
+
+ /* Helper for decode 16-bit instruction RS2. */
+ static regnum_type
+ decode_crs2_short (ULONGEST opcode) noexcept
+ {
+ return ((opcode >> OP_SH_CRS2S) & OP_MASK_CRS2S) + 8;
+ }
+
+ /* Helper for decode 16-bit instruction CRS1. */
+ static regnum_type
+ decode_crs1 (ULONGEST opcode) noexcept
+ {
+ return ((opcode >> OP_SH_RD) & OP_MASK_RD);
+ }
+
+ /* Helper for decode 16-bit instruction CRS2. */
+ static regnum_type
+ decode_crs2 (ULONGEST opcode) noexcept
+ {
+ return ((opcode >> OP_SH_CRS2) & OP_MASK_CRS2);
+ }
+
+ /* Helper for decode 32-bit instruction RD. */
+ static regnum_type
+ decode_rd (ULONGEST ival) noexcept
+ {
+ return (ival >> OP_SH_RD) & OP_MASK_RD;
+ }
+
+ /* Helper for decode 32-bit instruction RS1. */
+ static regnum_type
+ decode_rs1 (ULONGEST ival) noexcept
+ {
+ return (ival >> OP_SH_RS1) & OP_MASK_RS1;
+ }
+
+ /* Helper for decode 32-bit instruction RS2. */
+ static regnum_type
+ decode_rs2 (ULONGEST ival) noexcept
+ {
+ return (ival >> OP_SH_RS2) & OP_MASK_RS2;
+ }
+
+ /* Helper for decode 32-bit instruction CSR. */
+ static regnum_type
+ decode_csr (ULONGEST ival) noexcept
+ {
+ return (ival >> OP_SH_CSR) & OP_MASK_CSR;
+ }
+
+ /* Set ordinary record type. Always returns true. */
+ bool
+ set_ordinary_record_type () noexcept
+ {
+ m_record_type = record_type::ORDINARY;
+ return true;
+ }
+
+ /* Set error happened. Always returns false. */
+ bool
+ set_error () noexcept
+ {
+ m_error_occured = true;
+ return false;
+ }
+
+ /* Check if current recording has an error. */
+ bool
+ has_error () const noexcept
+ {
+ return m_error_occured;
+ }
+
+ /* Reads register. Sets error and returns false if error happened. */
+ bool
+ read_reg (struct regcache *regcache, regnum_type reg,
+ ULONGEST &addr) noexcept
+ {
+ gdb_assert (regcache != nullptr);
+
+ if (!try_read (regcache, reg, addr))
+ return set_error ();
+ return true;
+ }
+
+ /* Save register. Returns true or aborts if exception happened. */
+ bool
+ save_reg (regnum_type regnum) noexcept
+ {
+ m_regs.emplace_back (regnum);
+ return true;
+ }
+
+ /* Save memory chunk. Returns true or aborts if exception happened. */
+ bool
+ save_mem (mem_addr addr, mem_len len) noexcept
+ {
+ m_mems.emplace_back (addr, len);
+ return true;
+ }
+
+ /* Returns true if instruction needs only saving pc. */
+ static bool
+ need_save_pc (ULONGEST ival) noexcept
+ {
+ return (is_beq_insn (ival) || is_bne_insn (ival) || is_blt_insn (ival)
+ || is_bge_insn (ival) || is_bltu_insn (ival) || is_bgeu_insn (ival)
+ || is_fence_insn (ival) || is_pause_insn (ival)
+ || is_fence_i_insn (ival));
+ }
+
+ /* Returns true if instruction is classified. */
+ bool
+ try_save_pc (ULONGEST ival) noexcept
+ {
+ if (!need_save_pc (ival))
+ return false;
+
+ return set_ordinary_record_type ();
+ }
+
+ /* Returns true if instruction needs only saving pc and rd. */
+ static bool
+ need_save_pc_rd (ULONGEST ival) noexcept
+ {
+ return (is_lui_insn (ival) || is_auipc_insn (ival) || is_jal_insn (ival)
+ || is_jalr_insn (ival) || is_lb_insn (ival) || is_lh_insn (ival)
+ || is_lw_insn (ival) || is_lbu_insn (ival) || is_lhu_insn (ival)
+ || is_addi_insn (ival) || is_slti_insn (ival)
+ || is_sltiu_insn (ival) || is_xori_insn (ival) || is_ori_insn (ival)
+ || is_andi_insn (ival) || is_slli_rv32_insn (ival)
+ || is_srli_rv32_insn (ival) || is_srai_rv32_insn (ival)
+ || is_add_insn (ival) || is_sub_insn (ival) || is_sll_insn (ival)
+ || is_slt_insn (ival) || is_sltu_insn (ival) || is_xor_insn (ival)
+ || is_srl_insn (ival) || is_sra_insn (ival) || is_or_insn (ival)
+ || is_and_insn (ival) || is_lwu_insn (ival) || is_ld_insn (ival)
+ || is_slli_insn (ival) || is_srli_insn (ival) || is_srai_insn (ival)
+ || is_addiw_insn (ival) || is_slliw_insn (ival)
+ || is_srliw_insn (ival) || is_sraiw_insn (ival)
+ || is_addw_insn (ival) || is_subw_insn (ival) || is_sllw_insn (ival)
+ || is_srlw_insn (ival) || is_sraw_insn (ival) || is_mul_insn (ival)
+ || is_mulh_insn (ival) || is_mulhsu_insn (ival)
+ || is_mulhu_insn (ival) || is_div_insn (ival) || is_divu_insn (ival)
+ || is_rem_insn (ival) || is_remu_insn (ival) || is_mulw_insn (ival)
+ || is_divw_insn (ival) || is_divuw_insn (ival)
+ || is_remw_insn (ival) || is_remuw_insn (ival)
+ || is_lr_w_insn (ival) || is_lr_d_insn (ival)
+ || is_fcvt_w_s_insn (ival) || is_fcvt_wu_s_insn (ival)
+ || is_fmv_x_s_insn (ival) || is_feq_s_insn (ival)
+ || is_flt_s_insn (ival) || is_fle_s_insn (ival)
+ || is_fclass_s_insn (ival) || is_fcvt_l_s_insn (ival)
+ || is_fcvt_lu_s_insn (ival) || is_feq_d_insn (ival)
+ || is_flt_d_insn (ival) || is_fle_d_insn (ival)
+ || is_fclass_d_insn (ival) || is_fcvt_w_d_insn (ival)
+ || is_fcvt_wu_d_insn (ival) || is_fcvt_l_d_insn (ival)
+ || is_fcvt_lu_d_insn (ival) || is_fmv_x_d_insn (ival));
+ }
+
+ /* Returns true if instruction is classified. This function can set
+ m_error_occured. */
+ bool
+ try_save_pc_rd (ULONGEST ival) noexcept
+ {
+ if (!need_save_pc_rd (ival))
+ return false;
+
+ return (!save_reg (decode_rd (ival)) || set_ordinary_record_type ());
+ }
+
+ /* Returns true if instruction needs only saving pc and
+ floating point rd. */
+ static bool
+ need_save_pc_fprd (ULONGEST ival) noexcept
+ {
+ return (is_flw_insn (ival) || is_fmadd_s_insn (ival)
+ || is_fmsub_s_insn (ival) || is_fnmsub_s_insn (ival)
+ || is_fnmadd_s_insn (ival) || is_fadd_s_insn (ival)
+ || is_fsub_s_insn (ival) || is_fmul_s_insn (ival)
+ || is_fdiv_s_insn (ival) || is_fsqrt_s_insn (ival)
+ || is_fsgnj_s_insn (ival) || is_fsgnjn_s_insn (ival)
+ || is_fsgnjx_s_insn (ival) || is_fmin_s_insn (ival)
+ || is_fmax_s_insn (ival) || is_fcvt_s_w_insn (ival)
+ || is_fcvt_s_wu_insn (ival) || is_fmv_s_x_insn (ival)
+ || is_fcvt_s_l_insn (ival) || is_fcvt_s_lu_insn (ival)
+ || is_fld_insn (ival) || is_fmadd_d_insn (ival)
+ || is_fmsub_d_insn (ival) || is_fnmsub_d_insn (ival)
+ || is_fnmadd_d_insn (ival) || is_fadd_d_insn (ival)
+ || is_fsub_d_insn (ival) || is_fmul_d_insn (ival)
+ || is_fdiv_d_insn (ival) || is_fsqrt_d_insn (ival)
+ || is_fsgnj_d_insn (ival) || is_fsgnjn_d_insn (ival)
+ || is_fsgnjx_d_insn (ival) || is_fmin_d_insn (ival)
+ || is_fmax_d_insn (ival) || is_fcvt_s_d_insn (ival)
+ || is_fcvt_d_s_insn (ival) || is_fcvt_d_w_insn (ival)
+ || is_fcvt_d_wu_insn (ival) || is_fcvt_d_l_insn (ival)
+ || is_fcvt_d_lu_insn (ival) || is_fmv_d_x_insn (ival));
+ }
+
+ /* Returns true if instruction is classified. This function can set
+ m_error_occured. */
+ bool
+ try_save_pc_fprd (ULONGEST ival) noexcept
+ {
+ if (!need_save_pc_fprd (ival))
+ return false;
+
+ return (!save_reg (RISCV_FIRST_FP_REGNUM + decode_rd (ival))
+ || set_ordinary_record_type ());
+ }
+
+ /* Returns true if instruction needs only saving pc, rd and csr. */
+ static bool
+ need_save_pc_rd_csr (ULONGEST ival) noexcept
+ {
+ return (is_csrrw_insn (ival) || is_csrrs_insn (ival) || is_csrrc_insn (ival)
+ || is_csrrwi_insn (ival) || is_csrrsi_insn (ival)
+ || is_csrrc_insn (ival));
+ }
+
+ /* Returns true if instruction is classified. This function can set
+ m_error_occured. */
+ bool
+ try_save_pc_rd_csr (ULONGEST ival) noexcept
+ {
+ if (!need_save_pc_rd_csr (ival))
+ return false;
+
+ return (!save_reg (decode_rd (ival))
+ || !save_reg (RISCV_FIRST_CSR_REGNUM + decode_csr (ival))
+ || set_ordinary_record_type ());
+ }
+
+ /* Returns the size of the memory chunk that needs to be saved if the
+ instruction belongs to the group that needs only saving pc and memory.
+ Otherwise returns 0. */
+ static mem_len
+ need_save_pc_mem (ULONGEST ival) noexcept
+ {
+ if (is_sb_insn (ival))
+ return 1;
+ if (is_sh_insn (ival))
+ return 2;
+ if (is_sw_insn (ival) || is_fsw_insn (ival))
+ return 4;
+ if (is_sd_insn (ival) || is_fsd_insn (ival))
+ return 8;
+ return 0;
+ }
+
+ /* Returns true if instruction is classified. This function can set
+ m_error_occured. */
+ bool
+ try_save_pc_mem (ULONGEST ival, struct regcache *regcache) noexcept
+ {
+ gdb_assert (regcache != nullptr);
+
+ mem_addr addr = mem_addr{};
+ mem_len len = need_save_pc_mem (ival);
+ if (len <= 0)
+ return false;
+
+ mem_len offset = EXTRACT_STYPE_IMM (ival);
+ return (!read_reg (regcache, decode_rs1 (ival), addr)
+ || !save_mem (addr + offset, len) || set_ordinary_record_type ());
+ }
+
+ /* Returns the size of the memory chunk that needs to be saved if the
+ instruction belongs to the group that needs only saving pc, rd and memory.
+ Otherwise returns 0. */
+ static mem_len
+ need_save_pc_rd_mem (ULONGEST ival) noexcept
+ {
+ if (is_sc_w_insn (ival) || is_amoswap_w_insn (ival)
+ || is_amoadd_w_insn (ival) || is_amoxor_w_insn (ival)
+ || is_amoand_w_insn (ival) || is_amoor_w_insn (ival)
+ || is_amomin_w_insn (ival) || is_amomax_w_insn (ival)
+ || is_amominu_w_insn (ival) || is_amomaxu_w_insn (ival))
+ return 4;
+ if (is_sc_d_insn (ival) || is_amoswap_d_insn (ival)
+ || is_amoadd_d_insn (ival) || is_amoxor_d_insn (ival)
+ || is_amoand_d_insn (ival) || is_amoor_d_insn (ival)
+ || is_amomin_d_insn (ival) || is_amomax_d_insn (ival)
+ || is_amominu_d_insn (ival) || is_amomaxu_d_insn (ival))
+ return 8;
+ return 0;
+ }
+
+ /* Returns true if instruction is classified. This function can set
+ m_error_occured. */
+ bool
+ try_save_pc_rd_mem (ULONGEST ival, struct regcache *regcache) noexcept
+ {
+ gdb_assert (regcache != nullptr);
+
+ mem_len len = need_save_pc_rd_mem (ival);
+ mem_addr addr = 0;
+ if (len <= 0)
+ return false;
+
+ return (!read_reg (regcache, decode_rs1 (ival), addr)
+ || !save_mem (addr, len) || !save_reg (decode_rd (ival))
+ || set_ordinary_record_type ());
+ }
+
+ /* Returns true if instruction is successfully recordered. The length of
+ the instruction must be equal 4 bytes. */
+ bool
+ record_insn_len4 (ULONGEST ival, struct regcache *regcache) noexcept
+ {
+ gdb_assert (regcache != nullptr);
+
+ if (is_ecall_insn (ival))
+ {
+ m_record_type = record_type::ECALL;
+ return true;
+ }
+
+ if (is_ebreak_insn (ival))
+ {
+ m_record_type = record_type::EBREAK;
+ return true;
+ }
+
+ if (try_save_pc (ival) || try_save_pc_rd (ival) || try_save_pc_fprd (ival)
+ || try_save_pc_rd_csr (ival) || try_save_pc_mem (ival, regcache)
+ || try_save_pc_rd_mem (ival, regcache))
+ return !has_error ();
+
+ warning (_("Currently this instruction with len 4(%lx) is unsupported"),
+ ival);
+ return false;
+ }
+
+ /* Returns true if instruction is successfully recordered. The length of
+ the instruction must be equal 2 bytes. */
+ bool
+ record_insn_len2 (ULONGEST ival, struct regcache *regcache) noexcept
+ {
+ gdb_assert (regcache != nullptr);
+
+ mem_addr addr = mem_addr{};
+
+ /* The order here is very important, because
+ opcodes of some instructions may be the same. */
+
+ if (is_c_addi4spn_insn (ival) || is_c_lw_insn (ival)
+ || (m_xlen == 8 && is_c_ld_insn (ival)))
+ return (!save_reg (decode_crs2_short (ival))
+ || set_ordinary_record_type ());
+
+ if (is_c_fld_insn (ival) || (m_xlen == 4 && is_c_flw_insn (ival)))
+ return (!save_reg (RISCV_FIRST_FP_REGNUM + decode_crs2_short (ival))
+ || set_ordinary_record_type ());
+
+ if (is_c_fsd_insn (ival) || (m_xlen == 8 && is_c_sd_insn (ival)))
+ {
+ ULONGEST offset = ULONGEST{EXTRACT_CLTYPE_LD_IMM (ival)};
+ return (!read_reg (regcache, decode_crs1_short (ival), addr)
+ || !save_mem (addr + offset, 8) || set_ordinary_record_type ());
+ }
+
+ if ((m_xlen == 4 && is_c_fsw_insn (ival)) || is_c_sw_insn (ival))
+ {
+ ULONGEST offset = ULONGEST{EXTRACT_CLTYPE_LW_IMM (ival)};
+ return (!read_reg (regcache, decode_crs1_short (ival), addr)
+ || !save_mem (addr + offset, 4) || set_ordinary_record_type ());
+ }
+
+ if (is_c_nop_insn (ival))
+ return set_ordinary_record_type ();
+
+ if (is_c_addi_insn (ival))
+ return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_type ());
+
+ if (m_xlen == 4 && is_c_jal_insn (ival))
+ return (!save_reg (RISCV_RA_REGNUM) || set_ordinary_record_type ());
+
+ if ((m_xlen == 8 && is_c_addiw_insn (ival)) || is_c_li_insn (ival))
+ return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_type ());
+
+ if (is_c_addi16sp_insn (ival))
+ return (!save_reg (RISCV_SP_REGNUM) || set_ordinary_record_type ());
+
+ if (is_c_lui_insn (ival))
+ return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_type ());
+
+ if (is_c_srli_insn (ival) || is_c_srai_insn (ival) || is_c_andi_insn (ival)
+ || is_c_sub_insn (ival) || is_c_xor_insn (ival) || is_c_or_insn (ival)
+ || is_c_and_insn (ival) || (m_xlen == 8 && is_c_subw_insn (ival))
+ || (m_xlen == 8 && is_c_addw_insn (ival)))
+ return (!save_reg (decode_crs1_short (ival))
+ || set_ordinary_record_type ());
+
+ if (is_c_j_insn (ival) || is_c_beqz_insn (ival) || is_c_bnez_insn (ival))
+ return set_ordinary_record_type ();
+
+ if (is_c_slli_insn (ival))
+ return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_type ());
+
+ if (is_c_fldsp_insn (ival) || (m_xlen == 4 && is_c_flwsp_insn (ival)))
+ return (!save_reg (RISCV_FIRST_FP_REGNUM + decode_crs1 (ival))
+ || set_ordinary_record_type ());
+
+ if (is_c_lwsp_insn (ival) || (m_xlen == 8 && is_c_ldsp_insn (ival)))
+ return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_type ());
+
+ if (is_c_jr_insn (ival))
+ return set_ordinary_record_type ();
+
+ if (is_c_mv_insn (ival))
+ return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_type ());
+
+ if (is_c_ebreak_insn (ival))
+ {
+ m_record_type = record_type::EBREAK;
+ return true;
+ }
+
+ if (is_c_jalr_insn (ival))
+ return (!save_reg (RISCV_RA_REGNUM) || set_ordinary_record_type ());
+
+ if (is_c_add_insn (ival))
+ return (!save_reg (decode_crs1 (ival)) || set_ordinary_record_type ());
+
+ if (is_c_fsdsp_insn (ival) || (m_xlen == 8 && is_c_sdsp_insn (ival)))
+ {
+ ULONGEST offset = ULONGEST{EXTRACT_CSSTYPE_SDSP_IMM (ival)};
+ return (!read_reg (regcache, RISCV_SP_REGNUM, addr)
+ || !save_mem (addr + offset, 8) || set_ordinary_record_type ());
+ }
+
+ if (is_c_swsp_insn (ival) || (m_xlen == 4 && is_c_fswsp_insn (ival)))
+ {
+ ULONGEST offset = ULONGEST{EXTRACT_CSSTYPE_SWSP_IMM (ival)};
+ return (!read_reg (regcache, RISCV_SP_REGNUM, addr)
+ || !save_mem (addr + offset, 4) || set_ordinary_record_type ());
+ }
+
+ warning (_("Currently this instruction with len 2(%lx) is unsupported"),
+ ival);
+ return false;
+ }
+
+public:
+ /* Iterator for registers that need to be recorded. */
+ using regs_iter = recorded_regs::const_iterator;
+ /* Iterator for memory chunks that need to be recorded. */
+ using mems_iter = recorded_mems::const_iterator;
+
+ /* Record instruction at address addr. Returns false if error happened. */
+ bool
+ record (gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR addr) noexcept
+ {
+ gdb_assert (gdbarch != nullptr);
+ gdb_assert (regcache != nullptr);
+
+ int m_length = 0;
+ m_xlen = riscv_isa_xlen (gdbarch);
+ ULONGEST ival = riscv_insn::fetch_instruction (gdbarch, addr, &m_length);
+ if (!save_reg (RISCV_PC_REGNUM))
+ return false;
+
+ if (m_length == 4)
+ return record_insn_len4 (ival, regcache);
+
+ if (m_length == 2)
+ return record_insn_len2 (ival, regcache);
+
+ /* 6 bytes or more. If the instruction is longer than 8 bytes, we don't
+ have full instruction bits in ival. At least, such long instructions
+ are not defined yet, so just ignore it. */
+ gdb_assert (m_length > 0 && m_length % 2 == 0);
+
+ warning (_("Can not record unknown instruction (opcode = %lx)"), ival);
+ return false;
+ }
+
+ /* Get record type of instruction. */
+ record_type
+ get_record_type () const noexcept
+ {
+ return m_record_type;
+ }
+
+ /* Returns an iterator to the beginning of the registers that need
+ to be saved. */
+ regs_iter
+ regs_begin () const noexcept
+ {
+ return m_regs.begin ();
+ }
+
+ /* Returns an iterator to the end of the registers that need
+ to be saved. */
+ regs_iter
+ regs_end () const noexcept
+ {
+ return m_regs.end ();
+ }
+
+ /* Returns an iterator to the beginning of the memory chunks that need
+ to be saved. */
+ mems_iter
+ mems_begin () const noexcept
+ {
+ return m_mems.begin ();
+ }
+
+ /* Returns an iterator to the end of the memory chunks that need
+ to be saved. */
+ mems_iter
+ mems_end () const noexcept
+ {
+ return m_mems.end ();
+ }
+};
+
+/* A helper function to record instruction using record API. */
+
+static int
+riscv_record_insn_details (struct gdbarch *gdbarch, struct regcache *regcache,
+ const riscv_recorded_insn &insn)
+{
+ gdb_assert (gdbarch != nullptr);
+ gdb_assert (regcache != nullptr);
+
+ riscv_gdbarch_tdep *tdep = gdbarch_tdep<riscv_gdbarch_tdep> (gdbarch);
+ auto regs_begin = insn.regs_begin ();
+ auto regs_end = insn.regs_end ();
+ if (std::any_of (regs_begin,
+ regs_end,
+ [&regcache] (auto &&reg_it)
+ {
+ return record_full_arch_list_add_reg (regcache, reg_it);
+ }))
+ return -1;
+
+ auto mems_begin = insn.mems_begin ();
+ auto mems_end = insn.mems_end ();
+ if (std::any_of (mems_begin,
+ mems_end,
+ [] (auto &&mem_it)
+ {
+ return record_full_arch_list_add_mem (mem_it.first,
+ mem_it.second);
+ }))
+ return -1;
+
+ switch (insn.get_record_type ())
+ {
+ case riscv_recorded_insn::record_type::ORDINARY:
+ break;
+
+ case riscv_recorded_insn::record_type::ECALL:
+ {
+ if (!tdep->riscv_syscall_record)
+ {
+ warning (_("Syscall record is not supported"));
+ return -1;
+ }
+ ULONGEST reg_val = ULONGEST{};
+ if (!try_read (regcache, RISCV_A7_REGNUM, reg_val))
+ return -1;
+ return tdep->riscv_syscall_record (regcache, reg_val);
+ }
+
+ case riscv_recorded_insn::record_type::EBREAK:
+ break;
+
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+/* Parse the current instruction and record the values of the registers and
+ memory that will be changed in current instruction to record_arch_list.
+ Return -1 if something is wrong. */
+
+int
+riscv_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
+ CORE_ADDR addr)
+{
+ gdb_assert (gdbarch != nullptr);
+ gdb_assert (regcache != nullptr);
+
+ riscv_recorded_insn insn;
+ if (!insn.record (gdbarch, regcache, addr))
+ {
+ record_full_arch_list_add_end ();
+ return -1;
+ }
+
+ int ret_val = riscv_record_insn_details (gdbarch, regcache, insn);
+
+ if (record_full_arch_list_add_end ())
+ return -1;
+
+ return ret_val;
+}
diff --git a/gdb/riscv-tdep.h b/gdb/riscv-tdep.h
index ad1e959..2903aef 100644
--- a/gdb/riscv-tdep.h
+++ b/gdb/riscv-tdep.h
@@ -35,7 +35,11 @@ enum
RISCV_FP_REGNUM = 8, /* Frame Pointer. */
RISCV_A0_REGNUM = 10, /* First argument. */
RISCV_A1_REGNUM = 11, /* Second argument. */
- RISCV_A7_REGNUM = 17, /* Seventh argument. */
+ RISCV_A2_REGNUM = 12, /* Third argument. */
+ RISCV_A3_REGNUM = 13, /* Forth argument. */
+ RISCV_A4_REGNUM = 14, /* Fifth argument. */
+ RISCV_A5_REGNUM = 15, /* Sixth argument. */
+ RISCV_A7_REGNUM = 17, /* Register to pass syscall number. */
RISCV_PC_REGNUM = 32, /* Program Counter. */
RISCV_NUM_INTEGER_REGS = 32,
@@ -113,6 +117,10 @@ struct riscv_gdbarch_tdep : gdbarch_tdep_base
/* Return the expected next PC assuming FRAME is stopped at a syscall
instruction. */
CORE_ADDR (*syscall_next_pc) (const frame_info_ptr &frame) = nullptr;
+
+ /* Syscall record. */
+ int (*riscv_syscall_record) (struct regcache *regcache,
+ unsigned long svc_number) = nullptr;
};
@@ -177,6 +185,12 @@ extern void riscv_supply_regset (const struct regset *regset,
struct regcache *regcache, int regnum,
const void *regs, size_t len);
+/* Parse the current instruction, and record the values of the
+ registers and memory that will be changed by the current
+ instruction. Returns -1 if something goes wrong, 0 otherwise. */
+extern int riscv_process_record (struct gdbarch *gdbarch,
+ struct regcache *regcache, CORE_ADDR addr);
+
/* The names of the RISC-V target description features. */
extern const char *riscv_feature_name_csr;
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index 04c523b..bd1f42c 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -29,6 +29,7 @@
#include "gdbcore.h"
#include "linux-record.h"
#include "linux-tdep.h"
+#include "svr4-tls-tdep.h"
#include "objfiles.h"
#include "osabi.h"
#include "regcache.h"
@@ -40,6 +41,7 @@
#include "target.h"
#include "trad-frame.h"
#include "xml-syscall.h"
+#include "inferior.h"
#include "features/s390-linux32v1.c"
#include "features/s390-linux32v2.c"
@@ -1124,6 +1126,45 @@ s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
record_tdep->ioctl_FIOQSIZE = 0x545e;
}
+/* Fetch and return the TLS DTV (dynamic thread vector) address for PTID.
+ Throw a suitable TLS error if something goes wrong. */
+
+static CORE_ADDR
+s390_linux_get_tls_dtv_addr (struct gdbarch *gdbarch, ptid_t ptid,
+ enum svr4_tls_libc libc)
+{
+ /* On S390, the thread pointer is found in two registers A0 and A1
+ (or, using gdb naming, acr0 and acr1) A0 contains the top 32
+ bits of the address and A1 contains the bottom 32 bits. */
+ regcache *regcache
+ = get_thread_arch_regcache (current_inferior (), ptid, gdbarch);
+ target_fetch_registers (regcache, S390_A0_REGNUM);
+ target_fetch_registers (regcache, S390_A1_REGNUM);
+ ULONGEST thr_ptr_lo, thr_ptr_hi, thr_ptr;
+ if (regcache->cooked_read (S390_A0_REGNUM, &thr_ptr_hi) != REG_VALID
+ || regcache->cooked_read (S390_A1_REGNUM, &thr_ptr_lo) != REG_VALID)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to fetch thread pointer"));
+ thr_ptr = (thr_ptr_hi << 32) + thr_ptr_lo;
+
+ /* The thread pointer points at the TCB (thread control block). The
+ first two members of this struct are both pointers, where the
+ first will be a pointer to the TCB (i.e. it points at itself)
+ and the second will be a pointer to the DTV (dynamic thread
+ vector). There are many other fields too, but the one we care
+ about here is the DTV pointer. Compute the address of the DTV
+ pointer, fetch it, and convert it to an address. */
+ CORE_ADDR dtv_ptr_addr
+ = thr_ptr + gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
+ gdb::byte_vector buf (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
+ if (target_read_memory (dtv_ptr_addr, buf.data (), buf.size ()) != 0)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to fetch DTV address"));
+
+ const struct builtin_type *builtin = builtin_type (gdbarch);
+ CORE_ADDR dtv_addr = gdbarch_pointer_to_address
+ (gdbarch, builtin->builtin_data_ptr, buf.data ());
+ return dtv_addr;
+}
+
/* Initialize OSABI common for GNU/Linux on 31- and 64-bit systems. */
static void
@@ -1152,6 +1193,9 @@ s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch)
/* Enable TLS support. */
set_gdbarch_fetch_tls_load_module_address (gdbarch,
svr4_fetch_objfile_link_map);
+ set_gdbarch_get_thread_local_address (gdbarch,
+ svr4_tls_get_thread_local_address);
+ svr4_tls_register_tls_methods (info, gdbarch, s390_linux_get_tls_dtv_addr);
/* Support reverse debugging. */
set_gdbarch_process_record_signal (gdbarch, s390_linux_record_signal);
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index d030a4d..a3b7658 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -41,6 +41,8 @@
#include "value.h"
#include "inferior.h"
#include "dwarf2/loc.h"
+#include "gdbsupport/selftest.h"
+#include "gdb/disasm-selftests.h"
#include "features/s390-linux32.c"
#include "features/s390x-linux64.c"
@@ -7468,6 +7470,51 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
return gdbarch;
}
+#if GDB_SELF_TEST
+namespace selftests {
+
+/* Return bfd_arch_info representing s390x. */
+
+static const bfd_arch_info *
+bfd_arch_info_s390x ()
+{
+ return bfd_lookup_arch (bfd_arch_s390, bfd_mach_s390_64);
+}
+
+/* Return gdbarch representing s390x. */
+
+static gdbarch *
+gdbarch_s390x ()
+{
+ struct gdbarch_info info;
+ info.bfd_arch_info = bfd_arch_info_s390x ();
+ if (info.bfd_arch_info == nullptr)
+ return nullptr;
+
+ info.osabi = GDB_OSABI_NONE;
+ return gdbarch_find_by_info (info);
+}
+
+/* Check disassembly of s390x instructions. */
+
+static void
+disassemble_s390x ()
+{
+ gdbarch *gdbarch = gdbarch_s390x ();
+ if (gdbarch == nullptr)
+ return;
+
+ scoped_restore disassembler_options_restore
+ = make_scoped_restore (&s390_disassembler_options, "zarch");
+
+ gdb::byte_vector insn = { 0xb9, 0x68, 0x00, 0x03 };
+ disassemble_insn (gdbarch, insn, "clzg\t%r0,%r3");
+}
+
+} /* namespace selftests */
+
+#endif /* GDB_SELF_TEST */
+
void _initialize_s390_tdep ();
void
_initialize_s390_tdep ()
@@ -7477,4 +7524,9 @@ _initialize_s390_tdep ()
initialize_tdesc_s390_linux32 ();
initialize_tdesc_s390x_linux64 ();
+
+#if GDB_SELF_TEST
+ selftests::register_test ("disassemble-s390x",
+ selftests::disassemble_s390x);
+#endif /* GDB_SELF_TEST */
}
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 83cb389..458c4ba 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -431,6 +431,14 @@ struct svr4_info
/* This identifies which namespaces are active. A namespace is considered
active when there is at least one shared object loaded into it. */
std::set<size_t> active_namespaces;
+
+ /* This flag indicates whether initializations related to the
+ GLIBC TLS module id tracking code have been performed. */
+ bool glibc_tls_slots_inited = false;
+
+ /* A vector of link map addresses for GLIBC TLS slots. See comment
+ for tls_maybe_fill_slot for more information. */
+ std::vector<CORE_ADDR> glibc_tls_slots;
};
/* Per-program-space data key. */
@@ -451,6 +459,12 @@ svr4_maybe_add_namespace (svr4_info *info, CORE_ADDR lmid)
info->namespace_id.push_back (lmid);
info->active_namespaces.insert (i);
+
+ /* Create or update the convenience variable "active_namespaces".
+ It only needs to be updated here, as this only changes when a
+ dlmopen or dlclose call happens. */
+ set_internalvar_integer (lookup_internalvar ("_active_linker_namespaces"),
+ info->active_namespaces.size ());
}
/* Return whether DEBUG_BASE is the default namespace of INFO. */
@@ -629,10 +643,10 @@ read_program_header (int type, int *p_arch_size, CORE_ADDR *base_addr)
return buf;
}
+/* See solib-svr4.h. */
-/* Return program interpreter string. */
-static std::optional<gdb::byte_vector>
-find_program_interpreter (void)
+std::optional<gdb::byte_vector>
+svr4_find_program_interpreter ()
{
/* If we have a current exec_bfd, use its section table. */
if (current_program_space->exec_bfd ()
@@ -1574,6 +1588,198 @@ svr4_fetch_objfile_link_map (struct objfile *objfile)
return 0;
}
+/* Return true if bfd section BFD_SECT is a thread local section
+ (i.e. either named ".tdata" or ".tbss"), and false otherwise. */
+
+static bool
+is_thread_local_section (struct bfd_section *bfd_sect)
+{
+ return ((strcmp (bfd_sect->name, ".tdata") == 0
+ || strcmp (bfd_sect->name, ".tbss") == 0)
+ && bfd_sect->size != 0);
+}
+
+/* Return true if objfile OBJF contains a thread local section, and
+ false otherwise. */
+
+static bool
+has_thread_local_section (const objfile *objf)
+{
+ for (obj_section *objsec : objf->sections ())
+ if (is_thread_local_section (objsec->the_bfd_section))
+ return true;
+ return false;
+}
+
+/* Return true if solib SO contains a thread local section, and false
+ otherwise. */
+
+static bool
+has_thread_local_section (const solib &so)
+{
+ for (const target_section &p : so.sections)
+ if (is_thread_local_section (p.the_bfd_section))
+ return true;
+ return false;
+}
+
+/* For the MUSL C library, given link map address LM_ADDR, return the
+ corresponding TLS module id, or 0 if not found.
+
+ Background: Unlike the mechanism used by glibc (see below), the
+ scheme used by the MUSL C library is pretty simple. If the
+ executable contains TLS variables it gets module id 1. Otherwise,
+ the first shared object loaded which contains TLS variables is
+ assigned to module id 1. TLS-containing shared objects are then
+ assigned consecutive module ids, based on the order that they are
+ loaded. When unloaded via dlclose, module ids are reassigned as if
+ that module had never been loaded. */
+
+int
+musl_link_map_to_tls_module_id (CORE_ADDR lm_addr)
+{
+ /* When lm_addr is zero, the program is statically linked. Any TLS
+ variables will be in module id 1. */
+ if (lm_addr == 0)
+ return 1;
+
+ int mod_id = 0;
+ if (has_thread_local_section (current_program_space->symfile_object_file))
+ mod_id++;
+
+ struct svr4_info *info = get_svr4_info (current_program_space);
+
+ /* Cause svr4_current_sos() to be run if it hasn't been already. */
+ if (info->main_lm_addr == 0)
+ solib_add (NULL, 0, auto_solib_add);
+
+ /* Handle case where lm_addr corresponds to the main program.
+ Return value is either 0, when there are no TLS variables, or 1,
+ when there are. */
+ if (lm_addr == info->main_lm_addr)
+ return mod_id;
+
+ /* Iterate through the shared objects, possibly incrementing the
+ module id, and returning mod_id should a match be found. */
+ for (const solib &so : current_program_space->solibs ())
+ {
+ if (has_thread_local_section (so))
+ mod_id++;
+
+ auto *li = gdb::checked_static_cast<lm_info_svr4 *> (so.lm_info.get ());
+ if (li->lm_addr == lm_addr)
+ return mod_id;
+ }
+ return 0;
+}
+
+/* For GLIBC, given link map address LM_ADDR, return the corresponding TLS
+ module id, or 0 if not found. */
+
+int
+glibc_link_map_to_tls_module_id (CORE_ADDR lm_addr)
+{
+ /* When lm_addr is zero, the program is statically linked. Any TLS
+ variables will be in module id 1. */
+ if (lm_addr == 0)
+ return 1;
+
+ /* Look up lm_addr in the TLS slot data structure. */
+ struct svr4_info *info = get_svr4_info (current_program_space);
+ auto it = std::find (info->glibc_tls_slots.begin (),
+ info->glibc_tls_slots.end (),
+ lm_addr);
+ if (it == info->glibc_tls_slots.end ())
+ return 0;
+ else
+ return 1 + it - info->glibc_tls_slots.begin ();
+}
+
+/* Conditionally, based on whether the shared object, SO, contains TLS
+ variables, assign a link map address to a TLS module id slot. This
+ code is GLIBC-specific and may only work for specific GLIBC
+ versions. That said, it is known to work for (at least) GLIBC
+ versions 2.27 thru 2.40.
+
+ Background: In order to implement internal TLS address lookup
+ code, it is necessary to find the module id that has been
+ associated with a specific link map address. In GLIBC, the TLS
+ module id is stored in struct link_map, in the member
+ 'l_tls_modid'. While the first several members of struct link_map
+ are part of the SVR4 ABI, the offset to l_tls_modid definitely is
+ not. Therefore, since we don't know the offset to l_tls_modid, we
+ cannot simply look it up - which is a shame, because things would
+ be so much more easy and obviously accurate, if we could access
+ l_tls_modid.
+
+ GLIBC has a concept of TLS module id slots. These slots are
+ allocated consecutively as shared objects containing TLS variables
+ are loaded. When unloaded (e.g. via dlclose()), the corresponding
+ slot is marked as unused, but may be used again when later loading
+ a shared object.
+
+ The functions tls_maybe_fill_slot and tls_maybe_erase_slot are
+ associated with the observers 'solib_loaded' and 'solib_unloaded'.
+ They (attempt to) track use of TLS module id slots in the same way
+ that GLIBC does, which will hopefully provide an accurate module id
+ when asked to provide it via glibc_link_map_to_tls_module_id(),
+ above. */
+
+static void
+tls_maybe_fill_slot (solib &so)
+{
+ struct svr4_info *info = get_svr4_info (current_program_space);
+ if (!info->glibc_tls_slots_inited)
+ {
+ /* Cause svr4_current_sos() to be run if it hasn't been already. */
+ if (info->main_lm_addr == 0)
+ svr4_current_sos_direct (info);
+
+ /* Quit early when main_lm_addr is still 0. */
+ if (info->main_lm_addr == 0)
+ return;
+
+ /* Also quit early when symfile_object_file is not yet known. */
+ if (current_program_space->symfile_object_file == nullptr)
+ return;
+
+ if (has_thread_local_section (current_program_space->symfile_object_file))
+ info->glibc_tls_slots.push_back (info->main_lm_addr);
+ info->glibc_tls_slots_inited = true;
+ }
+
+ if (has_thread_local_section (so))
+ {
+ auto it = std::find (info->glibc_tls_slots.begin (),
+ info->glibc_tls_slots.end (),
+ 0);
+ auto *li = gdb::checked_static_cast<lm_info_svr4 *> (so.lm_info.get ());
+ if (it == info->glibc_tls_slots.end ())
+ info->glibc_tls_slots.push_back (li->lm_addr);
+ else
+ *it = li->lm_addr;
+ }
+}
+
+/* Remove a link map address from the TLS module slot data structure.
+ As noted above, this code is GLIBC-specific. */
+
+static void
+tls_maybe_erase_slot (program_space *pspace, const solib &so,
+ bool still_in_use, bool silent)
+{
+ if (still_in_use)
+ return;
+
+ struct svr4_info *info = get_svr4_info (pspace);
+ auto *li = gdb::checked_static_cast<lm_info_svr4 *> (so.lm_info.get ());
+ auto it = std::find (info->glibc_tls_slots.begin (),
+ info->glibc_tls_slots.end (),
+ li->lm_addr);
+ if (it != info->glibc_tls_slots.end ())
+ *it = 0;
+}
+
/* On some systems, the only way to recognize the link map entry for
the main executable file is by looking at its name. Return
non-zero iff SONAME matches one of the known main executable names. */
@@ -2371,7 +2577,7 @@ enable_break (struct svr4_info *info, int from_tty)
/* Find the program interpreter; if not found, warn the user and drop
into the old breakpoint at symbol code. */
std::optional<gdb::byte_vector> interp_name_holder
- = find_program_interpreter ();
+ = svr4_find_program_interpreter ();
if (interp_name_holder)
{
const char *interp_name = (const char *) interp_name_holder->data ();
@@ -3552,6 +3758,54 @@ svr4_num_active_namespaces ()
return info->active_namespaces.size ();
}
+/* See solib_ops::get_solibs_in_ns in solist.h. */
+static std::vector<const solib *>
+svr4_get_solibs_in_ns (int nsid)
+{
+ std::vector<const solib*> ns_solibs;
+ svr4_info *info = get_svr4_info (current_program_space);
+
+ /* If the namespace ID is inactive, there will be no active
+ libraries, so we can have an early exit, as a treat. */
+ if (info->active_namespaces.count (nsid) != 1)
+ return ns_solibs;
+
+ /* Since we only have the names of solibs in a given namespace,
+ we'll need to walk through the solib list of the inferior and
+ find which solib objects correspond to which svr4_so. We create
+ an unordered map with the names and lm_info to check things
+ faster, and to be able to remove SOs from the map, to avoid
+ returning the dynamic linker multiple times. */
+ CORE_ADDR debug_base = info->namespace_id[nsid];
+ std::unordered_map<std::string, const lm_info_svr4 *> namespace_solibs;
+ for (svr4_so &so : info->solib_lists[debug_base])
+ {
+ namespace_solibs[so.name]
+ = gdb::checked_static_cast<const lm_info_svr4 *>
+ (so.lm_info.get ());
+ }
+ for (const solib &so: current_program_space->solibs ())
+ {
+ auto *lm_inferior
+ = gdb::checked_static_cast<const lm_info_svr4 *> (so.lm_info.get ());
+
+ /* This is inspired by the svr4_same, by finding the svr4_so object
+ in the map, and then double checking if the lm_info is considered
+ the same. */
+ if (namespace_solibs.count (so.so_original_name) > 0
+ && namespace_solibs[so.so_original_name]->l_addr_inferior
+ == lm_inferior->l_addr_inferior)
+ {
+ ns_solibs.push_back (&so);
+ /* Remove the SO from the map, so that we don't end up
+ printing the dynamic linker multiple times. */
+ namespace_solibs.erase (so.so_original_name);
+ }
+ }
+
+ return ns_solibs;
+}
+
const struct solib_ops svr4_so_ops =
{
svr4_relocate_section_addresses,
@@ -3569,6 +3823,7 @@ const struct solib_ops svr4_so_ops =
svr4_find_solib_addr,
svr4_find_solib_ns,
svr4_num_active_namespaces,
+ svr4_get_solibs_in_ns,
};
void _initialize_svr4_solib ();
@@ -3577,4 +3832,8 @@ _initialize_svr4_solib ()
{
gdb::observers::free_objfile.attach (svr4_free_objfile_observer,
"solib-svr4");
+
+ /* Set up observers for tracking GLIBC TLS module id slots. */
+ gdb::observers::solib_loaded.attach (tls_maybe_fill_slot, "solib-svr4");
+ gdb::observers::solib_unloaded.attach (tls_maybe_erase_slot, "solib-svr4");
}
diff --git a/gdb/solib-svr4.h b/gdb/solib-svr4.h
index c08bacf..e59c8e4 100644
--- a/gdb/solib-svr4.h
+++ b/gdb/solib-svr4.h
@@ -112,4 +112,16 @@ extern struct link_map_offsets *svr4_lp64_fetch_link_map_offsets (void);
SVR4 run time loader. */
int svr4_in_dynsym_resolve_code (CORE_ADDR pc);
+/* For the MUSL C library, given link map address LM_ADDR, return the
+ corresponding TLS module id, or 0 if not found. */
+int musl_link_map_to_tls_module_id (CORE_ADDR lm_addr);
+
+/* For GLIBC, given link map address LM_ADDR, return the corresponding TLS
+ module id, or 0 if not found. */
+int glibc_link_map_to_tls_module_id (CORE_ADDR lm_addr);
+
+/* Return program interpreter string. */
+
+std::optional<gdb::byte_vector> svr4_find_program_interpreter ();
+
#endif /* GDB_SOLIB_SVR4_H */
diff --git a/gdb/solib.c b/gdb/solib.c
index 4876f1a..5c5cfbd 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1010,84 +1010,61 @@ solib_add (const char *pattern, int from_tty, int readsyms)
}
}
-/* Implement the "info sharedlibrary" command. Walk through the
- shared library list and print information about each attached
- library matching PATTERN. If PATTERN is elided, print them
- all. */
+/* Helper function for "info sharedlibrary" and "info namespace".
+ This receives a list of solibs to be printed, and prints a table
+ with all the relevant data. If PRINT_NAMESPACE is true, figure out
+ the solib_ops of the current gdbarch, to calculate the namespace
+ that contains an solib.
+ Returns true if one or more solibs are missing debug information,
+ false otherwise. */
static void
-info_sharedlibrary_command (const char *pattern, int from_tty)
+print_solib_list_table (std::vector<const solib *> solib_list,
+ bool print_namespace)
{
- bool so_missing_debug_info = false;
- int addr_width;
- int nr_libs;
gdbarch *gdbarch = current_inferior ()->arch ();
- struct ui_out *uiout = current_uiout;
-
- if (pattern)
- {
- char *re_err = re_comp (pattern);
-
- if (re_err)
- error (_ ("Invalid regexp: %s"), re_err);
- }
-
/* "0x", a little whitespace, and two hex digits per byte of pointers. */
- addr_width = 4 + (gdbarch_ptr_bit (gdbarch) / 4);
-
- update_solib_list (from_tty);
-
- /* ui_out_emit_table table_emitter needs to know the number of rows,
- so we need to make two passes over the libs. */
+ int addr_width = 4 + (gdbarch_ptr_bit (gdbarch) / 4);
+ const solib_ops *ops = gdbarch_so_ops (gdbarch);
+ struct ui_out *uiout = current_uiout;
+ bool so_missing_debug_info = false;
- nr_libs = 0;
- for (const solib &so : current_program_space->solibs ())
- {
- if (!so.so_name.empty ())
- {
- if (pattern && !re_exec (so.so_name.c_str ()))
- continue;
- ++nr_libs;
- }
- }
+ /* There are 3 conditions for this command to print solib namespaces,
+ first PRINT_NAMESPACE has to be true, second the solib_ops has to
+ support multiple namespaces, and third there must be more than one
+ active namespace. Fold all these into the PRINT_NAMESPACE condition. */
+ print_namespace = print_namespace && ops->num_active_namespaces != nullptr
+ && ops->num_active_namespaces () > 1;
- /* How many columns the table should have. If the inferior has
- more than one namespace active, we need a column to show that. */
int num_cols = 4;
- const solib_ops *ops = gdbarch_so_ops (gdbarch);
- if (ops->num_active_namespaces != nullptr
- && ops->num_active_namespaces () > 1)
+ if (print_namespace)
num_cols++;
{
- ui_out_emit_table table_emitter (uiout, num_cols, nr_libs,
+ ui_out_emit_table table_emitter (uiout, num_cols, solib_list.size (),
"SharedLibraryTable");
/* The "- 1" is because ui_out adds one space between columns. */
uiout->table_header (addr_width - 1, ui_left, "from", "From");
uiout->table_header (addr_width - 1, ui_left, "to", "To");
- if (ops->num_active_namespaces != nullptr
- && ops->num_active_namespaces () > 1)
+ if (print_namespace)
uiout->table_header (5, ui_left, "namespace", "NS");
uiout->table_header (12 - 1, ui_left, "syms-read", "Syms Read");
uiout->table_header (0, ui_noalign, "name", "Shared Object Library");
uiout->table_body ();
- for (const solib &so : current_program_space->solibs ())
+ for (const solib *so : solib_list)
{
- if (so.so_name.empty ())
- continue;
-
- if (pattern && !re_exec (so.so_name.c_str ()))
+ if (so->so_name.empty ())
continue;
ui_out_emit_tuple tuple_emitter (uiout, "lib");
- if (so.addr_high != 0)
+ if (so->addr_high != 0)
{
- uiout->field_core_addr ("from", gdbarch, so.addr_low);
- uiout->field_core_addr ("to", gdbarch, so.addr_high);
+ uiout->field_core_addr ("from", gdbarch, so->addr_low);
+ uiout->field_core_addr ("to", gdbarch, so->addr_high);
}
else
{
@@ -1095,12 +1072,11 @@ info_sharedlibrary_command (const char *pattern, int from_tty)
uiout->field_skip ("to");
}
- if (ops->num_active_namespaces != nullptr
- && ops->num_active_namespaces ()> 1)
+ if (print_namespace)
{
try
{
- uiout->field_fmt ("namespace", "[[%d]]", ops->find_solib_ns (so));
+ uiout->field_fmt ("namespace", "[[%d]]", ops->find_solib_ns (*so));
}
catch (const gdb_exception_error &er)
{
@@ -1109,32 +1085,157 @@ info_sharedlibrary_command (const char *pattern, int from_tty)
}
if (!top_level_interpreter ()->interp_ui_out ()->is_mi_like_p ()
- && so.symbols_loaded && !objfile_has_symbols (so.objfile))
+ && so->symbols_loaded && !objfile_has_symbols (so->objfile))
{
so_missing_debug_info = true;
uiout->field_string ("syms-read", "Yes (*)");
}
else
- uiout->field_string ("syms-read", so.symbols_loaded ? "Yes" : "No");
+ uiout->field_string ("syms-read", so->symbols_loaded ? "Yes" : "No");
- uiout->field_string ("name", so.so_name, file_name_style.style ());
+ uiout->field_string ("name", so->so_name, file_name_style.style ());
uiout->text ("\n");
}
}
- if (nr_libs == 0)
+ if (so_missing_debug_info)
+ uiout->message (_ ("(*): Shared library is missing "
+ "debugging information.\n"));
+}
+
+/* Implement the "info sharedlibrary" command. Walk through the
+ shared library list and print information about each attached
+ library matching PATTERN. If PATTERN is elided, print them
+ all. */
+
+static void
+info_sharedlibrary_command (const char *pattern, int from_tty)
+{
+ struct ui_out *uiout = current_uiout;
+
+ if (pattern)
+ {
+ char *re_err = re_comp (pattern);
+
+ if (re_err)
+ error (_ ("Invalid regexp: %s"), re_err);
+ }
+
+ update_solib_list (from_tty);
+
+ /* ui_out_emit_table table_emitter needs to know the number of rows,
+ so we need to make two passes over the libs. */
+
+ std::vector<const solib *> print_libs;
+ for (const solib &so : current_program_space->solibs ())
+ {
+ if (!so.so_name.empty ())
+ {
+ if (pattern && !re_exec (so.so_name.c_str ()))
+ continue;
+ print_libs.push_back (&so);
+ }
+ }
+
+ print_solib_list_table (print_libs, true);
+
+ if (print_libs.size () == 0)
{
if (pattern)
uiout->message (_ ("No shared libraries matched.\n"));
else
uiout->message (_ ("No shared libraries loaded at this time.\n"));
}
+}
+
+/* Implement the "info linker-namespaces" command. If the current
+ gdbarch's solib_ops object does not support multiple namespaces,
+ this command would just look like "info sharedlibrary", so point
+ the user to that command instead.
+ If solib_ops does support multiple namespaces, this command
+ will group the libraries by linker namespace, or only print the
+ libraries in the supplied namespace. */
+static void
+info_linker_namespace_command (const char *pattern, int from_tty)
+{
+ const solib_ops *ops = gdbarch_so_ops (current_inferior ()->arch ());
+ /* This command only really makes sense for inferiors that support
+ linker namespaces, so we can leave early. */
+ if (ops->num_active_namespaces == nullptr)
+ error (_("Current inferior does not support linker namespaces." \
+ "Use \"info sharedlibrary\" instead"));
+
+ struct ui_out *uiout = current_uiout;
+ std::vector<std::pair<int, std::vector<const solib *>>> all_solibs_to_print;
+
+ if (pattern != nullptr)
+ while (*pattern == ' ')
+ pattern++;
+
+ if (pattern == nullptr || pattern[0] == '\0')
+ {
+ uiout->message (_ ("There are %d linker namespaces loaded\n"),
+ ops->num_active_namespaces ());
+
+ int printed = 0;
+ for (int i = 0; printed < ops->num_active_namespaces (); i++)
+ {
+ std::vector<const solib *> solibs_to_print
+ = ops->get_solibs_in_ns (i);
+ if (solibs_to_print.size () > 0)
+ {
+ all_solibs_to_print.push_back (std::make_pair
+ (i, solibs_to_print));
+ printed++;
+ }
+ }
+ }
else
{
- if (so_missing_debug_info)
- uiout->message (_ ("(*): Shared library is missing "
- "debugging information.\n"));
+ int ns;
+ /* Check if the pattern includes the optional [[ and ]] decorators.
+ To match multiple occurrences, '+' needs to be escaped, and every
+ escape sequence must be doubled to survive the compiler pass. */
+ re_comp ("^\\[\\[[0-9]\\+\\]\\]$");
+ if (re_exec (pattern))
+ ns = strtol (pattern+2, nullptr, 10);
+ else
+ {
+ char * end = nullptr;
+ ns = strtol (pattern, &end, 10);
+ if (end[0] != '\0')
+ error (_ ("Invalid linker namespace identifier: %s"), pattern);
+ }
+
+ all_solibs_to_print.push_back
+ (std::make_pair (ns, ops->get_solibs_in_ns (ns)));
+ }
+
+ bool ns_separator = false;
+
+ for (auto &solibs_pair : all_solibs_to_print)
+ {
+ if (ns_separator)
+ uiout->message ("\n\n");
+ else
+ ns_separator = true;
+ int ns = solibs_pair.first;
+ std::vector<const solib *> solibs_to_print = solibs_pair.second;
+ if (solibs_to_print.size () == 0)
+ {
+ uiout->message (_("Linker namespace [[%d]] is not active.\n"), ns);
+ /* If we got here, a specific namespace was requested, so there
+ will only be one vector. We can leave early. */
+ break;
+ }
+ uiout->message
+ (_ ("There are %ld libraries loaded in linker namespace [[%d]]\n"),
+ solibs_to_print.size (), ns);
+ uiout->message
+ (_ ("Displaying libraries for linker namespace [[%d]]:\n"), ns);
+
+ print_solib_list_table (solibs_to_print, false);
}
}
@@ -1715,6 +1816,44 @@ default_find_solib_addr (solib &so)
return {};
}
+/* Implementation of the current_linker_namespace convenience variable.
+ This returns the GDB internal identifier of the linker namespace,
+ for the current frame, in the form '[[<number>]]'. If the inferior
+ doesn't support linker namespaces, this always returns [[0]]. */
+
+static value *
+current_linker_namespace_make_value (gdbarch *gdbarch, internalvar *var,
+ void *ignore)
+{
+ const solib_ops *ops = gdbarch_so_ops (gdbarch);
+ const language_defn *lang = language_def (get_frame_language
+ (get_current_frame ()));
+ std::string nsid = "[[0]]";
+ if (ops->find_solib_ns != nullptr)
+ {
+ CORE_ADDR curr_pc = get_frame_pc (get_current_frame ());
+ for (const solib &so : current_program_space->solibs ())
+ if (solib_contains_address_p (so, curr_pc))
+ {
+ nsid = string_printf ("[[%d]]", ops->find_solib_ns (so));
+ break;
+ }
+ }
+
+
+ /* If the PC is not in an SO, or the solib_ops doesn't support
+ linker namespaces, the inferior is in the default namespace. */
+ return lang->value_string (gdbarch, nsid.c_str (), nsid.length ());
+}
+
+/* Implementation of `$_current_linker_namespace' variable. */
+
+static const struct internalvar_funcs current_linker_namespace_funcs =
+{
+ current_linker_namespace_make_value,
+ nullptr,
+};
+
void _initialize_solib ();
void
@@ -1727,6 +1866,13 @@ _initialize_solib ()
},
"solib");
+ /* Convenience variables for debugging linker namespaces. These are
+ set here, even if the solib_ops doesn't support them,
+ for consistency. */
+ create_internalvar_type_lazy ("_current_linker_namespace",
+ &current_linker_namespace_funcs, nullptr);
+ set_internalvar_integer (lookup_internalvar ("_active_linker_namespaces"), 1);
+
add_com (
"sharedlibrary", class_files, sharedlibrary_command,
_ ("Load shared object library symbols for files matching REGEXP."));
@@ -1737,6 +1883,9 @@ _initialize_solib ()
add_com ("nosharedlibrary", class_files, no_shared_libraries_command,
_ ("Unload all shared object library symbols."));
+ add_info ("linker-namespaces", info_linker_namespace_command,
+ _ ("Get information about linker namespaces in the inferior."));
+
add_setshow_boolean_cmd ("auto-solib-add", class_support, &auto_solib_add,
_ ("\
Set autoloading of shared library symbols."),
diff --git a/gdb/solist.h b/gdb/solist.h
index 0b7bbf9..6ab5a06 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -194,6 +194,10 @@ struct solib_ops
/* Returns the number of active namespaces in the inferior. */
int (*num_active_namespaces) ();
+
+ /* Returns all solibs for a given namespace. If the namespace is not
+ active, returns an empty vector. */
+ std::vector<const solib *> (*get_solibs_in_ns) (int ns);
};
/* A unique pointer to a so_list. */
diff --git a/gdb/svr4-tls-tdep.c b/gdb/svr4-tls-tdep.c
new file mode 100644
index 0000000..56e1470
--- /dev/null
+++ b/gdb/svr4-tls-tdep.c
@@ -0,0 +1,256 @@
+/* Target-dependent code for GNU/Linux, architecture independent.
+
+ Copyright (C) 2009-2024 Free Software Foundation, Inc.
+
+ 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/>. */
+
+#include "svr4-tls-tdep.h"
+#include "solib-svr4.h"
+#include "inferior.h"
+#include "objfiles.h"
+#include "cli/cli-cmds.h"
+#include <optional>
+
+struct svr4_tls_gdbarch_data
+{
+ /* Method for looking up TLS DTV. */
+ get_tls_dtv_addr_ftype *get_tls_dtv_addr = nullptr;
+
+ /* Method for looking up the TLS DTP offset. */
+ get_tls_dtp_offset_ftype *get_tls_dtp_offset = nullptr;
+
+ /* Cached libc value for TLS lookup purposes. */
+ enum svr4_tls_libc libc = svr4_tls_libc_unknown;
+};
+
+static const registry<gdbarch>::key<svr4_tls_gdbarch_data>
+ svr4_tls_gdbarch_data_handle;
+
+static struct svr4_tls_gdbarch_data *
+get_svr4_tls_gdbarch_data (struct gdbarch *gdbarch)
+{
+ struct svr4_tls_gdbarch_data *result = svr4_tls_gdbarch_data_handle.get (gdbarch);
+ if (result == nullptr)
+ result = svr4_tls_gdbarch_data_handle.emplace (gdbarch);
+ return result;
+}
+
+/* When true, force internal TLS address lookup instead of lookup via
+ the thread stratum. */
+
+static bool force_internal_tls_address_lookup = false;
+
+/* For TLS lookup purposes, use heuristics to decide whether program
+ was linked against MUSL or GLIBC. */
+
+static enum svr4_tls_libc
+libc_tls_sniffer (struct gdbarch *gdbarch)
+{
+ /* Check for cached libc value. */
+ svr4_tls_gdbarch_data *gdbarch_data = get_svr4_tls_gdbarch_data (gdbarch);
+ if (gdbarch_data->libc != svr4_tls_libc_unknown)
+ return gdbarch_data->libc;
+
+ svr4_tls_libc libc = svr4_tls_libc_unknown;
+
+ /* Fetch the program interpreter. */
+ std::optional<gdb::byte_vector> interp_name_holder
+ = svr4_find_program_interpreter ();
+ if (interp_name_holder)
+ {
+ /* A dynamically linked program linked against MUSL will have a
+ "ld-musl-" in its interpreter name. (Two examples of MUSL
+ interpreter names are "/lib/ld-musl-x86_64.so.1" and
+ "lib/ld-musl-aarch64.so.1".) If it's not found, assume GLIBC. */
+ const char *interp_name = (const char *) interp_name_holder->data ();
+ if (strstr (interp_name, "/ld-musl-") != nullptr)
+ libc = svr4_tls_libc_musl;
+ else
+ libc = svr4_tls_libc_glibc;
+ gdbarch_data->libc = libc;
+ return libc;
+ }
+
+ /* If there is no interpreter name, it's statically linked. For
+ programs with TLS data, a program statically linked against MUSL
+ will have the symbols 'main_tls' and 'builtin_tls'. If both of
+ these are present, assume that it was statically linked against
+ MUSL, otherwise assume GLIBC. */
+ if (lookup_minimal_symbol (current_program_space, "main_tls").minsym
+ != nullptr
+ && lookup_minimal_symbol (current_program_space, "builtin_tls").minsym
+ != nullptr)
+ libc = svr4_tls_libc_musl;
+ else
+ libc = svr4_tls_libc_glibc;
+ gdbarch_data->libc = libc;
+ return libc;
+}
+
+/* Implement gdbarch method, get_thread_local_address, for architectures
+ which provide a method for determining the DTV and possibly the DTP
+ offset. */
+
+CORE_ADDR
+svr4_tls_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
+ CORE_ADDR lm_addr, CORE_ADDR offset)
+{
+ svr4_tls_gdbarch_data *gdbarch_data = get_svr4_tls_gdbarch_data (gdbarch);
+
+ /* Use the target's get_thread_local_address method when:
+
+ - No method has been provided for finding the TLS DTV.
+
+ or
+
+ - The thread stratum has been pushed (at some point) onto the
+ target stack, except when 'force_internal_tls_address_lookup'
+ has been set.
+
+ The idea here is to prefer use of of the target's thread_stratum
+ method since it should be more accurate. */
+ if (gdbarch_data->get_tls_dtv_addr == nullptr
+ || (find_target_at (thread_stratum) != nullptr
+ && !force_internal_tls_address_lookup))
+ {
+ struct target_ops *target = current_inferior ()->top_target ();
+ return target->get_thread_local_address (ptid, lm_addr, offset);
+ }
+ else
+ {
+ /* Details, found below, regarding TLS layout is for the GNU C
+ library (glibc) and the MUSL C library (musl), circa 2024.
+ While some of this layout is defined by the TLS ABI, some of
+ it, such as how/where to find the DTV pointer in the TCB, is
+ not. A good source of ABI info for some architectures can be
+ found in "ELF Handling For Thread-Local Storage" by Ulrich
+ Drepper. That document is worth consulting even for
+ architectures not described there, since the general approach
+ and terminology is used regardless.
+
+ Some architectures, such as aarch64, are not described in
+ that document, so some details had to ferreted out using the
+ glibc source code. Likewise, the MUSL source code was
+ consulted for details which differ from GLIBC. */
+ enum svr4_tls_libc libc = libc_tls_sniffer (gdbarch);
+ int mod_id;
+ if (libc == svr4_tls_libc_glibc)
+ mod_id = glibc_link_map_to_tls_module_id (lm_addr);
+ else /* Assume MUSL. */
+ mod_id = musl_link_map_to_tls_module_id (lm_addr);
+ if (mod_id == 0)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to determine TLS module id"));
+
+ /* Use the architecture specific DTV fetcher to obtain the DTV. */
+ CORE_ADDR dtv_addr = gdbarch_data->get_tls_dtv_addr (gdbarch, ptid, libc);
+
+ /* In GLIBC, The DTV (dynamic thread vector) is an array of
+ structs consisting of two fields, the first of which is a
+ pointer to the TLS block of interest. (The second field is a
+ pointer that assists with memory management, but that's not
+ of interest here.) Also, the 0th entry is the generation
+ number, but although it's a single scalar, the 0th entry is
+ padded to be the same size as all the rest. Thus each
+ element of the DTV array is two pointers in size.
+
+ In MUSL, the DTV is simply an array of pointers. The 0th
+ entry is still the generation number, but contains no padding
+ aside from that which is needed to make it pointer sized. */
+ int m; /* Multiplier, for size of DTV entry. */
+ switch (libc)
+ {
+ case svr4_tls_libc_glibc:
+ m = 2;
+ break;
+ default:
+ m = 1;
+ break;
+ }
+
+ /* Obtain TLS block address. Module ids start at 1, so there's
+ no need to adjust it to skip over the 0th entry of the DTV,
+ which is the generation number. */
+ CORE_ADDR dtv_elem_addr
+ = dtv_addr + mod_id * m * (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
+ gdb::byte_vector buf (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
+ if (target_read_memory (dtv_elem_addr, buf.data (), buf.size ()) != 0)
+ throw_error (TLS_GENERIC_ERROR, _("Unable to fetch TLS block address"));
+ const struct builtin_type *builtin = builtin_type (gdbarch);
+ CORE_ADDR tls_block_addr = gdbarch_pointer_to_address
+ (gdbarch, builtin->builtin_data_ptr,
+ buf.data ());
+
+ /* When the TLS block addr is 0 or -1, this usually indicates that
+ the TLS storage hasn't been allocated yet. (In GLIBC, some
+ architectures use 0 while others use -1.) */
+ if (tls_block_addr == 0 || tls_block_addr == (CORE_ADDR) -1)
+ throw_error (TLS_NOT_ALLOCATED_YET_ERROR, _("TLS not allocated yet"));
+
+ /* MUSL (and perhaps other C libraries, though not GLIBC) have
+ TLS implementations for some architectures which, for some
+ reason, have DTV entries which must be negatively offset by
+ DTP_OFFSET in order to obtain the TLS block address.
+ DTP_OFFSET is a constant in the MUSL sources - these offsets,
+ when they're non-zero, seem to be either 0x800 or 0x8000,
+ and are present for riscv[32/64], powerpc[32/64], m68k, and
+ mips.
+
+ Use the architecture specific get_tls_dtp_offset method, if
+ present, to obtain this offset. */
+ ULONGEST dtp_offset
+ = gdbarch_data->get_tls_dtp_offset == nullptr
+ ? 0
+ : gdbarch_data->get_tls_dtp_offset (gdbarch, ptid, libc);
+
+ return tls_block_addr - dtp_offset + offset;
+ }
+}
+
+/* See svr4-tls-tdep.h. */
+
+void
+svr4_tls_register_tls_methods (struct gdbarch_info info, struct gdbarch *gdbarch,
+ get_tls_dtv_addr_ftype *get_tls_dtv_addr,
+ get_tls_dtp_offset_ftype *get_tls_dtp_offset)
+{
+ gdb_assert (get_tls_dtv_addr != nullptr);
+
+ svr4_tls_gdbarch_data *gdbarch_data = get_svr4_tls_gdbarch_data (gdbarch);
+ gdbarch_data->get_tls_dtv_addr = get_tls_dtv_addr;
+ gdbarch_data->get_tls_dtp_offset = get_tls_dtp_offset;
+}
+
+void _initialize_svr4_tls_tdep ();
+void
+_initialize_svr4_tls_tdep ()
+{
+ add_setshow_boolean_cmd ("force-internal-tls-address-lookup", class_obscure,
+ &force_internal_tls_address_lookup, _("\
+Set to force internal TLS address lookup."), _("\
+Show whether GDB is forced to use internal TLS address lookup."), _("\
+When resolving addresses for TLS (Thread Local Storage) variables,\n\
+GDB will attempt to use facilities provided by the thread library (i.e.\n\
+libthread_db). If those facilities aren't available, GDB will fall\n\
+back to using some internal (to GDB), but possibly less accurate\n\
+mechanisms to resolve the addresses for TLS variables. When this flag\n\
+is set, GDB will force use of the fall-back TLS resolution mechanisms.\n\
+This flag is used by some GDB tests to ensure that the internal fallback\n\
+code is exercised and working as expected. The default is to not force\n\
+the internal fall-back mechanisms to be used."),
+ NULL, NULL,
+ &maintenance_set_cmdlist,
+ &maintenance_show_cmdlist);
+}
diff --git a/gdb/svr4-tls-tdep.h b/gdb/svr4-tls-tdep.h
new file mode 100644
index 0000000..73efc02
--- /dev/null
+++ b/gdb/svr4-tls-tdep.h
@@ -0,0 +1,59 @@
+/* Target-dependent code for GNU/Linux, architecture independent.
+
+ Copyright (C) 2025 Free Software Foundation, Inc.
+
+ 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_SVR4_TLS_TDEP_H
+#define GDB_SVR4_TLS_TDEP_H
+
+/* C library variants for TLS lookup. */
+
+enum svr4_tls_libc
+{
+ svr4_tls_libc_unknown,
+ svr4_tls_libc_musl,
+ svr4_tls_libc_glibc
+};
+
+/* Function type for "get_tls_dtv_addr" method. */
+
+typedef CORE_ADDR (get_tls_dtv_addr_ftype) (struct gdbarch *gdbarch,
+ ptid_t ptid,
+ enum svr4_tls_libc libc);
+
+/* Function type for "get_tls_dtp_offset" method. */
+
+typedef CORE_ADDR (get_tls_dtp_offset_ftype) (struct gdbarch *gdbarch,
+ ptid_t ptid,
+ enum svr4_tls_libc libc);
+
+/* Register architecture specific methods for fetching the TLS DTV
+ and TLS DTP, used by linux_get_thread_local_address. */
+
+extern void svr4_tls_register_tls_methods
+ (struct gdbarch_info info, struct gdbarch *gdbarch,
+ get_tls_dtv_addr_ftype *get_tls_dtv_addr,
+ get_tls_dtp_offset_ftype *get_tls_dtp_offset = nullptr);
+
+/* Used as a gdbarch method for get_thread_local_address when the tdep
+ file also defines a suitable method for obtaining the TLS DTV.
+ See linux_init_abi(), above. */
+CORE_ADDR
+svr4_tls_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid,
+ CORE_ADDR lm_addr, CORE_ADDR offset);
+
+#endif /* GDB_SVR4_TLS_TDEP_H */
diff --git a/gdb/syscalls/riscv-canonicalize-syscall-gen.py b/gdb/syscalls/riscv-canonicalize-syscall-gen.py
new file mode 100755
index 0000000..40039bb
--- /dev/null
+++ b/gdb/syscalls/riscv-canonicalize-syscall-gen.py
@@ -0,0 +1,171 @@
+#!/usr/bin/env python3
+# pylint: disable=invalid-name
+
+# Copyright (C) 2024-2025 Free Software Foundation, Inc.
+# Contributed by Timur Golubovich
+
+# 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/>.
+
+
+# To get help message for this script, run:
+# ./gdb/syscalls/riscv-canonicalize-syscall-gen.py --help
+
+# Execution result:
+
+# usage: riscv-canonicalize-syscall-gen.py [-h] -i INPUT
+#
+# Generate file gdb/riscv-canonicalize-syscall-gen.c from path to riscv linux syscalls.
+#
+# options:
+# -h, --help show this help message and exit
+# -i INPUT, --input INPUT
+# path to riscv linux syscalls (glibc/sysdeps/unix/sysv/linux/riscv/rv64/arch-syscall.h)
+
+import argparse
+import re
+import sys
+from pathlib import Path as _Path
+
+head = """\
+/* DO NOT EDIT: Autogenerated by riscv-canonicalize-syscall-gen.py
+
+ Copyright (C) 2024-2025 Free Software Foundation, Inc.
+
+ 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/>. */
+
+#include "defs.h"
+#include "riscv-linux-tdep.h"
+
+/* riscv64_canonicalize_syscall maps from the native riscv 64 Linux set
+ of syscall ids into a canonical set of syscall ids used by
+ process record. */
+
+enum gdb_syscall
+riscv64_canonicalize_syscall (int syscall)
+{
+ switch (syscall)
+ {
+"""
+
+tail = """\
+ default:
+ return gdb_sys_no_syscall;
+ }
+}
+"""
+
+
+class Generator:
+ def _get_gdb_syscalls(self, gdb_syscalls_path: _Path) -> list[str]:
+ gdb_syscalls: list[str] = []
+ with open(gdb_syscalls_path, "r", encoding="UTF-8") as file:
+ lines = file.readlines()
+ for line in lines:
+ match = re.search(r"\s*(?P<name>gdb_sys_[^S]+)\S*=", line)
+ if match:
+ gdb_syscalls.append(match.group("name").strip())
+ return gdb_syscalls
+
+ def _get_canon_syscalls_lines(
+ self, syscalls_path: _Path, gdb_syscalls: list[str]
+ ) -> list[str]:
+ canon_syscalls: dict[int, str] = {}
+ with open(syscalls_path, "r", encoding="UTF-8") as file:
+ lines = file.readlines()
+ for line in lines:
+ match = re.match(
+ r"#define\s+__NR_(?P<name>[^\s]+)\s+(?P<number>\d+)", line
+ )
+ if match:
+ syscall_name = match.group("name")
+ syscall_num = int(match.group("number"))
+ gdb_syscall_name = f"gdb_sys_{syscall_name}"
+ if gdb_syscall_name in gdb_syscalls:
+ value = f" case {syscall_num}: return {gdb_syscall_name};\n"
+ canon_syscalls[syscall_num] = value
+ # this is a place for corner cases
+ elif syscall_name == "mmap":
+ gdb_old_syscall_name = "gdb_sys_old_mmap"
+ value = (
+ f" case {syscall_num}: return {gdb_old_syscall_name};\n"
+ )
+ canon_syscalls[syscall_num] = value
+ else:
+ value = f" /* case {syscall_num}: return {gdb_syscall_name}; */\n"
+ canon_syscalls[syscall_num] = value
+ return [canon_syscalls[syscall_num] for syscall_num in sorted(canon_syscalls)]
+
+ def generate(self, syscalls_path: _Path) -> None:
+ repo_path = _Path(__file__).parent.parent.parent
+ gdb_syscalls_path = repo_path / "gdb" / "linux-record.h"
+ canon_syscalls_path = repo_path / "gdb" / "riscv-canonicalize-syscall-gen.c"
+
+ gdb_syscalls = self._get_gdb_syscalls(gdb_syscalls_path)
+ canon_syscalls_lines = self._get_canon_syscalls_lines(
+ syscalls_path, gdb_syscalls
+ )
+
+ with open(canon_syscalls_path, "w", encoding="UTF-8") as file:
+ file.writelines(head)
+ file.writelines(canon_syscalls_lines)
+ file.writelines(tail)
+
+
+help_message = """\
+Generate file gdb/riscv-canonicalize-syscall-gen.c
+from path to riscv linux syscalls.
+"""
+
+
+def setup_parser() -> argparse.ArgumentParser:
+ parser = argparse.ArgumentParser(description=help_message)
+ parser.add_argument(
+ "-i",
+ "--input",
+ type=_Path,
+ required=True,
+ help="path to riscv linux syscalls (glibc/sysdeps/unix/sysv/linux/riscv/rv64/arch-syscall.h)",
+ )
+ return parser
+
+
+def main(argv: list[str]) -> int:
+ try:
+ parser = setup_parser()
+ args = parser.parse_args(argv)
+ generator = Generator()
+ generator.generate(args.input)
+ return 0
+ except RuntimeError as e:
+ print(str(e))
+ return -1
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv[1:]))
diff --git a/gdb/target.c b/gdb/target.c
index 4a1964e..522bed8 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1250,11 +1250,21 @@ generic_tls_error (void)
_("Cannot find thread-local variables on this target"));
}
-/* Using the objfile specified in OBJFILE, find the address for the
- current thread's thread-local storage with offset OFFSET. */
+/* See target.h. */
+
CORE_ADDR
-target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
+target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset,
+ const char *name)
{
+ if (!target_has_registers ())
+ {
+ if (name == nullptr)
+ error (_("Cannot translate TLS address without registers"));
+ else
+ error (_("Cannot find address of TLS symbol `%s' without registers"),
+ name);
+ }
+
volatile CORE_ADDR addr = 0;
struct target_ops *target = current_inferior ()->top_target ();
gdbarch *gdbarch = current_inferior ()->arch ();
diff --git a/gdb/target.h b/gdb/target.h
index 004494d..2d3bac7 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -2472,8 +2472,14 @@ extern void target_pre_inferior ();
extern void target_preopen (int);
+/* Using the objfile specified in OBJFILE, find the address for the
+ current thread's thread-local storage with offset OFFSET. If it's
+ provided, NAME might be used to indicate the relevant variable
+ in an error message. */
+
extern CORE_ADDR target_translate_tls_address (struct objfile *objfile,
- CORE_ADDR offset);
+ CORE_ADDR offset,
+ const char *name = nullptr);
/* Return the "section" containing the specified address. */
const struct target_section *target_section_by_addr (struct target_ops *target,
diff --git a/gdb/testsuite/analyze-racy-logs.py b/gdb/testsuite/analyze-racy-logs.py
index e7c5647..f24bea9 100755
--- a/gdb/testsuite/analyze-racy-logs.py
+++ b/gdb/testsuite/analyze-racy-logs.py
@@ -62,7 +62,6 @@ sum_matcher = re.compile("^(.?(PASS|FAIL)): (.*)$")
def parse_sum_line(line: str, dic: dict[str, set[str]]):
"""Parse a single LINE from a sumfile, and store the results in the
dictionary referenced by DIC."""
- global sum_matcher
line = line.rstrip()
m = re.match(sum_matcher, line)
@@ -96,7 +95,6 @@ def read_sum_files(files: list[str]):
"""Read the sumfiles (passed as a list in the FILES variable), and
process each one, filling the FILES_AND_TESTS global dictionary with
information about them."""
- global files_and_tests
for x in files:
with open(x, "r") as f:
@@ -115,7 +113,6 @@ def identify_racy_tests():
This function does that for all sets (PASS, FAIL, KPASS, KFAIL, etc.),
and then print a sorted list (without duplicates) of all the tests
that were found to be racy."""
- global files_and_tests
# First, construct two dictionaries that will hold one set of
# testcases for each state (PASS, FAIL, etc.).
diff --git a/gdb/testsuite/boards/cc-with-dwz-5.exp b/gdb/testsuite/boards/cc-with-dwz-5.exp
new file mode 100644
index 0000000..b254f91
--- /dev/null
+++ b/gdb/testsuite/boards/cc-with-dwz-5.exp
@@ -0,0 +1,28 @@
+# 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/>.
+
+# This file is a dejagnu "board file" and is used to run the testsuite
+# with contrib/cc-with-tweaks.sh -5.
+#
+# NOTE: We assume dwz is in $PATH.
+#
+# Example usage:
+# bash$ cd $objdir
+# bash$ make check-gdb \
+# RUNTESTFLAGS='--target_board=cc-with-dwz-5'
+#
+
+set CC_WITH_TWEAKS_FLAGS "-5"
+load_board_description "cc-with-tweaks"
diff --git a/gdb/testsuite/gdb.ada/scalar_storage.exp b/gdb/testsuite/gdb.ada/scalar_storage.exp
index 6b29226..52a85cd 100644
--- a/gdb/testsuite/gdb.ada/scalar_storage.exp
+++ b/gdb/testsuite/gdb.ada/scalar_storage.exp
@@ -45,10 +45,30 @@ if {![runto "storage.adb:$bp_location"]} {
return
}
-gdb_test "print V_LE" "= \\(value => 126, another_value => 12, color => green\\)"
+set re "value => 126, another_value => 12, color => green"
# This requires a compiler fix that is in GCC 14.
-if { ![gnat_version_compare >= 14] } {
- setup_kfail "DW_AT_endianity on enum types" *-*-*
+set have_xfail [expr ![gnat_version_compare >= 14]]
+set re_color "(red|green|blue|$decimal)"
+set re_xfail \
+ "value => $decimal, another_value => $decimal, color => $re_color"
+
+set re_pre [string_to_regexp " = ("]
+set re_post [string_to_regexp ")"]
+set re $re_pre$re$re_post
+set re_xfail $re_pre$re_xfail$re_post
+
+foreach var { V_LE V_BE } {
+ gdb_test_multiple "print $var" "" {
+ -re -wrap $re {
+ pass $gdb_test_name
+ }
+ -re -wrap $re_xfail {
+ if { $have_xfail } {
+ xfail $gdb_test_name
+ } else {
+ fail $gdb_test_name
+ }
+ }
+ }
}
-gdb_test "print V_BE" "= \\(value => 126, another_value => 12, color => green\\)"
diff --git a/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.c b/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.c
new file mode 100644
index 0000000..c86beaf
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.c
@@ -0,0 +1,205 @@
+/* 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/>. */
+
+/* Exercise unwinding AArch64's SVE registers from a signal frame. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/prctl.h>
+#include <unistd.h>
+
+static int second_vl = 0;
+
+static void
+initialize_sve_state_main ()
+{
+ __asm __volatile ("dup z0.b, -1");
+ __asm __volatile ("dup z1.b, -1");
+ __asm __volatile ("dup z2.b, -1");
+ __asm __volatile ("dup z3.b, -1");
+ __asm __volatile ("dup z4.b, -1");
+ __asm __volatile ("dup z5.b, -1");
+ __asm __volatile ("dup z6.b, -1");
+ __asm __volatile ("dup z7.b, -1");
+ __asm __volatile ("dup z8.b, -1");
+ __asm __volatile ("dup z9.b, -1");
+ __asm __volatile ("dup z10.b, -1");
+ __asm __volatile ("dup z11.b, -1");
+ __asm __volatile ("dup z12.b, -1");
+ __asm __volatile ("dup z13.b, -1");
+ __asm __volatile ("dup z14.b, -1");
+ __asm __volatile ("dup z15.b, -1");
+ __asm __volatile ("dup z16.b, -1");
+ __asm __volatile ("dup z17.b, -1");
+ __asm __volatile ("dup z18.b, -1");
+ __asm __volatile ("dup z19.b, -1");
+ __asm __volatile ("dup z20.b, -1");
+ __asm __volatile ("dup z21.b, -1");
+ __asm __volatile ("dup z22.b, -1");
+ __asm __volatile ("dup z23.b, -1");
+ __asm __volatile ("dup z24.b, -1");
+ __asm __volatile ("dup z25.b, -1");
+ __asm __volatile ("dup z26.b, -1");
+ __asm __volatile ("dup z27.b, -1");
+ __asm __volatile ("dup z28.b, -1");
+ __asm __volatile ("dup z29.b, -1");
+ __asm __volatile ("dup z30.b, -1");
+ __asm __volatile ("dup z31.b, -1");
+ __asm __volatile ("ptrue p0.d");
+ __asm __volatile ("ptrue p1.d");
+ __asm __volatile ("ptrue p2.d");
+ __asm __volatile ("ptrue p3.d");
+ __asm __volatile ("ptrue p4.d");
+ __asm __volatile ("ptrue p5.d");
+ __asm __volatile ("ptrue p6.d");
+ __asm __volatile ("ptrue p7.d");
+ __asm __volatile ("ptrue p8.d");
+ __asm __volatile ("ptrue p9.d");
+ __asm __volatile ("ptrue p10.d");
+ __asm __volatile ("ptrue p11.d");
+ __asm __volatile ("ptrue p12.d");
+ __asm __volatile ("ptrue p13.d");
+ __asm __volatile ("ptrue p14.d");
+ __asm __volatile ("ptrue p15.d");
+ __asm __volatile ("setffr");
+}
+
+static void
+initialize_sve_state_sighandler ()
+{
+ __asm __volatile ("dup z0.b, -2");
+ __asm __volatile ("dup z1.b, -2");
+ __asm __volatile ("dup z2.b, -2");
+ __asm __volatile ("dup z3.b, -2");
+ __asm __volatile ("dup z4.b, -2");
+ __asm __volatile ("dup z5.b, -2");
+ __asm __volatile ("dup z6.b, -2");
+ __asm __volatile ("dup z7.b, -2");
+ __asm __volatile ("dup z8.b, -2");
+ __asm __volatile ("dup z9.b, -2");
+ __asm __volatile ("dup z10.b, -2");
+ __asm __volatile ("dup z11.b, -2");
+ __asm __volatile ("dup z12.b, -2");
+ __asm __volatile ("dup z13.b, -2");
+ __asm __volatile ("dup z14.b, -2");
+ __asm __volatile ("dup z15.b, -2");
+ __asm __volatile ("dup z16.b, -2");
+ __asm __volatile ("dup z17.b, -2");
+ __asm __volatile ("dup z18.b, -2");
+ __asm __volatile ("dup z19.b, -2");
+ __asm __volatile ("dup z20.b, -2");
+ __asm __volatile ("dup z21.b, -2");
+ __asm __volatile ("dup z22.b, -2");
+ __asm __volatile ("dup z23.b, -2");
+ __asm __volatile ("dup z24.b, -2");
+ __asm __volatile ("dup z25.b, -2");
+ __asm __volatile ("dup z26.b, -2");
+ __asm __volatile ("dup z27.b, -2");
+ __asm __volatile ("dup z28.b, -2");
+ __asm __volatile ("dup z29.b, -2");
+ __asm __volatile ("dup z30.b, -2");
+ __asm __volatile ("dup z31.b, -2");
+ __asm __volatile ("pfalse p0.b");
+ __asm __volatile ("pfalse p1.b");
+ __asm __volatile ("pfalse p2.b");
+ __asm __volatile ("pfalse p3.b");
+ __asm __volatile ("pfalse p4.b");
+ __asm __volatile ("pfalse p5.b");
+ __asm __volatile ("pfalse p6.b");
+ __asm __volatile ("pfalse p7.b");
+ __asm __volatile ("pfalse p8.b");
+ __asm __volatile ("pfalse p9.b");
+ __asm __volatile ("pfalse p10.b");
+ __asm __volatile ("pfalse p11.b");
+ __asm __volatile ("pfalse p12.b");
+ __asm __volatile ("pfalse p13.b");
+ __asm __volatile ("pfalse p14.b");
+ __asm __volatile ("pfalse p15.b");
+ __asm __volatile ("setffr");
+}
+
+/* Set new value for the SVE vector length.
+ Return the value that was set. */
+
+static int
+set_vl (int vl)
+{
+ int rc;
+
+ rc = prctl (PR_SVE_SET_VL, vl, 0, 0, 0);
+ if (rc < 0)
+ {
+ perror ("FAILED to PR_SVE_SET_VL");
+ exit (EXIT_FAILURE);
+ }
+
+ return rc & PR_SVE_VL_LEN_MASK;
+}
+
+static void
+sighandler (int sig, siginfo_t *info, void *ucontext)
+{
+ /* Set vector length to the second value. */
+ second_vl = set_vl (second_vl);
+ initialize_sve_state_sighandler ();
+ printf ("sighandler: second_vl = %d\n", second_vl); /* Break here. */
+}
+
+int
+main (int argc, char *argv[])
+{
+ if (argc != 3)
+ {
+ fprintf (stderr, "Usage: %s <first vl> <second vl>\n", argv[0]);
+ return 1;
+ }
+
+ int first_vl = atoi (argv[1]);
+ second_vl = atoi (argv[2]);
+
+ if (first_vl == 0 || second_vl == 0)
+ {
+ fprintf (stderr, "Invalid vector length.\n");
+ return 1;
+ }
+
+ /* Set vector length to the first value. */
+ first_vl = set_vl (first_vl);
+
+ printf ("main: first_vl = %d\n", first_vl);
+
+ unsigned char buf[256];
+
+ /* Use an SVE register to make the kernel start saving the SVE bank. */
+ asm volatile ("mov z0.b, #255\n\t"
+ "str z0, %0"
+ :
+ : "m" (buf)
+ : "z0", "memory");
+
+ initialize_sve_state_main ();
+
+ struct sigaction sigact;
+ sigact.sa_sigaction = sighandler;
+ sigact.sa_flags = SA_SIGINFO;
+ sigaction (SIGUSR1, &sigact, NULL);
+
+ kill (getpid (), SIGUSR1);
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.exp b/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.exp
new file mode 100644
index 0000000..32340bb
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.exp
@@ -0,0 +1,106 @@
+# 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/>.
+
+# Exercise unwinding AArch64's SVE registers from a signal frame.
+
+require allow_aarch64_sve_tests
+# Remote targets can't communicate vector length changes to GDB via the RSP.
+require !gdb_protocol_is_remote
+
+set first_vl 0
+set second_vl 0
+
+# Find two valid VL values to use in the test.
+# The minimum supported VL is 16 bytes, maximum is 256 bytes, and VL can change
+# in increments of at least 16 bytes.
+for {set i 16} {$i <= 256} {incr i 16} {
+ if {![aarch64_supports_sve_vl $i]} {
+ continue
+ }
+
+ if {$first_vl == 0} {
+ set first_vl $i
+ } elseif {$second_vl == 0} {
+ set second_vl $i
+ break
+ }
+}
+
+if {$first_vl == 0 || $second_vl == 0} {
+ untested "test needs to support at least two vector lengths"
+ return
+}
+
+standard_testfile
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
+ [list debug additional_flags=-march=armv9-a]] } {
+ return
+}
+
+# We want SIGUSR1 to be delivered normally.
+gdb_test "handle SIGUSR1 nostop" \
+ [multi_line {Signal Stop Print Pass to program Description} \
+ {SIGUSR1 No Yes Yes User defined signal 1}] \
+ "don't stop for SIGUSR1"
+
+set linespec ${srcfile}:[gdb_get_line_number "Break here."]
+gdb_test_no_output "set args $first_vl $second_vl"
+
+if ![runto ${linespec}] {
+ return
+}
+
+set first_vg [expr $first_vl/8]
+set second_vg [expr $second_vl/8]
+
+gdb_test "print \$vg" ". = $second_vg" "vg was changed"
+
+for {set row 0} {$row < 32} {incr row} {
+ set register_name "\$z${row}\.b\.u"
+ gdb_test "print sizeof $register_name" " = $second_vl" \
+ "size of $register_name in the signal handler"
+ gdb_test "print $register_name" ". = \\{254 <repeats $second_vl times>\\}" \
+ "$register_name contents in signal handler"
+}
+
+for {set row 0} {$row < 16} {incr row} {
+ set register_name "\$p${row}"
+ gdb_test "print $register_name" ". = \\{(0, ){[expr $second_vl/8 - 1]}0\\}" \
+ "$register_name contents in signal handler"
+}
+gdb_test "print \$ffr" ". = \\{(255, ){[expr $second_vl/8 - 1]}255\\}" \
+ "ffr contents in signal handler"
+
+gdb_test "frame function main" \
+ [multi_line "#$decimal $hex in main \[^\r\n\]+" \
+ "$decimal\[ \t\]+kill \\(getpid \\(\\), SIGUSR1\\);"]
+
+gdb_test "print \$vg" ". = $first_vg" "vg was correctly unwound"
+
+for {set row 0} {$row < 32} {incr row} {
+ set register_name "\$z${row}\.b\.u"
+ gdb_test "print sizeof $register_name" " = $first_vl" \
+ "size of $register_name was correctly unwound"
+ gdb_test "print $register_name" ". = \\{255 <repeats $first_vl times>\\}" \
+ "$register_name contents were correctly unwound"
+}
+
+for {set row 0} {$row < 16} {incr row} {
+ set register_name "\$p${row}"
+ gdb_test "print $register_name" ". = \\{(1, ){[expr $first_vl/8 - 1]}1\\}" \
+ "$register_name contents were correctly unwound"
+}
+gdb_test "print \$ffr" ". = \\{(255, ){[expr $first_vl/8 - 1]}255\\}" \
+ "ffr contents were correctly unwound"
diff --git a/gdb/testsuite/gdb.base/bg-execution-repeat.c b/gdb/testsuite/gdb.base/bg-execution-repeat.c
index 8e9bae4..3c0cc76 100644
--- a/gdb/testsuite/gdb.base/bg-execution-repeat.c
+++ b/gdb/testsuite/gdb.base/bg-execution-repeat.c
@@ -37,9 +37,9 @@ main (void)
{
alarm (60);
+ do_wait = 1;
foo ();
- do_wait = 1;
wait ();
/* do_wait set to 0 externally. */
diff --git a/gdb/testsuite/gdb.base/bg-execution-repeat.exp b/gdb/testsuite/gdb.base/bg-execution-repeat.exp
index b1496ee..d5580fb 100644
--- a/gdb/testsuite/gdb.base/bg-execution-repeat.exp
+++ b/gdb/testsuite/gdb.base/bg-execution-repeat.exp
@@ -67,6 +67,17 @@ proc test {continue_cmd} {
# enable the "set var" command with an interrupt / continue& pair.
gdb_test -no-prompt-anchor "interrupt"
+ set test "interrupt received"
+ set re [string_to_regexp "Program received signal SIGINT, Interrupt."]
+ gdb_expect {
+ -re $re {
+ pass $test
+ }
+ timeout {
+ fail "$test (timeout)"
+ }
+ }
+
# Allow the breakpoint to trigger.
gdb_test -no-prompt-anchor "set var do_wait=0"
diff --git a/gdb/testsuite/gdb.base/break1.c b/gdb/testsuite/gdb.base/break1.c
index 110341c..26c4663 100644
--- a/gdb/testsuite/gdb.base/break1.c
+++ b/gdb/testsuite/gdb.base/break1.c
@@ -23,7 +23,13 @@ struct some_struct
{
int a_field;
int b_field;
- union { int z_field; };
+ union
+ {
+ struct
+ {
+ int z_field;
+ };
+ };
};
struct some_struct values[50];
diff --git a/gdb/testsuite/gdb.base/corefile3.c b/gdb/testsuite/gdb.base/corefile3.c
new file mode 100644
index 0000000..16030dd
--- /dev/null
+++ b/gdb/testsuite/gdb.base/corefile3.c
@@ -0,0 +1,118 @@
+/* Copyright 1992-2025 Free Software Foundation, Inc.
+
+ 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/>. */
+
+/* This file is based on coremaker.c. */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <assert.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#define MAPSIZE (8 * 1024)
+
+/* Global pointers so it's easier to access them from GDB. */
+
+char *rw_mapping = NULL;
+char *malloc_buffer = NULL;
+char *anon_mapping = NULL;
+char *shm_mapping = NULL;
+
+/* Create mappings within this process. */
+
+void
+mmapdata ()
+{
+ /* Allocate and initialize a buffer that will be used to write the file
+ that is later mapped in. */
+
+ malloc_buffer = (char *) malloc (MAPSIZE);
+ for (int j = 0; j < MAPSIZE; ++j)
+ malloc_buffer[j] = j;
+
+ /* Write the file to map in. */
+
+ int fd = open ("coremmap.data", O_CREAT | O_RDWR, 0666);
+ assert (fd != -1);
+ write (fd, malloc_buffer, MAPSIZE);
+
+ /* Now map the file into our address space as RW_MAPPING. */
+
+ rw_mapping
+ = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+ assert (rw_mapping != (char *) MAP_FAILED);
+
+ /* Verify that the original data and the mapped data are identical. If
+ not, we'd rather fail now than when trying to access the mapped data
+ from the core file. */
+
+ for (int j = 0; j < MAPSIZE; ++j)
+ assert (malloc_buffer[j] == rw_mapping[j]);
+
+ /* Touch RW_MAPPING so the kernel writes it out into 'core'. */
+ rw_mapping[0] = malloc_buffer[0];
+
+ /* Create yet another region which is allocated, but not written to. */
+ anon_mapping = mmap (NULL, MAPSIZE, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ assert (anon_mapping != MAP_FAILED);
+
+ /* Create a shared memory mapping. */
+ int sid = shmget (IPC_PRIVATE, MAPSIZE, IPC_CREAT | IPC_EXCL | 0777);
+ assert (sid != -1);
+ shm_mapping = (char *) shmat (sid, NULL, 0);
+ int res = shmctl (sid, IPC_RMID, NULL);
+ assert (res == 0);
+ assert (shm_mapping != MAP_FAILED);
+}
+
+void
+func2 ()
+{
+#ifdef SA_FULLDUMP
+ /* Force a corefile that includes the data section for AIX. */
+ {
+ struct sigaction sa;
+
+ sigaction (SIGABRT, (struct sigaction *)0, &sa);
+ sa.sa_flags |= SA_FULLDUMP;
+ sigaction (SIGABRT, &sa, (struct sigaction *)0);
+ }
+#endif
+
+ abort ();
+}
+
+void
+func1 ()
+{
+ func2 ();
+}
+
+int
+main (void)
+{
+ mmapdata ();
+ func1 ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/corefile3.exp b/gdb/testsuite/gdb.base/corefile3.exp
new file mode 100644
index 0000000..57b2300
--- /dev/null
+++ b/gdb/testsuite/gdb.base/corefile3.exp
@@ -0,0 +1,71 @@
+# 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/>.
+
+# Create a core file with some mapped file regions, but ensure that
+# the the kernel should write the regions into the core file (e.g. r/w
+# file backed mapping).
+#
+# We then delete the file that backed the mapping and load the core
+# file into GDB.
+#
+# GDB shouldn't warn about the file being missing. It doesn't matter;
+# the file contents can all be found in the core file itself.
+
+require isnative
+require {!is_remote host}
+
+standard_testfile
+
+if {[build_executable $testfile.exp $testfile $srcfile] == -1} {
+ return
+}
+
+set corefile [core_find $binfile {}]
+if {$corefile == ""} {
+ return
+}
+
+# Move the coremap.data file out of the way, so it cannot be found
+# when we later load the core file into GDB. This file was generated
+# by the inferior as it was running.
+set data_filename \
+ [standard_output_file coredir.[getpid]/coremmap.data]
+set backup_filename \
+ [standard_output_file coredir.[getpid]/coremmap.data.backup]
+remote_exec host "mv ${data_filename} ${backup_filename}"
+
+clean_restart $binfile
+
+# Load the core file. The 'coremap.data' file cannot be found by GDB,
+# but all the mappings for that file are r/w and should be present in
+# the core file, so we shouldn't get any warnings from GDB about it.
+set warnings_seen 0
+gdb_test_multiple "core-file $corefile" "core-file command" {
+ -re "^warning: Can't open file \[^\r\n\]+ during file-backed mapping note processing\r\n" {
+ incr warnings_seen
+ exp_continue
+ }
+ -re "^$gdb_prompt $" {
+ gdb_assert { $warnings_seen == 0 } $gdb_test_name
+ }
+ -re "^\[^\r\n\]*\r\n" {
+ exp_continue
+ }
+}
+
+# Check the mappings are all readable.
+foreach label { rw_mapping malloc_buffer anon_mapping shm_mapping } {
+ gdb_test "x/1wd $label" "^$hex:\\s+$decimal"
+}
diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp
index d4d6b20..3abd049 100644
--- a/gdb/testsuite/gdb.base/default.exp
+++ b/gdb/testsuite/gdb.base/default.exp
@@ -699,6 +699,8 @@ set show_conv_list \
{$_gdb_minor = 1} \
{$_shell_exitsignal = void} \
{$_shell_exitcode = 0} \
+ {$_active_linker_namespaces = 1} \
+ {$_current_linker_namespace = <error: No registers.>}\
}
if [allow_python_tests] {
append show_conv_list \
diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c b/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c
index 3bcd819..c7c038a 100644
--- a/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c
+++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c
@@ -41,6 +41,12 @@ main (void)
handle[2] = dlmopen (LM_ID_NEWLM, DSO_NAME, RTLD_LAZY | RTLD_LOCAL);
assert (handle[2] != NULL);
+ for (dl = 2; dl >= 0; dl--)
+ {
+ fun = dlsym (handle[dl], "inc");
+ fun (dl);
+ }
+
dlclose (handle[0]); /* TAG: first dlclose */
dlclose (handle[1]); /* TAG: second dlclose */
dlclose (handle[2]); /* TAG: third dlclose */
diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
index 03b7a52..8f52199 100644
--- a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
+++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
@@ -24,7 +24,8 @@ require allow_dlmopen_tests
standard_testfile -main.c -lib.c
set srcfile_lib $srcfile2
-set binfile_lib [standard_output_file dlmopen-lib.so]
+set so_name dlmopen-lib.so
+set binfile_lib [standard_output_file $so_name]
if { [build_executable "build shlib" $binfile_lib $srcfile_lib \
[list debug shlib]] == -1 } {
@@ -41,18 +42,19 @@ if { [build_executable "failed to build" $testfile $srcfile \
# for the so
proc get_first_so_ns {} {
set ns -1
- gdb_test_multiple "info sharedlibrary" "get SO namespace" -lbl {
- -re "From\\s+To\\s+\(NS\\s+\)?Syms\\s+Read\\s+Shared Object Library\r\n" {
+ set lib_regexp [string_to_regexp ${::binfile_lib}]
+ gdb_test_multiple "info sharedlibrary $::so_name" "get SO namespace" -lbl {
+ -re "\r\nFrom\\s+To\\s+\(NS\\s+\)?Syms\\s+Read\\s+Shared Object Library(?=\r\n)" {
exp_continue
}
- -re "^$::hex\\s+$::hex\\s+\\\[\\\[($::decimal)\\\]\\\]\\s+\[^\r\n]+$::binfile_lib.*" {
- set ns $expect_out(1,string)
- }
- -re "^$::gdb_prompt $" {
- }
- -re "^\[^\r\n\]+\r\n" {
+ -re "\r\n$::hex\\s+$::hex\\s+\\\[\\\[($::decimal)\\\]\\\]\\s+\[^\r\n]+${lib_regexp}(?=\r\n)" {
+ if {$ns == -1} {
+ set ns $expect_out(1,string)
+ }
exp_continue
}
+ -re -wrap "" {
+ }
}
return $ns
}
@@ -103,4 +105,137 @@ proc test_info_shared {} {
"after unloading everything"
}
+# Run all tests related to the linkage namespaces convenience
+# variables, _active_namespaces and _current_namespaces.
+proc_with_prefix test_conv_vars {} {
+ clean_restart $::binfile
+
+ gdb_test "print \$_active_linker_namespaces" "1" \
+ "1 namespace before starting inferior"
+ gdb_test "print \$_current_linker_namespace" "No registers." \
+ "No current namespace before starting inferior"
+
+ if { ![runto_main] } {
+ return
+ }
+
+ gdb_test "print \$_active_linker_namespaces" "1" \
+ "Before activating namespaces"
+ gdb_test "print \$_current_linker_namespace" ".*\"\\\[\\\[0\\\]\\\]\"" \
+ "Still in the default namespace"
+
+ gdb_breakpoint "inc" allow-pending
+ gdb_breakpoint [gdb_get_line_number "TAG: first dlclose"]
+
+ foreach_with_prefix dl {3 2 1} {
+ gdb_continue_to_breakpoint "inc"
+
+ gdb_test "print \$_current_linker_namespace" ".*\"\\\[\\\[$dl\\\]\\\]\"" \
+ "Verify we're in namespace $dl"
+ }
+
+ gdb_continue_to_breakpoint "first dlclose"
+ gdb_test "print \$_active_linker_namespaces" "4" "all SOs loaded"
+
+ gdb_test "next" ".*second dlclose.*" "close one SO"
+ gdb_test "print \$_active_linker_namespaces" "3" "one SOs unloaded"
+ gdb_test "next" ".*third dlclose.*" "close another SO"
+ gdb_test "print \$_active_linker_namespaces" "2" "two SOs unloaded"
+
+ # Restarting GDB so that we can test setting a breakpoint
+ # using the convenience variable, while a proper bp syntax
+ # isn't implemented for namespaces
+ clean_restart $::binfile
+ if {![runto_main]} {
+ return
+ }
+
+ # We need to load one SO because you can't have confitional
+ # breakpoints and pending breakpoints at the same time with
+ # gdb_breakpoint.
+ gdb_test "next" ".*assert.*" "load the first SO"
+ gdb_breakpoint "inc if \$_streq(\$_current_linker_namespace, \"\[\[2\]\]\")"
+ gdb_continue_to_breakpoint "inc"
+ gdb_continue_to_end "" continue 1
+}
+
+# Run several tests relating to the command "info namespaces".
+proc test_info_linker_namespaces {} {
+ clean_restart $::binfile
+
+ if { ![runto_main] } {
+ return
+ }
+
+ with_test_prefix "info linker-namespaces" {
+ gdb_breakpoint [gdb_get_line_number "TAG: first dlclose"]
+ gdb_continue_to_breakpoint "TAG: first dlclose"
+ }
+
+ # First, test printing a single namespace, and ensure all of
+ # them are correct, using both syntaxes.
+ set found_all_libs false
+ gdb_test_multiple "info linker-namespaces \[\[0\]\]" "print namespace 0" -lbl {
+ -re "^\r\nThere are ($::decimal) libraries loaded in linker namespace \\\[\\\[0\\\]\\\]" {
+ # Some systems may add libc and libm to every loaded namespace,
+ # others may load only one or neither, because the SO doesn't
+ # actually use either library. The best we can do is check if
+ # we found the dynamic linker, and up to 2 more libraries.
+ set libs $expect_out(1,string)
+ set found_all_libs [expr $libs - 1 <= 2]
+ exp_continue
+ }
+ -re "^\r\n$::gdb_prompt $" {
+ gdb_assert $found_all_libs "the correct number of libraries was reported"
+ }
+ -re "(^\r\n)?\[^\r\n\]+(?=\r\n)" {
+ exp_continue
+ }
+ }
+ foreach_with_prefix ns {1 2 3} {
+ set found_test_so false
+ set found_all_libs false
+ gdb_test_multiple "info linker-namespaces $ns" "print namespace $ns" -lbl {
+ -re "^\r\nThere are ($::decimal) libraries loaded in linker namespace \\\[\\\[$ns\\\]\\\]" {
+ set libs $expect_out(1,string)
+ # Some systems may add libc and libm to every loaded namespace,
+ # others may load only one or neither, because the SO doesn't
+ # actually use either library. The best we can do is check if
+ # we found the dynamic linker, the test SO, and maybe up to 2
+ # more libraries.
+ set found_all_libs [expr $libs - 2 <= 2]
+ exp_continue
+ }
+ -re "^\r\n\[^\r\n\]+${::binfile_lib}\[^\r\n\]*(?=\r\n)" {
+ set found_test_so true
+ exp_continue
+ }
+ -re "^\r\n$::gdb_prompt $" {
+ gdb_assert $found_test_so "this testfle's SO was reported"
+ gdb_assert $found_all_libs "the correct number of libraries was reported"
+ }
+ -re "(^\r\n)?\[^\r\n\]+(?=\r\n)" {
+ exp_continue
+ }
+ }
+ }
+
+ # These patterns are simpler, and purposefully glob multiple lines.
+ # The point is to ensure that we find and display all the namespaces,
+ # without worrying about the libraries printed, since that was tested
+ # above.
+ gdb_test "info linker-namespaces" \
+ [multi_line "There are 4 linker namespaces loaded" \
+ "There are $::decimal libraries loaded in linker namespace ..0.." \
+ ".*" \
+ "There are $::decimal libraries loaded in linker namespace ..1.." \
+ ".*" \
+ "There are $::decimal libraries loaded in linker namespace ..2.." \
+ ".*" \
+ "There are $::decimal libraries loaded in linker namespace ..3.." \
+ ".*" ] "print namespaces with no argument"
+}
+
test_info_shared
+test_conv_vars
+test_info_linker_namespaces
diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
index e1c996e..8634668 100644
--- a/gdb/testsuite/gdb.base/printcmds.exp
+++ b/gdb/testsuite/gdb.base/printcmds.exp
@@ -744,6 +744,12 @@ proc test_print_char_arrays {} {
gdb_test_no_output "set print address off" "address off char arrays"
}
+proc test_print_arrays_negative {} {
+ # Check whether correct error messages are printed
+ gdb_test "p 1 == { }" "size of the array element must not be zero"
+ gdb_test "p 1 == { 1, 'a' }" "array elements must all be the same size"
+}
+
proc test_print_nibbles {} {
gdb_test_no_output "set print nibbles on"
foreach lang_line {
@@ -1235,6 +1241,7 @@ test_print_int_arrays
test_print_typedef_arrays
test_artificial_arrays
test_print_char_arrays
+test_print_arrays_negative
test_print_nibbles
# We used to do the runto main here.
test_print_string_constants
diff --git a/gdb/testsuite/gdb.base/tls-common.exp.tcl b/gdb/testsuite/gdb.base/tls-common.exp.tcl
new file mode 100644
index 0000000..7aa7f46
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tls-common.exp.tcl
@@ -0,0 +1,50 @@
+# Copyright 2024 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.
+
+# Require statement, variables and procs used by tls-nothreads.exp,
+# tls-multiobj.exp, and tls-dlobj.exp.
+
+# The tests listed above are known to work for the targets listed on
+# the 'require' line, below.
+#
+# At the moment, only the Linux target is listed, but, ideally, these
+# tests should be run on other targets too. E.g, testing on FreeBSD
+# shows many failures which should be addressed in some fashion before
+# enabling it for that target.
+
+require {is_any_target "*-*-linux*"}
+
+# These are the targets which have support for internal TLS lookup:
+
+set internal_tls_linux_targets {"x86_64-*-linux*" "aarch64-*-linux*"
+ "riscv*-*-linux*" "powerpc64*-*-linux*"
+ "s390x*-*-linux*"}
+
+# The "maint set force-internal-tls-address-lookup" command is only
+# available for certain Linux architectures. Don't attempt to force
+# use of internal TLS support for architectures which don't support
+# it.
+
+if [is_any_target {*}$internal_tls_linux_targets] {
+ set internal_tls_iters { false true }
+} else {
+ set internal_tls_iters { false }
+}
+
+# Set up a kfail with message KFAIL_MSG when KFAIL_COND holds, then
+# issue gdb_test with command CMD and regular expression RE.
+
+proc gdb_test_with_kfail {cmd re kfail_cond kfail_msg} {
+ if [uplevel 1 [list expr $kfail_cond]] {
+ setup_kfail $kfail_msg *-*-*
+ }
+ gdb_test $cmd $re
+}
diff --git a/gdb/testsuite/gdb.base/tls-dlobj-lib.c b/gdb/testsuite/gdb.base/tls-dlobj-lib.c
new file mode 100644
index 0000000..c69bab7
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tls-dlobj-lib.c
@@ -0,0 +1,87 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2024 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/>. */
+
+/* This program needs to be compiled with preprocessor symbol set to
+ a small integer, e.g. "gcc -DN=1 ..." With N defined, the CONCAT2
+ and CONCAT3 macros will construct suitable names for the global
+ variables and functions. */
+
+#define CONCAT2(a,b) CONCAT2_(a,b)
+#define CONCAT2_(a,b) a ## b
+
+#define CONCAT3(a,b,c) CONCAT3_(a,b,c)
+#define CONCAT3_(a,b,c) a ## b ## c
+
+/* For N=1, this ends up being...
+ __thread int tls_lib1_tbss_1;
+ __thread int tls_lib1_tbss_2;
+ __thread int tls_lib1_tdata_1 = 196;
+ __thread int tls_lib1_tdata_2 = 197; */
+
+__thread int CONCAT3(tls_lib, N, _tbss_1);
+__thread int CONCAT3(tls_lib, N, _tbss_2);
+__thread int CONCAT3(tls_lib, N, _tdata_1) = CONCAT2(N, 96);
+__thread int CONCAT3(tls_lib, N, _tdata_2) = CONCAT2(N, 97);
+
+/* Substituting for N, define function:
+
+ int get_tls_libN_var (int which) . */
+
+int
+CONCAT3(get_tls_lib, N, _var) (int which)
+{
+ switch (which)
+ {
+ case 0:
+ return -1;
+ case 1:
+ return CONCAT3(tls_lib, N, _tbss_1);
+ case 2:
+ return CONCAT3(tls_lib, N, _tbss_2);
+ case 3:
+ return CONCAT3(tls_lib, N, _tdata_1);
+ case 4:
+ return CONCAT3(tls_lib, N, _tdata_2);
+ }
+ return -1;
+}
+
+/* Substituting for N, define function:
+
+ void set_tls_libN_var (int which, int val) . */
+
+void
+CONCAT3(set_tls_lib, N, _var) (int which, int val)
+{
+ switch (which)
+ {
+ case 0:
+ break;
+ case 1:
+ CONCAT3(tls_lib, N, _tbss_1) = val;
+ break;
+ case 2:
+ CONCAT3(tls_lib, N, _tbss_2) = val;
+ break;
+ case 3:
+ CONCAT3(tls_lib, N, _tdata_1) = val;
+ break;
+ case 4:
+ CONCAT3(tls_lib, N, _tdata_2) = val;
+ break;
+ }
+}
diff --git a/gdb/testsuite/gdb.base/tls-dlobj.c b/gdb/testsuite/gdb.base/tls-dlobj.c
new file mode 100644
index 0000000..322bdda
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tls-dlobj.c
@@ -0,0 +1,311 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2024 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/>. */
+
+#include <dlfcn.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+typedef void (*setter_ftype) (int which, int val);
+
+__thread int tls_main_tbss_1;
+__thread int tls_main_tbss_2;
+__thread int tls_main_tdata_1 = 96;
+__thread int tls_main_tdata_2 = 97;
+
+extern void set_tls_lib10_var (int which, int val);
+extern void set_tls_lib11_var (int which, int val);
+
+volatile int data;
+
+static void
+set_tls_main_var (int which, int val)
+{
+ switch (which)
+ {
+ case 1:
+ tls_main_tbss_1 = val;
+ break;
+ case 2:
+ tls_main_tbss_2 = val;
+ break;
+ case 3:
+ tls_main_tdata_1 = val;
+ break;
+ case 4:
+ tls_main_tdata_2 = val;
+ break;
+ }
+}
+
+void
+use_it (int a)
+{
+ data = a;
+}
+
+static void *
+load_dso (char *dso_name, int n, setter_ftype *setterp)
+{
+ char buf[80];
+ void *sym;
+ void *handle = dlopen (dso_name, RTLD_NOW | RTLD_GLOBAL);
+ if (handle == NULL)
+ {
+ fprintf (stderr, "dlopen of DSO '%s' failed: %s\n", dso_name, dlerror ());
+ exit (1);
+ }
+ sprintf (buf, "set_tls_lib%d_var", n);
+ sym = dlsym (handle, buf);
+ assert (sym != NULL);
+ *setterp = sym;
+
+ /* Some libc implementations (for some architectures) refuse to
+ initialize TLS data structures (specifically, the DTV) without
+ first calling dlsym on one of the TLS symbols. */
+ sprintf (buf, "tls_lib%d_tdata_1", n);
+ assert (dlsym (handle, buf) != NULL);
+
+ return handle;
+}
+
+int
+main (int argc, char **argv)
+{
+ int i, status;
+ setter_ftype s0, s1, s2, s3, s4, s10, s11;
+ void *h1 = load_dso (OBJ1, 1, &s1);
+ void *h2 = load_dso (OBJ2, 2, &s2);
+ void *h3 = load_dso (OBJ3, 3, &s3);
+ void *h4 = load_dso (OBJ4, 4, &s4);
+ s0 = set_tls_main_var;
+ s10 = set_tls_lib10_var;
+ s11 = set_tls_lib11_var;
+
+ use_it (0); /* main-breakpoint-1 */
+
+ /* Set TLS variables in main program and all libraries. */
+ for (i = 1; i <= 4; i++)
+ s0 (i, 10 + i);
+ for (i = 1; i <= 4; i++)
+ s1 (i, 110 + i);
+ for (i = 1; i <= 4; i++)
+ s2 (i, 210 + i);
+ for (i = 1; i <= 4; i++)
+ s3 (i, 310 + i);
+ for (i = 1; i <= 4; i++)
+ s4 (i, 410 + i);
+ for (i = 1; i <= 4; i++)
+ s10 (i, 1010 + i);
+ for (i = 1; i <= 4; i++)
+ s11 (i, 1110 + i);
+
+ use_it (0); /* main-breakpoint-2 */
+
+ /* Unload lib2 and lib3. */
+ status = dlclose (h2);
+ assert (status == 0);
+ status = dlclose (h3);
+ assert (status == 0);
+
+ /* Set TLS variables in main program and in libraries which are still
+ loaded. */
+ for (i = 1; i <= 4; i++)
+ s0 (i, 20 + i);
+ for (i = 1; i <= 4; i++)
+ s1 (i, 120 + i);
+ for (i = 1; i <= 4; i++)
+ s4 (i, 420 + i);
+ for (i = 1; i <= 4; i++)
+ s10 (i, 1020 + i);
+ for (i = 1; i <= 4; i++)
+ s11 (i, 1120 + i);
+
+ use_it (0); /* main-breakpoint-3 */
+
+ /* Load lib3. */
+ h3 = load_dso (OBJ3, 3, &s3);
+
+ /* Set TLS vars again; currently, only lib2 is not loaded. */
+ for (i = 1; i <= 4; i++)
+ s0 (i, 30 + i);
+ for (i = 1; i <= 4; i++)
+ s1 (i, 130 + i);
+ for (i = 1; i <= 4; i++)
+ s3 (i, 330 + i);
+ for (i = 1; i <= 4; i++)
+ s4 (i, 430 + i);
+ for (i = 1; i <= 4; i++)
+ s10 (i, 1030 + i);
+ for (i = 1; i <= 4; i++)
+ s11 (i, 1130 + i);
+
+ use_it (0); /* main-breakpoint-4 */
+
+ /* Unload lib1 and lib4; load lib2. */
+ status = dlclose (h1);
+ assert (status == 0);
+ status = dlclose (h4);
+ assert (status == 0);
+ h2 = load_dso (OBJ2, 2, &s2);
+
+ /* Set TLS vars; currently, lib2 and lib3 are loaded,
+ lib1 and lib4 are not. */
+ for (i = 1; i <= 4; i++)
+ s0 (i, 40 + i);
+ for (i = 1; i <= 4; i++)
+ s2 (i, 240 + i);
+ for (i = 1; i <= 4; i++)
+ s3 (i, 340 + i);
+ for (i = 1; i <= 4; i++)
+ s10 (i, 1040 + i);
+ for (i = 1; i <= 4; i++)
+ s11 (i, 1140 + i);
+
+ use_it (0); /* main-breakpoint-5 */
+
+ /* Load lib4 and lib1. Unload lib2. */
+ h4 = load_dso (OBJ4, 4, &s4);
+ h1 = load_dso (OBJ1, 1, &s1);
+ status = dlclose (h2);
+ assert (status == 0);
+
+ /* Set TLS vars; currently, lib1, lib3, and lib4 are loaded;
+ lib2 is not loaded. */
+ for (i = 1; i <= 4; i++)
+ s0 (i, 50 + i);
+ for (i = 1; i <= 4; i++)
+ s1 (i, 150 + i);
+ for (i = 1; i <= 4; i++)
+ s3 (i, 350 + i);
+ for (i = 1; i <= 4; i++)
+ s4 (i, 450 + i);
+ for (i = 1; i <= 4; i++)
+ s10 (i, 1050 + i);
+ for (i = 1; i <= 4; i++)
+ s11 (i, 1150 + i);
+
+ use_it (0); /* main-breakpoint-6 */
+
+ /* Load lib2, unload lib1, lib3, and lib4; then load lib3 again. */
+ h2 = load_dso (OBJ2, 2, &s2);
+ status = dlclose (h1);
+ assert (status == 0);
+ status = dlclose (h3);
+ assert (status == 0);
+ status = dlclose (h4);
+ assert (status == 0);
+ h3 = load_dso (OBJ3, 3, &s3);
+
+ /* Set TLS vars; currently, lib2 and lib3 are loaded;
+ lib1 and lib4 are not loaded. */
+ for (i = 1; i <= 4; i++)
+ s0 (i, 60 + i);
+ for (i = 1; i <= 4; i++)
+ s2 (i, 260 + i);
+ for (i = 1; i <= 4; i++)
+ s3 (i, 360 + i);
+ for (i = 1; i <= 4; i++)
+ s10 (i, 1060 + i);
+ for (i = 1; i <= 4; i++)
+ s11 (i, 1160 + i);
+
+ use_it (0); /* main-breakpoint-7 */
+
+ /* Unload lib3 and lib2, then (re)load lib4, lib3, lib2, and lib1,
+ in that order. */
+ status = dlclose (h3);
+ assert (status == 0);
+ status = dlclose (h2);
+ assert (status == 0);
+ h4 = load_dso (OBJ4, 4, &s4);
+ h3 = load_dso (OBJ3, 3, &s3);
+ h2 = load_dso (OBJ2, 2, &s2);
+ h1 = load_dso (OBJ1, 1, &s1);
+
+ /* Set TLS vars; currently, lib1, lib2, lib3, and lib4 are all
+ loaded. */
+ for (i = 1; i <= 4; i++)
+ s0 (i, 70 + i);
+ for (i = 1; i <= 4; i++)
+ s1 (i, 170 + i);
+ for (i = 1; i <= 4; i++)
+ s2 (i, 270 + i);
+ for (i = 1; i <= 4; i++)
+ s3 (i, 370 + i);
+ for (i = 1; i <= 4; i++)
+ s4 (i, 470 + i);
+ for (i = 1; i <= 4; i++)
+ s10 (i, 1070 + i);
+ for (i = 1; i <= 4; i++)
+ s11 (i, 1170 + i);
+
+ use_it (0); /* main-breakpoint-8 */
+
+ /* Unload lib3, lib1, and lib4. */
+ status = dlclose (h3);
+ assert (status == 0);
+ status = dlclose (h1);
+ assert (status == 0);
+ status = dlclose (h4);
+ assert (status == 0);
+
+ /* Set TLS vars; currently, lib2 is loaded; lib1, lib3, and lib4 are
+ not. */
+ for (i = 1; i <= 4; i++)
+ s0 (i, 80 + i);
+ for (i = 1; i <= 4; i++)
+ s2 (i, 280 + i);
+ for (i = 1; i <= 4; i++)
+ s10 (i, 1080 + i);
+ for (i = 1; i <= 4; i++)
+ s11 (i, 1180 + i);
+
+ use_it (0); /* main-breakpoint-9 */
+
+ /* Load lib3, unload lib2, load lib4. */
+ h3 = load_dso (OBJ3, 3, &s3);
+ status = dlclose (h2);
+ assert (status == 0);
+ h4 = load_dso (OBJ4, 4, &s4);
+
+ /* Set TLS vars; currently, lib3 and lib4 are loaded; lib1 and lib2
+ are not. */
+ for (i = 1; i <= 4; i++)
+ s0 (i, 90 + i);
+ for (i = 1; i <= 4; i++)
+ s3 (i, 390 + i);
+ for (i = 1; i <= 4; i++)
+ s4 (i, 490 + i);
+ for (i = 1; i <= 4; i++)
+ s10 (i, 1090 + i);
+ for (i = 1; i <= 4; i++)
+ s11 (i, 1190 + i);
+
+ use_it (0); /* main-breakpoint-10 */
+
+ /* Attempt to keep variables in the main program from being optimized
+ away. */
+ use_it (tls_main_tbss_1);
+ use_it (tls_main_tbss_2);
+ use_it (tls_main_tdata_1);
+ use_it (tls_main_tdata_2);
+
+ use_it (100); /* main-breakpoint-last */
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/tls-dlobj.exp b/gdb/testsuite/gdb.base/tls-dlobj.exp
new file mode 100644
index 0000000..02f2ff8
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tls-dlobj.exp
@@ -0,0 +1,378 @@
+# Copyright 2024 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.
+
+# Test that the GDB-internal TLS link map to module id mapping code
+# works correctly when debugging a program which is linked against
+# shared objects and which also loads and unloads other shared objects
+# in different orders. For targets which have GDB-internal TLS
+# support, it'll check both GDB-internal TLS support as well as that
+# provided by a helper library such as libthread_db.
+
+source $srcdir/$subdir/tls-common.exp.tcl
+
+require allow_shlib_tests
+
+standard_testfile
+
+set libsrc "${srcdir}/${subdir}/${testfile}-lib.c"
+
+# These will be dlopen'd:
+set lib1obj [standard_output_file "${testfile}1-lib.so"]
+set lib2obj [standard_output_file "${testfile}2-lib.so"]
+set lib3obj [standard_output_file "${testfile}3-lib.so"]
+set lib4obj [standard_output_file "${testfile}4-lib.so"]
+
+# These will be dynamically linked with the main program:
+set lib10obj [standard_output_file "${testfile}10-lib.so"]
+set lib11obj [standard_output_file "${testfile}11-lib.so"]
+
+# Due to problems with some versions of glibc, we expect some tests to
+# fail due to TLS storage not being allocated/initialized. Test
+# command CMD using regular expression RE, and use XFAIL instead of
+# FAIL when the relevant RE is matched and COND is true when evaluated
+# in the upper level.
+
+proc gdb_test_with_xfail { cmd re cond} {
+ gdb_test_multiple $cmd $cmd {
+ -re -wrap $re {
+ pass $gdb_test_name
+ }
+ -re -wrap "The inferior has not yet allocated storage for thread-local variables.*" {
+ if [ uplevel 1 [list expr $cond]] {
+ xfail $gdb_test_name
+ } else {
+ fail $gdb_test_name
+ }
+ }
+ }
+}
+
+proc do_tests {force_internal_tls} {
+ clean_restart $::binfile
+ if ![runto_main] {
+ return
+ }
+
+ if $force_internal_tls {
+ gdb_test_no_output "maint set force-internal-tls-address-lookup on"
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-1"]
+ gdb_continue_to_breakpoint "main-breakpoint-1"
+
+ with_test_prefix "before assignments" {
+ gdb_test "print tls_main_tbss_1" ".* = 0"
+ gdb_test "print tls_main_tbss_2" ".* = 0"
+ gdb_test "print tls_main_tdata_1" ".* = 96"
+ gdb_test "print tls_main_tdata_2" ".* = 97"
+
+ # For these tests, where we're attempting to access TLS vars
+ # in a dlopen'd library, but before assignment to any of the
+ # vars, so it could happen that storage hasn't been allocated
+ # yet. But it might also work. (When testing against MUSL,
+ # things just work; GLIBC ends to produce the TLS error.) So
+ # accept either the right answer or a TLS error message.
+
+ set tlserr "The inferior has not yet allocated storage for thread-local variables.*"
+ foreach n {1 2 3 4} {
+ gdb_test "print tls_lib${n}_tbss_1" \
+ "0|${tlserr}"
+ gdb_test "print tls_lib${n}_tbss_2" \
+ "0|${tlserr}"
+ gdb_test "print tls_lib${n}_tdata_1" \
+ "96|${tlserr}"
+ gdb_test "print tls_lib${n}_tdata_2" \
+ "97|${tlserr}"
+ }
+ foreach n {10 11} {
+ gdb_test "print tls_lib${n}_tbss_1" ".* = 0"
+ gdb_test "print tls_lib${n}_tbss_2" ".* = 0"
+ gdb_test "print tls_lib${n}_tdata_1" ".* = ${n}96"
+ gdb_test "print tls_lib${n}_tdata_2" ".* = ${n}97"
+ }
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-2"]
+ gdb_continue_to_breakpoint "main-breakpoint-2"
+
+ with_test_prefix "at main-breakpoint-2" {
+ gdb_test "print tls_main_tbss_1" ".* = 11"
+ gdb_test "print tls_main_tbss_2" ".* = 12"
+ gdb_test "print tls_main_tdata_1" ".* = 13"
+ gdb_test "print tls_main_tdata_2" ".* = 14"
+
+ foreach n {1 2 3 4 10 11} {
+ gdb_test "print tls_lib${n}_tbss_1" ".* = ${n}11"
+ gdb_test "print tls_lib${n}_tbss_2" ".* = ${n}12"
+ gdb_test "print tls_lib${n}_tdata_1" ".* = ${n}13"
+ gdb_test "print tls_lib${n}_tdata_2" ".* = ${n}14"
+ }
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-3"]
+ gdb_continue_to_breakpoint "main-breakpoint-3"
+
+ # At this point lib2 and lib3 have been unloaded. Also, TLS vars
+ # in remaining libraries have been changed.
+
+ with_test_prefix "at main-breakpoint-3" {
+ gdb_test "print tls_main_tbss_1" ".* = 21"
+ gdb_test "print tls_main_tbss_2" ".* = 22"
+ gdb_test "print tls_main_tdata_1" ".* = 23"
+ gdb_test "print tls_main_tdata_2" ".* = 24"
+
+ foreach n {1 4 10 11} {
+ gdb_test "print tls_lib${n}_tbss_1" ".* = ${n}21"
+ gdb_test "print tls_lib${n}_tbss_2" ".* = ${n}22"
+ gdb_test "print tls_lib${n}_tdata_1" ".* = ${n}23"
+ gdb_test "print tls_lib${n}_tdata_2" ".* = ${n}24"
+ }
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-4"]
+ gdb_continue_to_breakpoint "main-breakpoint-4"
+
+ # lib3 has been loaded again; lib2 is the only one not loaded.
+
+ with_test_prefix "at main-breakpoint-4" {
+ gdb_test "print tls_main_tbss_1" ".* = 31"
+ gdb_test "print tls_main_tbss_2" ".* = 32"
+ gdb_test "print tls_main_tdata_1" ".* = 33"
+ gdb_test "print tls_main_tdata_2" ".* = 34"
+
+ set cond { $n == 3 }
+ foreach n {1 3 4 10 11} {
+ gdb_test_with_xfail "print tls_lib${n}_tbss_1" ".* = ${n}31" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tbss_2" ".* = ${n}32" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_1" ".* = ${n}33" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_2" ".* = ${n}34" $cond
+ }
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-5"]
+ gdb_continue_to_breakpoint "main-breakpoint-5"
+
+ # lib2 and lib3 are loaded; lib1 and lib4 are not.
+
+ with_test_prefix "at main-breakpoint-5" {
+ gdb_test "print tls_main_tbss_1" ".* = 41"
+ gdb_test "print tls_main_tbss_2" ".* = 42"
+ gdb_test "print tls_main_tdata_1" ".* = 43"
+ gdb_test "print tls_main_tdata_2" ".* = 44"
+
+ set cond { $n == 2 || $n == 3 }
+ foreach n {2 3 10 11} {
+ gdb_test_with_xfail "print tls_lib${n}_tbss_1" ".* = ${n}41" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tbss_2" ".* = ${n}42" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_1" ".* = ${n}43" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_2" ".* = ${n}44" $cond
+ }
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-6"]
+ gdb_continue_to_breakpoint "main-breakpoint-6"
+
+ # lib1, lib3 and lib4 are loaded; lib2 is not loaded.
+
+ with_test_prefix "at main-breakpoint-6" {
+ gdb_test "print tls_main_tbss_1" ".* = 51"
+ gdb_test "print tls_main_tbss_2" ".* = 52"
+ gdb_test "print tls_main_tdata_1" ".* = 53"
+ gdb_test "print tls_main_tdata_2" ".* = 54"
+
+ set cond { $n == 1 || $n == 3 || $n == 4}
+ foreach n {1 3 4 10 11} {
+ gdb_test_with_xfail "print tls_lib${n}_tbss_1" ".* = ${n}51" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tbss_2" ".* = ${n}52" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_1" ".* = ${n}53" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_2" ".* = ${n}54" $cond
+ }
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-7"]
+ gdb_continue_to_breakpoint "main-breakpoint-7"
+
+ # lib2 and lib3 are loaded; lib1 and lib4 are not.
+
+ with_test_prefix "at main-breakpoint-7" {
+ gdb_test "print tls_main_tbss_1" ".* = 61"
+ gdb_test "print tls_main_tbss_2" ".* = 62"
+ gdb_test "print tls_main_tdata_1" ".* = 63"
+ gdb_test "print tls_main_tdata_2" ".* = 64"
+
+ set cond { $n == 2 || $n == 3 }
+ foreach n {2 3 10 11} {
+ gdb_test_with_xfail "print tls_lib${n}_tbss_1" ".* = ${n}61" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tbss_2" ".* = ${n}62" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_1" ".* = ${n}63" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_2" ".* = ${n}64" $cond
+ }
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-8"]
+ gdb_continue_to_breakpoint "main-breakpoint-8"
+
+ # lib1, lib2, lib3, and lib4 are all loaded.
+
+ with_test_prefix "at main-breakpoint-8" {
+ gdb_test "print tls_main_tbss_1" ".* = 71"
+ gdb_test "print tls_main_tbss_2" ".* = 72"
+ gdb_test "print tls_main_tdata_1" ".* = 73"
+ gdb_test "print tls_main_tdata_2" ".* = 74"
+
+ foreach n {1 2 3 4 10 11} {
+ gdb_test "print tls_lib${n}_tbss_1" ".* = ${n}71"
+ gdb_test "print tls_lib${n}_tbss_2" ".* = ${n}72"
+ gdb_test "print tls_lib${n}_tdata_1" ".* = ${n}73"
+ gdb_test "print tls_lib${n}_tdata_2" ".* = ${n}74"
+ }
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-9"]
+ gdb_continue_to_breakpoint "main-breakpoint-9"
+
+ # lib2 is loaded; lib1, lib3, and lib4 are not.
+
+ with_test_prefix "at main-breakpoint-9" {
+ gdb_test "print tls_main_tbss_1" ".* = 81"
+ gdb_test "print tls_main_tbss_2" ".* = 82"
+ gdb_test "print tls_main_tdata_1" ".* = 83"
+ gdb_test "print tls_main_tdata_2" ".* = 84"
+
+ foreach n {2 10 11} {
+ gdb_test "print tls_lib${n}_tbss_1" ".* = ${n}81"
+ gdb_test "print tls_lib${n}_tbss_2" ".* = ${n}82"
+ gdb_test "print tls_lib${n}_tdata_1" ".* = ${n}83"
+ gdb_test "print tls_lib${n}_tdata_2" ".* = ${n}84"
+ }
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-10"]
+ gdb_continue_to_breakpoint "main-breakpoint-10"
+
+ # lib3 and lib4 are loaded; lib1 and lib2 are not.
+
+ with_test_prefix "at main-breakpoint-10" {
+ gdb_test "print tls_main_tbss_1" ".* = 91"
+ gdb_test "print tls_main_tbss_2" ".* = 92"
+ gdb_test "print tls_main_tdata_1" ".* = 93"
+ gdb_test "print tls_main_tdata_2" ".* = 94"
+
+ set cond { $n == 3 || $n == 4 }
+ foreach n {3 4 10 11} {
+ gdb_test_with_xfail "print tls_lib${n}_tbss_1" ".* = ${n}91" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tbss_2" ".* = ${n}92" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_1" ".* = ${n}93" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_2" ".* = ${n}94" $cond
+ }
+ }
+
+ # gdb_interact
+
+ set corefile ${::binfile}.core
+ set core_supported 0
+ if { ![is_remote host] } {
+ set core_supported [gdb_gcore_cmd $corefile "save corefile"]
+ }
+
+ # Finish test early if no core file was made.
+ if !$core_supported {
+ return
+ }
+
+ clean_restart $::binfile
+
+ set core_loaded [gdb_core_cmd $corefile "load corefile"]
+ if { $core_loaded == -1 } {
+ return
+ }
+
+ with_test_prefix "core file" {
+ if $force_internal_tls {
+ gdb_test_no_output "maint set force-internal-tls-address-lookup on"
+ }
+
+ gdb_test "print tls_main_tbss_1" ".* = 91"
+ gdb_test "print tls_main_tbss_2" ".* = 92"
+ gdb_test "print tls_main_tdata_1" ".* = 93"
+ gdb_test "print tls_main_tdata_2" ".* = 94"
+
+ set cond { $n == 3 || $n == 4 }
+ foreach n {3 4 10 11} {
+ gdb_test_with_xfail "print tls_lib${n}_tbss_1" ".* = ${n}91" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tbss_2" ".* = ${n}92" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_1" ".* = ${n}93" $cond
+ gdb_test_with_xfail "print tls_lib${n}_tdata_2" ".* = ${n}94" $cond
+ }
+ }
+}
+
+# Build shared objects for dlopen:
+if { [gdb_compile_shlib $libsrc $lib1obj [list debug additional_flags=-DN=1]] != "" } {
+ untested "failed to compile shared object"
+ return -1
+}
+if { [gdb_compile_shlib $libsrc $lib2obj [list debug additional_flags=-DN=2]] != "" } {
+ untested "failed to compile shared object"
+ return -1
+}
+if { [gdb_compile_shlib $libsrc $lib3obj [list debug additional_flags=-DN=3]] != "" } {
+ untested "failed to compile shared object"
+ return -1
+}
+if { [gdb_compile_shlib $libsrc $lib4obj [list debug additional_flags=-DN=4]] != "" } {
+ untested "failed to compile shared object"
+ return -1
+}
+
+# Build shared objects to link against main program:
+if { [gdb_compile_shlib $libsrc $lib10obj [list debug additional_flags=-DN=10]] != "" } {
+ untested "failed to compile shared object"
+ return -1
+}
+if { [gdb_compile_shlib $libsrc $lib11obj [list debug additional_flags=-DN=11]] != "" } {
+ untested "failed to compile shared object"
+ return -1
+}
+
+# Use gdb_compile_pthreads to build and link the main program for
+# testing. It's also possible to run the tests using plain old
+# gdb_compile, but this adds complexity with setting up additional
+# KFAILs. (When run using GLIBC versions earlier than 2.34, a program
+# that's not dynamically linked against libpthread will lack a working
+# libthread_db, and, therefore, won't be able to access thread local
+# storage without GDB-internal TLS support. Additional complications
+# arise from when testing on x86_64 with -m32, which tends to work
+# okay on GLIBC 2.34 and newer, but not older versions. It gets messy
+# to properly sort out all of these cases.)
+#
+# This test was originally written to do it both ways, i.e. with both
+# both gdb_compile and gdb_compile_pthreads, but the point of this
+# test is to check that the link map address to TLS module id mapping
+# code works correctly in programs which use lots of dlopen and
+# dlclose calls in various orders - and that can be done using just
+# gdb_compile_pthreads.
+
+if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
+ [list debug shlib_load \
+ shlib=${lib10obj} \
+ shlib=${lib11obj} \
+ additional_flags=-DOBJ1=\"${lib1obj}\" \
+ additional_flags=-DOBJ2=\"${lib2obj}\" \
+ additional_flags=-DOBJ3=\"${lib3obj}\" \
+ additional_flags=-DOBJ4=\"${lib4obj}\" \
+ ]] != "" } {
+ untested "failed to compile"
+} else {
+ foreach_with_prefix force_internal_tls $internal_tls_iters {
+ do_tests $force_internal_tls
+ }
+}
diff --git a/gdb/testsuite/gdb.base/tls-multiobj.c b/gdb/testsuite/gdb.base/tls-multiobj.c
new file mode 100644
index 0000000..10e67da
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tls-multiobj.c
@@ -0,0 +1,89 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2024 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/>. */
+
+__thread int tls_main_tbss_1;
+__thread int tls_main_tbss_2;
+__thread int tls_main_tdata_1 = 96;
+__thread int tls_main_tdata_2 = 97;
+
+extern __thread int tls_lib1_tbss_1;
+extern __thread int tls_lib1_tbss_2;
+extern __thread int tls_lib1_tdata_1;
+extern __thread int tls_lib1_tdata_2;
+
+extern __thread int tls_lib2_tbss_1;
+extern __thread int tls_lib2_tbss_2;
+extern __thread int tls_lib2_tdata_1;
+extern __thread int tls_lib2_tdata_2;
+
+extern __thread int tls_lib3_tbss_1;
+extern __thread int tls_lib3_tbss_2;
+extern __thread int tls_lib3_tdata_1;
+extern __thread int tls_lib3_tdata_2;
+
+extern void lib1_func ();
+extern void lib2_func ();
+extern void lib3_func ();
+
+volatile int data;
+
+void
+use_it (int a)
+{
+ data = a;
+}
+
+int
+main (int argc, char **argv)
+{
+ use_it (-1);
+
+ tls_main_tbss_1 = 51; /* main-breakpoint-1 */
+ tls_main_tbss_2 = 52;
+ tls_main_tdata_1 = 53;
+ tls_main_tdata_2 = 54;
+
+ tls_lib1_tbss_1 = 151;
+ tls_lib1_tbss_2 = 152;
+ tls_lib1_tdata_1 = 153;
+ tls_lib1_tdata_2 = 154;
+
+ tls_lib2_tbss_1 = 251;
+ tls_lib2_tbss_2 = 252;
+ tls_lib2_tdata_1 = 253;
+ tls_lib2_tdata_2 = 254;
+
+ tls_lib3_tbss_1 = 351;
+ tls_lib3_tbss_2 = 352;
+ tls_lib3_tdata_1 = 353;
+ tls_lib3_tdata_2 = 354;
+
+ lib1_func ();
+ lib2_func ();
+ lib3_func ();
+
+ /* Attempt to keep variables in the main program from being optimized
+ away. */
+ use_it (tls_main_tbss_1);
+ use_it (tls_main_tbss_2);
+ use_it (tls_main_tdata_1);
+ use_it (tls_main_tdata_2);
+
+ use_it (100); /* main-breakpoint-2 */
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/tls-multiobj.exp b/gdb/testsuite/gdb.base/tls-multiobj.exp
new file mode 100644
index 0000000..97acb33
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tls-multiobj.exp
@@ -0,0 +1,230 @@
+# Copyright 2024 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.
+
+# Using different compilation/linking scenarios, attempt to access
+# thread-local variables in a non-threaded program using multiple
+# shared objects.
+
+source $srcdir/$subdir/tls-common.exp.tcl
+
+standard_testfile
+
+set lib1src "${srcdir}/${subdir}/${testfile}1.c"
+set lib2src "${srcdir}/${subdir}/${testfile}2.c"
+set lib3src "${srcdir}/${subdir}/${testfile}3.c"
+
+set lib1obj [standard_output_file "${testfile}1-lib.so"]
+set lib2obj [standard_output_file "${testfile}2-lib.so"]
+set lib3obj [standard_output_file "${testfile}3-lib.so"]
+
+proc do_tests {force_internal_tls {do_kfail_tls_access 0}} {
+ clean_restart $::binfile
+ if ![runto_main] {
+ return
+ }
+
+ if $force_internal_tls {
+ gdb_test_no_output "maint set force-internal-tls-address-lookup on"
+ }
+
+ if { $do_kfail_tls_access && [istarget "*-*-linux*"] } {
+ # Turn off do_kfail_tls_access when libthread_db is loaded.
+ # This can happen for the default case when testing x86_64
+ # w/ -m32 using glibc versions 2.34 or newer.
+ gdb_test_multiple "maint check libthread-db" "Check for loaded libthread_db" {
+ -re -wrap "libthread_db integrity checks passed." {
+ set do_kfail_tls_access 0
+ pass $gdb_test_name
+ }
+ -re -wrap "No libthread_db loaded" {
+ pass $gdb_test_name
+ }
+ }
+ # Also turn off do_kfail_tls_access when connected to a
+ # gdbserver and we observe that accessing a TLS variable
+ # works.
+ if [target_is_gdbserver] {
+ gdb_test_multiple "print tls_main_tbss_1" \
+ "Check TLS accessibility when connected to a gdbserver" {
+ -re -wrap "= 0" {
+ set do_kfail_tls_access 0
+ pass $gdb_test_name
+ }
+ -re -wrap "Remote target failed to process qGetTLSAddr request" {
+ pass $gdb_test_name
+ }
+ }
+ }
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-1"]
+ gdb_continue_to_breakpoint "main-breakpoint-1"
+
+ set t $do_kfail_tls_access
+ set m "tls not available"
+ with_test_prefix "before assignments" {
+ gdb_test_with_kfail "print tls_main_tbss_1" ".* = 0" $t $m
+ gdb_test_with_kfail "print tls_main_tbss_2" ".* = 0" $t $m
+ gdb_test_with_kfail "print tls_main_tdata_1" ".* = 96" $t $m
+ gdb_test_with_kfail "print tls_main_tdata_2" ".* = 97" $t $m
+
+ gdb_test_with_kfail "print tls_lib1_tbss_1" ".* = 0" $t $m
+ gdb_test_with_kfail "print tls_lib1_tbss_2" ".* = 0" $t $m
+ gdb_test_with_kfail "print tls_lib1_tdata_1" ".* = 196" $t $m
+ gdb_test_with_kfail "print tls_lib1_tdata_2" ".* = 197" $t $m
+
+ gdb_test_with_kfail "print tls_lib2_tbss_1" ".* = 0" $t $m
+ gdb_test_with_kfail "print tls_lib2_tbss_2" ".* = 0" $t $m
+ gdb_test_with_kfail "print tls_lib2_tdata_1" ".* = 296" $t $m
+ gdb_test_with_kfail "print tls_lib2_tdata_2" ".* = 297" $t $m
+
+ gdb_test_with_kfail "print tls_lib3_tbss_1" ".* = 0" $t $m
+ gdb_test_with_kfail "print tls_lib3_tbss_2" ".* = 0" $t $m
+ gdb_test_with_kfail "print tls_lib3_tdata_1" ".* = 396" $t $m
+ gdb_test_with_kfail "print tls_lib3_tdata_2" ".* = 397" $t $m
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-2"]
+ gdb_continue_to_breakpoint "main-breakpoint-2"
+
+ with_test_prefix "after assignments" {
+ gdb_test_with_kfail "print tls_main_tbss_1" ".* = 51" $t $m
+ gdb_test_with_kfail "print tls_main_tbss_2" ".* = 52" $t $m
+ gdb_test_with_kfail "print tls_main_tdata_1" ".* = 53" $t $m
+ gdb_test_with_kfail "print tls_main_tdata_2" ".* = 54" $t $m
+
+ gdb_test_with_kfail "print tls_lib1_tbss_1" ".* = 151" $t $m
+ gdb_test_with_kfail "print tls_lib1_tbss_2" ".* = 152" $t $m
+ gdb_test_with_kfail "print tls_lib1_tdata_1" ".* = 153" $t $m
+ gdb_test_with_kfail "print tls_lib1_tdata_2" ".* = 154" $t $m
+
+ gdb_test_with_kfail "print tls_lib2_tbss_1" ".* = 251" $t $m
+ gdb_test_with_kfail "print tls_lib2_tbss_2" ".* = 252" $t $m
+ gdb_test_with_kfail "print tls_lib2_tdata_1" ".* = 253" $t $m
+ gdb_test_with_kfail "print tls_lib2_tdata_2" ".* = 254" $t $m
+
+ gdb_test_with_kfail "print tls_lib3_tbss_1" ".* = 351" $t $m
+ gdb_test_with_kfail "print tls_lib3_tbss_2" ".* = 352" $t $m
+ gdb_test_with_kfail "print tls_lib3_tdata_1" ".* = 353" $t $m
+ gdb_test_with_kfail "print tls_lib3_tdata_2" ".* = 354" $t $m
+ }
+
+ set corefile ${::binfile}.core
+ set core_supported 0
+ if { ![is_remote host] } {
+ set core_supported [gdb_gcore_cmd $corefile "save corefile"]
+ }
+
+ # Finish test early if no core file was made.
+ if !$core_supported {
+ return
+ }
+
+ clean_restart $::binfile
+
+ set core_loaded [gdb_core_cmd $corefile "load corefile"]
+ if { $core_loaded == -1 } {
+ return
+ }
+
+ with_test_prefix "core file" {
+ if $force_internal_tls {
+ gdb_test_no_output "maint set force-internal-tls-address-lookup on"
+ }
+
+ gdb_test_with_kfail "print tls_main_tbss_1" ".* = 51" $t $m
+ gdb_test_with_kfail "print tls_main_tbss_2" ".* = 52" $t $m
+ gdb_test_with_kfail "print tls_main_tdata_1" ".* = 53" $t $m
+ gdb_test_with_kfail "print tls_main_tdata_2" ".* = 54" $t $m
+
+ gdb_test_with_kfail "print tls_lib1_tbss_1" ".* = 151" $t $m
+ gdb_test_with_kfail "print tls_lib1_tbss_2" ".* = 152" $t $m
+ gdb_test_with_kfail "print tls_lib1_tdata_1" ".* = 153" $t $m
+ gdb_test_with_kfail "print tls_lib1_tdata_2" ".* = 154" $t $m
+
+ gdb_test_with_kfail "print tls_lib2_tbss_1" ".* = 251" $t $m
+ gdb_test_with_kfail "print tls_lib2_tbss_2" ".* = 252" $t $m
+ gdb_test_with_kfail "print tls_lib2_tdata_1" ".* = 253" $t $m
+ gdb_test_with_kfail "print tls_lib2_tdata_2" ".* = 254" $t $m
+
+ gdb_test_with_kfail "print tls_lib3_tbss_1" ".* = 351" $t $m
+ gdb_test_with_kfail "print tls_lib3_tbss_2" ".* = 352" $t $m
+ gdb_test_with_kfail "print tls_lib3_tdata_1" ".* = 353" $t $m
+ gdb_test_with_kfail "print tls_lib3_tdata_2" ".* = 354" $t $m
+ }
+}
+
+if { [gdb_compile_shlib $lib1src $lib1obj {debug}] != "" } {
+ untested "failed to compile shared object"
+ return -1
+}
+if { [gdb_compile_shlib $lib2src $lib2obj {debug}] != "" } {
+ untested "failed to compile shared object"
+ return -1
+}
+if { [gdb_compile_shlib $lib3src $lib3obj {debug}] != "" } {
+ untested "failed to compile shared object"
+ return -1
+}
+
+# Certain linux target architectures implement support for internal
+# TLS lookup which is used when thread stratum support (via
+# libthread_db) is missing or when the linux-only GDB maintenance
+# setting 'force-internal-tls-address-lookup' is 'on'. Thus for some
+# of the testing scenarios, such as statically linked executables,
+# this internal support will be used. Set 'do_kfail_tls_access' to 1
+# for those architectures which don't implement internal tls support.
+if {[istarget *-*-linux*]
+ && ![is_any_target {*}$internal_tls_linux_targets]} {
+ set do_kfail_tls_access 1
+} elseif {[istarget *-*-linux*] && [is_x86_like_target]} {
+ # This covers the case of x86_64 with -m32:
+ set do_kfail_tls_access 1
+} else {
+ set do_kfail_tls_access 0
+}
+
+set binprefix $binfile
+
+with_test_prefix "default" {
+ set binfile $binprefix-default
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
+ [list debug shlib=${lib1obj} \
+ shlib=${lib2obj} \
+ shlib=${lib3obj}]] != "" } {
+ untested "failed to compile"
+ } else {
+ foreach_with_prefix force_internal_tls $internal_tls_iters {
+ # Depending on glibc version, it might not be appropriate
+ # for do_kfail_tls_access to be set here. That will be
+ # handled in 'do_tests', disabling it if necessary.
+ #
+ # Specifically, glibc versions 2.34 and later have the
+ # thread library (and libthread_db availability) in
+ # programs not linked against libpthread.so
+ do_tests $force_internal_tls $do_kfail_tls_access
+ }
+ }
+}
+
+with_test_prefix "pthreads" {
+ set binfile $binprefix-pthreads
+ if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
+ [list debug shlib=${lib1obj} \
+ shlib=${lib2obj} \
+ shlib=${lib3obj}]] != "" } {
+ untested "failed to compile"
+ } else {
+ foreach_with_prefix force_internal_tls $internal_tls_iters {
+ do_tests $force_internal_tls
+ }
+ }
+}
diff --git a/gdb/testsuite/gdb.base/tls-multiobj1.c b/gdb/testsuite/gdb.base/tls-multiobj1.c
new file mode 100644
index 0000000..86e7222
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tls-multiobj1.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2024 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/>. */
+
+__thread int tls_lib1_tbss_1;
+__thread int tls_lib1_tbss_2;
+__thread int tls_lib1_tdata_1 = 196;
+__thread int tls_lib1_tdata_2 = 197;
+
+void
+lib1_func ()
+{
+}
diff --git a/gdb/testsuite/gdb.base/tls-multiobj2.c b/gdb/testsuite/gdb.base/tls-multiobj2.c
new file mode 100644
index 0000000..cea0709
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tls-multiobj2.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2024 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/>. */
+
+__thread int tls_lib2_tbss_1;
+__thread int tls_lib2_tbss_2;
+__thread int tls_lib2_tdata_1 = 296;
+__thread int tls_lib2_tdata_2 = 297;
+
+void
+lib2_func ()
+{
+}
diff --git a/gdb/testsuite/gdb.base/tls-multiobj3.c b/gdb/testsuite/gdb.base/tls-multiobj3.c
new file mode 100644
index 0000000..bb0f239
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tls-multiobj3.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2024 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/>. */
+
+__thread int tls_lib3_tbss_1;
+__thread int tls_lib3_tbss_2;
+__thread int tls_lib3_tdata_1 = 396;
+__thread int tls_lib3_tdata_2 = 397;
+
+void
+lib3_func ()
+{
+}
diff --git a/gdb/testsuite/gdb.base/tls-nothreads.c b/gdb/testsuite/gdb.base/tls-nothreads.c
new file mode 100644
index 0000000..b3aaa33
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tls-nothreads.c
@@ -0,0 +1,57 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2024 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/>. */
+
+__thread int tls_tbss_1;
+__thread int tls_tbss_2;
+__thread int tls_tbss_3;
+
+__thread int tls_tdata_1 = 21;
+__thread int tls_tdata_2 = 22;
+__thread int tls_tdata_3 = 23;
+
+volatile int data;
+
+void
+use_it (int a)
+{
+ data = a;
+}
+
+int
+main (int argc, char **argv)
+{
+ use_it (-1);
+
+ tls_tbss_1 = 24; /* main-breakpoint-1 */
+ tls_tbss_2 = 25;
+ tls_tbss_3 = 26;
+
+ tls_tdata_1 = 42;
+ tls_tdata_2 = 43;
+ tls_tdata_3 = 44;
+
+ use_it (tls_tbss_1);
+ use_it (tls_tbss_2);
+ use_it (tls_tbss_3);
+ use_it (tls_tdata_1);
+ use_it (tls_tdata_2);
+ use_it (tls_tdata_3);
+
+ use_it (100); /* main-breakpoint-2 */
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/tls-nothreads.exp b/gdb/testsuite/gdb.base/tls-nothreads.exp
new file mode 100644
index 0000000..92a5cd9
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tls-nothreads.exp
@@ -0,0 +1,248 @@
+# Copyright 2024 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.
+
+# Using different compilation/linking scenarios, attempt to access
+# thread-local variables in a non-threaded program. Also test that
+# GDB internal TLS lookup works correctly.
+
+source $srcdir/$subdir/tls-common.exp.tcl
+
+standard_testfile
+
+proc do_tests {force_internal_tls {do_kfail_tls_access 0}} {
+ clean_restart $::binfile
+ if ![runto_main] {
+ return
+ }
+
+ if $force_internal_tls {
+ gdb_test_no_output "maint set force-internal-tls-address-lookup on"
+ }
+
+ if { $do_kfail_tls_access && [istarget "*-*-linux*"] } {
+ # Turn off do_kfail_tls_access when libthread_db is loaded.
+ # This can happen for the default case when testing x86_64
+ # w/ -m32 using glibc versions 2.34 or newer.
+ gdb_test_multiple "maint check libthread-db" "Check for loaded libthread_db" {
+ -re -wrap "libthread_db integrity checks passed." {
+ set do_kfail_tls_access 0
+ pass $gdb_test_name
+ }
+ -re -wrap "No libthread_db loaded" {
+ pass $gdb_test_name
+ }
+ }
+ # Also turn off do_kfail_tls_access when connected to a
+ # gdbserver and we observe that accessing a TLS variable
+ # works.
+ if [target_is_gdbserver] {
+ gdb_test_multiple "print tls_tbss_1" "Check TLS accessibility when connected to a gdbserver" {
+ -re -wrap "= 0" {
+ set do_kfail_tls_access 0
+ pass $gdb_test_name
+ }
+ -re -wrap "Remote target failed to process qGetTLSAddr request" {
+ pass $gdb_test_name
+ }
+ }
+ }
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-1"]
+ gdb_continue_to_breakpoint "main-breakpoint-1"
+
+ set t $do_kfail_tls_access
+ set m "tls not available"
+ with_test_prefix "before assignments" {
+ gdb_test_with_kfail "print tls_tbss_1" ".* = 0" $t $m
+ gdb_test_with_kfail "print tls_tbss_2" ".* = 0" $t $m
+ gdb_test_with_kfail "print tls_tbss_3" ".* = 0" $t $m
+
+ gdb_test_with_kfail "print tls_tdata_1" ".* = 21" $t $m
+ gdb_test_with_kfail "print tls_tdata_2" ".* = 22" $t $m
+ gdb_test_with_kfail "print tls_tdata_3" ".* = 23" $t $m
+ }
+
+ gdb_breakpoint [gdb_get_line_number "main-breakpoint-2"]
+ gdb_continue_to_breakpoint "main-breakpoint-2"
+
+ with_test_prefix "after assignments" {
+ gdb_test_with_kfail "print tls_tbss_1" ".* = 24" $t $m
+ gdb_test_with_kfail "print tls_tbss_2" ".* = 25" $t $m
+ gdb_test_with_kfail "print tls_tbss_3" ".* = 26" $t $m
+
+ gdb_test_with_kfail "print tls_tdata_1" ".* = 42" $t $m
+ gdb_test_with_kfail "print tls_tdata_2" ".* = 43" $t $m
+ gdb_test_with_kfail "print tls_tdata_3" ".* = 44" $t $m
+ }
+
+ # Make a core file now, but save testing using it until the end
+ # in case core files are not supported.
+ set corefile ${::binfile}.core
+ set core_supported 0
+ if { ![is_remote host] } {
+ set core_supported [gdb_gcore_cmd $corefile "save corefile"]
+ }
+
+ # Now continue to end and see what happens when attempting to
+ # access a TLS variable when the program is no longer running.
+ gdb_continue_to_end
+ with_test_prefix "after exit" {
+ gdb_test "print tls_tbss_1" \
+ "Cannot (?:read|find address of TLS symbol) `tls_tbss_1' without registers"
+ }
+
+ with_test_prefix "stripped" {
+ set binfile_stripped "${::binfile}.stripped"
+ set objcopy [gdb_find_objcopy]
+ set cmd "$objcopy --strip-debug ${::binfile} $binfile_stripped"
+ if ![catch "exec $cmd" cmd_output] {
+ clean_restart $binfile_stripped
+ if ![runto_main] {
+ return
+ }
+
+ if $force_internal_tls {
+ gdb_test_no_output "maint set force-internal-tls-address-lookup on"
+ }
+
+ # While there are no debug (e.g. DWARF) symbols, there
+ # are minimal symbols, so we should be able to place a
+ # breakpoint in use_it and continue to it. Continuing
+ # twice should put us past the assignments, at which point
+ # we can see if the TLS variables are still accessible.
+ gdb_test "break use_it" "Breakpoint 2 at $::hex"
+ gdb_test "continue" "Breakpoint 2, $::hex in use_it.*"
+ gdb_test "continue" "Breakpoint 2, $::hex in use_it.*" "continue 2"
+
+ # Note that a cast has been added in order to avoid the
+ # "...has unknown type; cast it to its declared type"
+ # problem.
+ gdb_test_with_kfail "print (int) tls_tbss_1" ".* = 24" $t $m
+ gdb_test_with_kfail "print (int) tls_tbss_2" ".* = 25" $t $m
+ gdb_test_with_kfail "print (int) tls_tbss_3" ".* = 26" $t $m
+
+ gdb_test_with_kfail "print (int) tls_tdata_1" ".* = 42" $t $m
+ gdb_test_with_kfail "print (int) tls_tdata_2" ".* = 43" $t $m
+ gdb_test_with_kfail "print (int) tls_tdata_3" ".* = 44" $t $m
+
+ # Get rid of the "use_it" breakpoint
+ gdb_test_no_output "del 2"
+
+ # Continue to program exit
+ gdb_continue_to_end
+
+ # TLS variables should not be accessible after program exit
+ # (This case initially caused GDB to crash during development
+ # of GDB-internal TLS lookup support.)
+ with_test_prefix "after exit" {
+ gdb_test "print (int) tls_tbss_1" \
+ "Cannot find address of TLS symbol `tls_tbss_1' without registers"
+ }
+ }
+ }
+
+ # Finish test early if no core file was made.
+ if !$core_supported {
+ return
+ }
+
+ clean_restart $::binfile
+
+ set core_loaded [gdb_core_cmd $corefile "load corefile"]
+ if { $core_loaded == -1 } {
+ return
+ }
+
+ with_test_prefix "core file" {
+ if $force_internal_tls {
+ gdb_test_no_output "maint set force-internal-tls-address-lookup on"
+ }
+
+ gdb_test_with_kfail "print tls_tbss_1" ".* = 24" $t $m
+ gdb_test_with_kfail "print tls_tbss_2" ".* = 25" $t $m
+ gdb_test_with_kfail "print tls_tbss_3" ".* = 26" $t $m
+
+ gdb_test_with_kfail "print tls_tdata_1" ".* = 42" $t $m
+ gdb_test_with_kfail "print tls_tdata_2" ".* = 43" $t $m
+ gdb_test_with_kfail "print tls_tdata_3" ".* = 44" $t $m
+ }
+}
+
+# Certain linux target architectures implement support for internal
+# TLS lookup which is used when thread stratum support (via
+# libthread_db) is missing or when the linux-only GDB maintenance
+# setting 'force-internal-tls-address-lookup' is 'on'. Thus for some
+# of the testing scenarios, such as statically linked executables,
+# this internal support will be used. Set 'do_kfail_tls_access' to 1
+# for those architectures which don't implement internal TLS support.
+if {[istarget *-*-linux*]
+ && ![is_any_target {*}$internal_tls_linux_targets]} {
+ set do_kfail_tls_access 1
+} elseif {[istarget *-*-linux*] && [is_x86_like_target]} {
+ # This covers the case of x86_64 with -m32:
+ set do_kfail_tls_access 1
+} else {
+ set do_kfail_tls_access 0
+}
+
+set binprefix $binfile
+
+with_test_prefix "default" {
+ set binfile $binprefix-default
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ untested "failed to compile"
+ } else {
+ foreach_with_prefix force_internal_tls $internal_tls_iters {
+ # Depending on glibc version, it might not be appropriate
+ # for do_kfail_tls_access to be set here. That will be
+ # handled in 'do_tests', disabling it if necessary.
+ #
+ # Specifically, glibc versions 2.34 and later have the
+ # thread library (and libthread_db availability) in
+ # programs not linked against libpthread.so
+ do_tests $force_internal_tls $do_kfail_tls_access
+ }
+ }
+}
+
+with_test_prefix "static" {
+ set binfile $binprefix-static
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug "additional_flags=-static"}] != "" } {
+ untested "failed to compile"
+ } else {
+ foreach_with_prefix force_internal_tls $internal_tls_iters {
+ do_tests $force_internal_tls $do_kfail_tls_access
+ }
+ }
+}
+
+with_test_prefix "pthreads" {
+ set binfile $binprefix-pthreads
+ if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ untested "failed to compile"
+ } else {
+ foreach_with_prefix force_internal_tls $internal_tls_iters {
+ do_tests $force_internal_tls
+ }
+ }
+}
+
+with_test_prefix "pthreads-static" {
+ set binfile $binprefix-pthreads-static
+ if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug "additional_flags=-static"}] != "" } {
+ untested "failed to compile"
+ } else {
+ foreach_with_prefix force_internal_tls $internal_tls_iters {
+ do_tests $force_internal_tls $do_kfail_tls_access
+ }
+ }
+}
diff --git a/gdb/testsuite/gdb.cp/cplusfuncs.exp b/gdb/testsuite/gdb.cp/cplusfuncs.exp
index 94d9df3..e785909 100644
--- a/gdb/testsuite/gdb.cp/cplusfuncs.exp
+++ b/gdb/testsuite/gdb.cp/cplusfuncs.exp
@@ -579,7 +579,8 @@ proc do_tests {} {
gdb_test_no_output "set width 0"
- runto_main
+ # Don't run to main, to avoid loading and expanding debug info for
+ # libstdc++.
gdb_test_no_output "set language c++"
probe_demangler
diff --git a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
index 7b36f65..4b3894e 100644
--- a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
+++ b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp
@@ -152,7 +152,7 @@ proc_with_prefix no_url { } {
# Test that GDB cannot find dwz without debuginfod.
clean_restart
gdb_test "file ${binfile}_alt.o" \
- ".*could not find '.gnu_debugaltlink'.*" \
+ ".*could not find supplementary DWARF file .*" \
"file [file tail ${binfile}_alt.o]"
# Generate a core file and test that GDB cannot find the
diff --git a/gdb/testsuite/gdb.dwarf2/dwzbuildid.exp b/gdb/testsuite/gdb.dwarf2/dwzbuildid.exp
index 055e69c..080e999 100644
--- a/gdb/testsuite/gdb.dwarf2/dwzbuildid.exp
+++ b/gdb/testsuite/gdb.dwarf2/dwzbuildid.exp
@@ -13,160 +13,5 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-load_lib dwarf.exp
-
-# This test can only be run on targets which support DWARF-2 and use gas.
-require dwarf2_support
-
-# No remote host testing either.
-require {!is_remote host}
-
-
-# Lots of source files since we test a few cases and make new files
-# for each.
-# The tests are:
-# ok - the main file refers to a dwz and the buildids match
-# mismatch - the buildids do not match
-# fallback - the buildids do not match but a match is found via buildid
-standard_testfile main.c \
- dwzbuildid-ok-base.S dwzbuildid-ok-sep.S \
- dwzbuildid-mismatch-base.S dwzbuildid-mismatch-sep.S \
- dwzbuildid-fallback-base.S dwzbuildid-fallback-sep.S \
- dwzbuildid-fallback-ok.S
-
-# Write some assembly that just has a .gnu_debugaltlink section.
-proc write_just_debugaltlink {filename dwzname buildid} {
- set asm_file [standard_output_file $filename]
-
- Dwarf::assemble $asm_file {
- upvar dwzname dwzname
- upvar buildid buildid
-
- gnu_debugaltlink $dwzname $buildid
-
- # Only the DWARF reader checks .gnu_debugaltlink, so make sure
- # there is a bit of DWARF in here.
- cu { label cu_start } {
- compile_unit {{language @DW_LANG_C}} {
- }
- }
- aranges {} cu_start {
- arange {} 0 0
- }
- }
-}
-
-# Write some DWARF that also sets the buildid.
-proc write_dwarf_file {filename buildid {value 99}} {
- set asm_file [standard_output_file $filename]
-
- Dwarf::assemble $asm_file {
- declare_labels int_label int_label2
-
- upvar buildid buildid
- upvar value value
-
- build_id $buildid
-
- cu { label cu_start } {
- compile_unit {{language @DW_LANG_C}} {
- int_label2: base_type {
- {name int}
- {byte_size 4 sdata}
- {encoding @DW_ATE_signed}
- }
-
- constant {
- {name the_int}
- {type :$int_label2}
- {const_value $value data1}
- }
- }
- }
-
- aranges {} cu_start {
- arange {} 0 0
- }
- }
-}
-
-if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
- object {nodebug}] != "" } {
- return -1
-}
-
-# The values don't really matter, just whether they are equal.
-set ok_prefix 01
-set ok_suffix 02030405060708091011121314151617181920
-set ok_suffix2 020304050607080910111213141516171819ff
-set ok_buildid ${ok_prefix}${ok_suffix}
-set ok_buildid2 ${ok_prefix}${ok_suffix2}
-set bad_buildid [string repeat ff 20]
-
-set debugdir [standard_output_file {}]
-set basedir $debugdir/.build-id
-file mkdir $basedir $basedir/$ok_prefix
-
-# Test where the separate debuginfo's buildid matches.
-write_just_debugaltlink $srcfile2 ${binfile}3.o $ok_buildid
-write_dwarf_file $srcfile3 $ok_buildid
-
-# Test where the separate debuginfo's buildid does not match.
-write_just_debugaltlink $srcfile4 ${binfile}5.o $ok_buildid
-write_dwarf_file $srcfile5 $bad_buildid
-
-# Test where the separate debuginfo's buildid does not match, but then
-# we find a match in the .build-id directory.
-write_just_debugaltlink $srcfile6 ${binfile}7.o $ok_buildid2
-# Use 77 as the value so that if we load the bad debuginfo, we will
-# see the wrong result.
-write_dwarf_file $srcfile7 $bad_buildid 77
-write_dwarf_file $srcfile8 $ok_buildid2
-
-# Compile everything.
-for {set i 2} {$i <= 8} {incr i} {
- if {[gdb_compile [standard_output_file [set srcfile$i]] \
- ${binfile}$i.o object nodebug] != ""} {
- return -1
- }
-}
-
-# Copy a file into the .build-id place for the "fallback" test.
-file copy -force -- ${binfile}8.o $basedir/$ok_prefix/$ok_suffix2.debug
-
-proc do_test {} {
- clean_restart
-
- gdb_test_no_output "set debug-file-directory $::debugdir" \
- "set debug-file-directory"
-
- gdb_load ${::binfile}-${::testname}
-
- if {![runto_main]} {
- return
- }
-
- if {$::testname == "mismatch"} {
- gdb_test "print the_int" \
- "(No symbol table is loaded|No symbol \"the_int\" in current context).*"
- } else {
- gdb_test "print the_int" " = 99"
- }
-}
-
-foreach_with_prefix testname { ok mismatch fallback } {
- if { $testname == "ok" } {
- set objs [list ${binfile}1.o ${binfile}2.o]
- } elseif { $testname == "mismatch" } {
- set objs [list ${binfile}1.o ${binfile}4.o]
- } elseif { $testname == "fallback" } {
- set objs [list ${binfile}1.o ${binfile}6.o]
- }
-
- if {[gdb_compile $objs ${binfile}-$testname executable {quiet}] != ""} {
- unsupported "compilation failed"
- continue
- }
-
- do_test
-}
+set scenario gnu
+source $srcdir/$subdir/dwzbuildid.tcl
diff --git a/gdb/testsuite/gdb.dwarf2/dwzbuildid.tcl b/gdb/testsuite/gdb.dwarf2/dwzbuildid.tcl
new file mode 100644
index 0000000..a9077eb
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dwzbuildid.tcl
@@ -0,0 +1,184 @@
+# Copyright 2013-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/>.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+require dwarf2_support
+
+# No remote host testing either.
+require {!is_remote host}
+
+
+# Lots of source files since we test a few cases and make new files
+# for each.
+# The tests are:
+# ok - the main file refers to a dwz and the buildids match
+# mismatch - the buildids do not match
+# fallback - the buildids do not match but a match is found via buildid
+standard_testfile main.c \
+ dwzbuildid-ok-base.S dwzbuildid-ok-sep.S \
+ dwzbuildid-mismatch-base.S dwzbuildid-mismatch-sep.S \
+ dwzbuildid-fallback-base.S dwzbuildid-fallback-sep.S \
+ dwzbuildid-fallback-ok.S
+
+# Write some assembly that just has a .gnu_debugaltlink section.
+proc write_just_debugaltlink {filename dwzname buildid} {
+ set asm_file [standard_output_file $filename]
+
+ Dwarf::assemble $asm_file {
+ upvar dwzname dwzname
+ upvar buildid buildid
+
+ if {$::scenario == "gnu"} {
+ gnu_debugaltlink $dwzname $buildid
+ } else {
+ debug_sup 0 $dwzname $buildid
+ }
+
+ # Only the DWARF reader checks .gnu_debugaltlink, so make sure
+ # there is a bit of DWARF in here.
+ cu { label cu_start } {
+ compile_unit {{language @DW_LANG_C}} {
+ }
+ }
+ aranges {} cu_start {
+ arange {} 0 0
+ }
+ }
+}
+
+# Write some DWARF that also sets the buildid.
+proc write_dwarf_file {filename buildid {value 99}} {
+ set asm_file [standard_output_file $filename]
+
+ Dwarf::assemble $asm_file {
+ declare_labels int_label int_label2
+
+ upvar buildid buildid
+ upvar value value
+
+ if {$::scenario == "gnu"} {
+ build_id $buildid
+ } else {
+ debug_sup 1 "" $buildid
+ }
+
+ cu { label cu_start } {
+ compile_unit {{language @DW_LANG_C}} {
+ int_label2: base_type {
+ {name int}
+ {byte_size 4 sdata}
+ {encoding @DW_ATE_signed}
+ }
+
+ constant {
+ {name the_int}
+ {type :$int_label2}
+ {const_value $value data1}
+ }
+ }
+ }
+
+ aranges {} cu_start {
+ arange {} 0 0
+ }
+ }
+}
+
+if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \
+ object {nodebug}] != "" } {
+ return -1
+}
+
+# The values don't really matter, just whether they are equal.
+set ok_prefix 01
+set ok_suffix 02030405060708091011121314151617181920
+set ok_suffix2 020304050607080910111213141516171819ff
+set ok_buildid ${ok_prefix}${ok_suffix}
+set ok_buildid2 ${ok_prefix}${ok_suffix2}
+set bad_buildid [string repeat ff 20]
+
+set debugdir [standard_output_file {}]
+set basedir $debugdir/.build-id
+file mkdir $basedir $basedir/$ok_prefix
+
+# Test where the separate debuginfo's buildid matches.
+write_just_debugaltlink $srcfile2 ${binfile}3.o $ok_buildid
+write_dwarf_file $srcfile3 $ok_buildid
+
+# Test where the separate debuginfo's buildid does not match.
+write_just_debugaltlink $srcfile4 ${binfile}5.o $ok_buildid
+write_dwarf_file $srcfile5 $bad_buildid
+
+# Test where the separate debuginfo's buildid does not match, but then
+# we find a match in the .build-id directory.
+write_just_debugaltlink $srcfile6 ${binfile}7.o $ok_buildid2
+# Use 77 as the value so that if we load the bad debuginfo, we will
+# see the wrong result.
+write_dwarf_file $srcfile7 $bad_buildid 77
+write_dwarf_file $srcfile8 $ok_buildid2
+
+# Compile everything.
+for {set i 2} {$i <= 8} {incr i} {
+ if {[gdb_compile [standard_output_file [set srcfile$i]] \
+ ${binfile}$i.o object nodebug] != ""} {
+ return -1
+ }
+}
+
+# Copy a file into the .build-id place for the "fallback" test.
+file copy -force -- ${binfile}8.o $basedir/$ok_prefix/$ok_suffix2.debug
+
+proc do_test {} {
+ clean_restart
+
+ gdb_test_no_output "set debug-file-directory $::debugdir" \
+ "set debug-file-directory"
+
+ gdb_load ${::binfile}-${::testname}
+
+ if {![runto_main]} {
+ return
+ }
+
+ if {$::testname == "mismatch"} {
+ gdb_test "print the_int" \
+ "(No symbol table is loaded|No symbol \"the_int\" in current context).*"
+ } else {
+ gdb_test "print the_int" " = 99"
+ }
+}
+
+set tests {ok mismatch}
+if {$scenario == "gnu"} {
+ lappend tests fallback
+}
+foreach_with_prefix testname $tests {
+ if { $testname == "ok" } {
+ set objs [list ${binfile}1.o ${binfile}2.o]
+ } elseif { $testname == "mismatch" } {
+ set objs [list ${binfile}1.o ${binfile}4.o]
+ } elseif { $testname == "fallback" } {
+ set objs [list ${binfile}1.o ${binfile}6.o]
+ }
+
+ if {[gdb_compile $objs ${binfile}-$testname executable {quiet}] != ""} {
+ unsupported "compilation failed"
+ continue
+ }
+
+ do_test
+}
diff --git a/gdb/testsuite/gdb.dwarf2/dwzbuildid5.exp b/gdb/testsuite/gdb.dwarf2/dwzbuildid5.exp
new file mode 100644
index 0000000..047626c
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dwzbuildid5.exp
@@ -0,0 +1,17 @@
+# 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/>.
+
+set scenario dwarf5
+source $srcdir/$subdir/dwzbuildid.tcl
diff --git a/gdb/testsuite/gdb.dwarf2/dwznolink.exp b/gdb/testsuite/gdb.dwarf2/dwznolink.exp
index 91fe369..0c486ea 100644
--- a/gdb/testsuite/gdb.dwarf2/dwznolink.exp
+++ b/gdb/testsuite/gdb.dwarf2/dwznolink.exp
@@ -49,5 +49,5 @@ if {[build_executable $testfile.exp $testfile \
clean_restart
gdb_test "file -readnow $binfile" \
- "could not read '.gnu_debugaltlink' section" \
+ "could not find supplementary DWARF file" \
"file $testfile"
diff --git a/gdb/testsuite/gdb.dwarf2/fission-with-type-unit.exp b/gdb/testsuite/gdb.dwarf2/fission-with-type-unit.exp
index a1b3bb7..0a02f7c 100644
--- a/gdb/testsuite/gdb.dwarf2/fission-with-type-unit.exp
+++ b/gdb/testsuite/gdb.dwarf2/fission-with-type-unit.exp
@@ -91,6 +91,10 @@ if { [gdb_compile_shlib $dwo_asm_file $dwo_file nodebug] != "" } {
return
}
+if { [is_remote host] } {
+ gdb_remote_download host $dwo_file
+}
+
clean_restart ${testfile}
# This would cause an internal error.
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw4.exp b/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw4.exp
new file mode 100644
index 0000000..c0c2635
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw4.exp
@@ -0,0 +1,71 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2022-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/>.
+
+# Generate binaries imitating different ways source file paths can be passed to
+# compilers. Test printing macros from those binaries.
+
+# The do_test proc comes from macro-source-path.exp.tcl.
+source $srcdir/$subdir/macro-source-path.exp.tcl
+
+# When adding a test here, please consider adding an equivalent case to
+# `gdb.base/macro-source-path.exp`.
+
+# The following tests are based on the output of `clang-14 -gdwarf-4
+# -fdebug-macro -g3 <file>` (using its built-in assembler). With -gdwarf-4,
+# clang produces a .debug_macinfo section, not a .debug_macro section. But
+# this test still creates a .debug_macro section, that's good enough for what
+# we want to test.
+
+## test.c
+do_test filename 4 "test.c" 1 {
+} {
+ {"test.c" 0}
+}
+
+## ./test.c
+do_test dot-filename 4 "test.c" 1 {
+ "."
+} {
+ {"test.c" 1}
+}
+
+## ../cwd/test.c
+do_test dot-dot-cwd 4 "../cwd/test.c" 1 {
+ "../cwd"
+} {
+ {"test.c" 1}
+}
+
+## /tmp/cwd/test.c
+do_test absolute-cwd 4 "/tmp/cwd/test.c" 1 {
+} {
+ {"test.c" 0}
+}
+
+## ../other/test.c
+do_test dot-dot-other 4 "../other/test.c" 1 {
+ "../other"
+} {
+ {"test.c" 1}
+}
+
+## /tmp/other/test.c
+do_test absolute-other 4 "/tmp/other/test.c" 1 {
+ "/tmp"
+} {
+ {"other/test.c" 1}
+}
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw5.exp b/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw5.exp
new file mode 100644
index 0000000..0b3239e
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path-clang14-dw5.exp
@@ -0,0 +1,75 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2022-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/>.
+
+# Generate binaries imitating different ways source file paths can be passed to
+# compilers. Test printing macros from those binaries.
+
+# The do_test proc comes from macro-source-path.exp.tcl.
+source $srcdir/$subdir/macro-source-path.exp.tcl
+
+# When adding a test here, please consider adding an equivalent case to
+# `gdb.base/macro-source-path.exp`.
+
+# The following tests are based on the output of `clang-14 -gdwarf-5
+# -fdebug-macro -g3 <file>` (using its built-in assembler)
+
+## test.c
+do_test filename 5 "test.c" 0 {
+ "/tmp/cwd"
+} {
+ {"test.c" 0}
+}
+
+## ./test.c
+do_test dot-filename 5 "test.c" 1 {
+ "/tmp/cwd"
+ "."
+} {
+ {"test.c" 0}
+ {"test.c" 1}
+}
+
+## ../cwd/test.c
+do_test dot-dot-cwd 5 "../cwd/test.c" 0 {
+ "/tmp/cwd"
+} {
+ {"../cwd/test.c" 0}
+}
+
+## /tmp/cwd/test.c
+do_test absolute-cwd 5 "/tmp/cwd/test.c" 1 {
+ "/tmp/cwd"
+} {
+ {"/tmp/cwd/test.c" 0}
+ {"test.c" 0}
+}
+
+## ../other/test.c
+do_test dot-dot-other 5 "../other/test.c" 0 {
+ "/tmp/cwd"
+} {
+ {"../other/test.c" 0}
+}
+
+## /tmp/other/test.c
+do_test absolute-other 5 "/tmp/other/test.c" 1 {
+ "/tmp/cwd"
+ "/tmp"
+} {
+ {"/tmp/other/test.c" 0}
+ {"other/test.c" 1}
+}
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld234-dw5.exp b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld234-dw5.exp
new file mode 100644
index 0000000..940f997
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld234-dw5.exp
@@ -0,0 +1,70 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2022-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/>.
+
+# Generate binaries imitating different ways source file paths can be passed to
+# compilers. Test printing macros from those binaries.
+
+# The do_test proc comes from macro-source-path.exp.tcl.
+source $srcdir/$subdir/macro-source-path.exp.tcl
+
+# When adding a test here, please consider adding an equivalent case to
+# `gdb.base/macro-source-path.exp`.
+
+# The following tests are based on the output of `gcc -gdwarf-5 -g3 <file>`,
+# gcc 11 paired with gas from binutils 2.34 (Ubuntu 20.04). It generates a v5
+# .debug_macro section, but a v3 .debug_line section.
+
+## test.c
+do_test filename 3 "test.c" 1 {
+} {
+ {"test.c" 0}
+}
+
+## ./test.c
+do_test dot-filename 3 "./test.c" 1 {
+ "."
+} {
+ {"test.c" 1}
+}
+
+## ../cwd/test.c
+do_test dot-dot-cwd 3 "../cwd/test.c" 1 {
+ "../cwd"
+} {
+ {"test.c" 1}
+}
+
+## /tmp/cwd/test.c
+do_test absolute-cwd 3 "/tmp/cwd/test.c" 1 {
+ "/tmp/cwd"
+} {
+ {"test.c" 1}
+}
+
+## ../other/test.c
+do_test dot-dot-other 3 "../other/test.c" 1 {
+ "../other"
+} {
+ {"test.c" 1}
+}
+
+## /tmp/other/test.c
+do_test absolute-other 3 "/tmp/other/test.c" 1 {
+ "/tmp/other"
+} {
+ {"test.c" 1}
+}
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw4.exp b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw4.exp
new file mode 100644
index 0000000..dea0308
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw4.exp
@@ -0,0 +1,70 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2022-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/>.
+
+# Generate binaries imitating different ways source file paths can be passed to
+# compilers. Test printing macros from those binaries.
+
+# The do_test proc comes from macro-source-path.exp.tcl.
+source $srcdir/$subdir/macro-source-path.exp.tcl
+
+# When adding a test here, please consider adding an equivalent case to
+# `gdb.base/macro-source-path.exp`.
+
+# The following tests are based on the output of `gcc -gdwarf-4 -g3 <file>`,
+# gcc 11 paired with gas from binutils 2.38. With -gdwarf-4, gcc generates a
+# v4 (pre-standard) .debug_macro section.
+
+## test.c
+do_test filename 4 "test.c" 1 {
+} {
+ {"test.c" 0}
+}
+
+## ./test.c
+do_test dot-filename 4 "./test.c" 1 {
+ "."
+} {
+ {"test.c" 1}
+}
+
+## ../cwd/test.c
+do_test dot-dot-cwd 4 "../cwd/test.c" 1 {
+ "../cwd"
+} {
+ {"test.c" 1}
+}
+
+## /tmp/cwd/test.c
+do_test absolute-cwd 4 "/tmp/cwd/test.c" 1 {
+ "/tmp/cwd"
+} {
+ {"test.c" 1}
+}
+
+## ../other/test.c
+do_test dot-dot-other 4 "../other/test.c" 1 {
+ "../other"
+} {
+ {"test.c" 1}
+}
+
+## /tmp/other/test.c
+do_test absolute-other 4 "/tmp/other/test.c" 1 {
+ "/tmp/other"
+} {
+ {"test.c" 1}
+}
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw5.exp b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw5.exp
new file mode 100644
index 0000000..98a278e
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path-gcc11-ld238-dw5.exp
@@ -0,0 +1,81 @@
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2022-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/>.
+
+# Generate binaries imitating different ways source file paths can be passed to
+# compilers. Test printing macros from those binaries.
+
+# The do_test proc comes from macro-source-path.exp.tcl.
+source $srcdir/$subdir/macro-source-path.exp.tcl
+
+# When adding a test here, please consider adding an equivalent case to
+# `gdb.base/macro-source-path.exp`.
+
+# The following tests are based on the output of `gcc -gdwarf-5 -g3 <file>`,
+# gcc 11 paired with gas from binutils 2.38.
+
+## test.c
+do_test filename 5 "test.c" 1 {
+ "/tmp/cwd"
+} {
+ {"test.c" 0}
+ {"test.c" 0}
+}
+
+## ./test.c
+do_test dot-filename 5 "./test.c" 1 {
+ "/tmp/cwd"
+ "."
+} {
+ {"test.c" 1}
+ {"test.c" 1}
+}
+
+## ../cwd/test.c
+do_test dot-dot-cwd 5 "../cwd/test.c" 1 {
+ "/tmp/cwd"
+ "../cwd"
+} {
+ {"test.c" 1}
+ {"test.c" 1}
+}
+
+## /tmp/cwd/test.c
+do_test absolute-cwd 5 "/tmp/cwd/test.c" 1 {
+ "/tmp/cwd"
+ "/tmp/cwd"
+} {
+ {"test.c" 1}
+ {"test.c" 0}
+}
+
+## ../other/test.c
+do_test dot-dot-other 5 "../other/test.c" 1 {
+ "/tmp/cwd"
+ "../other"
+} {
+ {"test.c" 1}
+ {"test.c" 1}
+}
+
+## /tmp/other/test.c
+do_test absolute-other 5 "/tmp/other/test.c" 1 {
+ "/tmp/cwd"
+ "/tmp/other"
+} {
+ {"test.c" 1}
+ {"test.c" 1}
+}
diff --git a/gdb/testsuite/gdb.dwarf2/macro-source-path.exp b/gdb/testsuite/gdb.dwarf2/macro-source-path.exp.tcl
index 1318f8e..ecaf685 100644
--- a/gdb/testsuite/gdb.dwarf2/macro-source-path.exp
+++ b/gdb/testsuite/gdb.dwarf2/macro-source-path.exp.tcl
@@ -17,12 +17,15 @@
# Generate binaries imitating different ways source file paths can be passed to
# compilers. Test printing macros from those binaries.
+#
+# The entry points for this test are in the various
+# gdb.dwarf2/macro-source-path-*.exp files.
load_lib dwarf.exp
require dwarf2_support
-standard_testfile .c
+standard_testfile macro-source-path.c
lassign [function_range main $srcdir/$subdir/$srcfile] \
main_start main_len
@@ -160,248 +163,3 @@ proc do_test { test_name lines_version DW_AT_name main_file_idx directories
}
}
}
-
-# When adding a test here, please consider adding an equivalent case to the test
-# of the same name in gdb.base.
-
-# The following tests are based on the output of `gcc -gdwarf-5 -g3 <file>`,
-# gcc 11 paired with gas from binutils 2.38.
-
-## test.c
-do_test gcc11-ld238-dw5-filename 5 "test.c" 1 {
- "/tmp/cwd"
-} {
- {"test.c" 0}
- {"test.c" 0}
-}
-
-## ./test.c
-do_test gcc11-ld238-dw5-dot-filename 5 "./test.c" 1 {
- "/tmp/cwd"
- "."
-} {
- {"test.c" 1}
- {"test.c" 1}
-}
-
-## ../cwd/test.c
-do_test gcc11-ld238-dw5-dot-dot-cwd 5 "../cwd/test.c" 1 {
- "/tmp/cwd"
- "../cwd"
-} {
- {"test.c" 1}
- {"test.c" 1}
-}
-
-## /tmp/cwd/test.c
-do_test gcc11-ld238-dw5-absolute-cwd 5 "/tmp/cwd/test.c" 1 {
- "/tmp/cwd"
- "/tmp/cwd"
-} {
- {"test.c" 1}
- {"test.c" 0}
-}
-
-## ../other/test.c
-do_test gcc11-ld238-dw5-dot-dot-other 5 "../other/test.c" 1 {
- "/tmp/cwd"
- "../other"
-} {
- {"test.c" 1}
- {"test.c" 1}
-}
-
-## /tmp/other/test.c
-do_test gcc11-ld238-dw5-absolute-other 5 "/tmp/other/test.c" 1 {
- "/tmp/cwd"
- "/tmp/other"
-} {
- {"test.c" 1}
- {"test.c" 1}
-}
-
-# The following tests are based on the output of `gcc -gdwarf-4 -g3 <file>`,
-# gcc 11 paired with gas from binutils 2.38. With -gdwarf-4, gcc generates a
-# v4 (pre-standard) .debug_macro section.
-
-## test.c
-do_test gcc11-ld238-dw4-filename 4 "test.c" 1 {
-} {
- {"test.c" 0}
-}
-
-## ./test.c
-do_test gcc11-ld238-dw4-dot-filename 4 "./test.c" 1 {
- "."
-} {
- {"test.c" 1}
-}
-
-## ../cwd/test.c
-do_test gcc11-ld238-dw4-dot-dot-cwd 4 "../cwd/test.c" 1 {
- "../cwd"
-} {
- {"test.c" 1}
-}
-
-## /tmp/cwd/test.c
-do_test gcc11-ld238-dw4-absolute-cwd 4 "/tmp/cwd/test.c" 1 {
- "/tmp/cwd"
-} {
- {"test.c" 1}
-}
-
-## ../other/test.c
-do_test gcc11-ld238-dw4-dot-dot-other 4 "../other/test.c" 1 {
- "../other"
-} {
- {"test.c" 1}
-}
-
-## /tmp/other/test.c
-do_test gcc11-ld238-dw4-absolute-other 4 "/tmp/other/test.c" 1 {
- "/tmp/other"
-} {
- {"test.c" 1}
-}
-
-# The following tests are based on the output of `clang-14 -gdwarf-5
-# -fdebug-macro -g3 <file>` (using its built-in assembler)
-
-## test.c
-do_test clang14-dw5-filename 5 "test.c" 0 {
- "/tmp/cwd"
-} {
- {"test.c" 0}
-}
-
-## ./test.c
-do_test clang14-dw5-dot-filename 5 "test.c" 1 {
- "/tmp/cwd"
- "."
-} {
- {"test.c" 0}
- {"test.c" 1}
-}
-
-## ../cwd/test.c
-do_test clang14-dw5-dot-dot-cwd 5 "../cwd/test.c" 0 {
- "/tmp/cwd"
-} {
- {"../cwd/test.c" 0}
-}
-
-## /tmp/cwd/test.c
-do_test clang14-dw5-absolute-cwd 5 "/tmp/cwd/test.c" 1 {
- "/tmp/cwd"
-} {
- {"/tmp/cwd/test.c" 0}
- {"test.c" 0}
-}
-
-## ../other/test.c
-do_test clang14-dw5-dot-dot-other 5 "../other/test.c" 0 {
- "/tmp/cwd"
-} {
- {"../other/test.c" 0}
-}
-
-## /tmp/other/test.c
-do_test clang14-dw5-absolute-other 5 "/tmp/other/test.c" 1 {
- "/tmp/cwd"
- "/tmp"
-} {
- {"/tmp/other/test.c" 0}
- {"other/test.c" 1}
-}
-
-# The following tests are based on the output of `clang-14 -gdwarf-4
-# -fdebug-macro -g3 <file>` (using its built-in assembler). With -gdwarf-4,
-# clang produces a .debug_macinfo section, not a .debug_macro section. But
-# this test still creates a .debug_macro section, that's good enough for what
-# we want to test.
-
-## test.c
-do_test clang14-dw4-filename 4 "test.c" 1 {
-} {
- {"test.c" 0}
-}
-
-## ./test.c
-do_test clang14-dw4-dot-filename 4 "test.c" 1 {
- "."
-} {
- {"test.c" 1}
-}
-
-## ../cwd/test.c
-do_test clang14-dw4-dot-dot-cwd 4 "../cwd/test.c" 1 {
- "../cwd"
-} {
- {"test.c" 1}
-}
-
-## /tmp/cwd/test.c
-do_test clang14-dw4-absolute-cwd 4 "/tmp/cwd/test.c" 1 {
-} {
- {"test.c" 0}
-}
-
-## ../other/test.c
-do_test clang14-dw4-dot-dot-other 4 "../other/test.c" 1 {
- "../other"
-} {
- {"test.c" 1}
-}
-
-## /tmp/other/test.c
-do_test clang14-dw4-absolute-other 4 "/tmp/other/test.c" 1 {
- "/tmp"
-} {
- {"other/test.c" 1}
-}
-
-# The following tests are based on the output of `gcc -gdwarf-5 -g3 <file>`,
-# gcc 11 paired with gas from binutils 2.34 (Ubuntu 20.04). It generates a v5
-# .debug_macro section, but a v3 .debug_line section.
-
-## test.c
-do_test gcc11-ld234-dw5-filename 3 "test.c" 1 {
-} {
- {"test.c" 0}
-}
-
-## ./test.c
-do_test gcc11-ld234-dw5-dot-filename 3 "./test.c" 1 {
- "."
-} {
- {"test.c" 1}
-}
-
-## ../cwd/test.c
-do_test gcc11-ld234-dw5-dot-dot-cwd 3 "../cwd/test.c" 1 {
- "../cwd"
-} {
- {"test.c" 1}
-}
-
-## /tmp/cwd/test.c
-do_test gcc11-ld234-dw5-absolute-cwd 3 "/tmp/cwd/test.c" 1 {
- "/tmp/cwd"
-} {
- {"test.c" 1}
-}
-
-## ../other/test.c
-do_test gcc11-ld234-dw5-dot-dot-other 3 "../other/test.c" 1 {
- "../other"
-} {
- {"test.c" 1}
-}
-
-## /tmp/other/test.c
-do_test gcc11-ld234-dw5-absolute-other 3 "/tmp/other/test.c" 1 {
- "/tmp/other"
-} {
- {"test.c" 1}
-}
diff --git a/gdb/testsuite/gdb.dwarf2/no-gnu-debuglink.exp b/gdb/testsuite/gdb.dwarf2/no-gnu-debuglink.exp
index 7475d7a..05e625f 100644
--- a/gdb/testsuite/gdb.dwarf2/no-gnu-debuglink.exp
+++ b/gdb/testsuite/gdb.dwarf2/no-gnu-debuglink.exp
@@ -38,7 +38,7 @@ if { [build_executable $testfile.exp $testfile [list $srcfile $asm_file]] } {
clean_restart
gdb_test_no_output "maint set dwarf synchronous on"
-set msg "\r\nwarning: could not find '\.gnu_debugaltlink' file for \[^\r\n\]*"
+set msg "\r\nwarning: could not find supplementary DWARF file \[^\r\n\]*"
gdb_test "file $binfile" "$msg" "file command"
set question "Load new symbol table from .*\? .y or n. "
diff --git a/gdb/testsuite/gdb.python/gdb_leak_detector.py b/gdb/testsuite/gdb.python/gdb_leak_detector.py
new file mode 100644
index 0000000..8f74b67
--- /dev/null
+++ b/gdb/testsuite/gdb.python/gdb_leak_detector.py
@@ -0,0 +1,121 @@
+# Copyright (C) 2021-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/>.
+
+# Defines a base class, which can be sub-classed, in order to run
+# memory leak tests on some aspects of GDB's Python API. See the
+# comments on the gdb_leak_detector class for more details.
+
+import os
+import tracemalloc
+
+import gdb
+
+
+# This class must be sub-classed to create a memory leak test. The
+# sub-classes __init__ method should call the parent classes __init__
+# method, and the sub-class should override allocate() and
+# deallocate(). See the comments on the various methods below for
+# more details of required arguments and expected usage.
+class gdb_leak_detector:
+
+ # Class initialisation. FILENAME is the file in which the
+ # sub-class is defined, usually passed as just '__file__'. This
+ # is used when looking for memory allocations; only allocations in
+ # FILENAME are considered.
+ def __init__(self, filename):
+ self.filters = [tracemalloc.Filter(True, "*" + os.path.basename(filename))]
+
+ # Internal helper function to actually run the test. Calls the
+ # allocate() method to allocate an object from GDB's Python API.
+ # When CLEAR is True the object will then be deallocated by
+ # calling deallocate(), otherwise, deallocate() is not called.
+ #
+ # Finally, this function checks for any memory allocatios
+ # originating from 'self.filename' that have not been freed, and
+ # returns the total (in bytes) of the memory that has been
+ # allocated, but not freed.
+ def _do_test(self, clear):
+ # Start tracing, and take a snapshot of the current allocations.
+ tracemalloc.start()
+ snapshot1 = tracemalloc.take_snapshot()
+
+ # Generate the GDB Python API object by calling the allocate
+ # method.
+ self.allocate()
+
+ # Possibly clear the reference to the allocated object.
+ if clear:
+ self.deallocate()
+
+ # Now grab a second snapshot of memory allocations, and stop
+ # tracing memory allocations.
+ snapshot2 = tracemalloc.take_snapshot()
+ tracemalloc.stop()
+
+ # Filter the snapshots; we only care about allocations originating
+ # from this file.
+ snapshot1 = snapshot1.filter_traces(self.filters)
+ snapshot2 = snapshot2.filter_traces(self.filters)
+
+ # Compare the snapshots, this leaves only things that were
+ # allocated, but not deallocated since the first snapshot.
+ stats = snapshot2.compare_to(snapshot1, "traceback")
+
+ # Total up all the allocated things.
+ total = 0
+ for stat in stats:
+ total += stat.size_diff
+ return total
+
+ # Run the memory leak test. Prints 'PASS' if successful,
+ # otherwise, raises an exception (of type GdbError).
+ def run(self):
+ # The first time we run this some global state will be allocated which
+ # shows up as memory that is allocated, but not released. So, run the
+ # test once and discard the result.
+ self._do_test(True)
+
+ # Now run the test twice, the first time we clear our global reference
+ # to the allocated object, which should allow Python to deallocate the
+ # object. The second time we hold onto the global reference, preventing
+ # Python from performing the deallocation.
+ bytes_with_clear = self._do_test(True)
+ bytes_without_clear = self._do_test(False)
+
+ # If there are any allocations left over when we cleared the reference
+ # (and expected deallocation) then this indicates a leak.
+ if bytes_with_clear > 0:
+ raise gdb.GdbError("memory leak when object reference was released")
+
+ # If there are no allocations showing when we hold onto a reference,
+ # then this likely indicates that the testing infrastructure is broken,
+ # and we're no longer spotting the allocations at all.
+ if bytes_without_clear == 0:
+ raise gdb.GdbError("object is unexpectedly not showing as allocated")
+
+ # Print a PASS message that the TCL script can see.
+ print("PASS")
+
+ # Sub-classes must override this method. Allocate an object (or
+ # multiple objects) from GDB's Python API. Store references to
+ # these objects within SELF.
+ def allocate(self):
+ raise NotImplementedError("allocate() not implemented")
+
+ # Sub-classes must override this method. Deallocate the object(s)
+ # allocated by the allocate() method. All that is required is for
+ # the references created in allocate() to be set to None.
+ def deallocate(self):
+ raise NotImplementedError("allocate() not implemented")
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 1b9c05f..9a901a3 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -707,7 +707,7 @@ proc_with_prefix test_bkpt_explicit_loc {} {
delete_breakpoints
gdb_test "python bp1 = gdb.Breakpoint (line=bp1)" \
- "RuntimeError.*: Line keyword should be an integer or a string.*" \
+ "RuntimeError.*: Line keyword should be an integer or a string\\.\r\n.*" \
"set explicit breakpoint by invalid line type"
delete_breakpoints
diff --git a/gdb/testsuite/gdb.python/py-color-leak.exp b/gdb/testsuite/gdb.python/py-color-leak.exp
new file mode 100644
index 0000000..6d7fa7c
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-color-leak.exp
@@ -0,0 +1,28 @@
+# Copyright (C) 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/>.
+
+# This file is part of the GDB testsuite. It checks for memory leaks
+# associated with allocating gdb.Color objects.
+
+load_lib gdb-python.exp
+
+require allow_python_tests
+
+standard_testfile
+
+clean_restart
+
+gdb_py_run_memory_leak_test ${srcdir}/${subdir}/${testfile}.py \
+ "gdb.Color object deallocates correctly"
diff --git a/gdb/testsuite/gdb.python/py-color-leak.py b/gdb/testsuite/gdb.python/py-color-leak.py
new file mode 100644
index 0000000..50dc315
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-color-leak.py
@@ -0,0 +1,31 @@
+# Copyright (C) 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/>.
+
+import gdb_leak_detector
+
+
+class color_leak_detector(gdb_leak_detector.gdb_leak_detector):
+ def __init__(self):
+ super().__init__(__file__)
+ self.color = None
+
+ def allocate(self):
+ self.color = gdb.Color("red")
+
+ def deallocate(self):
+ self.color = None
+
+
+color_leak_detector().run()
diff --git a/gdb/testsuite/gdb.python/py-color.exp b/gdb/testsuite/gdb.python/py-color.exp
index c6f1041..3563d22 100644
--- a/gdb/testsuite/gdb.python/py-color.exp
+++ b/gdb/testsuite/gdb.python/py-color.exp
@@ -13,8 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# This file is part of the GDB testsuite.
-# It tests gdb.parameter and gdb.Parameter.
+# This file is part of the GDB testsuite. It tests gdb.Color.
load_lib gdb-python.exp
@@ -23,7 +22,10 @@ require allow_python_tests
# Start with a fresh gdb.
clean_restart
-gdb_test_no_output "python print_color_attrs = lambda c: print (c, c.colorspace, c.is_none, c.is_indexed, c.is_direct)" \
+gdb_test_no_output "python get_color_attrs = lambda c: \"%s %s %s %s %s\" % (str(c), c.colorspace, c.is_none, c.is_indexed, c.is_direct)" \
+ "get_color_attrs helper"
+
+gdb_test_no_output "python print_color_attrs = lambda c: print (get_color_attrs (c))" \
"print_color_attrs helper"
gdb_test_no_output "python c = gdb.Color ()" \
@@ -59,6 +61,15 @@ gdb_test "python print_color_attrs (c)" "green 1 False True False" \
gdb_test "python print (c.index)" "2" \
"print index of a basic color with ansi colorspace"
+# Create a color using keyword arguments, and check it matches the
+# non-keyword color.
+gdb_test_no_output "python c2 = gdb.Color (color_space = gdb.COLORSPACE_ANSI_8COLOR, value = 2)" \
+ "create color from basic index and ansi colorspace using keywords"
+gdb_test "python print(get_color_attrs (c) == get_color_attrs (c2))" "True" \
+ "check attributes match"
+gdb_test "python print(c.index == c2.index)" "True" \
+ "check index matches"
+
gdb_test_no_output "python c = gdb.Color (2, gdb.COLORSPACE_XTERM_256COLOR)" \
"create color from basic index and xterm256 colorspace"
gdb_test "python print_color_attrs (c)" "2 3 False True False" \
@@ -97,4 +108,48 @@ gdb_test [concat "python print (c_red.escape_sequence (True) + " \
"c_none.escape_sequence (True))"] \
"\033\\\[31m\033\\\[42mred on green\033\\\[49m red on default\033\\\[39m" \
"escape sequences"
-
+gdb_test [concat "python print (c_red.escape_sequence (is_foreground = True) + " \
+ "c_green.escape_sequence (is_foreground = False) + 'red on green' + " \
+ "c_none.escape_sequence (is_foreground = False) + ' red on default' + " \
+ "c_none.escape_sequence (is_foreground = True))"] \
+ "\033\\\[31m\033\\\[42mred on green\033\\\[49m red on default\033\\\[39m" \
+ "escape sequences using keyword arguments"
+
+gdb_test_multiline "Try to sub-class gdb.Color" \
+ "python" "" \
+ "class my_color(gdb.Color):" "" \
+ " def __init__(self):" "" \
+ " super().__init__('red')" "" \
+ "end" \
+ [multi_line \
+ "Python Exception <class 'TypeError'>: type 'gdb\\.Color' is not an acceptable base type" \
+ "Error occurred in Python: type 'gdb\\.Color' is not an acceptable base type"]
+
+gdb_test_multiline "Setup a color parameter and non gdb.Color object" \
+ "python" "" \
+ "class my_param(gdb.Parameter):" "" \
+ " def __init__(self):" "" \
+ " super().__init__('color-param', gdb.COMMAND_NONE, gdb.PARAM_COLOR)" "" \
+ " self.value = gdb.Color('red')" "" \
+ "color_param = my_param()" "" \
+ " " "" \
+ "class bad_type:" "" \
+ " @property" "" \
+ " def __class__(self):" "" \
+ " raise RuntimeError('__class__ error for bad_type')" "" \
+ "bad_obj = bad_type()" "" \
+ "end" ""
+
+gdb_test_no_output "python color_param.value = gdb.Color('blue')" \
+ "set color parameter to blue"
+
+gdb_test "python color_param.value = bad_obj" \
+ [multi_line \
+ "Python Exception <class 'RuntimeError'>: color argument must be a gdb\\.Color object\\." \
+ "Error occurred in Python: color argument must be a gdb\\.Color object\\."] \
+ "set color parameter to a non-color type"
+
+gdb_test "python c_none.escape_sequence(c_red)" \
+ [multi_line \
+ "Python Exception <class 'TypeError'>: argument 1 must be bool, not gdb.Color" \
+ "Error occurred in Python: argument 1 must be bool, not gdb.Color"]
diff --git a/gdb/testsuite/gdb.python/py-disasm.exp.tcl b/gdb/testsuite/gdb.python/py-disasm.exp.tcl
index 938326d..c5099ba 100644
--- a/gdb/testsuite/gdb.python/py-disasm.exp.tcl
+++ b/gdb/testsuite/gdb.python/py-disasm.exp.tcl
@@ -152,7 +152,10 @@ set test_plans \
"Buffer returned from read_memory is sized $decimal instead of the expected $decimal"]] \
[list "ResultOfWrongType" \
[make_exception_pattern "TypeError" \
- "Result is not a DisassemblerResult."]] \
+ "Result from Disassembler must be gdb.DisassemblerResult, not Blah."]] \
+ [list "ResultOfVeryWrongType" \
+ [make_exception_pattern "TypeError" \
+ "Result from Disassembler must be gdb.DisassemblerResult, not Blah."]] \
[list "ErrorCreatingTextPart_NoArgs" \
[make_exception_pattern "TypeError" \
[missing_arg_pattern "style" 1]]] \
diff --git a/gdb/testsuite/gdb.python/py-disasm.py b/gdb/testsuite/gdb.python/py-disasm.py
index 32d6aa7..9761337 100644
--- a/gdb/testsuite/gdb.python/py-disasm.py
+++ b/gdb/testsuite/gdb.python/py-disasm.py
@@ -294,6 +294,24 @@ class ResultOfWrongType(TestDisassembler):
return self.Blah(1, "ABC")
+class ResultOfVeryWrongType(TestDisassembler):
+ """Return something that is not a DisassemblerResult from disassemble
+ method. The thing returned will raise an exception if used in an
+ isinstance() call, or in PyObject_IsInstance from C++.
+ """
+
+ class Blah:
+ def __init__(self):
+ pass
+
+ @property
+ def __class__(self):
+ raise RuntimeError("error from __class__ in Blah")
+
+ def disassemble(self, info):
+ return self.Blah()
+
+
class TaggingDisassembler(TestDisassembler):
"""A simple disassembler that just tags the output."""
diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp
index 5668807..c1e3e33 100644
--- a/gdb/testsuite/gdb.python/py-frame.exp
+++ b/gdb/testsuite/gdb.python/py-frame.exp
@@ -188,6 +188,21 @@ gdb_test "python print(gdb.selected_frame().read_register(list()))" \
".*Invalid type for register.*" \
"test Frame.read_register with list"
+gdb_test_multiline "setup a bad object" \
+ "python" "" \
+ "class bad_type:" "" \
+ " def __init__ (self):" "" \
+ " pass" "" \
+ " @property" "" \
+ " def __class__(self):" "" \
+ " raise RuntimeError('error from __class in bad_type')" "" \
+ "bad_object = bad_type()" "" \
+ "end" ""
+
+gdb_test "python print(gdb.selected_frame().read_register(bad_object))" \
+ ".*Invalid type for register.*" \
+ "test Frame.read_register with bad_type object"
+
# Compile again without debug info.
gdb_exit
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {}] } {
diff --git a/gdb/testsuite/gdb.python/py-inferior-leak.exp b/gdb/testsuite/gdb.python/py-inferior-leak.exp
index 6710f59..15216ee 100644
--- a/gdb/testsuite/gdb.python/py-inferior-leak.exp
+++ b/gdb/testsuite/gdb.python/py-inferior-leak.exp
@@ -24,15 +24,5 @@ standard_testfile
clean_restart
-# Skip this test if the tracemalloc module is not available.
-if { ![gdb_py_module_available "tracemalloc"] } {
- unsupported "tracemalloc module not available"
- return
-}
-
-set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
-
-# Source the Python script, this runs the test (which is written
-# completely in Python), and either prints PASS, or throws an
-# exception.
-gdb_test "source ${pyfile}" "PASS" "source python script"
+gdb_py_run_memory_leak_test ${srcdir}/${subdir}/${testfile}.py \
+ "gdb.Inferior object deallocates correctly"
diff --git a/gdb/testsuite/gdb.python/py-inferior-leak.py b/gdb/testsuite/gdb.python/py-inferior-leak.py
index 97837dc..f764688 100644
--- a/gdb/testsuite/gdb.python/py-inferior-leak.py
+++ b/gdb/testsuite/gdb.python/py-inferior-leak.py
@@ -14,99 +14,32 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import re
-import tracemalloc
-import gdb
+import gdb_leak_detector
-# A global variable in which we store a reference to the gdb.Inferior
-# object sent to us in the new_inferior event.
-inf = None
+class inferior_leak_detector(gdb_leak_detector.gdb_leak_detector):
+ def __init__(self):
+ super().__init__(__file__)
+ self.inferior = None
+ self.__handler = lambda event: setattr(self, "inferior", event.inferior)
+ gdb.events.new_inferior.connect(self.__handler)
-# Register the new_inferior event handler.
-def new_inferior_handler(event):
- global inf
- inf = event.inferior
+ def __del__(self):
+ gdb.events.new_inferior.disconnect(self.__handler)
+ def allocate(self):
+ output = gdb.execute("add-inferior", False, True)
+ m = re.search(r"Added inferior (\d+)", output)
+ if m:
+ num = int(m.group(1))
+ else:
+ raise RuntimeError("no match")
-gdb.events.new_inferior.connect(new_inferior_handler)
+ gdb.execute("remove-inferiors %s" % num)
-# A global filters list, we only care about memory allocations
-# originating from this script.
-filters = [tracemalloc.Filter(True, "*py-inferior-leak.py")]
+ def deallocate(self):
+ self.inferior = None
-# Add a new inferior, and return the number of the new inferior.
-def add_inferior():
- output = gdb.execute("add-inferior", False, True)
- m = re.search(r"Added inferior (\d+)", output)
- if m:
- num = int(m.group(1))
- else:
- raise RuntimeError("no match")
- return num
-
-
-# Run the test. When CLEAR is True we clear the global INF variable
-# before comparing the before and after memory allocation traces.
-# When CLEAR is False we leave INF set to reference the gdb.Inferior
-# object, thus preventing the gdb.Inferior from being deallocated.
-def test(clear):
- global filters, inf
-
- # Start tracing, and take a snapshot of the current allocations.
- tracemalloc.start()
- snapshot1 = tracemalloc.take_snapshot()
-
- # Create an inferior, this triggers the new_inferior event, which
- # in turn holds a reference to the new gdb.Inferior object in the
- # global INF variable.
- num = add_inferior()
- gdb.execute("remove-inferiors %s" % num)
-
- # Possibly clear the global INF variable.
- if clear:
- inf = None
-
- # Now grab a second snapshot of memory allocations, and stop
- # tracing memory allocations.
- snapshot2 = tracemalloc.take_snapshot()
- tracemalloc.stop()
-
- # Filter the snapshots; we only care about allocations originating
- # from this file.
- snapshot1 = snapshot1.filter_traces(filters)
- snapshot2 = snapshot2.filter_traces(filters)
-
- # Compare the snapshots, this leaves only things that were
- # allocated, but not deallocated since the first snapshot.
- stats = snapshot2.compare_to(snapshot1, "traceback")
-
- # Total up all the deallocated things.
- total = 0
- for stat in stats:
- total += stat.size_diff
- return total
-
-
-# The first time we run this some global state will be allocated which
-# shows up as memory that is allocated, but not released. So, run the
-# test once and discard the result.
-test(True)
-
-# Now run the test twice, the first time we clear our global reference
-# to the gdb.Inferior object, which should allow Python to deallocate
-# the object. The second time we hold onto the global reference,
-# preventing Python from performing the deallocation.
-bytes_with_clear = test(True)
-bytes_without_clear = test(False)
-
-# The bug that used to exist in GDB was that even when we released the
-# global reference the gdb.Inferior object would not be deallocated.
-if bytes_with_clear > 0:
- raise gdb.GdbError("memory leak when gdb.Inferior should be released")
-if bytes_without_clear == 0:
- raise gdb.GdbError("gdb.Inferior object is no longer allocated")
-
-# Print a PASS message that the test script can see.
-print("PASS")
+inferior_leak_detector().run()
diff --git a/gdb/testsuite/gdb.python/py-read-memory-leak.exp b/gdb/testsuite/gdb.python/py-read-memory-leak.exp
index 0015a57..9ae5eb8 100644
--- a/gdb/testsuite/gdb.python/py-read-memory-leak.exp
+++ b/gdb/testsuite/gdb.python/py-read-memory-leak.exp
@@ -30,15 +30,5 @@ if ![runto_main] {
return -1
}
-# Skip this test if the tracemalloc module is not available.
-if { ![gdb_py_module_available "tracemalloc"] } {
- unsupported "tracemalloc module not available"
- return
-}
-
-set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
-
-# Source the Python script, this runs the test (which is written
-# completely in Python), and either prints PASS, or throws an
-# exception.
-gdb_test "source ${pyfile}" "PASS" "source python script"
+gdb_py_run_memory_leak_test ${srcdir}/${subdir}/${testfile}.py \
+ "buffers returned by read_memory() deallocates correctly"
diff --git a/gdb/testsuite/gdb.python/py-read-memory-leak.py b/gdb/testsuite/gdb.python/py-read-memory-leak.py
index 348403d..71edf47 100644
--- a/gdb/testsuite/gdb.python/py-read-memory-leak.py
+++ b/gdb/testsuite/gdb.python/py-read-memory-leak.py
@@ -13,81 +13,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import os
-import tracemalloc
+import gdb_leak_detector
-import gdb
-# A global variable in which we store a reference to the memory buffer
-# returned from gdb.Inferior.read_memory().
-mem_buf = None
+class read_leak_detector(gdb_leak_detector.gdb_leak_detector):
+ def __init__(self):
+ super().__init__(__file__)
+ self.mem_buf = None
+ self.addr = gdb.parse_and_eval("px")
+ self.inf = gdb.inferiors()[0]
+ def allocate(self):
+ self.mem_buf = self.inf.read_memory(self.addr, 4096)
-# A global filters list, we only care about memory allocations
-# originating from this script.
-filters = [tracemalloc.Filter(True, "*" + os.path.basename(__file__))]
+ def deallocate(self):
+ self.mem_buf = None
-# Run the test. When CLEAR is True we clear the global INF variable
-# before comparing the before and after memory allocation traces.
-# When CLEAR is False we leave INF set to reference the gdb.Inferior
-# object, thus preventing the gdb.Inferior from being deallocated.
-def test(clear):
- global filters, mem_buf
-
- addr = gdb.parse_and_eval("px")
- inf = gdb.inferiors()[0]
-
- # Start tracing, and take a snapshot of the current allocations.
- tracemalloc.start()
- snapshot1 = tracemalloc.take_snapshot()
-
- # Read from the inferior, this allocate a memory buffer object.
- mem_buf = inf.read_memory(addr, 4096)
-
- # Possibly clear the global INF variable.
- if clear:
- mem_buf = None
-
- # Now grab a second snapshot of memory allocations, and stop
- # tracing memory allocations.
- snapshot2 = tracemalloc.take_snapshot()
- tracemalloc.stop()
-
- # Filter the snapshots; we only care about allocations originating
- # from this file.
- snapshot1 = snapshot1.filter_traces(filters)
- snapshot2 = snapshot2.filter_traces(filters)
-
- # Compare the snapshots, this leaves only things that were
- # allocated, but not deallocated since the first snapshot.
- stats = snapshot2.compare_to(snapshot1, "traceback")
-
- # Total up all the allocated things.
- total = 0
- for stat in stats:
- total += stat.size_diff
- return total
-
-
-# The first time we run this some global state will be allocated which
-# shows up as memory that is allocated, but not released. So, run the
-# test once and discard the result.
-test(True)
-
-# Now run the test twice, the first time we clear our global reference
-# to the memory buffer object, which should allow Python to deallocate
-# the object. The second time we hold onto the global reference,
-# preventing Python from performing the deallocation.
-bytes_with_clear = test(True)
-bytes_without_clear = test(False)
-
-# The bug that used to exist in GDB was that even when we released the
-# global reference the gdb.Inferior object would not be deallocated.
-if bytes_with_clear > 0:
- raise gdb.GdbError("memory leak when memory buffer should be released")
-if bytes_without_clear == 0:
- raise gdb.GdbError("memory buffer object is no longer allocated")
-
-# Print a PASS message that the test script can see.
-print("PASS")
+read_leak_detector().run()
diff --git a/gdb/testsuite/gdb.python/py-unwind.exp b/gdb/testsuite/gdb.python/py-unwind.exp
index 80eac28..b416c2f 100644
--- a/gdb/testsuite/gdb.python/py-unwind.exp
+++ b/gdb/testsuite/gdb.python/py-unwind.exp
@@ -245,6 +245,13 @@ with_test_prefix "frame-id 'pc' is invalid" {
"Python Exception <class 'ValueError'>: invalid literal for int\\(\\) with base 10: 'xyz'\r\n.*"
}
+with_test_prefix "bad object unwinder" {
+ gdb_test_no_output "python obj = bad_object_unwinder(\"bad-object\")"
+ gdb_test_no_output "python gdb.unwinder.register_unwinder(None, obj, replace=True)"
+ gdb_test "backtrace" \
+ "Python Exception <class 'gdb.error'>: an Unwinder should return gdb.UnwindInfo, not Blah\\.\r\n.*"
+}
+
# Gather information about every frame.
gdb_test_no_output "python capture_all_frame_information()"
gdb_test_no_output "python gdb.newest_frame().select()"
diff --git a/gdb/testsuite/gdb.python/py-unwind.py b/gdb/testsuite/gdb.python/py-unwind.py
index 8e65a1a..0faccf2 100644
--- a/gdb/testsuite/gdb.python/py-unwind.py
+++ b/gdb/testsuite/gdb.python/py-unwind.py
@@ -267,4 +267,24 @@ class validating_unwinder(Unwinder):
return None
+class bad_object_unwinder(Unwinder):
+ def __init__(self, name):
+ super().__init__(name)
+
+ def __call__(self, pending_frame):
+
+ if pending_frame.level() != 1:
+ return None
+
+ class Blah:
+ def __init__(self):
+ pass
+
+ @property
+ def __class__(self):
+ raise RuntimeError("error in Blah.__class__")
+
+ return Blah()
+
+
print("Python script imported")
diff --git a/gdb/testsuite/gdb.server/no-thread-db.exp b/gdb/testsuite/gdb.server/no-thread-db.exp
index cc24708..9fd2090 100644
--- a/gdb/testsuite/gdb.server/no-thread-db.exp
+++ b/gdb/testsuite/gdb.server/no-thread-db.exp
@@ -57,6 +57,8 @@ gdb_breakpoint ${srcfile}:[gdb_get_line_number "after tls assignment"]
gdb_continue_to_breakpoint "after tls assignment"
# Printing a tls variable should fail gracefully without a libthread_db.
+# Alternately, the correct answer might be printed due GDB's internal
+# TLS support for some targets.
set re_exec "\[^\r\n\]*[file tail $binfile]"
gdb_test "print foo" \
- "Cannot find thread-local storage for Thread \[^,\]+, executable file $re_exec:\[\r\n\]+Remote target failed to process qGetTLSAddr request"
+ "= 1|(?:Cannot find thread-local storage for Thread \[^,\]+, executable file $re_exec:\[\r\n\]+Remote target failed to process qGetTLSAddr request)"
diff --git a/gdb/testsuite/gdb.threads/clone-attach-detach.exp b/gdb/testsuite/gdb.threads/clone-attach-detach.exp
index 0ae4281..3da2c3e 100644
--- a/gdb/testsuite/gdb.threads/clone-attach-detach.exp
+++ b/gdb/testsuite/gdb.threads/clone-attach-detach.exp
@@ -74,7 +74,7 @@ set attempts 3
for {set attempt 1} {$attempt <= $attempts} {incr attempt} {
with_test_prefix "bg attach $attempt" {
- gdb_test "attach $testpid &" \
+ gdb_test -no-prompt-anchor "attach $testpid &" \
"Attaching to program.*process $testpid.*" \
"attach"
diff --git a/gdb/testsuite/gdb.threads/tls.exp b/gdb/testsuite/gdb.threads/tls.exp
index 1bc5df2..73fada7 100644
--- a/gdb/testsuite/gdb.threads/tls.exp
+++ b/gdb/testsuite/gdb.threads/tls.exp
@@ -159,7 +159,7 @@ gdb_test_multiple "print a_thread_local" "" {
-re -wrap "Cannot find thread-local variables on this target" {
kfail "gdb/25807" $gdb_test_name
}
- -re -wrap "Cannot read .a_thread_local. without registers" {
+ -re -wrap "Cannot (?:read|find address of TLS symbol) .a_thread_local. without registers" {
pass $gdb_test_name
}
}
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 46b39a1..7e8778a 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -3068,6 +3068,24 @@ namespace eval Dwarf {
}
}
+ # Emit a .debug_sup section with the given file name and build-id.
+ # The buildid should be represented as a hexadecimal string, like
+ # "ffeeddcc".
+ proc debug_sup {is_sup filename buildid} {
+ _defer_output .debug_sup {
+ # The version.
+ _op .2byte 0x5
+ # Supplementary marker.
+ _op .byte $is_sup
+ _op .ascii [_quote $filename]
+ set len [expr {[string length $buildid] / 2}]
+ _op .uleb128 $len
+ foreach {a b} [split $buildid {}] {
+ _op .byte 0x$a$b
+ }
+ }
+ }
+
proc _note {type name hexdata} {
set namelen [expr [string length $name] + 1]
set datalen [expr [string length $hexdata] / 2]
diff --git a/gdb/testsuite/lib/gdb-python.exp b/gdb/testsuite/lib/gdb-python.exp
index b4eb40d..e026c1b 100644
--- a/gdb/testsuite/lib/gdb-python.exp
+++ b/gdb/testsuite/lib/gdb-python.exp
@@ -77,3 +77,24 @@ proc gdb_py_module_available { name } {
return ${available}
}
+
+# Run a memory leak test within the Python script FILENAME. This proc
+# checks that the required Python modules are available, sets up the
+# syspath so that the helper module can be found (in the same
+# directory as FILENAME), then loads FILENAME to run the test.
+proc gdb_py_run_memory_leak_test { filename testname } {
+ if { ![gdb_py_module_available "tracemalloc"] } {
+ unsupported "$testname (tracemalloc module not available)"
+ }
+
+ gdb_test_no_output -nopass "python import sys"
+ gdb_test_no_output -nopass \
+ "python sys.path.insert(0, \"[file dirname $filename]\")" \
+ "setup sys.path"
+
+ set pyfile [gdb_remote_download host ${filename}]
+
+ # Source the Python script, this runs the test, and either prints
+ # PASS, or throws an exception.
+ gdb_test "source ${pyfile}" "^PASS" $testname
+}
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index c37cc89..ead14bd 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3758,7 +3758,8 @@ proc supports_reverse {} {
|| [istarget "aarch64*-*-linux*"]
|| [istarget "loongarch*-*-linux*"]
|| [istarget "powerpc*-*-linux*"]
- || [istarget "s390*-*-linux*"] } {
+ || [istarget "s390*-*-linux*"]
+ || [istarget "riscv*-*-*"] } {
return 1
}
diff --git a/gdb/ui-file.c b/gdb/ui-file.c
index 09e8b0b..f86b6b1 100644
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -88,18 +88,6 @@ ui_file::emit_style_escape (const ui_file_style &style)
/* See ui-file.h. */
void
-ui_file::reset_style ()
-{
- if (can_emit_style_escape ())
- {
- m_applied_style = ui_file_style ();
- this->puts (m_applied_style.to_ansi ().c_str ());
- }
-}
-
-/* See ui-file.h. */
-
-void
ui_file::printchar (int c, int quoter, bool async_safe)
{
char buf[4];
diff --git a/gdb/ui-file.h b/gdb/ui-file.h
index 351cf1f..3919e52 100644
--- a/gdb/ui-file.h
+++ b/gdb/ui-file.h
@@ -123,9 +123,6 @@ public:
/* Emit an ANSI style escape for STYLE. */
virtual void emit_style_escape (const ui_file_style &style);
- /* Rest the current output style to the empty style. */
- virtual void reset_style ();
-
/* Print STR, bypassing any paging that might be done by this
ui_file. Note that nearly no code should call this -- it's
intended for use by gdb_printf, but nothing else. */
@@ -353,12 +350,6 @@ public:
m_two->emit_style_escape (style);
}
- void reset_style () override
- {
- m_one->reset_style ();
- m_two->reset_style ();
- }
-
void puts_unfiltered (const char *str) override
{
m_one->puts_unfiltered (str);
@@ -389,10 +380,6 @@ public:
void emit_style_escape (const ui_file_style &style) override
{
}
-
- void reset_style () override
- {
- }
};
/* A base class for ui_file types that wrap another ui_file. */
@@ -419,10 +406,6 @@ public:
void emit_style_escape (const ui_file_style &style) override
{ m_stream->emit_style_escape (style); }
- /* Rest the current output style to the empty style. */
- void reset_style () override
- { m_stream->reset_style (); }
-
int fd () const override
{ return m_stream->fd (); }
diff --git a/gdb/ui-style.c b/gdb/ui-style.c
index b8321c5..b8d73ab 100644
--- a/gdb/ui-style.c
+++ b/gdb/ui-style.c
@@ -45,7 +45,8 @@ static const char ansi_regex_text[] =
/* The compiled form of ansi_regex_text. */
-static regex_t ansi_regex;
+static compiled_regex ansi_regex (ansi_regex_text, REG_EXTENDED,
+ _("Error in ANSI terminal escape sequences regex"));
/* This maps 8-color palette to RGB triples. The values come from
plain linux terminal. */
@@ -364,7 +365,7 @@ ui_file_style::parse (const char *buf, size_t *n_read)
{
regmatch_t subexps[NUM_SUBEXPRESSIONS];
- int match = regexec (&ansi_regex, buf, ARRAY_SIZE (subexps), subexps, 0);
+ int match = ansi_regex.exec (buf, ARRAY_SIZE (subexps), subexps, 0);
if (match == REG_NOMATCH)
{
*n_read = 0;
@@ -531,7 +532,7 @@ skip_ansi_escape (const char *buf, int *n_read)
{
regmatch_t subexps[NUM_SUBEXPRESSIONS];
- int match = regexec (&ansi_regex, buf, ARRAY_SIZE (subexps), subexps, 0);
+ int match = ansi_regex.exec (buf, ARRAY_SIZE (subexps), subexps, 0);
if (match == REG_NOMATCH || buf[subexps[FINAL_SUBEXP].rm_so] != 'm')
return false;
@@ -539,16 +540,6 @@ skip_ansi_escape (const char *buf, int *n_read)
return true;
}
-void _initialize_ui_style ();
-void
-_initialize_ui_style ()
-{
- int code = regcomp (&ansi_regex, ansi_regex_text, REG_EXTENDED);
- /* If the regular expression was incorrect, it was a programming
- error. */
- gdb_assert (code == 0);
-}
-
/* See ui-style.h. */
const std::vector<color_space> &
diff --git a/gdb/unittests/remote-arg-selftests.c b/gdb/unittests/remote-arg-selftests.c
new file mode 100644
index 0000000..70f8a39
--- /dev/null
+++ b/gdb/unittests/remote-arg-selftests.c
@@ -0,0 +1,166 @@
+/* Self tests for GDB's argument splitting and merging.
+
+ Copyright (C) 2023-2025 Free Software Foundation, Inc.
+
+ 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/>. */
+
+#include "defs.h"
+#include "gdbsupport/selftest.h"
+#include "gdbsupport/buildargv.h"
+#include "gdbsupport/common-inferior.h"
+#include "gdbsupport/remote-args.h"
+#include "gdbsupport/gdb_argv_vec.h"
+
+namespace selftests {
+namespace remote_args_tests {
+
+/* The data needed to perform a single remote argument test. */
+struct arg_test_desc
+{
+ /* The original inferior argument string. */
+ std::string input;
+
+ /* The individual arguments once they have been split. */
+ std::vector<std::string> split;
+
+ /* The new inferior argument string, created by joining SPLIT. */
+ std::string joined;
+};
+
+/* The list of tests. */
+arg_test_desc desc[] = {
+ { "abc", { "abc" }, "abc" },
+ { "a b c", { "a", "b", "c" }, "a b c" },
+ { "\"a b\" 'c d'", { "a b", "c d" }, "a\\ b c\\ d" },
+ { "\\' \\\"", { "'", "\"" }, "\\' \\\"" },
+ { "'\\'", { "\\" }, "\\\\" },
+ { "\"\\\\\" \"\\\\\\\"\"", { "\\", "\\\"" }, "\\\\ \\\\\\\"" },
+ { "\\ \" \" ' '", { " ", " ", " "}, "\\ \\ \\ " },
+ { "\"'\"", { "'" }, "\\'" },
+ { "'\"' '\\\"'", { "\"", "\\\"" } , "\\\" \\\\\\\""},
+ { "\"first arg\" \"\" \"third-arg\" \"'\" \"\\\"\" \"\\\\\\\"\" \" \" \"\"",
+ { "first arg", "", "third-arg", "'", "\"", "\\\""," ", "" },
+ "first\\ arg '' third-arg \\' \\\" \\\\\\\" \\ ''"},
+ { "\"\\a\" \"\\&\" \"\\#\" \"\\<\" \"\\^\"",
+ { "\\a", "\\&", "\\#" , "\\<" , "\\^"},
+ "\\\\a \\\\\\& \\\\\\# \\\\\\< \\\\\\^" },
+ { "1 '\n' 3", { "1", "\n", "3" }, "1 '\n' 3" },
+};
+
+/* Run the remote argument passing self tests. */
+
+static void
+self_test ()
+{
+ int failure_count = 0;
+ for (const auto &d : desc)
+ {
+ if (run_verbose ())
+ {
+ if (&d != &desc[0])
+ debug_printf ("------------------------------\n");
+ debug_printf ("Input (%s)\n", d.input.c_str ());
+ }
+
+ /* Split argument string into individual arguments. */
+ std::vector<std::string> split_args = gdb::remote_args::split (d.input);
+
+ if (run_verbose ())
+ {
+ debug_printf ("Split:\n");
+
+ size_t len = std::max (split_args.size (), d.split.size ());
+ for (size_t i = 0; i < len; ++i)
+ {
+ const char *got = "N/A";
+ const char *expected = got;
+
+ if (i < split_args.size ())
+ got = split_args[i].c_str ();
+
+ if (i < d.split.size ())
+ expected = d.split[i].c_str ();
+
+ debug_printf (" got (%s), expected (%s)\n", got, expected);
+ }
+ }
+
+ if (split_args != d.split)
+ {
+ ++failure_count;
+ if (run_verbose ())
+ debug_printf ("FAIL\n");
+ continue;
+ }
+
+ /* Now join the arguments. */
+ gdb::argv_vec split_args_c_str;
+ for (const std::string &s : split_args)
+ split_args_c_str.push_back (xstrdup (s.c_str ()));
+ std::string joined_args
+ = gdb::remote_args::join (split_args_c_str.get ());
+
+ if (run_verbose ())
+ debug_printf ("Joined (%s), expected (%s)\n",
+ joined_args.c_str (), d.joined.c_str ());
+
+ if (joined_args != d.joined)
+ {
+ ++failure_count;
+ if (run_verbose ())
+ debug_printf ("FAIL\n");
+ continue;
+ }
+
+ /* The contents of JOINED_ARGS will not be identical to D.INPUT.
+ There are multiple ways that an argument can be escaped, and our
+ join function just picks one. However, if we split JOINED_ARGS
+ again then each individual argument should be the same as those in
+ SPLIT_ARGS. So test that next. */
+ std::vector<std::string> split_args_v2
+ = gdb::remote_args::split (joined_args);
+
+ if (split_args_v2 != split_args)
+ {
+ ++failure_count;
+ if (run_verbose ())
+ {
+ debug_printf ("Re-split:\n");
+ for (const auto &a : split_args_v2)
+ debug_printf (" got (%s)\n", a.c_str ());
+ debug_printf ("FAIL\n");
+ }
+ continue;
+ }
+
+ if (run_verbose ())
+ debug_printf ("PASS\n");
+ }
+
+ SELF_CHECK (failure_count == 0);
+}
+
+} /* namespace remote_args_tests */
+} /* namespace selftests */
+
+void _initialize_remote_arg_selftests ();
+
+void
+_initialize_remote_arg_selftests ()
+{
+ selftests::register_test ("remote-args",
+ selftests::remote_args_tests::self_test);
+}
diff --git a/gdb/unittests/rsp-low-selftests.c b/gdb/unittests/rsp-low-selftests.c
index df849c9..7a1b2de 100644
--- a/gdb/unittests/rsp-low-selftests.c
+++ b/gdb/unittests/rsp-low-selftests.c
@@ -51,7 +51,7 @@ static void test_hex2str ()
{
SELF_CHECK (hex2str ("666f6f") == "foo");
SELF_CHECK (hex2str ("666f6fa") == "foo");
- SELF_CHECK (hex2str ("666f6f", 2) == "fo");
+ SELF_CHECK (hex2str ("666f6f", 2) == "fo"); /* codespell:ignore */
SELF_CHECK (hex2str ("666", 2) == "f");
SELF_CHECK (hex2str ("666", 6) == "f");
SELF_CHECK (hex2str ("") == "");
diff --git a/gdb/utils.c b/gdb/utils.c
index 986b906..ce3c26e 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1407,18 +1407,6 @@ pager_file::emit_style_escape (const ui_file_style &style)
}
}
-/* See pager.h. */
-
-void
-pager_file::reset_style ()
-{
- if (can_emit_style_escape ())
- {
- m_applied_style = ui_file_style ();
- m_wrap_buffer.append (m_applied_style.to_ansi ());
- }
-}
-
/* Wait, so the user can read what's on the screen. Prompt the user
to continue by pressing RETURN. 'q' is also provided because
telling users what to do in the prompt is more user-friendly than
diff --git a/gdb/valops.c b/gdb/valops.c
index 09af0ae..94f908d 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1695,6 +1695,9 @@ value_array (int lowbound, gdb::array_view<struct value *> elemvec)
/* Validate that the bounds are reasonable and that each of the
elements have the same size. */
+ if (elemvec.empty ())
+ error (_("size of the array element must not be zero"));
+
typelength = type_length_units (elemvec[0]->enclosing_type ());
for (struct value *other : elemvec.slice (1))
{
@@ -2417,47 +2420,42 @@ value_struct_elt (struct value **argp,
return v;
}
-/* Given *ARGP, a value of type structure or union, or a pointer/reference
+/* Given VAL, a value of type structure or union, or a pointer/reference
to a structure or union, extract and return its component (field) of
type FTYPE at the specified BITPOS.
Throw an exception on error. */
struct value *
-value_struct_elt_bitpos (struct value **argp, int bitpos, struct type *ftype,
- const char *err)
+value_struct_elt_bitpos (struct value *val, int bitpos, struct type *ftype)
{
struct type *t;
int i;
- *argp = coerce_array (*argp);
+ val = coerce_array (val);
- t = check_typedef ((*argp)->type ());
+ t = check_typedef (val->type ());
while (t->is_pointer_or_reference ())
{
- *argp = value_ind (*argp);
- if (check_typedef ((*argp)->type ())->code () != TYPE_CODE_FUNC)
- *argp = coerce_array (*argp);
- t = check_typedef ((*argp)->type ());
+ val = value_ind (val);
+ if (check_typedef (val->type ())->code () != TYPE_CODE_FUNC)
+ val = coerce_array (val);
+ t = check_typedef (val->type ());
}
if (t->code () != TYPE_CODE_STRUCT
&& t->code () != TYPE_CODE_UNION)
- error (_("Attempt to extract a component of a value that is not a %s."),
- err);
+ error (_("Attempt to extract a component of non-aggregate value."));
for (i = TYPE_N_BASECLASSES (t); i < t->num_fields (); i++)
{
if (!t->field (i).is_static ()
&& bitpos == t->field (i).loc_bitpos ()
&& types_equal (ftype, t->field (i).type ()))
- return (*argp)->primitive_field (0, i, t);
+ return val->primitive_field (0, i, t);
}
error (_("No field with matching bitpos and type."));
-
- /* Never hit. */
- return NULL;
}
/* Search through the methods of an object (and its bases) to find a
diff --git a/gdb/value.h b/gdb/value.h
index 0cbcfca..71d0ba1 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1297,10 +1297,9 @@ extern struct value *value_struct_elt (struct value **argp,
const char *name, int *static_memfuncp,
const char *err);
-extern struct value *value_struct_elt_bitpos (struct value **argp,
+extern struct value *value_struct_elt_bitpos (struct value *val,
int bitpos,
- struct type *field_type,
- const char *err);
+ struct type *field_type);
extern struct value *value_aggregate_elt (struct type *curtype,
const char *name,
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 0ce40ee..4b1f4b2 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -51,6 +51,7 @@
#include "gdbsupport/scoped_restore.h"
#include "gdbsupport/search.h"
#include "gdbsupport/gdb_argv_vec.h"
+#include "gdbsupport/remote-args.h"
/* PBUFSIZ must also be at least as big as IPA_CMD_BUF_SIZE, because
the client state data is passed directly to some agent
@@ -3465,7 +3466,7 @@ handle_v_run (char *own_buf)
else
program_path.set (new_program_name.get ());
- program_args = construct_inferior_arguments (new_argv.get (), true);
+ program_args = gdb::remote_args::join (new_argv.get ());
try
{
diff --git a/gdbsupport/Makefile.am b/gdbsupport/Makefile.am
index 79aef95..20122e4 100644
--- a/gdbsupport/Makefile.am
+++ b/gdbsupport/Makefile.am
@@ -80,6 +80,7 @@ libgdbsupport_a_SOURCES = \
pathstuff.cc \
print-utils.cc \
ptid.cc \
+ remote-args.cc \
rsp-low.cc \
run-time-clock.cc \
safe-strerror.cc \
diff --git a/gdbsupport/Makefile.in b/gdbsupport/Makefile.in
index c2feacc..66b8891 100644
--- a/gdbsupport/Makefile.in
+++ b/gdbsupport/Makefile.in
@@ -163,12 +163,12 @@ am_libgdbsupport_a_OBJECTS = agent.$(OBJEXT) btrace-common.$(OBJEXT) \
gdb_tilde_expand.$(OBJEXT) gdb_wait.$(OBJEXT) \
gdb_vecs.$(OBJEXT) job-control.$(OBJEXT) netstuff.$(OBJEXT) \
new-op.$(OBJEXT) osabi.$(OBJEXT) pathstuff.$(OBJEXT) \
- print-utils.$(OBJEXT) ptid.$(OBJEXT) rsp-low.$(OBJEXT) \
- run-time-clock.$(OBJEXT) safe-strerror.$(OBJEXT) \
- scoped_mmap.$(OBJEXT) search.$(OBJEXT) signals.$(OBJEXT) \
- signals-state-save-restore.$(OBJEXT) task-group.$(OBJEXT) \
- tdesc.$(OBJEXT) thread-pool.$(OBJEXT) xml-utils.$(OBJEXT) \
- $(am__objects_1) $(am__objects_2)
+ print-utils.$(OBJEXT) ptid.$(OBJEXT) remote-args.$(OBJEXT) \
+ rsp-low.$(OBJEXT) run-time-clock.$(OBJEXT) \
+ safe-strerror.$(OBJEXT) scoped_mmap.$(OBJEXT) search.$(OBJEXT) \
+ signals.$(OBJEXT) signals-state-save-restore.$(OBJEXT) \
+ task-group.$(OBJEXT) tdesc.$(OBJEXT) thread-pool.$(OBJEXT) \
+ xml-utils.$(OBJEXT) $(am__objects_1) $(am__objects_2)
libgdbsupport_a_OBJECTS = $(am_libgdbsupport_a_OBJECTS)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -438,6 +438,7 @@ libgdbsupport_a_SOURCES = \
pathstuff.cc \
print-utils.cc \
ptid.cc \
+ remote-args.cc \
rsp-low.cc \
run-time-clock.cc \
safe-strerror.cc \
@@ -548,6 +549,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pathstuff.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/print-utils.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptid.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/remote-args.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rsp-low.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/run-time-clock.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/safe-strerror.Po@am__quote@
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
index a168458..10bf9f4 100644
--- a/gdbsupport/common-utils.h
+++ b/gdbsupport/common-utils.h
@@ -196,6 +196,16 @@ in_inclusive_range (T value, T low, T high)
extern ULONGEST align_up (ULONGEST v, int n);
extern ULONGEST align_down (ULONGEST v, int n);
+/* Sign-extend the value V, using N as the number of valid bits. That
+ is, bit N-1 is the sign bit. The higher-order bits (those outside
+ 0..N-1) must be zero. */
+static inline ULONGEST
+sign_extend (ULONGEST v, int n)
+{
+ ULONGEST mask = (ULONGEST) 1 << (n - 1);
+ return (v ^ mask) - mask;
+}
+
/* Convert hex digit A to a number, or throw an exception. */
extern int fromhex (int a);
diff --git a/gdbsupport/remote-args.cc b/gdbsupport/remote-args.cc
new file mode 100644
index 0000000..2493433
--- /dev/null
+++ b/gdbsupport/remote-args.cc
@@ -0,0 +1,43 @@
+/* Copyright (C) 2023-2025 Free Software Foundation, Inc.
+
+ 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/>. */
+
+#include "gdbsupport/common-defs.h"
+#include "gdbsupport/remote-args.h"
+#include "gdbsupport/common-inferior.h"
+#include "gdbsupport/buildargv.h"
+
+/* See remote-args.h. */
+
+std::vector<std::string>
+gdb::remote_args::split (const std::string &args)
+{
+ std::vector<std::string> results;
+
+ gdb_argv argv (args.c_str ());
+ for (int i = 0; argv[i] != nullptr; i++)
+ results.emplace_back (argv[i]);
+
+ return results;
+}
+
+/* See remote-args.h. */
+
+std::string
+gdb::remote_args::join (const std::vector<char *> &args)
+{
+ return construct_inferior_arguments (args, true);
+}
diff --git a/gdbsupport/remote-args.h b/gdbsupport/remote-args.h
new file mode 100644
index 0000000..0533da6
--- /dev/null
+++ b/gdbsupport/remote-args.h
@@ -0,0 +1,60 @@
+/* Functions to help when passing arguments between GDB and gdbserver.
+
+ Copyright (C) 2023-2025 Free Software Foundation, Inc.
+
+ 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 GDBSUPPORT_REMOTE_ARGS_H
+#define GDBSUPPORT_REMOTE_ARGS_H
+
+/* The functions declared here are used when passing inferior arguments
+ from GDB to gdbserver.
+
+ The remote protocol requires that arguments are passed as a vector of
+ separate argument while GDB stores the arguments as a single string, and
+ gdbserver also requires the arguments be a single string.
+
+ These functions then provide a mechanism to split up an argument string
+ and recombine it within gdbserver while preserving escaping of special
+ characters within the argument string. */
+
+namespace gdb
+{
+
+namespace remote_args
+{
+
+/* ARGS is an inferior argument string. This function splits ARGS into
+ individual arguments and returns a vector containing each argument. */
+
+extern std::vector<std::string> split (const std::string &args);
+
+/* Join together the separate arguments in ARGS and build a single
+ inferior argument string. The string returned by this function will be
+ equivalent, but not necessarily identical to the string passed to
+ ::split, for example passing the string '"a b"' (without the single
+ quotes, but including the double quotes) to ::split, will return an
+ argument of 'a b' (without the single quotes). When this argument is
+ passed through ::join we will get back the string 'a\ b' (without the
+ single quotes), that is, we choose to escape the white space, rather
+ than wrap the argument in quotes. */
+extern std::string join (const std::vector<char *> &args);
+
+} /* namespace remote_args */
+
+} /* namespace gdb */
+
+#endif /* GDBSUPPORT_REMOTE_ARGS_H */
diff --git a/gprofng/doc/gprofng_ug.texi b/gprofng/doc/gprofng_ug.texi
index 7147090..f23f7b3 100644
--- a/gprofng/doc/gprofng_ug.texi
+++ b/gprofng/doc/gprofng_ug.texi
@@ -310,9 +310,8 @@ Since there is no need to recompile, existing executables can be used
and the profile measures the behaviour of exactly the same executable that is
used in production runs.
-With sampling, one inherently profiles a different executable, because
-the calls to the instrumentation library may affect the compiler optimizations
-and run time behaviour.
+With tracing, one inherently profiles a different executable, because
+the calls to the instrumentation library may affect runtime behaviour.
@item
With sampling, there are very few restrictions on what can be profiled and
diff --git a/gprofng/src/CallStack.cc b/gprofng/src/CallStack.cc
index 6df4112..9a3a15d 100644
--- a/gprofng/src/CallStack.cc
+++ b/gprofng/src/CallStack.cc
@@ -527,14 +527,10 @@ CallStackP::add_stack (DataDescriptor *dDscr, long idx, FramePacket *frp,
Vaddr va = frp->getFromStack (index);
DbeInstr *cur_instr = experiment->map_Vaddr_to_PC (va, tstamp);
-#if ARCH(Intel)// TBR? FIXUP_XXX_SPARC_LINUX: switch should be on experiment ARCH, not dbe ARCH
// We need to adjust return addresses on intel
- // in order to attribute inclusive metrics to
- // proper call instructions.
- if (experiment->exp_maj_version <= 9)
- if (!leaf && cur_instr->addr != 0)
- cur_instr = cur_instr->func->find_dbeinstr (0, cur_instr->addr - 1);
-#endif
+ // in order to attribute inclusive metrics to proper instructions.
+ if (experiment->platform == Intel && cur_instr->addr != 0)
+ cur_instr = cur_instr->func->find_dbeinstr (0, cur_instr->addr - 1);
// Skip PC's from PLT, update leaf and state accordingly
if ((cur_instr->func->flags & FUNC_FLAG_PLT)
diff --git a/gprofng/src/gp-archive.cc b/gprofng/src/gp-archive.cc
index 4e68336..ee9f917 100644
--- a/gprofng/src/gp-archive.cc
+++ b/gprofng/src/gp-archive.cc
@@ -140,7 +140,8 @@ er_archive::usage ()
"See also:\n"
"\n"
"gprofng(1), gprofng-collect-app(1), gprofng-display-html(1), "
- "gprofng-display-src(1), gprofng-display-text(1)\n"));
+ "gprofng-display-src(1), gprofng-display-text(1)\n"
+ "\nReport bugs to <https://sourceware.org/bugzilla/>\n"));
exit (1);
}
diff --git a/gprofng/src/gp-collect-app.cc b/gprofng/src/gp-collect-app.cc
index bf146d9..b94f410 100644
--- a/gprofng/src/gp-collect-app.cc
+++ b/gprofng/src/gp-collect-app.cc
@@ -1481,7 +1481,8 @@ collect::usage ()
"See also:\n"
"\n"
"gprofng(1), gprofng-archive(1), gprofng-display-html(1), "
- "gpgprofng-display-src(1), gprofng-display-text(1)\n"));
+ "gpgprofng-display-src(1), gprofng-display-text(1)\n"
+ "\nReport bugs to <https://sourceware.org/bugzilla/>\n"));
}
void
diff --git a/gprofng/src/gp-display-src.cc b/gprofng/src/gp-display-src.cc
index 7eb6b33..5475f27 100644
--- a/gprofng/src/gp-display-src.cc
+++ b/gprofng/src/gp-display-src.cc
@@ -172,7 +172,8 @@ er_src::usage ()
"See also:\n"
"\n"
"gprofng(1), gprofng-archive(1), gprofng-collect-app(1), "
- "gprofng-display-html(1), gprofng-display-text(1)\n"));
+ "gprofng-display-html(1), gprofng-display-text(1)\n"
+ "\nReport bugs to <https://sourceware.org/bugzilla/>\n"));
/*
printf (GTXT ("Usage: %s [OPTION] a.out/.so/.o/.class\n\n"), whoami);
printf (GTXT (" -func List all the functions from the given object\n"
diff --git a/gprofng/src/gp-display-text.cc b/gprofng/src/gp-display-text.cc
index 4fcd639..32bda49 100644
--- a/gprofng/src/gp-display-text.cc
+++ b/gprofng/src/gp-display-text.cc
@@ -254,7 +254,8 @@ er_print::usage ()
"See also:\n"
"\n"
"gprofng(1), gprofng-archive(1), gprofng-collect-app(1), "
- "gprofng-display-html(1), gprofng-display-src(1)\n"));
+ "gprofng-display-html(1), gprofng-display-src(1)\n"
+ "\nReport bugs to <https://sourceware.org/bugzilla/>\n"));
}
int // returns count of experiments read
diff --git a/gprofng/src/gprofng.cc b/gprofng/src/gprofng.cc
index 99f904a..4364d97 100644
--- a/gprofng/src/gprofng.cc
+++ b/gprofng/src/gprofng.cc
@@ -155,7 +155,8 @@ Gprofng::usage ()
"See also:\n"
"\n"
"gprofng-archive(1), gprofng-collect-app(1), gprofng-display-html(1), "
- "gprofng-display-src(1), gprofng-display-text(1)\n"));
+ "gprofng-display-src(1), gprofng-display-text(1)\n"
+ "\nReport bugs to <https://sourceware.org/bugzilla/>\n"));
/*
printf ( GTXT (
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index 9a2b576..50bb082 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -7,11 +7,11 @@ else
fi
case ${target} in
- *-*-cygwin*)
- cygwin_behavior=1
+ *-*-mingw*)
+ mingw_behavior=1
;;
*)
- cygwin_behavior=0;
+ mingw_behavior=0
;;
esac
@@ -126,9 +126,10 @@ fragment <<EOF
#define DEFAULT_PSEUDO_RELOC_VERSION 1
#endif
-#define DEFAULT_DLL_CHARACTERISTICS (${cygwin_behavior} ? 0 : \
- IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
- | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)
+#define DEFAULT_DLL_CHARACTERISTICS (${mingw_behavior} \
+ ? IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
+ | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT \
+ : 0)
#if defined(TARGET_IS_i386pe) || ! defined(DLL_SUPPORT)
#define PE_DEF_SUBSYSTEM IMAGE_SUBSYSTEM_WINDOWS_CUI
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index 440c0bf..60a8339 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -9,11 +9,15 @@ fi
case ${target} in
*-*-cygwin*)
move_default_addr_high=1
- cygwin_behavior=1
+ mingw_behavior=0
+ ;;
+ *-*-mingw*)
+ move_default_addr_high=0
+ mingw_behavior=1
;;
*)
- move_default_addr_high=0;
- cygwin_behavior=0;
+ move_default_addr_high=0
+ mingw_behavior=0
;;
esac
@@ -126,10 +130,11 @@ fragment <<EOF
#define DLL_SUPPORT
#endif
-#define DEFAULT_DLL_CHARACTERISTICS (${cygwin_behavior} ? 0 : \
- IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
- | IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA \
- | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)
+#define DEFAULT_DLL_CHARACTERISTICS (${mingw_behavior} \
+ ? IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
+ | IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA \
+ | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT \
+ : 0)
#if defined(TARGET_IS_i386pep) || defined(COFF_WITH_peAArch64) || ! defined(DLL_SUPPORT)
#define PE_DEF_SUBSYSTEM IMAGE_SUBSYSTEM_WINDOWS_CUI
diff --git a/ld/ld.texi b/ld/ld.texi
index 29bd0e1..e8e09f8 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -3781,7 +3781,8 @@ of the PE file header:
@item --high-entropy-va
@itemx --disable-high-entropy-va
Image is compatible with 64-bit address space layout randomization
-(ASLR). This option is enabled by default for 64-bit PE images.
+(ASLR). This option is enabled by default for 64-bit PE images in
+MinGW targets.
This option also implies @option{--dynamicbase} and
@option{--enable-reloc-section}.
@@ -3791,9 +3792,9 @@ This option also implies @option{--dynamicbase} and
@itemx --disable-dynamicbase
The image base address may be relocated using address space layout
randomization (ASLR). This feature was introduced with MS Windows
-Vista for i386 PE targets. This option is enabled by default but
-can be disabled via the @option{--disable-dynamicbase} option.
-This option also implies @option{--enable-reloc-section}.
+Vista for i386 PE targets. This option is enabled by default for MinGW
+targets but can be disabled via the @option{--disable-dynamicbase}
+option. This option also implies @option{--enable-reloc-section}.
@kindex --forceinteg
@item --forceinteg
@@ -3806,7 +3807,7 @@ default.
@item --disable-nxcompat
The image is compatible with the Data Execution Prevention.
This feature was introduced with MS Windows XP SP2 for i386 PE
-targets. The option is enabled by default.
+targets. The option is enabled by default for MinGW targets.
@kindex --no-isolation
@item --no-isolation
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 0bb9e17..97fdb91 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -5062,7 +5062,8 @@ print_input_section (asection *i, bool is_discarded)
}
print_spaces (SECTION_NAME_MAP_LENGTH - len);
- if (i->output_section != NULL
+ if ((i->flags & SEC_EXCLUDE) == 0
+ && i->output_section != NULL
&& i->output_section->owner == link_info.output_bfd)
addr = i->output_section->vma + i->output_offset;
else
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 91237a4..67c60c3 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -423,8 +423,8 @@ ld_stop_phase (ld_phase phase)
if (pd->begin.ru_maxrss < usage.ru_maxrss)
pd->use.ru_maxrss += usage.ru_maxrss - pd->begin.ru_maxrss;
-#endif
}
+#endif
}
static void
@@ -563,8 +563,8 @@ report_phases (FILE * file, time_t * start, char ** argv)
COLUMN_ENTRY (pd->duration, "ld", 1);
#if defined (HAVE_GETRUSAGE)
COLUMN_ENTRY (pd->use.ru_maxrss, "ld", 2);
- COLUMN_ENTRY (pd->use.ru_utime.tv_sec, "ld", 3);
- COLUMN_ENTRY (pd->use.ru_stime.tv_sec, "ld", 4);
+ COLUMN_ENTRY ((int64_t) pd->use.ru_utime.tv_sec, PRId64, 3);
+ COLUMN_ENTRY ((int64_t) pd->use.ru_stime.tv_sec, PRId64, 4);
#endif
fprintf (file, "\n");
}
diff --git a/ld/ldmisc.c b/ld/ldmisc.c
index 9ee0781..3f305fa 100644
--- a/ld/ldmisc.c
+++ b/ld/ldmisc.c
@@ -42,7 +42,6 @@
%C clever filename:linenumber with function
%D like %C, but no function name
%E current bfd error or errno
- %F error is fatal
%G like %D, but only function name
%H like %C but in addition emit section+offset
%P print program name
@@ -70,7 +69,6 @@
void
vfinfo (FILE *fp, const char *fmt, va_list ap, bool is_warning)
{
- bool isfatal = false;
const char *scan;
int arg_type;
unsigned int arg_count = 0;
@@ -280,11 +278,6 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bool is_warning)
}
break;
- case 'F':
- /* Error is fatal. */
- isfatal = true;
- break;
-
case 'P':
/* Print program name. */
fprintf (fp, "%s", program_name);
@@ -586,9 +579,6 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bool is_warning)
if (is_warning && config.fatal_warnings)
config.make_executable = false;
-
- if (isfatal)
- xexit (1);
}
/* Format info message and print on stdout. */
diff --git a/ld/testsuite/ld-aarch64/protections/bti-and-memory-seal-plt-1-a.d b/ld/testsuite/ld-aarch64/protections/bti-and-memory-seal-plt-1-a.d
new file mode 100644
index 0000000..f8b1c21
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/protections/bti-and-memory-seal-plt-1-a.d
@@ -0,0 +1,45 @@
+#name: No '-z force-bti' with '-z memory-seal' with feature properties (BTI) forces the generation of BTI PLT (shared)
+#source: bti-plt-1.s
+#source: bti-plt-2.s
+#target: [check_shared_lib_support]
+#as: -mabi=lp64 -defsym __property_bti__=1
+#ld: -shared -z memory-seal -T bti-plt.ld -L./tmpdir -lbti-plt-so
+#objdump: -dr -j .plt
+
+[^:]*: *file format elf64-.*aarch64
+
+Disassembly of section \.plt:
+
+[0-9]+ <\.plt>:
+.*: d503245f bti c
+.*: a9bf7bf0 stp x16, x30, \[sp, #-16\]!
+.*: 90000090 adrp x16, 28000 <_GLOBAL_OFFSET_TABLE_>
+.*: f9400e11 ldr x17, \[x16, #24\]
+.*: 91006210 add x16, x16, #0x18
+.*: d61f0220 br x17
+.*: d503201f nop
+.*: d503201f nop
+
+[0-9]+ <.*>:
+.*: 90000090 adrp x16, 28000 <_GLOBAL_OFFSET_TABLE_>
+.*: f9401211 ldr x17, \[x16, #32\]
+.*: 91008210 add x16, x16, #0x20
+.*: d61f0220 br x17
+
+[0-9]+ <.*>:
+.*: 90000090 adrp x16, 28000 <_GLOBAL_OFFSET_TABLE_>
+.*: f9401611 ldr x17, \[x16, #40\]
+.*: 9100a210 add x16, x16, #0x28
+.*: d61f0220 br x17
+
+[0-9]+ <.*>:
+.*: 90000090 adrp x16, 28000 <_GLOBAL_OFFSET_TABLE_>
+.*: f9401a11 ldr x17, \[x16, #48\]
+.*: 9100c210 add x16, x16, #0x30
+.*: d61f0220 br x17
+
+[0-9]+ <.*>:
+.*: 90000090 adrp x16, 28000 <_GLOBAL_OFFSET_TABLE_>
+.*: f9401e11 ldr x17, \[x16, #56\]
+.*: 9100e210 add x16, x16, #0x38
+.*: d61f0220 br x17
diff --git a/ld/testsuite/ld-aarch64/protections/bti-and-memory-seal-plt-1-b.d b/ld/testsuite/ld-aarch64/protections/bti-and-memory-seal-plt-1-b.d
new file mode 100644
index 0000000..0dadcc9
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/protections/bti-and-memory-seal-plt-1-b.d
@@ -0,0 +1,14 @@
+#name: No '-z force-bti' with '-z memory-seal' all input objects have BTI emits BTI feature (shared)
+#source: bti-plt-1.s
+#source: bti-plt-2.s
+#target: [check_shared_lib_support]
+#as: -mabi=lp64 -defsym __property_bti__=1
+#ld: -z memory-seal -shared -T bti-plt.ld
+#readelf: -n
+
+Displaying notes found in: .note.gnu.property
+[ ]+Owner[ ]+Data size[ ]+Description
+ GNU 0x00000018 NT_GNU_PROPERTY_TYPE_0
+ Properties: memory seal\s
+\s+AArch64 feature: BTI
+#pass
diff --git a/ld/testsuite/ld-aarch64/protections/bti-plt-1-b.d b/ld/testsuite/ld-aarch64/protections/bti-plt-1-b.d
index 1bf956c..4b0e424 100644
--- a/ld/testsuite/ld-aarch64/protections/bti-plt-1-b.d
+++ b/ld/testsuite/ld-aarch64/protections/bti-plt-1-b.d
@@ -2,7 +2,7 @@
#source: bti-plt-1.s
#target: [check_shared_lib_support]
#as: -mabi=lp64 -defsym __property_bti__=1
-#ld: -shared -z force-bti -T bti-plt.ld -L./tmpdir -lbti-plt-so
+#ld: -shared -T bti-plt.ld -L./tmpdir -lbti-plt-so
#objdump: -dr -j .plt
[^:]*: *file format elf64-.*aarch64
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 9349190..3a56fb5 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -1212,6 +1212,38 @@ if { [is_elf_format] } {
if { [is_elf_format] && [check_lto_shared_available] } {
run_ld_link_exec_tests $lto_run_elf_shared_tests
+ if { [check_lto_fat_available] } {
+ run_cc_link_tests [list \
+ [list \
+ "Build libpr32846a.a" \
+ "$plug_opt" "-fPIC -O2 -flto $lto_no_fat" \
+ {pr32846a.c pr32846b.c} {} "libpr32846a.a" \
+ ] \
+ [list \
+ "Build libpr32846b.a" \
+ "$plug_opt" "-fPIC -O2 -flto $lto_no_fat" \
+ {pr32846a.c pr32846b.c pr32846c.c} {} "libpr32846b.a" \
+ ] \
+ [list \
+ "Build pr32846d.o" \
+ "$plug_opt" "-fPIC -O2 -flto $lto_no_fat" \
+ {pr32846d.c} {} \
+ ] \
+ [list \
+ "Build pr32846e.o" \
+ "$plug_opt" "-fPIC -O2 -flto $lto_no_fat" \
+ {pr32846e.c} {} \
+ ] \
+ [list \
+ "Build pr32846" \
+ "-shared -fPIC -O2 -flto $lto_no_fat -Wl,--no-undefined \
+ tmpdir/pr32846d.o tmpdir/libpr32846a.a \
+ tmpdir/libpr32846b.a tmpdir/pr32846e.o" \
+ "-O2 -fPIC -flto $lto_no_fat" \
+ {dummy.c} {} "pr32846" \
+ ] \
+ ] \
+ }
}
proc pr20103 {cflags libs} {
diff --git a/ld/testsuite/ld-plugin/pr32846a.c b/ld/testsuite/ld-plugin/pr32846a.c
new file mode 100644
index 0000000..8c16171
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846a.c
@@ -0,0 +1,6 @@
+extern void mkdir_p (void);
+void
+mkdir_parents (void)
+{
+ mkdir_p ();
+}
diff --git a/ld/testsuite/ld-plugin/pr32846b.c b/ld/testsuite/ld-plugin/pr32846b.c
new file mode 100644
index 0000000..9776a37
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846b.c
@@ -0,0 +1,4 @@
+void
+hash_new (void)
+{
+}
diff --git a/ld/testsuite/ld-plugin/pr32846c.c b/ld/testsuite/ld-plugin/pr32846c.c
new file mode 100644
index 0000000..f87cffb
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846c.c
@@ -0,0 +1,6 @@
+extern void hash_new (void);
+void
+kmod_new (void)
+{
+ hash_new();
+}
diff --git a/ld/testsuite/ld-plugin/pr32846d.c b/ld/testsuite/ld-plugin/pr32846d.c
new file mode 100644
index 0000000..c6f4102
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846d.c
@@ -0,0 +1,12 @@
+extern void kmod_new (void);
+extern void mkdir_parents (void);
+void
+do_lsmod (void)
+{
+ kmod_new ();
+}
+void
+do_static_nodes (void)
+{
+ mkdir_parents();
+}
diff --git a/ld/testsuite/ld-plugin/pr32846e.c b/ld/testsuite/ld-plugin/pr32846e.c
new file mode 100644
index 0000000..c4e5e56
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr32846e.c
@@ -0,0 +1,4 @@
+void
+mkdir_p (void)
+{
+}
diff --git a/opcodes/i386-gen.c b/opcodes/i386-gen.c
index bd3cd8f..df80130 100644
--- a/opcodes/i386-gen.c
+++ b/opcodes/i386-gen.c
@@ -356,11 +356,11 @@ static bitfield cpu_flags[] =
BITFIELD (3dnow),
BITFIELD (3dnowA),
BITFIELD (PadLock),
- BITFIELD (GMISM2),
- BITFIELD (GMICCS),
BITFIELD (PadLockRNG2),
BITFIELD (PadLockPHE2),
BITFIELD (PadLockXMODX),
+ BITFIELD (GMISM2),
+ BITFIELD (GMICCS),
BITFIELD (SVME),
BITFIELD (VMX),
BITFIELD (SMX),
diff --git a/opcodes/i386-init.h b/opcodes/i386-init.h
index a752b6c..0c9ae65 100644
--- a/opcodes/i386-init.h
+++ b/opcodes/i386-init.h
@@ -208,8 +208,8 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
-#define CPU_GMISM2_FLAGS \
- { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, \
+#define CPU_PADLOCKRNG2_FLAGS \
+ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -218,8 +218,8 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
-#define CPU_GMICCS_FLAGS \
- { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+#define CPU_PADLOCKPHE2_FLAGS \
+ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, \
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -228,7 +228,7 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
-#define CPU_PADLOCKRNG2_FLAGS \
+#define CPU_PADLOCKXMODX_FLAGS \
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, \
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -238,8 +238,8 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
-#define CPU_PADLOCKPHE2_FLAGS \
- { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, \
+#define CPU_GMISM2_FLAGS \
+ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -248,8 +248,8 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
-#define CPU_PADLOCKXMODX_FLAGS \
- { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, \
+#define CPU_GMICCS_FLAGS \
+ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -1979,8 +1979,8 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
#define CPU_ANY_PADLOCK_FLAGS \
- { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, \
- 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, \
+ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -1989,8 +1989,8 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
#define CPU_ANY_PADLOCKRNG2_FLAGS \
- { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
- 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, \
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -2000,7 +2000,7 @@
#define CPU_ANY_PADLOCKPHE2_FLAGS \
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
- 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
@@ -2010,7 +2010,7 @@
#define CPU_ANY_PADLOCKXMODX_FLAGS \
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
- 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
diff --git a/opcodes/i386-opc.h b/opcodes/i386-opc.h
index fac0371..9e3ed63 100644
--- a/opcodes/i386-opc.h
+++ b/opcodes/i386-opc.h
@@ -66,16 +66,16 @@ enum i386_cpu
CpuSSE3,
/* VIA PadLock required */
CpuPadLock,
- /* Zhaoxin GMI SM2 required */
- CpuGMISM2,
- /* Zhaoxin GMI CCS required */
- CpuGMICCS,
/* Zhaoxin PadLock RNG2 required */
CpuPadLockRNG2,
/* Zhaoxin PadLock PHE2 required */
CpuPadLockPHE2,
/* Zhaoxin PadLock XMODX required */
CpuPadLockXMODX,
+ /* Zhaoxin GMI SM2 required */
+ CpuGMISM2,
+ /* Zhaoxin GMI CCS required */
+ CpuGMICCS,
/* AMD Secure Virtual Machine Ext-s required */
CpuSVME,
/* VMX Instructions required */
@@ -428,11 +428,11 @@ typedef union i386_cpu_flags
unsigned int cpusse2:1;
unsigned int cpusse3:1;
unsigned int cpupadlock:1;
- unsigned int cpugmism2:1;
- unsigned int cpugmiccs:1;
unsigned int cpupadlockrng2:1;
unsigned int cpupadlockphe2:1;
unsigned int cpupadlockxmodx:1;
+ unsigned int cpugmism2:1;
+ unsigned int cpugmiccs:1;
unsigned int cpusvme:1;
unsigned int cpuvmx:1;
unsigned int cpusmx:1;
diff --git a/opcodes/i386-tbl.h b/opcodes/i386-tbl.h
index c7d2912..c12c69e 100644
--- a/opcodes/i386-tbl.h
+++ b/opcodes/i386-tbl.h
@@ -35660,7 +35660,7 @@ static const insn_template i386_optab[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0 },
- { { 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } } } },
@@ -35668,7 +35668,7 @@ static const insn_template i386_optab[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0 },
- { { 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } } } },
@@ -35676,7 +35676,7 @@ static const insn_template i386_optab[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0 },
- { { 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } } } },
@@ -35684,7 +35684,7 @@ static const insn_template i386_optab[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0 },
- { { 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } } } },
@@ -35692,7 +35692,7 @@ static const insn_template i386_optab[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0 },
- { { 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } } } },
@@ -35700,7 +35700,7 @@ static const insn_template i386_optab[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0 },
- { { 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } } } },
@@ -35708,7 +35708,7 @@ static const insn_template i386_optab[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0 },
- { { 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } } } },
@@ -35716,7 +35716,7 @@ static const insn_template i386_optab[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0 },
- { { 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
+ { { 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } } } },
diff --git a/opcodes/loongarch-opc.c b/opcodes/loongarch-opc.c
index a172a2a..fa53021 100644
--- a/opcodes/loongarch-opc.c
+++ b/opcodes/loongarch-opc.c
@@ -454,6 +454,9 @@ static struct loongarch_opcode loongarch_macro_opcodes[] =
static struct loongarch_opcode loongarch_alias_opcodes[] =
{
/* match, mask, name, format, macro, include, exclude, pinfo. */
+ { 0x00006000, 0xffffffe0, "rdcntvl.w", "r0:5", 0, 0, 0, INSN_DIS_ALIAS }, /* rdtimel.w rd, zero */
+ { 0x00006000, 0xfffffc1f, "rdcntid.w", "r5:5", 0, 0, 0, INSN_DIS_ALIAS }, /* rdtimel.w zero, rj */
+ { 0x00006400, 0xffffffe0, "rdcntvh.w", "r0:5", 0, 0, 0, INSN_DIS_ALIAS }, /* rdtimeh.w rd, zero */
{ 0x00150000, 0xfffffc00, "move", "r0:5,r5:5", 0, 0, 0, INSN_DIS_ALIAS }, /* or rd, rj, zero */
{ 0x02800000, 0xffc003e0, "li.w", "r0:5,s10:12", 0, 0, 0, INSN_DIS_ALIAS }, /* addi.w rd, zero, simm */
{ 0x02c00000, 0xffc003e0, "li.d", "r0:5,s10:12", 0, 0, 0, INSN_DIS_ALIAS }, /* addi.d rd, zero, simm */
@@ -494,7 +497,10 @@ static struct loongarch_opcode loongarch_fix_opcodes[] =
{ 0x00005400, 0xfffffc00, "bitrev.d", "r0:5,r5:5", 0, 0, 0, 0 },
{ 0x00005800, 0xfffffc00, "ext.w.h", "r0:5,r5:5", 0, 0, 0, 0 },
{ 0x00005c00, 0xfffffc00, "ext.w.b", "r0:5,r5:5", 0, 0, 0, 0 },
+ { 0x0, 0x0, "rdcntvl.w", "r", "rdtimel.w %1,$r0", 0, 0, 0 },
+ { 0x0, 0x0, "rdcntid.w", "r", "rdtimel.w $r0,%1", 0, 0, 0 },
{ 0x00006000, 0xfffffc00, "rdtimel.w", "r0:5,r5:5", 0, 0, 0, 0 },
+ { 0x0, 0x0, "rdcntvh.w", "r", "rdtimeh.w %1,$r0", 0, 0, 0 },
{ 0x00006400, 0xfffffc00, "rdtimeh.w", "r0:5,r5:5", 0, 0, 0, 0 },
{ 0x00006800, 0xfffffc00, "rdtime.d", "r0:5,r5:5", 0, 0, 0, 0 },
{ 0x00006c00, 0xfffffc00, "cpucfg", "r0:5,r5:5", 0, 0, 0, 0 },
diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index f862ef2..277b8fd 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -69,7 +69,7 @@ struct riscv_private_data
const char (*riscv_fpr_names)[NRC];
/* If set, disassemble as most general instruction. */
bool no_aliases;
- /* If set, disassemble without checking architectire string, just like what
+ /* If set, disassemble without checking architecture string, just like what
we did at the beginning. */
bool all_ext;
};
@@ -83,6 +83,7 @@ set_default_riscv_dis_options (struct disassemble_info *info)
pd->riscv_gpr_names = riscv_gpr_names_abi;
pd->riscv_fpr_names = riscv_fpr_names_abi;
pd->no_aliases = false;
+ pd->all_ext = false;
}
/* Parse RISC-V disassembler option (without arguments). */
@@ -1580,6 +1581,9 @@ static struct
riscv_option_arg_t arg;
} riscv_options[] =
{
+ { "max",
+ N_("Disassemble without checking architecture string."),
+ RISCV_OPTION_ARG_NONE },
{ "numeric",
N_("Print numeric register names, rather than ABI names."),
RISCV_OPTION_ARG_NONE },