diff options
-rw-r--r-- | bfd/version.h | 2 | ||||
-rw-r--r-- | gdb/corelow.c | 6 | ||||
-rw-r--r-- | gdb/doc/python.texi | 18 | ||||
-rw-r--r-- | gdb/ppc-sysv-tdep.c | 27 | ||||
-rw-r--r-- | gdb/python/python.c | 20 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/return-small-char-array.exp | 18 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/return-small-char-array/value.adb | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/corefile-exec-mismatch.c | 36 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/corefile-exec-mismatch.exp | 188 | ||||
-rw-r--r-- | libctf/testsuite/lib/ctf-lib.exp | 2 |
10 files changed, 276 insertions, 43 deletions
diff --git a/bfd/version.h b/bfd/version.h index 95d17a1..bb90d07 100644 --- a/bfd/version.h +++ b/bfd/version.h @@ -16,7 +16,7 @@ In releases, the date is not included in either version strings or sonames. */ -#define BFD_VERSION_DATE 20251017 +#define BFD_VERSION_DATE 20251019 #define BFD_VERSION @bfd_version@ #define BFD_VERSION_STRING @bfd_version_package@ @bfd_version_string@ #define REPORT_BUGS_TO @report_bugs_to@ diff --git a/gdb/corelow.c b/gdb/corelow.c index 8f7a07b..65a672b 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -1055,10 +1055,12 @@ core_target_open (const char *arg, int from_tty) /* Own the target until it is successfully pushed. */ target_ops_up target_holder (target); - validate_files (); - current_inferior ()->push_target (std::move (target_holder)); + /* Validate files after pushing the core_target, this allows the + validate_files function to see the newly loaded core file. */ + validate_files (); + switch_to_no_thread (); /* Need to flush the register cache (and the frame cache) from a diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index ed11317..9df2c58 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -76,7 +76,7 @@ If given an argument, the @code{python} command will evaluate the argument as a Python command. For example: @smallexample -(@value{GDBP}) python print 23 +(@value{GDBP}) python print(23) 23 @end smallexample @@ -88,7 +88,7 @@ containing @code{end}. For example: @smallexample (@value{GDBP}) python ->print 23 +>print(23) >end 23 @end smallexample @@ -756,7 +756,7 @@ depends on @code{set python print-stack} (@pxref{Python Commands}). Example: @smallexample -(@value{GDBP}) python print foo +(@value{GDBP}) python print(foo) Traceback (most recent call last): File "<string>", line 1, in <module> NameError: name 'foo' is not defined @@ -1945,7 +1945,7 @@ settings. During a @code{print} or other operation, the values will reflect any flags that are temporarily in effect. @smallexample -(gdb) python print (gdb.print_options ()['max_elements']) +(gdb) python print(gdb.print_options ()['max_elements']) 200 @end smallexample @end defun @@ -4652,7 +4652,7 @@ Arguments are separated by spaces and may be quoted. Example: @smallexample -print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"") +print(gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")) ['1', '2 "3', '4 "5', "6 '7"] @end smallexample @@ -5981,7 +5981,7 @@ Two @code{gdb.Frame} objects can be compared for equality with the @code{==} operator, like: @smallexample -(@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame () +(@value{GDBP}) python print(gdb.newest_frame() == gdb.selected_frame ()) True @end smallexample @@ -9129,7 +9129,7 @@ Then in gdb: (gdb) start (gdb) python import gdb.types (gdb) python foo_ref = gdb.parse_and_eval("foo_ref") -(gdb) python print gdb.types.get_basic_type(foo_ref.type) +(gdb) python print(gdb.types.get_basic_type(foo_ref.type)) int @end smallexample @@ -9162,9 +9162,9 @@ Then in @value{GDBN}: @smallexample (@value{GDBP}) python import gdb.types (@value{GDBP}) python struct_a = gdb.lookup_type("struct A") -(@value{GDBP}) python print struct_a.keys () +(@value{GDBP}) python print(struct_a.keys ()) @{['a', '']@} -(@value{GDBP}) python print [k for k,v in gdb.types.deep_items(struct_a)] +(@value{GDBP}) python print([k for k,v in gdb.types.deep_items(struct_a)]) @{['a', 'b0', 'b1']@} @end smallexample diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c index f872f73..cc300cd 100644 --- a/gdb/ppc-sysv-tdep.c +++ b/gdb/ppc-sysv-tdep.c @@ -2059,26 +2059,13 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function, return RETURN_VALUE_REGISTER_CONVENTION; } - /* Small character arrays are returned, right justified, in r3. */ - if (tdep->elf_abi == POWERPC_ELF_V1 - && valtype->code () == TYPE_CODE_ARRAY - && !valtype->is_vector () - && valtype->length () <= 8 - && (valtype->target_type ()->code () == TYPE_CODE_INT - || valtype->target_type ()->code () == TYPE_CODE_CHAR) - && valtype->target_type ()->length () == 1) - { - int regnum = tdep->ppc_gp0_regnum + 3; - int offset = (register_size (gdbarch, regnum) - valtype->length ()); - - if (writebuf != NULL) - regcache->cooked_write_part (regnum, offset, valtype->length (), - writebuf); - if (readbuf != NULL) - regcache->cooked_read_part (regnum, offset, valtype->length (), - readbuf); - return RETURN_VALUE_REGISTER_CONVENTION; - } + /* Small character arrays are returned, right justified, in r3, according to + the v1 ELF ABI spec [1]. But GCC doesn't implement this (PR gcc/122282), + so we treat this as an ABI spec bug, and use + RETURN_VALUE_STRUCT_CONVENTION. We don't handle this case explicly, but + let it be handled by the default return. + [1] https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html. + */ /* In the ELFv2 ABI, homogeneous floating-point or vector aggregates are returned in registers. */ diff --git a/gdb/python/python.c b/gdb/python/python.c index 51e7a0a..9c30d99 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -2432,7 +2432,17 @@ gdbpy_gdb_exiting (int exit_code) gdbpy_print_stack (); } -#if PY_VERSION_HEX < 0x030a0000 +/* Use PyConfig mechanisms for Python 3.9 and newer. + + We used to do this for 3.10 and newer to avoid Py_SetProgramName + deprecation in 3.11. + + With 3.9 and the py_initialize_catch_abort approach, we run into a problem + where exit is called instead of abort, making gdb exit (possibly + https://github.com/python/cpython/issues/107827). Using the PyConfig + mechanism (available starting 3.8) fixes that. Todo: see if we have the + same problem for 3.8, and if we can apply the same fix. */ +#if PY_VERSION_HEX < 0x03090000 /* Signal handler to convert a SIGABRT into an exception. */ static void @@ -2484,7 +2494,8 @@ py_initialize () ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE); -#if PY_VERSION_HEX < 0x030a0000 +/* Use PyConfig mechanisms for Python 3.9 and newer. */ +#if PY_VERSION_HEX < 0x03090000 /* Python documentation indicates that the memory given to Py_SetProgramName cannot be freed. However, it seems that at least Python 3.7.4 Py_SetProgramName takes a copy of the @@ -2525,9 +2536,8 @@ py_initialize () } #endif - /* Py_SetProgramName was deprecated in Python 3.11. Use PyConfig - mechanisms for Python 3.10 and newer. */ -#if PY_VERSION_HEX < 0x030a0000 +/* Use PyConfig mechanisms for Python 3.9 and newer. */ +#if PY_VERSION_HEX < 0x03090000 /* 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. */ diff --git a/gdb/testsuite/gdb.ada/return-small-char-array.exp b/gdb/testsuite/gdb.ada/return-small-char-array.exp index 1f6412e..63009be 100644 --- a/gdb/testsuite/gdb.ada/return-small-char-array.exp +++ b/gdb/testsuite/gdb.ada/return-small-char-array.exp @@ -19,7 +19,13 @@ require allow_ada_tests standard_ada_testfile proc -if { [gdb_compile_ada $srcfile $binfile executable debug] != "" } { +set opts {} +lappend opts debug +if { [ada_fvar_tracking] } { + lappend opts "additional_flags=-fvar-tracking" +} + +if { [gdb_compile_ada $srcfile $binfile executable $opts] != "" } { return } @@ -31,9 +37,13 @@ runto "proc.adb:$bp_location" gdb_test "print Value.Name(My_Value)" \ { = "abcd"} -# Step into the function. -gdb_test "step 2" \ - "return Of_Value;" +# Step into the function. Don't do this by stepping, but by setting a +# breakpoint and continuing to it, to avoid the problem that varying line info +# may require us to step a different amount of times to land at the same +# location. +set bp_location_2 [gdb_get_line_number "STOP" $testdir/value.adb] +gdb_breakpoint value.adb:$bp_location_2 +gdb_continue_to_breakpoint "STOP" # and finish. gdb_test "finish" \ diff --git a/gdb/testsuite/gdb.ada/return-small-char-array/value.adb b/gdb/testsuite/gdb.ada/return-small-char-array/value.adb index 2dd9faa..351e67a 100644 --- a/gdb/testsuite/gdb.ada/return-small-char-array/value.adb +++ b/gdb/testsuite/gdb.ada/return-small-char-array/value.adb @@ -16,6 +16,6 @@ package body Value is function Name (Of_Value : T) return T is begin - return Of_Value; + return Of_Value; -- STOP end Name; end Value; diff --git a/gdb/testsuite/gdb.base/corefile-exec-mismatch.c b/gdb/testsuite/gdb.base/corefile-exec-mismatch.c new file mode 100644 index 0000000..a52b2a3 --- /dev/null +++ b/gdb/testsuite/gdb.base/corefile-exec-mismatch.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2025 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <stdlib.h> + +#ifdef GEN_CORE +static int +crashfunc (void) +{ + abort (); + return 0; +} +#endif + +int +main (void) +{ +#ifdef GEN_CORE + int ret = crashfunc (); +#else + int ret = 0; +#endif + return ret; +} diff --git a/gdb/testsuite/gdb.base/corefile-exec-mismatch.exp b/gdb/testsuite/gdb.base/corefile-exec-mismatch.exp new file mode 100644 index 0000000..dbd652d --- /dev/null +++ b/gdb/testsuite/gdb.base/corefile-exec-mismatch.exp @@ -0,0 +1,188 @@ +# Copyright 2025 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test that when loading a core file, if the current executable +# doesn't match the expected executable for this core file, then GDB +# should give a warning. +# +# We only check the build-id based verification as the name only based +# verification relies on the name held in the PRPSINFO note, which is +# only 80 characters long, as a result, when running the testsuite, +# this string usually only holds the path to the testsuite build +# directory, which might be the same for every core file created. +# +# In addition, as the check is in a similar area of GDB, we check that +# if the executable is newer than the core file, GDB gives a warning. + +# The core file management in this script only works if the host +# machine is local. +require {!is_remote host} + +standard_testfile .c + +# Build an executable with a build id. +if { [build_executable "build" $testfile $srcfile \ + { debug build-id additional_flags=-DGEN_CORE } ] } { + return +} + +# Build an alternative executable. This is different than +# TESTFILE, and so has a different build-id. +set alt_testfile "alt-with-build-id" +set alt_binfile [standard_output_file $alt_testfile] +if { [build_executable "build" $alt_testfile $srcfile \ + { debug build-id } ] } { + return +} + +# Do we expect the build-id for BINFILE to appear in a core file +# generated from BINFILE? If not then this test isn't going to +# work. +if { ![expect_build_id_in_core_file $binfile] } { + unsupported "build-id will not appear in core file" + return +} + +# Create a core file by running BINFILE. +set corefile [core_find $binfile {}] +if {$corefile == ""} { + untested "unable to create corefile" + return +} + +# Start GDB using a completely different executable (than was used +# to generate the core file); this has a different filename and +# build-id. +clean_restart $alt_testfile + +# Load the core file. GDB should warn because the build-id of the +# executable doesn't match the expected build-id pulled from the +# core file. +set saw_mismatch_warning false +gdb_test_multiple "core $corefile" "load core file, different exec name" { + -re "^core \[^\r\n\]+\r\n" { + exp_continue + } + -re "^warning: core file may not match specified executable file\\.\r\n" { + set saw_mismatch_warning true + exp_continue + } + -re "^$gdb_prompt $" { + gdb_assert { $saw_mismatch_warning } $gdb_test_name + } + -re "^\[^\r\n\]*\r\n" { + exp_continue + } +} + +# Cleanup before the next test. +unset saw_mismatch_warning +gdb_exit + +# Touch TESTFILE (via its full filename) so that it is newer than +# the core file. +sleep 1 +remote_exec host "touch ${binfile}" + +# Start GDB using the correct executable, but this file is newer than +# the core file, we expect GDB to warn about this. +clean_restart $testfile + +# Load the core file. GDB should warn that the executable is +# newer than the core file. +# +# NOTE: In this case the build-ids match, so maybe GDB should +# ignore the fact that the core file is older than the executable? +# If we every make that change to GDB, and this test starts to +# fail, then the test should be updated to build executables +# without build-ids so that this warning is still tested. +# +# The reason I didn't do this initially is that, if there are any +# build-ids in the core file, from any shared library at all, then +# GDB will use this as "the" build-id for the core file, and +# compare this to the build-id of the executable. I say GDB here, +# but some of this logic is in BFD. Anyway, if GDB thinks that +# the core file has a build-id, but the executable doesn't, then +# GDB gives the generic "core file may not match specified +# executable file" warning instead of the "exec file is newer than +# core file" warning, which is what we want. +# +# For now then, I just check for the age based warning when we +# also have full build-ids. +set saw_age_warning false +gdb_test_multiple "core $corefile" "load core file, exec is newer" { + -re "^core \[^\r\n\]+\r\n" { + exp_continue + } + -re "^warning: exec file is newer than core file\\.\r\n" { + set saw_age_warning true + exp_continue + } + -re "^$gdb_prompt $" { + gdb_assert { $saw_age_warning } $gdb_test_name + } + -re "^\[^\r\n\]*\r\n" { + exp_continue + } +} + +# Cleanup before the next test. +unset saw_age_warning +gdb_exit + +# Replace BINFILE with ALT_BINFILE, a file with a different +# build-id. +remote_exec host "mv $binfile ${binfile}-hidden" +remote_exec host "cp $alt_binfile $binfile" + +# Ensure COREFILE is newer than BINFILE. +sleep 1 +remote_exec host "touch ${corefile}" + +# Start GDB using the filename that now points to the replacement +# file. +clean_restart $testfile + +# Load the core file. GDB should use the build-id to warn the +# user that the executable doesn't match the core file. We'll +# also get a warning that the build-id of the executable doesn't +# match while processing the mapped file information in the core +# file. +set saw_mismatch_warning false +set saw_build_id_warning false +gdb_test_multiple "core $corefile" "load core file, same exec name" { + -re "^core \[^\r\n\]+\r\n" { + exp_continue + } + -re "^warning: File [string_to_regexp $binfile] doesn't match build-id from core-file during file-backed mapping processing" { + set saw_build_id_warning true + exp_continue + } + -re "^warning: core file may not match specified executable file\\.\r\n" { + set saw_mismatch_warning true + exp_continue + } + -re "^$gdb_prompt $" { + gdb_assert { $saw_mismatch_warning \ + && $saw_build_id_warning } $gdb_test_name + } + -re "^\[^\r\n\]*\r\n" { + exp_continue + } +} + +unset saw_mismatch_warning +unset saw_build_id_warning +gdb_exit diff --git a/libctf/testsuite/lib/ctf-lib.exp b/libctf/testsuite/lib/ctf-lib.exp index 7175e14..da44396 100644 --- a/libctf/testsuite/lib/ctf-lib.exp +++ b/libctf/testsuite/lib/ctf-lib.exp @@ -298,7 +298,7 @@ proc run_lookup_test { name } { } if { $opts(link) == "objects" } { - set obj "[file rootname $src].o" + set obj "tmpdir/[file rootname [file tail $src]].o" set comp_output [prune_warnings [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET $lookup_flags $src -c -o $obj"]] if { $comp_output != ""} { |