Accepting request 733030 from home:tomdevries:branches:devel:gcc-gdb-fedora-sync

- Sync with f30, merging 1e222a3..8bf40c6.
  * gdb-rhbz1708192-parse_macro_definition-crash.patch
  * gdb-rhbz1704406-disable-style-log-output-1of3.patch
  * gdb-rhbz1704406-disable-style-log-output-2of3.patch
  * gdb-rhbz1704406-disable-style-log-output-3of3.patch
  * gdb-rhbz1723564-gdb-crash-PYTHONMALLOC-debug.patch
  * gdb-rhbz1553086-binutils-warning-loadable-section-outside-elf.patch

OBS-URL: https://build.opensuse.org/request/show/733030
OBS-URL: https://build.opensuse.org/package/show/devel:gcc/gdb?expand=0&rev=227
This commit is contained in:
Michael Matz 2019-09-26 14:07:43 +00:00 committed by Git OBS Bridge
parent 7942f114e3
commit 0753212449
8 changed files with 694 additions and 0 deletions

View File

@ -0,0 +1,100 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Nick Clifton <nickc@redhat.com>
Date: Tue, 2 Jul 2019 15:58:29 +0100
Subject: gdb-rhbz1553086-binutils-warning-loadable-section-outside-elf.patch
;; Fix 'gdb: warning: Loadable section ".note.gnu.property" outside of
;; ELF segments' (Nick Clifton, RH BZ 1553086).
;; This is a binutils patch.
Stop the BFD library from issuing a warning message when processing allocated sections in debuginfo files that lie outside of any loadable segment.
PR 24717
* elf.c (is_debuginfo_file): New function.
(assign_file_positions_for_non_load_sections): Do not warn about
allocated sections outside of loadable segments if they are found
in a debuginfo file.
* elf-bfd.h (is_debuginfo_file): Prototype.
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,12 @@
+2019-07-02 Nick Clifton <nickc@redhat.com>
+
+ PR 24717
+ * elf.c (is_debuginfo_file): New function.
+ (assign_file_positions_for_non_load_sections): Do not warn about
+ allocated sections outside of loadable segments if they are found
+ in a debuginfo file.
+ * elf-bfd.h (is_debuginfo_file): Prototype.
+
2019-05-02 Nick Clifton <nickc@redhat.com>
PR 24493
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2751,6 +2751,8 @@ extern bfd_vma elf64_r_sym (bfd_vma);
extern bfd_vma elf32_r_info (bfd_vma, bfd_vma);
extern bfd_vma elf32_r_sym (bfd_vma);
+extern bfd_boolean is_debuginfo_file (bfd *);
+
/* Large common section. */
extern asection _bfd_elf_large_com_section;
diff --git a/bfd/elf.c b/bfd/elf.c
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -5800,6 +5800,35 @@ assign_file_positions_for_load_sections (bfd *abfd,
return TRUE;
}
+/* Determine if a bfd is a debuginfo file. Unfortunately there
+ is no defined method for detecting such files, so we have to
+ use heuristics instead. */
+
+bfd_boolean
+is_debuginfo_file (bfd *abfd)
+{
+ if (abfd == NULL || bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+ return FALSE;
+
+ Elf_Internal_Shdr **start_headers = elf_elfsections (abfd);
+ Elf_Internal_Shdr **end_headers = start_headers + elf_numsections (abfd);
+ Elf_Internal_Shdr **headerp;
+
+ for (headerp = start_headers; headerp < end_headers; headerp ++)
+ {
+ Elf_Internal_Shdr *header = * headerp;
+
+ /* Debuginfo files do not have any allocated SHT_PROGBITS sections.
+ The only allocated sections are SHT_NOBITS or SHT_NOTES. */
+ if ((header->sh_flags & SHF_ALLOC) == SHF_ALLOC
+ && header->sh_type != SHT_NOBITS
+ && header->sh_type != SHT_NOTE)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/* Assign file positions for the other sections. */
static bfd_boolean
@@ -5833,7 +5862,13 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
BFD_ASSERT (hdr->sh_offset == hdr->bfd_section->filepos);
else if ((hdr->sh_flags & SHF_ALLOC) != 0)
{
- if (hdr->sh_size != 0)
+ if (hdr->sh_size != 0
+ /* PR 24717 - debuginfo files are known to be not strictly
+ compliant with the ELF standard. In particular they often
+ have .note.gnu.property sections that are outside of any
+ loadable segment. This is not a problem for such files,
+ so do not warn about them. */
+ && ! is_debuginfo_file (abfd))
_bfd_error_handler
/* xgettext:c-format */
(_("%pB: warning: allocated section `%s' not in segment"),

View File

@ -0,0 +1,101 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@adacore.com>
Date: Tue, 14 May 2019 08:04:22 -0600
Subject: gdb-rhbz1704406-disable-style-log-output-1of3.patch
;; Fix 'Color control codes should not appear in logging output'
;; Tom Tromey, RH BZ 1704406
Add "style" proc to the test suite
This adds a "style" helper proc to the test suite, and updates
existing style tests to use it. Thanks to Sergio for the idea.
Tested on x86-64 Fedora 29.
gdb/testsuite/ChangeLog
2019-05-22 Tom Tromey <tromey@adacore.com>
* gdb.base/info-shared.exp (check_info_shared): Use "style".
* gdb.base/style.exp: Use "style".
* lib/gdb-utils.exp (style): New proc.
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2019-05-22 Tom Tromey <tromey@adacore.com>
+
+ * gdb.base/info-shared.exp (check_info_shared): Use "style".
+ * gdb.base/style.exp: Use "style".
+ * lib/gdb-utils.exp (style): New proc.
+
2019-04-30 Tom Tromey <tromey@adacore.com>
PR c++/24470:
diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -41,10 +41,10 @@ save_vars { env(TERM) } {
gdb_test_no_output "set style enabled on"
- set main_expr "\033\\\[33mmain\033\\\[m"
- set base_file_expr "\033\\\[32m.*style\\.c\033\\\[m"
+ set main_expr [style main function]
+ set base_file_expr [style ".*style\\.c" file]
set file_expr "$base_file_expr:\[0-9\]"
- set arg_expr "\033\\\[36marg.\033\\\[m"
+ set arg_expr [style "arg." variable]
gdb_test "frame" \
"$main_expr.*$arg_expr.*$arg_expr.*$file_expr.*"
@@ -58,7 +58,7 @@ save_vars { env(TERM) } {
gdb_test "break main" "file $base_file_expr.*"
- gdb_test "print &main" " = .* \033\\\[34m$hex\033\\\[m <$main_expr>"
+ gdb_test "print &main" " = .* [style $hex address] <$main_expr>"
# Regression test for a bug where line-wrapping would occur at the
# wrong spot with styling. There were different bugs at different
@@ -86,11 +86,12 @@ save_vars { env(TERM) } {
gdb_exit
gdb_spawn
- gdb_test "" "\033\\\[35;1mGNU gdb.*\033\\\[m.*" \
+ set vers [style "GNU gdb.*" "35;1"]
+ gdb_test "" "${vers}.*" \
"version is styled"
set quoted [string_to_regexp $binfile]
gdb_test "file $binfile" \
- "Reading symbols from \033\\\[32m${quoted}\033\\\[m..." \
+ "Reading symbols from [style $quoted file]..." \
"filename is styled when loading symbol file"
}
diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -37,3 +37,21 @@ proc string_to_regexp {str} {
regsub -all {[]*+.|(){}^$\[\\]} $str {\\&} result
return $result
}
+
+# Wrap STR in an ANSI terminal escape sequences -- one to set the
+# style to STYLE, and one to reset the style to the default. The
+# return value is suitable for use as a regular expression.
+
+# STYLE can either be the payload part of an ANSI terminal sequence,
+# or a shorthand for one of the gdb standard styles: "file",
+# "function", "variable", or "address".
+
+proc style {str style} {
+ switch -exact -- $style {
+ file { set style 32 }
+ function { set style 33 }
+ variable { set style 36 }
+ address { set style 34 }
+ }
+ return "\033\\\[${style}m${str}\033\\\[m"
+}

View File

@ -0,0 +1,223 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@adacore.com>
Date: Tue, 30 Apr 2019 11:17:15 -0600
Subject: gdb-rhbz1704406-disable-style-log-output-2of3.patch
;; Fix 'Color control codes should not appear in logging output'
;; Tom Tromey, RH BZ 1704406
Do not emit style escape sequences to log file
PR gdb/24502 requests that the "set logging" log file not contain
style escape sequences emitted by gdb.
This seemed like a reasonable request to me, so this patch implements
filtering for the log file.
This also updates a comment in ui-style.h that I noticed while writing
the patch.
Tested on x86-64 Fedora 29.
gdb/ChangeLog
2019-06-14 Tom Tromey <tromey@adacore.com>
PR gdb/24502:
* ui-style.h (skip_ansi_escape): Update comment.
* ui-file.h (class no_terminal_escape_file): New class.
* ui-file.c (no_terminal_escape_file::write)
(no_terminal_escape_file::puts): New methods.
* cli/cli-logging.c (handle_redirections): Use
no_terminal_escape_file.
gdb/testsuite/ChangeLog
2019-06-14 Tom Tromey <tromey@adacore.com>
PR gdb/24502:
* gdb.base/style-logging.exp: New file.
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2019-06-14 Tom Tromey <tromey@adacore.com>
+
+ PR gdb/24502:
+ * ui-style.h (skip_ansi_escape): Update comment.
+ * ui-file.h (class no_terminal_escape_file): New class.
+ * ui-file.c (no_terminal_escape_file::write)
+ (no_terminal_escape_file::puts): New methods.
+ * cli/cli-logging.c (handle_redirections): Use
+ no_terminal_escape_file.
+
2019-05-15 Sergio Durigan Junior <sergiodj@redhat.com>
Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192
diff --git a/gdb/cli/cli-logging.c b/gdb/cli/cli-logging.c
--- a/gdb/cli/cli-logging.c
+++ b/gdb/cli/cli-logging.c
@@ -117,7 +117,7 @@ handle_redirections (int from_tty)
return;
}
- stdio_file_up log (new stdio_file ());
+ stdio_file_up log (new no_terminal_escape_file ());
if (!log->open (logging_filename, logging_overwrite ? "w" : "a"))
perror_with_name (_("set logging"));
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-14 Tom Tromey <tromey@adacore.com>
+
+ PR gdb/24502:
+ * gdb.base/style-logging.exp: New file.
+
2019-05-22 Tom Tromey <tromey@adacore.com>
* gdb.base/info-shared.exp (check_info_shared): Use "style".
diff --git a/gdb/testsuite/gdb.base/style-logging.exp b/gdb/testsuite/gdb.base/style-logging.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.base/style-logging.exp
@@ -0,0 +1,64 @@
+# Copyright 2019 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 that logging does not style.
+
+if {[is_remote host]} {
+ untested "does not work on remote host"
+ return 0
+}
+
+standard_testfile style.c
+
+save_vars { env(TERM) } {
+ # We need an ANSI-capable terminal to get the output.
+ setenv TERM ansi
+
+ if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+ return -1
+ }
+
+ if {![runto_main]} {
+ fail "style tests failed"
+ return
+ }
+
+ gdb_test_no_output "set style enabled on"
+
+ set log_name [standard_output_file log.txt]
+ gdb_test_no_output "set logging file $log_name"
+ gdb_test_no_output "set logging overwrite on"
+ gdb_test "set logging on" "Copying output to .*"
+
+ set main_expr [style main function]
+ set base_file_expr [style ".*style\\.c" file]
+ set file_expr "$base_file_expr:\[0-9\]"
+ set arg_expr [style "arg." variable]
+ gdb_test "frame" \
+ "$main_expr.*$arg_expr.*$arg_expr.*$file_expr.*"
+
+ gdb_test "set logging off" "Done logging to .*"
+
+ set fd [open $log_name]
+ set data [read -nonewline $fd]
+ close $fd
+
+ set testname "log is escape-free"
+ if {[regexp "\033" $data]} {
+ fail $testname
+ } else {
+ pass $testname
+ }
+}
diff --git a/gdb/ui-file.c b/gdb/ui-file.c
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -332,3 +332,33 @@ tee_file::isatty ()
{
return m_one->isatty ();
}
+
+void
+no_terminal_escape_file::write (const char *buf, long length_buf)
+{
+ std::string copy (buf, length_buf);
+ this->puts (copy.c_str ());
+}
+
+/* See ui-file.h. */
+
+void
+no_terminal_escape_file::puts (const char *buf)
+{
+ while (*buf != '\0')
+ {
+ const char *esc = strchr (buf, '\033');
+ if (esc == nullptr)
+ break;
+
+ int n_read = 0;
+ if (!skip_ansi_escape (esc, &n_read))
+ ++esc;
+
+ this->stdio_file::write (buf, esc - buf);
+ buf = esc + n_read;
+ }
+
+ if (*buf != '\0')
+ this->stdio_file::write (buf, strlen (buf));
+}
diff --git a/gdb/ui-file.h b/gdb/ui-file.h
--- a/gdb/ui-file.h
+++ b/gdb/ui-file.h
@@ -264,4 +264,20 @@ private:
bool m_close_one, m_close_two;
};
+/* A ui_file implementation that filters out terminal escape
+ sequences. */
+
+class no_terminal_escape_file : public stdio_file
+{
+public:
+ no_terminal_escape_file ()
+ {
+ }
+
+ /* Like the stdio_file methods, but these filter out terminal escape
+ sequences. */
+ void write (const char *buf, long length_buf) override;
+ void puts (const char *linebuffer) override;
+};
+
#endif
diff --git a/gdb/ui-style.h b/gdb/ui-style.h
--- a/gdb/ui-style.h
+++ b/gdb/ui-style.h
@@ -233,8 +233,8 @@ private:
/* Skip an ANSI escape sequence in BUF. BUF must begin with an ESC
character. Return true if an escape sequence was successfully
- skipped; false otherwise. In either case, N_READ is updated to
- reflect the number of chars read from BUF. */
+ skipped; false otherwise. If an escape sequence was skipped,
+ N_READ is updated to reflect the number of chars read from BUF. */
extern bool skip_ansi_escape (const char *buf, int *n_read);

View File

@ -0,0 +1,41 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Andrew Burgess <andrew.burgess@embecosm.com>
Date: Fri, 14 Jun 2019 23:31:10 +0100
Subject: gdb-rhbz1704406-disable-style-log-output-3of3.patch
;; Fix 'Color control codes should not appear in logging output'
;; Tom Tromey, RH BZ 1704406
gdb: Remove file path from test name
Having paths in test names makes comparing sum files difficult, rename
a test to avoid paths in test names.
gdb/testsuite/ChangeLog:
* gdb.base/style-logging.exp: Remove path from test name.
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2019-06-15 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * gdb.base/style-logging.exp: Remove path from test name.
+
2019-06-14 Tom Tromey <tromey@adacore.com>
PR gdb/24502:
diff --git a/gdb/testsuite/gdb.base/style-logging.exp b/gdb/testsuite/gdb.base/style-logging.exp
--- a/gdb/testsuite/gdb.base/style-logging.exp
+++ b/gdb/testsuite/gdb.base/style-logging.exp
@@ -38,7 +38,8 @@ save_vars { env(TERM) } {
gdb_test_no_output "set style enabled on"
set log_name [standard_output_file log.txt]
- gdb_test_no_output "set logging file $log_name"
+ gdb_test_no_output "set logging file $log_name" \
+ "set logging filename"
gdb_test_no_output "set logging overwrite on"
gdb_test "set logging on" "Copying output to .*"

View File

@ -0,0 +1,82 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Sergio Durigan Junior <sergiodj@redhat.com>
Date: Fri, 10 May 2019 16:57:26 -0400
Subject: gdb-rhbz1708192-parse_macro_definition-crash.patch
;; "Fix" segfault that happens on parse_macro_definition because
;; debugedit corrupts the .debug_macro section.
;; Sergio Durigan Junior, RH BZ 1708192.
Don't crash if dwarf_decode_macro_bytes's 'body' is NULL
Hi,
Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192
https://bugzilla.redhat.com/show_bug.cgi?id=1708786
During the Fedora RPM build process, gdb-add-index is invoked to
extract the DWARF index from the binary, and GDB will segfault because
dwarf2read.c:parse_definition_macro's 'body' variable is NULL.
The underlying problem is that Fedora's rpm-build's "debugedit"
program will silently corrupt .debug_macro strings when a binary is
compiled with -g3. This is being taken care of by Mark Wielaard,
here:
https://bugzilla.redhat.com/show_bug.cgi?id=1708786
However, I still feel it's important to make GDB more resilient
against invalid DWARF input, so I'm proposing this rather simple patch
to catch the situation when "body == NULL" (i.e., it's probably been
corrupted) and issue a complaint. This is not a real fix to the
problem, of course, but at least GDB is able to finish without
segfaulting.
OK for master?
gdb/ChangeLog:
2019-05-15 Sergio Durigan Junior <sergiodj@redhat.com>
Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192
* dwarf2read.c (dwarf_decode_macro_bytes): Check whether 'body' is
NULL, and complain if that's the case.
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2019-05-15 Sergio Durigan Junior <sergiodj@redhat.com>
+
+ Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192
+ * dwarf2read.c (parse_macro_definition): Check whether 'body' is
+ NULL, and complain/return if that's the case.
+
2019-05-11 Joel Brobecker <brobecker@adacore.com>
* version.in: Set GDB version number to 8.3.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -24627,7 +24627,21 @@ dwarf_decode_macro_bytes (struct dwarf2_cu *cu,
is_define ? _("definition") : _("undefinition"),
line == 0 ? _("zero") : _("non-zero"), line, body);
- if (is_define)
+ if (body == NULL)
+ {
+ /* Fedora's rpm-build's "debugedit" binary
+ corrupted .debug_macro sections.
+
+ For more info, see
+ https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
+ complaint (_("debug info gives %s invalid macro %s "
+ "without body (corrupted?) at line %d "
+ "on file %s"),
+ at_commandline ? _("command-line") : _("in-file"),
+ is_define ? _("definition") : _("undefinition"),
+ line, current_file->filename);
+ }
+ else if (is_define)
parse_macro_definition (current_file, line, body);
else
{

View File

@ -0,0 +1,124 @@
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Sergio Durigan Junior <sergiodj@redhat.com>
Date: Thu, 27 Jun 2019 13:14:26 -0400
Subject: gdb-rhbz1723564-gdb-crash-PYTHONMALLOC-debug.patch
;; Fix 'gdb crash when using PYTHONMALLOC=debug on Python'
;; RHBZ 1723564, Sergio Durigan Junior.
Fix crash when using PYTHONMALLOC=debug (PR python/24742)
This bug was originally reported against Fedora GDB:
https://bugzilla.redhat.com/show_bug.cgi?id=1723564
The problem is that GDB will crash in the following scenario:
- PYTHONMALLOC=debug or PYTHONDEVMODE=1 is set.
- The Python debuginfo is installed.
- GDB is used to debug Python.
The crash looks like this:
$ PYTHONMALLOC=debug gdb -args python3 -c pass
GNU gdb (GDB) Fedora 8.3-3.fc30
Reading symbols from python3...
Reading symbols from /usr/lib/debug/usr/bin/python3.7m-3.7.3-3.fc30.x86_64.debug...
(gdb) run
Starting program: /usr/bin/python3 -c pass
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.29-9.fc30.x86_64
Debug memory block at address p=0x5603977bf330: API ''
8098648152243306496 bytes originally requested
The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfb):
at p-7: 0x03 *** OUCH
at p-6: 0x00 *** OUCH
at p-5: 0x00 *** OUCH
at p-4: 0x00 *** OUCH
at p-3: 0x00 *** OUCH
at p-2: 0x00 *** OUCH
at p-1: 0x00 *** OUCH
Because memory is corrupted at the start, the count of bytes requested
may be bogus, and checking the trailing pad bytes may segfault.
The 8 pad bytes at tail=0x706483999ad1f330 are Segmentation fault (core dumped)
It's hard to determine what happens, but after doing some
investigation and talking to Victor Stinner I found that GDB should
not use the Python memory allocation functions before the Python
interpreter is initialized (which makes sense). However, we do just
that on python/python.c:do_start_initialization:
...
progsize = strlen (progname.get ());
progname_copy = (wchar_t *) PyMem_Malloc ((progsize + 1) * sizeof (wchar_t));
...
/* Note that Py_SetProgramName expects the string it is passed to
remain alive for the duration of the program's execution, so
it is not freed after this call. */
Py_SetProgramName (progname_copy);
...
Py_Initialize ();
PyEval_InitThreads ();
Upon reading the Python 3 C API documentation, I
found (https://docs.python.org/3.5/c-api/memory.html):
To avoid memory corruption, extension writers should never try to
operate on Python objects with the functions exported by the C
library: malloc(), calloc(), realloc() and free(). This will result in
mixed calls between the C allocator and the Python memory manager with
fatal consequences, because they implement different algorithms and
operate on different heaps. However, one may safely allocate and
release memory blocks with the C library allocator for individual
purposes[...]
And Py_SetProgramName seems like a very simple call that doesn't need
a Python-allocated memory to work on. So I'm proposing this patch,
which simply replaces PyMem_Malloc by xmalloc.
Testing this is more complicated. First, the crash is completely
non-deterministic; I was able to reproduce it 10 times in a row, and
then I wasn't able to reproduce it anymore. I found that if you
completely remove your build directory and rebuild GDB from scratch,
you can reproduce it again confidently. And with my patch, I
confirmed that the bug doesn't manifest even in this situation.
No regressions found.
OK to apply?
gdb/ChangeLog:
2019-06-28 Sergio Durigan Junior <sergiodj@redhat.com>
PR python/24742
https://bugzilla.redhat.com/show_bug.cgi?id=1723564
* python/python.c (do_start_initialization): Use 'xmalloc'
instead of 'PyMem_Malloc'.
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2019-06-28 Sergio Durigan Junior <sergiodj@redhat.com>
+
+ PR python/24742
+ https://bugzilla.redhat.com/show_bug.cgi?id=1723564
+ * python/python.c (do_start_initialization): Use 'xmalloc'
+ instead of 'PyMem_Malloc'.
+
2019-06-14 Tom Tromey <tromey@adacore.com>
PR gdb/24502:
diff --git a/gdb/python/python.c b/gdb/python/python.c
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1720,7 +1720,7 @@ do_start_initialization ()
std::string oldloc = setlocale (LC_ALL, NULL);
setlocale (LC_ALL, "");
progsize = strlen (progname.get ());
- progname_copy = (wchar_t *) PyMem_Malloc ((progsize + 1) * sizeof (wchar_t));
+ progname_copy = (wchar_t *) xmalloc ((progsize + 1) * sizeof (wchar_t));
if (!progname_copy)
{
fprintf (stderr, "out of memory\n");

View File

@ -1,3 +1,14 @@
-------------------------------------------------------------------
Tue Sep 24 08:31:04 UTC 2019 - Tom de Vries <tdevries@suse.com>
- Sync with f30, merging 1e222a3..8bf40c6.
* gdb-rhbz1708192-parse_macro_definition-crash.patch
* gdb-rhbz1704406-disable-style-log-output-1of3.patch
* gdb-rhbz1704406-disable-style-log-output-2of3.patch
* gdb-rhbz1704406-disable-style-log-output-3of3.patch
* gdb-rhbz1723564-gdb-crash-PYTHONMALLOC-debug.patch
* gdb-rhbz1553086-binutils-warning-loadable-section-outside-elf.patch
-------------------------------------------------------------------
Sun Sep 22 05:54:09 UTC 2019 - Tom de Vries <tdevries@suse.com>

View File

@ -211,6 +211,12 @@ Patch112: gdb-vla-intel-fix-print-char-array.patch
Patch113: gdb-rhbz1553104-s390x-arch12-test.patch
Patch114: gdb-rhbz795424-bitpos-arrayview.patch
Patch115: gdb-rhbz1371380-gcore-elf-headers.patch
Patch116: gdb-rhbz1708192-parse_macro_definition-crash.patch
Patch117: gdb-rhbz1704406-disable-style-log-output-1of3.patch
Patch118: gdb-rhbz1704406-disable-style-log-output-2of3.patch
Patch119: gdb-rhbz1704406-disable-style-log-output-3of3.patch
Patch120: gdb-rhbz1723564-gdb-crash-PYTHONMALLOC-debug.patch
Patch121: gdb-rhbz1553086-binutils-warning-loadable-section-outside-elf.patch
#Fedora Packages end
#Fedora patches fixup
@ -566,6 +572,12 @@ find -name "*.info*"|xargs rm -f
%patch113 -p1
%patch114 -p1
%patch115 -p1
%patch116 -p1
%patch117 -p1
%patch118 -p1
%patch119 -p1
%patch120 -p1
%patch121 -p1
#Fedora patching end
%patch500 -p1