Sync from SUSE:ALP:Source:Standard:1.0 gdb revision 3bcf2795561866793949a58c97f00a2f

This commit is contained in:
Adrian Schröter 2024-01-16 09:36:20 +01:00
commit 16b3d03efa
174 changed files with 30882 additions and 0 deletions

23
.gitattributes vendored Normal file
View File

@ -0,0 +1,23 @@
## Default LFS
*.7z filter=lfs diff=lfs merge=lfs -text
*.bsp filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.gem filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.lz filter=lfs diff=lfs merge=lfs -text
*.lzma filter=lfs diff=lfs merge=lfs -text
*.obscpio filter=lfs diff=lfs merge=lfs -text
*.oxt filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.rpm filter=lfs diff=lfs merge=lfs -text
*.tbz filter=lfs diff=lfs merge=lfs -text
*.tbz2 filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.txz filter=lfs diff=lfs merge=lfs -text
*.whl filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text

117
README.qa Normal file
View File

@ -0,0 +1,117 @@
I. LOCAL QA.
0. Notes.
Note that the configs are hardcoded in the script. F.i. atm SLE-11 is not
included, because the config is unresolvable on devel:gcc/gdb. Also Leap
15.2 is not included because of 'remote error: unknown repository type
UNDEFINED"'.
The script tries to keep disk usage low by removing the buildroot after each
build, but that requires sudo rights, so the first thing the script does is
ask for sudo authentication.
1. Cleanup.
Do:
...
$ bash qa-local.sh 1
...
2. Build.
Do:
...
$ bash qa-local.sh 2
...
This builds gdb for each x86_64 config, without running the testsuite.
I did a timing run on my laptop (with 6 configs) and got:
...
real 66m17.689s
user 149m31.925s
sys 12m25.359s
...
so for a dual-core/4-SMT CPU, it's ~1h5m.
3. Build & test.
Do:
...
$ bash qa-local.sh 3
...
This builds gdb and produces test results for each x86_64 config.
I did a timing run on my laptop (with 6 configs) and got:
...
real 285m9.679s
user 683m16.769s
sys 133m58.287s
...
so for a dual-core/4-SMT CPU, it's ~4h45m.
The resulting testlogs (with 6 configs) is 1.4GB.
4. Verify.
Do:
...
$ bash qa-local.sh 4
...
This verifies the test results for each x86_64 config, using the qa.sh script.
5. Cleanup.
Do:
...
$ rm -Rf tmp-qa-local
...
l
I. REMOTE QA.
1. Cleanup.
Do:
...
$ bash qa-remote.sh 1
...
2. Get test results.
Do:
...
$ bash qa-remote.sh 2
...
This downloads the remote test results.
3. Verify.
Do:
...
$ bash qa-remote.sh 3 <m>
...
with m running from 1 to 5.
This verifies the test results, using the qa.sh script.
4. Cleanup.
Do:
...
$ rm -Rf tmp-qa-remote
...

24
_constraints Normal file
View File

@ -0,0 +1,24 @@
<constraints>
<overwrite>
<conditions>
<arch>ppc64</arch>
<arch>ppc64le</arch>
</conditions>
<hardware>
<disk>
<size unit="G">4</size>
</disk>
</hardware>
</overwrite>
<overwrite>
<conditions>
<arch>x86_64</arch>
</conditions>
<hardware>
<disk>
<size unit="G">8</size>
</disk>
</hardware>
</overwrite>
</constraints>

3
_multibuild Normal file
View File

@ -0,0 +1,3 @@
<multibuild>
<package>testsuite</package>
</multibuild>

View File

@ -0,0 +1,50 @@
From 0f363ed540fef466f45eab4570c23853e1f14898 Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr@google.com>
Date: Thu, 9 Feb 2023 10:47:17 -0800
Subject: [PATCH] [aarch64] Avoid initializers for VLAs
Clang doesn't accept initializer syntax for variable-length
arrays in C. Just use memset instead.
---
gdb/aarch64-linux-nat.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index e4158236db2..ecb2eeb9540 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -56,6 +56,8 @@
#include "nat/aarch64-mte-linux-ptrace.h"
+#include <string.h>
+
#ifndef TRAP_HWBKPT
#define TRAP_HWBKPT 0x0004
#endif
@@ -445,7 +447,9 @@ fetch_tlsregs_from_thread (struct regcache *regcache)
gdb_assert (regno != -1);
gdb_assert (tdep->tls_register_count > 0);
- uint64_t tpidrs[tdep->tls_register_count] = { 0 };
+ uint64_t tpidrs[tdep->tls_register_count];
+ memset(tpidrs, 0, sizeof(tpidrs));
+
struct iovec iovec;
iovec.iov_base = tpidrs;
iovec.iov_len = sizeof (tpidrs);
@@ -471,7 +475,8 @@ store_tlsregs_to_thread (struct regcache *regcache)
gdb_assert (regno != -1);
gdb_assert (tdep->tls_register_count > 0);
- uint64_t tpidrs[tdep->tls_register_count] = { 0 };
+ uint64_t tpidrs[tdep->tls_register_count];
+ memset(tpidrs, 0, sizeof(tpidrs));
for (int i = 0; i < tdep->tls_register_count; i++)
{
base-commit: a39101060cdf2ee239833106fb3bdf9585f858aa
--
2.35.3

View File

@ -0,0 +1,202 @@
From 4e0e7ff14ba271576232160bf337639662a2ea23 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tom@tromey.com>
Date: Thu, 16 Feb 2023 17:36:29 -0700
Subject: [PATCH 2/3] Avoid manual memory management in go-lang.c
I noticed a couple of spots in go-lang.c that could be improved by
using unique_ptr.
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
---
gdb/dwarf2/read.c | 2 +-
gdb/go-exp.c | 287 +++++++++++++++++++++++-----------------------
gdb/go-exp.y | 8 +-
gdb/go-lang.c | 40 +++----
gdb/go-lang.h | 11 +-
5 files changed, 173 insertions(+), 175 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8aa7f8c31e5..61f4bd75013 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7890,7 +7890,7 @@ fixup_go_packaging (struct dwarf2_cu *cu)
&& sym->aclass () == LOC_BLOCK)
{
gdb::unique_xmalloc_ptr<char> this_package_name
- (go_symbol_package_name (sym));
+ = go_symbol_package_name (sym);
if (this_package_name == NULL)
continue;
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index cbaa79ee18c..542a06d06d6 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -1393,16 +1393,16 @@ classify_name (struct parser_state *par_state, const struct block *block)
current package. */
{
- char *current_package_name = go_block_package_name (block);
+ gdb::unique_xmalloc_ptr<char> current_package_name
+ = go_block_package_name (block);
if (current_package_name != NULL)
{
struct stoken sval =
- build_packaged_name (current_package_name,
- strlen (current_package_name),
+ build_packaged_name (current_package_name.get (),
+ strlen (current_package_name.get ()),
copy.c_str (), copy.size ());
- xfree (current_package_name);
sym = lookup_symbol (sval.ptr, block, VAR_DOMAIN,
&is_a_field_of_this);
if (sym.symbol)
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 7549f14dc63..f9176ace71d 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -163,11 +163,8 @@ unpack_package_and_object (char *buf,
Space for the resulting strings is malloc'd in one buffer.
PACKAGEP,OBJECTP,METHOD_TYPE* will (typically) point into this buffer.
- [There are a few exceptions, but the caller is still responsible for
- freeing the resulting pointer.]
A pointer to this buffer is returned, or NULL if symbol isn't a
mangled Go symbol.
- The caller is responsible for freeing the result.
*METHOD_TYPE_IS_POINTERP is set to a boolean indicating if
the method type is a pointer.
@@ -180,7 +177,7 @@ unpack_package_and_object (char *buf,
If we ever need to unpack the method type, this routine should work
for that too. */
-static char *
+static gdb::unique_xmalloc_ptr<char>
unpack_mangled_go_symbol (const char *mangled_name,
const char **packagep,
const char **objectp,
@@ -209,9 +206,10 @@ unpack_mangled_go_symbol (const char *mangled_name,
/* main.init is mangled specially. */
if (strcmp (mangled_name, "__go_init_main") == 0)
{
- char *package = xstrdup ("main");
+ gdb::unique_xmalloc_ptr<char> package
+ = make_unique_xstrdup ("main");
- *packagep = package;
+ *packagep = package.get ();
*objectp = "init";
return package;
}
@@ -219,9 +217,10 @@ unpack_mangled_go_symbol (const char *mangled_name,
/* main.main is mangled specially (missing prefix). */
if (strcmp (mangled_name, "main.main") == 0)
{
- char *package = xstrdup ("main");
+ gdb::unique_xmalloc_ptr<char> package
+ = make_unique_xstrdup ("main");
- *packagep = package;
+ *packagep = package.get ();
*objectp = "main";
return package;
}
@@ -261,7 +260,8 @@ unpack_mangled_go_symbol (const char *mangled_name,
/* At this point we've decided we have a mangled Go symbol. */
- buf = xstrdup (mangled_name);
+ gdb::unique_xmalloc_ptr<char> result = make_unique_xstrdup (mangled_name);
+ buf = result.get ();
/* Search backwards looking for "N<digit(s)>". */
p = buf + len;
@@ -317,7 +317,7 @@ unpack_mangled_go_symbol (const char *mangled_name,
}
unpack_package_and_object (buf, packagep, objectp);
- return buf;
+ return result;
}
/* Implements the la_demangle language_defn routine for language Go.
@@ -381,10 +381,9 @@ go_language::demangle_symbol (const char *mangled_name, int options) const
return make_unique_xstrdup ((const char *) obstack_finish (&tempbuf));
}
-/* Given a Go symbol, return its package or NULL if unknown.
- Space for the result is malloc'd, caller must free. */
+/* See go-lang.h. */
-char *
+gdb::unique_xmalloc_ptr<char>
go_symbol_package_name (const struct symbol *sym)
{
const char *mangled_name = sym->linkage_name ();
@@ -393,8 +392,7 @@ go_symbol_package_name (const struct symbol *sym)
const char *method_type_package_name;
const char *method_type_object_name;
int method_type_is_pointer;
- char *name_buf;
- char *result;
+ gdb::unique_xmalloc_ptr<char> name_buf;
gdb_assert (sym->language () == language_go);
name_buf = unpack_mangled_go_symbol (mangled_name,
@@ -405,15 +403,12 @@ go_symbol_package_name (const struct symbol *sym)
/* Some Go symbols don't have mangled form we interpret (yet). */
if (name_buf == NULL)
return NULL;
- result = xstrdup (package_name);
- xfree (name_buf);
- return result;
+ return make_unique_xstrdup (package_name);
}
-/* Return the package that BLOCK is in, or NULL if there isn't one.
- Space for the result is malloc'd, caller must free. */
+/* See go-lang.h. */
-char *
+gdb::unique_xmalloc_ptr<char>
go_block_package_name (const struct block *block)
{
while (block != NULL)
@@ -422,7 +417,8 @@ go_block_package_name (const struct block *block)
if (function != NULL)
{
- char *package_name = go_symbol_package_name (function);
+ gdb::unique_xmalloc_ptr<char> package_name
+ = go_symbol_package_name (function);
if (package_name != NULL)
return package_name;
diff --git a/gdb/go-lang.h b/gdb/go-lang.h
index f0929cc3ac5..8edfe6ed53a 100644
--- a/gdb/go-lang.h
+++ b/gdb/go-lang.h
@@ -62,9 +62,14 @@ extern const char *go_main_name (void);
extern enum go_type go_classify_struct_type (struct type *type);
-extern char *go_symbol_package_name (const struct symbol *sym);
-
-extern char *go_block_package_name (const struct block *block);
+/* Given a Go symbol, return its package or nullptr if unknown. */
+extern gdb::unique_xmalloc_ptr<char> go_symbol_package_name
+ (const struct symbol *sym);
+
+/* Return the package that BLOCK is in, or nullptr if there isn't
+ one. */
+extern gdb::unique_xmalloc_ptr<char> go_block_package_name
+ (const struct block *block);
extern const struct builtin_go_type *builtin_go_type (struct gdbarch *);
--
2.35.3

11
baselibs.conf Normal file
View File

@ -0,0 +1,11 @@
gdb
+/usr/bin/gdb -> /usr/bin/gdb<extension>
# kill package for i586 32bit
targetarch x86_64 block!
prereq -glibc-x86
gdbserver
+/usr/bin/gdbserver -> /usr/bin/gdbserver<extension>
provides "gdb-<targettype>:/usr/bin/gdbserver<extension>"
# kill package for i586 32bit
targetarch x86_64 block!
prereq -glibc-x86

46
clean.sh Normal file
View File

@ -0,0 +1,46 @@
#!/bin/sh
dryrun=false
while [ $# -gt 0 ]; do
case $1 in
-dryrun|--dryrun|-dry-run|--dry-run)
dryrun=true
;;
*)
echo "Don't know how to handle arg: $1"
exit 1
esac
shift
done
first=true
for f in *.patch; do
if grep -q "^Patch.*[ \t]$f" gdb.spec; then
continue
fi
if $dryrun; then
if $first; then
echo "Patches not mentioned in gdb.spec:"
fi
first=false
echo "$f"
continue
fi
( set -x; osc remove -f "$f" )
done
files=$(echo ./*~)
if [ "$files" != "./*~" ]; then
if $dryrun; then
echo "Backup files:"
echo "$files"
else
for f in $files; do
( set -x; rm -f "$f" )
done
fi
fi

View File

@ -0,0 +1,23 @@
Fix gdb.mi/new-ui-mi-sync.exp
---
gdb/testsuite/gdb.mi/new-ui-mi-sync.exp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.mi/new-ui-mi-sync.exp b/gdb/testsuite/gdb.mi/new-ui-mi-sync.exp
index 887bd60abcd..18072d4e668 100644
--- a/gdb/testsuite/gdb.mi/new-ui-mi-sync.exp
+++ b/gdb/testsuite/gdb.mi/new-ui-mi-sync.exp
@@ -83,7 +83,11 @@ proc do_test {sync_command} {
# in the separate MI UI. Note the "run" variant usually triggers
# =thread-group-started/=thread-created/=library-loaded as well.
with_spawn_id $gdb_main_spawn_id {
- gdb_test "add-inferior" "Added inferior 2 on connection .*"
+ gdb_test_multiple "add-inferior" "" {
+ -re "\r\nAdded inferior 2 on connection .*\[\r\n\]+$gdb_prompt " {
+ pass $gdb_test_name
+ }
+ }
}
# Interrupt the program.

View File

@ -0,0 +1,148 @@
From 11a41bc318ba0307248eadf29bf7d4a1af31d3a8 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Tue, 16 May 2023 17:00:51 +0100
Subject: [PATCH 2/2] Fix PR30369 regression on aarch64/arm (PR30506)
The gdb.dwarf2/dw2-prologue-end-2.exp test was failing for both AArch64 and
Arm.
As Tom pointed out here (https://inbox.sourceware.org/gdb-patches/6663707c-4297-c2f2-a0bd-f3e84fc62aad@suse.de/),
there are issues with both the prologue skipper for AArch64 and Arm and an
incorrect assumption by the testcase.
This patch fixes both of AArch64's and Arm's prologue skippers to not skip past
the end of a function. It also incorporates a fix to the testcase so it
doesn't assume the prologue skipper will stop at the first instruction of the
functions/labels.
Regression-tested on aarch64-linux/arm-linux Ubuntu 20.04/22.04 and
x86_64-linux Ubuntu 20.04.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30506
Co-Authored-By: Tom de Vries <tdevries@suse.de>
Co-Authored-By: Luis Machado <luis.machado@arm.com>
---
gdb/aarch64-tdep.c | 10 +++++++--
gdb/arm-tdep.c | 21 ++++++++++++++++---
.../gdb.dwarf2/dw2-prologue-end-2.exp | 12 +++++------
3 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 499b87ef480..e21d18f5c8c 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -896,12 +896,15 @@ aarch64_analyze_prologue_test (void)
static CORE_ADDR
aarch64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
{
- CORE_ADDR func_addr, limit_pc;
+ CORE_ADDR func_addr, func_end_addr, limit_pc;
/* See if we can determine the end of the prologue via the symbol
table. If so, then return either PC, or the PC after the
prologue, whichever is greater. */
- if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
+ bool func_addr_found
+ = find_pc_partial_function (pc, NULL, &func_addr, &func_end_addr);
+
+ if (func_addr_found)
{
CORE_ADDR post_prologue_pc
= skip_prologue_using_sal (gdbarch, func_addr);
@@ -921,6 +924,9 @@ aarch64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
if (limit_pc == 0)
limit_pc = pc + 128; /* Magic. */
+ limit_pc
+ = func_end_addr == 0? limit_pc : std::min (limit_pc, func_end_addr - 4);
+
/* Try disassembling prologue. */
return aarch64_analyze_prologue (gdbarch, pc, limit_pc, NULL);
}
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 58b9c5f4bd8..ecffb9223e1 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -1768,12 +1768,18 @@ arm_skip_stack_protector(CORE_ADDR pc, struct gdbarch *gdbarch)
static CORE_ADDR
arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
{
- CORE_ADDR func_addr, limit_pc;
+ CORE_ADDR func_addr, func_end_addr, limit_pc;
/* See if we can determine the end of the prologue via the symbol table.
If so, then return either PC, or the PC after the prologue, whichever
is greater. */
- if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
+ bool func_addr_found
+ = find_pc_partial_function (pc, NULL, &func_addr, &func_end_addr);
+
+ /* Whether the function is thumb mode or not. */
+ bool func_is_thumb = false;
+
+ if (func_addr_found)
{
CORE_ADDR post_prologue_pc
= skip_prologue_using_sal (gdbarch, func_addr);
@@ -1810,7 +1816,8 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
associate prologue code with the opening brace; so this
lets us skip the first line if we think it is the opening
brace. */
- if (arm_pc_is_thumb (gdbarch, func_addr))
+ func_is_thumb = arm_pc_is_thumb (gdbarch, func_addr);
+ if (func_is_thumb)
analyzed_limit = thumb_analyze_prologue (gdbarch, func_addr,
post_prologue_pc, NULL);
else
@@ -1836,6 +1843,14 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
if (limit_pc == 0)
limit_pc = pc + 64; /* Magic. */
+ /* Set the correct adjustment based on whether the function is thumb mode or
+ not. We use it to get the address of the last instruction in the
+ function (as opposed to the first address of the next function). */
+ CORE_ADDR adjustment = func_is_thumb? 2 : 4;
+
+ limit_pc
+ = func_end_addr == 0? limit_pc : std::min (limit_pc,
+ func_end_addr - adjustment);
/* Check if this is Thumb code. */
if (arm_pc_is_thumb (gdbarch, pc))
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-prologue-end-2.exp b/gdb/testsuite/gdb.dwarf2/dw2-prologue-end-2.exp
index 642b73fe2a1..da49902c13c 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-prologue-end-2.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-prologue-end-2.exp
@@ -95,17 +95,17 @@ if { $break_addr == "" } {
return
}
-# Get the "foo_label" address.
+# Get the "bar_label" address.
-set foo_label_addr ""
-gdb_test_multiple "print /x &foo_label" "" {
+set bar_label_addr ""
+gdb_test_multiple "print /x &bar_label" "" {
-re -wrap "= ($hex)" {
- set foo_label_addr $expect_out(1,string)
+ set bar_label_addr $expect_out(1,string)
pass $gdb_test_name
}
}
-if { $foo_label_addr == "" } {
+if { $bar_label_addr == "" } {
return
}
@@ -117,4 +117,4 @@ gdb_test "print &foo_end == &bar_label" " = 1"
# Check that the breakpoint is set at the expected address. Regression test
# for PR30369.
-gdb_assert { $break_addr == $foo_label_addr }
+gdb_assert { $break_addr < $bar_label_addr }
--
2.35.3

View File

@ -0,0 +1,29 @@
fixup-2-gdb-rhbz1553104-s390x-arch12-test
---
gdb/testsuite/gdb.arch/s390x-arch12.exp | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/gdb/testsuite/gdb.arch/s390x-arch12.exp b/gdb/testsuite/gdb.arch/s390x-arch12.exp
index 246c1e1c69a..7939a2d6932 100644
--- a/gdb/testsuite/gdb.arch/s390x-arch12.exp
+++ b/gdb/testsuite/gdb.arch/s390x-arch12.exp
@@ -31,4 +31,18 @@ gdb_exit
gdb_start
gdb_load $ofile
+set supported 0
+gdb_test_multiple "show arch" "" {
+ -re -wrap "\"s390:64-bit\".*" {
+ set supported 1
+ }
+ -re -wrap "" {
+ }
+}
+
+if { ! $supported } {
+ unsupported "No s390x support"
+ return -1
+}
+
gdb_test "disas load_guarded" " <\\+28>:\tlgg\t%r1,0\\(%r1\\)\r\n\[^\r\n\]* <\\+34>:\tstg\t%r1,168\\(%r11\\)\r\n.*"

View File

@ -0,0 +1,30 @@
From 19dc95258888a9e110ad54fa25a613611956a13f Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Tue, 13 Jun 2023 15:04:32 +0200
Subject: [PATCH 5/6] fixup gdb-6.3-attach-see-vdso-test.patch
---
gdb/testsuite/gdb.base/attach-see-vdso.exp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/gdb/testsuite/gdb.base/attach-see-vdso.exp b/gdb/testsuite/gdb.base/attach-see-vdso.exp
index 5457ec4129d..35c49731f0b 100644
--- a/gdb/testsuite/gdb.base/attach-see-vdso.exp
+++ b/gdb/testsuite/gdb.base/attach-see-vdso.exp
@@ -34,10 +34,11 @@ set escapedbinfile [string_to_regexp [standard_output_file ${testfile}]]
# The kernel VDSO is used for the syscalls returns only on i386 (not x86_64).
#
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-m32}] != "" } {
- gdb_suppress_entire_file "Testcase nonthraded compile failed, so all tests in this file will automatically fail."
+ unsupported "Testcase nonthreaded compile failed, so all tests in this file will automatically fail."
+ return
}
-if [get_compiler_info ${binfile}] {
+if [get_compiler_info] {
return -1
}
--
2.35.3

View File

@ -0,0 +1,25 @@
From 8c0ae8c3c6fa34f046131f76871db13bc392a440 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Tue, 13 Jun 2023 14:56:55 +0200
Subject: [PATCH 4/6] fixup gdb-6.3-gstack-20050411.patch
---
gdb/testsuite/gdb.base/gstack.exp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.base/gstack.exp b/gdb/testsuite/gdb.base/gstack.exp
index 089407ec04a..a5dacd582ff 100644
--- a/gdb/testsuite/gdb.base/gstack.exp
+++ b/gdb/testsuite/gdb.base/gstack.exp
@@ -52,7 +52,7 @@ gdb_expect {
# exiting the function. Still we could retry the gstack command if we fail.
set test "spawn gstack"
-set command "sh -c GDB=$GDB\\ GDBARGS=-data-directory\\\\\\ $BUILD_DATA_DIRECTORY\\ sh\\ ${srcdir}/../gstack.sh\\ $pid\\;echo\\ GSTACK-END"
+set command "sh -c GDB=$GDB\\ GDBARGS=-data-directory\\\\\\ $GDB_DATA_DIRECTORY\\ sh\\ ${srcdir}/../gstack.sh\\ $pid\\;echo\\ GSTACK-END"
set res [remote_spawn host $command];
if { $res < 0 || $res == "" } {
perror "Spawning $command failed."
--
2.35.3

View File

@ -0,0 +1,35 @@
Fixup gdb.base/tracefork-zombie.exp
Fix ERROR:
...
PASS: gdb.base/tracefork-zombie.exp: attach
ERROR: tcl error sourcing gdb/testsuite/gdb.base/tracefork-zombie.exp.
ERROR: tcl error code POSIX ESRCH {no such process}
ERROR: error reading "file12": no such process
while executing
"read $statusfi"
("foreach" body line 5)
invoked from within
...
---
gdb/testsuite/gdb.base/tracefork-zombie.exp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/gdb/testsuite/gdb.base/tracefork-zombie.exp b/gdb/testsuite/gdb.base/tracefork-zombie.exp
index 03f790d4c5d..3e2e5517d46 100644
--- a/gdb/testsuite/gdb.base/tracefork-zombie.exp
+++ b/gdb/testsuite/gdb.base/tracefork-zombie.exp
@@ -58,8 +58,10 @@ foreach procpid [glob -directory /proc -type d {[0-9]*}] {
if {[catch {open $procpid/status} statusfi]} {
continue
}
- set status [read $statusfi]
- close $statusfi
+ if {[catch {read $statusfi} status]} {
+ continue
+ }
+ catch {close $statusfi}
if {1
&& [regexp -line {^Name:\tgdb$} $status]
&& [regexp -line {^PPid:\t1$} $status]

View File

@ -0,0 +1,22 @@
From 023314feb400836eb377a5bc9151850fcdd81b11 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Tue, 6 Jun 2023 09:43:36 +0200
Subject: [PATCH 3/4] Fixup gdb-bz634108-solib_address.patch
---
gdb/testsuite/gdb.python/rh634108-solib_address.exp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.python/rh634108-solib_address.exp b/gdb/testsuite/gdb.python/rh634108-solib_address.exp
index 99e6aaba831..ebf00babc34 100644
--- a/gdb/testsuite/gdb.python/rh634108-solib_address.exp
+++ b/gdb/testsuite/gdb.python/rh634108-solib_address.exp
@@ -21,4 +21,4 @@ gdb_start
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
-gdb_test "python print (gdb.solib_name(-1))" "None" "gdb.solib_name exists"
+gdb_test "python print (gdb.solib_name(0))" "None" "gdb.solib_name exists"
--
2.35.3

View File

@ -0,0 +1,19 @@
fixup-gdb-glibc-strstr-workaround.patch
---
gdb/testsuite/gdb.base/gnu-ifunc-strstr-workaround.exp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.base/gnu-ifunc-strstr-workaround.exp b/gdb/testsuite/gdb.base/gnu-ifunc-strstr-workaround.exp
index 889f8c6f584..052bd84d420 100644
--- a/gdb/testsuite/gdb.base/gnu-ifunc-strstr-workaround.exp
+++ b/gdb/testsuite/gdb.base/gnu-ifunc-strstr-workaround.exp
@@ -68,7 +68,7 @@ gdb_test_multiple $test $test {
set addr $expect_out(1,string)
pass "$test (fixed glibc)"
}
- -re " = {char \\*\\(const char \\*, const char \\*\\)} 0x\[0-9a-f\]+ <strstr>\r\n$gdb_prompt $" {
+ -re " = {char \\*\\(const char \\*, const char \\*\\)} 0x\[0-9a-f\]+ <(__GI_)?strstr>\r\n$gdb_prompt $" {
untested "$test (gnu-ifunc not in use by glibc)"
return 0
}

View File

@ -0,0 +1,26 @@
From 266359a17e77a53d4ebaa4f3b15c2ae39e43fca0 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Tue, 13 Jun 2023 15:07:22 +0200
Subject: [PATCH 6/6] fixup gdb-lineno-makeup-test.patch
---
gdb/testsuite/gdb.base/lineno-makeup.exp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.base/lineno-makeup.exp b/gdb/testsuite/gdb.base/lineno-makeup.exp
index 9e11d78bf9c..d31e063bdc2 100644
--- a/gdb/testsuite/gdb.base/lineno-makeup.exp
+++ b/gdb/testsuite/gdb.base/lineno-makeup.exp
@@ -21,7 +21,8 @@ set binfuncfile [standard_output_file ${testfile}-func.bin]
set binfile [standard_output_file ${testfile}]
if { [gdb_compile "${srcdir}/${subdir}/${srcfuncfile}" "${objfuncfile}" object {}] != "" } {
- gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+ unsupported "Testcase compile failed, so all tests in this file will automatically fail."
+ return
}
set objcopy [catch "exec objcopy -O binary --only-section .text ${objfuncfile} ${binfuncfile}" output]
--
2.35.3

View File

@ -0,0 +1,24 @@
diff --git a/gdb/gdb.c b/gdb/gdb.c
index 82e9e6da210..b5e28445630 100644
--- a/gdb/gdb.c
+++ b/gdb/gdb.c
@@ -20,19 +20,11 @@
#include "main.h"
#include "interps.h"
-#ifdef PERF_ATTR_SIZE_VER5_BUNDLE
-extern "C" void __libipt_init(void);
-#endif
-
int
main (int argc, char **argv)
{
struct captured_main_args args;
-#ifdef PERF_ATTR_SIZE_VER5_BUNDLE
- __libipt_init();
-#endif
-
memset (&args, 0, sizeof args);
args.argc = argc;
args.argv = argv;

View File

@ -0,0 +1,43 @@
From e452307ba07f5d798edad73631182e137265da7d Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Tue, 13 Jun 2023 17:58:42 +0200
Subject: [PATCH 9/9] fixup gdb-rhbz1261564-aarch64-hw-watchpoint-test.patch
---
.../rhbz1261564-aarch64-watchpoint.exp | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/gdb/testsuite/gdb.base/rhbz1261564-aarch64-watchpoint.exp b/gdb/testsuite/gdb.base/rhbz1261564-aarch64-watchpoint.exp
index b1cf7115663..42ebc25cc49 100644
--- a/gdb/testsuite/gdb.base/rhbz1261564-aarch64-watchpoint.exp
+++ b/gdb/testsuite/gdb.base/rhbz1261564-aarch64-watchpoint.exp
@@ -20,12 +20,22 @@ if { [prepare_for_testing rhbz1261564-aarch64-watchpoint.exp "rhbz1261564-aarch6
if { ! [ runto main ] } then { return 0 }
set test "rwatch aligned.var4"
-if [istarget "s390*-*-*"] {
- gdb_test $test {Target does not support this type of hardware watchpoint\.}
- untested "s390* does not support hw read watchpoint"
+
+set supported 1
+gdb_test_multiple $test "" {
+ -re -wrap "Hardware read watchpoint \[0-9\]+: aligned.var4" {
+ pass $gdb_test_name
+ }
+ -re -wrap "Target does not support this type of hardware watchpoint\\." {
+ set supported 0
+ }
+}
+
+if { !$supported } {
+ unsupported $test
return
}
-gdb_test $test "Hardware read watchpoint \[0-9\]+: aligned.var4"
+
proc checkvar { address } {
global gdb_prompt
--
2.35.3

View File

@ -0,0 +1,19 @@
fixup-gdb-rhbz1553104-s390x-arch12-test.patch
---
gdb/testsuite/gdb.arch/s390x-arch12.exp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gdb/testsuite/gdb.arch/s390x-arch12.exp b/gdb/testsuite/gdb.arch/s390x-arch12.exp
index 4e902ff960d..246c1e1c69a 100644
--- a/gdb/testsuite/gdb.arch/s390x-arch12.exp
+++ b/gdb/testsuite/gdb.arch/s390x-arch12.exp
@@ -20,7 +20,7 @@
set testfile "s390x-arch12"
set uufile "${srcdir}/${subdir}/${testfile}.o.uu"
-set ofile "${srcdir}/${subdir}/${testfile}.o"
+set ofile [standard_output_file ${testfile}.o]
if { [catch "system \"uudecode -o ${ofile} ${uufile}\"" ] != 0 } {
untested "failed uudecode"

View File

@ -0,0 +1,38 @@
fixup-gdb-test-bt-cfi-without-die.patch
---
gdb/testsuite/gdb.base/cfi-without-die.exp | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/gdb/testsuite/gdb.base/cfi-without-die.exp b/gdb/testsuite/gdb.base/cfi-without-die.exp
index 5880d46f6d2..db1726646f8 100644
--- a/gdb/testsuite/gdb.base/cfi-without-die.exp
+++ b/gdb/testsuite/gdb.base/cfi-without-die.exp
@@ -37,19 +37,22 @@ if ![runto callback] then {
fail "verify unwinding: Can't run to callback"
return 0
}
-set test "verify unwinding breaks without CFI"
-gdb_test_multiple "bt" $test {
+
+set as_expected 1
+gdb_test_multiple "bt" "" {
-re " in \[?\]\[?\] .*\r\n$gdb_prompt $" {
# It may backtrace through some random frames even to main().
- pass $test
}
-re " in main .*\r\n$gdb_prompt $" {
- fail $test
+ set as_expected 0
}
-re "\r\n$gdb_prompt $" {
- pass $test
}
}
+if { ! $as_expected } {
+ untested ${testfile}.exp
+ return -1
+}
if { [gdb_compile "${srcdir}/${subdir}/${srccallerfile}" ${objcallerfile} \
object [list {additional_flags=-fomit-frame-pointer -funwind-tables -fasynchronous-unwind-tables}]] != ""

View File

@ -0,0 +1,21 @@
From 81a7585502092b3c133534ac6ecb34fd56d05337 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Thu, 16 Feb 2023 12:56:41 +0100
Subject: [PATCH 09/11] fixup gdb-test-dw2-aranges.patch
---
gdb/testsuite/gdb.dwarf2/dw2-aranges.S | 1 +
1 file changed, 1 insertion(+)
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.S b/gdb/testsuite/gdb.dwarf2/dw2-aranges.S
index d5b9ca5a3c6..b811f6644cb 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-aranges.S
+++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.S
@@ -138,3 +138,4 @@ main:
.byte 0 /* aranges segment_size */
.Laranges_end:
+ .section .note.GNU-stack,"",@progbits
--
2.35.3

BIN
gdb-13.2.tar.bz2 (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,120 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.3-attach-see-vdso-test.patch
;; Test kernel VDSO decoding while attaching to an i386 process.
;;=fedoratest
diff --git a/gdb/testsuite/gdb.base/attach-see-vdso.c b/gdb/testsuite/gdb.base/attach-see-vdso.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/attach-see-vdso.c
@@ -0,0 +1,25 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2007 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include <unistd.h>
+
+int main ()
+{
+ pause ();
+ return 1;
+}
diff --git a/gdb/testsuite/gdb.base/attach-see-vdso.exp b/gdb/testsuite/gdb.base/attach-see-vdso.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/attach-see-vdso.exp
@@ -0,0 +1,77 @@
+# Copyright 2007
+
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
+
+# This test only works on Linux
+if { ![istarget "*-*-linux-gnu*"] } {
+ return 0
+}
+
+if {[use_gdb_stub]} {
+ untested "skipping test because of use_gdb_stub"
+ return -1
+}
+
+set testfile "attach-see-vdso"
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+set escapedbinfile [string_to_regexp [standard_output_file ${testfile}]]
+
+# The kernel VDSO is used for the syscalls returns only on i386 (not x86_64).
+#
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-m32}] != "" } {
+ gdb_suppress_entire_file "Testcase nonthraded compile failed, so all tests in this file will automatically fail."
+}
+
+if [get_compiler_info ${binfile}] {
+ return -1
+}
+
+# Start the program running and then wait for a bit, to be sure
+# that it can be attached to.
+
+set testpid [eval exec $binfile &]
+
+# Avoid some race:
+sleep 2
+
+# Start with clean gdb
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+# Never call: gdb_load ${binfile}
+# as the former problem would not reproduce otherwise.
+
+set test "attach"
+gdb_test_multiple "attach $testpid" "$test" {
+ -re "Attaching to process $testpid\r?\n.*$gdb_prompt $" {
+ pass "$test"
+ }
+}
+
+gdb_test "bt" "#0 *0x\[0-9a-f\]* in \[^?\].*" "backtrace decodes VDSO"
+
+# Exit and detach the process.
+
+gdb_exit
+
+# Make sure we don't leave a process around to confuse
+# the next test run (and prevent the compile by keeping
+# the text file busy), in case the "set should_exit" didn't
+# work.
+
+remote_exec build "kill -9 ${testpid}"

View File

@ -0,0 +1,109 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.3-bz202689-exec-from-pthread-test.patch
;; Testcase for exec() from threaded program (BZ 202689).
;;=fedoratest
2007-01-17 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.threads/threaded-exec.exp, gdb.threads/threaded-exec.c: New files.
diff --git a/gdb/testsuite/gdb.threads/threaded-exec.c b/gdb/testsuite/gdb.threads/threaded-exec.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/threaded-exec.c
@@ -0,0 +1,46 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2007 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <stddef.h>
+#include <pthread.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void *
+threader (void *arg)
+{
+ return NULL;
+}
+
+int
+main (void)
+{
+ pthread_t t1;
+ int i;
+
+ i = pthread_create (&t1, NULL, threader, (void *) NULL);
+ assert (i == 0);
+ i = pthread_join (t1, NULL);
+ assert (i == 0);
+
+ execl ("/bin/true", "/bin/true", NULL);
+ abort ();
+}
diff --git a/gdb/testsuite/gdb.threads/threaded-exec.exp b/gdb/testsuite/gdb.threads/threaded-exec.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/threaded-exec.exp
@@ -0,0 +1,41 @@
+# threaded-exec.exp -- Check reset of the tracked threads on exec*(2)
+# Copyright (C) 2007 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+set testfile threaded-exec
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_load ${binfile}
+
+gdb_run_cmd
+
+gdb_test_multiple {} "Program exited" {
+ -re "\r\n\\\[Inferior .* exited normally\\\]\r\n$gdb_prompt $" {
+ pass "Program exited"
+ }
+}

View File

@ -0,0 +1,258 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Andrew Cagney <cagney@gnu.org>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.3-gstack-20050411.patch
;; Add a wrapper script to GDB that implements pstack using the
;; --readnever option.
;;=push
2004-11-23 Andrew Cagney <cagney@redhat.com>
* Makefile.in (uninstall-gstack, install-gstack): New rules, add
to install and uninstall.
* gstack.sh, gstack.1: New files.
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -2011,7 +2011,7 @@ info install-info clean-info dvi pdf install-pdf html install-html: force
install: all
@$(MAKE) $(FLAGS_TO_PASS) install-only
-install-only: $(CONFIG_INSTALL)
+install-only: install-gstack $(CONFIG_INSTALL)
transformed_name=`t='$(program_transform_name)'; \
echo gdb | sed -e "$$t"` ; \
if test "x$$transformed_name" = x; then \
@@ -2061,7 +2061,25 @@ install-guile:
install-python:
$(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(GDB_DATADIR)/python/gdb
-uninstall: force $(CONFIG_UNINSTALL)
+GSTACK=gstack
+.PHONY: install-gstack
+install-gstack:
+ transformed_name=`t='$(program_transform_name)'; \
+ echo $(GSTACK) | sed -e "$$t"` ; \
+ if test "x$$transformed_name" = x; then \
+ transformed_name=$(GSTACK) ; \
+ else \
+ true ; \
+ fi ; \
+ $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(bindir) ; \
+ $(INSTALL_PROGRAM) $(srcdir)/$(GSTACK).sh \
+ $(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT) ; \
+ : $(SHELL) $(srcdir)/../mkinstalldirs \
+ $(DESTDIR)$(man1dir) ; \
+ : $(INSTALL_DATA) $(srcdir)/gstack.1 \
+ $(DESTDIR)$(man1dir)/$$transformed_name.1
+
+uninstall: force uninstall-gstack $(CONFIG_UNINSTALL)
transformed_name=`t='$(program_transform_name)'; \
echo gdb | sed -e $$t` ; \
if test "x$$transformed_name" = x; then \
@@ -2092,6 +2110,18 @@ uninstall: force $(CONFIG_UNINSTALL)
rm -f $(DESTDIR)$(bindir)/$$transformed_name
@$(MAKE) DO=uninstall "DODIRS=$(SUBDIRS)" $(FLAGS_TO_PASS) subdir_do
+.PHONY: uninstall-gstack
+uninstall-gstack:
+ transformed_name=`t='$(program_transform_name)'; \
+ echo $(GSTACK) | sed -e $$t` ; \
+ if test "x$$transformed_name" = x; then \
+ transformed_name=$(GSTACK) ; \
+ else \
+ true ; \
+ fi ; \
+ rm -f $(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT) \
+ $(DESTDIR)$(man1dir)/$$transformed_name.1
+
# The C++ name parser can be built standalone for testing.
test-cp-name-parser.o: cp-name-parser.c
$(COMPILE) -DTEST_CPNAMES cp-name-parser.c
diff --git a/gdb/gstack.sh b/gdb/gstack.sh
new file mode 100644
--- /dev/null
+++ b/gdb/gstack.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+if test $# -ne 1; then
+ echo "Usage: `basename $0 .sh` <process-id>" 1>&2
+ exit 1
+fi
+
+if test ! -r /proc/$1; then
+ echo "Process $1 not found." 1>&2
+ exit 1
+fi
+
+# GDB doesn't allow "thread apply all bt" when the process isn't
+# threaded; need to peek at the process to determine if that or the
+# simpler "bt" should be used.
+
+backtrace="bt"
+if test -d /proc/$1/task ; then
+ # Newer kernel; has a task/ directory.
+ if test `/bin/ls /proc/$1/task | /usr/bin/wc -l` -gt 1 2>/dev/null ; then
+ backtrace="thread apply all bt"
+ fi
+elif test -f /proc/$1/maps ; then
+ # Older kernel; go by it loading libpthread.
+ if /bin/grep -e libpthread /proc/$1/maps > /dev/null 2>&1 ; then
+ backtrace="thread apply all bt"
+ fi
+fi
+
+GDB=${GDB:-gdb}
+
+# Run GDB, strip out unwanted noise.
+# --readnever is no longer used since .gdb_index is now in use.
+$GDB --quiet -nx $GDBARGS /proc/$1/exe $1 <<EOF 2>&1 |
+set width 0
+set height 0
+set pagination no
+$backtrace
+EOF
+/bin/sed -n \
+ -e 's/^\((gdb) \)*//' \
+ -e '/^#/p' \
+ -e '/^Thread/p'
diff --git a/gdb/testsuite/gdb.base/gstack.c b/gdb/testsuite/gdb.base/gstack.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gstack.c
@@ -0,0 +1,43 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2005, 2007, 2008, 2009 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 <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+void
+func (void)
+{
+ const char msg[] = "looping\n";
+
+ /* Use the most simple notification not to get caught by attach on exiting
+ the function. */
+ write (1, msg, strlen (msg));
+
+ for (;;);
+}
+
+int
+main (void)
+{
+ alarm (60);
+ nice (100);
+
+ func ();
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/gstack.exp b/gdb/testsuite/gdb.base/gstack.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gstack.exp
@@ -0,0 +1,84 @@
+# Copyright (C) 2012 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 testfile gstack
+set executable ${testfile}
+set binfile [standard_output_file $executable]
+if {[build_executable ${testfile} ${executable} "" {debug}] == -1} {
+ return -1
+}
+
+set test "spawn inferior"
+set command "${binfile}"
+set res [remote_spawn host $command];
+if { $res < 0 || $res == "" } {
+ perror "Spawning $command failed."
+ fail $test
+ return
+}
+
+# The spawn id of the test inferior.
+set test_spawn_id $res
+
+set use_gdb_stub 1
+set pid [exp_pid -i $res]
+gdb_expect {
+ -re "looping\r\n" {
+ pass $test
+ }
+ eof {
+ fail "$test (eof)"
+ return
+ }
+ timeout {
+ fail "$test (timeout)"
+ return
+ }
+}
+
+# Testcase uses the most simple notification not to get caught by attach on
+# exiting the function. Still we could retry the gstack command if we fail.
+
+set test "spawn gstack"
+set command "sh -c GDB=$GDB\\ GDBARGS=-data-directory\\\\\\ $BUILD_DATA_DIRECTORY\\ sh\\ ${srcdir}/../gstack.sh\\ $pid\\;echo\\ GSTACK-END"
+set res [remote_spawn host $command];
+if { $res < 0 || $res == "" } {
+ perror "Spawning $command failed."
+ fail $test
+}
+
+set gdb_spawn_id $res
+
+gdb_test_multiple "" $test {
+ -re "^#0 +(0x\[0-9a-f\]+ in )?\\.?func \\(\\) at \[^\r\n\]*\r\n#1 +0x\[0-9a-f\]+ in \\.?main \\(\\) at \[^\r\n\]*\r\nGSTACK-END\r\n\$" {
+ pass $test
+ }
+}
+
+gdb_test_multiple "" "gstack exits" {
+ eof {
+ set result [wait -i $gdb_spawn_id]
+ verbose $result
+
+ gdb_assert { [lindex $result 2] == 0 } "gstack exits with no error"
+ gdb_assert { [lindex $result 3] == 0 } "gstack's exit status is 0"
+
+ remote_close host
+ clear_gdb_spawn_id
+ }
+}
+
+# Kill the test inferior.
+kill_wait_spawned_process $test_spawn_id

View File

@ -0,0 +1,247 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.3-mapping-zero-inode-test.patch
;; Test GCORE for shmid 0 shared memory mappings.
;;=fedoratest: But it is broken anyway, sometimes the case being tested is not reproducible.
diff --git a/gdb/testsuite/gdb.base/gcore-shmid0.c b/gdb/testsuite/gdb.base/gcore-shmid0.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gcore-shmid0.c
@@ -0,0 +1,128 @@
+/* Copyright 2007, 2009 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * Test GDB's handling of gcore for mapping with a name but zero inode.
+ */
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <assert.h>
+#include <time.h>
+
+/* The same test running in a parallel testsuite may steal us the zero SID,
+ even if we never get any EEXIST. Just try a while. */
+
+#define TIMEOUT_SEC 10
+
+static volatile int v;
+
+static void
+initialized (void)
+{
+ v++;
+}
+
+static void
+unresolved (void)
+{
+ v++;
+}
+
+int
+main (void)
+{
+ int sid;
+ unsigned int *addr = (void *) -1L;
+ int attempt, round = 0;
+ time_t ts_start, ts;
+
+ if (time (&ts_start) == (time_t) -1)
+ {
+ printf ("time (): %m\n");
+ exit (1);
+ }
+
+ /* The generated SID will cycle with an increment of 32768, attempt until it
+ * wraps to 0. */
+
+ for (attempt = 0; addr == (void *) -1L; attempt++)
+ {
+ /* kernel-2.6.25-8.fc9.x86_64 just never returns the value 0 by
+ shmget(2). shmget returns SID range 0..1<<31 in steps of 32768,
+ 0x1000 should be enough but wrap the range it to be sure. */
+
+ if (attempt > 0x21000)
+ {
+ if (time (&ts) == (time_t) -1)
+ {
+ printf ("time (): %m\n");
+ exit (1);
+ }
+
+ if (ts >= ts_start && ts < ts_start + TIMEOUT_SEC)
+ {
+ attempt = 0;
+ round++;
+ continue;
+ }
+
+ printf ("Problem is not reproducible on this kernel (attempt %d, "
+ "round %d)\n", attempt, round);
+ unresolved ();
+ exit (1);
+ }
+
+ sid = shmget ((key_t) rand (), 0x1000, IPC_CREAT | IPC_EXCL | 0777);
+ if (sid == -1)
+ {
+ if (errno == EEXIST)
+ continue;
+
+ printf ("shmget (%d, 0x1000, IPC_CREAT): errno %d\n", 0, errno);
+ exit (1);
+ }
+
+ /* Use SID only if it is 0, retry it otherwise. */
+
+ if (sid == 0)
+ {
+ addr = shmat (sid, NULL, SHM_RND);
+ if (addr == (void *) -1L)
+ {
+ printf ("shmat (%d, NULL, SHM_RND): errno %d\n", sid,
+ errno);
+ exit (1);
+ }
+ }
+ if (shmctl (sid, IPC_RMID, NULL) != 0)
+ {
+ printf ("shmctl (%d, IPC_RMID, NULL): errno %d\n", sid, errno);
+ exit (1);
+ }
+ }
+
+ initialized ();
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/gcore-shmid0.exp b/gdb/testsuite/gdb.base/gcore-shmid0.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gcore-shmid0.exp
@@ -0,0 +1,101 @@
+# Copyright 2007, 2009 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Test GDB's handling of gcore for mapping with a name but zero inode.
+
+if { [prepare_for_testing gcore-shmid0.exp gcore-shmid0] } {
+ return -1
+}
+
+# Does this gdb support gcore?
+set test "help gcore"
+gdb_test_multiple $test $test {
+ -re "Undefined command: .gcore.*$gdb_prompt $" {
+ # gcore command not supported -- nothing to test here.
+ unsupported "gdb does not support gcore on this target"
+ return -1;
+ }
+ -re "Save a core file .*$gdb_prompt $" {
+ pass $test
+ }
+}
+
+if { ! [ runto_main ] } then {
+ untested gcore-shmid0.exp
+ return -1
+}
+
+gdb_breakpoint "initialized"
+gdb_breakpoint "unresolved"
+
+set oldtimeout $timeout
+set timeout [expr $oldtimeout + 120]
+
+set test "Continue to initialized."
+gdb_test_multiple "continue" $test {
+ -re "Breakpoint .*, initialized .* at .*\r\n$gdb_prompt $" {
+ pass $test
+ }
+ -re "Breakpoint .*, unresolved .* at .*\r\n$gdb_prompt $" {
+ set timeout $oldtimeout
+ unsupported $test
+ return -1
+ }
+}
+set timeout $oldtimeout
+
+set escapedfilename [string_to_regexp [standard_output_file gcore-shmid0.test]]
+
+set test "save a corefile"
+gdb_test_multiple "gcore [standard_output_file gcore-shmid0.test]" $test {
+ -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
+ pass $test
+ }
+ -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
+ unsupported $test
+ }
+}
+
+# Be sure to remove the handle first.
+# But it would get removed even on a kill by GDB as the handle is already
+# deleted, just it is still attached.
+gdb_continue_to_end "finish"
+
+set test "core-file command"
+gdb_test_multiple "core-file [standard_output_file gcore-shmid0.test]" $test {
+ -re ".* program is being debugged already.*y or n. $" {
+ # gdb_load may connect us to a gdbserver.
+ send_gdb "y\n"
+ exp_continue;
+ }
+ -re "Core was generated by .*\r\n\#0 .*\\\(\\\).*\r\n$gdb_prompt $" {
+ # The filename does not fit there anyway so do not check it.
+ pass $test
+ }
+ -re ".*registers from core file: File in wrong format.* $" {
+ fail "core-file command (could not read registers from core file)"
+ }
+}
+
+set test "backtrace"
+gdb_test_multiple "bt" $test {
+ -re "#0 *initialized \\\(\\\) at .*#1 .* main \\\(.*$gdb_prompt $" {
+ pass $test
+ }
+ -re "#0 *initialized \\\(\\\) at .*Cannot access memory at address .*$gdb_prompt $" {
+ fail $test
+ }
+}

View File

@ -0,0 +1,134 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.5-bz109921-DW_AT_decl_file-test.patch
;; Find symbols properly at their original (included) file (BZ 109921).
;;=fedoratest
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=109921
It is duplicite to its upstream variant:
http://sourceware.org/ml/gdb-cvs/2007-01/msg00157.html
http://sourceware.org/ml/gdb-patches/2007-01/msg00434.html
2007-01-21 Jan Kratochvil <jan.kratochvil@redhat.com>
Daniel Jacobowitz <dan@codesourcery.com>
* gdb.base/included.c, gdb.base/included.exp,
gdb.base/included.h: New files.
------------------------------------------------------------------------------
2007-01-09 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.dwarf2/dw2-included.exp, gdb.dwarf2/dw2-included.c,
gdb.dwarf2/dw2-included.h: New files.
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-included.c b/gdb/testsuite/gdb.dwarf2/dw2-included.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-included.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2006 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
+
+#include "dw2-included.h"
+
+int
+main()
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-included.exp b/gdb/testsuite/gdb.dwarf2/dw2-included.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-included.exp
@@ -0,0 +1,47 @@
+# Copyright 2006 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Minimal DWARF-2 unit test
+
+# This test can only be run on targets which support DWARF-2.
+# For now pick a sampling of likely targets.
+if {![istarget *-*-linux*]
+ && ![istarget *-*-gnu*]
+ && ![istarget *-*-elf*]
+ && ![istarget *-*-openbsd*]
+ && ![istarget arm-*-eabi*]
+ && ![istarget powerpc-*-eabi*]} {
+ return 0
+}
+
+set testfile "dw2-included"
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+gdb_test "set listsize 1" ""
+gdb_test "list integer" "int integer;\r"
+gdb_test "ptype integer" "type = int\r"
+# Path varies depending on the build location.
+gdb_test "info variables integer" "\r\nFile \[^\r\n\]*/gdb.dwarf2/dw2-included.h:\r\n${decimal}:.*int integer;\r"
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-included.h b/gdb/testsuite/gdb.dwarf2/dw2-included.h
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-included.h
@@ -0,0 +1,20 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2006 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
+
+int integer;

View File

@ -0,0 +1,264 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
;; Support TLS symbols (+`errno' suggestion if no pthread is found) (BZ 185337).
;;=push+jan: It should be replaced by Infinity project.
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337
2008-02-24 Jan Kratochvil <jan.kratochvil@redhat.com>
Port to GDB-6.8pre.
currently for trivial nonthreaded helloworld with no debug info up to -ggdb2 you
will get:
(gdb) p errno
[some error]
* with -ggdb2 and less "errno" in fact does not exist anywhere as it was
compiled to "(*__errno_location ())" and the macro definition is not present.
Unfortunately gdb will find the TLS symbol and it will try to access it but
as the program has been compiled without -lpthread the TLS base register
(%gs on i386) is not setup and it will result in:
Cannot access memory at address 0x8
Attached suggestion patch how to deal with the most common "errno" symbol
for the most common under-ggdb3 compiled programs.
Original patch hooked into target_translate_tls_address. But its inferior
call invalidates `struct frame *' in the callers - RH BZ 690908.
https://bugzilla.redhat.com/show_bug.cgi?id=1166549
2007-11-03 Jan Kratochvil <jan.kratochvil@redhat.com>
* ./gdb/dwarf2read.c (read_partial_die, dwarf2_linkage_name): Prefer
DW_AT_MIPS_linkage_name over DW_AT_name now only for non-C.
glibc-debuginfo-2.7-2.x86_64: /usr/lib/debug/lib64/libc.so.6.debug:
<81a2> DW_AT_name : (indirect string, offset: 0x280e): __errno_location
<81a8> DW_AT_MIPS_linkage_name: (indirect string, offset: 0x2808): *__GI___errno_location
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1300,6 +1300,10 @@ process_print_command_args (const char *args, value_print_options *print_opts,
if (exp != nullptr && *exp)
{
+ /* '*((int *(*) (void)) __errno_location) ()' is incompatible with
+ function descriptors. */
+ if (target_has_execution () && strcmp (exp, "errno") == 0)
+ exp = "*(*(int *(*)(void)) __errno_location) ()";
/* VOIDPRINT is true to indicate that we do want to print a void
value, so invert it for parse_expression. */
expression_up expr = parse_expression (exp, nullptr, !voidprint);
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-errno.c b/gdb/testsuite/gdb.dwarf2/dw2-errno.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-errno.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2005, 2007 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/>.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+#include <errno.h>
+
+int main()
+{
+ errno = 42;
+
+ return 0; /* breakpoint */
+}
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-errno.exp b/gdb/testsuite/gdb.dwarf2/dw2-errno.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-errno.exp
@@ -0,0 +1,60 @@
+# Copyright 2007 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 testfile dw2-errno
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+
+proc prep {} {
+ global srcdir subdir binfile
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}
+
+ runto_main
+
+ gdb_breakpoint [gdb_get_line_number "breakpoint"]
+ gdb_continue_to_breakpoint "breakpoint"
+}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+}
+prep
+gdb_test "print errno" ".* = 42" "errno with macros=N threads=N"
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+}
+prep
+gdb_test "print errno" ".* = 42" "errno with macros=Y threads=N"
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
+ return -1
+}
+prep
+gdb_test "print errno" ".* = 42" "errno with macros=N threads=Y"
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
+ return -1
+}
+prep
+gdb_test "print errno" ".* = 42" "errno with macros=Y threads=Y"
+
+# TODO: Test the error on resolving ERRNO with only libc loaded.
+# Just how to find the current libc filename?
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-errno2.c b/gdb/testsuite/gdb.dwarf2/dw2-errno2.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-errno2.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2005, 2007 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/>.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+#include <errno.h>
+
+int main()
+{
+ errno = 42;
+
+ return 0; /* breakpoint */
+}
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-errno2.exp b/gdb/testsuite/gdb.dwarf2/dw2-errno2.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-errno2.exp
@@ -0,0 +1,71 @@
+# Copyright 2007 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 testfile dw2-errno2
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+
+proc prep { message {do_xfail 0} } { with_test_prefix $message {
+ global srcdir subdir binfile variant
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}${variant}
+
+ runto_main
+
+ gdb_breakpoint [gdb_get_line_number "breakpoint"]
+ gdb_continue_to_breakpoint "breakpoint"
+
+ gdb_test "gcore ${binfile}${variant}.core" "\r\nSaved corefile .*" "gcore $variant"
+
+ gdb_test "print errno" ".* = 42"
+
+ gdb_test "kill" ".*" "kill" {Kill the program being debugged\? \(y or n\) } "y"
+ gdb_test "core-file ${binfile}${variant}.core" "\r\nCore was generated by .*" "core-file"
+ if $do_xfail {
+ setup_xfail "*-*-*"
+ }
+ gdb_test "print (int) errno" ".* = 42" "print errno for core"
+}}
+
+set variant g2thrN
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}${variant}" executable "additional_flags=-g2"] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+}
+prep "macros=N threads=N" 1
+
+set variant g3thrN
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}${variant}" executable "additional_flags=-g3"] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+}
+prep "macros=Y threads=N" 1
+
+set variant g2thrY
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}${variant}" executable "additional_flags=-g2"] != "" } {
+ return -1
+}
+prep "macros=N threads=Y"
+
+set variant g3thrY
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}${variant}" executable "additional_flags=-g3"] != "" } {
+ return -1
+}
+prep "macros=Y threads=Y" 1
+
+# TODO: Test the error on resolving ERRNO with only libc loaded.
+# Just how to find the current libc filename?

View File

@ -0,0 +1,107 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.5-bz218379-ppc-solib-trampoline-test.patch
;; Test sideeffects of skipping ppc .so libs trampolines (BZ 218379).
;;=fedoratest
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=218379
diff --git a/gdb/testsuite/gdb.base/step-over-trampoline.c b/gdb/testsuite/gdb.base/step-over-trampoline.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/step-over-trampoline.c
@@ -0,0 +1,28 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2006 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+#include <stdio.h>
+
+int main (void)
+{
+ puts ("hello world");
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/step-over-trampoline.exp b/gdb/testsuite/gdb.base/step-over-trampoline.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/step-over-trampoline.exp
@@ -0,0 +1,59 @@
+# Copyright 2006 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+if {[use_gdb_stub]} {
+ untested "skipping test because of use_gdb_stub"
+ return -1
+}
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set testfile step-over-trampoline
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+}
+
+# Get things started.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+# For C programs, "start" should stop in main().
+
+gdb_test "start" \
+ "main \\(\\) at .*$srcfile.*" \
+ "start"
+
+# main () at hello2.c:5
+# 5 puts("hello world\n");
+# (gdb) next
+# 0x100007e0 in call___do_global_ctors_aux ()
+
+gdb_test_multiple "next" "invalid `next' output" {
+ -re "\nhello world.*return 0;.*" {
+ pass "stepped over"
+ }
+ -re " in call___do_global_ctors_aux \\(\\).*" {
+ fail "stepped into trampoline"
+ }
+}

View File

@ -0,0 +1,89 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.5-bz243845-stale-testing-zombie-test.patch
;; Test leftover zombie process (BZ 243845).
;;=fedoratest
diff --git a/gdb/testsuite/gdb.base/tracefork-zombie.exp b/gdb/testsuite/gdb.base/tracefork-zombie.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/tracefork-zombie.exp
@@ -0,0 +1,76 @@
+# Copyright 2007 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+# are we on a target board
+if {[use_gdb_stub]} {
+ untested "skipping test because of use_gdb_stub"
+ return -1
+}
+
+# Start the program running and then wait for a bit, to be sure
+# that it can be attached to.
+
+gdb_exit
+gdb_start
+gdb_load sleep
+
+set gdb_pid [exp_pid -i [board_info host fileid]]
+set test "identified the child GDB"
+if {$gdb_pid != "" && $gdb_pid > 0} {
+ pass $test
+ verbose -log "Child GDB PID $gdb_pid"
+} else {
+ fail $test
+}
+
+set testpid [eval exec sleep 10 &]
+exec sleep 2
+
+set test "attach"
+gdb_test_multiple "attach $testpid" "$test" {
+ -re "Attaching to program.*`?.*'?, process $testpid..*$gdb_prompt $" {
+ pass "$test"
+ }
+ -re "Attaching to program.*`?.*\.exe'?, process $testpid.*\[Switching to thread $testpid\..*\].*$gdb_prompt $" {
+ # Response expected on Cygwin
+ pass "$test"
+ }
+}
+
+# Some time to let GDB spawn its testing child.
+exec sleep 2
+
+set found none
+foreach procpid [glob -directory /proc -type d {[0-9]*}] {
+ if {[catch {open $procpid/status} statusfi]} {
+ continue
+ }
+ set status [read $statusfi]
+ close $statusfi
+ if {1
+ && [regexp -line {^Name:\tgdb$} $status]
+ && [regexp -line {^PPid:\t1$} $status]
+ && [regexp -line "^TracerPid:\t$gdb_pid$" $status]} {
+ set found $procpid
+ verbose -log "Found linux_test_for_tracefork zombie PID $procpid"
+ }
+}
+set test "linux_test_for_tracefork leaves no zombie"
+if {$found eq {none}} {
+ pass $test
+} else {
+ fail $test
+}

View File

@ -0,0 +1,154 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.5-gcore-buffer-limit-test.patch
;; Test gcore memory and time requirements for large inferiors.
;;=fedoratest
diff --git a/gdb/testsuite/gdb.base/gcore-excessive-memory.c b/gdb/testsuite/gdb.base/gcore-excessive-memory.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gcore-excessive-memory.c
@@ -0,0 +1,37 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2008 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+#include <unistd.h>
+#include <stdlib.h>
+
+#define MEGS 64
+
+int main()
+{
+ void *mem;
+
+ mem = malloc (MEGS * 1024ULL * 1024ULL);
+
+ for (;;)
+ sleep (1);
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/gcore-excessive-memory.exp b/gdb/testsuite/gdb.base/gcore-excessive-memory.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gcore-excessive-memory.exp
@@ -0,0 +1,99 @@
+# Copyright 2008 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+if {[use_gdb_stub]} {
+ untested "skipping test because of use_gdb_stub"
+ return -1
+}
+
+set testfile gcore-excessive-memory
+set srcfile ${testfile}.c
+set shfile [standard_output_file ${testfile}-gdb.sh]
+set corefile [standard_output_file ${testfile}.core]
+set binfile [standard_output_file ${testfile}]
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+}
+
+set f [open "|getconf PAGESIZE" "r"]
+gets $f pagesize
+close $f
+
+set pid_of_bin [eval exec $binfile &]
+sleep 2
+
+# Get things started.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+set pid_of_gdb [exp_pid -i [board_info host fileid]]
+
+gdb_test "attach $pid_of_bin" "Attaching to .*" "attach"
+gdb_test "up 99" "in main .*" "verify we can get to main"
+
+proc memory_v_pages_get {} {
+ global pid_of_gdb pagesize
+ set fd [open "/proc/$pid_of_gdb/statm"]
+ gets $fd line
+ close $fd
+ # number of pages of virtual memory
+ scan $line "%d" drs
+ return $drs
+}
+
+set pages_found [memory_v_pages_get]
+
+# It must be definitely less than `MEGS' of `gcore-excessive-memory.c'.
+set mb_gcore_reserve 4
+verbose -log "pages_found = $pages_found, mb_gcore_reserve = $mb_gcore_reserve"
+set kb_found [expr $pages_found * $pagesize / 1024]
+set kb_permit [expr $kb_found + 1 * 1024 + $mb_gcore_reserve * 1024]
+verbose -log "kb_found = $kb_found, kb_permit = $kb_permit"
+
+# Create the ulimit wrapper.
+set f [open $shfile "w"]
+puts $f "#! /bin/sh"
+puts $f "ulimit -v $kb_permit"
+puts $f "exec $GDB \"\$@\""
+close $f
+remote_exec host "chmod +x $shfile"
+
+gdb_exit
+set GDBold $GDB
+set GDB "$shfile"
+gdb_start
+set GDB $GDBold
+
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+set pid_of_gdb [exp_pid -i [board_info host fileid]]
+
+gdb_test "attach $pid_of_bin" "Attaching to .*" "attach"
+gdb_test "up 99" "in main .*" "verify we can get to main"
+
+verbose -log "kb_found before gcore = [expr [memory_v_pages_get] * $pagesize / 1024]"
+
+gdb_test "gcore $corefile" "Saved corefile \[^\n\r\]*" "Save the core file"
+
+verbose -log "kb_found after gcore = [expr [memory_v_pages_get] * $pagesize / 1024]"
+
+# Cleanup.
+exec kill -9 $pid_of_bin

View File

@ -0,0 +1,135 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.5-ia64-libunwind-leak-test.patch
;; Test ia64 memory leaks of the code using libunwind.
;;=fedoratest
diff --git a/gdb/testsuite/gdb.base/unwind-leak.c b/gdb/testsuite/gdb.base/unwind-leak.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/unwind-leak.c
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2007 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+#include <unistd.h>
+
+int main()
+{
+ for (;;)
+ alarm (0);
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/unwind-leak.exp b/gdb/testsuite/gdb.base/unwind-leak.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/unwind-leak.exp
@@ -0,0 +1,88 @@
+# Copyright 2007 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+if {[use_gdb_stub]} {
+ untested "skipping test because of use_gdb_stub"
+ return -1
+}
+
+set testfile unwind-leak
+set srcfile ${testfile}.c
+set shfile [standard_output_file ${testfile}-gdb.sh]
+set binfile [standard_output_file ${testfile}]
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+}
+
+# Get things started.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+set pid [exp_pid -i [board_info host fileid]]
+
+# For C programs, "start" should stop in main().
+
+gdb_test "start" \
+ "main \\(\\) at .*$srcfile.*" \
+ "start"
+
+set loc [gdb_get_line_number "alarm"]
+gdb_breakpoint $loc
+
+proc memory_get {} {
+ global pid
+ set fd [open "/proc/$pid/statm"]
+ gets $fd line
+ close $fd
+ # number of pages of data/stack
+ scan $line "%*d%*d%*d%*d%*d%d" drs
+ return $drs
+}
+
+set cycles 100
+# For 100 cycles it was 1308: from = 363 KB, to = 1671 KB
+set permit_kb 100
+verbose -log "cycles = $cycles, permit_kb = $permit_kb"
+
+set fail 0
+set test "breakpoint stop/continue cycles"
+for {set i $cycles} {$i > 0} {set i [expr {$i - 1}]} {
+ gdb_test_multiple "continue" $test {
+ -re "Breakpoint 2, main .*alarm .*.*${gdb_prompt} $" {
+ }
+ -re "Segmentation fault" {
+ fail $test
+ set i 0
+ set fail 1
+ }
+ }
+ if ![info exists from] {
+ set from [memory_get]
+ }
+}
+set to [memory_get]
+if {!$fail} {
+ verbose -log "from = $from KB, to = $to KB"
+ if {$from > 0 && $to > 10 && $to < $from + $permit_kb} {
+ pass $test
+ } else {
+ fail $test
+ }
+}

View File

@ -0,0 +1,62 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.5-last-address-space-byte-test.patch
;; Testcase for deadlocking on last address space byte; for corrupted backtraces.
;;=fedoratest
diff --git a/gdb/testsuite/gdb.base/largecore-last-address-lock.exp b/gdb/testsuite/gdb.base/largecore-last-address-lock.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/largecore-last-address-lock.exp
@@ -0,0 +1,49 @@
+# Copyright 2006 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+# Get things started.
+
+gdb_exit
+gdb_start
+
+# i386 (32-bit) only: gdb with Red Hat largecore patch did lock up:
+# https://enterprise.redhat.com/issue-tracker/?module=issues&action=view&tid=103263
+# https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=210614
+
+# i386: Bug exists when the `target_xfer_memory' condition
+# `(memaddr + len < region->hi)' operates on 64-bit operands on
+# largecore-patched with 32-bit addresses and so it can get `false' with
+# arbitrary `len'.
+
+# x86_64: The bug is not present as the operands and calculations have the same
+# bit size. Would would still need to pass there the highest address
+# (`memaddr == 0xffffffffffffffff') but we would need to pass `len == 0'
+# to make the condition `(memaddr + len < region->hi)' false.
+# `len == 0' would get caught eariler.
+
+# Error in the success case is immediate.
+set timeoutold ${timeout}
+set timeout 10
+
+gdb_test "x/xb 0xffffffff" \
+ "Cannot access memory at address 0xffffffff" \
+ "Read the last address space byte"
+
+set timeout ${timeoutold}

View File

@ -0,0 +1,95 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.5-missed-trap-on-step-test.patch
;; Test hiding unexpected breakpoints on intentional step commands.
;;=fedoratest
Fix has been committed to:
gdb-6.6-scheduler_locking-step-sw-watchpoints2.patch
diff --git a/gdb/testsuite/gdb.base/watchpoint-during-step.c b/gdb/testsuite/gdb.base/watchpoint-during-step.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/watchpoint-during-step.c
@@ -0,0 +1,30 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2007 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+static int var;
+
+int main()
+{
+ var = 1;
+ var = 2;
+ var = 3;
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/watchpoint-during-step.exp b/gdb/testsuite/gdb.base/watchpoint-during-step.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/watchpoint-during-step.exp
@@ -0,0 +1,44 @@
+# Copyright 2007 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+set testfile watchpoint-during-step
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+}
+
+# Get things started.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+runto_main
+
+gdb_breakpoint [gdb_get_line_number "var = 2"]
+gdb_continue_to_breakpoint "Find the first var set"
+
+gdb_test "step" ".*var = 3;" "Step to the next var set"
+
+gdb_test "watch var" "atchpoint .*: var" "Set the watchpoint"
+
+# Here is the target point. Be careful to not have breakpoint set on the line
+# we step from as in this case it is a valid upstream KFAIL gdb/38
+
+gdb_test "step" ".*Old value = 2.*New value = 3.*" "Catch the watchpoint"

View File

@ -0,0 +1,127 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.5-section-num-fixup-test.patch
;; Test a crash on libraries missing the .text section.
;;=fedoratest
diff --git a/gdb/testsuite/gdb.base/datalib-lib.c b/gdb/testsuite/gdb.base/datalib-lib.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/datalib-lib.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2008 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+int var;
diff --git a/gdb/testsuite/gdb.base/datalib-main.c b/gdb/testsuite/gdb.base/datalib-main.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/datalib-main.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2008 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+int
+main (void)
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/datalib.exp b/gdb/testsuite/gdb.base/datalib.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/datalib.exp
@@ -0,0 +1,56 @@
+# Copyright 2008 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+if {[use_gdb_stub]} {
+ untested "skipping test because of use_gdb_stub"
+ return -1
+}
+
+set testfile datalib
+set srcfilemain ${testfile}-main.c
+set srcfilelib ${testfile}-lib.c
+set libfile [standard_output_file ${testfile}-lib.so]
+set binfile [standard_output_file ${testfile}-main]
+if { [gdb_compile "${srcdir}/${subdir}/${srcfilelib}" "${libfile}" executable [list debug {additional_flags=-shared -nostdlib}]] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+}
+if { [gdb_compile "${srcdir}/${subdir}/${srcfilemain}" "${binfile} ${libfile}" executable {debug}] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+}
+
+# Get things started.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+# We must use a separate library as the main executable is compiled to the
+# address 0 by default and it would get fixed up already at the end of
+# INIT_OBJFILE_SECT_INDICES. We also cannot PRELINK it as PRELINK is missing
+# on ia64. The library must be NOSTDLIB as otherwise some stub code would
+# create the `.text' section there. Also DEBUG option is useful as some of
+# the crashes occur in dwarf2read.c.
+
+# FAIL case:
+# ../../gdb/ia64-tdep.c:2838: internal-error: sect_index_text not initialized
+# A problem internal to GDB has been detected,
+
+gdb_test "start" \
+ "main \\(\\) at .*${srcfilemain}.*" \
+ "start"

View File

@ -0,0 +1,193 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.5-sharedlibrary-path.patch
;; Fix TLS symbols resolving for shared libraries with a relative pathname.
;; The testsuite needs `gdb-6.5-tls-of-separate-debuginfo.patch'.
;;=fedoratest: One should recheck if it is really fixed upstream.
If you provided some relative path to the shared library, such as with
export LD_LIBRARY_PATH=.
then gdb would fail to match the shared library name during the TLS lookup.
Dropped the workaround/fix for gdb-6.8.50.20081128 - is it still needed?
The testsuite needs `gdb-6.3-bz146810-solib_absolute_prefix_is_empty.patch'.
The testsuite needs `gdb-6.5-tls-of-separate-debuginfo.patch'.
2006-09-01 Jan Kratochvil <jan.kratochvil@redhat.com>
* solib-svr4.c (svr4_fetch_objfile_link_map): Match even absolute
requested pathnames to the internal loaded relative pathnames.
2007-10-16 Jan Kratochvil <jan.kratochvil@redhat.com>
Port to GDB-6.7.
2008-02-27 Jan Kratochvil <jan.kratochvil@redhat.com>
Port to gdb-6.7.50.20080227.
diff --git a/gdb/testsuite/gdb.threads/tls-sepdebug-main.c b/gdb/testsuite/gdb.threads/tls-sepdebug-main.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/tls-sepdebug-main.c
@@ -0,0 +1,31 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2006 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+#include <pthread.h>
+
+extern __thread int var;
+
+int main()
+{
+ /* Ensure we link against pthreads even with --as-needed. */
+ pthread_testcancel();
+ return var;
+}
diff --git a/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c b/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2006 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@prep.ai.mit.edu */
+
+__thread int var = 42;
diff --git a/gdb/testsuite/gdb.threads/tls-sepdebug.exp b/gdb/testsuite/gdb.threads/tls-sepdebug.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/tls-sepdebug.exp
@@ -0,0 +1,94 @@
+# Copyright 2006 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# This test uses gdb_exit and gdb_start, which are not supported
+# on non-extended-remote sessions.
+if {[use_gdb_stub]} {
+ untested "skipping test because of stub"
+ return 0
+}
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set testfile tls-sepdebug
+set srcmainfile ${testfile}-main.c
+set srcsharedfile ${testfile}-shared.c
+
+set binmainfile [standard_output_file ${testfile}-main]
+set binsharedbase ${testfile}-shared.so
+set binsharedfile [standard_output_file ${binsharedbase}]
+set binshareddebugfile [standard_output_file ${binsharedbase}.debug]
+
+# Use explicit -soname as otherwise the full path to the library would get
+# encoded into ${binmainfile} making LD_LIBRARY_PATH tests useless.
+
+# FIXME: gcc dependency (-Wl,-soname).
+
+if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcsharedfile}" "${binsharedfile}" [list debug additional_flags=-Wl,-soname=${binsharedbase}]] != "" } {
+ untested "Couldn't compile test library"
+ return -1
+}
+
+# eu-strip(1) works fine but it is a part of `elfutils', not `binutils'.
+if 0 then {
+ remote_exec build "eu-strip -f ${binshareddebugfile} ${binsharedfile}"
+} else {
+ remote_exec build "objcopy --only-keep-debug ${binsharedfile} ${binshareddebugfile}"
+ remote_exec build "objcopy --strip-debug ${binsharedfile}"
+ remote_exec build "objcopy --add-gnu-debuglink=${binshareddebugfile} ${binsharedfile}"
+}
+
+# Do not use `shlib=' as it will automatically add also -rpath for gcc.
+
+if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcmainfile} ${binsharedfile}" "${binmainfile}" executable {debug}] != "" } {
+ untested "Couldn't compile test program"
+ return -1
+}
+
+# Get things started.
+
+# Test also the proper resolving of relative library names to absolute ones.
+# \$PWD is easy - it is the absolute way
+# ${subdir} would fail on "print var"
+
+set absdir [file dirname [standard_output_file ${binsharedbase}]]
+foreach ld_library_path [list $absdir [relative_filename [pwd] $absdir]] name { absolute relative } {
+
+ gdb_exit
+ gdb_start
+ ###gdb_reinitialize_dir $srcdir/$subdir
+
+ gdb_test "set env LD_LIBRARY_PATH=$ld_library_path" \
+ "" \
+ "set env LD_LIBRARY_PATH is $name"
+
+ gdb_load ${binmainfile}
+
+ # For C programs, "start" should stop in main().
+
+ gdb_test "start" \
+ "main \\(\\) at .*${srcmainfile}.*" \
+ "start"
+
+ # Check for: Cannot find shared library `/usr/lib/debug/lib/libc-2.4.90.so.debug' in dynamic linker's load module list
+ # as happens with TLS variables and `separate_debug_objfile_backlink'.
+
+ gdb_test "print var" \
+ "\\\$1 = \[0-9\].*" \
+ "print TLS variable from a shared library with $name-directory separate debug info file"
+}

View File

@ -0,0 +1,19 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.6-buildid-locate-rpm-librpm-workaround.patch
;; Workaround librpm BZ 643031 due to its unexpected exit() calls (BZ 642879).
;;=push+jan
diff --git a/gdb/proc-service.list b/gdb/proc-service.list
--- a/gdb/proc-service.list
+++ b/gdb/proc-service.list
@@ -37,4 +37,7 @@
ps_pstop;
ps_ptread;
ps_ptwrite;
+
+ /* gdb-6.6-buildid-locate-rpm.patch */
+ rpmsqEnable;
};

View File

@ -0,0 +1,136 @@
From 444f438fe775a9480b93dc7d63418e0e169b4fbd Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Fri, 21 Apr 2023 09:08:03 +0200
Subject: [PATCH 1/5] gdb-6.6-buildid-locate-rpm-suse.patch
---
gdb/build-id.c | 71 +++++++++-----------------------------------------
1 file changed, 13 insertions(+), 58 deletions(-)
diff --git a/gdb/build-id.c b/gdb/build-id.c
index 86dfc8409b5..29aa10d8225 100644
--- a/gdb/build-id.c
+++ b/gdb/build-id.c
@@ -863,10 +863,8 @@ missing_rpm_enlist_1 (const char *filename, int verify_vendor)
#endif
{
Header h;
- char *debuginfo, **slot, *s, *s2;
+ char *debuginfo, **slot;
errmsg_t err;
- size_t srcrpmlen = sizeof (".src.rpm") - 1;
- size_t debuginfolen = sizeof ("-debuginfo") - 1;
rpmdbMatchIterator mi_debuginfo;
h = rpmdbNextIterator_p (mi);
@@ -875,7 +873,9 @@ missing_rpm_enlist_1 (const char *filename, int verify_vendor)
/* Verify the debuginfo file is not already installed. */
- debuginfo = headerFormat_p (h, "%{sourcerpm}-debuginfo.%{arch}",
+ /* The allocated memory gets utilized below for MISSING_RPM_HASH. */
+ debuginfo = headerFormat_p (h,
+ "%{name}-debuginfo-%{version}-%{release}.%{arch}",
&err);
if (!debuginfo)
{
@@ -883,60 +883,19 @@ missing_rpm_enlist_1 (const char *filename, int verify_vendor)
err);
continue;
}
- /* s = `.src.rpm-debuginfo.%{arch}' */
- s = strrchr (debuginfo, '-') - srcrpmlen;
- s2 = NULL;
- if (s > debuginfo && memcmp (s, ".src.rpm", srcrpmlen) == 0)
- {
- /* s2 = `-%{release}.src.rpm-debuginfo.%{arch}' */
- s2 = (char *) memrchr (debuginfo, '-', s - debuginfo);
- }
- if (s2)
- {
- /* s2 = `-%{version}-%{release}.src.rpm-debuginfo.%{arch}' */
- s2 = (char *) memrchr (debuginfo, '-', s2 - debuginfo);
- }
- if (!s2)
- {
- warning (_("Error querying the rpm file `%s': %s"), filename,
- debuginfo);
- xfree (debuginfo);
- continue;
- }
- /* s = `.src.rpm-debuginfo.%{arch}' */
- /* s2 = `-%{version}-%{release}.src.rpm-debuginfo.%{arch}' */
- memmove (s2 + debuginfolen, s2, s - s2);
- memcpy (s2, "-debuginfo", debuginfolen);
- /* s = `XXXX.%{arch}' */
- /* strlen ("XXXX") == srcrpmlen + debuginfolen */
- /* s2 = `-debuginfo-%{version}-%{release}XX.%{arch}' */
- /* strlen ("XX") == srcrpmlen */
- memmove (s + debuginfolen, s + srcrpmlen + debuginfolen,
- strlen (s + srcrpmlen + debuginfolen) + 1);
- /* s = `-debuginfo-%{version}-%{release}.%{arch}' */
+ /* Verify the debuginfo file is not already installed. */
/* RPMDBI_PACKAGES requires keylen == sizeof (int). */
/* RPMDBI_LABEL is an interface for NVR-based dbiFindByLabel(). */
mi_debuginfo = rpmtsInitIterator_p (ts, (rpmDbiTagVal) RPMDBI_LABEL, debuginfo, 0);
- xfree (debuginfo);
if (mi_debuginfo)
{
+ xfree (debuginfo);
rpmdbFreeIterator_p (mi_debuginfo);
count = 0;
break;
}
- /* The allocated memory gets utilized below for MISSING_RPM_HASH. */
- debuginfo = headerFormat_p (h,
- "%{name}-%{version}-%{release}.%{arch}",
- &err);
- if (!debuginfo)
- {
- warning (_("Error querying the rpm file `%s': %s"), filename,
- err);
- continue;
- }
-
/* Base package name for `debuginfo-install'. We do not use the
`yum' command directly as the line
yum --enablerepo='*debug*' install NAME-debuginfo.ARCH
@@ -1085,10 +1044,7 @@ missing_rpm_list_print (void)
missing_rpm_list_entries = 0;
gdb_printf (_("Missing separate debuginfos, use: %s"),
-#ifdef DNF_DEBUGINFO_INSTALL
- "dnf "
-#endif
- "debuginfo-install");
+ "zypper install");
for (const char *el : array)
{
gdb_printf (" %s", el);
@@ -1295,13 +1251,12 @@ debug_print_missing (const char *binary, const char *debug)
gdb_printf (gdb_stdlog,
_("Missing separate debuginfo for %s\n"), binary);
if (debug != NULL)
- gdb_printf (gdb_stdlog, _("Try: %s %s\n"),
-#ifdef DNF_DEBUGINFO_INSTALL
- "dnf"
-#else
- "yum"
-#endif
- " --enablerepo='*debug*' install", debug);
+ {
+ const char *p = strrchr (debug, '/');
+ gdb_printf (gdb_stdlog, _("Try: %s%.2s%.38s\"\n"),
+ "zypper install -C \"debuginfo(build-id)=",
+ p - 2, p + 1);
+ }
}
}
base-commit: 91ac179279557e27e6a149cbb78e4052a348f109
--
2.35.3

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,238 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.6-buildid-locate-solib-missing-ids.patch
;; Fix loading of core files without build-ids but with build-ids in executables.
;; Load strictly build-id-checked core files only if no executable is specified
;; (Jan Kratochvil, RH BZ 1339862).
;;=push+jan
gdb returns an incorrect back trace when applying a debuginfo
https://bugzilla.redhat.com/show_bug.cgi?id=1339862
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1321,14 +1321,28 @@ svr4_read_so_list (svr4_info *info, CORE_ADDR lm, CORE_ADDR prev_lm,
}
{
- struct bfd_build_id *build_id;
+ struct bfd_build_id *build_id = NULL;
strncpy (newobj->so_original_name, buffer.get (), SO_NAME_MAX_PATH_SIZE - 1);
newobj->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
/* May get overwritten below. */
strcpy (newobj->so_name, newobj->so_original_name);
- build_id = build_id_addr_get (((lm_info_svr4 *) newobj->lm_info)->l_ld);
+ /* In the case the main executable was found according to its build-id
+ (from a core file) prevent loading a different build of a library
+ with accidentally the same SO_NAME.
+
+ It suppresses bogus backtraces (and prints "??" there instead) if
+ the on-disk files no longer match the running program version.
+
+ If the main executable was not loaded according to its build-id do
+ not do any build-id checking of the libraries. There may be missing
+ build-ids dumped in the core file and we would map all the libraries
+ to the only existing file loaded that time - the executable. */
+ if (current_program_space->symfile_object_file != NULL
+ && (current_program_space->symfile_object_file->flags
+ & OBJF_BUILD_ID_CORE_LOADED) != 0)
+ build_id = build_id_addr_get (li->l_ld);
if (build_id != NULL)
{
char *name, *build_id_filename;
@@ -1343,23 +1357,7 @@ svr4_read_so_list (svr4_info *info, CORE_ADDR lm, CORE_ADDR prev_lm,
xfree (name);
}
else
- {
- debug_print_missing (newobj->so_name, build_id_filename);
-
- /* In the case the main executable was found according to
- its build-id (from a core file) prevent loading
- a different build of a library with accidentally the
- same SO_NAME.
-
- It suppresses bogus backtraces (and prints "??" there
- instead) if the on-disk files no longer match the
- running program version. */
-
- if (current_program_space->symfile_object_file != NULL
- && (current_program_space->symfile_object_file->flags
- & OBJF_BUILD_ID_CORE_LOADED) != 0)
- newobj->so_name[0] = 0;
- }
+ debug_print_missing (newobj->so_name, build_id_filename);
xfree (build_id_filename);
xfree (build_id);
diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c
@@ -0,0 +1,21 @@
+/* Copyright 2010 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/>. */
+
+void
+lib (void)
+{
+}
diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c
@@ -0,0 +1,25 @@
+/* Copyright 2010 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/>. */
+
+extern void lib (void);
+
+int
+main (void)
+{
+ lib ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp
@@ -0,0 +1,105 @@
+# Copyright 2016 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/>.
+
+if {[skip_shlib_tests]} {
+ return 0
+}
+
+set testfile "gcore-buildid-exec-but-not-solib"
+set srcmainfile ${testfile}-main.c
+set srclibfile ${testfile}-lib.c
+set libfile [standard_output_file ${testfile}-lib.so]
+set objfile [standard_output_file ${testfile}-main.o]
+set executable ${testfile}-main
+set binfile [standard_output_file ${executable}]
+set gcorefile [standard_output_file ${executable}.gcore]
+set outdir [file dirname $binfile]
+
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${srclibfile} ${libfile} "debug additional_flags=-Wl,--build-id"] != ""
+ || [gdb_compile ${srcdir}/${subdir}/${srcmainfile} ${objfile} object {debug}] != "" } {
+ unsupported "-Wl,--build-id compilation failed"
+ return -1
+}
+set opts [list debug shlib=${libfile} "additional_flags=-Wl,--build-id"]
+if { [gdb_compile ${objfile} ${binfile} executable $opts] != "" } {
+ unsupported "-Wl,--build-id compilation failed"
+ return -1
+}
+
+clean_restart $executable
+gdb_load_shlib $libfile
+
+# Does this gdb support gcore?
+set test "help gcore"
+gdb_test_multiple $test $test {
+ -re "Undefined command: .gcore.*\r\n$gdb_prompt $" {
+ # gcore command not supported -- nothing to test here.
+ unsupported "gdb does not support gcore on this target"
+ return -1;
+ }
+ -re "Save a core file .*\r\n$gdb_prompt $" {
+ pass $test
+ }
+}
+
+if { ![runto lib] } then {
+ return -1
+}
+
+set escapedfilename [string_to_regexp ${gcorefile}]
+
+set test "save a corefile"
+gdb_test_multiple "gcore ${gcorefile}" $test {
+ -re "Saved corefile ${escapedfilename}\r\n$gdb_prompt $" {
+ pass $test
+ }
+ -re "Can't create a corefile\r\n$gdb_prompt $" {
+ unsupported $test
+ return -1
+ }
+}
+
+# Now restart gdb and load the corefile.
+
+clean_restart $executable
+gdb_load_shlib $libfile
+
+set buildid [build_id_debug_filename_get $libfile]
+
+regsub {\.debug$} $buildid {} buildid
+
+set debugdir [standard_output_file ${testfile}-debugdir]
+file delete -force -- $debugdir
+
+file mkdir $debugdir/[file dirname $libfile]
+file copy $libfile $debugdir/${libfile}
+
+file mkdir $debugdir/[file dirname $buildid]
+file copy $libfile $debugdir/${buildid}
+
+remote_exec build "ln -s /lib ${debugdir}/"
+remote_exec build "ln -s /lib64 ${debugdir}/"
+# /usr is not needed, all the libs are in /lib64: libm.so.6 libc.so.6 ld-linux-x86-64.so.2
+
+gdb_test "set solib-absolute-prefix $debugdir"
+
+gdb_test_no_output "set debug-file-directory $debugdir" "set debug-file-directory"
+
+gdb_test "core ${gcorefile}" "Core was generated by .*" "re-load generated corefile"
+
+gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
+
+gdb_test "bt"
+gdb_test "info shared"

1915
gdb-6.6-buildid-locate.patch Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,188 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.6-bz229517-gcore-without-terminal.patch
;; Allow running `/usr/bin/gcore' with provided but inaccessible tty (BZ 229517).
;;=fedoratest
2007-04-22 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb_gcore.sh: Redirect GDB from `</dev/null'.
2007-04-22 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.base/gcorebg.exp, gdb.base/gcorebg.c: New files.
diff --git a/gdb/testsuite/gdb.base/gcorebg.c b/gdb/testsuite/gdb.base/gcorebg.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gcorebg.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <assert.h>
+
+int main (int argc, char **argv)
+{
+ pid_t pid = 0;
+ pid_t ppid;
+ char buf[1024*2 + 500];
+ int gotint;
+
+ if (argc != 4)
+ {
+ fprintf (stderr, "Syntax: %s {standard|detached} <gcore command> <core output file>\n",
+ argv[0]);
+ exit (1);
+ }
+
+ pid = fork ();
+
+ switch (pid)
+ {
+ case 0:
+ if (strcmp (argv[1], "detached") == 0)
+ setpgrp ();
+ ppid = getppid ();
+ gotint = snprintf (buf, sizeof (buf), "sh %s -o %s %d", argv[2], argv[3], (int) ppid);
+ assert (gotint < sizeof (buf));
+ system (buf);
+ fprintf (stderr, "Killing parent PID %d\n", ppid);
+ kill (ppid, SIGTERM);
+ break;
+
+ case -1:
+ perror ("fork err\n");
+ exit (1);
+ break;
+
+ default:
+ fprintf (stderr,"Sleeping as PID %d\n", getpid ());
+ sleep (60);
+ }
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/gcorebg.exp b/gdb/testsuite/gdb.base/gcorebg.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gcorebg.exp
@@ -0,0 +1,113 @@
+# Copyright 2007 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
+# This is a test for `gdb_gcore.sh' functionality.
+# It also tests a regression with `gdb_gcore.sh' being run without its
+# accessible terminal.
+
+if ![info exists GCORE] {
+ set GCORE "[standard_output_file ../../../../gcore]"
+}
+verbose "using GCORE = $GCORE" 2
+
+set testfile "gcorebg"
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+set corefile [standard_output_file ${testfile}.test]
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ untested gcorebg.exp
+ return -1
+}
+
+# Cleanup.
+
+proc core_clean {} {
+ global corefile
+
+ foreach file [glob -nocomplain [join [list $corefile *] ""]] {
+ verbose "Delete file $file" 1
+ remote_file target delete $file
+ }
+}
+core_clean
+remote_file target delete "./gdb"
+
+# Generate the core file.
+
+# Provide `./gdb' for `gdb_gcore.sh' running it as a bare `gdb' command.
+# Setup also `$PATH' appropriately.
+# If GDB was not found let `gdb_gcore.sh' to find the system GDB by `$PATH'.
+if {$GDB != "gdb"} {
+ file link ./gdb $GDB
+}
+global env
+set oldpath $env(PATH)
+set env(PATH) [join [list . $env(PATH)] ":"]
+verbose "PATH = $env(PATH)" 2
+
+# Test file body.
+# $detached == "standard" || $detached == "detached"
+
+proc test_body { detached } {
+ global binfile
+ global GCORE
+ global corefile
+
+ set res [remote_spawn target "$binfile $detached $GCORE $corefile"]
+ if { $res < 0 || $res == "" } {
+ fail "Spawning $detached gcore"
+ return 1
+ }
+ pass "Spawning $detached gcore"
+ remote_expect target 20 {
+ timeout {
+ fail "Spawned $detached gcore finished (timeout)"
+ remote_exec target "kill -9 -[exp_pid -i $res]"
+ return 1
+ }
+ "Saved corefile .*\r\nKilling parent PID " {
+ pass "Spawned $detached gcore finished"
+ remote_wait target 20
+ }
+ }
+
+ if {1 == [llength [glob -nocomplain [join [list $corefile *] ""]]]} {
+ pass "Core file generated by $detached gcore"
+ } else {
+ fail "Core file generated by $detached gcore"
+ }
+ core_clean
+}
+
+# First a general `gdb_gcore.sh' spawn with its controlling terminal available.
+
+test_body standard
+
+# And now `gdb_gcore.sh' spawn without its controlling terminal available.
+# It is spawned through `gcorebg.c' using setpgrp ().
+
+test_body detached
+
+
+# Cleanup.
+
+set env(PATH) $oldpath
+remote_file target delete "./gdb"

View File

@ -0,0 +1,278 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.6-bz237572-ppc-atomic-sequence-test.patch
;; Support for stepping over PPC atomic instruction sequences (BZ 237572).
;;=fedoratest
2007-06-25 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.threads/atomic-seq-threaded.c,
gdb.threads/atomic-seq-threaded.exp: New files.
diff --git a/gdb/testsuite/gdb.threads/atomic-seq-threaded.c b/gdb/testsuite/gdb.threads/atomic-seq-threaded.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/atomic-seq-threaded.c
@@ -0,0 +1,171 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2007 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 2 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, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA. */
+
+/* Test stepping over RISC atomic sequences.
+ This variant testcases the code for stepping another thread while skipping
+ over the atomic sequence in the former thread
+ (STEPPING_PAST_SINGLESTEP_BREAKPOINT).
+ Code comes from gcc/testsuite/gcc.dg/sync-2.c */
+
+/* { dg-options "-march=i486" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
+/* { dg-options "-mcpu=v9" { target sparc*-*-* } } */
+
+/* Test functionality of the intrinsics for 'short' and 'char'. */
+
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+
+#define LOOPS 2
+
+static int unused;
+
+static char AI[18];
+static char init_qi[18] = { 3,5,7,9,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0 };
+static char test_qi[18] = { 3,5,7,9,1,4,22,-12,7,8,9,7,1,-12,7,8,9,7 };
+
+static void
+do_qi (void)
+{
+ if (__sync_fetch_and_add(AI+4, 1) != 0)
+ abort ();
+ if (__sync_fetch_and_add(AI+5, 4) != 0)
+ abort ();
+ if (__sync_fetch_and_add(AI+6, 22) != 0)
+ abort ();
+ if (__sync_fetch_and_sub(AI+7, 12) != 0)
+ abort ();
+ if (__sync_fetch_and_and(AI+8, 7) != (char)-1)
+ abort ();
+ if (__sync_fetch_and_or(AI+9, 8) != 0)
+ abort ();
+ if (__sync_fetch_and_xor(AI+10, 9) != 0)
+ abort ();
+ if (__sync_fetch_and_nand(AI+11, 7) != 0)
+ abort ();
+
+ if (__sync_add_and_fetch(AI+12, 1) != 1)
+ abort ();
+ if (__sync_sub_and_fetch(AI+13, 12) != (char)-12)
+ abort ();
+ if (__sync_and_and_fetch(AI+14, 7) != 7)
+ abort ();
+ if (__sync_or_and_fetch(AI+15, 8) != 8)
+ abort ();
+ if (__sync_xor_and_fetch(AI+16, 9) != 9)
+ abort ();
+ if (__sync_nand_and_fetch(AI+17, 7) != 7)
+ abort ();
+}
+
+static short AL[18];
+static short init_hi[18] = { 3,5,7,9,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0 };
+static short test_hi[18] = { 3,5,7,9,1,4,22,-12,7,8,9,7,1,-12,7,8,9,7 };
+
+static void
+do_hi (void)
+{
+ if (__sync_fetch_and_add(AL+4, 1) != 0)
+ abort ();
+ if (__sync_fetch_and_add(AL+5, 4) != 0)
+ abort ();
+ if (__sync_fetch_and_add(AL+6, 22) != 0)
+ abort ();
+ if (__sync_fetch_and_sub(AL+7, 12) != 0)
+ abort ();
+ if (__sync_fetch_and_and(AL+8, 7) != -1)
+ abort ();
+ if (__sync_fetch_and_or(AL+9, 8) != 0)
+ abort ();
+ if (__sync_fetch_and_xor(AL+10, 9) != 0)
+ abort ();
+ if (__sync_fetch_and_nand(AL+11, 7) != 0)
+ abort ();
+
+ if (__sync_add_and_fetch(AL+12, 1) != 1)
+ abort ();
+ if (__sync_sub_and_fetch(AL+13, 12) != -12)
+ abort ();
+ if (__sync_and_and_fetch(AL+14, 7) != 7)
+ abort ();
+ if (__sync_or_and_fetch(AL+15, 8) != 8)
+ abort ();
+ if (__sync_xor_and_fetch(AL+16, 9) != 9)
+ abort ();
+ if (__sync_nand_and_fetch(AL+17, 7) != 7)
+ abort ();
+}
+
+static void *
+start1 (void *arg)
+{
+ unsigned loop;
+ sleep(1);
+
+ for (loop = 0; loop < LOOPS; loop++)
+ {
+ memcpy(AI, init_qi, sizeof(init_qi));
+
+ do_qi ();
+
+ if (memcmp (AI, test_qi, sizeof(test_qi)))
+ abort ();
+ }
+
+ return arg; /* _delete1_ */
+}
+
+static void *
+start2 (void *arg)
+{
+ unsigned loop;
+
+ for (loop = 0; loop < LOOPS; loop++)
+ {
+ memcpy(AL, init_hi, sizeof(init_hi));
+
+ do_hi ();
+
+ if (memcmp (AL, test_hi, sizeof(test_hi)))
+ abort ();
+ }
+
+ return arg; /* _delete2_ */
+}
+
+int
+main (int argc, char **argv)
+{
+ pthread_t thread;
+ int i;
+
+ i = pthread_create (&thread, NULL, start1, NULL); /* _create_ */
+ assert (i == 0); /* _create_after_ */
+
+ sleep (1);
+
+ start2 (NULL);
+
+ i = pthread_join (thread, NULL); /* _delete_ */
+ assert (i == 0);
+
+ return 0; /* _exit_ */
+}
diff --git a/gdb/testsuite/gdb.threads/atomic-seq-threaded.exp b/gdb/testsuite/gdb.threads/atomic-seq-threaded.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/atomic-seq-threaded.exp
@@ -0,0 +1,84 @@
+# atomic-seq-threaded.exp -- Test case for stepping over RISC atomic code seqs.
+# This variant testcases the code for stepping another thread while skipping
+# over the atomic sequence in the former thread
+# (STEPPING_PAST_SINGLESTEP_BREAKPOINT).
+# Copyright (C) 2007 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+set testfile atomic-seq-threaded
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+
+foreach opts {{} {compiler=gcc4} {FAIL}} {
+ if {$opts eq "FAIL"} {
+ return -1
+ }
+ if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $opts]] eq "" } {
+ break
+ }
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_load ${binfile}
+if ![runto_main] then {
+ fail "Can't run to main"
+ return 0
+}
+
+# pthread_create () will not pass even on x86_64 with software watchpoint.
+# Pass after pthread_create () without any watchpoint active.
+set line [gdb_get_line_number "_create_after_"]
+gdb_test "tbreak $line" \
+ "reakpoint (\[0-9\]+) at .*$srcfile, line $line\..*" \
+ "set breakpoint after pthread_create ()"
+gdb_test "c" \
+ ".*/\\* _create_after_ \\*/.*" \
+ "run till after pthread_create ()"
+
+# Without a watchpoint being software no single-stepping would be used.
+set test "Start (software) watchpoint"
+gdb_test_multiple "watch unused" $test {
+ -re "Watchpoint \[0-9\]+: unused.*$gdb_prompt $" {
+ pass $test
+ }
+ -re "Hardware watchpoint \[0-9\]+: unused.*$gdb_prompt $" {
+ # We do not test the goal but still the whole testcase should pass.
+ unsupported $test
+ }
+}
+
+# More thorough testing of the scheduling logic.
+gdb_test "set scheduler-locking step" ""
+
+# Critical code path is stepped through at this point.
+set line [gdb_get_line_number "_exit_"]
+gdb_test "tbreak $line" \
+ "reakpoint \[0-9\]+ at .*$srcfile, line $line\..*" \
+ "set breakpoint at _exit_"
+gdb_test "c" \
+ ".*/\\* _exit_ \\*/.*" \
+ "run till _exit_"
+
+# Just a nonproblematic program exit.
+gdb_test "c" \
+ ".*Program exited normally\\..*" \
+ "run till program exit"

View File

@ -0,0 +1,32 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.6-testsuite-timeouts.patch
;; Avoid too long timeouts on failing cases of "annota1.exp annota3.exp".
;;=fedoratest
diff --git a/gdb/testsuite/gdb.base/annota1.exp b/gdb/testsuite/gdb.base/annota1.exp
--- a/gdb/testsuite/gdb.base/annota1.exp
+++ b/gdb/testsuite/gdb.base/annota1.exp
@@ -39,6 +39,8 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
clean_restart ${binfile}
+gdb_test "set breakpoint pending off" "" "Avoid lockup on nonexisting functions"
+
# The commands we test here produce many lines of output; disable "press
# <return> to continue" prompts.
gdb_test_no_output "set height 0"
diff --git a/gdb/testsuite/gdb.base/annota3.exp b/gdb/testsuite/gdb.base/annota3.exp
--- a/gdb/testsuite/gdb.base/annota3.exp
+++ b/gdb/testsuite/gdb.base/annota3.exp
@@ -38,6 +38,8 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
clean_restart ${binfile}
+gdb_test "set breakpoint pending off" "" "Avoid lockup on nonexisting functions"
+
# The commands we test here produce many lines of output; disable "press
# <return> to continue" prompts.
gdb_test_no_output "set height 0"

View File

@ -0,0 +1,104 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.7-testsuite-stable-results.patch
;; Testsuite fixes for more stable/comparable results.
;;=fedoratest
gdb/testsuite/gdb.base/fileio.c:
gdb/testsuite/gdb.base/fileio.exp:
2007-12-08 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.base/fileio.c (ROOTSUBDIR): New macro.
(main): CHDIR into ROOTSUBDIR. CHOWN ROOTSUBDIR and CHDIR into
ROOTSUBDIR if we are being run as root.
* gdb.base/fileio.exp: Change the startup and finish cleanup.
Change the test file reference to be into the `fileio.dir' directory.
sources/gdb/testsuite/gdb.base/dump.exp:
Found on RHEL-5.s390x.
gdb-6.8.50.20090209/gdb/testsuite/gdb.base/auxv.exp:
random FAIL: gdb.base/auxv.exp: matching auxv data from live and gcore
gdb-6.8.50.20090209/gdb/testsuite/gdb.base/annota1.exp:
frames-invalid can happen asynchronously.
diff --git a/gdb/testsuite/gdb.base/fileio.c b/gdb/testsuite/gdb.base/fileio.c
--- a/gdb/testsuite/gdb.base/fileio.c
+++ b/gdb/testsuite/gdb.base/fileio.c
@@ -559,6 +559,28 @@ strerrno (int err)
int
main ()
{
+ /* These tests
+ Open for write but no write permission returns EACCES
+ Unlinking a file in a directory w/o write access returns EACCES
+ fail if we are being run as root - drop the privileges here. */
+
+ if (geteuid () == 0)
+ {
+ uid_t uid = 99;
+
+ if (chown (OUTDIR, uid, uid) != 0)
+ {
+ printf ("chown %d.%d %s: %s\n", (int) uid, (int) uid,
+ OUTDIR, strerror (errno));
+ exit (1);
+ }
+ if (setuid (uid) || geteuid () == 0)
+ {
+ printf ("setuid %d: %s\n", (int) uid, strerror (errno));
+ exit (1);
+ }
+ }
+
/* Don't change the order of the calls. They partly depend on each other */
test_open ();
test_write ();
diff --git a/gdb/testsuite/gdb.base/fileio.exp b/gdb/testsuite/gdb.base/fileio.exp
--- a/gdb/testsuite/gdb.base/fileio.exp
+++ b/gdb/testsuite/gdb.base/fileio.exp
@@ -24,9 +24,9 @@ if [target_info exists gdb,nofileio] {
standard_testfile
if {[is_remote host]} {
- set outdir .
+ set outdir "fileio.dir"
} else {
- set outdir [standard_output_file {}]
+ set outdir [standard_output_file "fileio.dir"]
}
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
@@ -40,7 +40,8 @@ set dir2 [standard_output_file dir2.fileio.test]
if {[file exists $dir2] && ![file writable $dir2]} {
system "chmod +w $dir2"
}
-system "rm -rf [standard_output_file *.fileio.test]"
+system "rm -rf [standard_output_file fileio.dir]"
+system "mkdir -m777 [standard_output_file fileio.dir]"
set oldtimeout $timeout
set timeout [expr "$timeout + 60"]
@@ -81,7 +82,7 @@ gdb_test continue \
gdb_test "continue" ".*" ""
-catch "system \"chmod -f -w [standard_output_file nowrt.fileio.test]\""
+catch "system \"chmod -f -w [standard_output_file fileio.dir/nowrt.fileio.test]\""
gdb_test continue \
"Continuing\\..*open 5:.*EACCES$stop_msg" \
@@ -268,9 +269,7 @@ gdb_test continue \
gdb_exit
# Make dir2 writable again so rm -rf of a build tree Just Works.
-if {[file exists $dir2] && ![file writable $dir2]} {
- system "chmod +w $dir2"
-}
+system "chmod -R +w $outdir"
set timeout $oldtimeout
return 0

View File

@ -0,0 +1,181 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-6.8-bz442765-threaded-exec-test.patch
;; Test various forms of threads tracking across exec() (BZ 442765).
;;=fedoratest
Test various forms of threads tracking across exec(2).
diff --git a/gdb/testsuite/gdb.threads/threaded-exec.c b/gdb/testsuite/gdb.threads/threaded-exec.c
--- a/gdb/testsuite/gdb.threads/threaded-exec.c
+++ b/gdb/testsuite/gdb.threads/threaded-exec.c
@@ -18,21 +18,95 @@
Boston, MA 02111-1307, USA. */
#include <stddef.h>
-#include <pthread.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
+#include <stdio.h>
+#ifdef THREADS
+
+# include <pthread.h>
static void *
threader (void *arg)
{
- return NULL;
+ return NULL;
}
+#endif
+
int
-main (void)
+main (int argc, char **argv)
{
+ char *exec_nothreads, *exec_threads, *cmd;
+ int phase;
+ char phase_s[8];
+
+ setbuf (stdout, NULL);
+
+ if (argc != 4)
+ {
+ fprintf (stderr, "%s <non-threaded> <threaded> <phase>\n", argv[0]);
+ return 1;
+ }
+
+#ifdef THREADS
+ puts ("THREADS: Y");
+#else
+ puts ("THREADS: N");
+#endif
+ exec_nothreads = argv[1];
+ printf ("exec_nothreads: %s\n", exec_nothreads);
+ exec_threads = argv[2];
+ printf ("exec_threads: %s\n", exec_threads);
+ phase = atoi (argv[3]);
+ printf ("phase: %d\n", phase);
+
+ /* Phases: threading
+ 0: N -> N
+ 1: N -> Y
+ 2: Y -> Y
+ 3: Y -> N
+ 4: N -> exit */
+
+ cmd = NULL;
+
+#ifndef THREADS
+ switch (phase)
+ {
+ case 0:
+ cmd = exec_nothreads;
+ break;
+ case 1:
+ cmd = exec_threads;
+ break;
+ case 2:
+ fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
+ phase);
+ return 1;
+ case 3:
+ fprintf (stderr, "%s: We should have threads for phase %d!\n", argv[0],
+ phase);
+ return 1;
+ case 4:
+ return 0;
+ default:
+ assert (0);
+ }
+#else /* THREADS */
+ switch (phase)
+ {
+ case 0:
+ fprintf (stderr, "%s: We should not have threads for phase %d!\n",
+ argv[0], phase);
+ return 1;
+ case 1:
+ fprintf (stderr, "%s: We should not have threads for phase %d!\n",
+ argv[0], phase);
+ return 1;
+ case 2:
+ cmd = exec_threads;
+ {
pthread_t t1;
int i;
@@ -40,7 +114,34 @@ main (void)
assert (i == 0);
i = pthread_join (t1, NULL);
assert (i == 0);
+ }
+ break;
+ case 3:
+ cmd = exec_nothreads;
+ {
+ pthread_t t1;
+ int i;
+
+ i = pthread_create (&t1, NULL, threader, (void *) NULL);
+ assert (i == 0);
+ i = pthread_join (t1, NULL);
+ assert (i == 0);
+ }
+ break;
+ case 4:
+ fprintf (stderr, "%s: We should not have threads for phase %d!\n",
+ argv[0], phase);
+ return 1;
+ default:
+ assert (0);
+ }
+#endif /* THREADS */
+
+ assert (cmd != NULL);
+
+ phase++;
+ snprintf (phase_s, sizeof phase_s, "%d", phase);
- execl ("/bin/true", "/bin/true", NULL);
- abort ();
+ execl (cmd, cmd, exec_nothreads, exec_threads, phase_s, NULL);
+ assert (0);
}
diff --git a/gdb/testsuite/gdb.threads/threaded-exec.exp b/gdb/testsuite/gdb.threads/threaded-exec.exp
--- a/gdb/testsuite/gdb.threads/threaded-exec.exp
+++ b/gdb/testsuite/gdb.threads/threaded-exec.exp
@@ -20,9 +20,14 @@
set testfile threaded-exec
set srcfile ${testfile}.c
-set binfile [standard_output_file ${testfile}]
+set binfile_nothreads [standard_output_file ${testfile}N]
+set binfile_threads [standard_output_file ${testfile}Y]
-if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable []] != "" } {
+if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile_nothreads}" executable {additional_flags=-UTHREADS}] != "" } {
+ return -1
+}
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile_threads}" executable {additional_flags=-DTHREADS}] != "" } {
return -1
}
@@ -30,9 +35,9 @@ gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
+gdb_load ${binfile_nothreads}
-gdb_run_cmd
+gdb_run_cmd [list ${binfile_nothreads} ${binfile_threads} 0]
gdb_test_multiple {} "Program exited" {
-re "\r\n\\\[Inferior .* exited normally\\\]\r\n$gdb_prompt $" {

View File

@ -0,0 +1,21 @@
[gdb-add-index.sh] Fix bashism
---
gdb/contrib/gdb-add-index.sh | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/gdb/contrib/gdb-add-index.sh b/gdb/contrib/gdb-add-index.sh
index 734110caa3b..00d3ae8b0ae 100755
--- a/gdb/contrib/gdb-add-index.sh
+++ b/gdb/contrib/gdb-add-index.sh
@@ -38,7 +38,9 @@ fi
file="$1"
if test -L "$file"; then
- if ! command -v readlink >/dev/null 2>&1; then
+ target=$(readlink "$file")
+ st=$?
+ if [ $st -eq 127 ]; then
echo "$myname: 'readlink' missing. Failed to follow symlink $1." 1>&2
exit 1
fi

View File

@ -0,0 +1,88 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-archer-next-over-throw-cxx-exec.patch
;; Fix follow-exec for C++ programs (bugreported by Martin Stransky).
;;=fedoratest
Archer-upstreamed:
http://sourceware.org/ml/archer/2010-q2/msg00031.html
diff --git a/gdb/testsuite/gdb.cp/cxxexec.cc b/gdb/testsuite/gdb.cp/cxxexec.cc
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/cxxexec.cc
@@ -0,0 +1,25 @@
+/* This test script is part of GDB, the GNU debugger.
+
+ Copyright 2010 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 <unistd.h>
+
+int
+main()
+{
+ execlp ("true", "true", NULL);
+ return 1;
+}
diff --git a/gdb/testsuite/gdb.cp/cxxexec.exp b/gdb/testsuite/gdb.cp/cxxexec.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/cxxexec.exp
@@ -0,0 +1,42 @@
+# Copyright 2010 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/>.
+
+if { [skip_cplus_tests] } { continue }
+
+set testfile cxxexec
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${testfile}.cc {c++ debug}] } {
+ return -1
+}
+
+runto_main
+
+# We could stop after `continue' again at `main'.
+delete_breakpoints
+
+set test "p _Unwind_DebugHook"
+gdb_test_multiple $test $test {
+ -re " = .* 0x\[0-9a-f\].*\r\n$gdb_prompt $" {
+ pass $test
+ }
+ -re "\r\nNo symbol .*\r\n$gdb_prompt $" {
+ xfail $test
+ untested ${testfile}.exp
+ return -1
+ }
+}
+
+# Run to end. The buggy GDB failed instead with:
+# Cannot access memory at address ADDR.
+gdb_continue_to_end "" "continue" 1

View File

@ -0,0 +1,24 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Nick Clifton <nickc@redhat.com>
Date: Wed, 11 Jan 2023 12:13:46 +0000
Subject: gdb-binutils29988-read_indexed_address.patch
;; Backport "Fix a potential illegal memory access in the BFD library..."
;; (Nick Clifton, binutils/29988)
PR 29988
* dwarf2.c (read_indexed_address): Fix check for an out of range
offset.
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -1412,7 +1412,7 @@ read_indexed_address (uint64_t idx, struct comp_unit *unit)
offset += unit->dwarf_addr_offset;
if (offset < unit->dwarf_addr_offset
|| offset > file->dwarf_addr_size
- || file->dwarf_addr_size - offset < unit->offset_size)
+ || file->dwarf_addr_size - offset < unit->addr_size)
return 0;
info_ptr = file->dwarf_addr_buffer + offset;

View File

@ -0,0 +1,68 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Andrew Burgess <aburgess@redhat.com>
Date: Thu, 14 Sep 2023 13:06:26 +0100
Subject: gdb-bz2237392-dwarf-obstack-allocation.patch
;; Backport upstream commit 54392c4df604f20 to fix an incorrect
;; obstack allocation that wold lead to memory corruption.
gdb: fix buffer overflow in DWARF reader
In this commit:
commit 48ac197b0c209ccf1f2de9704eb6cdf7c5c73a8e
Date: Fri Nov 19 10:12:44 2021 -0700
Handle multiple addresses in call_site_target
a buffer overflow bug was introduced when the following code was
added:
CORE_ADDR *saved = XOBNEWVAR (&objfile->objfile_obstack, CORE_ADDR,
addresses.size ());
std::copy (addresses.begin (), addresses.end (), saved);
The definition of XOBNEWVAR is (from libiberty.h):
#define XOBNEWVAR(O, T, S) ((T *) obstack_alloc ((O), (S)))
So 'saved' is going to point to addresses.size () bytes of memory,
however, the std::copy will write addresses.size () number of
CORE_ADDR sized entries to the address pointed to by 'saved', this is
going to result in memory corruption.
The mistake is that we should have used XOBNEWVEC, which allocates a
vector of entries, the definition of XOBNEWVEC is:
#define XOBNEWVEC(O, T, N) \
((T *) obstack_alloc ((O), sizeof (T) * (N)))
Which means we will have set aside enough space to create a copy of
the contents of the addresses vector.
I'm not sure how to create a test for this problem, this issue cropped
up when debugging a particular i686 built binary, which just happened
to trigger a glibc assertion (likely due to random memory corruption),
debugging the same binary built for x86-64 appeared to work just fine.
Using valgrind on the failing GDB binary pointed straight to the cause
of the problem, and with this patch in place there are no longer
valgrind errors in this area.
If anyone has ideas for a test I'm happy to work on something.
Co-Authored-By: Keith Seitz <keiths@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -12506,7 +12506,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
std::vector<CORE_ADDR> addresses;
dwarf2_ranges_read_low_addrs (ranges_offset, target_cu,
target_die->tag, addresses);
- CORE_ADDR *saved = XOBNEWVAR (&objfile->objfile_obstack, CORE_ADDR,
+ CORE_ADDR *saved = XOBNEWVEC (&objfile->objfile_obstack, CORE_ADDR,
addresses.size ());
std::copy (addresses.begin (), addresses.end (), saved);
call_site->target.set_loc_array (addresses.size (), saved);

View File

@ -0,0 +1,102 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@adacore.com>
Date: Tue, 6 Dec 2022 12:07:12 -0700
Subject: gdb-bz2237515-debuginfod-double-free.patch
;; Backport upstream commit f96328accde1e63 to fix a potential double
;; free issue in the debuginfod code.
Avoid double-free with debuginfod
PR gdb/29257 points out a possible double free when debuginfod is in
use. Aside from some ugly warts in the symbol code (an ongoing
issue), the underlying issue in this particular case is that elfread.c
seems to assume that symfile_bfd_open will return NULL on error,
whereas in reality it throws an exception. As this code isn't
prepared for an exception, bad things result.
This patch fixes the problem by introducing a non-throwing variant of
symfile_bfd_open and using it in the affected places.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29257
diff --git a/gdb/elfread.c b/gdb/elfread.c
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1222,10 +1222,12 @@ elf_symfile_read_dwarf2 (struct objfile *objfile,
if (!debugfile.empty ())
{
- gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (debugfile.c_str ()));
+ gdb_bfd_ref_ptr debug_bfd
+ (symfile_bfd_open_no_error (debugfile.c_str ()));
- symbol_file_add_separate (debug_bfd, debugfile.c_str (),
- symfile_flags, objfile);
+ if (debug_bfd != nullptr)
+ symbol_file_add_separate (debug_bfd, debugfile.c_str (),
+ symfile_flags, objfile);
}
else
{
@@ -1245,13 +1247,12 @@ elf_symfile_read_dwarf2 (struct objfile *objfile,
if (fd.get () >= 0)
{
/* File successfully retrieved from server. */
- gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (symfile_path.get ()));
+ gdb_bfd_ref_ptr debug_bfd
+ (symfile_bfd_open_no_error (symfile_path.get ()));
- if (debug_bfd == nullptr)
- warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
- filename);
- else if (build_id_verify (debug_bfd.get (), build_id->size,
- build_id->data))
+ if (debug_bfd != nullptr
+ && build_id_verify (debug_bfd.get (), build_id->size,
+ build_id->data))
{
symbol_file_add_separate (debug_bfd, symfile_path.get (),
symfile_flags, objfile);
diff --git a/gdb/symfile.c b/gdb/symfile.c
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1744,6 +1744,23 @@ symfile_bfd_open (const char *name)
return sym_bfd;
}
+/* See symfile.h. */
+
+gdb_bfd_ref_ptr
+symfile_bfd_open_no_error (const char *name) noexcept
+{
+ try
+ {
+ return symfile_bfd_open (name);
+ }
+ catch (const gdb_exception_error &err)
+ {
+ warning ("%s", err.what ());
+ }
+
+ return nullptr;
+}
+
/* Return the section index for SECTION_NAME on OBJFILE. Return -1 if
the section was not found. */
diff --git a/gdb/symfile.h b/gdb/symfile.h
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -269,6 +269,11 @@ extern void set_initial_language (void);
extern gdb_bfd_ref_ptr symfile_bfd_open (const char *);
+/* Like symfile_bfd_open, but will not throw an exception on error.
+ Instead, it issues a warning and returns nullptr. */
+
+extern gdb_bfd_ref_ptr symfile_bfd_open_no_error (const char *) noexcept;
+
extern int get_section_index (struct objfile *, const char *);
extern int print_symbol_loading_p (int from_tty, int mainline, int full);

View File

@ -0,0 +1,41 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-bz634108-solib_address.patch
;; Verify GDB Python built-in function gdb.solib_address exists (BZ # 634108).
;;=fedoratest
Fix gdb.solib_address (fix by Phil Muldoon).
s/solib_address/solib_name/ during upstreaming.
diff --git a/gdb/testsuite/gdb.python/rh634108-solib_address.exp b/gdb/testsuite/gdb.python/rh634108-solib_address.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.python/rh634108-solib_address.exp
@@ -0,0 +1,24 @@
+# Copyright (C) 2008, 2009, 2010 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/>.
+
+# https://bugzilla.redhat.com/show_bug.cgi?id=634108
+
+gdb_exit
+gdb_start
+
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+gdb_test "python print (gdb.solib_name(-1))" "None" "gdb.solib_name exists"

View File

@ -0,0 +1,26 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-ccache-workaround.patch
;; Workaround ccache making lineno non-zero for command-line definitions.
;;=fedoratest: ccache is rarely used and it is even fixed now.
diff --git a/gdb/testsuite/gdb.base/macscp.exp b/gdb/testsuite/gdb.base/macscp.exp
--- a/gdb/testsuite/gdb.base/macscp.exp
+++ b/gdb/testsuite/gdb.base/macscp.exp
@@ -20,6 +20,14 @@ set objfile [standard_output_file ${testfile}.o]
set options {debug macros additional_flags=-DFROM_COMMANDLINE=ARG}
+# Workaround ccache making lineno non-zero for command-line definitions.
+if {[find_gcc] == "gcc" && [file executable "/usr/bin/gcc"]} {
+ set result [catch "exec which gcc" output]
+ if {$result == 0 && [string first "/ccache/" $output] > -1} {
+ lappend options "compiler=/usr/bin/gcc"
+ }
+}
+
# Generate the intermediate object file. This is required by Darwin to
# have access to the .debug_macinfo section.
if {[gdb_compile "${srcdir}/${subdir}/macscp1.c" "${objfile}" \

View File

@ -0,0 +1,192 @@
[gdb/cli] Add ignore-errors command
While trying to reproduce a failing test-case from the testsuite on the
command line using a gdb command script, I ran into the problem that a command
failed which stopped script execution.
I could work around this by splitting the script at each error, but I realized
it would be nice if I could tell gdb to ignore the error.
A python workaround ignore-errors exists, mentioned here (
https://sourceware.org/legacy-ml/gdb/2010-06/msg00100.html ), which is
already supplied by distros like Fedora and openSUSE.
FTR, a more elaborate try-catch solution was posted here (
https://sourceware.org/bugzilla/show_bug.cgi?id=8487 ).
This patch adds native ignore-errors support (so no python needed).
So with this script:
...
$ cat script.gdb
ignore-errors run
echo here
...
we have:
...
$ gdb -q -batch -x script.gdb
No executable file specified.
Use the "file" or "exec-file" command.
here$
...
Note that quit is not caught:
...
$ gdb -q
(gdb) ignore-errors quit
$
...
which is the same behaviour as with the python implementation.
Tested on x86_64-linux.
gdb/ChangeLog:
2021-05-18 Tom de Vries <tdevries@suse.de>
* cli/cli-cmds.c (ignore_errors_command_completer)
(ignore_errors_command): New function.
(_initialize_cli_cmds): Add "ignore-errors" cmd.
gdb/doc/ChangeLog:
2021-05-18 Tom de Vries <tdevries@suse.de>
* gdb.texinfo (Command Files): Document command ignore-errors.
gdb/testsuite/ChangeLog:
2021-05-18 Tom de Vries <tdevries@suse.de>
* gdb.base/ignore-errors.exp: New test.
* gdb.base/ignore-errors.gdb: New command file.
---
gdb/cli/cli-cmds.c | 35 ++++++++++++++++++++++++++++++++
gdb/doc/gdb.texinfo | 8 +++++++-
gdb/testsuite/gdb.base/ignore-errors.exp | 24 ++++++++++++++++++++++
gdb/testsuite/gdb.base/ignore-errors.gdb | 2 ++
4 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 31d398cb13b..4eff591b3df 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -39,6 +39,7 @@
#include "gdbsupport/filestuff.h"
#include "location.h"
#include "block.h"
+#include "event-top.h"
#include "ui-out.h"
#include "interps.h"
@@ -2399,6 +2400,34 @@ gdb_maint_setting_str_internal_fn (struct gdbarch *gdbarch,
return str_value_from_setting (*show_cmd->var, gdbarch);
}
+/* Completer for "ignore-errors". */
+
+static void
+ignore_errors_command_completer (cmd_list_element *ignore,
+ completion_tracker &tracker,
+ const char *text, const char * /*word*/)
+{
+ complete_nested_command_line (tracker, text);
+}
+
+/* Implementation of the ignore-errors command. */
+
+static void
+ignore_errors_command (const char *args, int from_tty)
+{
+ try
+ {
+ execute_command (args, from_tty);
+ }
+ catch (const gdb_exception_error &ex)
+ {
+ exception_print (gdb_stderr, ex);
+
+ /* See also execute_gdb_command. */
+ async_enable_stdin ();
+ }
+}
+
void _initialize_cli_cmds ();
void
_initialize_cli_cmds ()
@@ -2786,4 +2815,10 @@ when GDB is started."), GDBINIT).release ();
c = add_cmd ("source", class_support, source_command,
source_help_text, &cmdlist);
set_cmd_completer (c, filename_completer);
+
+ c = add_cmd ("ignore-errors", class_support, ignore_errors_command,
+ _("Execute a single command, ignoring all errors.\n"
+ "Only one-line commands are supported.\n"
+ "This is primarily useful in scripts."), &cmdlist);
+ set_cmd_completer (c, ignore_errors_command_completer);
}
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 1cf3550885e..68e11585942 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -27680,7 +27680,8 @@ The lines in a command file are generally executed sequentially,
unless the order of execution is changed by one of the
@emph{flow-control commands} described below. The commands are not
printed as they are executed. An error in any command terminates
-execution of the command file and control is returned to the console.
+execution of the command file and control is returned to the console,
+unless the line is prefixed with the @code{ignore-errors} command.
@value{GDBN} first searches for @var{filename} in the current directory.
If the file is not found there, and @var{filename} does not specify a
@@ -27775,6 +27776,11 @@ the controlling expression.
@item end
Terminate the block of commands that are the body of @code{if},
@code{else}, or @code{while} flow-control commands.
+
+@kindex ignore-errors
+@item ignore-errors
+This command executes the command specified by its arguments, but
+doesn't stop execution of the script if the command fails.
@end table
diff --git a/gdb/testsuite/gdb.base/ignore-errors.exp b/gdb/testsuite/gdb.base/ignore-errors.exp
new file mode 100644
index 00000000000..30dac7a94e2
--- /dev/null
+++ b/gdb/testsuite/gdb.base/ignore-errors.exp
@@ -0,0 +1,24 @@
+# Copyright 2021 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/>. */
+
+# Check command ignore-errors.
+
+clean_restart
+
+gdb_test "source ignore-errors.gdb" \
+ [multi_line \
+ "No executable file specified\\." \
+ "Use the \"file\" or \"exec-file\" command\\." \
+ "here"]
diff --git a/gdb/testsuite/gdb.base/ignore-errors.gdb b/gdb/testsuite/gdb.base/ignore-errors.gdb
new file mode 100644
index 00000000000..5962ff49b11
--- /dev/null
+++ b/gdb/testsuite/gdb.base/ignore-errors.gdb
@@ -0,0 +1,2 @@
+ignore-errors run
+echo here\n

View File

@ -0,0 +1,69 @@
From 3f5ef7bf512c7565279832bad3d5c743e9d8ae4b Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Wed, 24 May 2023 10:53:02 +0200
Subject: [PATCH 1/4] [gdb/cli] Handle pending ^C after rl_callback_read_char
for readline 7
In commit faf01aee1d0 ("[gdb] Handle pending ^C after rl_callback_read_char")
we handled a problem (described in detail in that commit) for readline >= 8
using public readline functions rl_pending_signal and rl_check_signals.
For readline 7 (note that we require at least readline 7 so there's no need to
worry about readline 6), there was no fix though, because rl_check_signals was
not available.
Fix this by instead using the private readline function _rl_signal_handler.
There is precedent for using private readline variables and functions, but
it's something we want to get rid of (PR build/10723). Nevertheless, I think
we can allow this specific instance because it's not used when building
against readline >= 8.
[ In the meanwhile, a fix was committed in the devel branch of the readline
repo, contained in commit 8d0c439 ("rollup of changes since readline-8.2"),
first proposed here (
https://lists.gnu.org/archive/html/bug-readline/2022-10/msg00008.html ). ]
Tested on x86_64-linux, against system readline 7.0 on openSUSE Leap 15.4.
PR cli/27813
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27813
---
gdb/event-top.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 9181e4bdcff..399582698c1 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -134,6 +134,9 @@ static struct async_signal_handler *async_sigterm_token;
character is processed. */
void (*after_char_processing_hook) (void);
+#if RL_VERSION_MAJOR == 7
+EXTERN_C void _rl_signal_handler (int);
+#endif
/* Wrapper function for calling into the readline library. This takes
care of a couple things:
@@ -200,8 +203,14 @@ gdb_rl_callback_read_char_wrapper_noexcept () noexcept
pending signal. I'm not sure if that's possible, but it seems
better to handle the scenario than to assert. */
rl_check_signals ();
+#elif RL_VERSION_MAJOR == 7
+ /* Unfortunately, rl_check_signals is not available. Use private
+ function _rl_signal_handler instead. */
+
+ while (rl_pending_signal () != 0)
+ _rl_signal_handler (rl_pending_signal ());
#else
- /* Unfortunately, rl_check_signals is not available. */
+#error "Readline major version >= 7 expected"
#endif
if (after_char_processing_hook)
(*after_char_processing_hook) ();
base-commit: 7f7fcd7031430953f41b284069d1ed0cf3c8734a
--
2.35.3

View File

@ -0,0 +1,58 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-core-open-vdso-warning.patch
;; Fix GNU/Linux core open: Can't read pathname for load map: Input/output error.
;; Fix regression of undisplayed missing shared libraries caused by a fix for.
;;=fedoratest: It should be in glibc: libc-alpha: <20091004161706.GA27450@.*>
http://sourceware.org/ml/gdb-patches/2009-10/msg00142.html
Subject: [patch] Fix GNU/Linux core open: Can't read pathname for load map: Input/output error.
[ New patch variant. ]
commit 7d760051ffb8a23cdc51342d4e6243fbc462f73f
Author: Ulrich Weigand <uweigand@de.ibm.com>
Date: Wed Sep 25 11:52:50 2013 +0000
diff --git a/gdb/testsuite/gdb.base/solib-symbol.exp b/gdb/testsuite/gdb.base/solib-symbol.exp
--- a/gdb/testsuite/gdb.base/solib-symbol.exp
+++ b/gdb/testsuite/gdb.base/solib-symbol.exp
@@ -29,6 +29,7 @@ set testfile "solib-symbol-main"
set srcfile ${srcdir}/${subdir}/${testfile}.c
set binfile [standard_output_file ${testfile}]
set bin_flags [list debug shlib=${binfile_lib}]
+set executable ${testfile}
if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib} $lib_flags] != ""
|| [gdb_compile ${srcfile} ${binfile} executable $bin_flags] != "" } {
@@ -66,8 +67,26 @@ gdb_test "br foo2" \
"Breakpoint.*: foo2. .2 locations..*" \
"foo2 in mdlib"
-gdb_exit
+# Test GDB warns for shared libraris which have not been found.
-return 0
+gdb_test "info sharedlibrary" "/${libname}.*"
+clean_restart ${executable}
+gdb_breakpoint "main"
+gdb_run_cmd
+set test "no warning for missing libraries"
+gdb_test_multiple "" $test {
+ -re "warning: Could not load shared library symbols for \[0-9\]+ libraries,.*\r\n$gdb_prompt $" {
+ fail $test
+ }
+ -re "Breakpoint \[0-9\]+, main .*\r\n$gdb_prompt $" {
+ pass $test
+ }
+}
+clean_restart ${executable}
+gdb_test_no_output "set solib-absolute-prefix /doESnotEXIST"
+gdb_breakpoint "main"
+gdb_run_cmd
+gdb_test "" "warning: Could not load shared library symbols for \[0-9\]+ libraries,.*\r\nBreakpoint \[0-9\]+, main .*" \
+ "warning for missing libraries"

View File

@ -0,0 +1,71 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-fedora-libncursesw.patch
;; Force libncursesw over libncurses to match the includes (RH BZ 1270534).
;;=push+jan
Fedora: Force libncursesw over libncurses to match the includes.
https://bugzilla.redhat.com/show_bug.cgi?id=1270534
diff --git a/gdb/configure b/gdb/configure
--- a/gdb/configure
+++ b/gdb/configure
@@ -20915,6 +20915,7 @@ if test x"$prefer_curses" = xyes; then
# search /usr/local/include, if ncurses is installed in /usr/local. A
# default installation of ncurses on alpha*-dec-osf* will lead to such
# a situation.
+ # Fedora: Force libncursesw over libncurses to match the includes.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing waddstr" >&5
$as_echo_n "checking for library containing waddstr... " >&6; }
if ${ac_cv_search_waddstr+:} false; then :
@@ -20939,7 +20940,7 @@ return waddstr ();
return 0;
}
_ACEOF
-for ac_lib in '' ncursesw ncurses cursesX curses; do
+for ac_lib in '' ncursesw; do
if test -z "$ac_lib"; then
ac_res="none required"
else
@@ -21013,6 +21014,7 @@ case $host_os in
esac
# These are the libraries checked by Readline.
+# Fedora: Force libncursesw over libncurses to match the includes.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing tgetent" >&5
$as_echo_n "checking for library containing tgetent... " >&6; }
if ${ac_cv_search_tgetent+:} false; then :
@@ -21037,7 +21039,7 @@ return tgetent ();
return 0;
}
_ACEOF
-for ac_lib in '' termcap tinfow tinfo curses ncursesw ncurses; do
+for ac_lib in '' ncursesw; do
if test -z "$ac_lib"; then
ac_res="none required"
else
diff --git a/gdb/configure.ac b/gdb/configure.ac
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -704,7 +704,8 @@ if test x"$prefer_curses" = xyes; then
# search /usr/local/include, if ncurses is installed in /usr/local. A
# default installation of ncurses on alpha*-dec-osf* will lead to such
# a situation.
- AC_SEARCH_LIBS(waddstr, [ncursesw ncurses cursesX curses])
+ # Fedora: Force libncursesw over libncurses to match the includes.
+ AC_SEARCH_LIBS(waddstr, [ncursesw])
if test "$ac_cv_search_waddstr" != no; then
curses_found=yes
@@ -746,7 +747,8 @@ case $host_os in
esac
# These are the libraries checked by Readline.
-AC_SEARCH_LIBS(tgetent, [termcap tinfow tinfo curses ncursesw ncurses])
+# Fedora: Force libncursesw over libncurses to match the includes.
+AC_SEARCH_LIBS(tgetent, [ncursesw])
if test "$ac_cv_search_tgetent" = no; then
CONFIG_OBS="$CONFIG_OBS stub-termcap.o"

View File

@ -0,0 +1,645 @@
From 75617e6d28b93814ac46ad85ad4fc2b133f61114 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Fri, 3 Nov 2023 16:25:33 +0100
Subject: [PATCH] [gdb] Fix segfault in for_each_block, part 1
When running test-case gdb.base/vfork-follow-parent.exp on powerpc64 (likewise
on s390x), I run into:
...
(gdb) PASS: gdb.base/vfork-follow-parent.exp: \
exec_file=vfork-follow-parent-exit: target-non-stop=on: non-stop=off: \
resolution_method=schedule-multiple: print unblock_parent = 1
continue^M
Continuing.^M
Reading symbols from vfork-follow-parent-exit...^M
^M
^M
Fatal signal: Segmentation fault^M
----- Backtrace -----^M
0x1027d3e7 gdb_internal_backtrace_1^M
src/gdb/bt-utils.c:122^M
0x1027d54f _Z22gdb_internal_backtracev^M
src/gdb/bt-utils.c:168^M
0x1057643f handle_fatal_signal^M
src/gdb/event-top.c:889^M
0x10576677 handle_sigsegv^M
src/gdb/event-top.c:962^M
0x3fffa7610477 ???^M
0x103f2144 for_each_block^M
src/gdb/dcache.c:199^M
0x103f235b _Z17dcache_invalidateP13dcache_struct^M
src/gdb/dcache.c:251^M
0x10bde8c7 _Z24target_dcache_invalidatev^M
src/gdb/target-dcache.c:50^M
...
or similar.
The root cause for the segmentation fault is that linux_is_uclinux gives an
incorrect result: it should always return false, given that we're running on a
regular linux system, but instead it returns first true, then false.
In more detail, the segmentation fault happens as follows:
- a program space with an address space is created
- a second program space is about to be created. maybe_new_address_space
is called, and because linux_is_uclinux returns true, maybe_new_address_space
returns false, and no new address space is created
- a second program space with the same address space is created
- a program space is deleted. Because linux_is_uclinux now returns false,
gdbarch_has_shared_address_space (current_inferior ()->arch ()) returns
false, and the address space is deleted
- when gdb uses the address space of the remaining program space, we run into
the segfault, because the address space is deleted.
Hardcoding linux_is_uclinux to false makes the test-case pass.
We leave addressing the root cause for the following commit in this series.
For now, prevent the segmentation fault by making the address space a refcounted
object.
This was already suggested here [1]:
...
A better solution might be to have the address spaces be reference counted
...
Tested on top of trunk on x86_64-linux and ppc64le-linux.
Tested on top of gdb-14-branch on ppc64-linux.
Co-Authored-By: Simon Marchi <simon.marchi@polymtl.ca>
PR gdb/30547
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30547
[1] https://sourceware.org/pipermail/gdb-patches/2023-October/202928.html
---
gdb/breakpoint.c | 29 ++++++++-------
gdb/inferior.c | 8 ++---
gdb/inferior.h | 2 +-
gdb/infrun.c | 20 +++++------
gdb/linux-nat.c | 2 +-
gdb/process-stratum-target.c | 2 +-
gdb/progspace.c | 22 +++++-------
gdb/progspace.h | 64 +++++++++++++++++++++-------------
gdb/record-btrace.c | 2 +-
gdb/regcache.c | 2 +-
gdb/scoped-mock-context.h | 2 +-
gdb/target-dcache.c | 11 +++---
gdbsupport/refcounted-object.h | 17 +++++++++
13 files changed, 103 insertions(+), 80 deletions(-)
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index f8d19356828..f4acb4ea8c4 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1605,7 +1605,7 @@ one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf,
int bptoffset = 0;
if (!breakpoint_address_match (target_info->placed_address_space, 0,
- current_program_space->aspace, 0))
+ current_program_space->aspace.get (), 0))
{
/* The breakpoint is inserted in a different address space. */
return;
@@ -2278,7 +2278,7 @@ should_be_inserted (struct bp_location *bl)
a breakpoint. */
if ((bl->loc_type == bp_loc_software_breakpoint
|| bl->loc_type == bp_loc_hardware_breakpoint)
- && stepping_past_instruction_at (bl->pspace->aspace,
+ && stepping_past_instruction_at (bl->pspace->aspace.get (),
bl->address)
/* The single-step breakpoint may be inserted at the location
we're trying to step if the instruction branches to itself.
@@ -2713,7 +2713,7 @@ insert_bp_location (struct bp_location *bl,
read the breakpoint instead of returning the data saved in
the breakpoint location's shadow contents. */
bl->target_info.reqstd_address = bl->address;
- bl->target_info.placed_address_space = bl->pspace->aspace;
+ bl->target_info.placed_address_space = bl->pspace->aspace.get ();
bl->target_info.length = bl->length;
/* When working with target-side conditions, we must pass all the conditions
@@ -4276,7 +4276,7 @@ bp_location_inserted_here_p (const struct bp_location *bl,
const address_space *aspace, CORE_ADDR pc)
{
if (bl->inserted
- && breakpoint_address_match (bl->pspace->aspace, bl->address,
+ && breakpoint_address_match (bl->pspace->aspace.get (), bl->address,
aspace, pc))
{
/* An unmapped overlay can't be a match. */
@@ -4355,7 +4355,7 @@ hardware_watchpoint_inserted_in_range (const address_space *aspace,
continue;
for (bp_location *loc : bpt->locations ())
- if (loc->pspace->aspace == aspace && loc->inserted)
+ if (loc->pspace->aspace.get () == aspace && loc->inserted)
{
CORE_ADDR l, h;
@@ -7153,10 +7153,10 @@ breakpoint_location_address_match (struct bp_location *bl,
const address_space *aspace,
CORE_ADDR addr)
{
- return (breakpoint_address_match (bl->pspace->aspace, bl->address,
+ return (breakpoint_address_match (bl->pspace->aspace.get (), bl->address,
aspace, addr)
|| (bl->length
- && breakpoint_address_match_range (bl->pspace->aspace,
+ && breakpoint_address_match_range (bl->pspace->aspace.get (),
bl->address, bl->length,
aspace, addr)));
}
@@ -7173,7 +7173,7 @@ breakpoint_location_address_range_overlap (struct bp_location *bl,
CORE_ADDR addr, int len)
{
if (gdbarch_has_global_breakpoints (target_gdbarch ())
- || bl->pspace->aspace == aspace)
+ || bl->pspace->aspace.get () == aspace)
{
int bl_len = bl->length != 0 ? bl->length : 1;
@@ -7230,8 +7230,10 @@ breakpoint_locations_match (const struct bp_location *loc1,
/* We compare bp_location.length in order to cover ranged
breakpoints. Keep this in sync with
bp_location_is_less_than. */
- return (breakpoint_address_match (loc1->pspace->aspace, loc1->address,
- loc2->pspace->aspace, loc2->address)
+ return (breakpoint_address_match (loc1->pspace->aspace.get (),
+ loc1->address,
+ loc2->pspace->aspace.get (),
+ loc2->address)
&& (loc1->loc_type == loc2->loc_type || sw_hw_bps_match)
&& loc1->length == loc2->length);
}
@@ -9297,8 +9299,9 @@ ranged_breakpoint::breakpoint_hit (const struct bp_location *bl,
|| ws.sig () != GDB_SIGNAL_TRAP)
return 0;
- return breakpoint_address_match_range (bl->pspace->aspace, bl->address,
- bl->length, aspace, bp_addr);
+ return breakpoint_address_match_range (bl->pspace->aspace.get (),
+ bl->address, bl->length, aspace,
+ bp_addr);
}
/* Implement the "resources_needed" method for ranged breakpoints. */
@@ -11696,7 +11699,7 @@ code_breakpoint::breakpoint_hit (const struct bp_location *bl,
|| ws.sig () != GDB_SIGNAL_TRAP)
return 0;
- if (!breakpoint_address_match (bl->pspace->aspace, bl->address,
+ if (!breakpoint_address_match (bl->pspace->aspace.get (), bl->address,
aspace, bp_addr))
return 0;
diff --git a/gdb/inferior.c b/gdb/inferior.c
index b0ecca8b63a..87c61eeafd7 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -775,15 +775,13 @@ remove_inferior_command (const char *args, int from_tty)
struct inferior *
add_inferior_with_spaces (void)
{
- struct address_space *aspace;
struct program_space *pspace;
struct inferior *inf;
/* If all inferiors share an address space on this system, this
doesn't really return a new address space; otherwise, it
really does. */
- aspace = maybe_new_address_space ();
- pspace = new program_space (aspace);
+ pspace = new program_space (maybe_new_address_space ());
inf = add_inferior (0);
inf->pspace = pspace;
inf->aspace = pspace->aspace;
@@ -946,15 +944,13 @@ clone_inferior_command (const char *args, int from_tty)
for (i = 0; i < copies; ++i)
{
- struct address_space *aspace;
struct program_space *pspace;
struct inferior *inf;
/* If all inferiors share an address space on this system, this
doesn't really return a new address space; otherwise, it
really does. */
- aspace = maybe_new_address_space ();
- pspace = new program_space (aspace);
+ pspace = new program_space (maybe_new_address_space ());
inf = add_inferior (0);
inf->pspace = pspace;
inf->aspace = pspace->aspace;
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 4d001b0ad50..fa5c3c92eeb 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -541,7 +541,7 @@ class inferior : public refcounted_object,
bool removable = false;
/* The address space bound to this inferior. */
- struct address_space *aspace = NULL;
+ address_space_ref_ptr aspace;
/* The program space bound to this inferior. */
struct program_space *pspace = NULL;
diff --git a/gdb/infrun.c b/gdb/infrun.c
index c078098a6f8..4073150d80c 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -501,8 +501,8 @@ holding the child stopped. Try \"set detach-on-fork\" or \
}
else
{
- child_inf->aspace = new address_space ();
- child_inf->pspace = new program_space (child_inf->aspace);
+ child_inf->pspace = new program_space (new_address_space ());
+ child_inf->aspace = child_inf->pspace->aspace;
child_inf->removable = true;
clone_program_space (child_inf->pspace, parent_inf->pspace);
}
@@ -573,8 +573,8 @@ holding the child stopped. Try \"set detach-on-fork\" or \
child_inf->aspace = parent_inf->aspace;
child_inf->pspace = parent_inf->pspace;
- parent_inf->aspace = new address_space ();
- parent_inf->pspace = new program_space (parent_inf->aspace);
+ parent_inf->pspace = new program_space (new_address_space ());
+ parent_inf->aspace = parent_inf->pspace->aspace;
clone_program_space (parent_inf->pspace, child_inf->pspace);
/* The parent inferior is still the current one, so keep things
@@ -583,8 +583,8 @@ holding the child stopped. Try \"set detach-on-fork\" or \
}
else
{
- child_inf->aspace = new address_space ();
- child_inf->pspace = new program_space (child_inf->aspace);
+ child_inf->pspace = new program_space (new_address_space ());
+ child_inf->aspace = child_inf->pspace->aspace;
child_inf->removable = true;
child_inf->symfile_flags = SYMFILE_NO_READ;
clone_program_space (child_inf->pspace, parent_inf->pspace);
@@ -938,7 +938,6 @@ handle_vfork_child_exec_or_exit (int exec)
if (vfork_parent->pending_detach)
{
struct program_space *pspace;
- struct address_space *aspace;
/* follow-fork child, detach-on-fork on. */
@@ -963,9 +962,8 @@ handle_vfork_child_exec_or_exit (int exec)
of" a hack. */
pspace = inf->pspace;
- aspace = inf->aspace;
- inf->aspace = nullptr;
inf->pspace = nullptr;
+ address_space_ref_ptr aspace = std::move (inf->aspace);
if (print_inferior_events)
{
@@ -1019,7 +1017,7 @@ handle_vfork_child_exec_or_exit (int exec)
/* Temporarily switch to the vfork parent, to facilitate ptrace
calls done during maybe_new_address_space. */
switch_to_thread (any_live_thread_of_inferior (vfork_parent));
- address_space *aspace = maybe_new_address_space ();
+ address_space_ref_ptr aspace = maybe_new_address_space ();
/* Switch back to the vfork child inferior. Switch to no-thread
while running clone_program_space, so that clone_program_space
@@ -5639,7 +5637,7 @@ handle_inferior_event (struct execution_control_state *ecs)
= get_thread_arch_aspace_regcache (parent_inf->process_target (),
ecs->ws.child_ptid (),
gdbarch,
- parent_inf->aspace);
+ parent_inf->aspace.get ());
/* Read PC value of parent process. */
parent_pc = regcache_read_pc (regcache);
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 2b206a4ec1e..474d3c7f945 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -4316,7 +4316,7 @@ linux_nat_target::thread_address_space (ptid_t ptid)
inf = find_inferior_pid (this, pid);
gdb_assert (inf != NULL);
- return inf->aspace;
+ return inf->aspace.get ();
}
/* Return the cached value of the processor core for thread PTID. */
diff --git a/gdb/process-stratum-target.c b/gdb/process-stratum-target.c
index 4722c5a0f28..e67012a8591 100644
--- a/gdb/process-stratum-target.c
+++ b/gdb/process-stratum-target.c
@@ -37,7 +37,7 @@ process_stratum_target::thread_address_space (ptid_t ptid)
"address space of thread %s\n"),
target_pid_to_str (ptid).c_str ());
- return inf->aspace;
+ return inf->aspace.get ();
}
struct gdbarch *
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 32bdfebcf7c..55df3b65dfe 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -54,8 +54,8 @@ address_space::address_space ()
return a pointer to an existing address space, in case inferiors
share an address space on this target system. */
-struct address_space *
-maybe_new_address_space (void)
+address_space_ref_ptr
+maybe_new_address_space ()
{
int shared_aspace = gdbarch_has_shared_address_space (target_gdbarch ());
@@ -65,7 +65,7 @@ maybe_new_address_space (void)
return program_spaces[0]->aspace;
}
- return new address_space ();
+ return new_address_space ();
}
/* Start counting over from scratch. */
@@ -93,9 +93,9 @@ remove_program_space (program_space *pspace)
/* See progspace.h. */
-program_space::program_space (address_space *aspace_)
+program_space::program_space (address_space_ref_ptr aspace_)
: num (++last_program_space_num),
- aspace (aspace_)
+ aspace (std::move (aspace_))
{
program_spaces.push_back (this);
}
@@ -118,8 +118,6 @@ program_space::~program_space ()
/* Defer breakpoint re-set because we don't want to create new
locations for this pspace which we're tearing down. */
clear_symtab_users (SYMFILE_DEFER_BP_RESET);
- if (!gdbarch_has_shared_address_space (target_gdbarch ()))
- delete this->aspace;
}
/* See progspace.h. */
@@ -389,18 +387,14 @@ update_address_spaces (void)
if (shared_aspace)
{
- struct address_space *aspace = new address_space ();
+ address_space_ref_ptr aspace = new_address_space ();
- delete current_program_space->aspace;
for (struct program_space *pspace : program_spaces)
pspace->aspace = aspace;
}
else
for (struct program_space *pspace : program_spaces)
- {
- delete pspace->aspace;
- pspace->aspace = new address_space ();
- }
+ pspace->aspace = new_address_space ();
for (inferior *inf : all_inferiors ())
if (gdbarch_has_global_solist (target_gdbarch ()))
@@ -437,5 +431,5 @@ initialize_progspace (void)
modules have done that. Do this before
initialize_current_architecture, because that accesses the ebfd
of current_program_space. */
- current_program_space = new program_space (new address_space ());
+ current_program_space = new program_space (new_address_space ());
}
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 85215f0e2f1..07cca8c675c 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -28,6 +28,8 @@
#include "solist.h"
#include "gdbsupport/next-iterator.h"
#include "gdbsupport/safe-iterator.h"
+#include "gdbsupport/refcounted-object.h"
+#include "gdbsupport/gdb_ref_ptr.h"
#include <list>
#include <vector>
@@ -42,6 +44,40 @@ struct so_list;
typedef std::list<std::unique_ptr<objfile>> objfile_list;
+/* An address space. It is used for comparing if
+ pspaces/inferior/threads see the same address space and for
+ associating caches to each address space. */
+struct address_space : public refcounted_object
+{
+ /* Create a new address space object, and add it to the list. */
+ address_space ();
+ DISABLE_COPY_AND_ASSIGN (address_space);
+
+ /* Returns the integer address space id of this address space. */
+ int num () const
+ {
+ return m_num;
+ }
+
+ /* Per aspace data-pointers required by other GDB modules. */
+ registry<address_space> registry_fields;
+
+private:
+ int m_num;
+};
+
+using address_space_ref_ptr
+ = gdb::ref_ptr<address_space,
+ refcounted_object_delete_ref_policy<address_space>>;
+
+/* Create a new address space. */
+
+static inline address_space_ref_ptr
+new_address_space ()
+{
+ return address_space_ref_ptr::new_reference (new address_space);
+}
+
/* An iterator that wraps an iterator over std::unique_ptr<objfile>,
and dereferences the returned object. This is useful for iterating
over a list of shared pointers and returning raw pointers -- which
@@ -191,7 +227,7 @@ struct program_space
{
/* Constructs a new empty program space, binds it to ASPACE, and
adds it to the program space list. */
- explicit program_space (address_space *aspace);
+ explicit program_space (address_space_ref_ptr aspace);
/* Releases a program space, and all its contents (shared libraries,
objfiles, and any other references to the program space in other
@@ -332,7 +368,7 @@ struct program_space
are global, then this field is ignored (we don't currently
support inferiors sharing a program space if the target doesn't
make breakpoints global). */
- struct address_space *aspace = NULL;
+ address_space_ref_ptr aspace;
/* True if this program space's section offsets don't yet represent
the final offsets of the "live" address space (that is, the
@@ -379,28 +415,6 @@ struct program_space
target_section_table m_target_sections;
};
-/* An address space. It is used for comparing if
- pspaces/inferior/threads see the same address space and for
- associating caches to each address space. */
-struct address_space
-{
- /* Create a new address space object, and add it to the list. */
- address_space ();
- DISABLE_COPY_AND_ASSIGN (address_space);
-
- /* Returns the integer address space id of this address space. */
- int num () const
- {
- return m_num;
- }
-
- /* Per aspace data-pointers required by other GDB modules. */
- registry<address_space> registry_fields;
-
-private:
- int m_num;
-};
-
/* The list of all program spaces. There's always at least one. */
extern std::vector<struct program_space *>program_spaces;
@@ -443,7 +457,7 @@ class scoped_restore_current_program_space
/* Maybe create a new address space object, and add it to the list, or
return a pointer to an existing address space, in case inferiors
share an address space. */
-extern struct address_space *maybe_new_address_space (void);
+extern address_space_ref_ptr maybe_new_address_space ();
/* Update all program spaces matching to address spaces. The user may
have created several program spaces, and loaded executables into
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 0daba893813..276cdcc03b8 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -2314,7 +2314,7 @@ record_btrace_replay_at_breakpoint (struct thread_info *tp)
if (insn == NULL)
return 0;
- return record_check_stopped_by_breakpoint (tp->inf->aspace, insn->pc,
+ return record_check_stopped_by_breakpoint (tp->inf->aspace.get (), insn->pc,
&btinfo->stop_reason);
}
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 56b6d047874..8a0b57e67b8 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -1617,7 +1617,7 @@ get_thread_arch_aspace_regcache_and_check (process_stratum_target *target,
the current inferior's gdbarch. Also use the current inferior's address
space. */
gdbarch *arch = current_inferior ()->gdbarch;
- address_space *aspace = current_inferior ()->aspace;
+ address_space *aspace = current_inferior ()->aspace.get ();
regcache *regcache
= get_thread_arch_aspace_regcache (target, ptid, arch, aspace);
diff --git a/gdb/scoped-mock-context.h b/gdb/scoped-mock-context.h
index 9ad7ebf5f0c..5f25dc7ed6b 100644
--- a/gdb/scoped-mock-context.h
+++ b/gdb/scoped-mock-context.h
@@ -38,7 +38,7 @@ struct scoped_mock_context
Target mock_target;
ptid_t mock_ptid {1, 1};
- program_space mock_pspace {new address_space ()};
+ program_space mock_pspace {new_address_space ()};
inferior mock_inferior {mock_ptid.pid ()};
thread_info mock_thread {&mock_inferior, mock_ptid};
diff --git a/gdb/target-dcache.c b/gdb/target-dcache.c
index 13c2888e7ea..b1b772ab76e 100644
--- a/gdb/target-dcache.c
+++ b/gdb/target-dcache.c
@@ -33,7 +33,7 @@ int
target_dcache_init_p (void)
{
DCACHE *dcache
- = target_dcache_aspace_key.get (current_program_space->aspace);
+ = target_dcache_aspace_key.get (current_program_space->aspace.get ());
return (dcache != NULL);
}
@@ -44,7 +44,7 @@ void
target_dcache_invalidate (void)
{
DCACHE *dcache
- = target_dcache_aspace_key.get (current_program_space->aspace);
+ = target_dcache_aspace_key.get (current_program_space->aspace.get ());
if (dcache != NULL)
dcache_invalidate (dcache);
@@ -56,7 +56,7 @@ target_dcache_invalidate (void)
DCACHE *
target_dcache_get (void)
{
- return target_dcache_aspace_key.get (current_program_space->aspace);
+ return target_dcache_aspace_key.get (current_program_space->aspace.get ());
}
/* Return the target dcache. If it is not initialized yet, initialize
@@ -66,12 +66,13 @@ DCACHE *
target_dcache_get_or_init (void)
{
DCACHE *dcache
- = target_dcache_aspace_key.get (current_program_space->aspace);
+ = target_dcache_aspace_key.get (current_program_space->aspace.get ());
if (dcache == NULL)
{
dcache = dcache_init ();
- target_dcache_aspace_key.set (current_program_space->aspace, dcache);
+ target_dcache_aspace_key.set (current_program_space->aspace.get (),
+ dcache);
}
return dcache;
diff --git a/gdbsupport/refcounted-object.h b/gdbsupport/refcounted-object.h
index d8fdb950043..294fd873df1 100644
--- a/gdbsupport/refcounted-object.h
+++ b/gdbsupport/refcounted-object.h
@@ -67,4 +67,21 @@ struct refcounted_object_ref_policy
}
};
+/* A policy class to interface gdb::ref_ptr with a refcounted_object, that
+ deletes the object once the refcount reaches 0.. */
+
+template<typename T>
+struct refcounted_object_delete_ref_policy
+{
+ static void incref (T *obj)
+ { obj->incref (); }
+
+ static void decref (T *obj)
+ {
+ obj->decref ();
+ if (obj->refcount () == 0)
+ delete obj;
+ }
+};
+
#endif /* COMMON_REFCOUNTED_OBJECT_H */
base-commit: c55a452eaf9390d5659d3205f762aa2cb84511e1
--
2.35.3

View File

@ -0,0 +1,168 @@
From 1cd845ab3d405412aabf9b959aa527dd60143826 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Thu, 2 Nov 2023 14:51:02 +0100
Subject: [PATCH] [gdb] Fix segfault in for_each_block, part 2
The previous commit describes PR gdb/30547, a segfault when running test-case
gdb.base/vfork-follow-parent.exp on powerpc64 (likewise on s390x).
The root cause for the segmentation fault is that linux_is_uclinux gives an
incorrect result: it returns true instead of false.
So, why does linux_is_uclinux:
...
int
linux_is_uclinux (void)
{
CORE_ADDR dummy;
return (target_auxv_search (AT_NULL, &dummy) > 0
&& target_auxv_search (AT_PAGESZ, &dummy) == 0);
...
return true?
This is because ppc_linux_target_wordsize returns 4 instead of 8, causing
ppc_linux_nat_target::auxv_parse to misinterpret the auxv vector.
So, why does ppc_linux_target_wordsize:
...
int
ppc_linux_target_wordsize (int tid)
{
int wordsize = 4;
/* Check for 64-bit inferior process. This is the case when the host is
64-bit, and in addition the top bit of the MSR register is set. */
long msr;
errno = 0;
msr = (long) ptrace (PTRACE_PEEKUSER, tid, PT_MSR * 8, 0);
if (errno == 0 && ppc64_64bit_inferior_p (msr))
wordsize = 8;
return wordsize;
}
...
return 4?
Specifically, we get this result because because tid == 0, so we get
errno == ESRCH.
The tid == 0 is caused by the switch_to_no_thread in
handle_vfork_child_exec_or_exit:
...
/* Switch to no-thread while running clone_program_space, so
that clone_program_space doesn't want to read the
selected frame of a dead process. */
scoped_restore_current_thread restore_thread;
switch_to_no_thread ();
inf->pspace = new program_space (maybe_new_address_space ());
...
but moving the maybe_new_address_space call to before that gives us the
same result. The tid is no longer 0, but we still get ESRCH because the
thread has exited.
Fix this in handle_vfork_child_exec_or_exit by doing the
maybe_new_address_space call in the context of the vfork parent.
Tested on top of trunk on x86_64-linux and ppc64le-linux.
Tested on top of gdb-14-branch on ppc64-linux.
Co-Authored-By: Simon Marchi <simon.marchi@polymtl.ca>
PR gdb/30547
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30547
---
gdb/infrun.c | 16 +++++++++++-----
gdb/nat/ppc-linux.c | 2 ++
gdb/ppc-linux-nat.c | 2 ++
gdb/s390-linux-nat.c | 5 ++++-
4 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 9c1b1f04e4d..c078098a6f8 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1014,13 +1014,19 @@ handle_vfork_child_exec_or_exit (int exec)
go ahead and create a new one for this exiting
inferior. */
- /* Switch to no-thread while running clone_program_space, so
- that clone_program_space doesn't want to read the
- selected frame of a dead process. */
scoped_restore_current_thread restore_thread;
- switch_to_no_thread ();
- inf->pspace = new program_space (maybe_new_address_space ());
+ /* Temporarily switch to the vfork parent, to facilitate ptrace
+ calls done during maybe_new_address_space. */
+ switch_to_thread (any_live_thread_of_inferior (vfork_parent));
+ address_space *aspace = maybe_new_address_space ();
+
+ /* Switch back to the vfork child inferior. Switch to no-thread
+ while running clone_program_space, so that clone_program_space
+ doesn't want to read the selected frame of a dead process. */
+ switch_to_inferior_no_thread (inf);
+
+ inf->pspace = new program_space (aspace);
inf->aspace = inf->pspace->aspace;
set_current_program_space (inf->pspace);
inf->removable = true;
diff --git a/gdb/nat/ppc-linux.c b/gdb/nat/ppc-linux.c
index 0957d1b58a7..74549754806 100644
--- a/gdb/nat/ppc-linux.c
+++ b/gdb/nat/ppc-linux.c
@@ -78,6 +78,8 @@ ppc64_64bit_inferior_p (long msr)
int
ppc_linux_target_wordsize (int tid)
{
+ gdb_assert (tid != 0);
+
int wordsize = 4;
/* Check for 64-bit inferior process. This is the case when the host is
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index d8a8fbdf706..500fb566bc1 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -1918,6 +1918,8 @@ ppc_linux_nat_target::auxv_parse (const gdb_byte **readptr,
const gdb_byte *endptr, CORE_ADDR *typep,
CORE_ADDR *valp)
{
+ gdb_assert (inferior_ptid != null_ptid);
+
int tid = inferior_ptid.lwp ();
if (tid == 0)
tid = inferior_ptid.pid ();
diff --git a/gdb/s390-linux-nat.c b/gdb/s390-linux-nat.c
index fc3917d30be..403f37d690d 100644
--- a/gdb/s390-linux-nat.c
+++ b/gdb/s390-linux-nat.c
@@ -949,10 +949,12 @@ s390_target_wordsize (void)
/* Check for 64-bit inferior process. This is the case when the host is
64-bit, and in addition bit 32 of the PSW mask is set. */
#ifdef __s390x__
+ int tid = s390_inferior_tid ();
+ gdb_assert (tid != 0);
long pswm;
errno = 0;
- pswm = (long) ptrace (PTRACE_PEEKUSER, s390_inferior_tid (), PT_PSWMASK, 0);
+ pswm = (long) ptrace (PTRACE_PEEKUSER, tid, PT_PSWMASK, 0);
if (errno == 0 && (pswm & 0x100000000ul) != 0)
wordsize = 8;
#endif
@@ -965,6 +967,7 @@ s390_linux_nat_target::auxv_parse (const gdb_byte **readptr,
const gdb_byte *endptr, CORE_ADDR *typep,
CORE_ADDR *valp)
{
+ gdb_assert (inferior_ptid != null_ptid);
int sizeof_auxv_field = s390_target_wordsize ();
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
const gdb_byte *ptr = *readptr;
base-commit: 59053f06bd94be51efacfa80f9a1f738e3e1ee9c
--
2.35.3

10
gdb-gcore-bash.patch Normal file
View File

@ -0,0 +1,10 @@
diff --git a/gdb/gcore.in b/gdb/gcore.in
index b9770ea415..3149f6e1fe 100644
--- a/gdb/gcore.in
+++ b/gdb/gcore.in
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/bash
# Copyright (C) 2003-2023 Free Software Foundation, Inc.

View File

@ -0,0 +1,132 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-glibc-strstr-workaround.patch
;; Workaround PR libc/14166 for inferior calls of strstr.
;;=fedoratest: Compatibility with RHELs (unchecked which ones).
diff --git a/gdb/testsuite/gdb.base/gnu-ifunc-strstr-workaround.exp b/gdb/testsuite/gdb.base/gnu-ifunc-strstr-workaround.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gnu-ifunc-strstr-workaround.exp
@@ -0,0 +1,119 @@
+# Copyright (C) 2012 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/>.
+
+# Workaround for:
+# invalid IFUNC DW_AT_linkage_name: memmove strstr time
+# http://sourceware.org/bugzilla/show_bug.cgi?id=14166
+
+if {[skip_shlib_tests]} {
+ return 0
+}
+
+set testfile "gnu-ifunc-strstr-workaround"
+set executable ${testfile}
+set srcfile start.c
+set binfile [standard_output_file ${executable}]
+
+if [prepare_for_testing ${testfile}.exp $executable $srcfile] {
+ return -1
+}
+
+if ![runto_main] {
+ return 0
+}
+
+set test "ptype atoi"
+gdb_test_multiple $test $test {
+ -re "type = int \\(const char \\*\\)\r\n$gdb_prompt $" {
+ pass $test
+ }
+ -re "type = int \\(\\)\r\n$gdb_prompt $" {
+ untested "$test (no DWARF)"
+ return 0
+ }
+ -re "type = <unknown return type> \\(\\)\r\n$gdb_prompt $" {
+ untested "$test (no DWARF)"
+ return 0
+ }
+}
+
+set addr ""
+set test "print strstr"
+gdb_test_multiple $test $test {
+ -re " = {<text gnu-indirect-function variable, no debug info>} (0x\[0-9a-f\]+) <strstr>\r\n$gdb_prompt $" {
+ set addr $expect_out(1,string)
+ pass $test
+ }
+ -re " = {<text gnu-indirect-function variable, no debug info>} (0x\[0-9a-f\]+) <__strstr>\r\n$gdb_prompt $" {
+ set addr $expect_out(1,string)
+ pass "$test (GDB workaround)"
+ }
+ -re " = {<text gnu-indirect-function variable, no debug info>} (0x\[0-9a-f\]+) <__libc_strstr>\r\n$gdb_prompt $" {
+ set addr $expect_out(1,string)
+ pass "$test (fixed glibc)"
+ }
+ -re " = {<text gnu-indirect-function variable, no debug info>} (0x\[0-9a-f\]+) <__libc_strstr_ifunc>\r\n$gdb_prompt $" {
+ set addr $expect_out(1,string)
+ pass "$test (fixed glibc)"
+ }
+ -re " = {char \\*\\(const char \\*, const char \\*\\)} 0x\[0-9a-f\]+ <strstr>\r\n$gdb_prompt $" {
+ untested "$test (gnu-ifunc not in use by glibc)"
+ return 0
+ }
+}
+
+set test "info sym"
+gdb_test_multiple "info sym $addr" $test {
+ -re "strstr in section \\.text of /lib\[^/\]*/libc.so.6\r\n$gdb_prompt $" {
+ pass $test
+ }
+ -re " = {char \\*\\(const char \\*, const char \\*\\)} 0x\[0-9a-f\]+ <strstr>\r\n$gdb_prompt $" {
+ # unexpected
+ xfail "$test (not in libc.so.6)"
+ return 0
+ }
+}
+
+set test "info addr strstr"
+gdb_test_multiple $test $test {
+ -re "Symbol \"strstr\" is a function at address $addr\\.\r\n$gdb_prompt $" {
+ fail "$test (DWARF for strstr)"
+ }
+ -re "Symbol \"strstr\" is at $addr in a file compiled without debugging\\.\r\n$gdb_prompt $" {
+ pass "$test"
+ }
+}
+
+set test "print strstr second time"
+gdb_test_multiple "print strstr" $test {
+ -re " = {<text gnu-indirect-function variable, no debug info>} $addr <strstr>\r\n$gdb_prompt $" {
+ pass $test
+ }
+ -re " = {<text gnu-indirect-function variable, no debug info>} $addr <__strstr>\r\n$gdb_prompt $" {
+ pass "$test (GDB workaround)"
+ }
+ -re " = {<text gnu-indirect-function variable, no debug info>} $addr <__libc_strstr>\r\n$gdb_prompt $" {
+ pass "$test (fixed glibc)"
+ }
+ -re " = {<text gnu-indirect-function variable, no debug info>} $addr <__libc_strstr_ifunc>\r\n$gdb_prompt $" {
+ pass "$test (fixed glibc)"
+ }
+ -re " = {void \\*\\(void\\)} 0x\[0-9a-f\]+ <strstr>\r\n$gdb_prompt $" {
+ fail $test
+ }
+}
+
+gdb_test {print (char *)strstr("abc","b")} { = 0x[0-9a-f]+ "bc"}
+gdb_test {print (char *)strstr("def","e")} { = 0x[0-9a-f]+ "ef"}

View File

@ -0,0 +1,138 @@
From 6c9e159dbd1a35aafa134fcd52982174236a8dd9 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Thu, 5 Oct 2023 23:22:11 +0200
Subject: [PATCH 3/3] [gdb/go] Handle v3 go_0 mangled prefix
With gcc-10 we have:
...
(gdb) break package2.Foo^M
Breakpoint 2 at 0x402563: file package2.go, line 5.^M
(gdb) PASS: gdb.go/package.exp: setting breakpoint 1
...
but with gcc-11:
...
gdb) break package2.Foo^M
Function "package2.Foo" not defined.^M
Make breakpoint pending on future shared library load? (y or [n]) n^M
(gdb) FAIL: gdb.go/package.exp: gdb_breakpoint: set breakpoint at package2.Foo
...
In the gcc-10 case, though the exec contains dwarf, it's not used to set the
breakpoint (which is an independent problem, filed as PR go/30941), instead
the minimal symbol information is used.
The minimal symbol information changed between gcc-10 and gcc-11:
...
$ nm a.out.10 | grep Foo
000000000040370d T go.package2.Foo
0000000000404e50 R go.package2.Foo..f
$ nm a.out.11 | grep Foo
0000000000403857 T go_0package2.Foo
0000000000405030 R go_0package2.Foo..f
...
A new v3 mangling scheme was used. The mangling schemes define a separator
character and mangling character:
- for v2, dot is used both as separator character and mangling character, and
- for v3, dot is used as separator character and underscore as mangling
character.
For more details, see [1] and [2].
In v3, "_0" demangles to ".". [ See gcc commit a01dda3c23b ("compiler, libgo:
change mangling scheme"), function Special_char_code::Special_char_code. ]
Handle the new go_0 prefix in unpack_mangled_go_symbol, which fixes the
test-case.
Note that this doesn't fix this regression:
...
$ gccgo-10 package2.go -c -g0
$ gccgo-10 package1.go package2.o -g0
$ gdb -q -batch a.out -ex "break go.package2.Foo"
Breakpoint 1 at 0x40370d
$ gccgo-11 package2.go -c -g0
$ gccgo-11 package1.go package2.o -g0
$ gdb -q -batch a.out -ex "break go.package2.Foo"
Function "go.package2.Foo" not defined.
...
With gcc-10, we set a breakpoint on the mangled minimal symbol. That
one has simply changed for gcc-11, so it's equivalent to using:
...
$ gdb -q -batch a.out -ex "break go_0package2.Foo"
Breakpoint 1 at 0x403857
...
which does work.
Tested on x86_64-linux:
- openSUSE Leap 15.4, using gccgo-7,
- openSUSE Tumbleweed, using gccgo-13.
PR go/27238
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27238
[1] https://go-review.googlesource.com/c/gofrontend/+/271726
[2] https://github.com/golang/go/issues/41862#issuecomment-707244103
---
gdb/go-lang.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index f9176ace71d..8a5568f56e0 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -233,16 +233,28 @@ unpack_mangled_go_symbol (const char *mangled_name,
libgo_.*: used by gccgo's runtime
Thus we don't support -fgo-prefix (except as used by the runtime). */
- if (!startswith (mangled_name, "go.")
- && !startswith (mangled_name, "libgo_"))
+ bool v3;
+ if (startswith (mangled_name, "go_0"))
+ /* V3 mangling detected, see
+ https://go-review.googlesource.com/c/gofrontend/+/271726 . */
+ v3 = true;
+ else if (startswith (mangled_name, "go.")
+ || startswith (mangled_name, "libgo_"))
+ v3 = false;
+ else
return NULL;
/* Quick check for whether a search may be fruitful. */
/* Ignore anything with @plt, etc. in it. */
if (strchr (mangled_name, '@') != NULL)
return NULL;
+
/* It must have at least two dots. */
- first_dot = strchr (mangled_name, '.');
+ if (v3)
+ first_dot = strchr (mangled_name, '0');
+ else
+ first_dot = strchr (mangled_name, '.');
+
if (first_dot == NULL)
return NULL;
/* Treat "foo.bar" as unmangled. It can collide with lots of other
@@ -263,6 +275,18 @@ unpack_mangled_go_symbol (const char *mangled_name,
gdb::unique_xmalloc_ptr<char> result = make_unique_xstrdup (mangled_name);
buf = result.get ();
+ if (v3)
+ {
+ /* Replace "go_0" with "\0go.". */
+ buf[0] = '\0';
+ buf[1] = 'g';
+ buf[2] = 'o';
+ buf[3] = '.';
+
+ /* Skip the '\0'. */
+ buf++;
+ }
+
/* Search backwards looking for "N<digit(s)>". */
p = buf + len;
saw_digit = method_type = NULL;
--
2.35.3

48
gdb-gstack.man Normal file
View File

@ -0,0 +1,48 @@
.\"
.\" gstack manual page.
.\" Copyright (c) 1999 Ross Thompson
.\" Copyright (c) 2001, 2002, 2004, 2008 Red Hat, Inc.
.\"
.\" Original author: Ross Thompson <ross@whatsis.com>
.\"
.\" 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 2, 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; see the file COPYING. If not, write to
.\" the Free Software Foundation, 59 Temple Place - Suite 330,
.\" Boston, MA 02111-1307, USA.
.\"
.TH GSTACK 1 "Feb 15 2008" "Red Hat Linux" "Linux Programmer's Manual"
.SH NAME
gstack \- print a stack trace of a running process
.SH SYNOPSIS
.B gstack
pid
.SH DESCRIPTION
\f3gstack\f1 attaches to the active process named by the \f3pid\f1 on
the command line, and prints out an execution stack trace. If ELF
symbols exist in the binary (usually the case unless you have run
strip(1)), then symbolic addresses are printed as well.
If the process is part of a thread group, then \f3gstack\f1 will print
out a stack trace for each of the threads in the group.
.SH SEE ALSO
nm(1), ptrace(2), gdb(1)
.SH AUTHORS
Ross Thompson <ross@whatsis.com>
Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>

View File

@ -0,0 +1,165 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-lineno-makeup-test.patch
;; Testcase for "Do not make up line information" fix by Daniel Jacobowitz.
;;=fedoratest
New testcase for:
https://bugzilla.redhat.com/show_bug.cgi?id=466222
(for the first / customer recommended fix)
and the upstream fix:
http://sourceware.org/ml/gdb-patches/2006-11/msg00253.html
[rfc] Do not make up line information
http://sourceware.org/ml/gdb-cvs/2006-11/msg00127.html
diff --git a/gdb/testsuite/gdb.base/lineno-makeup-func.c b/gdb/testsuite/gdb.base/lineno-makeup-func.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/lineno-makeup-func.c
@@ -0,0 +1,21 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2009 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/>. */
+
+void
+func (void)
+{
+}
diff --git a/gdb/testsuite/gdb.base/lineno-makeup.c b/gdb/testsuite/gdb.base/lineno-makeup.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/lineno-makeup.c
@@ -0,0 +1,35 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2009 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/>. */
+
+/* DW_AT_low_pc-DW_AT_high_pc should cover the function without line number
+ information (.debug_line) so we cannot use an external object file.
+
+ It must not be just a label as it would alias on the next function even for
+ correct GDB. Therefore some stub data must be placed there.
+
+ We need to provide a real stub function body as at least s390
+ (s390_analyze_prologue) would skip the whole body till reaching `main'. */
+
+extern void func (void);
+asm ("func: .incbin \"" BINFILENAME "\"");
+
+int
+main (void)
+{
+ func ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/lineno-makeup.exp b/gdb/testsuite/gdb.base/lineno-makeup.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/lineno-makeup.exp
@@ -0,0 +1,78 @@
+# Copyright 2009 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 testfile "lineno-makeup"
+set srcfuncfile ${testfile}-func.c
+set srcfile ${testfile}.c
+set objfuncfile [standard_output_file ${testfile}-func.o]
+set binfuncfile [standard_output_file ${testfile}-func.bin]
+set binfile [standard_output_file ${testfile}]
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfuncfile}" "${objfuncfile}" object {}] != "" } {
+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+set objcopy [catch "exec objcopy -O binary --only-section .text ${objfuncfile} ${binfuncfile}" output]
+verbose -log "objcopy=$objcopy: $output"
+if { $objcopy != 0 } {
+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+set binfuncfilesize [file size $binfuncfile]
+verbose -log "file size $binfuncfile = $binfuncfilesize"
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug additional_flags=-DBINFILENAME=\"$binfuncfile\"]] != "" } {
+ gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+set b_addr ""
+set test "break func"
+gdb_test_multiple $test $test {
+ -re "Breakpoint \[0-9\]+ at (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
+ set b_addr $expect_out(1,string)
+ pass $test
+ }
+ -re "Breakpoint \[0-9\]+ at (0x\[0-9a-f\]+): .*\r\n$gdb_prompt $" {
+ set b_addr $expect_out(1,string)
+ fail $test
+ }
+}
+verbose -log "b_addr=<$b_addr>"
+
+set p_addr ""
+set test "print func"
+gdb_test_multiple $test $test {
+ -re "\\$\[0-9\]+ = {<text variable, no debug info>} (0x\[0-9a-f\]+) <func>\r\n$gdb_prompt $" {
+ set p_addr $expect_out(1,string)
+ pass $test
+ }
+}
+verbose -log "p_addr=<$p_addr>"
+
+set test "break address belongs to func"
+if {$b_addr == $p_addr} {
+ pass "$test (exact match)"
+} else {
+ set skip [expr $b_addr - $p_addr]
+ if {$skip > 0 && $skip < $binfuncfilesize} {
+ pass "$test (prologue skip by $skip bytes)"
+ } else {
+ fail $test
+ }
+}

224
gdb-linux_perf-bundle.patch Normal file
View File

@ -0,0 +1,224 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-linux_perf-bundle.patch
;; [dts+el7] [x86*] Bundle linux_perf.h for libipt (RH BZ 1256513).
;;=fedora
diff --git a/gdb/gdb.c b/gdb/gdb.c
--- a/gdb/gdb.c
+++ b/gdb/gdb.c
@@ -20,11 +20,19 @@
#include "main.h"
#include "interps.h"
+#ifdef PERF_ATTR_SIZE_VER5_BUNDLE
+extern "C" void __libipt_init(void);
+#endif
+
int
main (int argc, char **argv)
{
struct captured_main_args args;
+#ifdef PERF_ATTR_SIZE_VER5_BUNDLE
+ __libipt_init();
+#endif
+
memset (&args, 0, sizeof args);
args.argc = argc;
args.argv = argv;
diff --git a/gdb/nat/linux-btrace.h b/gdb/nat/linux-btrace.h
--- a/gdb/nat/linux-btrace.h
+++ b/gdb/nat/linux-btrace.h
@@ -27,6 +27,177 @@
# include <linux/perf_event.h>
#endif
+#ifdef PERF_ATTR_SIZE_VER5_BUNDLE
+#ifndef HAVE_LINUX_PERF_EVENT_H
+# error "PERF_ATTR_SIZE_VER5_BUNDLE && !HAVE_LINUX_PERF_EVENT_H"
+#endif
+#ifndef PERF_ATTR_SIZE_VER5
+#define PERF_ATTR_SIZE_VER5
+#define perf_event_mmap_page perf_event_mmap_page_bundle
+// kernel-headers-3.10.0-493.el7.x86_64/usr/include/linux/perf_event.h
+/*
+ * Structure of the page that can be mapped via mmap
+ */
+struct perf_event_mmap_page {
+ __u32 version; /* version number of this structure */
+ __u32 compat_version; /* lowest version this is compat with */
+
+ /*
+ * Bits needed to read the hw events in user-space.
+ *
+ * u32 seq, time_mult, time_shift, index, width;
+ * u64 count, enabled, running;
+ * u64 cyc, time_offset;
+ * s64 pmc = 0;
+ *
+ * do {
+ * seq = pc->lock;
+ * barrier()
+ *
+ * enabled = pc->time_enabled;
+ * running = pc->time_running;
+ *
+ * if (pc->cap_usr_time && enabled != running) {
+ * cyc = rdtsc();
+ * time_offset = pc->time_offset;
+ * time_mult = pc->time_mult;
+ * time_shift = pc->time_shift;
+ * }
+ *
+ * index = pc->index;
+ * count = pc->offset;
+ * if (pc->cap_user_rdpmc && index) {
+ * width = pc->pmc_width;
+ * pmc = rdpmc(index - 1);
+ * }
+ *
+ * barrier();
+ * } while (pc->lock != seq);
+ *
+ * NOTE: for obvious reason this only works on self-monitoring
+ * processes.
+ */
+ __u32 lock; /* seqlock for synchronization */
+ __u32 index; /* hardware event identifier */
+ __s64 offset; /* add to hardware event value */
+ __u64 time_enabled; /* time event active */
+ __u64 time_running; /* time event on cpu */
+ union {
+ __u64 capabilities;
+ struct {
+ __u64 cap_bit0 : 1, /* Always 0, deprecated, see commit 860f085b74e9 */
+ cap_bit0_is_deprecated : 1, /* Always 1, signals that bit 0 is zero */
+
+ cap_user_rdpmc : 1, /* The RDPMC instruction can be used to read counts */
+ cap_user_time : 1, /* The time_* fields are used */
+ cap_user_time_zero : 1, /* The time_zero field is used */
+ cap_____res : 59;
+ };
+ };
+
+ /*
+ * If cap_user_rdpmc this field provides the bit-width of the value
+ * read using the rdpmc() or equivalent instruction. This can be used
+ * to sign extend the result like:
+ *
+ * pmc <<= 64 - width;
+ * pmc >>= 64 - width; // signed shift right
+ * count += pmc;
+ */
+ __u16 pmc_width;
+
+ /*
+ * If cap_usr_time the below fields can be used to compute the time
+ * delta since time_enabled (in ns) using rdtsc or similar.
+ *
+ * u64 quot, rem;
+ * u64 delta;
+ *
+ * quot = (cyc >> time_shift);
+ * rem = cyc & (((u64)1 << time_shift) - 1);
+ * delta = time_offset + quot * time_mult +
+ * ((rem * time_mult) >> time_shift);
+ *
+ * Where time_offset,time_mult,time_shift and cyc are read in the
+ * seqcount loop described above. This delta can then be added to
+ * enabled and possible running (if index), improving the scaling:
+ *
+ * enabled += delta;
+ * if (index)
+ * running += delta;
+ *
+ * quot = count / running;
+ * rem = count % running;
+ * count = quot * enabled + (rem * enabled) / running;
+ */
+ __u16 time_shift;
+ __u32 time_mult;
+ __u64 time_offset;
+ /*
+ * If cap_usr_time_zero, the hardware clock (e.g. TSC) can be calculated
+ * from sample timestamps.
+ *
+ * time = timestamp - time_zero;
+ * quot = time / time_mult;
+ * rem = time % time_mult;
+ * cyc = (quot << time_shift) + (rem << time_shift) / time_mult;
+ *
+ * And vice versa:
+ *
+ * quot = cyc >> time_shift;
+ * rem = cyc & (((u64)1 << time_shift) - 1);
+ * timestamp = time_zero + quot * time_mult +
+ * ((rem * time_mult) >> time_shift);
+ */
+ __u64 time_zero;
+ __u32 size; /* Header size up to __reserved[] fields. */
+
+ /*
+ * Hole for extension of the self monitor capabilities
+ */
+
+ __u8 __reserved[118*8+4]; /* align to 1k. */
+
+ /*
+ * Control data for the mmap() data buffer.
+ *
+ * User-space reading the @data_head value should issue an smp_rmb(),
+ * after reading this value.
+ *
+ * When the mapping is PROT_WRITE the @data_tail value should be
+ * written by userspace to reflect the last read data, after issueing
+ * an smp_mb() to separate the data read from the ->data_tail store.
+ * In this case the kernel will not over-write unread data.
+ *
+ * See perf_output_put_handle() for the data ordering.
+ *
+ * data_{offset,size} indicate the location and size of the perf record
+ * buffer within the mmapped area.
+ */
+ __u64 data_head; /* head in the data section */
+ __u64 data_tail; /* user-space written tail */
+ __u64 data_offset; /* where the buffer starts */
+ __u64 data_size; /* data buffer size */
+
+ /*
+ * AUX area is defined by aux_{offset,size} fields that should be set
+ * by the userspace, so that
+ *
+ * aux_offset >= data_offset + data_size
+ *
+ * prior to mmap()ing it. Size of the mmap()ed area should be aux_size.
+ *
+ * Ring buffer pointers aux_{head,tail} have the same semantics as
+ * data_{head,tail} and same ordering rules apply.
+ */
+ __u64 aux_head;
+ __u64 aux_tail;
+ __u64 aux_offset;
+ __u64 aux_size;
+};
+#endif // PERF_ATTR_SIZE_VER5
+#endif // PERF_ATTR_SIZE_VER5_BUNDLE
+
struct target_ops;
#if HAVE_LINUX_PERF_EVENT_H
diff --git a/gdbsupport/common.m4 b/gdbsupport/common.m4
--- a/gdbsupport/common.m4
+++ b/gdbsupport/common.m4
@@ -166,7 +166,7 @@ AC_DEFUN([GDB_AC_COMMON], [
AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
#include <linux/perf_event.h>
#ifndef PERF_ATTR_SIZE_VER5
- # error
+ // error // PERF_ATTR_SIZE_VER5_BUNDLE is not available here - Fedora+RHEL
#endif
]])], [perf_event=yes], [perf_event=no])
if test "$perf_event" != yes; then

View File

@ -0,0 +1,62 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-opcodes-clflushopt-test.patch
;; Test clflushopt instruction decode (for RH BZ 1262471).
;;=fedoratest
diff --git a/gdb/testsuite/gdb.arch/amd64-clflushopt.S b/gdb/testsuite/gdb.arch/amd64-clflushopt.S
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-clflushopt.S
@@ -0,0 +1,19 @@
+/* Copyright 2016 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. */
+
+_start: .globl _start
+ clflushopt (%edi)
diff --git a/gdb/testsuite/gdb.arch/amd64-clflushopt.exp b/gdb/testsuite/gdb.arch/amd64-clflushopt.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-clflushopt.exp
@@ -0,0 +1,25 @@
+# Copyright 2016 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/>.
+
+if { ![istarget "x86_64-*-*"] && ![istarget "i?86-*-*"] } then {
+ verbose "Skipping amd64 clflushopt test."
+ return
+}
+
+if [prepare_for_testing amd64-clflushopt.exp amd64-clflushopt amd64-clflushopt.S [list debug "additional_flags=-nostdlib"]] {
+ return -1
+}
+
+gdb_test "disas _start" "Dump of assembler code for function _start:\r\n *0x\[0-9a-f\]+ <\[+\]0>:\tclflushopt \\(%edi\\)\r\nEnd of assembler dump\\." "clflushopt"

752
gdb-orphanripper.c Normal file
View File

@ -0,0 +1,752 @@
/*
* Copyright 2006-2007 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Reap any leftover children possibly holding file descriptors.
* Children are identified by the stale file descriptor or PGID / SID.
* Both can be missed but only the stale file descriptors are important for us.
* PGID / SID may be set by the children on their own.
* If we fine a candidate we kill it will all its process tree (grandchildren).
* The child process is run with `2>&1' redirection (due to forkpty(3)).
* 2007-07-10 Jan Kratochvil <jan.kratochvil@redhat.com>
*/
/* For getpgid(2). */
#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <fcntl.h>
#include <assert.h>
#include <pty.h>
#include <poll.h>
#include <sys/stat.h>
#define LENGTH(x) (sizeof (x) / sizeof (*(x)))
static const char *progname;
static volatile pid_t child;
static void signal_chld (int signo)
{
}
static volatile int signal_alrm_hit = 0;
static void signal_alrm (int signo)
{
signal_alrm_hit = 1;
}
static char childptyname[LINE_MAX];
static void print_child_error (const char *reason, char **argv)
{
char **sp;
fprintf (stderr, "%s: %d %s:", progname, (int) child, reason);
for (sp = argv; *sp != NULL; sp++)
{
fputc (' ', stderr);
fputs (*sp, stderr);
}
fputc ('\n', stderr);
}
static int read_out (int amaster)
{
char buf[LINE_MAX];
ssize_t buf_got;
buf_got = read (amaster, buf, sizeof buf);
if (buf_got == 0)
return 0;
/* Weird but at least after POLLHUP we get EIO instead of just EOF. */
if (buf_got == -1 && errno == EIO)
return 0;
if (buf_got == -1 && errno == EAGAIN)
return 0;
if (buf_got < 0)
{
perror ("read (amaster)");
exit (EXIT_FAILURE);
}
if (write (STDOUT_FILENO, buf, buf_got) != buf_got)
{
perror ("write(2)");
exit (EXIT_FAILURE);
}
return 1;
}
/* kill (child, 0) == 0 sometimes even when CHILD's state is already "Z". */
static int child_exited (void)
{
char buf[200];
int fd, i, retval;
ssize_t got;
char state[3];
snprintf (buf, sizeof (buf), "/proc/%ld/stat", (long) child);
fd = open (buf, O_RDONLY);
if (fd == -1)
{
perror ("open (/proc/CHILD/stat)");
exit (EXIT_FAILURE);
}
got = read (fd, buf, sizeof(buf));
if (got <= 0)
{
perror ("read (/proc/CHILD/stat)");
exit (EXIT_FAILURE);
}
if (close (fd) != 0)
{
perror ("close (/proc/CHILD/stat)");
exit (EXIT_FAILURE);
}
/* RHEL-5 does not support %ms. */
i = sscanf (buf, "%*d%*s%2s", state);
if (i != 1)
{
perror ("sscanf (/proc/CHILD/stat)");
exit (EXIT_FAILURE);
}
retval = strcmp (state, "Z") == 0;
return retval;
}
static int spawn (char **argv, int timeout)
{
pid_t child_got;
int status, amaster, i, rc;
struct sigaction act;
sigset_t set;
struct termios termios;
unsigned alarm_orig;
/* We do not use signal(2) to be sure we do not have SA_RESTART. */
memset (&act, 0, sizeof (act));
act.sa_handler = signal_chld;
i = sigemptyset (&act.sa_mask);
assert (i == 0);
act.sa_flags = 0; /* !SA_RESTART */
i = sigaction (SIGCHLD, &act, NULL);
assert (i == 0);
i = sigemptyset (&set);
assert (i == 0);
i = sigaddset (&set, SIGCHLD);
assert (i == 0);
i = sigprocmask (SIG_SETMASK, &set, NULL);
assert (i == 0);
/* With TERMP passed as NULL we get "\n" -> "\r\n". */
termios.c_iflag = IGNBRK | IGNPAR;
termios.c_oflag = 0;
termios.c_cflag = CS8 | CREAD | CLOCAL | HUPCL | B9600;
termios.c_lflag = IEXTEN | NOFLSH;
memset (termios.c_cc, _POSIX_VDISABLE, sizeof (termios.c_cc));
termios.c_cc[VTIME] = 0;
termios.c_cc[VMIN ] = 1;
cfmakeraw (&termios);
#ifdef FLUSHO
/* Workaround a readline deadlock bug in _get_tty_settings(). */
termios.c_lflag &= ~FLUSHO;
#endif
child = forkpty (&amaster, childptyname, &termios, NULL);
switch (child)
{
case -1:
perror ("forkpty(3)");
exit (EXIT_FAILURE);
case 0:
/* Do not replace STDIN as inferiors query its termios. */
#if 0
i = close (STDIN_FILENO);
assert (i == 0);
i = open ("/dev/null", O_RDONLY);
assert (i == STDIN_FILENO);
#endif
i = sigemptyset (&set);
assert (i == 0);
i = sigprocmask (SIG_SETMASK, &set, NULL);
assert (i == 0);
/* Do not setpgrp(2) in the parent process as the process-group
is shared for the whole sh(1) pipeline we could be a part
of. The process-group is set according to PID of the first
command in the pipeline.
We would rip even vi(1) in the case of:
./orphanripper sh -c 'sleep 1&' | vi -
*/
/* Do not setpgrp(2) as our pty would not be ours and we would
get `SIGSTOP' later, particularly after spawning gdb(1).
setsid(3) was already executed by forkpty(3) and it would fail if
executed again. */
if (getpid() != getpgrp ())
{
perror ("getpgrp(2)");
exit (EXIT_FAILURE);
}
execvp (argv[0], argv);
perror ("execvp(2)");
exit (EXIT_FAILURE);
default:
break;
}
i = fcntl (amaster, F_SETFL, O_RDWR | O_NONBLOCK);
if (i != 0)
{
perror ("fcntl (amaster, F_SETFL, O_NONBLOCK)");
exit (EXIT_FAILURE);
}
/* We do not use signal(2) to be sure we do not have SA_RESTART. */
act.sa_handler = signal_alrm;
i = sigaction (SIGALRM, &act, NULL);
assert (i == 0);
alarm_orig = alarm (timeout);
assert (alarm_orig == 0);
i = sigemptyset (&set);
assert (i == 0);
while (!signal_alrm_hit)
{
struct pollfd pollfd;
pollfd.fd = amaster;
pollfd.events = POLLIN;
i = ppoll (&pollfd, 1, NULL, &set);
if (i == -1 && errno == EINTR)
{
if (child_exited ())
break;
/* Non-CHILD child may have exited. */
continue;
}
assert (i == 1);
/* Data available? Process it first. */
if (pollfd.revents & POLLIN)
{
if (!read_out (amaster))
{
fprintf (stderr, "%s: Unexpected EOF\n", progname);
exit (EXIT_FAILURE);
}
}
if (pollfd.revents & POLLHUP)
break;
if ((pollfd.revents &= ~POLLIN) != 0)
{
fprintf (stderr, "%s: ppoll(2): revents 0x%x\n", progname,
(unsigned) pollfd.revents);
exit (EXIT_FAILURE);
}
/* Child exited? */
if (child_exited ())
break;
}
if (signal_alrm_hit)
{
i = kill (child, SIGKILL);
assert (i == 0);
}
else
alarm (0);
/* WNOHANG still could fail. */
child_got = waitpid (child, &status, 0);
if (child != child_got)
{
fprintf (stderr, "waitpid (%d) = %d: %m\n", (int) child, (int) child_got);
exit (EXIT_FAILURE);
}
if (signal_alrm_hit)
{
char *buf;
if (asprintf (&buf, "Timed out after %d seconds", timeout) != -1)
{
print_child_error (buf, argv);
free (buf);
}
rc = 128 + SIGALRM;
}
else if (WIFEXITED (status))
rc = WEXITSTATUS (status);
else if (WIFSIGNALED (status))
{
print_child_error (strsignal (WTERMSIG (status)), argv);
rc = 128 + WTERMSIG (status);
}
else if (WIFSTOPPED (status))
{
fprintf (stderr, "waitpid (%d): WIFSTOPPED - WSTOPSIG is %d\n",
(int) child, WSTOPSIG (status));
exit (EXIT_FAILURE);
}
else
{
fprintf (stderr, "waitpid (%d): !WIFEXITED (%d)\n", (int) child, status);
exit (EXIT_FAILURE);
}
/* Not used in fact. */
i = sigprocmask (SIG_SETMASK, &set, NULL);
assert (i == 0);
/* Do not unset O_NONBLOCK as a stale child (the whole purpose of this
program) having open its output pty would block us in read_out. */
#if 0
i = fcntl (amaster, F_SETFL, O_RDONLY /* !O_NONBLOCK */);
if (i != 0)
{
perror ("fcntl (amaster, F_SETFL, O_RDONLY /* !O_NONBLOCK */)");
exit (EXIT_FAILURE);
}
#endif
while (read_out (amaster));
/* Do not close the master FD as the child would have `/dev/pts/23 (deleted)'
entries which are not expected (and expecting ` (deleted)' would be
a race. */
#if 0
i = close (amaster);
if (i != 0)
{
perror ("close (forkpty ()'s amaster)");
exit (EXIT_FAILURE);
}
#endif
return rc;
}
/* Detected commandline may look weird due to a race:
Original command:
./orphanripper sh -c 'sleep 1&' &
Correct output:
[1] 29610
./orphanripper: Killed -9 orphan PID 29612 (PGID 29611): sleep 1
Raced output (sh(1) child still did not update its argv[]):
[1] 29613
./orphanripper: Killed -9 orphan PID 29615 (PGID 29614): sh -c sleep 1&
We could delay a bit before ripping the children. */
static const char *read_cmdline (pid_t pid)
{
char cmdline_fname[32];
static char cmdline[LINE_MAX];
int fd;
ssize_t got;
char *s;
if (snprintf (cmdline_fname, sizeof cmdline_fname, "/proc/%d/cmdline",
(int) pid) < 0)
return NULL;
fd = open (cmdline_fname, O_RDONLY);
if (fd == -1)
{
/* It may have already exited - ENOENT. */
#if 0
fprintf (stderr, "%s: open (\"%s\"): %m\n", progname, cmdline_fname);
#endif
return NULL;
}
got = read (fd, cmdline, sizeof (cmdline) - 1);
if (got == -1)
fprintf (stderr, "%s: read (\"%s\"): %m\n", progname,
cmdline_fname);
if (close (fd) != 0)
fprintf (stderr, "%s: close (\"%s\"): %m\n", progname,
cmdline_fname);
if (got < 0)
return NULL;
/* Convert '\0' argument delimiters to spaces. */
for (s = cmdline; s < cmdline + got; s++)
if (!*s)
*s = ' ';
/* Trim the trailing spaces (typically single '\0'->' '). */
while (s > cmdline && isspace (s[-1]))
s--;
*s = 0;
return cmdline;
}
static int dir_scan (const char *dirname,
int (*callback) (struct dirent *dirent, const char *pathname))
{
DIR *dir;
struct dirent *dirent;
int rc = 0;
dir = opendir (dirname);
if (dir == NULL)
{
if (errno == EACCES || errno == ENOENT)
return rc;
fprintf (stderr, "%s: opendir (\"%s\"): %m\n", progname, dirname);
exit (EXIT_FAILURE);
}
while ((errno = 0, dirent = readdir (dir)))
{
char pathname[LINE_MAX];
int pathname_len;
pathname_len = snprintf (pathname, sizeof pathname, "%s/%s",
dirname, dirent->d_name);
if (pathname_len <= 0 || pathname_len >= (int) sizeof pathname)
{
fprintf (stderr, "entry file name too long: `%s' / `%s'\n",
dirname, dirent->d_name);
continue;
}
/* RHEL-4.5 on s390x never fills in D_TYPE. */
if (dirent->d_type == DT_UNKNOWN)
{
struct stat statbuf;
int i;
/* We are not interested in the /proc/PID/fd/ links targets. */
i = lstat (pathname, &statbuf);
if (i == -1)
{
if (errno == EACCES || errno == ENOENT)
continue;
fprintf (stderr, "%s: stat (\"%s\"): %m\n", progname, pathname);
exit (EXIT_FAILURE);
}
if (S_ISDIR (statbuf.st_mode))
dirent->d_type = DT_DIR;
if (S_ISLNK (statbuf.st_mode))
dirent->d_type = DT_LNK;
/* No other D_TYPE types used in this code. */
}
rc = (*callback) (dirent, pathname);
if (rc != 0)
{
errno = 0;
break;
}
}
if (errno != 0)
{
fprintf (stderr, "%s: readdir (\"%s\"): %m\n", progname, dirname);
exit (EXIT_FAILURE);
}
if (closedir (dir) != 0)
{
fprintf (stderr, "%s: closedir (\"%s\"): %m\n", progname, dirname);
exit (EXIT_FAILURE);
}
return rc;
}
static int fd_fs_scan (pid_t pid, int (*func) (pid_t pid, const char *link))
{
char dirname[64];
if (snprintf (dirname, sizeof dirname, "/proc/%d/fd", (int) pid) < 0)
{
perror ("snprintf(3)");
exit (EXIT_FAILURE);
}
int callback (struct dirent *dirent, const char *pathname)
{
char buf[LINE_MAX];
ssize_t buf_len;
if ((dirent->d_type != DT_DIR && dirent->d_type != DT_LNK)
|| (dirent->d_type == DT_DIR && strcmp (dirent->d_name, ".") != 0
&& strcmp (dirent->d_name, "..") != 0)
|| (dirent->d_type == DT_LNK && strspn (dirent->d_name, "0123456789")
!= strlen (dirent->d_name)))
{
fprintf (stderr, "Unexpected entry \"%s\" (d_type %u)"
" on readdir (\"%s\"): %m\n",
dirent->d_name, (unsigned) dirent->d_type, dirname);
return 0;
}
if (dirent->d_type == DT_DIR)
return 0;
buf_len = readlink (pathname, buf, sizeof buf - 1);
if (buf_len <= 0 || buf_len >= (ssize_t) sizeof buf - 1)
{
if (errno != ENOENT && errno != EACCES)
fprintf (stderr, "Error reading link \"%s\": %m\n", pathname);
return 0;
}
buf[buf_len] = 0;
return (*func) (pid, buf);
}
return dir_scan (dirname, callback);
}
static void pid_fs_scan (void (*func) (pid_t pid, void *data), void *data)
{
int callback (struct dirent *dirent, const char *pathname)
{
if (dirent->d_type != DT_DIR
|| strspn (dirent->d_name, "0123456789") != strlen (dirent->d_name))
return 0;
(*func) (atoi (dirent->d_name), data);
return 0;
}
dir_scan ("/proc", callback);
}
static int rip_check_ptyname (pid_t pid, const char *link)
{
assert (pid != getpid ());
return strcmp (link, childptyname) == 0;
}
struct pid
{
struct pid *next;
pid_t pid;
};
static struct pid *pid_list;
static int pid_found (pid_t pid)
{
struct pid *entry;
for (entry = pid_list; entry != NULL; entry = entry->next)
if (entry->pid == pid)
return 1;
return 0;
}
/* Single pass is not enough, a (multithreaded) process was seen to survive.
Repeated killing of the same process is not enough, zombies can be killed.
*/
static int cleanup_acted;
static void pid_record (pid_t pid)
{
struct pid *entry;
if (pid_found (pid))
return;
cleanup_acted = 1;
entry = malloc (sizeof (*entry));
if (entry == NULL)
{
fprintf (stderr, "%s: malloc: %m\n", progname);
exit (EXIT_FAILURE);
}
entry->pid = pid;
entry->next = pid_list;
pid_list = entry;
}
static void pid_forall (void (*func) (pid_t pid))
{
struct pid *entry;
for (entry = pid_list; entry != NULL; entry = entry->next)
(*func) (entry->pid);
}
/* Returns 0 on failure. */
static pid_t pid_get_parent (pid_t pid)
{
char fname[64];
FILE *f;
char line[LINE_MAX];
pid_t retval = 0;
if (snprintf (fname, sizeof fname, "/proc/%d/status", (int) pid) < 0)
{
perror ("snprintf(3)");
exit (EXIT_FAILURE);
}
f = fopen (fname, "r");
if (f == NULL)
{
return 0;
}
while (errno = 0, fgets (line, sizeof line, f) == line)
{
if (strncmp (line, "PPid:\t", sizeof "PPid:\t" - 1) != 0)
continue;
retval = atoi (line + sizeof "PPid:\t" - 1);
errno = 0;
break;
}
if (errno != 0)
{
fprintf (stderr, "%s: fgets (\"%s\"): %m\n", progname, fname);
exit (EXIT_FAILURE);
}
if (fclose (f) != 0)
{
fprintf (stderr, "%s: fclose (\"%s\"): %m\n", progname, fname);
exit (EXIT_FAILURE);
}
return retval;
}
static void killtree (pid_t pid);
static void killtree_pid_fs_scan (pid_t pid, void *data)
{
pid_t parent_pid = *(pid_t *) data;
/* Do not optimize it as we could miss some newly spawned processes.
Always traverse all the leaves. */
#if 0
/* Optimization. */
if (pid_found (pid))
return;
#endif
if (pid_get_parent (pid) != parent_pid)
return;
killtree (pid);
}
static void killtree (pid_t pid)
{
pid_record (pid);
pid_fs_scan (killtree_pid_fs_scan, &pid);
}
static void rip_pid_fs_scan (pid_t pid, void *data)
{
pid_t pgid;
/* Shouldn't happen. */
if (pid == getpid ())
return;
/* Check both PGID and the stale file descriptors. */
pgid = getpgid (pid);
if (pgid == child
|| fd_fs_scan (pid, rip_check_ptyname) != 0)
killtree (pid);
}
static void killproc (pid_t pid)
{
const char *cmdline;
cmdline = read_cmdline (pid);
/* Avoid printing the message for already gone processes. */
if (kill (pid, 0) != 0 && errno == ESRCH)
return;
if (cmdline == NULL)
cmdline = "<error>";
fprintf (stderr, "%s: Killed -9 orphan PID %d: %s\n", progname, (int) pid, cmdline);
if (kill (pid, SIGKILL) == 0)
cleanup_acted = 1;
else if (errno != ESRCH)
fprintf (stderr, "%s: kill (%d, SIGKILL): %m\n", progname, (int) pid);
/* RHEL-3 kernels cannot SIGKILL a `T (stopped)' process. */
kill (pid, SIGCONT);
/* Do not waitpid(2) as it cannot be our direct descendant and it gets
cleaned up by init(8). */
#if 0
pid_t pid_got;
pid_got = waitpid (pid, NULL, 0);
if (pid != pid_got)
{
fprintf (stderr, "%s: waitpid (%d) != %d: %m\n", progname,
(int) pid, (int) pid_got);
return;
}
#endif
}
static void rip (void)
{
cleanup_acted = 0;
do
{
if (cleanup_acted)
usleep (1000000 / 10);
cleanup_acted = 0;
pid_fs_scan (rip_pid_fs_scan, NULL);
pid_forall (killproc);
}
while (cleanup_acted);
}
int main (int argc, char **argv)
{
int timeout = 0;
int rc;
progname = *argv++;
argc--;
if (argc < 1 || strcmp (*argv, "-h") == 0
|| strcmp (*argv, "--help") == 0)
{
puts ("Syntax: orphanripper [-t <seconds>] <execvp(3) commandline>");
exit (EXIT_FAILURE);
}
if ((*argv)[0] == '-' && (*argv)[1] == 't')
{
char *timeout_s = NULL;
if ((*argv)[2] == 0)
timeout_s = *++argv;
else if (isdigit ((*argv)[2]))
timeout_s = (*argv) + 2;
if (timeout_s != NULL)
{
long l;
char *endptr;
argv++;
l = strtol (timeout_s, &endptr, 0);
timeout = l;
if ((endptr != NULL && *endptr != 0) || timeout < 0 || timeout != l)
{
fprintf (stderr, "%s: Invalid timeout value: %s\n", progname,
timeout_s);
exit (EXIT_FAILURE);
}
}
}
rc = spawn (argv, timeout);
rip ();
return rc;
}

View File

@ -0,0 +1,453 @@
[gdb/python] FinishBreakPoint update
I.
Consider the python gdb.FinishBreakpoint class, an extension of the
gdb.Breakpoint class.
It sets a temporary breakpoint on the return address of a frame.
This type of breakpoints is thread-specific.
II.
If the FinishBreakpoint is hit, it is deleted, and the method return_value
can be used to get the value returned by the function.
Let's demonstrate this:
...
$ cat -n test.c
1 int foo (int a) { return a + 2; }
2 int main () { return foo (1); }
$ gcc -g test.c
$ gdb -q -batch a.out -ex "set trace-commands on" -ex "tbreak foo" -ex run \
-ex "python bp = gdb.FinishBreakpoint()" -ex "info breakpoints" \
-ex continue -ex "info breakpoints" -ex "python print (bp.return_value)"
+tbreak foo
Temporary breakpoint 1 at 0x40049e: file test.c, line 1.
+run
Temporary breakpoint 1, foo (a=1) at test.c:1
1 int foo (int a) { return a + 2; }
+python bp = gdb.FinishBreakpoint()
Temporary breakpoint 2 at 0x4004b4: file test.c, line 2.
+info breakpoints
Num Type Disp Enb Address What
2 breakpoint del y 0x004004b4 in main at test.c:2 thread 1
stop only in thread 1
+continue
Temporary breakpoint 2, 0x004004b4 in main () at test.c:2
2 int main () { return foo (1); }
+info breakpoints
No breakpoints or watchpoints.
+python print (bp.return_value)
3
...
III.
Another possibility is that the FinishBreakpoint is not hit, because the
function did not terminate, f.i. because of longjmp, C++ exceptions, or GDB
return command.
Let's demonstrate this, using C++ exceptions:
...
$ cat -n test.c
1 int foo (int a) { throw 1; return a + 2; }
2 int main () {
3 try { return foo (1); } catch (...) {};
4 return 1;
5 }
$ g++ -g test.c
$ gdb -q -batch a.out -ex "set trace-commands on" -ex "tbreak foo" -ex run \
-ex "python bp = gdb.FinishBreakpoint()" -ex "info breakpoints" \
-ex continue -ex "info breakpoints" -ex "python print (bp.return_value)"
+tbreak foo
Temporary breakpoint 1 at 0x400712: file test.c, line 1.
+run
Temporary breakpoint 1, foo (a=1) at test.c:1
1 int foo (int a) { throw 1; return a + 2; }
+python bp = gdb.FinishBreakpoint()
Temporary breakpoint 2 at 0x400742: file test.c, line 3.
+info breakpoints
Num Type Disp Enb Address What
2 breakpoint del y 0x00400742 in main() at test.c:3 thread 1
stop only in thread 1
+continue
[Inferior 1 (process 25269) exited with code 01]
Thread-specific breakpoint 2 deleted - thread 1 no longer in the thread list.
+info breakpoints
No breakpoints or watchpoints.
+python print (bp.return_value)
None
...
Indeed, we do not hit the FinishBreakpoint. Instead, it's deleted when the
thread disappears, like any other thread-specific breakpoint.
I think this is a bug: the deletion is meant to be handled by FinishBreakpoint
itself.
IV.
Fix aforementioned bug by:
- adding an observer of the thread_exit event in FinishBreakpoint
- making sure that this observer is called before the
remove_threaded_breakpoints observer of that same event.
This changes the behaviour to:
...
+continue
[Inferior 1 (process 30256) exited with code 01]
+info breakpoints
No breakpoints or watchpoints.
+python print (bp.return_value)
None
...
V.
An out_of_scope callback can be defined to make this more verbose:
...
$ cat fbp.py
class FBP(gdb.FinishBreakpoint):
def __init__(self):
gdb.FinishBreakpoint.__init__(self)
def out_of_scope(self):
try:
frame = gdb.selected_frame ()
sal = frame.find_sal ()
print ("out_of_scope triggered at %s:%s"
% (sal.symtab.fullname(), sal.line))
except gdb.error as e:
print ("out_of_scope triggered at thread/inferior exit")
...
and using that gets us:
...
+continue
[Inferior 1 (process 30742) exited with code 01]
out_of_scope triggered at thread/inferior exit
+info breakpoints
No breakpoints or watchpoints.
+python print (bp.return_value)
None
...
VI.
This out_of_scope event can be triggered earlier than inferior/thread exit.
Let's demonstrate this:
...
$ cat -n test.c
1 int bar (int a) { throw 1; return a + 2; }
2 int foo (int a) {
3 int res = a;
4 try
5 {
6 res += bar (1);
7 }
8 catch (...)
9 {
10 }
11 return res;
12 }
13 int main () {
14 int res = 0;
15 res += foo (1);
16 res += 2;
17 return res * 2;
18 }
$ g++ -g test.c
$ gdb -q -batch -ex "source fbp.py" a.out -ex "set trace-commands on" \
-ex "tbreak bar" -ex run -ex "python bp = FBP()" -ex "info breakpoints" \
-ex "tbreak 16" -ex continue -ex "info breakpoints" \
-ex "python print (bp.return_value)"
+tbreak bar
Temporary breakpoint 1 at 0x400712: file test.c, line 1.
+run
Temporary breakpoint 1, bar (a=1) at test.c:1
1 int bar (int a) { throw 1; return a + 2; }
+python bp = FBP()
Temporary breakpoint 2 at 0x40074f: file test.c, line 6.
+info breakpoints
Num Type Disp Enb Address What
2 breakpoint del y 0x0040074f in foo(int) at test.c:6 thread 1
stop only in thread 1
+tbreak 16
Temporary breakpoint 3 at 0x400784: file test.c, line 16.
+continue
Temporary breakpoint 3, main () at test.c:16
16 res += 2;
out_of_scope triggered at /home/vries/gdb_versions/devel/test.c:16
+info breakpoints
No breakpoints or watchpoints.
+python print (bp.return_value)
None
...
Note that the out_of_scope event triggers at the breakpoint we set at
test.c:16. If we'd set that breakpoint at line 17, the out_of_scope event
would trigger at line 17 instead.
Also note that it can't be triggered earlier, say by setting the breakpoint in
foo at line 11. We would get instead "out_of_scope triggered at
thread/inferior exit".
VII.
Now consider a reduced version of
src/gdb/testsuite/gdb.python/py-finish-breakpoint2.cc:
...
$ cat -n test.c
1 #include <iostream>
2
3 void
4 throw_exception_1 (int e)
5 {
6 throw new int (e);
7 }
8
9 int
10 main (void)
11 {
12 int i;
13 try
14 {
15 throw_exception_1 (10);
16 }
17 catch (const int *e)
18 {
19 std::cerr << "Exception #" << *e << std::endl;
20 }
21 i += 1;
22
23 return i;
24 }
$ g++ -g test.c
...
Now let's try to see if the FinishBreakPoint triggers:
...
$ gdb -q -batch -ex "source fbp.py" a.out -ex "set trace-commands on" \
-ex "tbreak throw_exception_1" -ex run -ex "python bp = FBP()" \
-ex "info breakpoints" -ex continue -ex "info breakpoints" \
-ex "python print (bp.return_value)"
+tbreak throw_exception_1
Temporary breakpoint 1 at 0x400bd5: file test.c, line 6.
+run
Temporary breakpoint 1, throw_exception_1 (e=10) at test.c:6
6 throw new int (e);
+python bp = FBP()
Temporary breakpoint 2 at 0x400c2f: file test.c, line 21.
+info breakpoints
Num Type Disp Enb Address What
2 breakpoint del y 0x00400c2f in main() at test.c:21 thread 1
stop only in thread 1
+continue
Exception #10
Temporary breakpoint 2, main () at test.c:21
21 i += 1;
+info breakpoints
No breakpoints or watchpoints.
+python print (bp.return_value)
None
...
Surprisingly, it did. The explanation is that FinishBreakPoint is really a
frame-return-address breakpoint, and that address happens to be at line 21,
which is still executed after the throw in throw_exception_1.
Interestingly, with -m32 the FinishBreakPoint doesn't trigger, because the
frame-return-address happens to be an instruction which is part of line 15.
VIII.
In conclusion, the FinishBreakpoint is a frame-return-address breakpoint.
After being set, either:
- it triggers, or
- an out-of-scope event will be generated.
If an out-of-scope event is generated, it will be due to incomplete function
termination.
OTOH, incomplete function termination does not guarantee an out-of-scope event
instead of hitting the breakpoint.
IX.
The documentation states that 'A finish breakpoint is a temporary breakpoint
set at the return address of a frame, based on the finish command'.
It's indeed somewhat similar to the finish command, at least in the sense that
both may stop at the frame-return-address.
But the finish command can accurately detect function termination.
And the finish command will stop at any other address that is the first
address not in the original function.
The documentation needs updating to accurately describe what it does.
X.
A better implementation of a finish breakpoint would be one that borrows from
the finish command implementation. That one:
- installs a thread_fsm, and
- continues
A finish breakpoint would do the same minus the continue, but it requires gdb
to handle multiple thread_fsms at a time (because other commands may wish to
install their own thread_fsm), which AFAICT is not supported yet.
XI.
This patch repairs a minor part of the functionality, and updates
documentation and test-cases to match actual behaviour.
The question remains how useful the functionality is, as it is now
( see f.i. discussion at
https://sourceware.org/pipermail/gdb-patches/2021-January/175290.html ).
Perhaps it would be better to deprecate this in a follow-up patch in some form
or another, say by disabling it by default and introducing a maintenance
command that switches it on, with the warning that it is deprecated.
Tested on x86_64-linux with native and target board unix/-m32, by rebuilding
and running the test-cases:
- gdb.python/py-finish-breakpoint.exp
- gdb.python/py-finish-breakpoint2.exp
---
gdb/breakpoint.c | 10 ++++++++++
gdb/doc/python.texi | 6 ++++--
gdb/python/py-finishbreakpoint.c | 21 +++++++++++++++++++++
gdb/testsuite/gdb.python/py-finish-breakpoint2.exp | 16 +++++++++++++---
4 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index dbbea6b8bff..64a9a3d394f 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -15452,6 +15452,10 @@ initialize_breakpoint_ops (void)
static struct cmd_list_element *enablebreaklist = NULL;
+#if HAVE_PYTHON
+extern gdb::observers::token bpfinishpy_handle_thread_exit_observer_token;
+#endif
+
/* See breakpoint.h. */
cmd_list_element *commands_cmd_element = nullptr;
@@ -16065,6 +16069,12 @@ This is useful for formatted output in user-defined commands."));
gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed,
"breakpoint");
+#if HAVE_PYTHON
+ gdb::observers::thread_exit.attach
+ (remove_threaded_breakpoints, "breakpoint",
+ { &bpfinishpy_handle_thread_exit_observer_token });
+#else
gdb::observers::thread_exit.attach (remove_threaded_breakpoints,
"breakpoint");
+#endif
}
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index f4865b3d6a6..17a67800ba2 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -5698,7 +5698,7 @@ attribute is @code{None}. This attribute is writable.
@tindex gdb.FinishBreakpoint
A finish breakpoint is a temporary breakpoint set at the return address of
-a frame, based on the @code{finish} command. @code{gdb.FinishBreakpoint}
+a frame. @code{gdb.FinishBreakpoint}
extends @code{gdb.Breakpoint}. The underlying breakpoint will be disabled
and deleted when the execution will run out of the breakpoint scope (i.e.@:
@code{Breakpoint.stop} or @code{FinishBreakpoint.out_of_scope} triggered).
@@ -5717,7 +5717,9 @@ details about this argument.
In some circumstances (e.g.@: @code{longjmp}, C@t{++} exceptions, @value{GDBN}
@code{return} command, @dots{}), a function may not properly terminate, and
thus never hit the finish breakpoint. When @value{GDBN} notices such a
-situation, the @code{out_of_scope} callback will be triggered.
+situation, the @code{out_of_scope} callback will be triggered. Note
+though that improper function termination does not guarantee that the
+finish breakpoint is not hit.
You may want to sub-class @code{gdb.FinishBreakpoint} and override this
method:
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 1d8373d807e..a881103fdad 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -398,6 +398,24 @@ bpfinishpy_handle_exit (struct inferior *inf)
bpfinishpy_detect_out_scope_cb (bp, nullptr);
}
+/* Attached to `thread_exit' notifications, triggers all the necessary out of
+ scope notifications. */
+
+static void
+bpfinishpy_handle_thread_exit (struct thread_info *tp, int ignore)
+{
+ gdbpy_enter enter_py (target_gdbarch (), current_language);
+
+ for (breakpoint *bp : all_breakpoints_safe ())
+ {
+ if (tp->global_num == bp->thread)
+ bpfinishpy_detect_out_scope_cb (bp, nullptr);
+ }
+}
+
+extern gdb::observers::token bpfinishpy_handle_thread_exit_observer_token;
+gdb::observers::token bpfinishpy_handle_thread_exit_observer_token;
+
/* Initialize the Python finish breakpoint code. */
int
@@ -414,6 +432,9 @@ gdbpy_initialize_finishbreakpoints (void)
"py-finishbreakpoint");
gdb::observers::inferior_exit.attach (bpfinishpy_handle_exit,
"py-finishbreakpoint");
+ gdb::observers::thread_exit.attach
+ (bpfinishpy_handle_thread_exit,
+ bpfinishpy_handle_thread_exit_observer_token, "py-finishbreakpoint");
return 0;
}
diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp b/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp
index 58e086ad3b4..46c39d0d108 100644
--- a/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp
+++ b/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp
@@ -50,10 +50,20 @@ gdb_test "continue" "Breakpoint .*throw_exception_1.*" "run to exception 1"
gdb_test "python print (len(gdb.breakpoints()))" "3" "check BP count"
gdb_test "python ExceptionFinishBreakpoint(gdb.newest_frame())" \
"init ExceptionFinishBreakpoint" "set FinishBP after the exception"
-gdb_test "continue" ".*stopped at ExceptionFinishBreakpoint.*" "check FinishBreakpoint in catch()"
-gdb_test "python print (len(gdb.breakpoints()))" "3" "check finish BP removal"
-gdb_test "continue" ".*Breakpoint.* throw_exception_1.*" "continue to second exception"
+gdb_test_multiple "continue" "continue after setting FinishBreakpoint" {
+ -re -wrap ".*stopped at ExceptionFinishBreakpoint.*" {
+ pass "$gdb_test_name (scenario 1, triggered)"
+ gdb_test "python print (len(gdb.breakpoints()))" "3" \
+ "check finish BP removal"
+ gdb_test "continue" ".*Breakpoint.* throw_exception_1.*" \
+ "continue to second exception"
+ }
+ -re -wrap ".*Breakpoint.* throw_exception_1.*" {
+ pass "$gdb_test_name (scenario 2, not triggered)"
+ }
+}
+
gdb_test "python ExceptionFinishBreakpoint(gdb.newest_frame())" \
"init ExceptionFinishBreakpoint" "set FinishBP after the exception again"
gdb_test "continue" ".*exception did not finish.*" "FinishBreakpoint with exception thrown not caught"

View File

@ -0,0 +1,83 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-rhbz-818343-set-solib-absolute-prefix-testcase.patch
;; Testcase for `Setting solib-absolute-prefix breaks vDSO' (BZ 818343).
;;=fedoratest
diff --git a/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 2012 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 <stdio.h>
+#include <stdlib.h>
+
+int
+main (int argc, char *argv[])
+{
+ printf ("Hello, World.\n");
+ abort ();
+}
diff --git a/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/set-solib-absolute-prefix.exp
@@ -0,0 +1,39 @@
+# Copyright 2012 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 testfile "set-solib-absolute-prefix"
+set srcfile ${testfile}.c
+
+# It is necessary to verify if the binary is 32-bit, so that the system
+# call `__kernel_vsyscall' originates from vDSO.
+
+if { ![is_ilp32_target] } {
+ return -1
+}
+
+if { [prepare_for_testing $testfile.exp $testfile $srcfile] } {
+ return -1
+}
+
+if { ![runto_main] } {
+ return -1
+}
+
+gdb_test "continue" "Program received signal SIGABRT, Aborted.*" \
+ "continue until abort"
+gdb_test "set solib-absolute-prefix /BOGUS_DIRECT" \
+ ".*warning: Unable to find dynamic linker breakpoint function.*" \
+ "set solib-absolute-prefix"
+gdb_test "bt" "__kernel_vsyscall.*" "backtrace with __kernel_vsyscall"

View File

@ -0,0 +1,170 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-rhbz1007614-memleak-infpy_read_memory-test.patch
;; Fix 'memory leak in infpy_read_memory()' (RH BZ 1007614)
;;=fedoratest
Original message by Tom Tromey:
<https://sourceware.org/ml/gdb-patches/2012-03/msg00955.html>
Message-ID: <871uoc1va3.fsf@fleche.redhat.com>
Comment from Sergio Durigan Junior:
In order to correctly test this patch, I wrote a testcase based on Jan
Kratochvil's <gdb/testsuite/gdb.base/gcore-excessive-memory.exp>. The
testcase, which can be seen below, tests GDB in order to see if the
amount of memory being leaked is minimal, as requested in the bugzilla.
It is hard to define what "minimum" is, so I ran the testcase on all
supported RHEL architectures and came up with an average.
commit cc0265cdda9dc7e8665e8bfcf5b4477489daf27c
Author: Tom Tromey <tromey@redhat.com>
Date: Wed Mar 28 17:38:08 2012 +0000
* python/py-inferior.c (infpy_read_memory): Remove cleanups and
explicitly free 'buffer' on exit paths. Decref 'membuf_object'
before returning.
diff --git a/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.c b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.c
@@ -0,0 +1,27 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2014 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/>. */
+
+static struct x
+ {
+ char unsigned u[4096];
+ } x, *px = &x;
+
+int
+main (int argc, char *argv[])
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.exp b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.exp
@@ -0,0 +1,68 @@
+# Copyright 2014 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 testfile py-gdb-rhbz1007614-memleak-infpy_read_memory
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
+ return -1
+}
+
+if { [skip_python_tests] } { continue }
+
+set pid_of_gdb [exp_pid -i [board_info host fileid]]
+
+proc memory_v_pages_get {} {
+ global pid_of_gdb
+ set fd [open "/proc/$pid_of_gdb/statm"]
+ gets $fd line
+ close $fd
+ # number of pages of virtual memory
+ scan $line "%d" drs
+ return $drs
+}
+
+if { ![runto_main] } {
+ untested $testfile.exp
+ return -1
+}
+
+set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py]
+
+gdb_test "source ${remote_python_file}" ""
+
+gdb_test "hello-world" ""
+
+set kbytes_before [memory_v_pages_get]
+verbose -log "kbytes_before = $kbytes_before"
+
+gdb_test "hello-world" ""
+
+set kbytes_after [memory_v_pages_get]
+verbose -log "kbytes_after = $kbytes_after"
+
+set kbytes_diff [expr $kbytes_after - $kbytes_before]
+verbose -log "kbytes_diff = $kbytes_diff"
+
+# The value "1000" was calculated by running a few GDB sessions with this
+# testcase, and seeing how much (in average) the memory consumption
+# increased after the "hello-world" command issued above. The average
+# was around 500 bytes, so I chose 1000 as a high estimate.
+if { $kbytes_diff > 1000 } {
+ fail "there is a memory leak on GDB (RHBZ 1007614)"
+} else {
+ pass "there is not a memory leak on GDB (RHBZ 1007614)"
+}
diff --git a/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.py b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.py
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-gdb-rhbz1007614-memleak-infpy_read_memory.py
@@ -0,0 +1,30 @@
+# Copyright (C) 2014 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/>.
+
+class HelloWorld (gdb.Command):
+ """Greet the whole world."""
+
+ def __init__ (self):
+ super (HelloWorld, self).__init__ ("hello-world",
+ gdb.COMMAND_OBSCURE)
+
+ def invoke (self, arg, from_tty):
+ px = gdb.parse_and_eval("px")
+ core = gdb.inferiors()[0]
+ for i in range(256 * 1024):
+ chunk = core.read_memory(px, 4096)
+ print "Hello, World!"
+
+HelloWorld ()

View File

@ -0,0 +1,235 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-rhbz1084404-ppc64-s390x-wrong-prologue-skip-O2-g-3of3.patch
;; Fix '[ppc64] and [s390x] wrong prologue skip on -O2 -g code' (Jan
;; Kratochvil, RH BZ 1084404).
;;=fedoratest
These testcases have been created by compiling glibc-2.17-78 on
RHEL-7.1 s390x/ppc64 boxes, and then taking the "select.o" file
present at $builddir/misc/select.o.
diff --git a/gdb/testsuite/gdb.arch/ppc64-prologue-skip.exp b/gdb/testsuite/gdb.arch/ppc64-prologue-skip.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/ppc64-prologue-skip.exp
@@ -0,0 +1,34 @@
+# Copyright 2015 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/>.
+
+if { ![istarget powerpc64-*linux-*] || ![is_lp64_target] } {
+ verbose "Skipping ppc64-prologue-skip.exp"
+ return
+}
+
+set testfile "ppc64-prologue-skip"
+set uufile "${srcdir}/${subdir}/${testfile}.o.uu"
+set ofile "${srcdir}/${subdir}/${testfile}.o"
+
+if { [catch "system \"uudecode -o ${ofile} ${uufile}\"" ] != 0 } {
+ untested "failed uudecode"
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_load $ofile
+
+gdb_test "break ___newselect_nocancel" "Breakpoint $decimal at 0xc: file ../sysdeps/unix/syscall-template.S, line 81." "breakpoint on ___newselect_nocancel"
diff --git a/gdb/testsuite/gdb.arch/ppc64-prologue-skip.o.uu b/gdb/testsuite/gdb.arch/ppc64-prologue-skip.o.uu
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/ppc64-prologue-skip.o.uu
@@ -0,0 +1,70 @@
+begin 644 ppc64-skip-prologue.o.uu
+M?T5,1@("`0`````````````!`!4````!````````````````````````````
+M``-(``````!```````!``!0`$8%-B-`L"@``0,(`-#@``(Y$```"3.,`('P(
+M`J;X`0`0^"'_D4@```%@````Z`$`@#@A`'!\"`.F3H``(/@A_X%]*`*F^2$`
+MD/CA`-#XP0#(^*$`P/B!`+CX80"P2````6````#X80!PZ.$`T.C!`,CHH0#`
+MZ($`N.AA`+`X``".1````GP``";X80!X^`$`B.AA`'!(```!8````.DA`)#H
+M`0"(Z&$`>'TH`Z9\#_$@."$`@$SC`"!+__]@```````,($``````````O``(
+M7U]S96QE8W0```````````````````````````!6``(````Y!`'[#@T``0$!
+M`0````$```$N+B]S>7-D97!S+W5N:7@``'-Y<V-A;&PM=&5M<&QA=&4N4P`!
+M``````D"```````````#T``!`BT3`@D``0$```"/``(`````"`$`````````
+M`````````````````"XN+W-Y<V1E<',O=6YI>"]S>7-C86QL+71E;7!L871E
+M+E,`+W)O;W0O9VQI8F,O9VQI8F,M,BXQ-RTW."YE;#<N<W)C+V=L:6)C+3(N
+M,3<M8S<U.&$V.#8O;6ES8P!'3E4@05,@,BXR,RXU,BXP+C$`@`$!$0`0!A$!
+M$@$#"!L()0@3!0`````````````````L``(`````"```````````````````
+M````````V``````````````````````````0``````%Z4@`$>$$!&PP!````
+M`#`````8`````````+P`20YP$4%^1`X`009!0@Z``4(107Y2$49_20X`!D$&
+M1@``````+G-Y;71A8@`N<W1R=&%B`"YS:'-T<G1A8@`N<F5L82YT97AT`"YD
+M871A`"YB<W,`+G)E;&$N;W!D`"YN;W1E+D=.52US=&%C:P`N<F5L82YD96)U
+M9U]L:6YE`"YR96QA+F1E8G5G7VEN9F\`+F1E8G5G7V%B8G)E=@`N<F5L82YD
+M96)U9U]A<F%N9V5S`"YR96QA+F5H7V9R86UE````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````"`````!``````````8```````````````````!``````````-@`
+M```````````````````$```````````````;````!```````````````````
+M```````````*>`````````!(````$@````$`````````"``````````8````
+M)@````$``````````P```````````````````1@`````````````````````
+M``````````$``````````````"P````(``````````,`````````````````
+M``$8```````````````````````````````!```````````````V`````0``
+M```````#```````````````````!&``````````0````````````````````
+M"```````````````,0````0`````````````````````````````"L``````
+M````,````!(````%``````````@`````````&````#L````!````````````
+M``````````````````$H```````````````````````````````!````````
+M``````!0`````0`````````````````````````````!*`````````!:````
+M`````````````````0``````````````2P````0`````````````````````
+M````````"O``````````&````!(````(``````````@`````````&````&$`
+M```!``````````````````````````````&"`````````),`````````````
+M```````!``````````````!<````!``````````````````````````````+
+M"`````````!@````$@````H`````````"``````````8````;0````$`````
+M`````````````````````````A4`````````%`````````````````````$`
+M`````````````(`````!``````````````````````````````(P````````
+M`#`````````````````````0``````````````![````!```````````````
+M```````````````+:``````````P````$@````T`````````"``````````8
+M````E`````$``````````@```````````````````F``````````2```````
+M``````````````@``````````````(\````$````````````````````````
+M``````N8`````````!@````2````#P`````````(`````````!@````1````
+M`P`````````````````````````````"J`````````">````````````````
+M`````0```````````````0````(`````````````````````````````"$@`
+M```````!L````!,````+``````````@`````````&`````D````#````````
+M``````````````````````GX`````````'H````````````````````!````
+M`````````````````````````````````````````````P```0``````````
+M`````````````````P```P```````````````````````````P``!```````
+M`````````````````````P``!0```````````````````````````P``"@``
+M`````````````````````````P``#````````````````````````````P``
+M"````````````````````````````P``#0``````````````````````````
+M`P``#P```````````````````````````P``!P``````````````````````
+M```!$@``!0```````````````````-@````*$@```0`````````,````````
+M`#`````@$``````````````````````````````P$```````````````````
+M``````````!*$`````````````````````````````!E(@``!0``````````
+M`````````-@```!S(@``!0```````````````````-@`7U]S96QE8W0`7U]?
+M;F5W<V5L96-T7VYO8V%N8V5L`%]?<WES8V%L;%]E<G)O<@!?7VQI8F-?96YA
+M8FQE7V%S>6YC8V%N8V5L`%]?;&EB8U]D:7-A8FQE7V%S>6YC8V%N8V5L`%]?
+M;&EB8U]S96QE8W0`<V5L96-T```````````````````D````#0````H`````
+M``````````````!<````#@````H```````````````````"4````#P````H`
+M`````````````````````````0```"8````````````````````(````````
+M`#,```````````````````!&`````0```"8````````````````````&````
+M!@````$````````````````````,````!P````$````````````````````0
+M`````0```"8````````````````````8`````0```"8`````````V```````
+M```&````!0````$````````````````````0`````0```"8`````````````
+6```````<`````0```!H`````````````
+`
+end
diff --git a/gdb/testsuite/gdb.arch/s390x-prologue-skip.exp b/gdb/testsuite/gdb.arch/s390x-prologue-skip.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/s390x-prologue-skip.exp
@@ -0,0 +1,34 @@
+# Copyright 2015 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/>.
+
+if { ![istarget s390x-*linux-*] || ![is_lp64_target] } {
+ verbose "Skipping s390x-prologue-skip.exp"
+ return
+}
+
+set testfile "s390x-prologue-skip"
+set uufile "${srcdir}/${subdir}/${testfile}.o.uu"
+set ofile "${srcdir}/${subdir}/${testfile}.o"
+
+if { [catch "system \"uudecode -o ${ofile} ${uufile}\"" ] != 0 } {
+ untested "failed uudecode"
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_load $ofile
+
+gdb_test "break select" "Breakpoint $decimal at 0x48: file ../sysdeps/unix/syscall-template.S, line 81." "breakpoint on select"
diff --git a/gdb/testsuite/gdb.arch/s390x-prologue-skip.o.uu b/gdb/testsuite/gdb.arch/s390x-prologue-skip.o.uu
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/s390x-prologue-skip.o.uu
@@ -0,0 +1,64 @@
+begin 644 s390x-prologue-skip.o.uu
+M?T5,1@("`0`````````````!`!8````!````````````````````````````
+M``+```````!```````!``!(`#^LE\!``).O?\&@`)+D$`.^G^_]@X^#P```D
+MP.4`````N00``NLE\+``!`J.N00`TKD$`"#`Y0````"Y!``MZ]_Q"``$I_0`
+M"L`0`````+\/$`"G=/_7"HZG2?`!N2$`),"T``````?^````5@`"````.0$!
+M^PX-``$!`0$````!```!+BXO<WES9&5P<R]U;FEX``!S>7-C86QL+71E;7!L
+M871E+E,``0`````)`@```````````]```0)F$P("``$!````CP`"``````@!
+M```````````````````````````N+B]S>7-D97!S+W5N:7@O<WES8V%L;"UT
+M96UP;&%T92Y3`"]R;V]T+V=L:6)C+V=L:6)C+3(N,3<M-S@N96PW+G-R8R]G
+M;&EB8RTR+C$W+6,W-3AA-C@V+VUI<V,`1TY5($%3(#(N,C,N-3(N,"XQ`(`!
+M`1$`$`81`1(!`P@;""4($P4`````````````````+``"``````@`````````
+M`````````````````&@`````````````````````````%``````!>E(``7@.
+M`1L,#Z`!````````&````!P`````````1`!,CP6.!HT'2`[``@```!`````X
+M`````````"```````"YS>6UT86(`+G-T<G1A8@`N<VAS=')T86(`+G)E;&$N
+M=&5X=``N9&%T80`N8G-S`"YN;W1E+D=.52US=&%C:P`N<F5L82YD96)U9U]L
+M:6YE`"YR96QA+F1E8G5G7VEN9F\`+F1E8G5G7V%B8G)E=@`N<F5L82YD96)U
+M9U]A<F%N9V5S`"YR96QA+F5H7V9R86UE````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````(`````$`````````!@```````````````````$``````````:```
+M``````````````````0``````````````!L````$````````````````````
+M``````````F``````````&`````0`````0`````````(`````````!@````F
+M`````0`````````#````````````````````J```````````````````````
+M````````!```````````````+`````@``````````P``````````````````
+M`*@```````````````````````````````0``````````````#$````!````
+M``````````````````````````"H```````````````````````````````!
+M``````````````!&`````0``````````````````````````````J```````
+M``!:`````````````````````0``````````````00````0`````````````
+M````````````````">``````````&````!`````&``````````@`````````
+M&````%<````!``````````````````````````````$"`````````),`````
+M```````````````!``````````````!2````!```````````````````````
+M```````)^`````````!@````$`````@`````````"``````````8````8P``
+M``$``````````````````````````````94`````````%```````````````
+M``````$``````````````'8````!``````````````````````````````&P
+M`````````#`````````````````````0``````````````!Q````!```````
+M```````````````````````*6``````````P````$`````L`````````"```
+M```````8````B@````$``````````@```````````````````>``````````
+M2`````````````````````@``````````````(4````$````````````````
+M``````````````J(`````````#`````0````#0`````````(`````````!@`
+M```1`````P`````````````````````````````"*`````````"4````````
+M`````````````0```````````````0````(`````````````````````````
+M````!T`````````!L````!$````*``````````@`````````&`````D````#
+M``````````````````````````````CP`````````(X`````````````````
+M```!`````````````````````````````````````````````````P```0``
+M`````````````````````````P```P```````````````````````````P``
+M!````````````````````````````P``"```````````````````````````
+M`P``"@```````````````````````````P``!@``````````````````````
+M`````P``"P```````````````````````````P``#0``````````````````
+M`````````P``!0`````````````````````````!$```````````````````
+M```````````;$``````````````````````````````V$@```0````````!(
+M`````````"`````_$`````````````````````````````!7$@```0``````
+M``!6`````````!````!I$`````````````````````````````!Y(@```0``
+M``````!(`````````"````"'(@```0````````!(`````````"``7U]L:6)C
+M7V5N86)L95]A<WEN8V-A;F-E;`!?7VQI8F-?9&ES86)L95]A<WEN8V-A;F-E
+M;`!?7W-E;&5C=`!?7VQI8F-?;75L=&EP;&5?=&AR96%D<P!?7W-E;&5C=%]N
+M;V-A;F-E;`!?7W-Y<V-A;&Q?97)R;W(`7U]L:6)C7W-E;&5C=`!S96QE8W0`
+M````````````'`````H````3``````````(`````````-@````L````3````
+M``````(`````````2@````T````3``````````(`````````8@````\````3
+M``````````(`````````1@````$````6````````````````````!@````4`
+M```$````````````````````#`````8````$````````````````````$```
+M``$````6````````````````````&`````$````6`````````&@`````````
+M!@````0````$````````````````````$`````$````6````````````````
+L````(`````$````%````````````````````/`````$````%`````````$@`
+`
+end

View File

@ -0,0 +1,123 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-rhbz1149205-catch-syscall-after-fork-test.patch
;; Fix '`catch syscall' doesn't work for parent after `fork' is called'
;; (Philippe Waroquiers, RH BZ 1149205).
;;=fedoratest
URL: <https://sourceware.org/ml/gdb-patches/2013-05/msg00364.html>
Message-ID: <1368136582.30058.7.camel@soleil>
From: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>
To: gdb-patches at sourceware dot org
Subject: RFA: fix gdb_assert caused by 'catch signal ...' and fork
Date: Thu, 09 May 2013 23:56:22 +0200
The attached patch fixes a gdb_assert caused by the combination of catch
signal and fork:
break-catch-sig.c:152: internal-error: signal_catchpoint_remove_location: Assertion `signal_catch_counts[iter] > 0' failed.
The problem is that the signal_catch_counts is decremented by detach_breakpoints.
The fix consists in not detaching breakpoint locations of type bp_loc_other.
The patch introduces a new test.
Comments by Sergio Durigan Junior:
I addded a specific testcase for this patch, which tests exactly the
issue that the customer is facing. This patch does not solve the
whole problem of catching a syscall and forking (for more details,
see <https://sourceware.org/bugzilla/show_bug.cgi?id=13457>,
specifically comment #3), but it solves the issue reported by the
customer.
I also removed the original testcase of this patch, because it
relied on "catch signal", which is a command that is not implemented
in this version of GDB.
commit bd9673a4ded96ea5c108601501c8e59003ea1be6
Author: Philippe Waroquiers <philippe@sourceware.org>
Date: Tue May 21 18:47:05 2013 +0000
Fix internal error caused by interaction between catch signal and fork
diff --git a/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.c b/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <unistd.h>
+
+int
+main (int argc, char **argv)
+{
+ if (fork () == 0)
+ sleep (1);
+ chdir (".");
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.exp b/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/gdb-rhbz1149205-catch-syscall-fork.exp
@@ -0,0 +1,58 @@
+# Copyright 2015 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/>.
+
+if { [is_remote target] || ![isnative] } then {
+ continue
+}
+
+set testfile "gdb-rhbz1149205-catch-syscall-fork"
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+
+# Until "catch syscall" is implemented on other targets...
+if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
+ continue
+}
+
+# This shall be updated whenever 'catch syscall' is implemented
+# on some architecture.
+#if { ![istarget "i\[34567\]86-*-linux*"]
+if { ![istarget "x86_64-*-linux*"] && ![istarget "i\[34567\]86-*-linux*"]
+ && ![istarget "powerpc-*-linux*"] && ![istarget "powerpc64-*-linux*"]
+ && ![istarget "sparc-*-linux*"] && ![istarget "sparc64-*-linux*"] } {
+ continue
+}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ untested ${testfile}.exp
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load $binfile
+
+if { ![runto_main] } {
+ return -1
+}
+
+gdb_test "catch syscall chdir" \
+ "Catchpoint $decimal \\\(syscall (.)?chdir(.)? \\\[$decimal\\\]\\\)" \
+ "catch syscall chdir"
+
+gdb_test "continue" \
+ "Continuing\.\r\n.*\r\nCatchpoint $decimal \\\(call to syscall .?chdir.?.*" \
+ "continue from catch syscall after fork"

View File

@ -0,0 +1,135 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-rhbz1186476-internal-error-unqualified-name-re-set-test.patch
;; Fix 'backport GDB 7.4 fix to RHEL 6.6 GDB' [Original Sourceware bug
;; description: 'C++ (and objc): Internal error on unqualified name
;; re-set', PR 11657] (RH BZ 1186476).
;;=fedoratest
Comments from Sergio Durigan Junior:
The "proper" fix for this whole problem would be to backport the
"ambiguous linespec" patch series. However, it is really not
recommended to do that for RHEL GDB, because the patch series is too
big and could introduce unwanted regressions. Instead, what we
chose to do was to replace the gdb_assert call by a warning (which
allows the user to continue the debugging session), and tell the
user that, although more than one location was found for his/her
breakpoint, only one will be used.
diff --git a/gdb/testsuite/gdb.cp/gdb-rhbz1186476-internal-error-unqualified-name-re-set-main.cc b/gdb/testsuite/gdb.cp/gdb-rhbz1186476-internal-error-unqualified-name-re-set-main.cc
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/gdb-rhbz1186476-internal-error-unqualified-name-re-set-main.cc
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 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/>. */
+
+int
+main (int argc, char *argv[])
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/gdb-rhbz1186476-internal-error-unqualified-name-re-set.cc b/gdb/testsuite/gdb.cp/gdb-rhbz1186476-internal-error-unqualified-name-re-set.cc
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/gdb-rhbz1186476-internal-error-unqualified-name-re-set.cc
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 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/>. */
+
+class C
+ {
+ public:
+ C () {}
+ C (int x) {}
+ };
+
+C a;
+C b (1);
diff --git a/gdb/testsuite/gdb.cp/gdb-rhbz1186476-internal-error-unqualified-name-re-set.exp b/gdb/testsuite/gdb.cp/gdb-rhbz1186476-internal-error-unqualified-name-re-set.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/gdb-rhbz1186476-internal-error-unqualified-name-re-set.exp
@@ -0,0 +1,51 @@
+# Copyright 2015 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/>.
+
+if { [skip_cplus_tests] } { continue }
+if { [skip_shlib_tests] } { continue }
+if { [is_remote target] } { continue }
+if { [target_info exists use_gdb_stub] } { continue }
+
+set testfile gdb-rhbz1186476-internal-error-unqualified-name-re-set-main
+set srcfile $testfile.cc
+set executable $testfile
+set binfile [standard_output_file $executable]
+
+set libtestfile gdb-rhbz1186476-internal-error-unqualified-name-re-set
+set libsrcfile $libtestfile.cc
+set sofile [standard_output_file lib$libtestfile.so]
+
+# Create and source the file that provides information about the compiler
+# used to compile the test case.
+if [get_compiler_info "c++"] {
+ return -1
+}
+
+if { [gdb_compile_shlib $srcdir/$subdir/$libsrcfile $sofile {debug c++ "additional_flags=-fPIC"}] != ""
+ || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable [list additional_flags=-Wl,-rpath,[file dirname ${sofile}] "c++" shlib=${sofile} ]] != ""} {
+ untested $libtestfile.exp
+ return -1
+}
+
+clean_restart $executable
+
+gdb_test_no_output "set breakpoint pending on"
+# gdb_breakpoint would print a failure because of some warning messages
+gdb_test "break C::C" "Breakpoint $decimal \\(C::C\\) pending."
+
+#gdb_test "run" "warning: Found more than one location for breakpoint #$decimal; only the first location will be used.(\r\n)+Breakpoint $decimal, C::C.*"
+gdb_test "run"
+
+gdb_test "info break" " in C::C\\(\\) at .* in C::C\\(int\\) at .*"

View File

@ -0,0 +1,104 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-rhbz1261564-aarch64-hw-watchpoint-test.patch
;; [aarch64] Fix hardware watchpoints (RH BZ 1261564).
;;=fedoratest
diff --git a/gdb/testsuite/gdb.base/rhbz1261564-aarch64-watchpoint.c b/gdb/testsuite/gdb.base/rhbz1261564-aarch64-watchpoint.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/rhbz1261564-aarch64-watchpoint.c
@@ -0,0 +1,33 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2016 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/>. */
+
+__attribute__((aligned(16))) struct
+{
+ int var0, var4, var8;
+} aligned;
+
+int
+main (void)
+{
+ aligned.var0 = 1;
+ aligned.var4 = 2;
+ aligned.var8 = 3;
+
+ aligned.var4 = aligned.var0;
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/rhbz1261564-aarch64-watchpoint.exp b/gdb/testsuite/gdb.base/rhbz1261564-aarch64-watchpoint.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/rhbz1261564-aarch64-watchpoint.exp
@@ -0,0 +1,53 @@
+# Copyright (C) 2016 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/>.
+
+if { [prepare_for_testing rhbz1261564-aarch64-watchpoint.exp "rhbz1261564-aarch64-watchpoint"] } {
+ return -1
+}
+
+if { ! [ runto main ] } then { return 0 }
+
+set test "rwatch aligned.var4"
+if [istarget "s390*-*-*"] {
+ gdb_test $test {Target does not support this type of hardware watchpoint\.}
+ untested "s390* does not support hw read watchpoint"
+ return
+}
+gdb_test $test "Hardware read watchpoint \[0-9\]+: aligned.var4"
+
+proc checkvar { address } {
+ global gdb_prompt
+
+ set test "p &aligned.var$address"
+ gdb_test_multiple $test $test {
+ -re " = \\(int \\*\\) 0x\[0-9a-f\]+$address <aligned(\\+\[0-9\]+)?>\r\n$gdb_prompt $" {
+ pass $test
+ }
+ -re "\r\n$gdb_prompt $" {
+ untested "$test (unexpected ELF layout)"
+ return 0
+ }
+ }
+ return 1
+}
+if ![checkvar "0"] { return }
+if ![checkvar "4"] { return }
+if ![checkvar "8"] { return }
+
+# Assumes: PPC_PTRACE_GETHWDBGINFO::data_bp_alignment == 8
+# 'lwz' does read only 4 bytes but the hw watchpoint is 8 bytes wide.
+setup_xfail "powerpc*-*-*"
+
+gdb_continue_to_end

View File

@ -0,0 +1,83 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-rhbz1350436-type-printers-error.patch
;; Test 'info type-printers' Python error (RH BZ 1350436).
;;=fedoratest
Typo in Python support breaks info type-printers command
https://bugzilla.redhat.com/show_bug.cgi?id=1350436
[testsuite patch] PR python/17136: 'info type-printers' causes an exception when there are per-objfile printers
https://sourceware.org/ml/gdb-patches/2016-06/msg00455.html
diff --git a/gdb/testsuite/gdb.python/py-typeprint.cc b/gdb/testsuite/gdb.python/py-typeprint.cc
--- a/gdb/testsuite/gdb.python/py-typeprint.cc
+++ b/gdb/testsuite/gdb.python/py-typeprint.cc
@@ -31,6 +31,12 @@ templ<basic_string> s;
basic_string bs;
+class Other
+{
+};
+
+Other ovar;
+
int main()
{
return 0;
diff --git a/gdb/testsuite/gdb.python/py-typeprint.exp b/gdb/testsuite/gdb.python/py-typeprint.exp
--- a/gdb/testsuite/gdb.python/py-typeprint.exp
+++ b/gdb/testsuite/gdb.python/py-typeprint.exp
@@ -50,3 +50,7 @@ gdb_test_no_output "enable type-printer string"
gdb_test "whatis bs" "string" "whatis with enabled printer"
gdb_test "whatis s" "templ<string>"
+
+gdb_test "info type-printers" "Type printers for \[^\r\n\]*/py-typeprint:\r\n *other\r\n.*" \
+ "info type-printers for other"
+gdb_test "whatis ovar" "type = Another"
diff --git a/gdb/testsuite/gdb.python/py-typeprint.py b/gdb/testsuite/gdb.python/py-typeprint.py
--- a/gdb/testsuite/gdb.python/py-typeprint.py
+++ b/gdb/testsuite/gdb.python/py-typeprint.py
@@ -15,8 +15,7 @@
import gdb
-
-class Recognizer(object):
+class StringRecognizer(object):
def __init__(self):
self.enabled = True
@@ -32,7 +31,27 @@ class StringTypePrinter(object):
self.enabled = True
def instantiate(self):
- return Recognizer()
+ return StringRecognizer()
gdb.type_printers.append(StringTypePrinter())
+
+class OtherRecognizer(object):
+ def __init__(self):
+ self.enabled = True
+
+ def recognize(self, type_obj):
+ if type_obj.tag == 'Other':
+ return 'Another'
+ return None
+
+class OtherTypePrinter(object):
+ def __init__(self):
+ self.name = 'other'
+ self.enabled = True
+
+ def instantiate(self):
+ return OtherRecognizer()
+
+import gdb.types
+gdb.types.register_type_printer(gdb.objfiles()[0], OtherTypePrinter())

View File

@ -0,0 +1,81 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Fri, 23 Mar 2018 20:42:44 +0100
Subject: gdb-rhbz1553104-s390x-arch12-test.patch
;; [s390x] Backport arch12 instructions decoding (RH BZ 1553104).
;; =fedoratest
diff --git a/gdb/testsuite/gdb.arch/s390x-arch12.S b/gdb/testsuite/gdb.arch/s390x-arch12.S
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/s390x-arch12.S
@@ -0,0 +1,4 @@
+.text
+.globl load_guarded
+load_guarded:
+.byte 0xeb,0xbf,0xf0,0x58,0x00,0x24,0xe3,0xf0,0xff,0x50,0xff,0x71,0xb9,0x04,0x00,0xbf,0xe3,0x20,0xb0,0xa0,0x00,0x24,0xe3,0x10,0xb0,0xa0,0x00,0x04,0xe3,0x10,0x10,0x00,0x00,0x4c,0xe3,0x10,0xb0,0xa8,0x00,0x24,0xe3,0x10,0xb0,0xa8,0x00,0x04,0xb9,0x04,0x00,0x21,0xe3,0x40,0xb1,0x20,0x00,0x04,0xeb,0xbf,0xb1,0x08,0x00,0x04,0x07,0xf4
diff --git a/gdb/testsuite/gdb.arch/s390x-arch12.exp b/gdb/testsuite/gdb.arch/s390x-arch12.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/s390x-arch12.exp
@@ -0,0 +1,34 @@
+# Copyright 2018 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/>.
+
+#if { ![istarget s390x-*linux-*] || ![is_lp64_target] } {
+# verbose "Skipping s390x-prologue-skip.exp"
+# return
+#}
+
+set testfile "s390x-arch12"
+set uufile "${srcdir}/${subdir}/${testfile}.o.uu"
+set ofile "${srcdir}/${subdir}/${testfile}.o"
+
+if { [catch "system \"uudecode -o ${ofile} ${uufile}\"" ] != 0 } {
+ untested "failed uudecode"
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_load $ofile
+
+gdb_test "disas load_guarded" " <\\+28>:\tlgg\t%r1,0\\(%r1\\)\r\n\[^\r\n\]* <\\+34>:\tstg\t%r1,168\\(%r11\\)\r\n.*"
diff --git a/gdb/testsuite/gdb.arch/s390x-arch12.o.uu b/gdb/testsuite/gdb.arch/s390x-arch12.o.uu
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/s390x-arch12.o.uu
@@ -0,0 +1,20 @@
+begin 644 s390x-arch12.o
+M?T5,1@("`0`````````````!`!8````!````````````````````````````
+M``$X``````!```````!```<`!.N_\%@`)./P_U#_<;D$`+_C(+"@`"3C$+"@
+M``3C$!```$SC$+"H`"3C$+"H``2Y!``AXT"Q(``$Z[^Q"``$!_0`+G-Y;71A
+M8@`N<W1R=&%B`"YS:'-T<G1A8@`N=&5X=``N9&%T80`N8G-S````````````
+M`````````````````````````````````P```0``````````````````````
+M`````P```@```````````````````````````P```P``````````````````
+M```````!$````0``````````````````````;&]A9%]G=6%R9&5D````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````!L````!``````````8`````````````````
+M``!``````````$`````````````````````$```````````````A`````0``
+M```````#````````````````````@```````````````````````````````
+M!```````````````)P````@``````````P```````````````````(``````
+M``````````````````````````0``````````````!$````#````````````
+M``````````````````"``````````"P````````````````````!````````
+M```````!`````@``````````````````````````````L`````````!X````
+M!@````0`````````"``````````8````"0````,`````````````````````
+H`````````2@`````````#@````````````````````$`````````````
+`
+end

View File

@ -0,0 +1,105 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Kevin Buettner <kevinb@redhat.com>
Date: Mon, 2 Oct 2023 15:05:23 -0700
Subject: gdb-rhbz1773651-gdb-index-internal-error.patch
;; Backport upstream patch which prevents internal error when
;; generating a gdb-index file (RH BZ 1773651).
Throw error when creating an overly large gdb-index file
The header in a .gdb_index section uses 32-bit unsigned offsets to
refer to other areas of the section. Thus, there is a size limit of
2^32-1 which is currently unaccounted for by GDB's code for outputting
these sections.
At the moment, when GDB creates an overly large section, it will exit
abnormally due to an internal error, which is caused by a failed
assert in assert_file_size, which in turn is called from
write_gdbindex_1, both of which are in gdb/dwarf2/index-write.c.
This is what happens when that assert fails:
$ gdb -q -nx -iex 'set auto-load no' -iex 'set debuginfod enabled off' -ex file ./libgraph_tool_inference.so -ex "save gdb-index `pwd`/"
Reading symbols from ./libgraph_tool_inference.so...
No executable file now.
Discard symbol table from `libgraph_tool_inference.so'? (y or n) n
Not confirmed.
../../gdb/dwarf2/index-write.c:1069: internal-error: assert_file_size: Assertion `file_size == expected_size' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
0x55fddb4d78b0 gdb_internal_backtrace_1
../../gdb/bt-utils.c:122
0x55fddb4d78b0 _Z22gdb_internal_backtracev
../../gdb/bt-utils.c:168
0x55fddb98b5d4 internal_vproblem
../../gdb/utils.c:396
0x55fddb98b8de _Z15internal_verrorPKciS0_P13__va_list_tag
../../gdb/utils.c:476
0x55fddbb71654 _Z18internal_error_locPKciS0_z
../../gdbsupport/errors.cc:58
0x55fddb5a0f23 assert_file_size
../../gdb/dwarf2/index-write.c:1069
0x55fddb5a1ee0 assert_file_size
/usr/include/c++/13/bits/stl_iterator.h:1158
0x55fddb5a1ee0 write_gdbindex_1
../../gdb/dwarf2/index-write.c:1119
0x55fddb5a51be write_gdbindex
../../gdb/dwarf2/index-write.c:1273
[...]
---------------------
../../gdb/dwarf2/index-write.c:1069: internal-error: assert_file_size: Assertion `file_size == expected_size' failed.
This problem was encountered while building the python-graph-tool
package on Fedora. The Fedora bugzilla bug can be found here:
https://bugzilla.redhat.com/show_bug.cgi?id=1773651
This commit prevents the internal error from occurring by calling error()
when the file size exceeds 2^32-1.
Using a gdb built with this commit, I now see this behavior instead:
$ gdb -q -nx -iex 'set auto-load no' -iex 'set debuginfod enabled off' -ex file ./libgraph_tool_inference.so -ex "save gdb-index `pwd`/"
Reading symbols from ./libgraph_tool_inference.so...
No executable file now.
Discard symbol table from `/mesquite2/fedora-bugs/1773651/libgraph_tool_inference.so'? (y or n) n
Not confirmed.
Error while writing index for `/mesquite2/fedora-bugs/1773651/libgraph_tool_inference.so': gdb-index maximum file size of 4294967295 exceeded
(gdb)
I wish I could provide a test case, but due to the sizes of both the
input and output files, I think that testing resources would be
strained or exceeded in many environments.
My testing on Fedora 38 shows no regressions.
Approved-by: Tom Tromey <tom@tromey.com>
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1082,7 +1082,7 @@ write_gdbindex_1 (FILE *out_file,
{
data_buf contents;
const offset_type size_of_header = 6 * sizeof (offset_type);
- offset_type total_len = size_of_header;
+ size_t total_len = size_of_header;
/* The version number. */
contents.append_offset (8);
@@ -1109,6 +1109,13 @@ write_gdbindex_1 (FILE *out_file,
gdb_assert (contents.size () == size_of_header);
+ /* The maximum size of an index file is limited by the maximum value
+ capable of being represented by 'offset_type'. Throw an error if
+ that length has been exceeded. */
+ size_t max_size = ~(offset_type) 0;
+ if (total_len > max_size)
+ error (_("gdb-index maximum file size of %zu exceeded"), max_size);
+
contents.file_write (out_file);
cu_list.file_write (out_file);
types_cu_list.file_write (out_file);

View File

@ -0,0 +1,108 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Kevin Buettner <kevinb@redhat.com>
Date: Thu, 29 Jun 2023 18:20:30 -0700
Subject: gdb-rhbz2160211-excessive-core-file-warnings.patch
;; Backport two commits, 0ad504dd464 and ea70f941f9b, from Lancelot SIX
;; which prevent repeated warnings from being printed while loading a
;; core file. (RH BZ 2160211)
gdb/corelow.c: avoid repeated warnings in build_file_mappings
When GDB opens a coredump it tries to locate and then open all files
which were mapped in the process.
If a file is found but cannot be opened with BFD (bfd_open /
bfd_check_format fails), then a warning is printed to the user. If the
same file was mapped multiple times in the process's address space, the
warning is printed once for each time the file was mapped. I find this
un-necessarily noisy.
This patch makes it so the warning message is printed only once per
file.
There was a comment in the code assuming that if the file was found on
the system, opening it (bfd_open + bfd_check_format) should always
succeed. A recent change in BFD (014a602b86f "Don't optimise bfd_seek
to same position") showed that this assumption is not valid. For
example, it is possible to have a core dump of a process which had
mmaped an IO page from a DRI render node (/dev/dri/runderD$NUM). In
such case the core dump does contain the information that portions of
this special file were mapped in the host process, but trying to seek to
position 0 will fail, making bfd_check_format fail. This patch removes
this comment.
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/corelow.c: do not try to reopen a file if open failed once
In the current implementation, core_target::build_file_mappings will try
to locate and open files which were mapped in the process for which the
core dump was produced. If the file cannot be found or cannot be
opened, GDB will re-try to open it once for each time it was mapped in
the process's address space.
This patch makes it so GDB recognizes that it has already failed to open
a given file once and does not re-try the process for each mapping.
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
diff --git a/gdb/corelow.c b/gdb/corelow.c
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -237,6 +237,16 @@ core_target::build_file_mappings ()
weed out non-file-backed mappings. */
gdb_assert (filename != nullptr);
+ if (unavailable_paths.find (filename) != unavailable_paths.end ())
+ {
+ /* We have already seen some mapping for FILENAME but failed to
+ find/open the file. There is no point in trying the same
+ thing again so just record that the range [start, end) is
+ unavailable. */
+ m_core_unavailable_mappings.emplace_back (start, end - start);
+ return;
+ }
+
struct bfd *bfd = bfd_map[filename];
if (bfd == nullptr)
{
@@ -254,11 +264,10 @@ core_target::build_file_mappings ()
if (expanded_fname == nullptr)
{
m_core_unavailable_mappings.emplace_back (start, end - start);
- /* Print just one warning per path. */
- if (unavailable_paths.insert (filename).second)
- warning (_("Can't open file %s during file-backed mapping "
- "note processing"),
- filename);
+ unavailable_paths.insert (filename);
+ warning (_("Can't open file %s during file-backed mapping "
+ "note processing"),
+ filename);
return;
}
@@ -268,18 +277,11 @@ core_target::build_file_mappings ()
if (bfd == nullptr || !bfd_check_format (bfd, bfd_object))
{
m_core_unavailable_mappings.emplace_back (start, end - start);
- /* If we get here, there's a good chance that it's due to
- an internal error. We issue a warning instead of an
- internal error because of the possibility that the
- file was removed in between checking for its
- existence during the expansion in exec_file_find()
- and the calls to bfd_openr() / bfd_check_format().
- Output both the path from the core file note along
- with its expansion to make debugging this problem
- easier. */
+ unavailable_paths.insert (filename);
warning (_("Can't open file %s which was expanded to %s "
"during file-backed mapping note processing"),
filename, expanded_fname.get ());
+
if (bfd != nullptr)
bfd_close (bfd);
return;

View File

@ -0,0 +1,107 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Kevin Buettner <kevinb@redhat.com>
Date: Wed, 3 May 2023 11:28:24 -0700
Subject: gdb-rhbz2192105-ftbs-dangling-pointer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
;; Backport upstream patch fixing a "dangling pointer" build problem
;; first seen when building with GCC 13.1.1 20230426 (Red Hat ;; 13.1.1-1).
Pass const frame_info_ptr reference for skip_[language_]trampoline
g++ 13.1.1 produces a -Werror=dangling-pointer=
In file included from ../../binutils-gdb/gdb/frame.h:75,
from ../../binutils-gdb/gdb/symtab.h:40,
from ../../binutils-gdb/gdb/language.c:33:
In member function void intrusive_list<T, AsNode>::push_empty(T&) [with T = frame_info_ptr; AsNode = intrusive_base_node<frame_info_ptr>],
inlined from void intrusive_list<T, AsNode>::push_back(reference) [with T = frame_info_ptr; AsNode = intrusive_base_node<frame_info_ptr>] at gdbsupport/intrusive_list.h:332:24,
inlined from frame_info_ptr::frame_info_ptr(const frame_info_ptr&) at gdb/frame.h:241:26,
inlined from CORE_ADDR skip_language_trampoline(frame_info_ptr, CORE_ADDR) at gdb/language.c:530:49:
gdbsupport/intrusive_list.h:415:12: error: storing the address of local variable <anonymous> in frame_info_ptr::frame_list.intrusive_list<frame_info_ptr>::m_back [-Werror=dangling-pointer=]
415 | m_back = &elem;
| ~~~~~~~^~~~~~~
gdb/language.c: In function CORE_ADDR skip_language_trampoline(frame_info_ptr, CORE_ADDR):
gdb/language.c:530:49: note: <anonymous> declared here
530 | CORE_ADDR real_pc = lang->skip_trampoline (frame, pc);
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
gdb/frame.h:359:41: note: frame_info_ptr::frame_list declared here
359 | static intrusive_list<frame_info_ptr> frame_list;
| ^~~~~~~~~~
Each new frame_info_ptr is being pushed on a static frame list and g++
cannot see why that is safe in case the frame_info_ptr is created and
destroyed immediately when passed as value.
It isn't clear why only in this one place g++ sees the issue (probably
because it can inline enough code in this specific case).
Since passing the frame_info_ptr as const reference is cheaper, use
that as workaround for this warning.
PR build/30413
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30413
Tested-by: Kevin Buettner <kevinb@redhat.com>
Reviewed-by: Kevin Buettner <kevinb@redhat.com>
Reviewed-by: Tom Tromey <tom@tromey.com>
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -1003,7 +1003,7 @@ class cplus_language : public language_defn
/* See language.h. */
- CORE_ADDR skip_trampoline (frame_info_ptr fi,
+ CORE_ADDR skip_trampoline (const frame_info_ptr &fi,
CORE_ADDR pc) const override
{
return cplus_skip_trampoline (fi, pc);
diff --git a/gdb/language.c b/gdb/language.c
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -528,7 +528,7 @@ add_set_language_command ()
Return the result from the first that returns non-zero, or 0 if all
`fail'. */
CORE_ADDR
-skip_language_trampoline (frame_info_ptr frame, CORE_ADDR pc)
+skip_language_trampoline (const frame_info_ptr &frame, CORE_ADDR pc)
{
for (const auto &lang : language_defn::languages)
{
diff --git a/gdb/language.h b/gdb/language.h
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -471,7 +471,7 @@ struct language_defn
If that PC falls in a trampoline belonging to this language, return
the address of the first pc in the real function, or 0 if it isn't a
language tramp for this language. */
- virtual CORE_ADDR skip_trampoline (frame_info_ptr fi, CORE_ADDR pc) const
+ virtual CORE_ADDR skip_trampoline (const frame_info_ptr &fi, CORE_ADDR pc) const
{
return (CORE_ADDR) 0;
}
@@ -789,7 +789,7 @@ extern const char *language_str (enum language);
/* Check for a language-specific trampoline. */
-extern CORE_ADDR skip_language_trampoline (frame_info_ptr, CORE_ADDR pc);
+extern CORE_ADDR skip_language_trampoline (const frame_info_ptr &, CORE_ADDR pc);
/* Return demangled language symbol, or NULL. */
extern gdb::unique_xmalloc_ptr<char> language_demangle
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -282,7 +282,7 @@ class objc_language : public language_defn
/* See language.h. */
- CORE_ADDR skip_trampoline (frame_info_ptr frame,
+ CORE_ADDR skip_trampoline (const frame_info_ptr &frame,
CORE_ADDR stop_pc) const override
{
struct gdbarch *gdbarch = get_frame_arch (frame);

View File

@ -0,0 +1,188 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Andrew Burgess <aburgess@redhat.com>
Date: Tue, 20 Jun 2023 09:46:35 +0100
Subject: gdb-rhbz2196395-debuginfod-legacy-openssl-crash.patch
;; Backport upstream commit f3eee5861743d635 to fix a crash triggered
;; when debuginfod makes use of particular openssl settings.
gdb/debuginfod: cleanup debuginfod earlier
A GDB crash was discovered on Fedora GDB that was tracked back to an
issue with the way that debuginfod is cleaned up.
The bug was reported on Fedora 37, 38, and 39. Here are the steps to
reproduce:
1. The file /etc/ssl/openssl.cnf contains the following lines:
[provider_sect]
default = default_sect
##legacy = legacy_sect
##
[default_sect]
activate = 1
##[legacy_sect]
##activate = 1
The bug will occur when the '##' characters are removed so that the
lines in question look like this:
[provider_sect]
default = default_sect
legacy = legacy_sect
[default_sect]
activate = 1
[legacy_sect]
activate = 1
2. Clean up any existing debuginfod cache data:
> rm -rf $HOME/.cache/debuginfod_client
3. Run GDB:
> gdb -nx -q -iex 'set trace-commands on' \
-iex 'set debuginfod enabled on' \
-iex 'set confirm off' \
-ex 'start' -ex 'quit' /bin/ls
+set debuginfod enabled on
+set confirm off
Reading symbols from /bin/ls...
Downloading separate debug info for /usr/bin/ls
... snip ...
Temporary breakpoint 1, main (argc=1, argv=0x7fffffffde38) at ../src/ls.c:1646
1646 {
+quit
Fatal signal: Segmentation fault
----- Backtrace -----
... snip ...
So GDB ends up crashing during exit.
What's happening is that when debuginfod is initialised
debuginfod_begin is called (this is in the debuginfod library), this
in turn sets up libcurl, which makes use of openssl. Somewhere during
this setup process an at_exit function is registered to cleanup some
state.
Back in GDB the debuginfod_client object is managed using this code:
/* Deleter for a debuginfod_client. */
struct debuginfod_client_deleter
{
void operator() (debuginfod_client *c)
{
debuginfod_end (c);
}
};
using debuginfod_client_up
= std::unique_ptr<debuginfod_client, debuginfod_client_deleter>;
And then a global debuginfod_client_up is created to hold a pointer to
the debuginfod_client object. As a global this will be cleaned up
using the standard C++ global object destructor mechanism, which is
run after the at_exit handlers.
However, it is expected that when debuginfod_end is called the
debuginfod_client object will still be in a usable state, that is, we
don't expect the at_exit handlers to have run and started cleaning up
the library state.
To fix this issue we need to ensure that debuginfod_end is called
before the at_exit handlers have a chance to run.
This commit removes the debuginfod_client_up type, and instead has GDB
hold a raw pointer to the debuginfod_client object. We then make use
of GDB's make_final_cleanup to register a function that will call
debuginfod_end.
As GDB's final cleanups are called before exit is called, this means
that debuginfod_end will be called before the at_exit handlers are
called, and the crash identified above is resolved.
It's not obvious how this issue can easily be tested for. The bug does
not appear to manifest when using a local debuginfod server, so we'd
need to setup something more involved. For now I'm proposing this
patch without any associated tests.
diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -96,20 +96,6 @@ struct user_data
ui_out::progress_update progress;
};
-/* Deleter for a debuginfod_client. */
-
-struct debuginfod_client_deleter
-{
- void operator() (debuginfod_client *c)
- {
- debuginfod_end (c);
- }
-};
-
-using debuginfod_client_up
- = std::unique_ptr<debuginfod_client, debuginfod_client_deleter>;
-
-
/* Convert SIZE into a unit suitable for use with progress updates.
SIZE should in given in bytes and will be converted into KB, MB, GB
or remain unchanged. UNIT will be set to "B", "KB", "MB" or "GB"
@@ -180,20 +166,45 @@ progressfn (debuginfod_client *c, long cur, long total)
return 0;
}
+/* Cleanup ARG, which is a debuginfod_client pointer. */
+
+static void
+cleanup_debuginfod_client (void *arg)
+{
+ debuginfod_client *client = static_cast<debuginfod_client *> (arg);
+ debuginfod_end (client);
+}
+
+/* Return a pointer to the single global debuginfod_client, initialising it
+ first if needed. */
+
static debuginfod_client *
get_debuginfod_client ()
{
- static debuginfod_client_up global_client;
+ static debuginfod_client *global_client = nullptr;
if (global_client == nullptr)
{
- global_client.reset (debuginfod_begin ());
+ global_client = debuginfod_begin ();
if (global_client != nullptr)
- debuginfod_set_progressfn (global_client.get (), progressfn);
+ {
+ /* It is important that we cleanup the debuginfod_client object
+ before calling exit. Some of the libraries used by debuginfod
+ make use of at_exit handlers to perform cleanup.
+
+ If we wrapped the debuginfod_client in a unique_ptr and relied
+ on its destructor to cleanup then this would be run as part of
+ the global C++ object destructors, which is after the at_exit
+ handlers, which is too late.
+
+ So instead, we make use of GDB's final cleanup mechanism. */
+ make_final_cleanup (cleanup_debuginfod_client, global_client);
+ debuginfod_set_progressfn (global_client, progressfn);
+ }
}
- return global_client.get ();
+ return global_client;
}
/* Check if debuginfod is enabled. If configured to do so, ask the user

View File

@ -0,0 +1,50 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= <ahajkova@redhat.com>
Date: Thu, 21 Sep 2023 18:52:49 +0200
Subject: gdb-rhbz2233961-CVE-2022-4806.patch
;; Backport PR29922, SHT_NOBITS section
;; avoids section size sanity check.
PR29922, SHT_NOBITS section avoids section size sanity check
PR 29922
* dwarf2.c (find_debug_info): Ignore sections without
SEC_HAS_CONTENTS.
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -4831,16 +4831,19 @@ find_debug_info (bfd *abfd, const struct dwarf_debug_section *debug_sections,
{
look = debug_sections[debug_info].uncompressed_name;
msec = bfd_get_section_by_name (abfd, look);
- if (msec != NULL)
+ /* Testing SEC_HAS_CONTENTS is an anti-fuzzer measure. Of
+ course debug sections always have contents. */
+ if (msec != NULL && (msec->flags & SEC_HAS_CONTENTS) != 0)
return msec;
look = debug_sections[debug_info].compressed_name;
msec = bfd_get_section_by_name (abfd, look);
- if (msec != NULL)
+ if (msec != NULL && (msec->flags & SEC_HAS_CONTENTS) != 0)
return msec;
for (msec = abfd->sections; msec != NULL; msec = msec->next)
- if (startswith (msec->name, GNU_LINKONCE_INFO))
+ if ((msec->flags & SEC_HAS_CONTENTS) != 0
+ && startswith (msec->name, GNU_LINKONCE_INFO))
return msec;
return NULL;
@@ -4848,6 +4851,9 @@ find_debug_info (bfd *abfd, const struct dwarf_debug_section *debug_sections,
for (msec = after_sec->next; msec != NULL; msec = msec->next)
{
+ if ((msec->flags & SEC_HAS_CONTENTS) == 0)
+ continue;
+
look = debug_sections[debug_info].uncompressed_name;
if (strcmp (msec->name, look) == 0)
return msec;

View File

@ -0,0 +1,115 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= <ahajkova@redhat.com>
Date: Sat, 14 Oct 2023 12:37:50 +0200
Subject: gdb-rhbz2233965-memory-leak.patch
;; Backport PR29925, Memory leak in find_abstract_instance
PR29925, Memory leak in find_abstract_instance
The testcase in the PR had a variable with both DW_AT_decl_file and
DW_AT_specification, where the DW_AT_specification also specified
DW_AT_decl_file. This leads to a memory leak as the file name is
malloced and duplicates are not expected.
I've also changed find_abstract_instance to not use a temp for "name",
because that can result in a change in behaviour from the usual last
of duplicate attributes wins.
PR 29925
* dwarf2.c (find_abstract_instance): Delete "name" variable.
Free *filename_ptr before assigning new file name.
(scan_unit_for_symbols): Similarly free func->file and
var->file before assigning.
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -3441,7 +3441,6 @@ find_abstract_instance (struct comp_unit *unit,
struct abbrev_info *abbrev;
uint64_t die_ref = attr_ptr->u.val;
struct attribute attr;
- const char *name = NULL;
if (recur_count == 100)
{
@@ -3602,9 +3601,9 @@ find_abstract_instance (struct comp_unit *unit,
case DW_AT_name:
/* Prefer DW_AT_MIPS_linkage_name or DW_AT_linkage_name
over DW_AT_name. */
- if (name == NULL && is_str_form (&attr))
+ if (*pname == NULL && is_str_form (&attr))
{
- name = attr.u.str;
+ *pname = attr.u.str;
if (mangle_style (unit->lang) == 0)
*is_linkage = true;
}
@@ -3612,7 +3611,7 @@ find_abstract_instance (struct comp_unit *unit,
case DW_AT_specification:
if (is_int_form (&attr)
&& !find_abstract_instance (unit, &attr, recur_count + 1,
- &name, is_linkage,
+ pname, is_linkage,
filename_ptr, linenumber_ptr))
return false;
break;
@@ -3622,7 +3621,7 @@ find_abstract_instance (struct comp_unit *unit,
non-string forms into these attributes. */
if (is_str_form (&attr))
{
- name = attr.u.str;
+ *pname = attr.u.str;
*is_linkage = true;
}
break;
@@ -3630,8 +3629,11 @@ find_abstract_instance (struct comp_unit *unit,
if (!comp_unit_maybe_decode_line_info (unit))
return false;
if (is_int_form (&attr))
- *filename_ptr = concat_filename (unit->line_table,
- attr.u.val);
+ {
+ free (*filename_ptr);
+ *filename_ptr = concat_filename (unit->line_table,
+ attr.u.val);
+ }
break;
case DW_AT_decl_line:
if (is_int_form (&attr))
@@ -3643,7 +3645,6 @@ find_abstract_instance (struct comp_unit *unit,
}
}
}
- *pname = name;
return true;
}
@@ -4139,8 +4140,11 @@ scan_unit_for_symbols (struct comp_unit *unit)
case DW_AT_decl_file:
if (is_int_form (&attr))
- func->file = concat_filename (unit->line_table,
- attr.u.val);
+ {
+ free (func->file);
+ func->file = concat_filename (unit->line_table,
+ attr.u.val);
+ }
break;
case DW_AT_decl_line:
@@ -4182,8 +4186,11 @@ scan_unit_for_symbols (struct comp_unit *unit)
case DW_AT_decl_file:
if (is_int_form (&attr))
- var->file = concat_filename (unit->line_table,
- attr.u.val);
+ {
+ free (var->file);
+ var->file = concat_filename (unit->line_table,
+ attr.u.val);
+ }
break;
case DW_AT_decl_line:

View File

@ -0,0 +1,147 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-rhbz947564-findvar-assertion-frame-failed-testcase.patch
;; Import regression test for `gdb/findvar.c:417: internal-error:
;; read_var_value: Assertion `frame' failed.' (RH BZ 947564) from RHEL 6.5.
;;=fedoratest
diff --git a/gdb/testsuite/gdb.threads/tls-rhbz947564.cc b/gdb/testsuite/gdb.threads/tls-rhbz947564.cc
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/tls-rhbz947564.cc
@@ -0,0 +1,53 @@
+#include <iostream>
+#include <pthread.h>
+
+class x
+ {
+ public:
+ int n;
+
+ x() : n(0) {}
+ };
+
+class y
+ {
+ public:
+ int v;
+
+ y() : v(0) {}
+ static __thread x *xp;
+ };
+
+__thread x *y::xp;
+
+static void
+foo (y *yp)
+{
+ yp->v = 1; /* foo_marker */
+}
+
+static void *
+bar (void *unused)
+{
+ x xinst;
+ y::xp= &xinst;
+
+ y yy;
+ foo(&yy);
+
+ return NULL;
+}
+
+int
+main(int argc, char *argv[])
+{
+ pthread_t t[2];
+
+ pthread_create (&t[0], NULL, bar, NULL);
+ pthread_create (&t[1], NULL, bar, NULL);
+
+ pthread_join (t[0], NULL);
+ pthread_join (t[1], NULL);
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.threads/tls-rhbz947564.exp b/gdb/testsuite/gdb.threads/tls-rhbz947564.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/tls-rhbz947564.exp
@@ -0,0 +1,75 @@
+# Copyright (C) 2013 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 testfile tls-rhbz947564
+set srcfile ${testfile}.cc
+set binfile [standard_output_file ${testfile}]
+
+if [istarget "*-*-linux"] then {
+ set target_cflags "-D_MIT_POSIX_THREADS"
+} else {
+ set target_cflags ""
+}
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list c++ debug]] != "" } {
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_load ${binfile}
+
+if { ![runto_main] } {
+ fail "Can't run to function main"
+ return 0
+}
+
+gdb_breakpoint "foo"
+gdb_continue_to_breakpoint "foo" ".* foo_marker .*"
+
+proc get_xp_val {try} {
+ global expect_out
+ global gdb_prompt
+ global hex
+
+ set xp_val ""
+ gdb_test_multiple "print *yp" "print yp value" {
+ -re { = \{v = 0, static xp = (0x[0-9a-f]+)\}.* } {
+ pass "print $try value of *yp"
+ set xp_val $expect_out(1,string)
+ }
+ -re "$gdb_prompt $" {
+ fail "print $try value of *yp"
+ }
+ timeout {
+ fail "print $try value of *yp (timeout)"
+ }
+ }
+ return $xp_val
+}
+
+set first_run [get_xp_val "first"]
+
+gdb_test "continue" "Breakpoint \[0-9\]+, foo \\\(yp=$hex\\\) at.*"
+
+set second_run [get_xp_val "second"]
+
+if { $first_run != $second_run } {
+ pass "different values for TLS variable"
+} else {
+ fail "different values for TLS variable"
+}

View File

@ -0,0 +1,731 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-rhel5.9-testcase-xlf-var-inside-mod.patch
;; Include testcase for `Unable to see a variable inside a module (XLF)' (BZ 823789).
;;=fedoratest
diff --git a/gdb/testsuite/gdb.fortran/xlf-variable.S b/gdb/testsuite/gdb.fortran/xlf-variable.S
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/xlf-variable.S
@@ -0,0 +1,638 @@
+/* Copyright (C) 2012 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 has been generated from the file named `xlf-variable.f', which
+ should be present in this directory. The command used to generate this
+ file was:
+
+ xlf -qnoopt -g9 -S xlf-variable.f -o xlf-variable.S
+
+ After issuing this command, you must hand-edit this file and remove the
+ mentions for `_xlfExit', since it is only present in XLF-specific
+ libraries. You must also make sure to remove the file named `mod1.mod'
+ which will be created in the compilation directory.
+
+ In order to generated this file, the following XLF package was used:
+
+ xlf.14.1.0.0.linux.eval.tar.gz
+
+ These instructions may be different for different versions of the XLF
+ compiler. */
+
+.set r0,0; .set SP,1; .set RTOC,2; .set r3,3; .set r4,4
+.set r5,5; .set r6,6; .set r7,7; .set r8,8; .set r9,9
+.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14
+.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19
+.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24
+.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29
+.set r30,30; .set r31,31
+.set fp0,0; .set fp1,1; .set fp2,2; .set fp3,3; .set fp4,4
+.set fp5,5; .set fp6,6; .set fp7,7; .set fp8,8; .set fp9,9
+.set fp10,10; .set fp11,11; .set fp12,12; .set fp13,13; .set fp14,14
+.set fp15,15; .set fp16,16; .set fp17,17; .set fp18,18; .set fp19,19
+.set fp20,20; .set fp21,21; .set fp22,22; .set fp23,23; .set fp24,24
+.set fp25,25; .set fp26,26; .set fp27,27; .set fp28,28; .set fp29,29
+.set fp30,30; .set fp31,31
+.set v0,0; .set v1,1; .set v2,2; .set v3,3; .set v4,4
+.set v5,5; .set v6,6; .set v7,7; .set v8,8; .set v9,9
+.set v10,10; .set v11,11; .set v12,12; .set v13,13; .set v14,14
+.set v15,15; .set v16,16; .set v17,17; .set v18,18; .set v19,19
+.set v20,20; .set v21,21; .set v22,22; .set v23,23; .set v24,24
+.set v25,25; .set v26,26; .set v27,27; .set v28,28; .set v29,29
+.set v30,30; .set v31,31
+.set q0,0; .set q1,1; .set q2,2; .set q3,3; .set q4,4
+.set q5,5; .set q6,6; .set q7,7; .set q8,8; .set q9,9
+.set q10,10; .set q11,11; .set q12,12; .set q13,13; .set q14,14
+.set q15,15; .set q16,16; .set q17,17; .set q18,18; .set q19,19
+.set q20,20; .set q21,21; .set q22,22; .set q23,23; .set q24,24
+.set q25,25; .set q26,26; .set q27,27; .set q28,28; .set q29,29
+.set q30,30; .set q31,31
+.set MQ,0; .set XER,1; .set FROM_RTCU,4; .set FROM_RTCL,5; .set FROM_DEC,6
+.set LR,8; .set CTR,9; .set TID,17; .set DSISR,18; .set DAR,19; .set TO_RTCU,20
+.set TO_RTCL,21; .set TO_DEC,22; .set SDR_0,24; .set SDR_1,25; .set SRR_0,26
+.set SRR_1,27
+.set BO_dCTR_NZERO_AND_NOT,0; .set BO_dCTR_NZERO_AND_NOT_1,1
+.set BO_dCTR_ZERO_AND_NOT,2; .set BO_dCTR_ZERO_AND_NOT_1,3
+.set BO_IF_NOT,4; .set BO_IF_NOT_1,5; .set BO_IF_NOT_2,6
+.set BO_IF_NOT_3,7; .set BO_dCTR_NZERO_AND,8; .set BO_dCTR_NZERO_AND_1,9
+.set BO_dCTR_ZERO_AND,10; .set BO_dCTR_ZERO_AND_1,11; .set BO_IF,12
+.set BO_IF_1,13; .set BO_IF_2,14; .set BO_IF_3,15; .set BO_dCTR_NZERO,16
+.set BO_dCTR_NZERO_1,17; .set BO_dCTR_ZERO,18; .set BO_dCTR_ZERO_1,19
+.set BO_ALWAYS,20; .set BO_ALWAYS_1,21; .set BO_ALWAYS_2,22
+.set BO_ALWAYS_3,23; .set BO_dCTR_NZERO_8,24; .set BO_dCTR_NZERO_9,25
+.set BO_dCTR_ZERO_8,26; .set BO_dCTR_ZERO_9,27; .set BO_ALWAYS_8,28
+.set BO_ALWAYS_9,29; .set BO_ALWAYS_10,30; .set BO_ALWAYS_11,31
+.set CR0_LT,0; .set CR0_GT,1; .set CR0_EQ,2; .set CR0_SO,3
+.set CR1_FX,4; .set CR1_FEX,5; .set CR1_VX,6; .set CR1_OX,7
+.set CR2_LT,8; .set CR2_GT,9; .set CR2_EQ,10; .set CR2_SO,11
+.set CR3_LT,12; .set CR3_GT,13; .set CR3_EQ,14; .set CR3_SO,15
+.set CR4_LT,16; .set CR4_GT,17; .set CR4_EQ,18; .set CR4_SO,19
+.set CR5_LT,20; .set CR5_GT,21; .set CR5_EQ,22; .set CR5_SO,23
+.set CR6_LT,24; .set CR6_GT,25; .set CR6_EQ,26; .set CR6_SO,27
+.set CR7_LT,28; .set CR7_GT,29; .set CR7_EQ,30; .set CR7_SO,31
+.set TO_LT,16; .set TO_GT,8; .set TO_EQ,4; .set TO_LLT,2; .set TO_LGT,1
+
+ .file "xlf-variable.f"
+ .globl __mod1_NMOD_____mod1
+ .type __mod1_NMOD_____mod1,@function
+ .size __mod1_NMOD_____mod1,32
+ .globl main
+ .type main,@function
+ .size main,68
+ .globl __mod1_NMOD_sub1
+ .type __mod1_NMOD_sub1,@function
+ .size __mod1_NMOD_sub1,136
+ .globl _main
+ .type _main,@function
+ .size _main,68
+
+ .section ".text"
+ .align 7
+.LC.text:
+__mod1_NMOD_____mod1:
+ stwu SP,-32(SP)
+ stw r31,28(SP)
+ or r31,SP,SP
+ b $+0x4
+ addi r11,r31,32
+ lwz r31,-4(r11)
+ or SP,r11,r11
+ bclr BO_ALWAYS,CR0_LT
+.LC.text32:
+
+__mod1_NMOD_sub1:
+ stwu SP,-32(SP)
+ stw r31,28(SP)
+ stw r30,24(SP)
+ or r31,SP,SP
+ addis r30,r0,.const_dr@ha
+ addi r30,r30,.const_dr@l
+ addis r3,r0,__N_mod1@ha
+ addi r3,r3,__N_mod1@l
+ addi r0,r0,1
+ stb r0,4(r3)
+ addi r4,r0,14
+ stb r4,5(r3)
+ stb r0,7(r3)
+ addis r5,r0,__N__mod1@ha
+ addi r5,r5,__N__mod1@l
+ stw r5,0(r3)
+ lbz r5,6(r3)
+ rlwinm r5,r5,0,25,25
+ ori r5,r5,0x0040
+ stb r5,6(r3)
+ lwz r5,0(r3)
+ lfs fp0,0(r30)
+ stfs fp0,0(r5)
+ stb r0,4(r3)
+ stb r4,5(r3)
+ addi r4,r0,0
+ stb r4,6(r3)
+ stb r0,7(r3)
+ b $+0x4
+ addi r11,r31,32
+ lwz r30,-8(r11)
+ lwz r31,-4(r11)
+ or SP,r11,r11
+ bclr BO_ALWAYS,CR0_LT
+.LC.text168:
+ .long 0
+ .skip 0x54
+.LC.text256:
+
+main:
+_main:
+ mfspr r0,LR
+ stwu SP,-32(SP)
+ stw r31,28(SP)
+ stw r0,36(SP)
+ or r31,SP,SP
+ bl __mod1_NMOD_sub1
+ addi r3,r0,0
+.LC.text288:
+
+ tw TO_EQ,r14,r14
+ addi r3,r0,0
+ b $+0x4
+ addi r11,r31,32
+ lwz r31,-4(r11)
+ lwz r0,4(r11)
+ mtspr LR,r0
+ or SP,r11,r11
+ bclr BO_ALWAYS,CR0_LT
+.LC.text324:
+
+
+ .section ".rodata","a"
+ .align 2
+.LC.rodata:
+ .type .const_dr,@object
+ .size .const_dr,4
+.const_dr:
+ .long 0x40400000
+
+ .section ".eh_frame","wa"
+ .align 2
+.LC.eh_frame:
+ .long 0x0000000c
+ .long 0x00000000
+ .long 0x0100047c
+ .long 0x410c0100
+ .long 0x0000001c
+ .long 0x00000014
+ .long .LC.text
+ .long 0x00000020
+ .long 0x410e2041
+ .long 0x9f01410d
+ .long 0x1f410a42
+ .long 0xdf420b00
+ .long 0x00000020
+ .long 0x00000034
+ .long .LC.text32
+ .long 0x00000088
+ .long 0x410e2041
+ .long 0x9f01419e
+ .long 0x02410d1f
+ .long 0x590a42de
+ .long 0x41df420b
+ .long 0x0000000c
+ .long 0x00000000
+ .long 0x0100047c
+ .long 0x410c0100
+ .long 0x00000020
+ .long 0x00000014
+ .long .LC.text256
+ .long 0x00000044
+ .long 0x420e2041
+ .long 0x9f014111
+ .long 0x417f410d
+ .long 0x1f460a42
+ .long 0xdf440b00
+
+ .section ".data","wa"
+ .align 4
+.LC.data:
+ .globl __N_mod1
+ .type __N_mod1,@object
+ .size __N_mod1,8
+__N_mod1:
+ .long 0x00000000
+ .long 0x01000001
+
+ .section ".except.1","wa"
+ .align 1
+.LC.except.1:
+ .long .LC.text288
+ .byte 0x01
+ .byte 0x09
+
+ .ident "Fri Jun 15 16:35:45 2012 .IBM XL Fortran for Linux, V14.1 (5765-J05, 5725-C75) Version 14.01.0000.0000.Fri Jun 15 16:35:45 2012 .IBM XL Fortran for Linux, V14.1 (5765-J05, 5725-C75) Version 14.01.0000.0000."
+
+ .section ".debug_aranges"
+ .align 0
+.LC.debug_aranges:
+ .long 0x0000001c
+ .byte 0x00
+ .byte 0x02
+ .long .LC.debug_info
+ .long 0x04000000
+ .byte 0x00
+ .byte 0x00
+ .long .LC.text
+ .long 0x000000a8
+ .long 0x00000000
+ .long 0x00000000
+ .long 0x0000001c
+ .byte 0x00
+ .byte 0x02
+ .long .LC.debug_info273
+ .long 0x04000000
+ .byte 0x00
+ .byte 0x00
+ .long .LC.text256
+ .long 0x00000044
+ .long 0x00000000
+ .long 0x00000000
+
+ .section ".debug_pubnames"
+ .align 0
+.LC.debug_pubnames:
+ .long 0x0000002f
+ .byte 0x00
+ .byte 0x02
+ .long .LC.debug_info
+ .long 0x00000111
+ .long 0x000000dc
+ .long 0x79000000
+ .long 0x00ec7a00
+ .long 0x000000fc
+ .long 0x5f5f6d6f
+ .long 0x64315f4e
+ .long 0x4d4f445f
+ .long 0x73756231
+ .long 0x00000000
+ .long 0x00000000
+ .byte 0x18
+ .byte 0x00
+ .byte 0x02
+ .long .LC.debug_info273
+ .long 0x00000127
+ .long 0x0000010f
+ .long 0x5f6d6169
+ .long 0x6e000000
+ .byte 0x00
+ .byte 0x00
+
+ .section ".debug_info"
+ .align 0
+.LC.debug_info:
+ .long 0x0000010d
+ .byte 0x00
+ .byte 0x02
+ .long .LC.debug_abbrev
+ .long 0x0401786c
+ .long 0x662d7661
+ .long 0x72696162
+ .long 0x6c652e66
+ .byte 0x00
+ .long .LC.debug_line
+ .long .LC.text
+ .long .LC.text168
+ .long 0x082f726f
+ .long 0x6f742f73
+ .long 0x65726769
+ .long 0x6f646a2f
+ .long 0x6764622d
+ .long 0x372e302e
+ .long 0x312d3432
+ .long 0x2e656c35
+ .long 0x2f676462
+ .long 0x2d372e30
+ .long 0x2e312f67
+ .long 0x64622f74
+ .long 0x65737473
+ .long 0x75697465
+ .long 0x2f676462
+ .long 0x2e666f72
+ .long 0x7472616e
+ .long 0x0049424d
+ .long 0x20584c20
+ .long 0x466f7274
+ .long 0x72616e20
+ .long 0x666f7220
+ .long 0x4c696e75
+ .long 0x782c2056
+ .long 0x31342e31
+ .long 0x20283537
+ .long 0x36352d4a
+ .long 0x30352c20
+ .long 0x35373235
+ .long 0x2d433735
+ .long 0x29205665
+ .long 0x7273696f
+ .long 0x6e203134
+ .long 0x2e30312e
+ .long 0x30303030
+ .long 0x2e303030
+ .long 0x30000249
+ .long 0x4e544547
+ .long 0x45520004
+ .long 0x05030005
+ .long 0x02524541
+ .long 0x4c000404
+ .long 0x04050000
+ .long 0x0000c706
+ .long 0x6d6f6431
+ .long 0x00070503
+ .long __N_mod1
+ .long 0x79000100
+ .long 0x01000000
+ .long 0xd0070503
+ .long __N__mod1
+ .long 0x7a000100
+ .long 0x01000000
+ .long 0xc7087375
+ .byte 0x62
+ .byte 0x31
+ .byte 0x00
+ .long .LC.text32
+ .long .LC.text168
+ .long 0x01180101
+ .byte 0x6f
+ .byte 0x00
+ .byte 0x00
+.LC.debug_info273:
+ .long 0x00000123
+ .byte 0x00
+ .byte 0x02
+ .long .LC.debug_abbrev97
+ .long 0x0401786c
+ .long 0x662d7661
+ .long 0x72696162
+ .long 0x6c652e66
+ .byte 0x00
+ .long .LC.debug_line98
+ .long .LC.text256
+ .long .LC.text324
+ .long 0x082f726f
+ .long 0x6f742f73
+ .long 0x65726769
+ .long 0x6f646a2f
+ .long 0x6764622d
+ .long 0x372e302e
+ .long 0x312d3432
+ .long 0x2e656c35
+ .long 0x2f676462
+ .long 0x2d372e30
+ .long 0x2e312f67
+ .long 0x64622f74
+ .long 0x65737473
+ .long 0x75697465
+ .long 0x2f676462
+ .long 0x2e666f72
+ .long 0x7472616e
+ .long 0x0049424d
+ .long 0x20584c20
+ .long 0x466f7274
+ .long 0x72616e20
+ .long 0x666f7220
+ .long 0x4c696e75
+ .long 0x782c2056
+ .long 0x31342e31
+ .long 0x20283537
+ .long 0x36352d4a
+ .long 0x30352c20
+ .long 0x35373235
+ .long 0x2d433735
+ .long 0x29205665
+ .long 0x7273696f
+ .long 0x6e203134
+ .long 0x2e30312e
+ .long 0x30303030
+ .long 0x2e303030
+ .long 0x30000249
+ .long 0x4e544547
+ .long 0x45520004
+ .long 0x05030005
+ .long 0x02524541
+ .long 0x4c000404
+ .long 0x04000000
+ .long 0xb9050000
+ .long 0x0000c706
+ .long 0x000000f4
+ .long 0x26264e26
+ .long 0x6d6f6431
+ .long 0x00080779
+ .long 0x00022300
+ .long 0x000000d4
+ .long 0x00060000
+ .long 0x010f2626
+ .long 0x4e26266d
+ .long 0x6f643100
+ .long 0x04077a00
+ .long 0x02230000
+ .long 0x0000c700
+ .long 0x085f6d61
+ .byte 0x69
+ .byte 0x6e
+ .byte 0x00
+ .long .LC.text256
+ .long .LC.text324
+ .long 0x0201016f
+ .long 0x000000b9
+ .byte 0x00
+
+ .section ".debug_abbrev"
+ .align 0
+.LC.debug_abbrev:
+ .long 0x01110103
+ .long 0x08100611
+ .long 0x01120113
+ .long 0x0b1b0825
+ .long 0x08000002
+ .long 0x24000308
+ .long 0x0b0b3e0b
+ .long 0x00000324
+ .long 0x000b0b3e
+ .long 0x0b000004
+ .long 0x15000000
+ .long 0x050f0033
+ .long 0x0b491300
+ .long 0x00061e01
+ .long 0x03080000
+ .long 0x07340002
+ .long 0x0a03083a
+ .long 0x0b3b0b3f
+ .long 0x0c491300
+ .long 0x00082e00
+ .long 0x03081101
+ .long 0x12013a0b
+ .long 0x3b0b3f0c
+ .long 0x400a0000
+ .byte 0x00
+.LC.debug_abbrev97:
+ .long 0x01110103
+ .long 0x08100611
+ .long 0x01120113
+ .long 0x0b1b0825
+ .long 0x08000002
+ .long 0x24000308
+ .long 0x0b0b3e0b
+ .long 0x00000324
+ .long 0x000b0b3e
+ .long 0x0b000004
+ .long 0x15004913
+ .long 0x0000050f
+ .long 0x00330b49
+ .long 0x13000006
+ .long 0x13010113
+ .long 0x03080b0b
+ .long 0x0000070d
+ .long 0x00030838
+ .long 0x0a491300
+ .long 0x00082e00
+ .long 0x03081101
+ .long 0x1201360b
+ .long 0x3f0c400a
+ .long 0x49130000
+ .byte 0x00
+
+ .section ".debug_line"
+ .align 0
+.LC.debug_line:
+ .long 0x0000005e
+ .long 0x00020000
+ .long 0x00220101
+ .long 0x9cdc0a00
+ .long 0x01010101
+ .long 0x00000001
+ .long 0x00786c66
+ .long 0x2d766172
+ .long 0x6961626c
+ .long 0x652e6600
+ .long 0x00000000
+ .long 0x04010005
+ .byte 0x02
+ .long .LC.text
+ .long 0x03130109
+ .long 0x000c0309
+ .long 0x01090014
+ .long 0x037b0109
+ .long 0x00180301
+ .long 0x01090038
+ .long 0x03010109
+ .long 0x000c0301
+ .long 0x01090014
+ .long 0x03010109
+ .long 0x00180001
+ .byte 0x01
+.LC.debug_line98:
+ .long 0x00000046
+ .long 0x00020000
+ .long 0x00220101
+ .long 0x9cdc0a00
+ .long 0x01010101
+ .long 0x00000001
+ .long 0x00786c66
+ .long 0x2d766172
+ .long 0x6961626c
+ .long 0x652e6600
+ .long 0x00000000
+ .long 0x04010005
+ .byte 0x02
+ .long .LC.text256
+ .long 0x031f0109
+ .long 0x00140300
+ .long 0x01090004
+ .long 0x03010109
+ .long 0x002c0001
+ .byte 0x01
+
+ .section ".debug_frame"
+ .align 0
+.LC.debug_frame:
+ .long 0x0000000c
+ .long 0xffffffff
+ .long 0x0100047c
+ .long 0x410c0100
+ .long 0x0000001c
+ .long .LC.debug_frame
+ .long .LC.text
+ .long 0x00000020
+ .long 0x410e2041
+ .long 0x9f01410d
+ .long 0x1f410a42
+ .long 0xdf420b00
+ .long 0x00000020
+ .long .LC.debug_frame
+ .long .LC.text32
+ .long 0x00000088
+ .long 0x410e2041
+ .long 0x9f01419e
+ .long 0x02410d1f
+ .long 0x590a42de
+ .long 0x41df420b
+.LC.debug_frame84:
+ .long 0x0000000c
+ .long 0xffffffff
+ .long 0x0100047c
+ .long 0x410c0100
+ .long 0x00000020
+ .long .LC.debug_frame84
+ .long .LC.text256
+ .long 0x00000044
+ .long 0x420e2041
+ .long 0x9f014111
+ .long 0x417f410d
+ .long 0x1f460a42
+ .long 0xdf440b00
+
+ .section ".debug_pubtypes"
+ .align 0
+.LC.debug_pubtypes:
+ .long 0x00000023
+ .byte 0x00
+ .byte 0x02
+ .long .LC.debug_info
+ .long 0x00000111
+ .long 0x000000b9
+ .long 0x494e5445
+ .long 0x47455200
+ .long 0x000000c7
+ .long 0x5245414c
+ .long 0x00000000
+ .long 0x00000000
+ .byte 0x3e
+ .byte 0x00
+ .byte 0x02
+ .long .LC.debug_info273
+ .long 0x00000127
+ .long 0x000000b9
+ .long 0x494e5445
+ .long 0x47455200
+ .long 0x000000c7
+ .long 0x5245414c
+ .long 0x00000000
+ .long 0xda26264e
+ .long 0x266d6f64
+ .long 0x31000000
+ .long 0x00f42626
+ .long 0x4e26266d
+ .long 0x6f643100
+ .long 0x00000000
+
+ .comm __N__mod1,4,16
diff --git a/gdb/testsuite/gdb.fortran/xlf-variable.exp b/gdb/testsuite/gdb.fortran/xlf-variable.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/xlf-variable.exp
@@ -0,0 +1,37 @@
+# Copyright 2012 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 test can only be run on PPC64 machines.
+
+if { ![istarget powerpc64-*] || ![is_ilp32_target] } {
+ return -1
+}
+
+set testfile "xlf-variable"
+set srcfile ${testfile}.S
+
+if { [prepare_for_testing $testfile.exp $testfile $srcfile] } {
+ return -1
+}
+
+if { ![runto_main] } {
+ return -1
+}
+
+gdb_test "step" ".*y => z.*" "y => z"
+gdb_test "step" ".*y = 3\.0.*" "y = 3.0"
+gdb_test "step" ".*nullify \\(y\\).*" "nullify (y)"
+gdb_test "print z" "= 3" "z = 3"
+gdb_test "ptype z" "= REAL" "z is REAL"
diff --git a/gdb/testsuite/gdb.fortran/xlf-variable.f b/gdb/testsuite/gdb.fortran/xlf-variable.f
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/xlf-variable.f
@@ -0,0 +1,33 @@
+c Copyright 2012 Free Software Foundation, Inc.
+c
+c This program is free software; you can redistribute it and/or modify
+c it under the terms of the GNU General Public License as published by
+c the Free Software Foundation; either version 3 of the License, or
+c (at your option) any later version.
+c
+c This program is distributed in the hope that it will be useful,
+c but WITHOUT ANY WARRANTY; without even the implied warranty of
+c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+c GNU General Public License for more details.
+c
+c You should have received a copy of the GNU General Public License
+c along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+c This file is the Fortran source file for xlf-variable.f.
+c It was used to generate the assembly output called xlf-variable.S,
+c which was generated using IBM's XLF compiler.
+
+ module mod1
+ real, pointer :: y
+ real, target :: z
+ contains
+ subroutine sub1
+ y => z
+ y = 3.0
+ nullify (y)
+ end subroutine
+ end module
+
+ use mod1
+ call sub1
+ end

16
gdb-rpmlintrc Normal file
View File

@ -0,0 +1,16 @@
# This line is mandatory to access the configuration functions
from Config import *
# The testresult logs contain part of the build log and thus
# necessarily mention the buildroot
addFilter ("gdb-testresults.*file-contains-buildroot")
# Historically libinproctrace was always in gdbserver. It's
# LD_PRELOADed into processes, so there are no direct ELF
# dependencies to it. It's required on the remote side (where
# gdbserver is) so it makes sense to put it in the same package.
# This never was a problem for rpmlint before because libinproctrace
# had no SONAME, so the check wasn't active. Now it has, so it's checked
# and because the gdbserver binary has no direct ELF visible dependency
# it's thought to be necessary to follow shlib policy. That's not the case.
addFilter ("gdbserver.*shlib-policy-name-error.*libinproctrace")

View File

@ -0,0 +1,162 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-simultaneous-step-resume-breakpoint-test.patch
;; New test for step-resume breakpoint placed in multiple threads at once.
;;=fedoratest
diff --git a/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c
@@ -0,0 +1,79 @@
+/* Copyright 2009 Free Software Foundation, Inc.
+
+ Written by Fred Fish of Cygnus Support
+ Contributed by Cygnus Support
+
+ 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/>. */
+
+/* Test multiple threads stepping into a .debug_line-less function with
+ a breakpoint placed on its return-to-caller point. */
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+
+#define THREADS 3
+
+static void *
+func (void *unused)
+{
+ int i;
+
+ errno = 0;
+ i = 0xdeadf00d;
+ i = sleep (THREADS); /* sleep-call */
+ if (errno != 0) /* sleep-after */
+ perror ("sleep");
+
+ /* The GDB bug with forgotten step-resume breakpoint could leave stale
+ breakpoint on the I assignment making it a nop. */
+ if (i == 0xdeadf00d)
+ assert (0);
+
+ assert (i == 0);
+
+ pthread_exit (NULL);
+}
+
+int
+main (void)
+{
+ pthread_t threads[THREADS];
+ int threadi;
+
+ for (threadi = 0; threadi < THREADS; threadi++)
+ {
+ int i;
+
+ i = pthread_create (&threads[threadi], NULL, func, NULL);
+ assert (i == 0);
+
+ i = sleep (1);
+ assert (i == 0);
+ }
+
+ for (threadi = 0; threadi < THREADS; threadi++)
+ {
+ int i;
+
+ i = pthread_join (threads[threadi], NULL);
+ assert (i == 0);
+ }
+
+ return 0; /* final-exit */
+}
diff --git a/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp
@@ -0,0 +1,65 @@
+# Copyright (C) 2009 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+# Test multiple threads stepping into a .debug_line-less function with
+# a breakpoint placed on its return-to-caller point.
+
+set testfile simultaneous-step-resume-breakpoint
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+# Ensure we have no debuginfo for the `sleep' call itself (=for libc).
+gdb_test "set debug-file-directory /DoesNotExist"
+
+gdb_load ${binfile}
+if ![runto_main] {
+ return -1
+}
+
+# Red Hat vendor patch does set it to "step" by default.
+gdb_test "set scheduler-locking off"
+
+gdb_breakpoint [gdb_get_line_number "final-exit"]
+
+gdb_breakpoint [gdb_get_line_number "sleep-call"]
+gdb_continue_to_breakpoint "sleep-call"
+
+gdb_test "step" "sleep-call.*" "step thread 1"
+gdb_test "step" "sleep-call.*" "step thread 2"
+gdb_test "step" "sleep-after.*" "step thread 3"
+
+set test "first continue"
+gdb_test_multiple "continue" $test {
+ -re "final-exit.*$gdb_prompt $" {
+ # gdb-7.0.
+ pass $test
+ return
+ }
+ -re "sleep-after.*$gdb_prompt $" {
+ # Fedora/RHEL branch.
+ pass $test
+ }
+}
+
+gdb_test "continue" "sleep-after.*" "second continue"
+gdb_test "continue" "final-exit.*" "third continue"

View File

@ -0,0 +1,45 @@
From 1bbcd2144710c4b1daa9c404df0ebc80c3461747 Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich <iii@linux.ibm.com>
Date: Thu, 22 Jun 2023 01:03:04 +0200
Subject: [PATCH 11/12] gdb: support rseq auxvs
Linux kernel commit commit 317c8194e6ae ("rseq: Introduce feature size
and alignment ELF auxiliary vector entries") introduced two new auxvs:
AT_RSEQ_FEATURE_SIZE and AT_RSEQ_ALIGN. Support them in GDB. This
fixes auxv.exp on kernels >= v6.3.
---
gdb/auxv.c | 4 ++++
include/elf/common.h | 2 ++
2 files changed, 6 insertions(+)
diff --git a/gdb/auxv.c b/gdb/auxv.c
index 812b2807554..3ce5ccd3342 100644
--- a/gdb/auxv.c
+++ b/gdb/auxv.c
@@ -493,6 +493,10 @@ default_print_auxv_entry (struct gdbarch *gdbarch, struct ui_file *file,
AUXV_FORMAT_STR);
TAG (AT_RANDOM, _("Address of 16 random bytes"), AUXV_FORMAT_HEX);
TAG (AT_HWCAP2, _("Extension of AT_HWCAP"), AUXV_FORMAT_HEX);
+ TAG (AT_RSEQ_FEATURE_SIZE, _("rseq supported feature size"),
+ AUXV_FORMAT_HEX);
+ TAG (AT_RSEQ_ALIGN, _("rseq allocation alignment"),
+ AUXV_FORMAT_HEX);
TAG (AT_EXECFN, _("File name of executable"), AUXV_FORMAT_STR);
TAG (AT_SECURE, _("Boolean, was exec setuid-like?"), AUXV_FORMAT_DEC);
TAG (AT_SYSINFO, _("Special system info/entry points"), AUXV_FORMAT_HEX);
diff --git a/include/elf/common.h b/include/elf/common.h
index 16587f6fb06..a37b1f9a264 100644
--- a/include/elf/common.h
+++ b/include/elf/common.h
@@ -1353,6 +1353,8 @@
may differ from AT_PLATFORM. */
#define AT_RANDOM 25 /* Address of 16 random bytes. */
#define AT_HWCAP2 26 /* Extension of AT_HWCAP. */
+#define AT_RSEQ_FEATURE_SIZE 27 /* rseq supported feature size */
+#define AT_RSEQ_ALIGN 28 /* rseq allocation alignment */
#define AT_EXECFN 31 /* Filename of executable. */
/* Pointer to the global system page used for system calls and other
nice things. */
--
2.35.3

View File

@ -0,0 +1,299 @@
From 7f4601b0a51f400bd1b1bc0f7895254d467e3bb4 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Fri, 21 Jul 2023 08:25:25 +0200
Subject: [PATCH] [gdb/symtab] Add optimized out static var to cooked index
Consider the test-case:
...
$ cat main.c
int main (void) { return 0; }
$ cat static-optimized-out.c
static int aaa;
...
compiled like this:
...
$ gcc-12 static-optimized-out.c main.c -g -O2 -flto
...
There's a difference in behaviour depending on symtab expansion state:
...
$ gdb -q -batch a.out -ex "print aaa"
No symbol "aaa" in current context.
$ gdb -q -batch a.out -ex "maint expand-symtab" -ex "print aaa"
$1 = <optimized out>
...
The reason for the difference is that the optimized out variable aaa:
...
<1><104>: Abbrev Number: 2 (DW_TAG_variable)
<105> DW_AT_name : aaa
<109> DW_AT_decl_file : 1
<10a> DW_AT_decl_line : 18
<10b> DW_AT_decl_column : 12
<10c> DW_AT_type : <0x110>
...
is not added to the cooked index because of this clause in abbrev_table::read:
...
else if (!has_location && !has_specification_or_origin && !has_external
&& cur_abbrev->tag == DW_TAG_variable)
cur_abbrev->interesting = false;
...
Fix this inconsistency by making sure that the optimized out variable is added
to the cooked index.
Regression tested on x86_64-linux.
Add two test-cases, a C test-case gdb.opt/static-optimized-out.exp and a dwarf
assembly test-case gdb.dwarf2/static-optimized-out.exp.
Tested gdb.opt/static-optimized-out.exp with gcc-8 to gcc-12, for which we now
consistently get:
...
(gdb) print aaa^M
$1 = <optimized out>^M
...
and with gcc 7.5.0 and clang 13.0.1, for which we still consistently get:
...
(gdb) print aaa^M
No symbol "aaa" in current context.^M
...
due to missing debug info for the variable.
PR symtab/30656
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30656
Approved-By: Tom Tromey <tom@tromey.com>
---
gdb/dwarf2/abbrev.c | 9 ---
.../gdb.dwarf2/static-optimized-out.exp | 69 +++++++++++++++++++
gdb/testsuite/gdb.opt/main.c | 22 ++++++
gdb/testsuite/gdb.opt/static-optimized-out.c | 18 +++++
.../gdb.opt/static-optimized-out.exp | 49 +++++++++++++
5 files changed, 158 insertions(+), 9 deletions(-)
create mode 100644 gdb/testsuite/gdb.dwarf2/static-optimized-out.exp
create mode 100644 gdb/testsuite/gdb.opt/main.c
create mode 100644 gdb/testsuite/gdb.opt/static-optimized-out.c
create mode 100644 gdb/testsuite/gdb.opt/static-optimized-out.exp
diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
index 1ebf8f6eed5..3a429fd41b1 100644
--- a/gdb/dwarf2/abbrev.c
+++ b/gdb/dwarf2/abbrev.c
@@ -162,7 +162,6 @@ abbrev_table::read (struct dwarf2_section_info *section,
bool has_specification_or_origin = false;
bool has_name = false;
bool has_linkage_name = false;
- bool has_location = false;
bool has_external = false;
/* Now read in declarations. */
@@ -217,11 +216,6 @@ abbrev_table::read (struct dwarf2_section_info *section,
has_linkage_name = true;
break;
- case DW_AT_const_value:
- case DW_AT_location:
- has_location = true;
- break;
-
case DW_AT_sibling:
if (is_csize && cur_attr.form == DW_FORM_ref4)
sibling_offset = size;
@@ -296,9 +290,6 @@ abbrev_table::read (struct dwarf2_section_info *section,
cur_abbrev->interesting = false;
else if (!tag_interesting_for_index (cur_abbrev->tag))
cur_abbrev->interesting = false;
- else if (!has_location && !has_specification_or_origin && !has_external
- && cur_abbrev->tag == DW_TAG_variable)
- cur_abbrev->interesting = false;
else
cur_abbrev->interesting = true;
diff --git a/gdb/testsuite/gdb.dwarf2/static-optimized-out.exp b/gdb/testsuite/gdb.dwarf2/static-optimized-out.exp
new file mode 100644
index 00000000000..1547a8acbc0
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/static-optimized-out.exp
@@ -0,0 +1,69 @@
+# Copyright 2023 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/>.
+
+# Check that an optimized out static variable is printed the same independent
+# of state of symtab expansion. See also gdb.opt/static-optimized-out.exp.
+
+load_lib dwarf.exp
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+if { ![dwarf2_support] } {
+ return 0
+}
+
+standard_testfile main.c -dw.S
+
+# Make DWARF for the test.
+set asm_file [standard_output_file $srcfile2]
+Dwarf::assemble $asm_file {
+ cu {} {
+ compile_unit {
+ {
+ language @DW_LANG_C
+ }
+ } {
+ declare_labels integer_label
+
+ integer_label: DW_TAG_base_type {
+ {DW_AT_byte_size 4 DW_FORM_sdata}
+ {DW_AT_encoding @DW_ATE_signed}
+ {DW_AT_name integer}
+ }
+
+ DW_TAG_variable {
+ {name var}
+ {type :$integer_label}
+ }
+ }
+ }
+}
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+ [list $srcfile $asm_file] {nodebug}] } {
+ return -1
+}
+
+gdb_test "print var" " = <optimized out>"
+
+# Expand all symbol tables.
+gdb_test_no_output "maint expand-symtabs"
+
+# Make sure we do an actual lookup rather than just returning the same as
+# before.
+gdb_test_no_output "maint flush symbol-cache"
+
+with_test_prefix "after expand-symtabs" {
+ gdb_test "print var" " = <optimized out>"
+}
diff --git a/gdb/testsuite/gdb.opt/main.c b/gdb/testsuite/gdb.opt/main.c
new file mode 100644
index 00000000000..c6beff77dbe
--- /dev/null
+++ b/gdb/testsuite/gdb.opt/main.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2023 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/>. */
+
+int
+main (void)
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.opt/static-optimized-out.c b/gdb/testsuite/gdb.opt/static-optimized-out.c
new file mode 100644
index 00000000000..44287fbd6d2
--- /dev/null
+++ b/gdb/testsuite/gdb.opt/static-optimized-out.c
@@ -0,0 +1,18 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2023 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/>. */
+
+static int aaa;
diff --git a/gdb/testsuite/gdb.opt/static-optimized-out.exp b/gdb/testsuite/gdb.opt/static-optimized-out.exp
new file mode 100644
index 00000000000..bd673b6503e
--- /dev/null
+++ b/gdb/testsuite/gdb.opt/static-optimized-out.exp
@@ -0,0 +1,49 @@
+# Copyright 2023 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/>.
+
+# Check that an optimized out static variable is printed the same independent
+# of state of symtab expansion. See also gdb.dwarf2/static-optimized-out.exp.
+
+standard_testfile .c main.c
+
+set opts {}
+lappend opts debug
+lappend opts "optimize=-O2 -flto"
+
+if { [prepare_for_testing "failed to prepare" $testfile \
+ [list $srcfile $srcfile2] $opts] } {
+ return -1
+}
+
+set val ""
+gdb_test_multiple "print aaa" "" {
+ -re -wrap "\r\n(?:\\$$decimal = )?(\[^\r\n\]*)" {
+ set val $expect_out(1,string)
+ }
+}
+
+if { $val == "" } {
+ return
+}
+
+# Expand all symbol tables.
+gdb_test_no_output "maint expand-symtab"
+
+# Make sure we do an actual lookup rather than just returning the same as
+# before.
+gdb_test_no_output "maint flush symbol-cache"
+
+# Now check that we get the same result in both cases.
+gdb_test "print aaa" [string_to_regexp $val] "consistency"
base-commit: 800c393f89a94f49b01dff99f693cb13c5e28116
--
2.35.3

View File

@ -0,0 +1,125 @@
From aa8ba17b9a3fdfeeb65df4c3e0731a0e9e96cbf7 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Wed, 1 Nov 2023 00:33:12 +0100
Subject: [PATCH 1/2] [gdb/symtab] Add producer_is_gas
Add producer_is_gas, a generic way to get the gas version from the
producer string.
Tested on x86_64-linux.
---
gdb/dwarf2/read.c | 4 ++--
gdb/producer.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
gdb/producer.h | 5 +++++
3 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 970dd54c7a5..472684a5817 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -13376,8 +13376,8 @@ check_producer (struct dwarf2_cu *cu)
cu->producer_is_codewarrior = true;
else if (producer_is_clang (cu->producer, &major, &minor))
cu->producer_is_clang = true;
- else if (startswith (cu->producer, "GNU AS 2.39.0"))
- cu->producer_is_gas_2_39 = true;
+ else if (producer_is_gas (cu->producer, &major, &minor))
+ cu->producer_is_gas_2_39 = major == 2 && minor == 39;
else
{
/* For other non-GCC compilers, expect their behavior is DWARF version
diff --git a/gdb/producer.c b/gdb/producer.c
index 9fcf749e3d4..cd83dfce128 100644
--- a/gdb/producer.c
+++ b/gdb/producer.c
@@ -81,6 +81,45 @@ producer_is_gcc (const char *producer, int *major, int *minor)
/* See producer.h. */
+bool
+producer_is_gas (const char *producer, int *major, int *minor)
+{
+ if (producer == nullptr)
+ {
+ /* No producer, don't know. */
+ return false;
+ }
+
+ /* Detect prefix. */
+ const char prefix[] = "GNU AS ";
+ if (!startswith (producer, prefix))
+ {
+ /* Producer is not gas. */
+ return false;
+ }
+
+ /* Skip prefix. */
+ const char *cs = &producer[strlen (prefix)];
+
+ /* Ensure that major/minor are not nullptrs. */
+ int maj, min;
+ if (major == nullptr)
+ major = &maj;
+ if (minor == nullptr)
+ minor = &min;
+
+ int scanned = sscanf (cs, "%d.%d", major, minor);
+ if (scanned != 2)
+ {
+ /* Unable to scan major/minor version. */
+ return false;
+ }
+
+ return true;
+}
+
+ /* See producer.h. */
+
bool
producer_is_icc_ge_19 (const char *producer)
{
@@ -251,6 +290,23 @@ Version 18.0 Beta";
SELF_CHECK (!producer_is_gcc (flang_llvm_exp, &major, &minor));
SELF_CHECK (producer_is_llvm (flang_llvm_exp));
}
+
+ {
+ static const char gas_exp[] = "GNU AS 2.39.0";
+ int major = 0, minor = 0;
+ SELF_CHECK (!producer_is_gcc (gas_exp, &major, &minor));
+ SELF_CHECK (producer_is_gas (gas_exp, &major, &minor));
+ SELF_CHECK (major == 2 && minor == 39);
+
+ static const char gas_incomplete_exp[] = "GNU AS ";
+ SELF_CHECK (!producer_is_gas (gas_incomplete_exp, &major, &minor));
+ SELF_CHECK (!producer_is_gcc (gas_incomplete_exp, &major, &minor));
+
+ static const char gas_incomplete_exp_2[] = "GNU AS 2";
+ SELF_CHECK (!producer_is_gas (gas_incomplete_exp_2, &major, &minor));
+ SELF_CHECK (!producer_is_gcc (gas_incomplete_exp_2, &major, &minor));
+ }
+
}
}
}
diff --git a/gdb/producer.h b/gdb/producer.h
index c915979b122..00718511775 100644
--- a/gdb/producer.h
+++ b/gdb/producer.h
@@ -30,6 +30,11 @@ extern int producer_is_gcc_ge_4 (const char *producer);
is NULL or it isn't GCC. */
extern int producer_is_gcc (const char *producer, int *major, int *minor);
+/* Returns nonzero if the given PRODUCER string is GAS and sets the MAJOR
+ and MINOR versions when not NULL. Returns zero if the given PRODUCER
+ is NULL or it isn't GAS. */
+bool producer_is_gas (const char *producer, int *major, int *minor);
+
/* Check for Intel compilers >= 19.0. */
extern bool producer_is_icc_ge_19 (const char *producer);
base-commit: 39553c1e285c426946188ec2a890c1c1cb933060
--
2.35.3

View File

@ -0,0 +1,81 @@
From 04d0d6ebdc6d08f5a7ec0d4c89eb1835deef54dc Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Sun, 13 Aug 2023 14:08:06 +0200
Subject: [PATCH] [gdb/symtab] Don't deduplicate variables in gdb-index
When running test-case gdb.python/py-symbol.exp with target board
cc-with-gdb-index, we run into:
...
(gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M
1^M
(gdb) FAIL: gdb.python/py-symbol.exp: print (len (gdb.lookup_static_symbols ('rr')))
...
[ Note that the test-case contains rr in both py-symtab.c:
...
static int __attribute__ ((used)) rr = 42; /* line of rr */
...
and py-symtab-2.c:
...
static int __attribute__ ((used)) rr = 99; /* line of other rr */
... ]
This passes with gdb-12-branch, and fails with gdb-13-branch.
AFAIU the current code in symtab_index_entry::minimize makes the assumption
that it's fine to store only one copy of rr in the gdb-index, because
"print rr" will only ever print one, and always the same.
But that fails to recognize that gdb supports gdb.lookup_static_symbols, which
returns a list of variables rather than the first one.
In other words, the current approach breaks feature parity between cooked
index and gdb-index.
Note btw that also debug-names has both instances:
...
[ 5] #00597969 rr:
<4> DW_TAG_variable DW_IDX_compile_unit=3 DW_IDX_GNU_internal=1
<4> DW_TAG_variable DW_IDX_compile_unit=4 DW_IDX_GNU_internal=1
...
Fix this in symtab_index_entry::minimize, by not deduplicating variables.
Tested on x86_64-linux, with target boards unix and cc-with-gdb-index.
Reviewed-by: Kevin Buettner <kevinb@redhat.com>
PR symtab/30720
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30720
---
gdb/dwarf2/index-write.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index d10583568c0..ea67f73ac3c 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -294,7 +294,7 @@ symtab_index_entry::minimize ()
auto from = std::unique (cu_indices.begin (), cu_indices.end ());
cu_indices.erase (from, cu_indices.end ());
- /* We don't want to enter a variable or type more than once, so
+ /* We don't want to enter a type more than once, so
remove any such duplicates from the list as well. When doing
this, we want to keep the entry from the first CU -- but this is
implicit due to the sort. This choice is done because it's
@@ -304,8 +304,7 @@ symtab_index_entry::minimize ()
[&] (offset_type val)
{
gdb_index_symbol_kind kind = GDB_INDEX_SYMBOL_KIND_VALUE (val);
- if (kind != GDB_INDEX_SYMBOL_KIND_TYPE
- && kind != GDB_INDEX_SYMBOL_KIND_VARIABLE)
+ if (kind != GDB_INDEX_SYMBOL_KIND_TYPE)
return false;
val &= ~GDB_INDEX_CU_MASK;
base-commit: 2521ac7ed0c495b9e804c4356939b9be7166853c
--
2.35.3

View File

@ -0,0 +1,74 @@
From 6d472b241c96f181f88867860e92f1dfe7364903 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Sat, 16 Sep 2023 04:07:22 +0200
Subject: [PATCH 08/11] [gdb/symtab] Don't defer backward refs, inter-cu
intra-shard case
In patch "[gdb/symtab] Resolve deferred entries, inter-shard case" we've
solved the generic case of handling deferred entries.
Add an optimization that doesn't defer inter-CU intra-shard dependencies that
are present in the shard's parent map.
Tested on x86_64-linux.
---
gdb/dwarf2/read.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 0ab3e1a1500..d2d50b5c9cc 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -6709,6 +6709,12 @@ class cooked_index_storage
m_index->set_parent_valid (start, end);
}
+ /* Return true if find_parents can be relied upon. */
+ bool parent_valid (CORE_ADDR addr)
+ {
+ return m_index->parent_valid (addr);
+ }
+
private:
/* Hash function for a cutu_reader. */
@@ -6857,6 +6863,12 @@ class cooked_indexer
{
m_index_storage->set_parent_valid (start, end);
}
+
+ /* Return true if find_parents can be relied upon. */
+ bool parent_valid (CORE_ADDR addr)
+ {
+ return m_index_storage->parent_valid (addr);
+ }
};
/* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
@@ -18387,7 +18399,22 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu,
else
{
/* Inter-CU case. */
- *maybe_defer = addr;
+ if (parent_valid (addr))
+ {
+ auto tmp = find_parent (addr);
+ if (tmp == &parent_map::deferred)
+ {
+ /* Defer because origin is deferred. */
+ *maybe_defer = addr;
+ }
+ else
+ *parent_entry = tmp;
+ }
+ else
+ {
+ /* Defer because origin is in other shard. */
+ *maybe_defer = addr;
+ }
}
}
--
2.35.3

View File

@ -0,0 +1,76 @@
From dac6c3b27a77589078add7e4e4586515ac85610d Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Fri, 15 Sep 2023 08:38:00 +0200
Subject: [PATCH 04/11] [gdb/symtab] Factor out m_deferred_entries usage
Factor out usage of cooked_indexer::m_deferred_entries in new member
functions defer_entry, handle_deferred_entries and resolve_deferred_entry.
Tested on x86_64-linux.
---
gdb/dwarf2/read.c | 35 ++++++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 1092cb1dca9..ff5be8e7dc5 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -6822,6 +6822,32 @@ class cooked_indexer
we'll know the containing context of all the DIEs that we might
have scanned. This vector stores these deferred entries. */
std::vector<deferred_entry> m_deferred_entries;
+
+ /* Defer creating a cooked_index_entry corresponding to deferred_entry DE. */
+ void defer_entry (const deferred_entry &de)
+ {
+ m_deferred_entries.push_back (de);
+ }
+
+ /* Create a cooked_index_entry corresponding to deferred_entry DE with
+ parent PARENT_ENTRY. */
+ const cooked_index_entry *resolve_deferred_entry
+ (const deferred_entry &de, const cooked_index_entry *parent_entry)
+ {
+ return m_index_storage->add (de.die_offset, de.tag, de.flags, de.name,
+ parent_entry, m_per_cu);
+ }
+
+ /* Create cooked_index_entries for the deferred entries. */
+ void handle_deferred_entries ()
+ {
+ for (const auto &entry : m_deferred_entries)
+ {
+ const cooked_index_entry *parent_entry
+ = find_parent (entry.spec_offset);
+ resolve_deferred_entry (entry, parent_entry);
+ }
+ }
};
/* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
@@ -18519,7 +18545,7 @@ cooked_indexer::index_dies (cutu_reader *reader,
if (name != nullptr)
{
if (defer != 0)
- m_deferred_entries.push_back ({
+ defer_entry ({
this_die, name, defer, abbrev->tag, flags
});
else
@@ -18624,12 +18650,7 @@ cooked_indexer::make_index (cutu_reader *reader)
return;
index_dies (reader, reader->info_ptr, nullptr, false);
- for (const auto &entry : m_deferred_entries)
- {
- const cooked_index_entry *parent = find_parent (entry.spec_offset);
- m_index_storage->add (entry.die_offset, entry.tag, entry.flags,
- entry.name, parent, m_per_cu);
- }
+ handle_deferred_entries ();
}
/* An implementation of quick_symbol_functions for the cooked DWARF
--
2.35.3

View File

@ -0,0 +1,153 @@
From 6ac3acf29782a059258fdfe21bd55f1716fc46ed Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Tue, 22 Aug 2023 13:17:47 +0200
Subject: [PATCH 02/11] [gdb/symtab] Factor out m_die_range_map usage
Factor out usage of cooked_indexer::m_die_range_map into new class parent_map
with member functions find_parent and set_parent, and static member function
form_addr.
Tested on x86_64-linux.
---
gdb/dwarf2/cooked-index.h | 32 ++++++++++++++++++++++++++
gdb/dwarf2/read.c | 48 +++++++++++++++++++++------------------
2 files changed, 58 insertions(+), 22 deletions(-)
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index 2ef1f4b27e9..1c967bdbf86 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -233,6 +233,38 @@ struct cooked_index_entry : public allocate_on_obstack
bool for_name) const;
};
+class parent_map
+{
+public:
+ /* A helper function to turn a section offset into an address that
+ can be used in a parent_map. */
+ static CORE_ADDR form_addr (sect_offset offset, bool is_dwz)
+ {
+ CORE_ADDR value = to_underlying (offset);
+ if (is_dwz)
+ value |= ((CORE_ADDR) 1) << (8 * sizeof (CORE_ADDR) - 1);
+ return value;
+ }
+
+ /* Find the parent of DIE LOOKUP. */
+ const cooked_index_entry *find_parent (CORE_ADDR lookup) const
+ {
+ const void *obj = m_parent_map.find (lookup);
+ return static_cast<const cooked_index_entry *> (obj);
+ }
+
+ /* Set the parent of DIES in range [START, END] to PARENT_ENTRY. */
+ void set_parent (CORE_ADDR start, CORE_ADDR end,
+ const cooked_index_entry *parent_entry)
+ {
+ m_parent_map.set_empty (start, end, (void *)parent_entry);
+ }
+
+private:
+ /* An addrmap that maps from section offsets to cooked_index_entry *. */
+ addrmap_mutable m_parent_map;
+};
+
class cooked_index_vector;
/* An index of interesting DIEs. This is "cooked", in contrast to a
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 00471d20d41..1092cb1dca9 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -6722,16 +6722,6 @@ class cooked_indexer
private:
- /* A helper function to turn a section offset into an address that
- can be used in an addrmap. */
- CORE_ADDR form_addr (sect_offset offset, bool is_dwz)
- {
- CORE_ADDR value = to_underlying (offset);
- if (is_dwz)
- value |= ((CORE_ADDR) 1) << (8 * sizeof (CORE_ADDR) - 1);
- return value;
- }
-
/* A helper function to scan the PC bounds of READER and record them
in the storage's addrmap. */
void check_bounds (cutu_reader *reader);
@@ -6799,7 +6789,20 @@ class cooked_indexer
/* An addrmap that maps from section offsets (see the form_addr
method) to newly-created entries. See m_deferred_entries to
understand this. */
- addrmap_mutable m_die_range_map;
+ parent_map m_die_range_map;
+
+ /* Find the parent of DIE LOOKUP. */
+ const cooked_index_entry *find_parent (CORE_ADDR lookup) const
+ {
+ return m_die_range_map.find_parent (lookup);
+ }
+
+ /* Set the parent of DIES in range [START, END] to PARENT_ENTRY. */
+ void set_parent (CORE_ADDR start, CORE_ADDR end,
+ const cooked_index_entry *parent_entry)
+ {
+ m_die_range_map.set_parent (start, end, parent_entry);
+ }
/* A single deferred entry. */
struct deferred_entry
@@ -18317,15 +18320,13 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu,
if (*parent_entry == nullptr)
{
- CORE_ADDR addr = form_addr (origin_offset, origin_is_dwz);
+ CORE_ADDR addr
+ = parent_map::form_addr (origin_offset, origin_is_dwz);
if (new_reader->cu == reader->cu
&& new_info_ptr > watermark_ptr)
*maybe_defer = addr;
else
- {
- void *obj = m_die_range_map.find (addr);
- *parent_entry = static_cast <cooked_index_entry *> (obj);
- }
+ *parent_entry = find_parent (addr);
}
unsigned int bytes_read;
@@ -18444,11 +18445,15 @@ cooked_indexer::recurse (cutu_reader *reader,
if (parent_entry != nullptr)
{
- CORE_ADDR start = form_addr (parent_entry->die_offset,
- reader->cu->per_cu->is_dwz);
- CORE_ADDR end = form_addr (sect_offset (info_ptr - 1 - reader->buffer),
+ /* Both start and end are inclusive, so use both "+ 1" and "- 1" to
+ limit the range to the children of parent_entry. */
+ CORE_ADDR start
+ = parent_map::form_addr (parent_entry->die_offset + 1,
+ reader->cu->per_cu->is_dwz);
+ CORE_ADDR end
+ = parent_map::form_addr (sect_offset (info_ptr - 1 - reader->buffer),
reader->cu->per_cu->is_dwz);
- m_die_range_map.set_empty (start, end, (void *) parent_entry);
+ set_parent (start, end, parent_entry);
}
return info_ptr;
@@ -18621,8 +18626,7 @@ cooked_indexer::make_index (cutu_reader *reader)
for (const auto &entry : m_deferred_entries)
{
- void *obj = m_die_range_map.find (entry.spec_offset);
- cooked_index_entry *parent = static_cast<cooked_index_entry *> (obj);
+ const cooked_index_entry *parent = find_parent (entry.spec_offset);
m_index_storage->add (entry.die_offset, entry.tag, entry.flags,
entry.name, parent, m_per_cu);
}
--
2.35.3

View File

@ -0,0 +1,202 @@
From e2f41776aa9ca2f625bbc50e9bb498e2a95dba25 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Sat, 5 Aug 2023 17:57:13 +0200
Subject: [PATCH] [gdb/symtab] Find main language without symtab expansion
When loading an executable using "file a.out", the language is set according
to a.out, which can involve looking up the language of symbol "main", which
will cause the symtab expansion for the containing CU.
Expansion of lto debug info can be slow, so in commit d3214198119 ("[gdb] Use
partial symbol table to find language for main") a feature was added to avoid
the symtab expansion.
This feature stopped working after commit 7f4307436fd ("Fix "start" for D,
Rust, etc").
[ The commit addresses problems related to command start, which requires finding
the main function:
- for language D, "main" was found instead of "D main", and
- for Rust, the correct function was found, but attributed the wrong name
(not fully qualified). ]
Reimplement the feature by adding
cooked_index_functions::lookup_global_symbol_language.
Tested on x86_64-linux.
PR symtab/30661
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30661
---
gdb/dwarf2/read.c | 41 +++++++++++++++++++++++++++++++
gdb/testsuite/gdb.base/main-c.exp | 33 +++++++++++++++++++++++++
gdb/testsuite/gdb.cp/main-cp.exp | 33 +++++++++++++++++++++++++
gdb/testsuite/gdb.cp/main.cc | 22 +++++++++++++++++
4 files changed, 129 insertions(+)
create mode 100644 gdb/testsuite/gdb.base/main-c.exp
create mode 100644 gdb/testsuite/gdb.cp/main-cp.exp
create mode 100644 gdb/testsuite/gdb.cp/main.cc
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 04bc0e1cbbd..8aa7f8c31e5 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -18621,6 +18621,47 @@ struct cooked_index_functions : public dwarf2_base_index_functions
if (dwarf2_has_info (objfile, nullptr))
dwarf2_build_psymtabs (objfile);
}
+
+ enum language lookup_global_symbol_language (struct objfile *objfile,
+ const char *name,
+ domain_enum domain,
+ bool *symbol_found_p) override
+ {
+ *symbol_found_p = false;
+
+ if (!(domain == VAR_DOMAIN && streq (name, "main")))
+ return language_unknown;
+
+ dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
+ struct dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
+ if (per_bfd->index_table == nullptr)
+ return language_unknown;
+
+ /* Expansion of large CUs can be slow. By returning the language of main
+ here for C and C++, we avoid CU expansion during set_initial_language.
+ But by doing a symbol lookup in the cooked index, we are forced to wait
+ for finalization to complete. See PR symtab/30174 for ideas how to
+ bypass that as well. */
+ cooked_index_vector *table
+ = (gdb::checked_static_cast<cooked_index_vector *>
+ (per_objfile->per_bfd->index_table.get ()));
+ table->wait ();
+
+ for (const cooked_index_entry *entry : table->find (name, false))
+ {
+ if (entry->tag != DW_TAG_subprogram)
+ continue;
+
+ enum language lang = entry->per_cu->lang ();
+ if (!(lang == language_c || lang == language_cplus))
+ continue;
+
+ *symbol_found_p = true;
+ return lang;
+ }
+
+ return language_unknown;
+ }
};
dwarf2_per_cu_data *
diff --git a/gdb/testsuite/gdb.base/main-c.exp b/gdb/testsuite/gdb.base/main-c.exp
new file mode 100644
index 00000000000..bcbd0fca7e4
--- /dev/null
+++ b/gdb/testsuite/gdb.base/main-c.exp
@@ -0,0 +1,33 @@
+# Copyright 2023 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/>.
+
+# Check that finding main to set the current language doesn't cause any symtab
+# to be expanded.
+
+standard_testfile main.c
+
+if { [readnow] } {
+ return -1
+}
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+ return -1
+}
+
+if { ![string eq [have_index $binfile] ""] } {
+ return -1
+}
+
+gdb_test_no_output "maint info symtabs"
diff --git a/gdb/testsuite/gdb.cp/main-cp.exp b/gdb/testsuite/gdb.cp/main-cp.exp
new file mode 100644
index 00000000000..86d626bdbaf
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/main-cp.exp
@@ -0,0 +1,33 @@
+# Copyright 2023 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/>.
+
+# Check that finding main to set the current language doesn't cause any symtab
+# to be expanded.
+
+standard_testfile main.cc
+
+if { [readnow] } {
+ return -1
+}
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+ return -1
+}
+
+if { ![string eq [have_index $binfile] ""] } {
+ return -1
+}
+
+gdb_test_no_output "maint info symtabs"
diff --git a/gdb/testsuite/gdb.cp/main.cc b/gdb/testsuite/gdb.cp/main.cc
new file mode 100644
index 00000000000..c6beff77dbe
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/main.cc
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2023 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/>. */
+
+int
+main (void)
+{
+ return 0;
+}
base-commit: ebceffa1196651683a7a6d31abb4b3b5adc6c168
--
2.35.3

View File

@ -0,0 +1,112 @@
From 19185006cfe0901da907da4f09fbc197aba976a2 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Fri, 11 Aug 2023 01:36:50 +0200
Subject: [PATCH 11/11] [gdb/symtab] Fix DW_TAG_inlined_subroutine entries in
the cooked index
We get incorrect qualified names in the cooked index for
DW_TAG_inlined_subroutine DIEs with abstract origin, due to the fact that the
DIE parent is used instead of the abstract origin.
Fix this by preferring the abstract origin parent, if available.
Tested on x86_64-linux.
PR symtab/30728
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30728
---
gdb/dwarf2/read.c | 67 ++++++++++++++++++++++-------------------------
1 file changed, 32 insertions(+), 35 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index e2d4fe8cde6..418acaabc60 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -18369,52 +18369,49 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu,
const gdb_byte *new_info_ptr = (new_reader->buffer
+ to_underlying (origin_offset));
- if (*parent_entry == nullptr)
+ gdb_assert (reader->cu->per_cu->is_debug_types
+ == new_reader->cu->per_cu->is_debug_types);
+ CORE_ADDR addr
+ = parent_map::form_addr (origin_offset, origin_is_dwz,
+ reader->cu->per_cu->is_debug_types);
+ if (new_reader->cu == reader->cu)
{
- gdb_assert (reader->cu->per_cu->is_debug_types
- == new_reader->cu->per_cu->is_debug_types);
- CORE_ADDR addr
- = parent_map::form_addr (origin_offset, origin_is_dwz,
- reader->cu->per_cu->is_debug_types);
- if (new_reader->cu == reader->cu)
+ /* Intra-CU case. */
+ if (new_info_ptr > watermark_ptr)
{
- /* Intra-CU case. */
- if (new_info_ptr > watermark_ptr)
- {
- /* Defer because origin is not read yet. */
- *maybe_defer = addr;
- }
- else
- {
- auto tmp = find_parent (addr);
- if (tmp == &parent_map::deferred)
- {
- /* Defer because origin is deferred. */
- *maybe_defer = addr;
- }
- else
- *parent_entry = tmp;
- }
+ /* Defer because origin is not read yet. */
+ *maybe_defer = addr;
}
else
{
- /* Inter-CU case. */
- if (parent_valid (addr))
+ auto tmp = find_parent (addr);
+ if (tmp == &parent_map::deferred)
{
- auto tmp = find_parent (addr);
- if (tmp == &parent_map::deferred)
- {
- /* Defer because origin is deferred. */
- *maybe_defer = addr;
- }
- else
- *parent_entry = tmp;
+ /* Defer because origin is deferred. */
+ *maybe_defer = addr;
}
else
+ *parent_entry = tmp;
+ }
+ }
+ else
+ {
+ /* Inter-CU case. */
+ if (parent_valid (addr))
+ {
+ auto tmp = find_parent (addr);
+ if (tmp == &parent_map::deferred)
{
- /* Defer because origin is in other shard. */
+ /* Defer because origin is deferred. */
*maybe_defer = addr;
}
+ else
+ *parent_entry = tmp;
+ }
+ else
+ {
+ /* Defer because origin is in other shard. */
+ *maybe_defer = addr;
}
}
--
2.35.3

View File

@ -0,0 +1,84 @@
From e5972def532f3ed248dfbd2f220f28dc367f4ca1 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Fri, 24 Mar 2023 15:45:56 +0100
Subject: [PATCH 07/12] [gdb/symtab] Fix line number of static const class
member
Since commit 6d263fe46e0 ("Avoid bad breakpoints with --gc-sections"), there
was a silent regression on openSUSE Leap 15.4 for test-case
gdb.cp/m-static.exp, from:
...
(gdb) info variable everywhere^M
All variables matching regular expression "everywhere":^M
^M
File /home/vries/tmp.local-remote-host-native/m-static.h:^M
8: const int gnu_obj_4::everywhere;^M
(gdb)
...
to:
...
(gdb) info variable everywhere^M
All variables matching regular expression "everywhere":^M
^M
File /data/vries/gdb/src/gdb/testsuite/gdb.cp/m-static.h:^M
8: const int gnu_obj_4::everywhere;^M
^M
File /data/vries/gdb/src/gdb/testsuite/gdb.cp/m-static1.cc:^M
8: const int gnu_obj_4::everywhere;^M
(gdb)
...
Another regression was found due to that commit, and it was fixed in commit
99d679e7b30 ("[gdb/symtab] Fix "file index out of range" complaint") by
limiting the scope of the fix in the original commit.
Fix this regression by yet further limiting the scope of that fix, making sure
that this bit in dwarf_decode_lines is executed again for m-static1.cc:
...
/* Make sure a symtab is created for every file, even files
which contain only variables (i.e. no code with associated
line numbers). */
...
Tested on x86_64-linux.
PR symtab/30265
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30265
---
gdb/dwarf2/read.c | 3 +--
gdb/testsuite/gdb.cp/m-static.exp | 4 +++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index f39eba7a008..04bc0e1cbbd 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9633,8 +9633,7 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
then there won't be any interesting code in the CU, but a check later on
(in lnp_state_machine::check_line_address) will fail to properly exclude
an entry that was removed via --gc-sections. */
- if (have_code)
- dwarf_decode_lines (cu->line_header, cu, lowpc, decode_mapping);
+ dwarf_decode_lines (cu->line_header, cu, lowpc, decode_mapping && have_code);
}
/* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
diff --git a/gdb/testsuite/gdb.cp/m-static.exp b/gdb/testsuite/gdb.cp/m-static.exp
index a67b4cd3736..049e88299da 100644
--- a/gdb/testsuite/gdb.cp/m-static.exp
+++ b/gdb/testsuite/gdb.cp/m-static.exp
@@ -183,8 +183,10 @@ gdb_test "print test4.somewhere" "\\$\[0-9\].* = 3.14\[0-9\]*" "static const flo
if { $non_dwarf } { setup_xfail *-*-* }
gdb_test "info variable everywhere" \
[multi_line \
+ {All variables matching regular expression "everywhere":} \
+ "" \
"File (.*/)?m-static\[.\]h:" \
- "$decimal:\tconst int gnu_obj_4::everywhere;.*"]
+ "$decimal:\tconst int gnu_obj_4::everywhere;"]
# Perhaps at some point test4 should also include a test for a static
# const int that was initialized in the header file. But I'm not sure
--
2.35.3

View File

@ -0,0 +1,66 @@
From 1362bc937bd54dbd22dd7b3c7ae9d8ab6ca7bbfc Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Wed, 6 Sep 2023 11:00:01 +0200
Subject: [PATCH 10/12] [gdb/symtab] Fix too many symbols in
gdbpy_lookup_static_symbols
When running test-case gdb.python/py-symbol.exp with target board
cc-with-dwz-m, we run into:
...
(gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M
4^M
(gdb) FAIL: gdb.python/py-symbol.exp: \
print (len (gdb.lookup_static_symbols ('rr')))
...
while with target board unix we have instead:
...
(gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M
2^M
(gdb) PASS: gdb.python/py-symbol.exp: \
print (len (gdb.lookup_static_symbols ('rr')))
...
The problem is that the loop in gdbpy_lookup_static_symbols loops over compunits
representing both CUs and PUs:
...
for (compunit_symtab *cust : objfile->compunits ())
...
When doing a lookup on a PU, the user link is followed until we end up at a CU,
and the lookup is done in that CU.
In other words, when doing a lookup in the loop for a PU we duplicate the
lookup for a CU that is already handled by the loop.
Fix this by skipping PUs in the loop in gdb.lookup_static_symbols.
Tested on x86_64-linux.
PR symtab/25261
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25261
---
gdb/python/py-symbol.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index b8777966c47..ed4250bc2c7 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -582,9 +582,12 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
{
for (compunit_symtab *cust : objfile->compunits ())
{
- const struct blockvector *bv;
+ /* Skip included compunits to prevent including compunits from
+ being searched twice. */
+ if (cust->user != nullptr)
+ continue;
- bv = cust->blockvector ();
+ const struct blockvector *bv = cust->blockvector ();
const struct block *block = bv->static_block ();
if (block != nullptr)
--
2.35.3

View File

@ -0,0 +1,37 @@
From 933f8ee225d4ccd3db9b81312dba76ae5a50b4ea Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Fri, 25 Aug 2023 09:30:54 +0200
Subject: [PATCH 03/11] [gdb/symtab] Handle nullptr parent in
parent_map::set_parent
Set_parent uses m_die_range_map.set_empty, which doesn't allow
parent_entry == nullptr.
So it may be necessary to guard calls to set_parent with
"if (parent_entry != nullptr)".
Fix this by handling the parent_entry == nullptr case in set_parent.
Tested on x86_64-linux.
---
gdb/dwarf2/cooked-index.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index 1c967bdbf86..f4abc7a974e 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -257,7 +257,9 @@ class parent_map
void set_parent (CORE_ADDR start, CORE_ADDR end,
const cooked_index_entry *parent_entry)
{
- m_parent_map.set_empty (start, end, (void *)parent_entry);
+ /* Calling set_empty with nullptr is currently not allowed. */
+ if (parent_entry != nullptr)
+ m_parent_map.set_empty (start, end, (void *)parent_entry);
}
private:
--
2.35.3

View File

@ -0,0 +1,59 @@
From c67e982325c5b2249b0e29d07a9dc1985614e898 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Wed, 6 Sep 2023 10:14:50 +0200
Subject: [PATCH 08/12] [gdb/symtab] Handle PU in iterate_over_some_symtabs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When running test-case gdb.base/setshow.exp with target board cc-with-dwz I
run into:
...
(gdb) info line 1^M
Line 1 of "setshow.c" is at address 0x400527 <main> but contains no code.^M
Line 1 of "setshow.c" is at address 0x400527 <main> but contains no code.^M
(gdb) FAIL: gdb.base/setshow.exp: test_setshow_annotate: annotation_level 1
...
while the expected output is:
...
Line 1 of "setshow.c" is at address 0x400527 <main> but contains no code.
<EFBFBD><EFBFBD>setshow.c:1:0:beg:0x400527
...
The second line of the expected output is missing due to the first line of the
expected output being repeated, so the problem is that the "Line 1" line is
printed twice.
This happens because the PU imported by the CU reuses the filetab of the CU,
and both the CU and PU are visited by iterate_over_some_symtabs.
Fix this by skipping PUs in iterate_over_some_symtabs.
Tested on x86_64-linux, target boards unix, cc-with-dwz and cc-with-dwz-m.
Approved-By: Tom Tromey <tom@tromey.com>
PR symtab/30797
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30797
---
gdb/symtab.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index a662d7d1869..fe7cc679b6b 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -550,6 +550,10 @@ iterate_over_some_symtabs (const char *name,
for (cust = first; cust != NULL && cust != after_last; cust = cust->next)
{
+ /* Skip included compunits. */
+ if (cust->user != nullptr)
+ continue;
+
for (symtab *s : cust->filetabs ())
{
if (compare_filenames_for_search (s->filename, name))
--
2.35.3

Some files were not shown because too many files have changed in this diff Show More