public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] [gdb] Fix segfault in for_each_block
@ 2023-11-09 15:00 Tom de Vries
  2023-11-09 15:00 ` [PATCH v3 1/3] [gdb] Fix segfault in for_each_block, part 1 Tom de Vries
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Tom de Vries @ 2023-11-09 15:00 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 three patches, the first and third by themselves sufficient to no
longer trigger the segfault.

The second is a slight refactoring which is user visible, so it comes as
a separate patch.

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 third 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've file PRs for these two issues:
- [gdb] Make auxv parsing more strict
  https://sourceware.org/bugzilla/show_bug.cgi?id=31040
- [gdb/tdep] ppc_linux_target_wordsize silently returns wrong result
  https://sourceware.org/bugzilla/show_bug.cgi?id=31038

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).

Submission history:

v3:
- fix std::shared_ptr usage issues after review by Simon
- add patch "[gdb] Eliminate local var pspace in inferior.c"
  following up on comments by Simon
- update third patch according to comments by Simon

v2:
- use std::shared_ptr as suggested by Andrew and Simon

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

Tom de Vries (3):
  [gdb] Fix segfault in for_each_block, part 1
  [gdb] Eliminate local var pspace in inferior.c
  [gdb] Fix segfault in for_each_block, part 2

 gdb/breakpoint.c                              | 29 ++++++++-------
 gdb/inferior.c                                | 24 ++++--------
 gdb/inferior.h                                |  2 +-
 gdb/infrun.c                                  | 37 +++++++++++--------
 gdb/linux-nat.c                               |  2 +-
 gdb/nat/ppc-linux.c                           |  2 +
 gdb/ppc-linux-nat.c                           |  2 +
 gdb/process-stratum-target.c                  |  2 +-
 gdb/progspace.c                               | 21 ++++-------
 gdb/progspace.h                               |  6 +--
 gdb/record-btrace.c                           |  2 +-
 gdb/regcache.c                                |  2 +-
 gdb/s390-linux-nat.c                          |  5 ++-
 gdb/scoped-mock-context.h                     |  2 +-
 gdb/target-dcache.c                           | 11 +++---
 .../gdb.python/py-progspace-events.exp        |  4 +-
 16 files changed, 78 insertions(+), 75 deletions(-)


base-commit: e7d74879870833fb0c42282da940e60fee13948e
-- 
2.35.3


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

end of thread, other threads:[~2023-11-10  8:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-09 15:00 [PATCH v3 0/3] [gdb] Fix segfault in for_each_block Tom de Vries
2023-11-09 15:00 ` [PATCH v3 1/3] [gdb] Fix segfault in for_each_block, part 1 Tom de Vries
2023-11-09 18:19   ` Simon Marchi
2023-11-10  8:14     ` Tom de Vries
2023-11-09 15:00 ` [PATCH v3 2/3] [gdb] Eliminate local var pspace in inferior.c Tom de Vries
2023-11-09 16:31   ` Simon Marchi
2023-11-10  8:15     ` Tom de Vries
2023-11-09 15:00 ` [PATCH v3 3/3] [gdb] Fix segfault in for_each_block, part 2 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).