public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] [gdb] Fix segfault in for_each_block
@ 2023-11-07 13:19 Tom de Vries
  2023-11-07 13:19 ` [PATCH v2 1/2] [gdb] Fix segfault in for_each_block, part 1 Tom de Vries
  2023-11-07 13:19 ` [PATCH v2 2/2] [gdb] Fix segfault in for_each_block, part 2 Tom de Vries
  0 siblings, 2 replies; 8+ messages in thread
From: Tom de Vries @ 2023-11-07 13:19 UTC (permalink / raw)
  To: gdb-patches

This patch series fixes PR gdb/30547, a segfault when running test-case
gdb.base/vfork-follow-parent.exp on powerpc64 (likewise on s390x).

There are two patches, each of them by themselves sufficient to no longer
trigger the segfault.

The root cause of the problem is that linux_is_uclinux, and consequently
gdbarch_has_shared_address_space returns an incorrect value.

The first patch makes gdb more robust against gdbarch_has_shared_address_space
returning incorrect values, by eliminating a call to it.

The second patch addresses the root cause.

Tested on top of trunk on x86_64-linux and ppc64le-linux.
Tested on top of gdb-14-branch on ppc64-linux.

[ I used gdb-14-branch for ppc64-linux, because I can't build trunk anymore
with system gcc 4.8.5 (CentOS-7), due to the recent c++17 requirement (and
just before that, some gcc bug in atomic support), and that's all I have
readily available on that machine. ]

There is still scope to fix things further.

When I started to investigate, I noticed that I only ran into the segfault on
ppc64 and s390x, two big-endian architectures, so I sort of expected to find an
endian-related problem.

Instead, the problem was ppc_linux_target_wordsize returning 4 instead of 8,
which causes gdb to interpret the 8-byte entry auxv vector using 4-byte
words, causing an incorrect linux_is_uclinux == true.

The same problem happens on ppc64le (ppc_linux_target_wordsize returns 4),
it's just that the incorrect word size doesn't change the outcome of:
- target_auxv_search (AT_NULL, &dummy) == 1, and
- target_auxv_search (AT_PAGESZ, &dummy) == 1
so linux_is_uclinux returns false, as it should.

This suggest a too forgiving parsing of the auxv vector, which should be made
more strict.

Finally, it should be fixed that ppc_linux_target_wordsize returns 4 in a
process with wordsize == 8.

I added an assert that PTRACE_PEEKUSER doesn't fail (errno != 0) and ran into
it in test-case gdb.base/access-mem-running.exp, during trying to "set a
breakpoint while the process is running".  It's clear that it's quite common
for this to happen, and it's surprising that this doesn't cause more problems.

I'll eventually file PRs for these two issues, for now my interest is to
backport at least one, possibly both patches from this series to fix this PR
on the gdb 14 release branch (and the 13.2 based distro packages I maintain).

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30547

Tom de Vries (2):
  [gdb] Fix segfault in for_each_block, part 1
  [gdb] Fix segfault in for_each_block, part 2

 gdb/infrun.c    | 12 +++++++++++-
 gdb/progspace.c | 37 +++++++++++++++++++++++++++----------
 gdb/progspace.h | 11 ++++++++++-
 3 files changed, 48 insertions(+), 12 deletions(-)

--
2.35.3

Tom de Vries (2):
  [gdb] Fix segfault in for_each_block, part 1
  [gdb] Fix segfault in for_each_block, part 2

 gdb/breakpoint.c             | 29 ++++++++++++++++-------------
 gdb/inferior.c               |  8 ++------
 gdb/inferior.h               |  2 +-
 gdb/infrun.c                 | 28 +++++++++++++++++++---------
 gdb/linux-nat.c              |  2 +-
 gdb/process-stratum-target.c |  2 +-
 gdb/progspace.c              | 29 +++++++++++++++++------------
 gdb/progspace.h              |  5 +++--
 gdb/record-btrace.c          |  2 +-
 gdb/regcache.c               |  2 +-
 gdb/target-dcache.c          | 11 ++++++-----
 11 files changed, 68 insertions(+), 52 deletions(-)


base-commit: d1bd9787f9ad8c49fb463d8d53411aeb5f9c179b
-- 
2.35.3


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-11-09 16:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-07 13:19 [PATCH v2 0/2] [gdb] Fix segfault in for_each_block Tom de Vries
2023-11-07 13:19 ` [PATCH v2 1/2] [gdb] Fix segfault in for_each_block, part 1 Tom de Vries
2023-11-07 15:00   ` Simon Marchi
2023-11-09 15:07     ` Tom de Vries
2023-11-09 16:26       ` Simon Marchi
2023-11-07 13:19 ` [PATCH v2 2/2] [gdb] Fix segfault in for_each_block, part 2 Tom de Vries
2023-11-07 15:26   ` Simon Marchi
2023-11-09 15:10     ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).