diff options
Diffstat (limited to 'gdb/testsuite/gdb.python')
297 files changed, 3472 insertions, 527 deletions
diff --git a/gdb/testsuite/gdb.python/amd64-py-framefilter-invalidarg.S b/gdb/testsuite/gdb.python/amd64-py-framefilter-invalidarg.S index e24b85d..0280591 100644 --- a/gdb/testsuite/gdb.python/amd64-py-framefilter-invalidarg.S +++ b/gdb/testsuite/gdb.python/amd64-py-framefilter-invalidarg.S @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2014-2024 Free Software Foundation, Inc. + Copyright 2014-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 diff --git a/gdb/testsuite/gdb.python/compare-enum-type-a.c b/gdb/testsuite/gdb.python/compare-enum-type-a.c index 237552a..cf02a15 100644 --- a/gdb/testsuite/gdb.python/compare-enum-type-a.c +++ b/gdb/testsuite/gdb.python/compare-enum-type-a.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2020-2024 Free Software Foundation, Inc. + Copyright 2020-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 diff --git a/gdb/testsuite/gdb.python/compare-enum-type-b.c b/gdb/testsuite/gdb.python/compare-enum-type-b.c index 07c7fb8..4576dbb 100644 --- a/gdb/testsuite/gdb.python/compare-enum-type-b.c +++ b/gdb/testsuite/gdb.python/compare-enum-type-b.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2020-2024 Free Software Foundation, Inc. + Copyright 2020-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 diff --git a/gdb/testsuite/gdb.python/compare-enum-type.exp b/gdb/testsuite/gdb.python/compare-enum-type.exp index 7d6ac9d..5dd6a3d 100644 --- a/gdb/testsuite/gdb.python/compare-enum-type.exp +++ b/gdb/testsuite/gdb.python/compare-enum-type.exp @@ -1,4 +1,4 @@ -# Copyright 2020-2024 Free Software Foundation, Inc. +# Copyright 2020-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 diff --git a/gdb/testsuite/gdb.python/compare-enum-type.h b/gdb/testsuite/gdb.python/compare-enum-type.h index 674ccb8..506e0c5 100644 --- a/gdb/testsuite/gdb.python/compare-enum-type.h +++ b/gdb/testsuite/gdb.python/compare-enum-type.h @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2020-2024 Free Software Foundation, Inc. + Copyright 2020-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 diff --git a/gdb/testsuite/gdb.python/flexible-array-member.c b/gdb/testsuite/gdb.python/flexible-array-member.c index d53bcd0..00e1313 100644 --- a/gdb/testsuite/gdb.python/flexible-array-member.c +++ b/gdb/testsuite/gdb.python/flexible-array-member.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2020-2024 Free Software Foundation, Inc. + Copyright 2020-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 diff --git a/gdb/testsuite/gdb.python/flexible-array-member.exp b/gdb/testsuite/gdb.python/flexible-array-member.exp index f684e68..3468ec8 100644 --- a/gdb/testsuite/gdb.python/flexible-array-member.exp +++ b/gdb/testsuite/gdb.python/flexible-array-member.exp @@ -1,4 +1,4 @@ -# Copyright 2020-2024 Free Software Foundation, Inc. +# Copyright 2020-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 diff --git a/gdb/testsuite/gdb.python/gdb_leak_detector.py b/gdb/testsuite/gdb.python/gdb_leak_detector.py new file mode 100644 index 0000000..8f74b67 --- /dev/null +++ b/gdb/testsuite/gdb.python/gdb_leak_detector.py @@ -0,0 +1,121 @@ +# Copyright (C) 2021-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/>. + +# Defines a base class, which can be sub-classed, in order to run +# memory leak tests on some aspects of GDB's Python API. See the +# comments on the gdb_leak_detector class for more details. + +import os +import tracemalloc + +import gdb + + +# This class must be sub-classed to create a memory leak test. The +# sub-classes __init__ method should call the parent classes __init__ +# method, and the sub-class should override allocate() and +# deallocate(). See the comments on the various methods below for +# more details of required arguments and expected usage. +class gdb_leak_detector: + + # Class initialisation. FILENAME is the file in which the + # sub-class is defined, usually passed as just '__file__'. This + # is used when looking for memory allocations; only allocations in + # FILENAME are considered. + def __init__(self, filename): + self.filters = [tracemalloc.Filter(True, "*" + os.path.basename(filename))] + + # Internal helper function to actually run the test. Calls the + # allocate() method to allocate an object from GDB's Python API. + # When CLEAR is True the object will then be deallocated by + # calling deallocate(), otherwise, deallocate() is not called. + # + # Finally, this function checks for any memory allocatios + # originating from 'self.filename' that have not been freed, and + # returns the total (in bytes) of the memory that has been + # allocated, but not freed. + def _do_test(self, clear): + # Start tracing, and take a snapshot of the current allocations. + tracemalloc.start() + snapshot1 = tracemalloc.take_snapshot() + + # Generate the GDB Python API object by calling the allocate + # method. + self.allocate() + + # Possibly clear the reference to the allocated object. + if clear: + self.deallocate() + + # Now grab a second snapshot of memory allocations, and stop + # tracing memory allocations. + snapshot2 = tracemalloc.take_snapshot() + tracemalloc.stop() + + # Filter the snapshots; we only care about allocations originating + # from this file. + snapshot1 = snapshot1.filter_traces(self.filters) + snapshot2 = snapshot2.filter_traces(self.filters) + + # Compare the snapshots, this leaves only things that were + # allocated, but not deallocated since the first snapshot. + stats = snapshot2.compare_to(snapshot1, "traceback") + + # Total up all the allocated things. + total = 0 + for stat in stats: + total += stat.size_diff + return total + + # Run the memory leak test. Prints 'PASS' if successful, + # otherwise, raises an exception (of type GdbError). + def run(self): + # The first time we run this some global state will be allocated which + # shows up as memory that is allocated, but not released. So, run the + # test once and discard the result. + self._do_test(True) + + # Now run the test twice, the first time we clear our global reference + # to the allocated object, which should allow Python to deallocate the + # object. The second time we hold onto the global reference, preventing + # Python from performing the deallocation. + bytes_with_clear = self._do_test(True) + bytes_without_clear = self._do_test(False) + + # If there are any allocations left over when we cleared the reference + # (and expected deallocation) then this indicates a leak. + if bytes_with_clear > 0: + raise gdb.GdbError("memory leak when object reference was released") + + # If there are no allocations showing when we hold onto a reference, + # then this likely indicates that the testing infrastructure is broken, + # and we're no longer spotting the allocations at all. + if bytes_without_clear == 0: + raise gdb.GdbError("object is unexpectedly not showing as allocated") + + # Print a PASS message that the TCL script can see. + print("PASS") + + # Sub-classes must override this method. Allocate an object (or + # multiple objects) from GDB's Python API. Store references to + # these objects within SELF. + def allocate(self): + raise NotImplementedError("allocate() not implemented") + + # Sub-classes must override this method. Deallocate the object(s) + # allocated by the allocate() method. All that is required is for + # the references created in allocate() to be set to None. + def deallocate(self): + raise NotImplementedError("allocate() not implemented") diff --git a/gdb/testsuite/gdb.python/lib-types.cc b/gdb/testsuite/gdb.python/lib-types.cc index c221693..3901a0b 100644 --- a/gdb/testsuite/gdb.python/lib-types.cc +++ b/gdb/testsuite/gdb.python/lib-types.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/lib-types.exp b/gdb/testsuite/gdb.python/lib-types.exp index de24517..168f497 100644 --- a/gdb/testsuite/gdb.python/lib-types.exp +++ b/gdb/testsuite/gdb.python/lib-types.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/libpy-autoloaded-pretty-printers-in-newobjfile-event.so-gdb.py b/gdb/testsuite/gdb.python/libpy-autoloaded-pretty-printers-in-newobjfile-event.so-gdb.py index 5b3a1b7..18407e2 100644 --- a/gdb/testsuite/gdb.python/libpy-autoloaded-pretty-printers-in-newobjfile-event.so-gdb.py +++ b/gdb/testsuite/gdb.python/libpy-autoloaded-pretty-printers-in-newobjfile-event.so-gdb.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/lotsa-lines.exp b/gdb/testsuite/gdb.python/lotsa-lines.exp index b3e980a..537e6f8 100644 --- a/gdb/testsuite/gdb.python/lotsa-lines.exp +++ b/gdb/testsuite/gdb.python/lotsa-lines.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 diff --git a/gdb/testsuite/gdb.python/pretty-print-call-by-hand.c b/gdb/testsuite/gdb.python/pretty-print-call-by-hand.c index 94121f5..88700a1 100644 --- a/gdb/testsuite/gdb.python/pretty-print-call-by-hand.c +++ b/gdb/testsuite/gdb.python/pretty-print-call-by-hand.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2022-2024 Free Software Foundation, Inc. + Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp b/gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp index e633e55..dd6cb59 100644 --- a/gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp +++ b/gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 diff --git a/gdb/testsuite/gdb.python/pretty-print-call-by-hand.py b/gdb/testsuite/gdb.python/pretty-print-call-by-hand.py index f9289ef..3620354 100644 --- a/gdb/testsuite/gdb.python/pretty-print-call-by-hand.py +++ b/gdb/testsuite/gdb.python/pretty-print-call-by-hand.py @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 diff --git a/gdb/testsuite/gdb.python/py-arch-reg-groups.exp b/gdb/testsuite/gdb.python/py-arch-reg-groups.exp index 4ff3e9c..855af27 100644 --- a/gdb/testsuite/gdb.python/py-arch-reg-groups.exp +++ b/gdb/testsuite/gdb.python/py-arch-reg-groups.exp @@ -1,4 +1,4 @@ -# Copyright 2020-2024 Free Software Foundation, Inc. +# Copyright 2020-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 @@ -32,10 +32,13 @@ if ![runto_main] { set groups {} set test "maint print reggroups" gdb_test_multiple $test $test { - -re ".*Group\[ \t\]+Type\[ \t\]+\r\n" { + -re "^$test\r\n" { exp_continue } - -re "^ (\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" { + -re "Group\[ \t\]+Type\[ \t\]+\r\n" { + exp_continue + } + -re "^(\[^ \t\]+)\[ \t\]+\[^\r\n\]+\r\n" { lappend groups $expect_out(1,string) exp_continue } @@ -74,7 +77,7 @@ gdb_test_multiple "python print (\"\\n\".join (groups))" \ gdb_assert {[llength $py_groups] > 0} \ "Found at least one register group from python" gdb_assert {[llength $py_groups] == [llength $groups]} \ - "Same numnber of registers groups found" + "Same number of registers groups found" set found_non_match 0 for { set i 0 } { $i < [llength $groups] } { incr i } { diff --git a/gdb/testsuite/gdb.python/py-arch-reg-names.exp b/gdb/testsuite/gdb.python/py-arch-reg-names.exp index 7c08168..7093674 100644 --- a/gdb/testsuite/gdb.python/py-arch-reg-names.exp +++ b/gdb/testsuite/gdb.python/py-arch-reg-names.exp @@ -1,4 +1,4 @@ -# Copyright 2020-2024 Free Software Foundation, Inc. +# Copyright 2020-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 diff --git a/gdb/testsuite/gdb.python/py-arch.c b/gdb/testsuite/gdb.python/py-arch.c index ec6874b..a630de4 100644 --- a/gdb/testsuite/gdb.python/py-arch.c +++ b/gdb/testsuite/gdb.python/py-arch.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2013-2024 Free Software Foundation, Inc. + Copyright 2013-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 diff --git a/gdb/testsuite/gdb.python/py-arch.exp b/gdb/testsuite/gdb.python/py-arch.exp index 3c58bf1..79e5939 100644 --- a/gdb/testsuite/gdb.python/py-arch.exp +++ b/gdb/testsuite/gdb.python/py-arch.exp @@ -1,4 +1,4 @@ -# Copyright 2013-2024 Free Software Foundation, Inc. +# Copyright 2013-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 @@ -28,7 +28,7 @@ if ![runto_main] { # internal GDB assert. gdb_py_test_silent_cmd "python empty = gdb.Architecture()" "get empty arch" 0 gdb_test "python print(repr (empty))" "<gdb\\.Architecture \\(invalid\\)>" \ - "Test empty achitecture __repr__ does not trigger an assert" + "Test empty architecture __repr__ does not trigger an assert" gdb_test "python print(empty.name())" ".*Architecture is invalid.*" \ "Test empty architecture.name does not trigger an assert" gdb_test "python print(empty.disassemble())" ".*Architecture is invalid.*" \ @@ -70,9 +70,7 @@ if { ![is_address_zero_readable] } { foreach size {0 1 2 3 4 8 16} { foreach sign_data {{"" True} \ {", True" True} \ - {", False" False} \ - {", None" False} \ - {", \"blah\"" True}} { + {", False" False}} { set sign [lindex $sign_data 0] # GDB's 0 bit type is always signed. if { $size == 0 } { @@ -94,6 +92,27 @@ gdb_test "python arch.integer_type(95)" \ ".*ValueError.* no integer type of that size is available.*" \ "call integer_type with invalid size" +foreach_with_prefix test_data { {None None} \ + {"\"blah\"" str} \ + {1 int} } { + set bad_sign [lindex $test_data 0] + set bad_type [lindex $test_data 1] + gdb_test "python arch.integer_type(8, $bad_sign)" \ + [multi_line \ + "Python Exception <class 'TypeError'>: argument 2 must be bool, not $bad_type" \ + "Error occurred in Python: argument 2 must be bool, not $bad_type"] \ + "check 'signed' argument can handle non-bool type $bad_type" +} + +gdb_test "python print(arch.void_type())" \ + "void" \ + "get void type" + +# Test type identity +gdb_test "python print(arch.integer_type(32) is arch.integer_type(32))" \ + "True" \ + "arch.integer_type(32) always return the same Python object" + # Test for gdb.architecture_names(). First we're going to grab the # complete list of architecture names using the 'complete' command. set arch_names [] diff --git a/gdb/testsuite/gdb.python/py-as-string.c b/gdb/testsuite/gdb.python/py-as-string.c index ec05206..1997300 100644 --- a/gdb/testsuite/gdb.python/py-as-string.c +++ b/gdb/testsuite/gdb.python/py-as-string.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2016-2024 Free Software Foundation, Inc. + Copyright 2016-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 diff --git a/gdb/testsuite/gdb.python/py-as-string.exp b/gdb/testsuite/gdb.python/py-as-string.exp index 1a38d4b..05d55df 100644 --- a/gdb/testsuite/gdb.python/py-as-string.exp +++ b/gdb/testsuite/gdb.python/py-as-string.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2024 Free Software Foundation, Inc. +# Copyright (C) 2016-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 diff --git a/gdb/testsuite/gdb.python/py-auto-load-chaining-f1.c b/gdb/testsuite/gdb.python/py-auto-load-chaining-f1.c index 7fb1c5f..10baa8e 100644 --- a/gdb/testsuite/gdb.python/py-auto-load-chaining-f1.c +++ b/gdb/testsuite/gdb.python/py-auto-load-chaining-f1.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-auto-load-chaining-f1.o-gdb.py b/gdb/testsuite/gdb.python/py-auto-load-chaining-f1.o-gdb.py index 0740de3..9641a86 100644 --- a/gdb/testsuite/gdb.python/py-auto-load-chaining-f1.o-gdb.py +++ b/gdb/testsuite/gdb.python/py-auto-load-chaining-f1.o-gdb.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-auto-load-chaining-f2.c b/gdb/testsuite/gdb.python/py-auto-load-chaining-f2.c index f2f3506..ef6c4a4 100644 --- a/gdb/testsuite/gdb.python/py-auto-load-chaining-f2.c +++ b/gdb/testsuite/gdb.python/py-auto-load-chaining-f2.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-auto-load-chaining-f2.o-gdb.py b/gdb/testsuite/gdb.python/py-auto-load-chaining-f2.o-gdb.py index 2be5cb1..f1abc2c 100644 --- a/gdb/testsuite/gdb.python/py-auto-load-chaining-f2.o-gdb.py +++ b/gdb/testsuite/gdb.python/py-auto-load-chaining-f2.o-gdb.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-auto-load-chaining.c b/gdb/testsuite/gdb.python/py-auto-load-chaining.c index 50236c2..74ec04f 100644 --- a/gdb/testsuite/gdb.python/py-auto-load-chaining.c +++ b/gdb/testsuite/gdb.python/py-auto-load-chaining.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-auto-load-chaining.exp b/gdb/testsuite/gdb.python/py-auto-load-chaining.exp index b5aabd3..451dca6 100644 --- a/gdb/testsuite/gdb.python/py-auto-load-chaining.exp +++ b/gdb/testsuite/gdb.python/py-auto-load-chaining.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.cc b/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.cc index 95312ca..c8eb2e6 100644 --- a/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.cc +++ b/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.h b/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.h index 4252d48..9e2bf4f 100644 --- a/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.h +++ b/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-lib.h @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-main.cc b/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-main.cc index 717daf2..0beb0af 100644 --- a/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-main.cc +++ b/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event-main.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.exp b/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.exp index 73f66f4..3bd0494 100644 --- a/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.exp +++ b/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.py b/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.py index d63c087..7bbb860 100644 --- a/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.py +++ b/gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-bad-printers.c b/gdb/testsuite/gdb.python/py-bad-printers.c index 17fe779..d10fde6 100644 --- a/gdb/testsuite/gdb.python/py-bad-printers.c +++ b/gdb/testsuite/gdb.python/py-bad-printers.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2008-2024 Free Software Foundation, Inc. + Copyright 2008-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 diff --git a/gdb/testsuite/gdb.python/py-bad-printers.exp b/gdb/testsuite/gdb.python/py-bad-printers.exp index cc51a6f..ab1a9ba 100644 --- a/gdb/testsuite/gdb.python/py-bad-printers.exp +++ b/gdb/testsuite/gdb.python/py-bad-printers.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 diff --git a/gdb/testsuite/gdb.python/py-bad-printers.py b/gdb/testsuite/gdb.python/py-bad-printers.py index ac9c35e..c93923c 100644 --- a/gdb/testsuite/gdb.python/py-bad-printers.py +++ b/gdb/testsuite/gdb.python/py-bad-printers.py @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 diff --git a/gdb/testsuite/gdb.python/py-block.c b/gdb/testsuite/gdb.python/py-block.c index d180d9b..3417e2d 100644 --- a/gdb/testsuite/gdb.python/py-block.c +++ b/gdb/testsuite/gdb.python/py-block.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/py-block.exp b/gdb/testsuite/gdb.python/py-block.exp index 0e6851d..ce3f7ce 100644 --- a/gdb/testsuite/gdb.python/py-block.exp +++ b/gdb/testsuite/gdb.python/py-block.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 @@ -61,6 +61,10 @@ gdb_py_test_silent_cmd "python sblock = block.static_block" \ "Get block, static_block" 1 gdb_test "python print (gblock.is_global)" "True" "is the global block" gdb_test "python print (sblock.is_static)" "True" "is the static block" +gdb_test "python print (len(gblock.subblocks) > 0)" "True" \ + "global block contains at least one block" +gdb_test "python print (sblock in gblock.subblocks)" "True" \ + "global block contains at static block" # Move up superblock(s) until we reach function block_func. gdb_test_no_output "python block = block.superblock" "get superblock" diff --git a/gdb/testsuite/gdb.python/py-bp-locations.c b/gdb/testsuite/gdb.python/py-bp-locations.c index 98b9380..a261f26 100644 --- a/gdb/testsuite/gdb.python/py-bp-locations.c +++ b/gdb/testsuite/gdb.python/py-bp-locations.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2022-2024 Free Software Foundation, Inc. + Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-bp-locations.exp b/gdb/testsuite/gdb.python/py-bp-locations.exp index 4892947..61e4e38 100644 --- a/gdb/testsuite/gdb.python/py-bp-locations.exp +++ b/gdb/testsuite/gdb.python/py-bp-locations.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 diff --git a/gdb/testsuite/gdb.python/py-breakpoint-create-fail.c b/gdb/testsuite/gdb.python/py-breakpoint-create-fail.c index bbb4ec2..a1a964c 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint-create-fail.c +++ b/gdb/testsuite/gdb.python/py-breakpoint-create-fail.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2016-2024 Free Software Foundation, Inc. + Copyright 2016-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 diff --git a/gdb/testsuite/gdb.python/py-breakpoint-create-fail.exp b/gdb/testsuite/gdb.python/py-breakpoint-create-fail.exp index 7840dba..391744e 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint-create-fail.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint-create-fail.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2024 Free Software Foundation, Inc. +# Copyright (C) 2016-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 diff --git a/gdb/testsuite/gdb.python/py-breakpoint-create-fail.py b/gdb/testsuite/gdb.python/py-breakpoint-create-fail.py index f85de0f..470eaea 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint-create-fail.py +++ b/gdb/testsuite/gdb.python/py-breakpoint-create-fail.py @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2024 Free Software Foundation, Inc. +# Copyright (C) 2016-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 diff --git a/gdb/testsuite/gdb.python/py-breakpoint.c b/gdb/testsuite/gdb.python/py-breakpoint.c index 9fe21ab..4e61d0e 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.c +++ b/gdb/testsuite/gdb.python/py-breakpoint.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index c44477c..9a901a3 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 @@ -707,7 +707,7 @@ proc_with_prefix test_bkpt_explicit_loc {} { delete_breakpoints gdb_test "python bp1 = gdb.Breakpoint (line=bp1)" \ - "RuntimeError.*: Line keyword should be an integer or a string.*" \ + "RuntimeError.*: Line keyword should be an integer or a string\\.\r\n.*" \ "set explicit breakpoint by invalid line type" delete_breakpoints @@ -743,7 +743,9 @@ proc_with_prefix test_bkpt_explicit_loc {} { "No source file named foo.*" \ "set invalid explicit breakpoint by missing source and line" gdb_test "python bp1 = gdb.Breakpoint (source=\"$srcfile\", line=\"900\")" \ - "No line 900 in file \"$srcfile\".*" \ + [multi_line \ + "^No compiled code for line 900 in file \"$srcfile\"\\." \ + "Breakpoint $::decimal \[^\r\n\]+ pending\\."] \ "set invalid explicit breakpoint by source and invalid line" gdb_test "python bp1 = gdb.Breakpoint (function=\"blah\")" \ "Function \"blah\" not defined.*" \ @@ -790,6 +792,15 @@ proc_with_prefix test_bkpt_qualified {} { $one_location_re \ "qualified true" + # Test qualified with a non-bool type. + delete_breakpoints + gdb_test \ + "python gdb.Breakpoint(\"multiply\", qualified=None)" \ + [multi_line \ + "Python Exception <class 'TypeError'>: argument 10 must be bool, not None" \ + "Error occurred in Python: argument 10 must be bool, not None"] \ + "qualified non_bool_type" + # Test qualified=True with an explicit function. delete_breakpoints gdb_test \ diff --git a/gdb/testsuite/gdb.python/py-caller-is.c b/gdb/testsuite/gdb.python/py-caller-is.c index f7c36c1..b6fd8d5 100644 --- a/gdb/testsuite/gdb.python/py-caller-is.c +++ b/gdb/testsuite/gdb.python/py-caller-is.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2012-2024 Free Software Foundation, Inc. + Copyright 2012-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 diff --git a/gdb/testsuite/gdb.python/py-caller-is.exp b/gdb/testsuite/gdb.python/py-caller-is.exp index 301dd1b..8e54c3b 100644 --- a/gdb/testsuite/gdb.python/py-caller-is.exp +++ b/gdb/testsuite/gdb.python/py-caller-is.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2024 Free Software Foundation, Inc. +# Copyright (C) 2012-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 diff --git a/gdb/testsuite/gdb.python/py-charset.exp b/gdb/testsuite/gdb.python/py-charset.exp index c7c4d02..0e98e07 100644 --- a/gdb/testsuite/gdb.python/py-charset.exp +++ b/gdb/testsuite/gdb.python/py-charset.exp @@ -1,4 +1,4 @@ -# Copyright 2022-2024 Free Software Foundation, Inc. +# Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-cmd-exception.c b/gdb/testsuite/gdb.python/py-cmd-exception.c index 6cb2c2c..aa5ec04 100644 --- a/gdb/testsuite/gdb.python/py-cmd-exception.c +++ b/gdb/testsuite/gdb.python/py-cmd-exception.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2023-2024 Free Software Foundation, Inc. + Copyright 2023-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 diff --git a/gdb/testsuite/gdb.python/py-cmd-exception.exp b/gdb/testsuite/gdb.python/py-cmd-exception.exp index 0bfa13e..0333d13 100644 --- a/gdb/testsuite/gdb.python/py-cmd-exception.exp +++ b/gdb/testsuite/gdb.python/py-cmd-exception.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/py-cmd-exception.py b/gdb/testsuite/gdb.python/py-cmd-exception.py index d37257d..5a72b81 100644 --- a/gdb/testsuite/gdb.python/py-cmd-exception.py +++ b/gdb/testsuite/gdb.python/py-cmd-exception.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/py-cmd-prompt.c b/gdb/testsuite/gdb.python/py-cmd-prompt.c index 304503c..5f785f0 100644 --- a/gdb/testsuite/gdb.python/py-cmd-prompt.c +++ b/gdb/testsuite/gdb.python/py-cmd-prompt.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2023-2024 Free Software Foundation, Inc. + Copyright 2023-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 diff --git a/gdb/testsuite/gdb.python/py-cmd-prompt.exp b/gdb/testsuite/gdb.python/py-cmd-prompt.exp index ccb695f..3f392d1 100644 --- a/gdb/testsuite/gdb.python/py-cmd-prompt.exp +++ b/gdb/testsuite/gdb.python/py-cmd-prompt.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/py-cmd-prompt.py b/gdb/testsuite/gdb.python/py-cmd-prompt.py index b80a0c9..1be9f3f 100644 --- a/gdb/testsuite/gdb.python/py-cmd-prompt.py +++ b/gdb/testsuite/gdb.python/py-cmd-prompt.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/py-cmd.c b/gdb/testsuite/gdb.python/py-cmd.c index c18c92a..6c4357c 100644 --- a/gdb/testsuite/gdb.python/py-cmd.c +++ b/gdb/testsuite/gdb.python/py-cmd.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2013-2024 Free Software Foundation, Inc. + Copyright 2013-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 diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp index 82cb4cb..5ac5712 100644 --- a/gdb/testsuite/gdb.python/py-cmd.exp +++ b/gdb/testsuite/gdb.python/py-cmd.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2024 Free Software Foundation, Inc. +# Copyright (C) 2009-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 @@ -128,19 +128,19 @@ gdb_test "test_error_cmd ugh" "you lose!" "call error command" gdb_test "python print (gdb.string_to_argv (\"1 2 3\"))" \ {\['1', '2', '3'\]} \ - "string_to_argv (\"1 2 3\")" + "string_to_argv (\"1 2 3\"), case 1" gdb_test "python print (gdb.string_to_argv (\"'1 2' 3\"))" \ {\['1 2', '3'\]} \ - "string_to_argv (\"'1 2' 3\")" + "string_to_argv (\"'1 2' 3\"), case 2" gdb_test "python print (gdb.string_to_argv ('\"1 2\" 3'))" \ {\['1 2', '3'\]} \ - "string_to_argv ('\"1 2\" 3')" + "string_to_argv ('\"1 2\" 3'), case 3" gdb_test "python print (gdb.string_to_argv ('1\\ 2 3'))" \ {\['1 2', '3'\]} \ - "string_to_argv ('1\\ 2 3')" + "string_to_argv ('1\\ 2 3'), case 4" # Test user-defined python commands. gdb_test_multiline "input simple user-defined command" \ @@ -328,4 +328,89 @@ proc_with_prefix test_command_redefining_itself {} { "call command redefining itself 2" } +# Try to create commands using unknown prefixes and check GDB gives an +# error. There's also a test in here for an ambiguous prefix, which +# gives the same error. +proc_with_prefix test_unknown_prefix {} { + clean_restart + + gdb_test_no_output "python gdb.Command('foo1', gdb.COMMAND_NONE, prefix=True)" + gdb_test_no_output "python gdb.Command('foo cmd', gdb.COMMAND_NONE)" + + foreach prefix { "xxx" "foo xxx" "foo1 xxx" } { + gdb_test "python gdb.Command('$prefix cmd', gdb.COMMAND_NONE)" \ + [multi_line \ + "Python Exception <class 'RuntimeError'>: Could not find command prefix $prefix\\." \ + "Error occurred in Python: Could not find command prefix $prefix\\."] + } + + gdb_test_no_output "python gdb.Command('foo2', gdb.COMMAND_NONE, prefix=True)" + + foreach prefix { "foo" "foo xxx" "foo1 xxx" "foo2 xxx" } { + gdb_test "python gdb.Command('$prefix cmd2', gdb.COMMAND_NONE)" \ + [multi_line \ + "Python Exception <class 'RuntimeError'>: Could not find command prefix $prefix\\." \ + "Error occurred in Python: Could not find command prefix $prefix\\."] + } +} + +# Check what happens if a command object is called without an 'invoke' +# method. +proc_with_prefix test_deleting_invoke_methods {} { + clean_restart + + gdb_test_multiline "create 'foo' prefix command" \ + "python" "" \ + "class test_prefix(gdb.Command):" "" \ + " def __init__ (self):" "" \ + " super().__init__ (\"foo\", gdb.COMMAND_USER, prefix=True)" "" \ + " def invoke (self, arg, from_tty):" "" \ + " print(\"In 'foo' invoke: %s\" % arg)" "" \ + "foo = test_prefix()" "" \ + "end" "" + + gdb_test_multiline "create 'foo bar' command" \ + "python" "" \ + "class test_cmd(gdb.Command):" "" \ + " def __init__ (self):" "" \ + " super().__init__ (\"foo bar\", gdb.COMMAND_USER)" "" \ + " def invoke (self, arg, from_tty):" "" \ + " print(\"In 'foo bar' invoke: %s\" % arg)" "" \ + "foo_bar = test_cmd()" "" \ + "end" "" + + gdb_test "foo def" "In 'foo' invoke: def" \ + "call 'foo' with an unknown sub-command" + + gdb_test "foo bar def" "In 'foo bar' invoke: def" \ + "call 'foo bar' with arguments" + + gdb_test_no_output "python del(foo_bar.__class__.invoke)" \ + "delete invoke from test_cmd class" + + with_test_prefix "after deleting test_cmd.invoke" { + gdb_test "foo def" "In 'foo' invoke: def" \ + "call 'foo' with an unknown sub-command" + + gdb_test "foo bar def" \ + "^Python command object missing 'invoke' method\\." \ + "call 'foo bar' with arguments" + } + + gdb_test_no_output "python del(foo.__class__.invoke)" \ + "delete invoke from test_prefix class" + + with_test_prefix "after deleting test_prefix.invoke" { + gdb_test "foo def" \ + "^Python command object missing 'invoke' method\\." \ + "call 'foo' with an unknown sub-command" + + gdb_test "foo bar def" \ + "^Python command object missing 'invoke' method\\." \ + "call 'foo bar' with arguments" + } +} + test_command_redefining_itself +test_unknown_prefix +test_deleting_invoke_methods diff --git a/gdb/testsuite/gdb.python/py-color-leak.exp b/gdb/testsuite/gdb.python/py-color-leak.exp new file mode 100644 index 0000000..6d7fa7c --- /dev/null +++ b/gdb/testsuite/gdb.python/py-color-leak.exp @@ -0,0 +1,28 @@ +# 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/>. + +# This file is part of the GDB testsuite. It checks for memory leaks +# associated with allocating gdb.Color objects. + +load_lib gdb-python.exp + +require allow_python_tests + +standard_testfile + +clean_restart + +gdb_py_run_memory_leak_test ${srcdir}/${subdir}/${testfile}.py \ + "gdb.Color object deallocates correctly" diff --git a/gdb/testsuite/gdb.python/py-color-leak.py b/gdb/testsuite/gdb.python/py-color-leak.py new file mode 100644 index 0000000..28afd59 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-color-leak.py @@ -0,0 +1,37 @@ +# 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/>. + +import sys + +# Avoid generating +# src/gdb/testsuite/gdb.python/__pycache__/gdb_leak_detector.cpython-<n>.pyc. +sys.dont_write_bytecode = True + +import gdb_leak_detector + + +class color_leak_detector(gdb_leak_detector.gdb_leak_detector): + def __init__(self): + super().__init__(__file__) + self.color = None + + def allocate(self): + self.color = gdb.Color("red") + + def deallocate(self): + self.color = None + + +color_leak_detector().run() diff --git a/gdb/testsuite/gdb.python/py-color.exp b/gdb/testsuite/gdb.python/py-color.exp new file mode 100644 index 0000000..2601cf3 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-color.exp @@ -0,0 +1,163 @@ +# Copyright (C) 2010-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/>. + +# This file is part of the GDB testsuite. It tests gdb.Color. + +load_lib gdb-python.exp + +require allow_python_tests + +# Start with a fresh GDB, but enable color support. +with_ansi_styling_terminal { + clean_restart +} + +gdb_test_no_output "python get_color_attrs = lambda c: \"%s %s %s %s %s\" % (str(c), c.colorspace, c.is_none, c.is_indexed, c.is_direct)" \ + "get_color_attrs helper" + +gdb_test_no_output "python print_color_attrs = lambda c: print (get_color_attrs (c))" \ + "print_color_attrs helper" + +gdb_test_no_output "python c = gdb.Color ()" \ + "create color without params" +gdb_test "python print_color_attrs (c)" "none 0 True False False" \ + "print attrs of a color without params" + +gdb_test_no_output "python c = gdb.Color ('green')" \ + "create color from basic name string" +gdb_test "python print_color_attrs (c)" "green 1 False True False" \ + "print attrs of a basic color name" +gdb_test "python print (c.index)" "2" \ + "print index of a basic color name" + +gdb_test_no_output "python c = gdb.Color (2)" \ + "create color from basic index" +gdb_test "python print_color_attrs (c)" "green 1 False True False" \ + "print attrs of a basic color" +gdb_test "python print (c.index)" "2" \ + "print index of a basic color" + +gdb_test_no_output "python c = gdb.Color (14)" \ + "create color from integer 14" +gdb_test "python print_color_attrs (c)" "14 2 False True False" \ + "print attrs of an color 14" +gdb_test "python print (c.index)" "14" \ + "print index of color 14" + +gdb_test_no_output "python c = gdb.Color (2, gdb.COLORSPACE_ANSI_8COLOR)" \ + "create color from basic index and ansi colorspace" +gdb_test "python print_color_attrs (c)" "green 1 False True False" \ + "print attrs of a basic color with ansi colorspace" +gdb_test "python print (c.index)" "2" \ + "print index of a basic color with ansi colorspace" + +# Create a color using keyword arguments, and check it matches the +# non-keyword color. +gdb_test_no_output "python c2 = gdb.Color (color_space = gdb.COLORSPACE_ANSI_8COLOR, value = 2)" \ + "create color from basic index and ansi colorspace using keywords" +gdb_test "python print(get_color_attrs (c) == get_color_attrs (c2))" "True" \ + "check attributes match" +gdb_test "python print(c.index == c2.index)" "True" \ + "check index matches" + +gdb_test_no_output "python c = gdb.Color (2, gdb.COLORSPACE_XTERM_256COLOR)" \ + "create color from basic index and xterm256 colorspace" +gdb_test "python print_color_attrs (c)" "2 3 False True False" \ + "print attrs of a basic color with xterm256 colorspace" +gdb_test "python print (c.index)" "2" \ + "print index of a basic color with xterm256 colorspace" + +gdb_test_no_output "python c = gdb.Color ((171, 205, 239), gdb.COLORSPACE_RGB_24BIT)" \ + "create color from rgb components" +gdb_test "python print_color_attrs (c)" "#ABCDEF 4 False False True" \ + "print attrs of an RGB color" +gdb_test "python print (c.components)" "\\(171, 205, 239\\)" \ + "print components of an RGB color" + +gdb_test_no_output "python c = gdb.Color ('none')" \ + "create color from string none" +gdb_test "python print_color_attrs (c)" "none 0 True False False" \ + "print attrs of a color none" + +gdb_test_no_output "python c = gdb.Color ('254')" \ + "create color from string 254" +gdb_test "python print_color_attrs (c)" "254 3 False True False" \ + "print attrs of an color 254" +gdb_test "python print (c.index)" "254" \ + "print index of color 254" + +gdb_test_no_output "python c_none = gdb.Color ('none')" \ + "save default color" +gdb_test_no_output "python c_red = gdb.Color ('red')" \ + "save blue color" +gdb_test_no_output "python c_green = gdb.Color ('green')" \ + "save yellow color" +gdb_test [concat "python print (c_red.escape_sequence (True) + " \ + "c_green.escape_sequence (False) + 'red on green' + " \ + "c_none.escape_sequence (False) + ' red on default' + " \ + "c_none.escape_sequence (True))"] \ + "\033\\\[31m\033\\\[42mred on green\033\\\[49m red on default\033\\\[39m" \ + "escape sequences" +gdb_test [concat "python print (c_red.escape_sequence (is_foreground = True) + " \ + "c_green.escape_sequence (is_foreground = False) + 'red on green' + " \ + "c_none.escape_sequence (is_foreground = False) + ' red on default' + " \ + "c_none.escape_sequence (is_foreground = True))"] \ + "\033\\\[31m\033\\\[42mred on green\033\\\[49m red on default\033\\\[39m" \ + "escape sequences using keyword arguments" + +# Ensure that turning styling off means no escape sequences. +gdb_test_no_output "set style enabled off" +gdb_test_no_output "python print (c_red.escape_sequence (True), end='')" +gdb_test_no_output "python print (c_red.escape_sequence (False), end='')" +gdb_test_no_output "set style enabled on" + +gdb_test_multiline "Try to sub-class gdb.Color" \ + "python" "" \ + "class my_color(gdb.Color):" "" \ + " def __init__(self):" "" \ + " super().__init__('red')" "" \ + "end" \ + [multi_line \ + "Python Exception <class 'TypeError'>: type 'gdb\\.Color' is not an acceptable base type" \ + "Error occurred in Python: type 'gdb\\.Color' is not an acceptable base type"] + +gdb_test_multiline "Setup a color parameter and non gdb.Color object" \ + "python" "" \ + "class my_param(gdb.Parameter):" "" \ + " def __init__(self):" "" \ + " super().__init__('color-param', gdb.COMMAND_NONE, gdb.PARAM_COLOR)" "" \ + " self.value = gdb.Color('red')" "" \ + "color_param = my_param()" "" \ + " " "" \ + "class bad_type:" "" \ + " @property" "" \ + " def __class__(self):" "" \ + " raise RuntimeError('__class__ error for bad_type')" "" \ + "bad_obj = bad_type()" "" \ + "end" "" + +gdb_test_no_output "python color_param.value = gdb.Color('blue')" \ + "set color parameter to blue" + +gdb_test "python color_param.value = bad_obj" \ + [multi_line \ + "Python Exception <class 'RuntimeError'>: color argument must be a gdb\\.Color object\\." \ + "Error occurred in Python: color argument must be a gdb\\.Color object\\."] \ + "set color parameter to a non-color type" + +gdb_test "python c_none.escape_sequence(c_red)" \ + [multi_line \ + "Python Exception <class 'TypeError'>: argument 1 must be bool, not gdb.Color" \ + "Error occurred in Python: argument 1 must be bool, not gdb.Color"] diff --git a/gdb/testsuite/gdb.python/py-commands-breakpoint.c b/gdb/testsuite/gdb.python/py-commands-breakpoint.c new file mode 100644 index 0000000..d719922 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-commands-breakpoint.c @@ -0,0 +1,31 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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/>. */ + +static void +test (void) +{ +} + +int +main (void) +{ + test (); + test (); + test (); + + return 0; +} diff --git a/gdb/testsuite/gdb.python/py-commands-breakpoint.exp b/gdb/testsuite/gdb.python/py-commands-breakpoint.exp new file mode 100644 index 0000000..d0771bd --- /dev/null +++ b/gdb/testsuite/gdb.python/py-commands-breakpoint.exp @@ -0,0 +1,45 @@ +# 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/>. + +# This file is part of the GDB testsuite. + +load_lib gdb-python.exp + +require allow_python_tests + +standard_testfile .c .py + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { + return -1 +} + +if { ![runto_main] } { + return 0 +} + +set host_python_file \ + [gdb_remote_download host $srcdir/$subdir/$srcfile2] + +gdb_test_no_output "source $host_python_file" \ + "source python file" + +gdb_test "python TestBreakpoint()" \ + "Breakpoint $decimal .*" + +gdb_test "continue" \ + [multi_line \ + "VAR: 1" \ + "VAR: 2" \ + "VAR: 3"] diff --git a/gdb/testsuite/gdb.python/py-commands-breakpoint.py b/gdb/testsuite/gdb.python/py-commands-breakpoint.py new file mode 100644 index 0000000..dbe7676 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-commands-breakpoint.py @@ -0,0 +1,59 @@ +# 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/>. + +# This file is part of the GDB testsuite. + +import gdb + + +class PyCommandsBreakpoint(gdb.Breakpoint): + bp_dict = dict() + + def __init__(self, *args, **kwargs): + gdb.Breakpoint.__init__(self, *args, **kwargs) + PyCommandsBreakpoint.bp_dict[self.number] = self + self.commands = "" + + @staticmethod + def run_py_commands(num): + bp = PyCommandsBreakpoint.bp_dict[num] + if hasattr(bp, "py_commands"): + bp.py_commands() + + def __setattr__(self, name, value): + if name == "commands": + l = ["python PyCommandsBreakpoint.run_py_commands(%d)" % self.number] + if value != "": + l.append(value) + value = "\n".join(l) + + super().__setattr__(name, value) + + +class TestBreakpoint(PyCommandsBreakpoint): + def __init__(self): + PyCommandsBreakpoint.__init__(self, spec="test") + self.var = 1 + self.commands = "continue" + self.silent = True + + def stop(self): + if self.var == 3: + self.commands = "" + return True + + def py_commands(self): + print("VAR: %d" % self.var) + self.var += 1 diff --git a/gdb/testsuite/gdb.python/py-completion.exp b/gdb/testsuite/gdb.python/py-completion.exp index 9abe407..4c08db4 100644 --- a/gdb/testsuite/gdb.python/py-completion.exp +++ b/gdb/testsuite/gdb.python/py-completion.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2024 Free Software Foundation, Inc. +# Copyright (C) 2014-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 diff --git a/gdb/testsuite/gdb.python/py-completion.py b/gdb/testsuite/gdb.python/py-completion.py index 1a39f6c..906b31e 100644 --- a/gdb/testsuite/gdb.python/py-completion.py +++ b/gdb/testsuite/gdb.python/py-completion.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2024 Free Software Foundation, Inc. +# Copyright (C) 2014-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 diff --git a/gdb/testsuite/gdb.python/py-connection-removed.exp b/gdb/testsuite/gdb.python/py-connection-removed.exp index 117075a..d60ebb0 100644 --- a/gdb/testsuite/gdb.python/py-connection-removed.exp +++ b/gdb/testsuite/gdb.python/py-connection-removed.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 @@ -33,8 +33,8 @@ if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { return -1 } -if ![runto_main] then { - return 0 +if {![runto_main]} { + return } # Register a callback that will trigger when a connection is removed diff --git a/gdb/testsuite/gdb.python/py-connection.c b/gdb/testsuite/gdb.python/py-connection.c index a5530dd..a6e5093 100644 --- a/gdb/testsuite/gdb.python/py-connection.c +++ b/gdb/testsuite/gdb.python/py-connection.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-connection.exp b/gdb/testsuite/gdb.python/py-connection.exp index ca78b37..dbfe20f 100644 --- a/gdb/testsuite/gdb.python/py-connection.exp +++ b/gdb/testsuite/gdb.python/py-connection.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-disasm-exec.exp b/gdb/testsuite/gdb.python/py-disasm-exec.exp new file mode 100644 index 0000000..a8dceec --- /dev/null +++ b/gdb/testsuite/gdb.python/py-disasm-exec.exp @@ -0,0 +1,21 @@ +# Copyright (C) 2024-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/>. + +# This file is part of the GDB testsuite. It validates the Python +# disassembler API. + +set kind exec + +source $srcdir/$subdir/py-disasm.exp.tcl diff --git a/gdb/testsuite/gdb.python/py-disasm-obj.exp b/gdb/testsuite/gdb.python/py-disasm-obj.exp new file mode 100644 index 0000000..55374ad --- /dev/null +++ b/gdb/testsuite/gdb.python/py-disasm-obj.exp @@ -0,0 +1,21 @@ +# Copyright (C) 2024-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/>. + +# This file is part of the GDB testsuite. It validates the Python +# disassembler API. + +set kind obj + +source $srcdir/$subdir/py-disasm.exp.tcl diff --git a/gdb/testsuite/gdb.python/py-disasm.c b/gdb/testsuite/gdb.python/py-disasm.c index f267dbd..95c2d11 100644 --- a/gdb/testsuite/gdb.python/py-disasm.c +++ b/gdb/testsuite/gdb.python/py-disasm.c @@ -1,6 +1,6 @@ /* This test program is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-disasm.exp b/gdb/testsuite/gdb.python/py-disasm.exp.tcl index 5d7d922..c5099ba 100644 --- a/gdb/testsuite/gdb.python/py-disasm.exp +++ b/gdb/testsuite/gdb.python/py-disasm.exp.tcl @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 @@ -20,26 +20,54 @@ load_lib gdb-python.exp require allow_python_tests -standard_testfile +standard_testfile py-disasm.c -if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} "debug"] } { - return -1 -} +if { $kind == "obj" } { + + set obj [standard_output_file ${gdb_test_file_name}.o] + + if { [gdb_compile "$srcdir/$subdir/$srcfile" $obj object "debug"] != "" } { + untested "failed to compile object file [file tail $obj]" + return -1 + } + + clean_restart $obj + +} else { + + if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { + return -1 + } + + if { ![runto_main] } { + fail "can't run to main" + return 0 + } -if {![runto_main]} { - fail "can't run to main" - return 0 } -set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py] +set pyfile [gdb_remote_download host ${srcdir}/${subdir}/py-disasm.py] gdb_test "source ${pyfile}" "Python script imported" \ "import python scripts" -gdb_breakpoint [gdb_get_line_number "Break here."] -gdb_continue_to_breakpoint "Break here." +set line [gdb_get_line_number "Break here."] + +if { $kind == "obj" } { + set curr_pc "*unknown*" + set line [gdb_get_line_number "Break here."] + gdb_test_multiple "info line $line" "" { + -re -wrap "starts at address ($hex) \[^\r\n\]*" { + set curr_pc $expect_out(1,string) + pass $gdb_test_name + } + } +} else { + gdb_breakpoint $line + gdb_continue_to_breakpoint "Break here." -set curr_pc [get_valueof "/x" "\$pc" "*unknown*"] + set curr_pc [get_valueof "/x" "\$pc" "*unknown*"] +} gdb_test_no_output "python current_pc = ${curr_pc}" @@ -67,7 +95,11 @@ proc py_remove_all_disassemblers {} { # Python disassembler API. set nop "(nop|nop\t0|[string_to_regexp nop\t{0}])" set unknown_error_pattern "unknown disassembler error \\(error = -1\\)" -set addr_pattern "\r\n=> ${curr_pc_pattern} <\[^>\]+>:\\s+" +if { $kind == "obj" } { + set addr_pattern "\r\n ${curr_pc_pattern} <\[^>\]+>:\\s+" +} else { + set addr_pattern "\r\n=> ${curr_pc_pattern} <\[^>\]+>:\\s+" +} set base_pattern "${addr_pattern}${nop}" # Helper proc to format a Python exception of TYPE with MSG. @@ -120,7 +152,10 @@ set test_plans \ "Buffer returned from read_memory is sized $decimal instead of the expected $decimal"]] \ [list "ResultOfWrongType" \ [make_exception_pattern "TypeError" \ - "Result is not a DisassemblerResult."]] \ + "Result from Disassembler must be gdb.DisassemblerResult, not Blah."]] \ + [list "ResultOfVeryWrongType" \ + [make_exception_pattern "TypeError" \ + "Result from Disassembler must be gdb.DisassemblerResult, not Blah."]] \ [list "ErrorCreatingTextPart_NoArgs" \ [make_exception_pattern "TypeError" \ [missing_arg_pattern "style" 1]]] \ diff --git a/gdb/testsuite/gdb.python/py-disasm.py b/gdb/testsuite/gdb.python/py-disasm.py index 2741fdb..9761337 100644 --- a/gdb/testsuite/gdb.python/py-disasm.py +++ b/gdb/testsuite/gdb.python/py-disasm.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 @@ -252,7 +252,7 @@ class MemoryErrorEarlyDisassembler(TestDisassembler): def disassemble(self, info): tag = "## FAIL" try: - info.read_memory(1, -info.address + 2) + info.read_memory(1, -info.address - 1) except gdb.MemoryError: tag = "## AFTER ERROR" result = builtin_disassemble_wrapper(info) @@ -267,7 +267,7 @@ class MemoryErrorLateDisassembler(TestDisassembler): def disassemble(self, info): result = builtin_disassemble_wrapper(info) # The following read will throw an error. - info.read_memory(1, -info.address + 2) + info.read_memory(1, -info.address - 1) return DisassemblerResult(1, "BAD") @@ -276,9 +276,9 @@ class RethrowMemoryErrorDisassembler(TestDisassembler): def disassemble(self, info): try: - info.read_memory(1, -info.address + 2) + info.read_memory(1, -info.address - 1) except gdb.MemoryError as e: - raise gdb.MemoryError("cannot read code at address 0x2") + raise gdb.MemoryError("cannot read code at address -1") return DisassemblerResult(1, "BAD") @@ -294,6 +294,24 @@ class ResultOfWrongType(TestDisassembler): return self.Blah(1, "ABC") +class ResultOfVeryWrongType(TestDisassembler): + """Return something that is not a DisassemblerResult from disassemble + method. The thing returned will raise an exception if used in an + isinstance() call, or in PyObject_IsInstance from C++. + """ + + class Blah: + def __init__(self): + pass + + @property + def __class__(self): + raise RuntimeError("error from __class__ in Blah") + + def disassemble(self, info): + return self.Blah() + + class TaggingDisassembler(TestDisassembler): """A simple disassembler that just tags the output.""" diff --git a/gdb/testsuite/gdb.python/py-doc-reformat.exp b/gdb/testsuite/gdb.python/py-doc-reformat.exp index 01671ed..519a314 100644 --- a/gdb/testsuite/gdb.python/py-doc-reformat.exp +++ b/gdb/testsuite/gdb.python/py-doc-reformat.exp @@ -1,4 +1,4 @@ -# Copyright 2022-2024 Free Software Foundation, Inc. +# Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-error.exp b/gdb/testsuite/gdb.python/py-error.exp index 6eb9cc3..1e920c2 100644 --- a/gdb/testsuite/gdb.python/py-error.exp +++ b/gdb/testsuite/gdb.python/py-error.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/py-error.py b/gdb/testsuite/gdb.python/py-error.py index f63e3e7..b128707 100644 --- a/gdb/testsuite/gdb.python/py-error.py +++ b/gdb/testsuite/gdb.python/py-error.py @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/py-event-load.c b/gdb/testsuite/gdb.python/py-event-load.c index 1616ff7..10b65fb 100644 --- a/gdb/testsuite/gdb.python/py-event-load.c +++ b/gdb/testsuite/gdb.python/py-event-load.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2022-2024 Free Software Foundation, Inc. + Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-event-load.exp b/gdb/testsuite/gdb.python/py-event-load.exp index c3e10f6..a09a946 100644 --- a/gdb/testsuite/gdb.python/py-event-load.exp +++ b/gdb/testsuite/gdb.python/py-event-load.exp @@ -1,4 +1,4 @@ -# Copyright 2022-2024 Free Software Foundation, Inc. +# Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-event-load.py b/gdb/testsuite/gdb.python/py-event-load.py index cffd5c0..ac7c533 100644 --- a/gdb/testsuite/gdb.python/py-event-load.py +++ b/gdb/testsuite/gdb.python/py-event-load.py @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 diff --git a/gdb/testsuite/gdb.python/py-events-shlib.c b/gdb/testsuite/gdb.python/py-events-shlib.c index 335bcdc..d77517a 100644 --- a/gdb/testsuite/gdb.python/py-events-shlib.c +++ b/gdb/testsuite/gdb.python/py-events-shlib.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2011-2024 Free Software Foundation, Inc. + Copyright 2011-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 diff --git a/gdb/testsuite/gdb.python/py-events.c b/gdb/testsuite/gdb.python/py-events.c index 747d7a8..9ecdeb7 100644 --- a/gdb/testsuite/gdb.python/py-events.c +++ b/gdb/testsuite/gdb.python/py-events.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp index 85b55ae..b440ac4 100644 --- a/gdb/testsuite/gdb.python/py-events.exp +++ b/gdb/testsuite/gdb.python/py-events.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/py-events.py b/gdb/testsuite/gdb.python/py-events.py index ebc59df..0573b16 100644 --- a/gdb/testsuite/gdb.python/py-events.py +++ b/gdb/testsuite/gdb.python/py-events.py @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/py-evsignal.exp b/gdb/testsuite/gdb.python/py-evsignal.exp index 83b351f..22b13af 100644 --- a/gdb/testsuite/gdb.python/py-evsignal.exp +++ b/gdb/testsuite/gdb.python/py-evsignal.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/py-evthreads.c b/gdb/testsuite/gdb.python/py-evthreads.c index 5605d03..321a9b7 100644 --- a/gdb/testsuite/gdb.python/py-evthreads.c +++ b/gdb/testsuite/gdb.python/py-evthreads.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/py-evthreads.exp b/gdb/testsuite/gdb.python/py-evthreads.exp index c2310a1..0e9cd97 100644 --- a/gdb/testsuite/gdb.python/py-evthreads.exp +++ b/gdb/testsuite/gdb.python/py-evthreads.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/py-exec-file.c b/gdb/testsuite/gdb.python/py-exec-file.c index ca3e5ab..df3db4d 100644 --- a/gdb/testsuite/gdb.python/py-exec-file.c +++ b/gdb/testsuite/gdb.python/py-exec-file.c @@ -1,6 +1,6 @@ /* This test program is part of GDB, the GNU debugger. - Copyright 2023-2024 Free Software Foundation, Inc. + Copyright 2023-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 diff --git a/gdb/testsuite/gdb.python/py-exec-file.exp b/gdb/testsuite/gdb.python/py-exec-file.exp index f735757..b3418a5 100644 --- a/gdb/testsuite/gdb.python/py-exec-file.exp +++ b/gdb/testsuite/gdb.python/py-exec-file.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/py-exec-mi.exp b/gdb/testsuite/gdb.python/py-exec-mi.exp index 8a5d0c9..96ee481 100644 --- a/gdb/testsuite/gdb.python/py-exec-mi.exp +++ b/gdb/testsuite/gdb.python/py-exec-mi.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 @@ -30,3 +30,7 @@ gdb_test_no_output "python gdb.execute_mi('-exec-arguments', 'a', 'b', 'c')" \ "set arguments" gdb_test "show args" ".*\"a b c\"." + +# Ensure that this causes an error, not a crash. +gdb_test "python gdb.execute_mi()" \ + "Error occurred in Python: gdb.execute_mi requires command argument" diff --git a/gdb/testsuite/gdb.python/py-explore-cc.exp b/gdb/testsuite/gdb.python/py-explore-cc.exp index 94fae13..0be7019 100644 --- a/gdb/testsuite/gdb.python/py-explore-cc.exp +++ b/gdb/testsuite/gdb.python/py-explore-cc.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2024 Free Software Foundation, Inc. +# Copyright (C) 2012-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 diff --git a/gdb/testsuite/gdb.python/py-explore.c b/gdb/testsuite/gdb.python/py-explore.c index 8f48ecb..5546eaf 100644 --- a/gdb/testsuite/gdb.python/py-explore.c +++ b/gdb/testsuite/gdb.python/py-explore.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2012-2024 Free Software Foundation, Inc. + Copyright 2012-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 diff --git a/gdb/testsuite/gdb.python/py-explore.cc b/gdb/testsuite/gdb.python/py-explore.cc index ea50ade..658979e 100644 --- a/gdb/testsuite/gdb.python/py-explore.cc +++ b/gdb/testsuite/gdb.python/py-explore.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2012-2024 Free Software Foundation, Inc. + Copyright 2012-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 diff --git a/gdb/testsuite/gdb.python/py-explore.exp b/gdb/testsuite/gdb.python/py-explore.exp index 93be521..a68c110 100644 --- a/gdb/testsuite/gdb.python/py-explore.exp +++ b/gdb/testsuite/gdb.python/py-explore.exp @@ -1,4 +1,4 @@ -# Copyright 2012-2024 Free Software Foundation, Inc. +# Copyright 2012-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 diff --git a/gdb/testsuite/gdb.python/py-failed-init.exp b/gdb/testsuite/gdb.python/py-failed-init.exp new file mode 100644 index 0000000..ee3dc7a --- /dev/null +++ b/gdb/testsuite/gdb.python/py-failed-init.exp @@ -0,0 +1,31 @@ +# Copyright 2024-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/>. + +require allow_python_tests +require {!is_remote host} + +save_vars { env(PYTHONHOME) } { + setenv PYTHONHOME foo + clean_restart +} + +gdb_test "python print (1)" \ + "Python not initialized" + +gdb_test_multiple "quit" "" { + eof { + pass $gdb_test_name + } +} diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.c b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.c index 8f0e6bb..6bc7cb6 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.c +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2022-2024 Free Software Foundation, Inc. + Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.exp b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.exp index 84e839b..42aa572 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.exp +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 @@ -25,8 +25,8 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} { return -1 } -if ![runto_main] then { - return 0 +if {![runto_main]} { + return } # For remote host testing diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.py b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.py index c6d6df6..8d8ca53 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.py +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.py @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint.c b/gdb/testsuite/gdb.python/py-finish-breakpoint.c index 45dcc98..237a152 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint.c +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2011-2024 Free Software Foundation, Inc. + Copyright 2011-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 diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint.exp b/gdb/testsuite/gdb.python/py-finish-breakpoint.exp index 0316bc7..c7d31f0 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2024 Free Software Foundation, Inc. +# Copyright (C) 2011-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 diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint.py b/gdb/testsuite/gdb.python/py-finish-breakpoint.py index dba0431..413489f 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint.py +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2024 Free Software Foundation, Inc. +# Copyright (C) 2011-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 diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint2.cc b/gdb/testsuite/gdb.python/py-finish-breakpoint2.cc index 3c4f143..af8801f 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint2.cc +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint2.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2011-2024 Free Software Foundation, Inc. + Copyright 2011-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 diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp b/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp index b837bb3..922426f 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint2.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2024 Free Software Foundation, Inc. +# Copyright (C) 2011-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 diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint2.py b/gdb/testsuite/gdb.python/py-finish-breakpoint2.py index 47bb2dd..ae75e51 100644 --- a/gdb/testsuite/gdb.python/py-finish-breakpoint2.py +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint2.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2024 Free Software Foundation, Inc. +# Copyright (C) 2011-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 diff --git a/gdb/testsuite/gdb.python/py-format-address.c b/gdb/testsuite/gdb.python/py-format-address.c index 2a0e916..f8eced6 100644 --- a/gdb/testsuite/gdb.python/py-format-address.c +++ b/gdb/testsuite/gdb.python/py-format-address.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2022-2024 Free Software Foundation, Inc. + Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-format-address.exp b/gdb/testsuite/gdb.python/py-format-address.exp index ab8022c..173297c 100644 --- a/gdb/testsuite/gdb.python/py-format-address.exp +++ b/gdb/testsuite/gdb.python/py-format-address.exp @@ -1,4 +1,4 @@ -# Copyright 2022-2024 Free Software Foundation, Inc. +# Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-format-string.c b/gdb/testsuite/gdb.python/py-format-string.c index c1f59eb..eed356f 100644 --- a/gdb/testsuite/gdb.python/py-format-string.c +++ b/gdb/testsuite/gdb.python/py-format-string.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2019-2024 Free Software Foundation, Inc. + Copyright 2019-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 diff --git a/gdb/testsuite/gdb.python/py-format-string.exp b/gdb/testsuite/gdb.python/py-format-string.exp index 0c70ad5..114a606 100644 --- a/gdb/testsuite/gdb.python/py-format-string.exp +++ b/gdb/testsuite/gdb.python/py-format-string.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2024 Free Software Foundation, Inc. +# Copyright (C) 2009-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 @@ -82,7 +82,7 @@ set default_pointer_regexp "0x\[a-fA-F0-9\]+" # A regular expression for a non-expanded C++ reference. # -# Stringifying a C++ reference produces an address preceeded by a "@" in +# Stringifying a C++ reference produces an address preceded by a "@" in # Python, but, by default, the C++ reference/class is expanded by the # GDB print command. set default_ref_regexp "@${default_pointer_regexp}" @@ -1104,10 +1104,16 @@ proc_with_prefix test_invalid_args {} { "12" \ "TypeError.*: format_string\\(\\) takes 0 positional arguments but 1 were given.*" + # For python <= 3.12. + set re1 \ + "TypeError.*: 'invalid' is an invalid keyword argument for this function" + # For python >= 3.13. + set re2 \ + "TypeError.*: this function got an unexpected keyword argument 'invalid'" check_format_string \ "a_point_t" \ "invalid=True" \ - "TypeError.*: 'invalid' is an invalid keyword argument for this function.*" + "($re1|$re2).*" check_format_string \ "a_point_t" \ @@ -1125,6 +1131,11 @@ proc_with_prefix test_invalid_args {} { proc test_styling {} { gdb_test "python print(gdb.parse_and_eval(\"a_point_t\").format_string(styling=True, raw=True))" \ "{[style x variable] = 42, [style y variable] = 12}" + + gdb_test "python print(gdb.parse_and_eval(\"a_point_t\").format_string(styling=None, raw=True))" \ + [multi_line \ + "Python Exception <class 'TypeError'>: argument 8 must be bool, not None" \ + "Error occurred in Python: argument 8 must be bool, not None" ] \ } # Test the gdb.print_options API. diff --git a/gdb/testsuite/gdb.python/py-format-string.py b/gdb/testsuite/gdb.python/py-format-string.py index e4f88b1..34b0124 100644 --- a/gdb/testsuite/gdb.python/py-format-string.py +++ b/gdb/testsuite/gdb.python/py-format-string.py @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 diff --git a/gdb/testsuite/gdb.python/py-frame-args.c b/gdb/testsuite/gdb.python/py-frame-args.c index cbf89c7..4a7b089 100644 --- a/gdb/testsuite/gdb.python/py-frame-args.c +++ b/gdb/testsuite/gdb.python/py-frame-args.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2013-2024 Free Software Foundation, Inc. + Copyright 2013-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 diff --git a/gdb/testsuite/gdb.python/py-frame-args.exp b/gdb/testsuite/gdb.python/py-frame-args.exp index 4fc8f0a..1dbd30e 100644 --- a/gdb/testsuite/gdb.python/py-frame-args.exp +++ b/gdb/testsuite/gdb.python/py-frame-args.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2024 Free Software Foundation, Inc. +# Copyright (C) 2013-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 diff --git a/gdb/testsuite/gdb.python/py-frame-args.py b/gdb/testsuite/gdb.python/py-frame-args.py index 04ab1ac..45476b1 100644 --- a/gdb/testsuite/gdb.python/py-frame-args.py +++ b/gdb/testsuite/gdb.python/py-frame-args.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2024 Free Software Foundation, Inc. +# Copyright (C) 2013-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 diff --git a/gdb/testsuite/gdb.python/py-frame-inline.c b/gdb/testsuite/gdb.python/py-frame-inline.c index 691ade5..c02ddf3 100644 --- a/gdb/testsuite/gdb.python/py-frame-inline.c +++ b/gdb/testsuite/gdb.python/py-frame-inline.c @@ -1,6 +1,6 @@ /* This test is part of GDB, the GNU debugger. - Copyright 2011-2024 Free Software Foundation, Inc. + Copyright 2011-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 diff --git a/gdb/testsuite/gdb.python/py-frame-inline.exp b/gdb/testsuite/gdb.python/py-frame-inline.exp index ce3d309..d4a74a1 100644 --- a/gdb/testsuite/gdb.python/py-frame-inline.exp +++ b/gdb/testsuite/gdb.python/py-frame-inline.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2024 Free Software Foundation, Inc. +# Copyright (C) 2011-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 diff --git a/gdb/testsuite/gdb.python/py-frame.exp b/gdb/testsuite/gdb.python/py-frame.exp index 8f776eb..c1e3e33 100644 --- a/gdb/testsuite/gdb.python/py-frame.exp +++ b/gdb/testsuite/gdb.python/py-frame.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2024 Free Software Foundation, Inc. +# Copyright (C) 2009-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 @@ -127,10 +127,10 @@ gdb_test "python print (f1 == gdb.newest_frame())" False \ gdb_test "python print (bframe == gdb.newest_frame())" True \ "newest frame -vs- newest frame" -gdb_test "python print ('result = %s' % (f0 == f1))" " = False" "test equality comparison (false)" -gdb_test "python print ('result = %s' % (f0 == f0))" " = True" "test equality comparison (true)" -gdb_test "python print ('result = %s' % (f0 != f1))" " = True" "test inequality comparison (true)" -gdb_test "python print ('result = %s' % (f0 != f0))" " = False" "test inequality comparison (false)" +gdb_test "python print ('result = %s' % (f0 == f1))" " = False" "test equality comparison, false" +gdb_test "python print ('result = %s' % (f0 == f0))" " = True" "test equality comparison, true" +gdb_test "python print ('result = %s' % (f0 != f1))" " = True" "test inequality comparison, true" +gdb_test "python print ('result = %s' % (f0 != f0))" " = False" "test inequality comparison, false" gdb_test "python print ('result = %s' % f0.is_valid ())" " = True" "test Frame.is_valid" gdb_test "python print ('result = %s' % f0.name ())" " = f2" "test Frame.name" gdb_test "python print ('result = %s' % (f0.type () == gdb.NORMAL_FRAME))" " = True" "test Frame.type" @@ -188,6 +188,21 @@ gdb_test "python print(gdb.selected_frame().read_register(list()))" \ ".*Invalid type for register.*" \ "test Frame.read_register with list" +gdb_test_multiline "setup a bad object" \ + "python" "" \ + "class bad_type:" "" \ + " def __init__ (self):" "" \ + " pass" "" \ + " @property" "" \ + " def __class__(self):" "" \ + " raise RuntimeError('error from __class in bad_type')" "" \ + "bad_object = bad_type()" "" \ + "end" "" + +gdb_test "python print(gdb.selected_frame().read_register(bad_object))" \ + ".*Invalid type for register.*" \ + "test Frame.read_register with bad_type object" + # Compile again without debug info. gdb_exit if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {}] } { diff --git a/gdb/testsuite/gdb.python/py-framefilter-addr.c b/gdb/testsuite/gdb.python/py-framefilter-addr.c index 6872c96..e356768 100644 --- a/gdb/testsuite/gdb.python/py-framefilter-addr.c +++ b/gdb/testsuite/gdb.python/py-framefilter-addr.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-framefilter-addr.exp b/gdb/testsuite/gdb.python/py-framefilter-addr.exp index dbc3250..14eebc2 100644 --- a/gdb/testsuite/gdb.python/py-framefilter-addr.exp +++ b/gdb/testsuite/gdb.python/py-framefilter-addr.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-framefilter-addr.py b/gdb/testsuite/gdb.python/py-framefilter-addr.py index c22d91c..513bf6f 100644 --- a/gdb/testsuite/gdb.python/py-framefilter-addr.py +++ b/gdb/testsuite/gdb.python/py-framefilter-addr.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-framefilter-gdb.py b/gdb/testsuite/gdb.python/py-framefilter-gdb.py index ada7ad7..a725dce 100644 --- a/gdb/testsuite/gdb.python/py-framefilter-gdb.py +++ b/gdb/testsuite/gdb.python/py-framefilter-gdb.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2024 Free Software Foundation, Inc. +# Copyright (C) 2013-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 diff --git a/gdb/testsuite/gdb.python/py-framefilter-invalidarg-gdb.py b/gdb/testsuite/gdb.python/py-framefilter-invalidarg-gdb.py index fbe0c0d..51922fc 100644 --- a/gdb/testsuite/gdb.python/py-framefilter-invalidarg-gdb.py +++ b/gdb/testsuite/gdb.python/py-framefilter-invalidarg-gdb.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2024 Free Software Foundation, Inc. +# Copyright (C) 2014-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 diff --git a/gdb/testsuite/gdb.python/py-framefilter-invalidarg.exp b/gdb/testsuite/gdb.python/py-framefilter-invalidarg.exp index 481eead..c58dd01 100644 --- a/gdb/testsuite/gdb.python/py-framefilter-invalidarg.exp +++ b/gdb/testsuite/gdb.python/py-framefilter-invalidarg.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2024 Free Software Foundation, Inc. +# Copyright (C) 2014-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 @@ -58,4 +58,4 @@ set remote_python_file [gdb_remote_download host \ ${srcdir}/${subdir}/${testfile}.py] gdb_test_no_output "source ${remote_python_file}" "load python file" -gdb_test "bt" "niam \\(argc=<error reading variable: dwarf expression stack underflow>, argv=0x\[0-9a-f\]+\\) at py-framefilter-invalidarg.c:\[0-9\]+" "bt full with filters" +gdb_test "bt" "niam \\(argc=<error reading variable: dwarf expression stack underflow>, argv=0x\[0-9a-f\]+\\) at \[^\r\n\]*py-framefilter-invalidarg.c:\[0-9\]+" "bt full with filters" diff --git a/gdb/testsuite/gdb.python/py-framefilter-invalidarg.py b/gdb/testsuite/gdb.python/py-framefilter-invalidarg.py index cb25cd9..b262968 100644 --- a/gdb/testsuite/gdb.python/py-framefilter-invalidarg.py +++ b/gdb/testsuite/gdb.python/py-framefilter-invalidarg.py @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2024 Free Software Foundation, Inc. +# Copyright (C) 2014-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 diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.c b/gdb/testsuite/gdb.python/py-framefilter-mi.c index 35f21b2..cba2b65 100644 --- a/gdb/testsuite/gdb.python/py-framefilter-mi.c +++ b/gdb/testsuite/gdb.python/py-framefilter-mi.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2013-2024 Free Software Foundation, Inc. + Copyright 2013-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 diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp index c6644e5..de04236 100644 --- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp +++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2024 Free Software Foundation, Inc. +# Copyright (C) 2013-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 diff --git a/gdb/testsuite/gdb.python/py-framefilter.c b/gdb/testsuite/gdb.python/py-framefilter.c index 135ead9..1b3d862 100644 --- a/gdb/testsuite/gdb.python/py-framefilter.c +++ b/gdb/testsuite/gdb.python/py-framefilter.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2013-2024 Free Software Foundation, Inc. + Copyright 2013-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 diff --git a/gdb/testsuite/gdb.python/py-framefilter.exp b/gdb/testsuite/gdb.python/py-framefilter.exp index 374d352..7cc8b01 100644 --- a/gdb/testsuite/gdb.python/py-framefilter.exp +++ b/gdb/testsuite/gdb.python/py-framefilter.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2024 Free Software Foundation, Inc. +# Copyright (C) 2013-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 @@ -82,11 +82,10 @@ gdb_breakpoint [gdb_get_line_number "Inner test breakpoint"] gdb_continue_to_breakpoint "Inner test breakpoint" # Test multiple local blocks. -gdb_test "bt full no-filters" \ +gdb_test_lines "bt full no-filters" "" \ ".*#0.*end_func.*h = 9.*f = 42.*g = 19.*bar = $hex \"Inside block x2\".*d = 15.*e = 14.*foo = $hex \"Inside block\".*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*" -gdb_test "bt full" \ - ".*#0.*cnuf_dne.*h = 9.*f = 42.*g = 19.*bar = $hex \"Inside block x2\".*d = 15.*e = 14.*foo = $hex \"Inside block\".*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*" \ - "bt full with filters" +gdb_test_lines "bt full" "bt full with filters" \ + ".*#0.*cnuf_dne.*h = 9.*f = 42.*g = 19.*bar = $hex \"Inside block x2\".*d = 15.*e = 14.*foo = $hex \"Inside block\".*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*" # Test pagination can be aborted even for frame filters. gdb_test_no_output "set height 5" "pagination quit - set height limited" @@ -161,15 +160,12 @@ gdb_test "bt -2" \ gdb_test "bt 3" \ ".*#0.*end_func.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\)\[^#\]*More stack frames follow.*" \ "bt 3 with frame-filter Reverse disabled" -gdb_test "bt no-filter full" \ - ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*" \ - "bt no-filters full with Reverse disabled" -gdb_test "bt full" \ - ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*#22.*in func1 \\(\\).*#23.*in func2 \\(f=3\\).*elided = $hex \"Elided frame\".*fb = \{nothing = $hex \"Elided Foo Bar\", f = 84, s = 38\}.*bf = $hex.*" \ - "bt full with Reverse disabled" -gdb_test "bt full hide" \ - ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*#22.*in func1 \\(\\)\[^#\]*#24.*in func3 \\(i=3\\).*" \ - "bt full hide with Reverse disabled" +gdb_test_lines "bt no-filter full" "bt no-filters full with Reverse disabled" \ + ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*" +gdb_test_lines "bt full" "bt full with Reverse disabled" \ + ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*#22.*in func1 \\(\\).*#23.*in func2 \\(f=3\\).*elided = $hex \"Elided frame\".*fb = \{nothing = $hex \"Elided Foo Bar\", f = 84, s = 38\}.*bf = $hex.*" +gdb_test_lines "bt full hide" "bt full hide with Reverse disabled" \ + ".*#0.*end_func.*str = $hex \"The End\".*st2 = $hex \"Is Near\".*b = 12.*c = 5.*#1.*in funca \\(\\).*#2.*in funcb \\(j=10\\).*bar = \{a = 42, b = 84\}.*#22.*in func1 \\(\\)\[^#\]*#24.*in func3 \\(i=3\\).*" # Re-enable Reverse gdb_test_no_output "enable frame-filter global Reverse" \ diff --git a/gdb/testsuite/gdb.python/py-framefilter.py b/gdb/testsuite/gdb.python/py-framefilter.py index fb679f1..5c3790d 100644 --- a/gdb/testsuite/gdb.python/py-framefilter.py +++ b/gdb/testsuite/gdb.python/py-framefilter.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2024 Free Software Foundation, Inc. +# Copyright (C) 2013-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 diff --git a/gdb/testsuite/gdb.python/py-function.exp b/gdb/testsuite/gdb.python/py-function.exp index 6de3b34..e618a13 100644 --- a/gdb/testsuite/gdb.python/py-function.exp +++ b/gdb/testsuite/gdb.python/py-function.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2024 Free Software Foundation, Inc. +# Copyright (C) 2009-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 diff --git a/gdb/testsuite/gdb.python/py-inferior-leak.c b/gdb/testsuite/gdb.python/py-inferior-leak.c index 7b7b92a..a8d19f2 100644 --- a/gdb/testsuite/gdb.python/py-inferior-leak.c +++ b/gdb/testsuite/gdb.python/py-inferior-leak.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-inferior-leak.exp b/gdb/testsuite/gdb.python/py-inferior-leak.exp index a068ebb..15216ee 100644 --- a/gdb/testsuite/gdb.python/py-inferior-leak.exp +++ b/gdb/testsuite/gdb.python/py-inferior-leak.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 @@ -24,15 +24,5 @@ standard_testfile clean_restart -# Skip this test if the tracemalloc module is not available. -if { ![gdb_py_module_available "tracemalloc"] } { - unsupported "tracemalloc module not available" - return -} - -set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py] - -# Source the Python script, this runs the test (which is written -# completely in Python), and either prints PASS, or throws an -# exception. -gdb_test "source ${pyfile}" "PASS" "source python script" +gdb_py_run_memory_leak_test ${srcdir}/${subdir}/${testfile}.py \ + "gdb.Inferior object deallocates correctly" diff --git a/gdb/testsuite/gdb.python/py-inferior-leak.py b/gdb/testsuite/gdb.python/py-inferior-leak.py index ae3629a..bf61668 100644 --- a/gdb/testsuite/gdb.python/py-inferior-leak.py +++ b/gdb/testsuite/gdb.python/py-inferior-leak.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 @@ -13,100 +13,39 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import re -import tracemalloc - -import gdb - -# A global variable in which we store a reference to the gdb.Inferior -# object sent to us in the new_inferior event. -inf = None - - -# Register the new_inferior event handler. -def new_inferior_handler(event): - global inf - inf = event.inferior - - -gdb.events.new_inferior.connect(new_inferior_handler) +import sys -# A global filters list, we only care about memory allocations -# originating from this script. -filters = [tracemalloc.Filter(True, "*py-inferior-leak.py")] +# Avoid generating +# src/gdb/testsuite/gdb.python/__pycache__/gdb_leak_detector.cpython-<n>.pyc. +sys.dont_write_bytecode = True +import re -# Add a new inferior, and return the number of the new inferior. -def add_inferior(): - output = gdb.execute("add-inferior", False, True) - m = re.search(r"Added inferior (\d+)", output) - if m: - num = int(m.group(1)) - else: - raise RuntimeError("no match") - return num - - -# Run the test. When CLEAR is True we clear the global INF variable -# before comparing the before and after memory allocation traces. -# When CLEAR is False we leave INF set to reference the gdb.Inferior -# object, thus preventing the gdb.Inferior from being deallocated. -def test(clear): - global filters, inf - - # Start tracing, and take a snapshot of the current allocations. - tracemalloc.start() - snapshot1 = tracemalloc.take_snapshot() - - # Create an inferior, this triggers the new_inferior event, which - # in turn holds a reference to the new gdb.Inferior object in the - # global INF variable. - num = add_inferior() - gdb.execute("remove-inferiors %s" % num) - - # Possibly clear the global INF variable. - if clear: - inf = None - - # Now grab a second snapshot of memory allocations, and stop - # tracing memory allocations. - snapshot2 = tracemalloc.take_snapshot() - tracemalloc.stop() +import gdb_leak_detector - # Filter the snapshots; we only care about allocations originating - # from this file. - snapshot1 = snapshot1.filter_traces(filters) - snapshot2 = snapshot2.filter_traces(filters) - # Compare the snapshots, this leaves only things that were - # allocated, but not deallocated since the first snapshot. - stats = snapshot2.compare_to(snapshot1, "traceback") +class inferior_leak_detector(gdb_leak_detector.gdb_leak_detector): + def __init__(self): + super().__init__(__file__) + self.inferior = None + self.__handler = lambda event: setattr(self, "inferior", event.inferior) + gdb.events.new_inferior.connect(self.__handler) - # Total up all the deallocated things. - total = 0 - for stat in stats: - total += stat.size_diff - return total + def __del__(self): + gdb.events.new_inferior.disconnect(self.__handler) + def allocate(self): + output = gdb.execute("add-inferior", False, True) + m = re.search(r"Added inferior (\d+)", output) + if m: + num = int(m.group(1)) + else: + raise RuntimeError("no match") -# The first time we run this some global state will be allocated which -# shows up as memory that is allocated, but not released. So, run the -# test once and discard the result. -test(True) + gdb.execute("remove-inferiors %s" % num) -# Now run the test twice, the first time we clear our global reference -# to the gdb.Inferior object, which should allow Python to deallocate -# the object. The second time we hold onto the global reference, -# preventing Python from performing the deallocation. -bytes_with_clear = test(True) -bytes_without_clear = test(False) + def deallocate(self): + self.inferior = None -# The bug that used to exist in GDB was that even when we released the -# global reference the gdb.Inferior object would not be deallocated. -if bytes_with_clear > 0: - raise gdb.GdbError("memory leak when gdb.Inferior should be released") -if bytes_without_clear == 0: - raise gdb.GdbError("gdb.Inferior object is no longer allocated") -# Print a PASS message that the test script can see. -print("PASS") +inferior_leak_detector().run() diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp index ee30390..62af1a4 100644 --- a/gdb/testsuite/gdb.python/py-inferior.exp +++ b/gdb/testsuite/gdb.python/py-inferior.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2024 Free Software Foundation, Inc. +# Copyright (C) 2009-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 @@ -27,12 +27,13 @@ if { [gdb_compile_pthreads ${srcdir}/${subdir}/${srcfile} ${binfile} executable } # Start with a fresh gdb. -save_vars { env(ASAN_OPTIONS) } { +save_vars { env(ASAN_OPTIONS) env(TSAN_OPTIONS) } { # The call to gdb.selected_inferior().read_memory (0, 0xffffffffffffffff) # triggers address sanitizer. Suppress the error, leaving us with just # this warning: # WARNING: AddressSanitizer failed to allocate 0xffffffffffffffff bytes - set_sanitizer ASAN_OPTIONS allocator_may_return_null 1 + append_environment ASAN_OPTIONS allocator_may_return_null 1 + append_environment TSAN_OPTIONS allocator_may_return_null 1 clean_restart ${testfile} } diff --git a/gdb/testsuite/gdb.python/py-infthread.exp b/gdb/testsuite/gdb.python/py-infthread.exp index 9b05165..40c90b4 100644 --- a/gdb/testsuite/gdb.python/py-infthread.exp +++ b/gdb/testsuite/gdb.python/py-infthread.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2024 Free Software Foundation, Inc. +# Copyright (C) 2009-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 diff --git a/gdb/testsuite/gdb.python/py-label-symbol-value.c b/gdb/testsuite/gdb.python/py-label-symbol-value.c index 8f6258e..0e92d58 100644 --- a/gdb/testsuite/gdb.python/py-label-symbol-value.c +++ b/gdb/testsuite/gdb.python/py-label-symbol-value.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2022-2024 Free Software Foundation, Inc. + Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-label-symbol-value.exp b/gdb/testsuite/gdb.python/py-label-symbol-value.exp index a8360e6..ca534d4 100644 --- a/gdb/testsuite/gdb.python/py-label-symbol-value.exp +++ b/gdb/testsuite/gdb.python/py-label-symbol-value.exp @@ -1,4 +1,4 @@ -# Copyright 2022-2024 Free Software Foundation, Inc. +# Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-lazy-string.c b/gdb/testsuite/gdb.python/py-lazy-string.c index 326523d..7eaf7fd 100644 --- a/gdb/testsuite/gdb.python/py-lazy-string.c +++ b/gdb/testsuite/gdb.python/py-lazy-string.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2015-2024 Free Software Foundation, Inc. + Copyright 2015-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 @@ -24,6 +24,7 @@ main () const char array[] = "array"; pointer typedef_ptr = "typedef pointer"; const char *null = 0; + int not_a_string = 23; return 0; /* break here */ } diff --git a/gdb/testsuite/gdb.python/py-lazy-string.exp b/gdb/testsuite/gdb.python/py-lazy-string.exp index a00f47b..7e7272e 100644 --- a/gdb/testsuite/gdb.python/py-lazy-string.exp +++ b/gdb/testsuite/gdb.python/py-lazy-string.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2024 Free Software Foundation, Inc. +# Copyright (C) 2015-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 @@ -48,6 +48,8 @@ gdb_test "python print(null.lazy_string(length=3).value())" \ gdb_test "python print(null.lazy_string(length=-2))" \ "ValueError.*: Invalid length.*Error occurred in Python.*" \ "bad length" +gdb_py_test_silent_cmd "python nullstr = null.lazy_string()" \ + "create null lazy string with default length" 1 foreach var_spec { { "ptr" "pointer" "const char \\*" -1 } \ { "array" "array" "const char \\[6\\]" 6 } \ @@ -73,3 +75,8 @@ foreach var_spec { { "ptr" "pointer" "const char \\*" -1 } \ #gdb_test "python print ($var.lazy_string(length=0).value())" "\"\"" "empty lazy string value" } } + +gdb_py_test_silent_cmd "python nas = gdb.parse_and_eval('not_a_string')" \ + "get not_a_string" 1 +gdb_test "python print(nas.lazy_string())" \ + "Cannot make lazy string from this object" diff --git a/gdb/testsuite/gdb.python/py-linetable-empty.c b/gdb/testsuite/gdb.python/py-linetable-empty.c index 85e5588..0e6da2d 100644 --- a/gdb/testsuite/gdb.python/py-linetable-empty.c +++ b/gdb/testsuite/gdb.python/py-linetable-empty.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2024 Free Software Foundation, Inc. + Copyright 2024-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 diff --git a/gdb/testsuite/gdb.python/py-linetable-empty.exp b/gdb/testsuite/gdb.python/py-linetable-empty.exp index 2b7f8be..1e737e1 100644 --- a/gdb/testsuite/gdb.python/py-linetable-empty.exp +++ b/gdb/testsuite/gdb.python/py-linetable-empty.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2024 Free Software Foundation, Inc. +# Copyright (C) 2024-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 diff --git a/gdb/testsuite/gdb.python/py-linetable.S b/gdb/testsuite/gdb.python/py-linetable.S index 5400bc0..f17faa7 100644 --- a/gdb/testsuite/gdb.python/py-linetable.S +++ b/gdb/testsuite/gdb.python/py-linetable.S @@ -1,4 +1,4 @@ -/* Copyright (C) 2013-2024 Free Software Foundation, Inc. +/* Copyright (C) 2013-2025 Free Software Foundation, Inc. This file is part of GDB. diff --git a/gdb/testsuite/gdb.python/py-linetable.c b/gdb/testsuite/gdb.python/py-linetable.c index 68f3226..d44ffb5 100644 --- a/gdb/testsuite/gdb.python/py-linetable.c +++ b/gdb/testsuite/gdb.python/py-linetable.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2013-2024 Free Software Foundation, Inc. + Copyright 2013-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 diff --git a/gdb/testsuite/gdb.python/py-linetable.exp b/gdb/testsuite/gdb.python/py-linetable.exp index 5caa7c4..d27d16e 100644 --- a/gdb/testsuite/gdb.python/py-linetable.exp +++ b/gdb/testsuite/gdb.python/py-linetable.exp @@ -1,4 +1,4 @@ -# Copyright 2013-2024 Free Software Foundation, Inc. +# Copyright 2013-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 diff --git a/gdb/testsuite/gdb.python/py-lookup-type.exp b/gdb/testsuite/gdb.python/py-lookup-type.exp index 0b2f334..8673d56 100644 --- a/gdb/testsuite/gdb.python/py-lookup-type.exp +++ b/gdb/testsuite/gdb.python/py-lookup-type.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2024 Free Software Foundation, Inc. +# Copyright (C) 2015-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 diff --git a/gdb/testsuite/gdb.python/py-mi-cmd.exp b/gdb/testsuite/gdb.python/py-mi-cmd.exp index 28c71cd..7c630f6 100644 --- a/gdb/testsuite/gdb.python/py-mi-cmd.exp +++ b/gdb/testsuite/gdb.python/py-mi-cmd.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2024 Free Software Foundation, Inc. +# Copyright (C) 2019-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 @@ -119,13 +119,47 @@ mi_gdb_test "-pycmd dash-key" \ # With this argument the command raises a gdb.GdbError with no message # string. GDB considers this a bug in the user program, so prints a # backtrace, and a generic error message. -mi_gdb_test "-pycmd exp" \ - [multi_line ".*&\"Traceback \\(most recent call last\\):..\"" \ - "&\"\[^\r\n\]+${testfile}.py\[^\r\n\]+\"" \ - "&\"\[^\r\n\]+raise gdb.GdbError\\(\\)..\"" \ - "&\"gdb.GdbError..\"" \ - "\\^error,msg=\"Error occurred in Python\\.\""] \ - "-pycmd exp" + +set line1 \ + [string_to_regexp {Traceback (most recent call last):\n}] +set line2 \ + [string cat \ + [string_to_regexp { File \"}] \ + "\[^\r\n\]+" \ + [string_to_regexp ${testfile}.py] \ + [string_to_regexp {\", line }] \ + $decimal \ + [string_to_regexp {, in invoke\n}]] +set line3 \ + [string_to_regexp { raise gdb.GdbError()\n}] +set line4 \ + [string_to_regexp {gdb.GdbError\n}] +set errline \ + [string_to_regexp {^error,msg="Error occurred in Python."}] + +set start_line \ + [string_to_regexp {&"}] +set end_line \ + [string_to_regexp {"}] + +# With python <= 3.12. +set re1 \ + [multi_line \ + $start_line$line1$end_line \ + $start_line$line2$end_line \ + $start_line$line3$end_line \ + $start_line$line4$end_line \ + $errline] + +# With python >= 3.13. +set re2 \ + [multi_line \ + $start_line$line1$end_line \ + $start_line$line2$line3$end_line \ + $start_line$line4$end_line \ + $errline] + +mi_gdb_test "-pycmd exp" ($re1|$re2) mi_gdb_test "python pycmd2('-pycmd')" \ ".*\\^done" \ @@ -199,6 +233,21 @@ mi_gdb_test "-abc str" \ "\\^error,msg=\"Undefined MI command: abc\",code=\"undefined-command\"" \ "-abc str, but now the command is gone" +mi_gdb_test "python cmd.installed = None" \ + ".*\r\n\\^error,msg=\"Error occurred in Python: gdb\\.MICommand\\.installed must be set to a bool, not None\"" \ + "re-install the mi command using value None" + +mi_gdb_test "python cmd.installed = 1" \ + ".*\r\n\\^error,msg=\"Error occurred in Python: gdb\\.MICommand\\.installed must be set to a bool, not int\"" \ + "re-install the mi command using an int value" + +mi_gdb_test "python print(cmd.installed)" \ + [multi_line \ + ".*" \ + "~\"False\\\\n\"" \ + "\\^done"] \ + "cmd is still not installed" + mi_gdb_test "python cmd.installed = True" \ ".*\\^done" \ "re-install the mi command" diff --git a/gdb/testsuite/gdb.python/py-mi-cmd.py b/gdb/testsuite/gdb.python/py-mi-cmd.py index ad75c3b..7bfe188 100644 --- a/gdb/testsuite/gdb.python/py-mi-cmd.py +++ b/gdb/testsuite/gdb.python/py-mi-cmd.py @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2024 Free Software Foundation, Inc. +# Copyright (C) 2019-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 diff --git a/gdb/testsuite/gdb.python/py-mi-events-gdb.py b/gdb/testsuite/gdb.python/py-mi-events-gdb.py index 94ecddb..ea5f470 100644 --- a/gdb/testsuite/gdb.python/py-mi-events-gdb.py +++ b/gdb/testsuite/gdb.python/py-mi-events-gdb.py @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2024 Free Software Foundation, Inc. +# Copyright (C) 2016-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 diff --git a/gdb/testsuite/gdb.python/py-mi-events.c b/gdb/testsuite/gdb.python/py-mi-events.c index d3b727e..d5df385 100644 --- a/gdb/testsuite/gdb.python/py-mi-events.c +++ b/gdb/testsuite/gdb.python/py-mi-events.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2016-2024 Free Software Foundation, Inc. + Copyright 2016-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 diff --git a/gdb/testsuite/gdb.python/py-mi-events.exp b/gdb/testsuite/gdb.python/py-mi-events.exp index d5de247..ecdb74a 100644 --- a/gdb/testsuite/gdb.python/py-mi-events.exp +++ b/gdb/testsuite/gdb.python/py-mi-events.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 diff --git a/gdb/testsuite/gdb.python/py-mi-notify.exp b/gdb/testsuite/gdb.python/py-mi-notify.exp index f808fb2..e7b1521 100644 --- a/gdb/testsuite/gdb.python/py-mi-notify.exp +++ b/gdb/testsuite/gdb.python/py-mi-notify.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 @@ -42,8 +42,11 @@ mi_gdb_test "python gdb.notify_mi('-test-notification', None)" \ ".*=-test-notification\r\n\\^done" \ "python notification, no additional data" +set re_data1 {data1="1"} +set re_data2 {data2="2"} +set re_data1_data2 ($re_data1,$re_data2|$re_data2,$re_data1) mi_gdb_test "python gdb.notify_mi('-test-notification', \{ 'data1' : 1 , 'data2' : 2 })" \ - ".*=-test-notification,data1=\"1\",data2=\"2\"\r\n\\^done" \ + ".*=-test-notification,$re_data1_data2\r\n\\^done" \ "python notification, with additional data" mi_gdb_test "python gdb.notify_mi('-test-notification', 1)" \ diff --git a/gdb/testsuite/gdb.python/py-mi-objfile-gdb.py b/gdb/testsuite/gdb.python/py-mi-objfile-gdb.py index f5a032e..0ae75b0 100644 --- a/gdb/testsuite/gdb.python/py-mi-objfile-gdb.py +++ b/gdb/testsuite/gdb.python/py-mi-objfile-gdb.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2024 Free Software Foundation, Inc. +# Copyright (C) 2015-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 diff --git a/gdb/testsuite/gdb.python/py-mi-objfile.c b/gdb/testsuite/gdb.python/py-mi-objfile.c index 59fd2bf..829419c 100644 --- a/gdb/testsuite/gdb.python/py-mi-objfile.c +++ b/gdb/testsuite/gdb.python/py-mi-objfile.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2015-2024 Free Software Foundation, Inc. + Copyright 2015-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 diff --git a/gdb/testsuite/gdb.python/py-mi-objfile.exp b/gdb/testsuite/gdb.python/py-mi-objfile.exp index 28b4589..58ecbc5 100644 --- a/gdb/testsuite/gdb.python/py-mi-objfile.exp +++ b/gdb/testsuite/gdb.python/py-mi-objfile.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 diff --git a/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.c b/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.c index 5e46442..6bd4b65 100644 --- a/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.c +++ b/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright (C) 2018-2024 Free Software Foundation, Inc. + Copyright (C) 2018-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 diff --git a/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.exp b/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.exp index f7e072e..07cd40f 100644 --- a/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.exp +++ b/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2024 Free Software Foundation, Inc. +# Copyright (C) 2018-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 diff --git a/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.py b/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.py index 889188f..e7638db 100644 --- a/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.py +++ b/gdb/testsuite/gdb.python/py-mi-var-info-path-expression.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2024 Free Software Foundation, Inc. +# Copyright (C) 2018-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 diff --git a/gdb/testsuite/gdb.python/py-mi.exp b/gdb/testsuite/gdb.python/py-mi.exp index dad909a..7f1dffc 100644 --- a/gdb/testsuite/gdb.python/py-mi.exp +++ b/gdb/testsuite/gdb.python/py-mi.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 diff --git a/gdb/testsuite/gdb.python/py-missing-debug.c b/gdb/testsuite/gdb.python/py-missing-debug.c index ca3e5ab..df3db4d 100644 --- a/gdb/testsuite/gdb.python/py-missing-debug.c +++ b/gdb/testsuite/gdb.python/py-missing-debug.c @@ -1,6 +1,6 @@ /* This test program is part of GDB, the GNU debugger. - Copyright 2023-2024 Free Software Foundation, Inc. + Copyright 2023-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 diff --git a/gdb/testsuite/gdb.python/py-missing-debug.exp b/gdb/testsuite/gdb.python/py-missing-debug.exp index d1eef34..f028711 100644 --- a/gdb/testsuite/gdb.python/py-missing-debug.exp +++ b/gdb/testsuite/gdb.python/py-missing-debug.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 @@ -19,7 +19,8 @@ require allow_python_tests standard_testfile -if {[build_executable "failed to prepare" ${testfile} ${srcfile}]} { +if {[build_executable "failed to prepare" ${testfile} ${srcfile} \ + {debug build-id}]} { return -1 } diff --git a/gdb/testsuite/gdb.python/py-missing-debug.py b/gdb/testsuite/gdb.python/py-missing-debug.py index c1bafdd..c018d4d 100644 --- a/gdb/testsuite/gdb.python/py-missing-debug.py +++ b/gdb/testsuite/gdb.python/py-missing-debug.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/py-missing-objfile-lib.c b/gdb/testsuite/gdb.python/py-missing-objfile-lib.c new file mode 100644 index 0000000..179c329 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-missing-objfile-lib.c @@ -0,0 +1,35 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2024-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/>. */ + +struct lib_type +{ + int a; + int b; +}; + +volatile struct lib_type global_lib_var = { 0, 0 }; + +int +foo (void) +{ + int res = 0; + + res += global_lib_var.a; + res += global_lib_var.b; + + return 0; +} diff --git a/gdb/testsuite/gdb.python/py-missing-objfile.c b/gdb/testsuite/gdb.python/py-missing-objfile.c new file mode 100644 index 0000000..c5e8a63 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-missing-objfile.c @@ -0,0 +1,49 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2024-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> + +struct exec_type +{ + int a; + int b; + int c; +}; + +volatile struct exec_type global_exec_var = { 0, 0, 0 }; + +extern int foo (void); + +void +dump_core (void) +{ + abort (); +} + +int +main (void) +{ + int res = foo (); + + res += global_exec_var.a; + res += global_exec_var.b; + res += global_exec_var.c; + + dump_core (); + + return res; +} diff --git a/gdb/testsuite/gdb.python/py-missing-objfile.exp b/gdb/testsuite/gdb.python/py-missing-objfile.exp new file mode 100644 index 0000000..29bc555 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-missing-objfile.exp @@ -0,0 +1,575 @@ +# Copyright (C) 2024-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/>. + +load_lib gdb-python.exp + +require allow_python_tests +require {!is_remote host} + +standard_testfile .c -lib.c + +# Build the library. +set libname ${testfile}-lib +set libfile [standard_output_file $libname] +if { [build_executable "build shlib" $libfile $srcfile2 \ + {debug shlib build-id}] == -1} { + return +} + +# Build the executable. +set opts [list debug build-id shlib=${libfile}] +if { [build_executable "build exec" $binfile $srcfile $opts] == -1} { + return +} + +# The cc-with-gnu-debuglink board will split the debug out into the +# .debug directory. This test script relies on having GDB lookup the +# objfile and debug via the build-id, which this test sets up. Trying +# to do that, while also supporting the cc-with-gnu-debuglink board is +# just too complicated. +if {[file isdirectory [standard_output_file ".debug"]]} { + unsupported "split debug testing not supported" + return +} + +set remote_python_file \ + [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py] + +# Generate a core file. +set corefile [core_find $binfile {}] +if {$corefile == ""} { + unsupported "core file not generated" + return 0 +} + +# Create a directory named DIRNAME for use as the +# debug-file-directory. Populate the directory with links (based on +# the build-ids) to each file in the list FILES. +# +# Return the full filename of DIRNAME on the host. +proc setup_debugdir { dirname files } { + set debugdir [host_standard_output_file $dirname] + + # Create basic empty directory structure (in case FILES is empty). + remote_exec host "mkdir -p $debugdir/.build-id/" + + foreach file $files { + set build_id_filename [build_id_debug_filename_get $file ""] + + remote_exec host "mkdir -p $debugdir/[file dirname $build_id_filename]" + remote_exec host "ln -s $file $debugdir/$build_id_filename" + } + + return $debugdir +} + +# Query some symbols in the inferior to see if GDB managed to find the +# executable (when EXEC_LOADED is true) and/or the library (when LIB_LOADED +# is true). +proc check_loaded_debug { exec_loaded lib_loaded } { + set re_warn \ + [string_to_regexp \ + "Warning: the current language does not match this frame."] + set cmd "set lang c" + gdb_test_multiple $cmd "" { + -re -wrap "${cmd}(\r\n$re_warn)?" { + pass $gdb_test_name + } + } + + if { $exec_loaded } { + gdb_test "whatis global_exec_var" "^type = volatile struct exec_type" + + if { $lib_loaded } { + gdb_test "whatis global_lib_var" "^type = volatile struct lib_type" + } else { + gdb_test "whatis global_lib_var" \ + "^No symbol \"global_lib_var\" in current context\\." + } + } else { + gdb_test "whatis global_exec_var" \ + "^No symbol table is loaded\\. Use the \"file\" command\\." + gdb_test "whatis global_lib_var" \ + "^No symbol table is loaded\\. Use the \"file\" command\\." + } +} + +# Load the global corefile. The EXTRA_RE is checked for prior to GDB +# announcing that the core-file has been loaded. +proc load_core_file { {extra_re ".*"} } { + gdb_test "core-file $::corefile" \ + [multi_line \ + "$extra_re" \ + "Core was generated by \[^\r\n\]+" \ + "Program terminated with signal SIGABRT, Aborted\\." \ + "\[^\r\n\]+(?:\r\n\[^\r\n\]+)?"] \ + "loaded the core file" +} + +# Set the debug-file-directory to DIRNAME. +proc set_debug_file_dir { dirname } { + gdb_test_no_output "set debug-file-directory $dirname" \ + "set debug-file-directory" +} + +# Restart GDB and load the support Python script. +proc clean_restart_load_python {} { + clean_restart + gdb_test "source $::remote_python_file" "^Success" \ + "load python script" +} + +# For sanity, lets check that we can load the specify the executable +# and then load the core-file the easy way. +with_test_prefix "initial sanity check" { + clean_restart $binfile + load_core_file + check_loaded_debug true true +} + +# Move the executable and library into a location that the core-file +# can't possibly know about. After this the only way GDB can track +# down these files will be by looking in the debug-file-directory. +set hidden_dir [host_standard_output_file "hidden"] +set hidden_binfile "$hidden_dir/$testfile" +set hidden_libfile "$hidden_dir/$libname" +remote_exec host "mkdir -p $hidden_dir" +remote_exec host "mv $libfile $hidden_libfile" +remote_exec host "mv $binfile $hidden_binfile" + +# If using the fission-dwp board then we'll have .dwp files that also +# need to be moved. +if {[remote_file host exists ${libfile}.dwp]} { + remote_exec host "mv ${libfile}.dwp ${hidden_libfile}.dwp" +} + +if {[remote_file host exists ${binfile}.dwp]} { + remote_exec host "mv ${binfile}.dwp ${hidden_binfile}.dwp" +} + +with_test_prefix "no objfiles, no debug-file-directory" { + clean_restart + load_core_file + check_loaded_debug false false +} + +# Setup some debug-file-directories. +set debugdir_no_lib \ + [setup_debugdir "debugdir.no-lib" [list "$hidden_binfile"]] +set debugdir_empty \ + [setup_debugdir "debugdir.empty" {}] +set debugdir_all \ + [setup_debugdir "debugdir.all" [list "$hidden_libfile" \ + "$hidden_binfile"]] + +with_test_prefix "no objfiles available" { + # Another sanity check that GDB can find the files via the + # debug-file-directory. + clean_restart + set_debug_file_dir $debugdir_empty + load_core_file + check_loaded_debug false false +} + +with_test_prefix "all objfiles available" { + # Another sanity check that GDB can find the files via the + # debug-file-directory. + set_debug_file_dir $debugdir_all + load_core_file + check_loaded_debug true true +} + +with_test_prefix "lib objfile missing" { + # Another sanity check that GDB can find the files via the + # debug-file-directory. + set_debug_file_dir $debugdir_no_lib + load_core_file + check_loaded_debug true false +} + +with_test_prefix "all objfiles missing, handler returns None" { + clean_restart_load_python + gdb_test_no_output \ + "python gdb.missing_objfile.register_handler(None, handler_obj)" \ + "register initial handler" + load_core_file + + check_loaded_debug false false + + # The handler should be called three times, once for the + # mapped-file, once for the core-file's exec, and once for the + # shared library. + gdb_test "python print(handler_obj.call_count)" "^3" \ + "check handler was called three times" +} + +with_test_prefix "lib objfile missing, handler returns None" { + # Reset handler_obj. + gdb_test_no_output "python handler_obj.set_mode(Mode.RETURN_NONE)" + + set_debug_file_dir $debugdir_no_lib + load_core_file + check_loaded_debug true false + + # The handler will be called twice, once when GDB tries to + # load the shared library during the memory-mapped file phase, + # then again for the shared library loading. + gdb_test "python print(handler_obj.call_count)" "^2" \ + "check handler was called three times" +} + +with_test_prefix "handler installs lib objfile" { + set build_id_filename [build_id_debug_filename_get \ + $hidden_libfile ""] + remote_exec host \ + "mkdir -p $debugdir_no_lib/[file dirname $build_id_filename]" + gdb_test_no_output "python handler_obj.set_mode(Mode.RETURN_TRUE, \ + \"$hidden_libfile\", \"$debugdir_no_lib/$build_id_filename\")" \ + "configure handler" + + load_core_file + check_loaded_debug true true + + # Cleanup so the test can be reproduced again later if needed. + remote_exec host "rm $debugdir_no_lib/$build_id_filename" +} + +with_test_prefix "handler points to lib objfile" { + set build_id_filename [build_id_debug_filename_get \ + $hidden_libfile ""] + remote_exec host \ + "mkdir -p $debugdir_no_lib/[file dirname $build_id_filename]" + gdb_test_no_output "python handler_obj.set_mode(Mode.RETURN_STRING, \ + \"$hidden_libfile\")" \ + "configure handler" + + load_core_file + check_loaded_debug true true + + # Cleanup so the test can be reproduced again later if needed. + remote_exec host "rm $debugdir_no_lib/$build_id_filename" + + # The handler will only have been called once when loading the + # memory-mapped file. GDB is smart enough to reuse the previously + # discovered BFD object as the shared library. + gdb_test "python print(handler_obj.call_count)" "^1" \ + "check good handler hasn't been called again" + + # Validate the filename and build-id arguments passed to the handler. + set expected_buildid [get_build_id $hidden_libfile] + gdb_test "python print(handler_last_buildid)" "^$expected_buildid" + gdb_test "python print(handler_last_filename)" \ + "^[string_to_regexp $libfile]" +} + +# Register another global handler, this one raises an exception. Reload the +# core-file, the bad handler should be invoked first, which raises an +# excetption, at which point GDB should skip further Python handlers. +with_test_prefix "handler raises an exception" { + gdb_test_no_output \ + "python gdb.missing_objfile.register_handler(None, rhandler)" + + foreach_with_prefix exception_type {gdb.GdbError TypeError} { + gdb_test_no_output \ + "python rhandler.exception_type = $exception_type" + + # Load the core file. We expect the exception message to appear at + # least once in the output. + set re [string_to_regexp \ + "Python Exception <class '$exception_type'>: message"] + load_core_file "${re}.*" + + # Our original handler is still registered, but should not have been + # called again (as the exception occurs first). + gdb_test "python print(handler_obj.call_count)" "^1" \ + "check good handler hasn't been called again" + } +} + +# Re-start GDB. +clean_restart_load_python + +# Attempt to register a missing-debug-handler with NAME. The expectation is +# that this should fail as NAME contains some invalid characters. +proc check_bad_name {name} { + set name_re [string_to_regexp $name] + set re \ + [multi_line \ + "ValueError.*: invalid character '.' in handler name: $name_re" \ + "Error occurred in Python.*"] + + gdb_test "python register(\"$name\")" $re \ + "check that '$name' is not accepted" +} + +# We don't attempt to be exhaustive here, just check a few random examples +# of invalid names. +check_bad_name "!! Bad Name" +check_bad_name "Bad Name" +check_bad_name "(Bad Name)" +check_bad_name "Bad \[Name\]" +check_bad_name "Bad,Name" +check_bad_name "Bad;Name" + +# Check that there are no handlers registered. +gdb_test_no_output "info missing-objfile-handlers" \ + "check no handlers are registered" + +# Grab the current program space object, used for registering handler later. +gdb_test_no_output "python pspace = gdb.selected_inferior().progspace" + +# Now register some handlers. +foreach hspec {{\"Foo\" None} + {\"-bar\" None} + {\"baz-\" pspace} + {\"abc-def\" pspace}} { + lassign $hspec name locus + gdb_test "python register($name, $locus)" +} + +with_test_prefix "all handlers enabled" { + gdb_test "info missing-objfile-handlers" \ + [multi_line \ + "Current Progspace:" \ + " abc-def" \ + " baz-" \ + "Global:" \ + " -bar" \ + " Foo"] + + set_debug_file_dir $debugdir_no_lib + load_core_file + + # As we perform two look ups, first for the mapped-file then for the + # shared library, each handler will be called twice. + gdb_test "python print(handler_call_log)" \ + [string_to_regexp {['abc-def', 'baz-', '-bar', 'Foo', 'abc-def', 'baz-', '-bar', 'Foo']}] + gdb_test_no_output "python handler_call_log = \[\]" \ + "reset call log" +} + +with_test_prefix "disable 'baz-'" { + gdb_test "disable missing-objfile-handler progspace baz-" \ + "^1 missing objfile handler disabled" + + gdb_test "info missing-objfile-handlers" \ + [multi_line \ + "Progspace \[^\r\n\]+:" \ + " abc-def" \ + " baz- \\\[disabled\\\]" \ + "Global:" \ + " -bar" \ + " Foo"] + + load_core_file + gdb_test "python print(handler_call_log)" \ + [string_to_regexp {['abc-def', '-bar', 'Foo', 'abc-def', '-bar', 'Foo']}] + gdb_test_no_output "python handler_call_log = \[\]" \ + "reset call log" +} + +with_test_prefix "disable 'Foo'" { + gdb_test "disable missing-objfile-handler .* Foo" \ + "^1 missing objfile handler disabled" + + gdb_test "info missing-objfile-handlers" \ + [multi_line \ + "Progspace \[^\r\n\]+:" \ + " abc-def" \ + " baz- \\\[disabled\\\]" \ + "Global:" \ + " -bar" \ + " Foo \\\[disabled\\\]"] + + load_core_file + gdb_test "python print(handler_call_log)" \ + [string_to_regexp {['abc-def', '-bar', 'abc-def', '-bar']}] + gdb_test_no_output "python handler_call_log = \[\]" \ + "reset call log" +} + +with_test_prefix "disable everything" { + gdb_test "disable missing-objfile-handler .* .*" \ + "^2 missing objfile handlers disabled" + + gdb_test "info missing-objfile-handlers" \ + [multi_line \ + "Progspace \[^\r\n\]+:" \ + " abc-def \\\[disabled\\\]" \ + " baz- \\\[disabled\\\]" \ + "Global:" \ + " -bar \\\[disabled\\\]" \ + " Foo \\\[disabled\\\]"] + + load_core_file + gdb_test "python print(handler_call_log)" \ + [string_to_regexp {[]}] + gdb_test_no_output "python handler_call_log = \[\]" \ + "reset call log" +} + +with_test_prefix "enable 'abc-def'" { + set re [string_to_regexp $hidden_binfile] + + gdb_test "enable missing-objfile-handler \"$re\" abc-def" \ + "^1 missing objfile handler enabled" \ + "enable missing-objfile-handler" + + gdb_test "info missing-objfile-handlers" \ + [multi_line \ + "Progspace \[^\r\n\]+:" \ + " abc-def" \ + " baz- \\\[disabled\\\]" \ + "Global:" \ + " -bar \\\[disabled\\\]" \ + " Foo \\\[disabled\\\]"] + + load_core_file + gdb_test "python print(handler_call_log)" \ + [string_to_regexp {['abc-def', 'abc-def']}] + gdb_test_no_output "python handler_call_log = \[\]" \ + "reset call log" +} + +with_test_prefix "enable global handlers" { + gdb_test "enable missing-objfile-handler global" \ + "^2 missing objfile handlers enabled" + + gdb_test "info missing-objfile-handlers" \ + [multi_line \ + "Progspace \[^\r\n\]+:" \ + " abc-def" \ + " baz- \\\[disabled\\\]" \ + "Global:" \ + " -bar" \ + " Foo"] + + load_core_file + gdb_test "python print(handler_call_log)" \ + [string_to_regexp {['abc-def', '-bar', 'Foo', 'abc-def', '-bar', 'Foo']}] + gdb_test_no_output "python handler_call_log = \[\]" \ + "reset call log" +} + +# Add handler_obj to the global handler list, and configure it to +# return False. We should call all of the program space specific +# handlers (which return None), and then call handler_obj from the +# global list, which returns False, at which point we shouldn't call +# anyone else. +with_test_prefix "return False handler in global list" { + gdb_test "enable missing-objfile-handler progspace" \ + "^1 missing objfile handler enabled" + + gdb_test_no_output \ + "python gdb.missing_objfile.register_handler(None, handler_obj)" \ + "register handler_obj in global list" + + gdb_test "info missing-objfile-handlers" \ + [multi_line \ + "Progspace \[^\r\n\]+:" \ + " abc-def" \ + " baz-" \ + "Global:" \ + " handler" \ + " -bar" \ + " Foo"] + + gdb_test_no_output "python handler_obj.set_mode(Mode.RETURN_FALSE)" \ + "confirgure handler" + + load_core_file + gdb_test "python print(handler_call_log)" \ + [string_to_regexp {['abc-def', 'baz-', 'handler', 'abc-def', 'baz-', 'handler']}] + gdb_test_no_output "python handler_call_log = \[\]" \ + "reset call log" +} + +# Now add handler_obj to the current program space's handler list. We +# use the same handler object here, that's fine. We should only see a +# call to the first handler object in the call log. +with_test_prefix "return False handler in progspace list" { + gdb_test_no_output \ + "python gdb.missing_objfile.register_handler(pspace, handler_obj)" \ + "register handler_obj in progspace list" + + gdb_test "info missing-objfile-handlers" \ + [multi_line \ + "Progspace \[^\r\n\]+:" \ + " handler" \ + " abc-def" \ + " baz-" \ + "Global:" \ + " handler" \ + " -bar" \ + " Foo"] + + load_core_file + gdb_test "python print(handler_call_log)" \ + [string_to_regexp {['handler', 'handler']}] + gdb_test_no_output "python handler_call_log = \[\]" \ + "reset call log" +} + +with_test_prefix "check handler replacement" { + # First, check we can have the same name appear in both program + # space and global lists without giving an error. + gdb_test_no_output "python register(\"Foo\", pspace)" + + gdb_test "info missing-objfile-handlers" \ + [multi_line \ + "Progspace \[^\r\n\]+:" \ + " Foo" \ + " handler" \ + " abc-def" \ + " baz-" \ + "Global:" \ + " handler" \ + " -bar" \ + " Foo"] + + # Now check that we get an error if we try to add a handler with + # the same name. + gdb_test "python gdb.missing_objfile.register_handler(pspace, log_handler(\"Foo\"))" \ + [multi_line \ + "RuntimeError.*: Handler Foo already exists\\." \ + "Error occurred in Python.*"] + + gdb_test "python gdb.missing_objfile.register_handler(handler=log_handler(\"Foo\"), locus=pspace)" \ + [multi_line \ + "RuntimeError.*: Handler Foo already exists\\." \ + "Error occurred in Python.*"] + + # And now try again, but this time with 'replace=True', we + # shouldn't get an error in this case. + gdb_test_no_output \ + "python gdb.missing_objfile.register_handler(pspace, log_handler(\"Foo\"), replace=True)" + + gdb_test_no_output \ + "python gdb.missing_objfile.register_handler(handler=log_handler(\"Foo\"), locus=None, replace=True)" + + # Now disable a handler and check we still need to use 'replace=True'. + gdb_test "disable missing-objfile-handler progspace Foo" \ + "^1 missing objfile handler disabled" + + gdb_test "python gdb.missing_objfile.register_handler(pspace, log_handler(\"Foo\"))" \ + [multi_line \ + "RuntimeError.*: Handler Foo already exists\\." \ + "Error occurred in Python.*"] \ + "still get an error when handler is disabled" + + gdb_test_no_output \ + "python gdb.missing_objfile.register_handler(pspace, log_handler(\"Foo\"), replace=True)" \ + "can replace a disabled handler" +} diff --git a/gdb/testsuite/gdb.python/py-missing-objfile.py b/gdb/testsuite/gdb.python/py-missing-objfile.py new file mode 100644 index 0000000..5efc36a --- /dev/null +++ b/gdb/testsuite/gdb.python/py-missing-objfile.py @@ -0,0 +1,167 @@ +# Copyright (C) 2024-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/>. + +import os +import shutil +from enum import Enum + +import gdb +from gdb.missing_objfile import MissingObjfileHandler + +# A global log that is filled in by instances of the LOG_HANDLER class +# when they are called. +handler_call_log = [] + +# A global holding a string, the build-id of the last missing objfile +# which triggered the 'handler' class below. This is set in the +# __call__ method of the 'handler' class and then checked from the +# expect script. +handler_last_buildid = None + + +# A global holding a string, the filename of the last missing objfile +# which triggered the 'handler' class below. This is set in the +# __call__ method of the 'handler' class and then checked from the +# expect script. +handler_last_filename = None + + +# A helper function that makes some assertions about the arguments +# passed to a MissingObjfileHandler.__call__() method. +def check_args(pspace, buildid, filename): + assert type(filename) == str + assert filename != "" + assert type(pspace) == gdb.Progspace + assert type(buildid) == str + assert buildid != "" + + +# Enum used to configure the 'handler' class from the test script. +class Mode(Enum): + RETURN_NONE = 0 + RETURN_TRUE = 1 + RETURN_FALSE = 2 + RETURN_STRING = 3 + + +# A missing objfile handler which can be configured to return each of +# the different possible return types. +class handler(MissingObjfileHandler): + def __init__(self): + super().__init__("handler") + self._call_count = 0 + self._mode = Mode.RETURN_NONE + + def __call__(self, pspace, buildid, filename): + global handler_call_log, handler_last_buildid, handler_last_filename + check_args(pspace, buildid, filename) + handler_call_log.append(self.name) + handler_last_buildid = buildid + handler_last_filename = filename + self._call_count += 1 + if self._mode == Mode.RETURN_NONE: + return None + + if self._mode == Mode.RETURN_TRUE: + shutil.copy(self._src, self._dest) + + # If we're using the fission-dwp board then there will + # also be a .dwp file that needs to be copied. + dwp_src = self._src + ".dwp" + if os.path.exists(dwp_src): + dwp_dest = self._dest + ".dwp" + shutil.copy(dwp_src, dwp_dest) + + return True + + if self._mode == Mode.RETURN_FALSE: + return False + + if self._mode == Mode.RETURN_STRING: + return self._dest + + assert False + + @property + def call_count(self): + """Return a count, the number of calls to __call__ since the last + call to set_mode. + """ + return self._call_count + + def set_mode(self, mode, *args): + self._call_count = 0 + self._mode = mode + + if mode == Mode.RETURN_NONE: + assert len(args) == 0 + return + + if mode == Mode.RETURN_TRUE: + assert len(args) == 2 + self._src = args[0] + self._dest = args[1] + return + + if mode == Mode.RETURN_FALSE: + assert len(args) == 0 + return + + if mode == Mode.RETURN_STRING: + assert len(args) == 1 + self._dest = args[0] + return + + assert False + + +# A missing objfile handler which raises an exception. The type of +# exception to be raised is configured from the test script. +class exception_handler(MissingObjfileHandler): + def __init__(self): + super().__init__("exception_handler") + self.exception_type = None + + def __call__(self, pspace, buildid, filename): + global handler_call_log + check_args(pspace, buildid, filename) + handler_call_log.append(self.name) + assert self.exception_type is not None + raise self.exception_type("message") + + +# A very simple logging missing objfile handler. Always returns None +# so that GDB will try any other registered handlers, but first logs +# the name of this handler into the global HANDLER_CALL_LOG, which can +# then be checked from the test script. +class log_handler(MissingObjfileHandler): + def __call__(self, pspace, buildid, filename): + global handler_call_log + check_args(pspace, buildid, filename) + handler_call_log.append(self.name) + return None + + +# A basic helper function, this keeps lines shorter in the TCL script. +def register(name, locus=None): + gdb.missing_objfile.register_handler(locus, log_handler(name)) + + +# Create instances of the handlers, but don't install any. We install +# these as needed from the TCL script. +rhandler = exception_handler() +handler_obj = handler() + +print("Success") diff --git a/gdb/testsuite/gdb.python/py-nested-maps.c b/gdb/testsuite/gdb.python/py-nested-maps.c index 6cd78f7..a9480a3 100644 --- a/gdb/testsuite/gdb.python/py-nested-maps.c +++ b/gdb/testsuite/gdb.python/py-nested-maps.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2019-2024 Free Software Foundation, Inc. + Copyright 2019-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 diff --git a/gdb/testsuite/gdb.python/py-nested-maps.exp b/gdb/testsuite/gdb.python/py-nested-maps.exp index 752b3a3..884b259 100644 --- a/gdb/testsuite/gdb.python/py-nested-maps.exp +++ b/gdb/testsuite/gdb.python/py-nested-maps.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2024 Free Software Foundation, Inc. +# Copyright (C) 2019-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 diff --git a/gdb/testsuite/gdb.python/py-nested-maps.py b/gdb/testsuite/gdb.python/py-nested-maps.py index ac04bbf..8d65fd8 100644 --- a/gdb/testsuite/gdb.python/py-nested-maps.py +++ b/gdb/testsuite/gdb.python/py-nested-maps.py @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2024 Free Software Foundation, Inc. +# Copyright (C) 2019-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 diff --git a/gdb/testsuite/gdb.python/py-objfile-script-gdb.py b/gdb/testsuite/gdb.python/py-objfile-script-gdb.py index 17a4217..8666074 100644 --- a/gdb/testsuite/gdb.python/py-objfile-script-gdb.py +++ b/gdb/testsuite/gdb.python/py-objfile-script-gdb.py @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2024 Free Software Foundation, Inc. +# Copyright (C) 2011-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 diff --git a/gdb/testsuite/gdb.python/py-objfile-script.c b/gdb/testsuite/gdb.python/py-objfile-script.c index ad9e421..1ce505d 100644 --- a/gdb/testsuite/gdb.python/py-objfile-script.c +++ b/gdb/testsuite/gdb.python/py-objfile-script.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2011-2024 Free Software Foundation, Inc. + Copyright 2011-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 diff --git a/gdb/testsuite/gdb.python/py-objfile-script.exp b/gdb/testsuite/gdb.python/py-objfile-script.exp index c8cd6ee..1a3d394 100644 --- a/gdb/testsuite/gdb.python/py-objfile-script.exp +++ b/gdb/testsuite/gdb.python/py-objfile-script.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2024 Free Software Foundation, Inc. +# Copyright (C) 2011-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 diff --git a/gdb/testsuite/gdb.python/py-objfile.c b/gdb/testsuite/gdb.python/py-objfile.c index 1c38ff9..d721e0c 100644 --- a/gdb/testsuite/gdb.python/py-objfile.c +++ b/gdb/testsuite/gdb.python/py-objfile.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2011-2024 Free Software Foundation, Inc. + Copyright 2011-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 @@ -19,7 +19,7 @@ int global_var = 42; static int __attribute__ ((used)) static_var = 50; int -main () +main (void) { int some_var = 0; return 0; diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp index 2f5b775..8d11028 100644 --- a/gdb/testsuite/gdb.python/py-objfile.exp +++ b/gdb/testsuite/gdb.python/py-objfile.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2024 Free Software Foundation, Inc. +# Copyright (C) 2011-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 @@ -144,7 +144,8 @@ gdb_test "python print (sep_objfile.owner.filename)" "${testfile}2" \ gdb_test "python print (sep_objfile.owner.username)" "${testfile}2" \ "Test user-name of owner of separate debug file" -gdb_test "p main" "= {int \\(\\)} $hex <main>" \ +set re_prototype [string_to_regexp "int (void)"] +gdb_test "p main" "= {$re_prototype} $hex <main>" \ "print main with debug info" # Separate debug files are not findable. diff --git a/gdb/testsuite/gdb.python/py-parameter-prefix.exp b/gdb/testsuite/gdb.python/py-parameter-prefix.exp new file mode 100644 index 0000000..eb09fe7 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-parameter-prefix.exp @@ -0,0 +1,382 @@ +# 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/>. + +# This file is part of the GDB testsuite. It tests +# gdb.ParameterPrefix. See each of the test procs for a full +# description of what is being tested. + +load_lib gdb-python.exp + +require allow_python_tests + +clean_restart + +# Helper proc to generate the output of 'show PREFIX' commands for the +# case where the prefix command doesn't handle unknown sub-commands. +# In this case GDB will list the value of every sub-command under +# PREFIX. +proc make_show_prefix_re { prefix } { + return "$prefix param-1:\\s+The current value of '$prefix param-1' is \"off\"\\." +} + +# Helper proc to generate the help text that describes all of the sub +# commands under PREFIX. The MODE is either 'set' or 'show'. This +# output will appear for 'help MODE PREFIX' and also for 'set PREFIX'. +proc make_sub_cmd_help_re { mode prefix } { + if { $mode == "set" } { + set word "Set" + } else { + set word "Show" + } + + return \ + [multi_line \ + "List of \"$mode $prefix\" subcommands:" \ + "" \ + "$mode $prefix param-1 -- $word the current value of '$prefix param-1'\\." \ + "" \ + "Type \"help $mode $prefix\" followed by subcommand name for full documentation\\." \ + "Type \"apropos word\" to search for commands related to \"word\"\\." \ + "Type \"apropos -v word\" for full documentation of commands related to \"word\"\\." \ + "Command name abbreviations are allowed if unambiguous\\."] +} + +# Helper proc to generate the output of 'help MODE PREFIX', where MODE +# will be either 'set' or 'show'. The HELP_TEXT is the expected help +# text for this prefix command, this should not be a regexp, as this +# proc converts the text to a regexp. +# +# Return a single regexp which should match the output. +proc make_help_re { mode prefix help_text } { + set help_re [string_to_regexp $help_text] + + return \ + [multi_line \ + "$help_re" \ + "" \ + [make_sub_cmd_help_re $mode $prefix]] +} + +# Create gdb.ParameterPrefix without using a sub-class, both with, and +# without a doc string. For the doc string case, test single line, +# and multi-line doc strings. +proc_with_prefix test_basic_usage {} { + gdb_test_multiline "some basic ParameterPrefix usage" \ + "python" "" \ + "gdb.ParameterPrefix('prefix-1', gdb.COMMAND_NONE)" "" \ + "gdb.Parameter('prefix-1 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "gdb.Parameter('prefix-1 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "gdb.ParameterPrefix('prefix-2', gdb.COMMAND_NONE," "" \ + " \"\"\"This is prefix-2 help string.\"\"\")" "" \ + "gdb.Parameter('prefix-2 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "gdb.ParameterPrefix('prefix-3', gdb.COMMAND_NONE," "" \ + " \"\"\"This is prefix-3 help string." "" \ + " " "" \ + " This help text spans multiple lines.\"\"\")" "" \ + "gdb.Parameter('prefix-3 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "end" + + foreach mode { "set" "show" } { + gdb_test "help $mode prefix-1" \ + [make_help_re $mode "prefix-1" \ + "This command is not documented."] + + gdb_test "help $mode prefix-2" \ + [make_help_re $mode "prefix-2" \ + "This is prefix-2 help string."] + + gdb_test "help $mode prefix-3" \ + [make_help_re $mode "prefix-3" \ + [multi_line \ + "This is prefix-3 help string." \ + "" \ + "This help text spans multiple lines."]] + + foreach prefix { prefix-1 prefix-2 prefix-3 } { + gdb_test "$mode $prefix xxx" \ + "^Undefined $mode $prefix command: \"xxx\"\\. Try \"help $mode $prefix\"\\." + } + } + + foreach prefix { prefix-1 prefix-2 prefix-3 } { + gdb_test "set $prefix" \ + [make_sub_cmd_help_re "set" $prefix] + + gdb_test "show $prefix" \ + [make_show_prefix_re $prefix] + } +} + +# Create a sub-class of gdb.ParameterPrefix, but don't do anything +# particularly interesting. Again test the with and without +# documentation string cases. +proc_with_prefix test_simple_sub_class {} { + gdb_test_multiline "some basic ParameterPrefix usage" \ + "python" "" \ + "class BasicParamPrefix(gdb.ParameterPrefix):" "" \ + " def __init__(self, name):" "" \ + " super().__init__(name, gdb.COMMAND_NONE)" "" \ + "BasicParamPrefix('prefix-4')" "" \ + "gdb.Parameter('prefix-4 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "class BasicParamPrefixWithSingleLineDoc(gdb.ParameterPrefix):" "" \ + " \"\"\"This is a single line doc string.\"\"\"" "" \ + " def __init__(self, name):" "" \ + " super().__init__(name, gdb.COMMAND_NONE)" "" \ + "BasicParamPrefixWithSingleLineDoc('prefix-5')" "" \ + "gdb.Parameter('prefix-5 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "class BasicParamPrefixWithMultiLineDoc(gdb.ParameterPrefix):" "" \ + " \"\"\"This is a multi line doc string." "" \ + " " "" \ + " The rest of the doc string is here.\"\"\"" "" \ + " def __init__(self, name):" "" \ + " super().__init__(name, gdb.COMMAND_NONE)" "" \ + "BasicParamPrefixWithMultiLineDoc('prefix-6')" "" \ + "gdb.Parameter('prefix-6 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "class BasicParamPrefixWithDocParameter(gdb.ParameterPrefix):" "" \ + " \"\"\"This is an unsused doc string.\"\"\"" "" \ + " def __init__(self, name, doc):" "" \ + " super().__init__(name, gdb.COMMAND_NONE, doc)" "" \ + "BasicParamPrefixWithDocParameter('prefix-7'," "" \ + " \"\"\"The doc string text is here.\"\"\")" "" \ + "gdb.Parameter('prefix-7 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "end" + + foreach mode { "set" "show" } { + gdb_test "help $mode prefix-4" \ + [make_help_re $mode "prefix-4" \ + "This command is not documented."] + + gdb_test "help $mode prefix-5" \ + [make_help_re $mode "prefix-5" \ + "This is a single line doc string."] + + gdb_test "help $mode prefix-6" \ + [make_help_re $mode "prefix-6" \ + [multi_line \ + "This is a multi line doc string." \ + "" \ + "The rest of the doc string is here."]] + + gdb_test "help $mode prefix-7" \ + [make_help_re $mode "prefix-7" \ + "The doc string text is here."] + + foreach prefix { prefix-4 prefix-5 prefix-6 prefix-7 } { + gdb_test "$mode $prefix xxx" \ + "^Undefined $mode $prefix command: \"xxx\"\\. Try \"help $mode $prefix\"\\." + } + } + + foreach prefix { prefix-4 prefix-5 prefix-6 prefix-7 } { + gdb_test "set $prefix" \ + [make_sub_cmd_help_re "set" $prefix] + + gdb_test "show $prefix" \ + [make_show_prefix_re $prefix] + } +} + +# Create a sub-class of gdb.ParameterPrefix, and make use of +# 'invoke_set' and 'invoke_show'. Test that the invoke method is +# executed when expected, and that, by default, these invoke methods +# repeat when the user issues an empty command. +proc_with_prefix test_prefix_with_invoke {} { + gdb_test_multiline "ParameterPrefix with invoke_set" \ + "python" "" \ + "class PrefixWithInvokeSet(gdb.ParameterPrefix):" "" \ + " def __init__(self, name):" "" \ + " super().__init__(name, gdb.COMMAND_NONE)" "" \ + " def invoke_set(self, args, from_tty):" "" \ + " print(f\"invoke_set (a): \\\"{args}\\\" {from_tty}\")" "" \ + "PrefixWithInvokeSet('prefix-8')" "" \ + "gdb.Parameter('prefix-8 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "class PrefixWithInvokeShow(gdb.ParameterPrefix):" "" \ + " def __init__(self, name):" "" \ + " super().__init__(name, gdb.COMMAND_NONE)" "" \ + " def invoke_show(self, args, from_tty):" "" \ + " print(f\"invoke_show (b): \\\"{args}\\\" {from_tty}\")" "" \ + "PrefixWithInvokeShow('prefix-9')" "" \ + "gdb.Parameter('prefix-9 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "class PrefixWithBothInvoke(gdb.ParameterPrefix):" "" \ + " def __init__(self, name):" "" \ + " super().__init__(name, gdb.COMMAND_NONE)" "" \ + " def invoke_set(self, args, from_tty):" "" \ + " print(f\"invoke_set (c): \\\"{args}\\\" {from_tty}\")" "" \ + " def invoke_show(self, args, from_tty):" "" \ + " print(f\"invoke_show (d): \\\"{args}\\\" {from_tty}\")" "" \ + "PrefixWithBothInvoke('prefix-10')" "" \ + "gdb.Parameter('prefix-10 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "end" + + gdb_test "set prefix-8 xxx yyy" \ + "^invoke_set \\(a\\): \"xxx yyy\" True" + + send_gdb "\n" + gdb_test "" "^\r\ninvoke_set \\(a\\): \"xxx yyy\" True" \ + "repeat set prefix-8 xxx yyy" + + gdb_test "show prefix-8 xxx yyy" \ + "^Undefined show prefix-8 command: \"xxx yyy\"\\. Try \"help show prefix-8\"\\." + + gdb_test "set prefix-9 xxx yyy" \ + "^Undefined set prefix-9 command: \"xxx yyy\"\\. Try \"help set prefix-9\"\\." + + gdb_test "show prefix-9 xxx yyy" \ + "^invoke_show \\(b\\): \"xxx yyy\" True" + + send_gdb "\n" + gdb_test "" "^\r\ninvoke_show \\(b\\): \"xxx yyy\" True" \ + "repeat show prefix-9 xxx yyy" + + gdb_test "set prefix-10 xxx yyy" \ + "^invoke_set \\(c\\): \"xxx yyy\" True" + + send_gdb "\n" + gdb_test "" "^\r\ninvoke_set \\(c\\): \"xxx yyy\" True" \ + "repeat set prefix-10 xxx yyy" + + gdb_test "show prefix-10 xxx yyy" \ + "^invoke_show \\(d\\): \"xxx yyy\" True" + + send_gdb "\n" + gdb_test "" "^\r\ninvoke_show \\(d\\): \"xxx yyy\" True" \ + "repeat show prefix-10 xxx yyy" + + gdb_test "set prefix-8" \ + "^invoke_set \\(a\\): \"\" True" + + gdb_test "show prefix-8" \ + [make_show_prefix_re "prefix-8"] + + gdb_test "set prefix-9" \ + [make_sub_cmd_help_re "set" "prefix-9"] + + gdb_test "show prefix-9" \ + "^invoke_show \\(b\\): \"\" True" + + gdb_test "set prefix-10" \ + "^invoke_set \\(c\\): \"\" True" + + gdb_test "show prefix-10" \ + "^invoke_show \\(d\\): \"\" True" +} + +# Create ParameterPrefix sub-classes that make use of the +# dont_repeat() method. Check that the relevant set/show invoke +# callback doesn't repeat when an empty command is used. +proc_with_prefix test_dont_repeat {} { + gdb_test_multiline "ParameterPrefix with invoke_set and dont_repeat" \ + "python" "" \ + "class PrefixWithInvokeAndDoNotRepeatSet(gdb.ParameterPrefix):" "" \ + " def __init__(self, name):" "" \ + " super().__init__(name, gdb.COMMAND_NONE)" "" \ + " def invoke_set(self, args, from_tty):" "" \ + " self.dont_repeat()" "" \ + " print(f\"invoke_set: \\\"{args}\\\" {from_tty}\")" "" \ + " def invoke_show(self, args, from_tty):" "" \ + " print(f\"invoke_show: \\\"{args}\\\" {from_tty}\")" "" \ + "PrefixWithInvokeAndDoNotRepeatSet('prefix-11')" "" \ + "gdb.Parameter('prefix-11 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "class PrefixWithInvokeAndDoNotRepeatShow(gdb.ParameterPrefix):" "" \ + " def __init__(self, name):" "" \ + " super().__init__(name, gdb.COMMAND_NONE)" "" \ + " def invoke_set(self, args, from_tty):" "" \ + " print(f\"invoke_set: \\\"{args}\\\" {from_tty}\")" "" \ + " def invoke_show(self, args, from_tty):" "" \ + " self.dont_repeat()" "" \ + " print(f\"invoke_show: \\\"{args}\\\" {from_tty}\")" "" \ + "PrefixWithInvokeAndDoNotRepeatShow('prefix-12')" "" \ + "gdb.Parameter('prefix-12 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "end" + + gdb_test "set prefix-11 xxx yyy" \ + "^invoke_set: \"xxx yyy\" True" + + send_gdb "\n" + gdb_test "" "^" \ + "repeat set prefix-11 xxx yyy" + + gdb_test "show prefix-11 xxx yyy" \ + "^invoke_show: \"xxx yyy\" True" + + send_gdb "\n" + gdb_test "" "invoke_show: \"xxx yyy\" True" \ + "repeat show prefix-11 xxx yyy" + + gdb_test "set prefix-12 xxx yyy" \ + "^invoke_set: \"xxx yyy\" True" + + send_gdb "\n" + gdb_test "" "^\r\ninvoke_set: \"xxx yyy\" True" \ + "repeat set prefix-12 xxx yyy" + + gdb_test "show prefix-12 xxx yyy" \ + "^invoke_show: \"xxx yyy\" True" + + send_gdb "\n" + gdb_test "" "^" \ + "repeat show prefix-12 xxx yyy" +} + +# Create a parameter prefixm, and immediately add another prefix under +# the first. The important thing here is that the second prefix is +# created into an otherwise empty prefix as this triggered a bug at +# one point. +proc_with_prefix test_nested {} { + gdb_test_multiline "Create nested parameter prefixes" \ + "python" "" \ + "gdb.ParameterPrefix('prefix-13', gdb.COMMAND_NONE)" "" \ + "gdb.ParameterPrefix('prefix-13 prefix-14', gdb.COMMAND_NONE)" "" \ + "gdb.Parameter('prefix-13 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "gdb.Parameter('prefix-13 param-2', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "gdb.Parameter('prefix-13 prefix-14 param-3', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "gdb.Parameter('prefix-13 prefix-14 param-4', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "end" "" + + gdb_test "show prefix-13 prefix-14" \ + [multi_line \ + "^prefix-13 prefix-14 param-3: The current value of 'prefix-13 prefix-14 param-3' is \"off\"\\." \ + "prefix-13 prefix-14 param-4: The current value of 'prefix-13 prefix-14 param-4' is \"off\"\\."] + + gdb_test "show prefix-13" \ + [multi_line \ + "^prefix-13 param-1: The current value of 'prefix-13 param-1' is \"off\"\\." \ + "prefix-13 param-2: The current value of 'prefix-13 param-2' is \"off\"\\." \ + "prefix-13 prefix-14 param-3: The current value of 'prefix-13 prefix-14 param-3' is \"off\"\\." \ + "prefix-13 prefix-14 param-4: The current value of 'prefix-13 prefix-14 param-4' is \"off\"\\."] + + gdb_test "set prefix-13 prefix-14" \ + [multi_line \ + "" \ + "set prefix-13 prefix-14 param-3 -- Set the current value of 'prefix-13 prefix-14 param-3'\\." \ + "set prefix-13 prefix-14 param-4 -- Set the current value of 'prefix-13 prefix-14 param-4'\\." \ + "" \ + ".*"] + + gdb_test "set prefix-13" \ + [multi_line \ + "" \ + "set prefix-13 param-1 -- Set the current value of 'prefix-13 param-1'\\." \ + "set prefix-13 param-2 -- Set the current value of 'prefix-13 param-2'\\." \ + "set prefix-13 prefix-14 -- This command is not documented\\." \ + "" \ + ".*"] +} + +test_basic_usage +test_simple_sub_class +test_prefix_with_invoke +test_dont_repeat +test_nested diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp index de524f4..214c570 100644 --- a/gdb/testsuite/gdb.python/py-parameter.exp +++ b/gdb/testsuite/gdb.python/py-parameter.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 @@ -185,6 +185,58 @@ proc_with_prefix test_enum_parameter { } { "Undefined item: \"three\".*" "set invalid enum parameter" } +# Test an color parameter. +proc_with_prefix test_color_parameter { } { + global env + with_ansi_styling_terminal { + # This enables 256 colors support and disables colors approximation. + setenv TERM xterm-256color + setenv COLORTERM truecolor + + clean_restart + + gdb_test_multiline "color gdb parameter" \ + "python" "" \ + "class TestColorParam (gdb.Parameter):" "" \ + " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ + " show_doc = \"Show the state of the color\"" ""\ + " set_doc = \"Set the state of the color\"" "" \ + " def get_show_string (self, pvalue):" ""\ + " return \"The state of the color is \" + str(pvalue)" ""\ + " def get_set_string (self):" ""\ + " return \"The state of the color has been set to \" + str(self.value)" ""\ + " def __init__ (self, name):" "" \ + " super (TestColorParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_COLOR)" "" \ + " self.value = gdb.Color(\"green\")" "" \ + "test_color_param = TestColorParam ('print test-color-param')" ""\ + "end" + + gdb_test "python print (test_color_param.value)" "green" \ + "test color parameter value is green" + gdb_test "show print test-color-param" \ + "The state of the color is green.*" \ + "show parameter is initial value" + gdb_test "set print test-color-param 255" \ + "The state of the color has been set to 255" "set color to 255" + gdb_test "show print test-color-param" \ + "The state of the color is 255.*" "show parameter is new value" + gdb_test "python print (test_color_param.value)" "255" \ + "test color parameter value is 255" + gdb_test_no_output "python test_color_param.value = gdb.Color(254)" \ + "assign test_color_param.value to 254" + gdb_test "python print (test_color_param.value)" "254" \ + "test color parameter value is integer" + gdb_test_no_output "python test_color_param.value = gdb.Color('#FED210')" \ + "assign test_color_param.value to #FED210" + gdb_test "python print (test_color_param.value.components)" "\\(254, 210, 16\\)" \ + "test color parameter components from RGB hex tripple value" + gdb_test "set print test-color-param 256" \ + "integer 256 out of range.*" "set invalid color parameter" + gdb_test "python test_color_param.value = gdb.Color(256)" \ + ".*Error occurred in Python: Palette color index 256 is out of range.*" "set invalid color value" + } +} + # Test a file parameter. proc_with_prefix test_file_parameter { } { clean_restart @@ -294,6 +346,91 @@ proc_with_prefix test_really_undocumented_parameter { } { "test general help" } +# Test a parameter in which the __doc__ string is empty or None. +proc_with_prefix test_empty_doc_parameter {} { + gdb_test_multiline "empty __doc__ parameter" \ + "python" "" \ + "class EmptyDocParam(gdb.Parameter):" "" \ + " __doc__ = \"\"" "" \ + " def __init__(self, name):" "" \ + " super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + " self.value = True" "" \ + "test_empty_doc_param = EmptyDocParam('print test-empty-doc-param')" ""\ + "end" + + # Setting the __doc__ string to empty means GDB will completely + # elide it from the output. + gdb_test "help set print test-empty-doc-param" \ + "^Set the current value of 'print test-empty-doc-param'\\." + + gdb_test_multiline "None __doc__ parameter" \ + "python" "" \ + "class NoneDocParam(gdb.Parameter):" "" \ + " __doc__ = None" "" \ + " def __init__(self, name):" "" \ + " super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + " self.value = True" "" \ + "test_none_doc_param = NoneDocParam('print test-none-doc-param')" ""\ + "end" + + # Setting the __doc__ string to None, or anything else that isn't + # a string, causes GDB to use a default string instead. + gdb_test "help set print test-none-doc-param" \ + [multi_line \ + "^Set the current value of 'print test-none-doc-param'\\." \ + "This command is not documented\\."] +} + +# Test a parameter in which the set_doc/show_doc strings are either +# empty, or None. +proc_with_prefix test_empty_set_show_doc_parameter {} { + gdb_test_multiline "empty set/show doc parameter" \ + "python" "" \ + "class EmptySetShowParam(gdb.Parameter):" "" \ + " set_doc = \"\"" "" \ + " show_doc = \"\"" "" \ + " def __init__(self, name):" "" \ + " super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + " self.value = True" "" \ + "test_empty_set_show_param = EmptySetShowParam('print test-empty-set-show-param')" ""\ + "end" + + # Setting the set_doc/show_doc string to empty means GDB will use + # a suitable default string. + gdb_test "help set print test-empty-set-show-param" \ + [multi_line \ + "^Set the current value of 'print test-empty-set-show-param'\\." \ + "This command is not documented\\."] + + gdb_test "help show print test-empty-set-show-param" \ + [multi_line \ + "^Show the current value of 'print test-empty-set-show-param'\\." \ + "This command is not documented\\."] + + gdb_test_multiline "None set/show doc parameter" \ + "python" "" \ + "class NoneSetShowParam(gdb.Parameter):" "" \ + " set_doc = None" "" \ + " show_doc = None" "" \ + " def __init__(self, name):" "" \ + " super ().__init__(name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + " self.value = True" "" \ + "test_none_set_show_param = NoneSetShowParam('print test-none-set-show-param')" ""\ + "end" + + # Setting the set_doc/show_doc string to None (or any non-string + # value) means GDB will use a suitable default string. + gdb_test "help set print test-none-set-show-param" \ + [multi_line \ + "^Set the current value of 'print test-none-set-show-param'\\." \ + "This command is not documented\\."] + + gdb_test "help show print test-none-set-show-param" \ + [multi_line \ + "^Show the current value of 'print test-none-set-show-param'\\." \ + "This command is not documented\\."] +} + # Test deprecated API. Do not use in your own implementations. proc_with_prefix test_deprecated_api_parameter { } { clean_restart @@ -617,20 +754,123 @@ proc_with_prefix test_ambiguous_parameter {} { "Parameter .* is ambiguous.*Error occurred in Python.*" gdb_test "python print(gdb.parameter('test-ambiguous-value-1a'))" \ "Could not find parameter.*Error occurred in Python.*" + + # Create command prefixs 'set foo1' and 'show foo1'. + gdb_test_no_output "python gdb.Command('set foo1', gdb.COMMAND_NONE, prefix=True)" + gdb_test_no_output "python gdb.Command('show foo1', gdb.COMMAND_NONE, prefix=True)" + + # Create a parameter under 'foo1', but use a truncated prefix. At + # this point though, the prefix is not ambiguous. + gdb_test_no_output "python gdb.Parameter('foo bar', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" + gdb_test "python print(gdb.parameter('foo1 bar'))" "False" + + # Create another prefix command, similar in name to the first. + gdb_test_no_output "python gdb.Command('set foo2', gdb.COMMAND_NONE, prefix=True)" + gdb_test_no_output "python gdb.Command('show foo2', gdb.COMMAND_NONE, prefix=True)" + + # An attempt to create a parameter using an ambiguous prefix will give an error. + gdb_test "python gdb.Parameter('foo baz', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" \ + [multi_line \ + "Python Exception <class 'RuntimeError'>: Could not find command prefix foo\\." \ + "Error occurred in Python: Could not find command prefix foo\\."] +} + +# Check that creating a gdb.Parameter with an unknown command prefix results in an error. +proc_with_prefix test_unknown_prefix {} { + gdb_test_multiline "create parameter" \ + "python" "" \ + "class UnknownPrefixParam(gdb.Parameter):" "" \ + " def __init__ (self, name):" "" \ + " super().__init__ (name, gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + " self.value = True" "" \ + "end" + + foreach prefix { "unknown-prefix" "style unknown-prefix" "style disassembler unknown-prefix"} { + gdb_test "python UnknownPrefixParam('$prefix new-param')" \ + [multi_line \ + "Python Exception <class 'RuntimeError'>: Could not find command prefix $prefix\\." \ + "Error occurred in Python: Could not find command prefix $prefix\\."] + } +} + +# Test the default behaviour of a set/show parameter prefix command. +proc_with_prefix test_set_show_parameters {} { + # This first set/show prefix command doesn't have an invoke + # method. As such, GDB installs the default invoke behaviour; set + # prints the full list of sub-commands, and show prints all the + # sub-command values. + gdb_test_multiline "Setup set/show parameter prefix with no invoke" \ + "python" "" \ + "class TestParamPrefix(gdb.Command):" "" \ + " \"\"\"TestParamPrefix documentation string.\"\"\"" "" \ + " def __init__(self, name):" "" \ + " super().__init__(name, gdb.COMMAND_NONE, prefix = True)" "" \ + "TestParamPrefix('set test-prefix')" "" \ + "TestParamPrefix('show test-prefix')" "" \ + "gdb.Parameter('test-prefix param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "gdb.Parameter('test-prefix param-2', gdb.COMMAND_NONE, gdb.PARAM_INTEGER)" "" \ + "gdb.Parameter('test-prefix param-3', gdb.COMMAND_NONE, gdb.PARAM_STRING)" "" \ + "end" + + gdb_test "set test-prefix" \ + [multi_line \ + "List of \"set test-prefix\" subcommands:" \ + "" \ + "set test-prefix param-1 -- Set the current value of 'test-prefix param-1'." \ + "set test-prefix param-2 -- Set the current value of 'test-prefix param-2'." \ + "set test-prefix param-3 -- Set the current value of 'test-prefix param-3'." \ + "" \ + "Type \"help set test-prefix\" followed by subcommand name for full documentation\\." \ + "Type \"apropos word\" to search for commands related to \"word\"\\." \ + "Type \"apropos -v word\" for full documentation of commands related to \"word\"\\." \ + "Command name abbreviations are allowed if unambiguous\\."] + + gdb_test "show test-prefix" \ + [multi_line \ + "test-prefix param-1: The current value of 'test-prefix param-1' is \"off\"\\." \ + "test-prefix param-2: The current value of 'test-prefix param-2' is \"0\"\\." \ + "test-prefix param-3: The current value of 'test-prefix param-3' is \"\"\\."] + + # This next set/show prefix has an invoke method, which will be + # called instead of the default behaviour tested above. + gdb_test_multiline "Setup set/show parameter prefix with invoke" \ + "python" "" \ + "class TestParamPrefix(gdb.Command):" "" \ + " \"\"\"TestParamPrefix documentation string.\"\"\"" "" \ + " def __init__(self, name, mode):" "" \ + " self._mode = mode" "" \ + " super().__init__(self._mode + ' ' + name, gdb.COMMAND_NONE, prefix = True)" "" \ + " def invoke(self, args, from_tty):" "" \ + " print('invoke -- ' + self._mode)" "" \ + "TestParamPrefix('test-prefix-2', 'set')" "" \ + "TestParamPrefix('test-prefix-2', 'show')" "" \ + "gdb.Parameter('test-prefix-2 param-1', gdb.COMMAND_NONE, gdb.PARAM_BOOLEAN)" "" \ + "gdb.Parameter('test-prefix-2 param-2', gdb.COMMAND_NONE, gdb.PARAM_INTEGER)" "" \ + "gdb.Parameter('test-prefix-2 param-3', gdb.COMMAND_NONE, gdb.PARAM_STRING)" "" \ + "end" + + gdb_test "set test-prefix-2" "^invoke -- set" + + gdb_test "show test-prefix-2" "^invoke -- show" } test_directories test_data_directory test_boolean_parameter test_enum_parameter +test_color_parameter test_file_parameter test_undocumented_parameter test_really_undocumented_parameter +test_empty_doc_parameter +test_empty_set_show_doc_parameter test_deprecated_api_parameter test_gdb_parameter test_integer_parameter test_throwing_parameter test_language test_ambiguous_parameter +test_unknown_prefix +test_set_show_parameters rename py_param_test_maybe_no_output "" diff --git a/gdb/testsuite/gdb.python/py-pending-frame-level.c b/gdb/testsuite/gdb.python/py-pending-frame-level.c index dba64b8..56734ad 100644 --- a/gdb/testsuite/gdb.python/py-pending-frame-level.c +++ b/gdb/testsuite/gdb.python/py-pending-frame-level.c @@ -1,6 +1,6 @@ /* This test program is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-pending-frame-level.exp b/gdb/testsuite/gdb.python/py-pending-frame-level.exp index dcefdce..4eb82c5 100644 --- a/gdb/testsuite/gdb.python/py-pending-frame-level.exp +++ b/gdb/testsuite/gdb.python/py-pending-frame-level.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-pending-frame-level.py b/gdb/testsuite/gdb.python/py-pending-frame-level.py index 7742fda..8a9783b 100644 --- a/gdb/testsuite/gdb.python/py-pending-frame-level.py +++ b/gdb/testsuite/gdb.python/py-pending-frame-level.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-pp-cast.c b/gdb/testsuite/gdb.python/py-pp-cast.c index be665bb..dcd4619 100644 --- a/gdb/testsuite/gdb.python/py-pp-cast.c +++ b/gdb/testsuite/gdb.python/py-pp-cast.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2023-2024 Free Software Foundation, Inc. + Copyright 2023-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 diff --git a/gdb/testsuite/gdb.python/py-pp-cast.exp b/gdb/testsuite/gdb.python/py-pp-cast.exp index 61c2fba..7e20756 100644 --- a/gdb/testsuite/gdb.python/py-pp-cast.exp +++ b/gdb/testsuite/gdb.python/py-pp-cast.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/py-pp-cast.py b/gdb/testsuite/gdb.python/py-pp-cast.py index 6eff800..515aa77 100644 --- a/gdb/testsuite/gdb.python/py-pp-cast.py +++ b/gdb/testsuite/gdb.python/py-pp-cast.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import gdb.printing + class PpIntPrinter(object): def __init__(self, val): diff --git a/gdb/testsuite/gdb.python/py-pp-integral.c b/gdb/testsuite/gdb.python/py-pp-integral.c index 1e13fc1..2c3afa1 100644 --- a/gdb/testsuite/gdb.python/py-pp-integral.c +++ b/gdb/testsuite/gdb.python/py-pp-integral.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2013-2024 Free Software Foundation, Inc. + Copyright 2013-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 diff --git a/gdb/testsuite/gdb.python/py-pp-integral.exp b/gdb/testsuite/gdb.python/py-pp-integral.exp index 0635e05..8111d75 100644 --- a/gdb/testsuite/gdb.python/py-pp-integral.exp +++ b/gdb/testsuite/gdb.python/py-pp-integral.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2024 Free Software Foundation, Inc. +# Copyright (C) 2013-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 diff --git a/gdb/testsuite/gdb.python/py-pp-integral.py b/gdb/testsuite/gdb.python/py-pp-integral.py index 089ca5b..a87736c 100644 --- a/gdb/testsuite/gdb.python/py-pp-integral.py +++ b/gdb/testsuite/gdb.python/py-pp-integral.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2024 Free Software Foundation, Inc. +# Copyright (C) 2013-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 diff --git a/gdb/testsuite/gdb.python/py-pp-maint.c b/gdb/testsuite/gdb.python/py-pp-maint.c index 3ef4f10..f40bbe5 100644 --- a/gdb/testsuite/gdb.python/py-pp-maint.c +++ b/gdb/testsuite/gdb.python/py-pp-maint.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/py-pp-maint.exp b/gdb/testsuite/gdb.python/py-pp-maint.exp index f224ae7..74d8e76 100644 --- a/gdb/testsuite/gdb.python/py-pp-maint.exp +++ b/gdb/testsuite/gdb.python/py-pp-maint.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 @@ -55,7 +55,7 @@ gdb_test "print flt" " = x=<42> y=<43>" \ gdb_test "print ss" " = a=<a=<1> b=<$hex>> b=<a=<2> b=<$hex>>" \ "print ss enabled #1" -set num_pp 7 +set num_pp 6 gdb_test "disable pretty-printer" \ "$num_pp printers disabled.*0 of $num_pp printers enabled" @@ -75,7 +75,7 @@ gdb_test "disable pretty-printer global lookup_function_lookup_test" \ "1 printer disabled.*[expr $num_pp - 1] of $num_pp printers enabled" gdb_test "disable pretty-printer global pp-test;.*" \ - "[expr $num_pp - 2] printers disabled.*1 of $num_pp printers enabled" + "[expr 5] printers disabled.*0 of $num_pp printers enabled" gdb_test "info pretty-printer global .*function" \ {.*function_lookup_test \[disabled\].*} \ @@ -92,13 +92,13 @@ gdb_test "print ss" " = {a = {a = 1, b = $hex}, b = {a = 2, b = $hex}}" \ "print ss disabled" gdb_test "enable pretty-printer global lookup_function_lookup_test" \ - "1 printer enabled.*2 of $num_pp printers enabled" + "1 printer enabled.*1 of $num_pp printers enabled" # This doesn't enable any printers because each subprinter in the collection # is still individually disabled. But this is still needed, to enable the # collection itself. gdb_test "enable pretty-printer global pp-test" \ - "0 printers enabled.*2 of $num_pp printers enabled" + "0 printers enabled.*1 of $num_pp printers enabled" gdb_test "enable pretty-printer global pp-test;.*ss.*" \ "2 printers enabled.*[expr $num_pp - 3] of $num_pp printers enabled" diff --git a/gdb/testsuite/gdb.python/py-pp-maint.py b/gdb/testsuite/gdb.python/py-pp-maint.py index 91c193f..8b96cc0 100644 --- a/gdb/testsuite/gdb.python/py-pp-maint.py +++ b/gdb/testsuite/gdb.python/py-pp-maint.py @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/py-pp-re-notag.c b/gdb/testsuite/gdb.python/py-pp-re-notag.c index 1e13fc1..2c3afa1 100644 --- a/gdb/testsuite/gdb.python/py-pp-re-notag.c +++ b/gdb/testsuite/gdb.python/py-pp-re-notag.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2013-2024 Free Software Foundation, Inc. + Copyright 2013-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 diff --git a/gdb/testsuite/gdb.python/py-pp-re-notag.exp b/gdb/testsuite/gdb.python/py-pp-re-notag.exp index 0635e05..8111d75 100644 --- a/gdb/testsuite/gdb.python/py-pp-re-notag.exp +++ b/gdb/testsuite/gdb.python/py-pp-re-notag.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2024 Free Software Foundation, Inc. +# Copyright (C) 2013-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 diff --git a/gdb/testsuite/gdb.python/py-pp-re-notag.py b/gdb/testsuite/gdb.python/py-pp-re-notag.py index 6aefad1..32ea2c9 100644 --- a/gdb/testsuite/gdb.python/py-pp-re-notag.py +++ b/gdb/testsuite/gdb.python/py-pp-re-notag.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2024 Free Software Foundation, Inc. +# Copyright (C) 2013-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 @@ -16,6 +16,7 @@ from time import asctime, gmtime import gdb # silence pyflakes +import gdb.printing class TimePrinter: diff --git a/gdb/testsuite/gdb.python/py-pp-registration.c b/gdb/testsuite/gdb.python/py-pp-registration.c index b597f14..5a95917 100644 --- a/gdb/testsuite/gdb.python/py-pp-registration.c +++ b/gdb/testsuite/gdb.python/py-pp-registration.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/py-pp-registration.exp b/gdb/testsuite/gdb.python/py-pp-registration.exp index 4bfdf5e..c5e7f9a 100644 --- a/gdb/testsuite/gdb.python/py-pp-registration.exp +++ b/gdb/testsuite/gdb.python/py-pp-registration.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/py-pp-registration.py b/gdb/testsuite/gdb.python/py-pp-registration.py index 1b7eff8..e9f3dfb 100644 --- a/gdb/testsuite/gdb.python/py-pp-registration.py +++ b/gdb/testsuite/gdb.python/py-pp-registration.py @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/py-prettyprint-stub-2.cc b/gdb/testsuite/gdb.python/py-prettyprint-stub-2.cc index 1988cc0..592200b 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint-stub-2.cc +++ b/gdb/testsuite/gdb.python/py-prettyprint-stub-2.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2023-2024 Free Software Foundation, Inc. + Copyright 2023-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 diff --git a/gdb/testsuite/gdb.python/py-prettyprint-stub.cc b/gdb/testsuite/gdb.python/py-prettyprint-stub.cc index fc453d9..156532f 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint-stub.cc +++ b/gdb/testsuite/gdb.python/py-prettyprint-stub.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2023-2024 Free Software Foundation, Inc. + Copyright 2023-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 diff --git a/gdb/testsuite/gdb.python/py-prettyprint-stub.exp b/gdb/testsuite/gdb.python/py-prettyprint-stub.exp index 2dab863..1c1d010 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint-stub.exp +++ b/gdb/testsuite/gdb.python/py-prettyprint-stub.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/py-prettyprint-stub.h b/gdb/testsuite/gdb.python/py-prettyprint-stub.h index fa18165..cb17cb5 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint-stub.h +++ b/gdb/testsuite/gdb.python/py-prettyprint-stub.h @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2023-2024 Free Software Foundation, Inc. + Copyright 2023-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 diff --git a/gdb/testsuite/gdb.python/py-prettyprint-stub.py b/gdb/testsuite/gdb.python/py-prettyprint-stub.py index 565ae19..b66086c 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint-stub.py +++ b/gdb/testsuite/gdb.python/py-prettyprint-stub.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 @@ -16,6 +16,8 @@ # This file is part of the GDB testsuite. # It tests Python-based pretty-printing of stubs. +import gdb.printing + class SPrinter: def __init__(self, val): diff --git a/gdb/testsuite/gdb.python/py-prettyprint.c b/gdb/testsuite/gdb.python/py-prettyprint.c index 312420b..56c19ad 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.c +++ b/gdb/testsuite/gdb.python/py-prettyprint.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2008-2024 Free Software Foundation, Inc. + Copyright 2008-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 diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp index ec2bdc9..0b5ca9a 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.exp +++ b/gdb/testsuite/gdb.python/py-prettyprint.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 diff --git a/gdb/testsuite/gdb.python/py-prettyprint.py b/gdb/testsuite/gdb.python/py-prettyprint.py index e4ac3e1..21c2569 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.py +++ b/gdb/testsuite/gdb.python/py-prettyprint.py @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 diff --git a/gdb/testsuite/gdb.python/py-progspace-events.c b/gdb/testsuite/gdb.python/py-progspace-events.c index f8b2909..5c4dd4d 100644 --- a/gdb/testsuite/gdb.python/py-progspace-events.c +++ b/gdb/testsuite/gdb.python/py-progspace-events.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2023-2024 Free Software Foundation, Inc. + Copyright 2023-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 diff --git a/gdb/testsuite/gdb.python/py-progspace-events.exp b/gdb/testsuite/gdb.python/py-progspace-events.exp index 95e4ca8..5ee9977 100644 --- a/gdb/testsuite/gdb.python/py-progspace-events.exp +++ b/gdb/testsuite/gdb.python/py-progspace-events.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 @@ -79,37 +79,16 @@ gdb_test "continue" \ "\\\[Inferior $decimal \[^\r\n\]+ exited normally\\\]"] \ "continue until inferior 2 exits" -gdb_test "inferior 1" "\\\[Switching to inferior 1 .*" - -# Step the inferior. During this process GDB will prune the now +# Switch to inferior 1. During this process GDB will prune the now # defunct inferior, which deletes its program space, which should # trigger the FreeProgspaceEvent. # -# However, there is a slight problem. When the target is remote, and -# GDB is accessing files using remote fileio, then GDB will attempt to -# prune the inferior at a point in time when the remote target is -# waiting for a stop reply. Pruning an inferior causes GDB to close -# files associated with that inferior. -# -# In non-async mode we can't send fileio packets while waiting for a -# stop reply, so the attempts to close files fails, and this shows up -# as an error. -# -# As this error has nothing to do with the feature being tested here, -# we just accept the error message, the important part is the -# 'FreeProgspaceEvent' string, so long as that appears (just once) -# then the test is a success. -set warning_msg \ - [multi_line \ - "warning: cannot close \"\[^\r\n\]+\": Cannot execute this command while the target is running\\." \ - "Use the \"interrupt\" command to stop the target" \ - "and then try again\\."] -gdb_test "step" \ +gdb_test "inferior 1" \ [multi_line \ - "^FreeProgspaceEvent.*: <gdb.Progspace object at $hex>(?:\r\n$warning_msg)*" \ - "do_parent_stuff \\(\\) at \[^\r\n\]+" \ - "$decimal\\s+\[^\r\n\]+"] + "\\\[Switching to inferior 1 .*" \ + ".*" \ + "FreeProgspaceEvent.*: <gdb.Progspace object at $hex>"] # Let this inferior run to completion. gdb_continue_to_end diff --git a/gdb/testsuite/gdb.python/py-progspace-events.py b/gdb/testsuite/gdb.python/py-progspace-events.py index 23c6fc5..3a53fb16 100644 --- a/gdb/testsuite/gdb.python/py-progspace-events.py +++ b/gdb/testsuite/gdb.python/py-progspace-events.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/py-progspace.c b/gdb/testsuite/gdb.python/py-progspace.c index 80fcda0..170249b 100644 --- a/gdb/testsuite/gdb.python/py-progspace.c +++ b/gdb/testsuite/gdb.python/py-progspace.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/py-progspace.exp b/gdb/testsuite/gdb.python/py-progspace.exp index 0ae5b56..1d271d4 100644 --- a/gdb/testsuite/gdb.python/py-progspace.exp +++ b/gdb/testsuite/gdb.python/py-progspace.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 @@ -42,7 +42,7 @@ gdb_py_test_silent_cmd "python progspace = gdb.current_progspace()" \ "Get current progspace" 1 gdb_test "python print (progspace.filename)" "py-progspace" \ - "current progspace filename (py-progspace)" + "current progspace filename, py-progspace" gdb_test "python print (gdb.current_progspace().symbol_file)" \ "<gdb.Objfile filename=.*/py-progspace>" \ diff --git a/gdb/testsuite/gdb.python/py-prompt.c b/gdb/testsuite/gdb.python/py-prompt.c index c7657d7..6718bb1 100644 --- a/gdb/testsuite/gdb.python/py-prompt.c +++ b/gdb/testsuite/gdb.python/py-prompt.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2007-2024 Free Software Foundation, Inc. + Copyright 2007-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 diff --git a/gdb/testsuite/gdb.python/py-prompt.exp b/gdb/testsuite/gdb.python/py-prompt.exp index 614fe9d..01176a3 100644 --- a/gdb/testsuite/gdb.python/py-prompt.exp +++ b/gdb/testsuite/gdb.python/py-prompt.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2011-2024 Free Software Foundation, Inc. +# Copyright (C) 2011-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 diff --git a/gdb/testsuite/gdb.python/py-rbreak-func2.c b/gdb/testsuite/gdb.python/py-rbreak-func2.c index fdcece6..085d869 100644 --- a/gdb/testsuite/gdb.python/py-rbreak-func2.c +++ b/gdb/testsuite/gdb.python/py-rbreak-func2.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2017-2024 Free Software Foundation, Inc. + Copyright 2017-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 diff --git a/gdb/testsuite/gdb.python/py-rbreak.c b/gdb/testsuite/gdb.python/py-rbreak.c index 1cc4561..4da4de4 100644 --- a/gdb/testsuite/gdb.python/py-rbreak.c +++ b/gdb/testsuite/gdb.python/py-rbreak.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2013-2024 Free Software Foundation, Inc. + Copyright 2013-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 diff --git a/gdb/testsuite/gdb.python/py-rbreak.exp b/gdb/testsuite/gdb.python/py-rbreak.exp index dca8731..fe1e0fc 100644 --- a/gdb/testsuite/gdb.python/py-rbreak.exp +++ b/gdb/testsuite/gdb.python/py-rbreak.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2024 Free Software Foundation, Inc. +# Copyright (C) 2017-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 diff --git a/gdb/testsuite/gdb.python/py-read-memory-leak.c b/gdb/testsuite/gdb.python/py-read-memory-leak.c new file mode 100644 index 0000000..0319268 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-read-memory-leak.c @@ -0,0 +1,27 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2014-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/>. */ + +static struct x +{ + char unsigned u[4096]; +} x, *px = &x; + +int +main (void) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.python/py-read-memory-leak.exp b/gdb/testsuite/gdb.python/py-read-memory-leak.exp new file mode 100644 index 0000000..9ae5eb8 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-read-memory-leak.exp @@ -0,0 +1,34 @@ +# Copyright (C) 2024-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/>. + +# This file is part of the GDB testsuite. It checks for memory leaks +# associated with calling gdb.Inferior.read_memory(). + +load_lib gdb-python.exp + +require allow_python_tests + +standard_testfile + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +gdb_py_run_memory_leak_test ${srcdir}/${subdir}/${testfile}.py \ + "buffers returned by read_memory() deallocates correctly" diff --git a/gdb/testsuite/gdb.python/py-read-memory-leak.py b/gdb/testsuite/gdb.python/py-read-memory-leak.py new file mode 100644 index 0000000..89647cf --- /dev/null +++ b/gdb/testsuite/gdb.python/py-read-memory-leak.py @@ -0,0 +1,39 @@ +# Copyright (C) 2024-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/>. + +import sys + +# Avoid generating +# src/gdb/testsuite/gdb.python/__pycache__/gdb_leak_detector.cpython-<n>.pyc. +sys.dont_write_bytecode = True + +import gdb_leak_detector + + +class read_leak_detector(gdb_leak_detector.gdb_leak_detector): + def __init__(self): + super().__init__(__file__) + self.mem_buf = None + self.addr = gdb.parse_and_eval("px") + self.inf = gdb.inferiors()[0] + + def allocate(self): + self.mem_buf = self.inf.read_memory(self.addr, 4096) + + def deallocate(self): + self.mem_buf = None + + +read_leak_detector().run() diff --git a/gdb/testsuite/gdb.python/py-record-btrace-threads.c b/gdb/testsuite/gdb.python/py-record-btrace-threads.c index 2c2ef32..5058ce1 100644 --- a/gdb/testsuite/gdb.python/py-record-btrace-threads.c +++ b/gdb/testsuite/gdb.python/py-record-btrace-threads.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2017-2024 Free Software Foundation, Inc. + Copyright 2017-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 diff --git a/gdb/testsuite/gdb.python/py-record-btrace-threads.exp b/gdb/testsuite/gdb.python/py-record-btrace-threads.exp index d723879..4a3b59fb 100644 --- a/gdb/testsuite/gdb.python/py-record-btrace-threads.exp +++ b/gdb/testsuite/gdb.python/py-record-btrace-threads.exp @@ -1,6 +1,6 @@ # This testcase is part of GDB, the GNU debugger. # -# Copyright 2017-2024 Free Software Foundation, Inc. +# Copyright 2017-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 diff --git a/gdb/testsuite/gdb.python/py-record-btrace.c b/gdb/testsuite/gdb.python/py-record-btrace.c index abc0dcf..10c0d41 100644 --- a/gdb/testsuite/gdb.python/py-record-btrace.c +++ b/gdb/testsuite/gdb.python/py-record-btrace.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2016-2024 Free Software Foundation, Inc. + Copyright 2016-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 diff --git a/gdb/testsuite/gdb.python/py-record-btrace.exp b/gdb/testsuite/gdb.python/py-record-btrace.exp index fba0b98..aff7c6c 100644 --- a/gdb/testsuite/gdb.python/py-record-btrace.exp +++ b/gdb/testsuite/gdb.python/py-record-btrace.exp @@ -1,6 +1,6 @@ # This testcase is part of GDB, the GNU debugger. # -# Copyright 2016-2024 Free Software Foundation, Inc. +# Copyright 2016-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 @@ -198,3 +198,14 @@ with_test_prefix "level" { gdb_test "python print(gdb.current_recording().function_call_history\[0\].level)" "1" gdb_test "python print(gdb.current_recording().function_call_history\[1\].level)" "0" } + +# Note: GDB can incrementally add to the recording from the raw trace data. +# After a clear(), GDB might not have all the raw trace data available in its +# buffer to recreate the full recording it had before the clear(). +# So, do this testing last to avoid disturbing subsequent tests. +with_test_prefix "clear" { + gdb_test_no_output "python r.clear()" + gdb_test "python insn = r.instruction_history" + gdb_test_no_output "python i = insn\[0\]" + gdb_test "python print(i.size)" "$decimal" +} diff --git a/gdb/testsuite/gdb.python/py-record-full.c b/gdb/testsuite/gdb.python/py-record-full.c index abc0dcf..10c0d41 100644 --- a/gdb/testsuite/gdb.python/py-record-full.c +++ b/gdb/testsuite/gdb.python/py-record-full.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2016-2024 Free Software Foundation, Inc. + Copyright 2016-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 diff --git a/gdb/testsuite/gdb.python/py-record-full.exp b/gdb/testsuite/gdb.python/py-record-full.exp index da38d1c..97d21ce 100644 --- a/gdb/testsuite/gdb.python/py-record-full.exp +++ b/gdb/testsuite/gdb.python/py-record-full.exp @@ -1,6 +1,6 @@ # This testcase is part of GDB, the GNU debugger. # -# Copyright 2016-2024 Free Software Foundation, Inc. +# Copyright 2016-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 diff --git a/gdb/testsuite/gdb.python/py-recurse-unwind.c b/gdb/testsuite/gdb.python/py-recurse-unwind.c index 1ecdaa2..573ee3c 100644 --- a/gdb/testsuite/gdb.python/py-recurse-unwind.c +++ b/gdb/testsuite/gdb.python/py-recurse-unwind.c @@ -1,6 +1,6 @@ /* This test program is part of GDB, the GNU debugger. - Copyright 2016-2024 Free Software Foundation, Inc. + Copyright 2016-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 diff --git a/gdb/testsuite/gdb.python/py-recurse-unwind.exp b/gdb/testsuite/gdb.python/py-recurse-unwind.exp index 1c22dc2..a1d1462 100644 --- a/gdb/testsuite/gdb.python/py-recurse-unwind.exp +++ b/gdb/testsuite/gdb.python/py-recurse-unwind.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2024 Free Software Foundation, Inc. +# Copyright (C) 2016-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 diff --git a/gdb/testsuite/gdb.python/py-recurse-unwind.py b/gdb/testsuite/gdb.python/py-recurse-unwind.py index 0b0004b..244c693 100644 --- a/gdb/testsuite/gdb.python/py-recurse-unwind.py +++ b/gdb/testsuite/gdb.python/py-recurse-unwind.py @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2024 Free Software Foundation, Inc. +# Copyright (C) 2016-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 diff --git a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc index 3403797..e3f71d0 100644 --- a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc +++ b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2012-2024 Free Software Foundation, Inc. + Copyright 2012-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 diff --git a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp index 7e6f0d0..2e92756 100644 --- a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp +++ b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2024 Free Software Foundation, Inc. +# Copyright (C) 2012-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 diff --git a/gdb/testsuite/gdb.python/py-section-script.c b/gdb/testsuite/gdb.python/py-section-script.c index 2d465c2..2d08cbc 100644 --- a/gdb/testsuite/gdb.python/py-section-script.c +++ b/gdb/testsuite/gdb.python/py-section-script.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/py-section-script.exp b/gdb/testsuite/gdb.python/py-section-script.exp index 206b8c6..cc4425c 100644 --- a/gdb/testsuite/gdb.python/py-section-script.exp +++ b/gdb/testsuite/gdb.python/py-section-script.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/py-section-script.py b/gdb/testsuite/gdb.python/py-section-script.py index 73230c9..d85221e 100644 --- a/gdb/testsuite/gdb.python/py-section-script.py +++ b/gdb/testsuite/gdb.python/py-section-script.py @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 diff --git a/gdb/testsuite/gdb.python/py-send-packet.c b/gdb/testsuite/gdb.python/py-send-packet.c index 1c97790..abdb71b 100644 --- a/gdb/testsuite/gdb.python/py-send-packet.c +++ b/gdb/testsuite/gdb.python/py-send-packet.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-send-packet.exp b/gdb/testsuite/gdb.python/py-send-packet.exp index bbee5ac..6c2984f 100644 --- a/gdb/testsuite/gdb.python/py-send-packet.exp +++ b/gdb/testsuite/gdb.python/py-send-packet.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-send-packet.py b/gdb/testsuite/gdb.python/py-send-packet.py index 402b039..0a0b359 100644 --- a/gdb/testsuite/gdb.python/py-send-packet.py +++ b/gdb/testsuite/gdb.python/py-send-packet.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-shared-sl.c b/gdb/testsuite/gdb.python/py-shared-sl.c index be736c2..49032ad 100644 --- a/gdb/testsuite/gdb.python/py-shared-sl.c +++ b/gdb/testsuite/gdb.python/py-shared-sl.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/py-shared.c b/gdb/testsuite/gdb.python/py-shared.c index 4b23980..dc28f32 100644 --- a/gdb/testsuite/gdb.python/py-shared.c +++ b/gdb/testsuite/gdb.python/py-shared.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/py-shared.exp b/gdb/testsuite/gdb.python/py-shared.exp index 9be5aa4..d80e139 100644 --- a/gdb/testsuite/gdb.python/py-shared.exp +++ b/gdb/testsuite/gdb.python/py-shared.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 diff --git a/gdb/testsuite/gdb.python/py-source-styling-2.c b/gdb/testsuite/gdb.python/py-source-styling-2.c new file mode 100644 index 0000000..aaa3d69 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-source-styling-2.c @@ -0,0 +1,26 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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/>. */ + +int +main () +{ /* List this line. */ + try + {} + catch (...) + {} + return 0; +} diff --git a/gdb/testsuite/gdb.python/py-source-styling-2.exp b/gdb/testsuite/gdb.python/py-source-styling-2.exp new file mode 100644 index 0000000..ebf7f32 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-source-styling-2.exp @@ -0,0 +1,55 @@ +# 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/>. + +# Compile a c++ file using a .c extension, and check that pygments uses c++ +# highlighting instead of c highlighting. + +require allow_python_tests + +load_lib gdb-python.exp + +standard_testfile py-source-styling-2.c + +set line_number [gdb_get_line_number "List this line."] + +set opts {} +lappend opts debug +lappend opts c++ + +if { [build_executable "failed to build" $testfile $srcfile $opts] == -1 } { + return +} + +with_ansi_styling_terminal { + clean_restart +} + +gdb_test_no_output "maint set gnu-source-highlight enabled off" + +gdb_load $binfile + +require {gdb_py_module_available pygments} + +gdb_test_no_output "set style enabled on" + +gdb_test_multiple "list $line_number" "Styling of c++ keyword try" { + -re -wrap " try\r\n.*" { + # Unstyled. + fail $gdb_test_name + } + -re -wrap "" { + pass $gdb_test_name + } +} diff --git a/gdb/testsuite/gdb.python/py-source-styling.c b/gdb/testsuite/gdb.python/py-source-styling.c index eda87a7..308da9c 100644 --- a/gdb/testsuite/gdb.python/py-source-styling.c +++ b/gdb/testsuite/gdb.python/py-source-styling.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2022-2024 Free Software Foundation, Inc. + Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-source-styling.exp b/gdb/testsuite/gdb.python/py-source-styling.exp index 7b5c1b0..308053c 100644 --- a/gdb/testsuite/gdb.python/py-source-styling.exp +++ b/gdb/testsuite/gdb.python/py-source-styling.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 @@ -13,27 +13,66 @@ # 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. It checks for memory leaks -# associated with allocating and deallocation gdb.Inferior objects. +# Test related to source code highlighting and Python. Includes a +# test for using the Pygments module as a fall back to GNU source +# highlight. +# +# This script also includes tests for handling a non-uft-8 character +# with both Pygments highlighting, and with gdb.execute (when using +# the list command). + +require allow_python_tests load_lib gdb-python.exp standard_testfile -with_ansi_styling_terminal { - # We need an ANSI-capable terminal to get the output, additionally - # we need to set LC_ALL so GDB knows the terminal is UTF-8 - # capable, otherwise we'll get a UnicodeEncodeError trying to - # encode the output. - if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { - return -1 +if { [build_executable "failed to build" ${testfile} ${srcfile}] == -1 } { + return +} + +set line_number [gdb_get_line_number "List this line."] + +# Helper proc. Run CMD, which should produce a source listing, and +# check if the source code is styled or not. EXPECT_STYLED indicates +# if we expect the source listing to be styled or not. +proc check_source_listing_styling { cmd expect_styled { testname "" } } { + if { $testname eq "" } { + set testname $cmd + } + + set seen_style_escape false + gdb_test_multiple $cmd $testname { + -re -wrap "Python Exception.*" { + fail $gdb_test_name + return + } + -re "\033" { + set seen_style_escape true + exp_continue + } + -re "$::gdb_prompt $" { + gdb_assert { $seen_style_escape == $expect_styled } \ + $gdb_test_name + } } +} - if { ![allow_python_tests] } { continue } +# Check that the Python pygments module can be used for source +# highlighting when GNU source highlight is not available (or is +# disabled, as is done in this test). +proc test_pygments_styling {} { + clean_restart $::binfile + + # Remote host boards disable styling via GDB's command line. Turn + # it back on now. + if {[is_remote host]} { + gdb_test "set style enabled on" + } if { ![gdb_py_module_available "pygments"] } { unsupported "pygments module not available" - return -1 + return } if ![runto_main] { @@ -44,19 +83,102 @@ with_ansi_styling_terminal { gdb_test "maint flush source-cache" "Source cache flushed\\." - set seen_style_escape false - set line_number [gdb_get_line_number "List this line."] - gdb_test_multiple "list ${line_number}" "" { - -re "Python Exception.*" { - fail $gdb_test_name - } - -re "\033" { - set seen_style_escape true - exp_continue - } - -re "$gdb_prompt $" { - gdb_assert { $seen_style_escape } - pass $gdb_test_name - } + check_source_listing_styling "list $::line_number" true +} + +# Use gdb.execute to list source code containing non-utf-8 character. +# Check that initially GDB fails to convert the source code to a +# string, then set the correct host encoding, and try again. This +# time the conversion should succeed. +proc test_gdb_execute_non_utf8_source {} { + clean_restart $::binfile + + # The default host charset is utf-8, the source code contains a + # non-utf-8 character, so this will fail. + gdb_test \ + "python source = gdb.execute('list $::line_number', True, True)" \ + [multi_line \ + "Python Exception <class 'UnicodeDecodeError'>: 'ascii' codec can't decode byte 0xc0 in position 250: ordinal not in range\\(128\\)" \ + "Error occurred in Python: 'ascii' codec can't decode byte 0xc0 in position 250: ordinal not in range\\(128\\)"] \ + "gdb.execute fails to convert result to string" + + # Set the correct host charset, and try the conversion again. + gdb_test_no_output "set host-charset ISO-8859-1" + gdb_test_no_output \ + "python source = gdb.execute('list $::line_number', True, True)" \ + "gdb.execute does convert result to string" + + # Check that we captured something that looks like the expected source. + gdb_test "python print(source)" ".*List this line.*" +} + +# Use gdb.execute() to list source code. Alternate between asking for +# styled, and unstyled source code. In some cases we ask for the +# output to be returned via a string, and in other cases we ask for +# the output to be sent straight to stdout. +proc_with_prefix test_source_cache_style_tracking {} { + clean_restart $::binfile + + # Remote host boards disable styling via GDB's command line. Turn + # it back on now. + if {[is_remote host]} { + gdb_test "set style enabled on" + } + + gdb_test_no_output "set host-charset ISO-8859-1" + + # Commands which return styled, and non-styled source code mixed + # together. This ensures that the source cache will need to keep + # discarding the entry with the wrong styling mode. All of these + # gdb.execute calls send their output via a string. + check_source_listing_styling \ + "python print(gdb.execute('list $::line_number', to_string=True), end='')" \ + false + check_source_listing_styling \ + "python print(gdb.execute('list $::line_number', to_string=True, styling=True), end='')" \ + true + foreach from_tty { True False } { + check_source_listing_styling \ + "python print(gdb.execute('list $::line_number', $from_tty, True), end='')" \ + false + check_source_listing_styling \ + "python print(gdb.execute('list $::line_number', $from_tty, True, True), end='')" \ + true + check_source_listing_styling \ + "python print(gdb.execute('list $::line_number', $from_tty, True, False), end='')" \ + false } + + # The same again, but this time the output is sent directly to + # stdout. + check_source_listing_styling \ + "python gdb.execute('list $::line_number')" \ + true + check_source_listing_styling \ + "python gdb.execute('list $::line_number', to_string=False, styling=False)" \ + false + check_source_listing_styling \ + "python gdb.execute('list $::line_number', to_string=False, styling=True)" \ + true + foreach from_tty { True False } { + check_source_listing_styling \ + "python gdb.execute('list $::line_number', $from_tty, False, False)" \ + false + check_source_listing_styling \ + "python gdb.execute('list $::line_number', $from_tty, False, True)" \ + true + check_source_listing_styling \ + "python gdb.execute('list $::line_number', $from_tty, False)" \ + true + } +} + +# We need an ANSI-capable terminal to get the output, additionally we +# need to set LC_ALL so GDB knows the terminal is UTF-8 capable, +# otherwise we'll get a UnicodeEncodeError trying to encode the +# output. +with_ansi_styling_terminal { + test_pygments_styling + test_gdb_execute_non_utf8_source + test_source_cache_style_tracking } diff --git a/gdb/testsuite/gdb.python/py-startup-opt.exp b/gdb/testsuite/gdb.python/py-startup-opt.exp index cf2a2cf..7410706 100644 --- a/gdb/testsuite/gdb.python/py-startup-opt.exp +++ b/gdb/testsuite/gdb.python/py-startup-opt.exp @@ -1,4 +1,4 @@ -# Copyright 2021-2024 Free Software Foundation, Inc. +# Copyright 2021-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 @@ -78,8 +78,9 @@ proc test_python_settings { exp_state } { # all GDB developers some will test GDB with this environment # variable unset. if { $attr == "dont_write_bytecode" \ - && $exp_state == "off" - && [info exists ::env(PYTHONDONTWRITEBYTECODE)] } { + && $exp_state == "off" \ + && [info exists ::env(PYTHONDONTWRITEBYTECODE)] \ + && $::env(PYTHONDONTWRITEBYTECODE) != "" } { set answer "on" } else { set answer $exp_state @@ -92,6 +93,16 @@ proc test_python_settings { exp_state } { "else:" "" \ " print (\"${attr} is off\")" "" \ "end" "${attr} is ${answer}" + + if { $attr == "dont_write_bytecode" } { + set setting dont-write-bytecode + } else { + set setting ignore-environment + } + set show_setting \ + "Python's $setting setting is $answer." + gdb_test "show python $setting" \ + [string_to_regexp $show_setting] } gdb_exit diff --git a/gdb/testsuite/gdb.python/py-strfns.c b/gdb/testsuite/gdb.python/py-strfns.c index 21988fe..c3b846d 100644 --- a/gdb/testsuite/gdb.python/py-strfns.c +++ b/gdb/testsuite/gdb.python/py-strfns.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2012-2024 Free Software Foundation, Inc. + Copyright 2012-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 diff --git a/gdb/testsuite/gdb.python/py-strfns.exp b/gdb/testsuite/gdb.python/py-strfns.exp index e8180ac..2b5dff19 100644 --- a/gdb/testsuite/gdb.python/py-strfns.exp +++ b/gdb/testsuite/gdb.python/py-strfns.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2024 Free Software Foundation, Inc. +# Copyright (C) 2012-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 diff --git a/gdb/testsuite/gdb.python/py-styled-execute.exp b/gdb/testsuite/gdb.python/py-styled-execute.exp new file mode 100644 index 0000000..0b27c63 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-styled-execute.exp @@ -0,0 +1,109 @@ +# 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/>. + +# Check the the output of gdb.execute can be styled or not depending +# on the value of the third argument passed to gdb.execute. + +require allow_python_tests + +load_lib gdb-python.exp + +# Use gdb.execute() to run CMD passing different argument values. The +# output should match either STYLED_RE or UNSTYLED_RE depending on +# whether the 'styling' argument is True or False. +proc do_gdb_execute { cmd styled_re unstyled_re } { + gdb_test "python gdb.execute('$cmd')" $styled_re + + foreach from_tty { True False } { + gdb_test \ + "python gdb.execute('$cmd', $from_tty)" \ + $styled_re + gdb_test \ + "python gdb.execute('$cmd', $from_tty, False)" \ + $styled_re + gdb_test \ + "python gdb.execute('$cmd', $from_tty, False, True)" \ + $styled_re + gdb_test \ + "python gdb.execute('$cmd', $from_tty, False, False)" \ + $unstyled_re + gdb_test \ + "python print(gdb.execute('$cmd', $from_tty, True), end='')" \ + $unstyled_re + gdb_test \ + "python print(gdb.execute('$cmd', $from_tty, True, False), end='')" \ + $unstyled_re + gdb_test \ + "python print(gdb.execute('$cmd', $from_tty, True, True), end='')" \ + $styled_re + } +} + +# Test that the output from gdb.execute is styled or not based on the +# arguments passed in. +proc test_gdb_execute_styling {} { + clean_restart + + # Two possible outputs, BASIC_RE, the unstyled output text, or + # STYLED_RE, the same things, but with styling applied. + set text "\"version\" style" + set styled_text \ + [style "\"" version][style "version" version][style "\" style" version] + set basic_re "The $text foreground color is: \[^\r\n\]+" + set styled_re "The $styled_text foreground color is: \[^\r\n\]+" + + # The command we'll run. It's output matches the above regexp. + set show_style_version_cmd "show style version foreground" + + # Another command we'll run. The output of this command is never + # styled, but we run this to check that the output doesn't change + # even when gdb.execute() asks for styled, or unstyled output. + set show_style_enabled_cmd "show style enabled" + + with_test_prefix "with style enabled on" { + do_gdb_execute $show_style_version_cmd $styled_re $basic_re + + # This time, print the value of 'show style enabled'. This + # output is unstyled, so there's only one regexp. The + # interesting thing here is that we don't expect the output to + # change, even when gdb.execute() is printing unstyled output. + # The "styling=False" argument to gdb.execute() is separate to + # the 'set style enabled on|off' setting. + set re "CLI output styling is enabled\\." + do_gdb_execute $show_style_enabled_cmd $re $re + } + + gdb_test_no_output "set style enabled off" + + with_test_prefix "with style enabled off" { + # With 'set style enabled off' in use, even a request to + # gdb.execute() to produce styled output should produce + # unstyled output. The assumption is that 'set style enabled + # off' is done by the user, while the gdb.execute() is likely + # from some Python extension. The users request for no + # styling overrules the extensions request for styled output. + do_gdb_execute $show_style_version_cmd $basic_re $basic_re + + # Now check that even when we request styled output, the 'show + # style enabled' value is always reported as disabled. + set re "CLI output styling is disabled\\." + do_gdb_execute $show_style_enabled_cmd $re $re + } +} + +# Run the tests. +with_ansi_styling_terminal { + test_gdb_execute_styling +} diff --git a/gdb/testsuite/gdb.python/py-sym-artificial.exp b/gdb/testsuite/gdb.python/py-sym-artificial.exp new file mode 100644 index 0000000..e26e9d2 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-sym-artificial.exp @@ -0,0 +1,62 @@ +# Copyright (C) 2024-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 gdb.Symbol.artificial. + +load_lib dwarf.exp +load_lib gdb-python.exp + +require dwarf2_support allow_python_tests + +# Just use a no-op main. +standard_testfile py-arch.c -dw.S + +set asm_file [standard_output_file ${srcfile2}] +Dwarf::assemble $asm_file { + cu {} { + compile_unit { + {language @DW_LANG_C} + {name py-sym-artificial.c} + } { + declare_labels signed + + signed: DW_TAG_base_type { + {DW_AT_byte_size 1 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_signed} + {DW_AT_name bool} + } + + DW_TAG_variable { + {name the_variable} + {DW_AT_type :$signed} + {artificial 1 DW_FORM_flag_present} + } + } + } +} + +if {[prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug}]} { + return -1 +} + +if {![runto_main]} { + return -1 +} + +gdb_py_test_silent_cmd "python v = gdb.lookup_symbol('the_variable')" \ + "get variable" 1 +gdb_test "python print(v\[0\].is_artificial)" True \ + "variable is artificial" diff --git a/gdb/testsuite/gdb.python/py-symbol-2.c b/gdb/testsuite/gdb.python/py-symbol-2.c index c895159..806bcca 100644 --- a/gdb/testsuite/gdb.python/py-symbol-2.c +++ b/gdb/testsuite/gdb.python/py-symbol-2.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2019-2024 Free Software Foundation, Inc. + Copyright 2019-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 diff --git a/gdb/testsuite/gdb.python/py-symbol-3.c b/gdb/testsuite/gdb.python/py-symbol-3.c new file mode 100644 index 0000000..181c3fc --- /dev/null +++ b/gdb/testsuite/gdb.python/py-symbol-3.c @@ -0,0 +1,20 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024-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/>. */ + +/* A global 'rr' -- used for testing that lookup_static_symbols does + not find it. */ +int __attribute__ ((used)) rr = 107; diff --git a/gdb/testsuite/gdb.python/py-symbol.c b/gdb/testsuite/gdb.python/py-symbol.c index 57fce1e..41cc60d 100644 --- a/gdb/testsuite/gdb.python/py-symbol.c +++ b/gdb/testsuite/gdb.python/py-symbol.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 @@ -44,6 +44,7 @@ extern void function_in_other_file (void); int qq = 72; /* line of qq */ static int __attribute__ ((used)) rr = 42; /* line of rr */ +static int __attribute__ ((used)) qqrr = 42; int func (int arg) { diff --git a/gdb/testsuite/gdb.python/py-symbol.exp b/gdb/testsuite/gdb.python/py-symbol.exp index c174ba4..55cdebe 100644 --- a/gdb/testsuite/gdb.python/py-symbol.exp +++ b/gdb/testsuite/gdb.python/py-symbol.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 @@ -20,11 +20,11 @@ load_lib gdb-python.exp require allow_python_tests -standard_testfile py-symbol.c py-symbol-2.c +standard_testfile py-symbol.c py-symbol-2.c py-symbol-3.c set opts { debug additional_flags=-DUSE_TWO_FILES } if {[prepare_for_testing "failed to prepare" $testfile \ - [list $srcfile $srcfile2] $opts]} { + [list $srcfile $srcfile2 $srcfile3] $opts]} { return -1 } @@ -36,6 +36,13 @@ set readnow_p [readnow] gdb_test "python print (len (gdb.lookup_static_symbols ('rr')))" \ "2" "print (len (gdb.lookup_static_symbols ('rr')))" +# This test does not make sense when readnow is in effect. +if {!$readnow_p} { + # Make sure that the global symbol's symtab was not expanded. + gdb_test_no_output "pipe maint info symtab | grep \"name.*py-symbol-3.c\"" \ + "global rr symtab was not expanded" +} + # Restart so we don't have expanded symtabs after the previous test. clean_restart ${binfile} @@ -65,7 +72,7 @@ gdb_test "python print (gdb.lookup_global_symbol('qq').needs_frame)" \ # Similarly, test looking up a static symbol before we runto_main. set rr_line [gdb_get_line_number "line of rr"] set rr_line_alt [gdb_get_line_number "line of other rr" py-symbol-2.c] -gdb_test "python print (gdb.lookup_global_symbol ('rr') is None)" "True" \ +gdb_test "python print (gdb.lookup_global_symbol ('qqrr') is None)" "True" \ "lookup_global_symbol for static var" set cmd "python print (gdb.lookup_static_symbol ('rr').line)" @@ -135,16 +142,19 @@ gdb_test "python print (func.name)" "func" "test func.name" gdb_test "python print (func.print_name)" "func" "test func.print_name" gdb_test "python print (func.linkage_name)" "func" "test func.linkage_name" gdb_test "python print (func.addr_class == gdb.SYMBOL_LOC_BLOCK)" "True" "test func.addr_class" +gdb_test "python print (func.domain == gdb.SYMBOL_FUNCTION_DOMAIN)" "True" "test func.domain" # Stop in a second file and ensure we find its local static symbol. gdb_breakpoint "function_in_other_file" gdb_continue_to_breakpoint "function_in_other_file" gdb_test "python print (gdb.lookup_static_symbol ('rr').value ())" "99" \ "print value of rr from other file" -gdb_test "python print (gdb.lookup_static_symbols ('rr')\[0\].value ())" "99" \ - "print value of gdb.lookup_static_symbols ('rr')\[0\], from the other file" -gdb_test "python print (gdb.lookup_static_symbols ('rr')\[1\].value ())" "42" \ - "print value of gdb.lookup_static_symbols ('rr')\[1\], from the other file" +# GDB doesn't really guarantee the order of these, so sort the values. +gdb_test_no_output "python rrs = gdb.lookup_static_symbols ('rr')" \ + "fetch all rr symbols, from the other file" +gdb_test "python print (sorted(\[int(x.value()) for x in rrs\]))" \ + "\\\[42, 99\\\]" \ + "print values of all 'rr' symbols, from the other file" # Now continue back to the first source file. set linenum [gdb_get_line_number "Break at end."] @@ -156,10 +166,12 @@ gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0 # static symbol from the second source file. gdb_test "python print (gdb.lookup_static_symbol ('rr').value ())" "42" \ "print value of rr from main file" -gdb_test "python print (gdb.lookup_static_symbols ('rr')\[0\].value ())" "99" \ - "print value of gdb.lookup_static_symbols ('rr')\[0\], from the main file" -gdb_test "python print (gdb.lookup_static_symbols ('rr')\[1\].value ())" "42" \ - "print value of gdb.lookup_static_symbols ('rr')\[1\], from the main file" +# This should be consistent with the first file. +gdb_test_no_output "python rrs = gdb.lookup_static_symbols ('rr')" \ + "fetch all rr symbols, from the main file" +gdb_test "python print (sorted(\[int(x.value()) for x in rrs\]))" \ + "\\\[42, 99\\\]" \ + "print values of all 'rr' symbols, from the main file" # Test is_variable attribute. gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0 diff --git a/gdb/testsuite/gdb.python/py-symtab.exp b/gdb/testsuite/gdb.python/py-symtab.exp index 4765ef5..a4891f3 100644 --- a/gdb/testsuite/gdb.python/py-symtab.exp +++ b/gdb/testsuite/gdb.python/py-symtab.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2010-2024 Free Software Foundation, Inc. +# Copyright (C) 2010-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 @@ -90,6 +90,34 @@ gdb_test_multiple "python print (\"simple_struct\" in static_symbols)" \ } } +# Test symtab identity +gdb_test "python print (symtab is symtab)"\ + "True" \ + "test symtab identity 1" +gdb_test "python print (symtab is gdb.selected_frame().find_sal().symtab)"\ + "True" \ + "test symtab identity 2" +gdb_test "python print (sal.symtab is gdb.selected_frame().find_sal().symtab)"\ + "True" \ + "test symtab identity 3" +gdb_test "python print (symtab is not \"xxx\")"\ + "True" \ + "test symtab non-identity with non-symtab" + +# Test symtab equality +gdb_test "python print (symtab == symtab)"\ + "True" \ + "test symtab equality 1" +gdb_test "python print (symtab == gdb.selected_frame().find_sal().symtab)"\ + "True" \ + "test symtab equality 2" +gdb_test "python print (sal.symtab == gdb.selected_frame().find_sal().symtab)"\ + "True" \ + "test symtab equality 3" +gdb_test "python print (symtab != \"xxx\")"\ + "True" \ + "test symtab non-equality with non-symtab" + # Test is_valid when the objfile is unloaded. This must be the last # test as it unloads the object file in GDB. gdb_unload diff --git a/gdb/testsuite/gdb.python/py-sync-interp.c b/gdb/testsuite/gdb.python/py-sync-interp.c index 9dabd28..f5fef95 100644 --- a/gdb/testsuite/gdb.python/py-sync-interp.c +++ b/gdb/testsuite/gdb.python/py-sync-interp.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2013-2024 Free Software Foundation, Inc. + Copyright 2013-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 diff --git a/gdb/testsuite/gdb.python/py-sync-interp.exp b/gdb/testsuite/gdb.python/py-sync-interp.exp index 9db7853..ea91cb2 100644 --- a/gdb/testsuite/gdb.python/py-sync-interp.exp +++ b/gdb/testsuite/gdb.python/py-sync-interp.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2024 Free Software Foundation, Inc. +# Copyright (C) 2013-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 diff --git a/gdb/testsuite/gdb.python/py-template.cc b/gdb/testsuite/gdb.python/py-template.cc index 73b4982..4c306ac 100644 --- a/gdb/testsuite/gdb.python/py-template.cc +++ b/gdb/testsuite/gdb.python/py-template.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2008-2024 Free Software Foundation, Inc. + Copyright 2008-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 diff --git a/gdb/testsuite/gdb.python/py-template.exp b/gdb/testsuite/gdb.python/py-template.exp index bba80e3..a0f9d80 100644 --- a/gdb/testsuite/gdb.python/py-template.exp +++ b/gdb/testsuite/gdb.python/py-template.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 diff --git a/gdb/testsuite/gdb.python/py-thread-exited.c b/gdb/testsuite/gdb.python/py-thread-exited.c index 3af93f9..dd859ce 100644 --- a/gdb/testsuite/gdb.python/py-thread-exited.c +++ b/gdb/testsuite/gdb.python/py-thread-exited.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2022-2024 Free Software Foundation, Inc. + Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-thread-exited.exp b/gdb/testsuite/gdb.python/py-thread-exited.exp index dda8470..dcacb11 100644 --- a/gdb/testsuite/gdb.python/py-thread-exited.exp +++ b/gdb/testsuite/gdb.python/py-thread-exited.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 diff --git a/gdb/testsuite/gdb.python/py-thread-exited.py b/gdb/testsuite/gdb.python/py-thread-exited.py index f813271..ef5a244 100644 --- a/gdb/testsuite/gdb.python/py-thread-exited.py +++ b/gdb/testsuite/gdb.python/py-thread-exited.py @@ -1,4 +1,4 @@ -# Copyright 2022-2024 Free Software Foundation, Inc. +# Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-thrhandle.c b/gdb/testsuite/gdb.python/py-thrhandle.c index f6dd6d2..69c0aaf 100644 --- a/gdb/testsuite/gdb.python/py-thrhandle.c +++ b/gdb/testsuite/gdb.python/py-thrhandle.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2017-2024 Free Software Foundation, Inc. + Copyright 2017-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 diff --git a/gdb/testsuite/gdb.python/py-thrhandle.exp b/gdb/testsuite/gdb.python/py-thrhandle.exp index 702a3a5..343bf4b 100644 --- a/gdb/testsuite/gdb.python/py-thrhandle.exp +++ b/gdb/testsuite/gdb.python/py-thrhandle.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2024 Free Software Foundation, Inc. +# Copyright (C) 2017-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 diff --git a/gdb/testsuite/gdb.python/py-type.c b/gdb/testsuite/gdb.python/py-type.c index 7a0df8a..cc5fcb2 100644 --- a/gdb/testsuite/gdb.python/py-type.c +++ b/gdb/testsuite/gdb.python/py-type.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2009-2024 Free Software Foundation, Inc. + Copyright 2009-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 diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp index e524959..0bc4556 100644 --- a/gdb/testsuite/gdb.python/py-type.exp +++ b/gdb/testsuite/gdb.python/py-type.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2009-2024 Free Software Foundation, Inc. +# Copyright (C) 2009-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 @@ -57,10 +57,10 @@ proc test_fields {lang} { if {$lang == "c++"} { # Test usage with a class - gdb_py_test_silent_cmd "print (c)" "print value (c)" 1 + gdb_py_test_silent_cmd "print (c)" "print value(c)" 1 gdb_py_test_silent_cmd "python c = gdb.history (0)" "get value (c) from history" 1 gdb_py_test_silent_cmd "python fields = c.type.fields()" "get fields from c.type" 1 - gdb_test "python print (len(fields))" "2" "check number of fields (c)" + gdb_test "python print (len(fields))" "2" "check number of fields, c" gdb_test "python print (fields\[0\].name)" "c" "check class field c name" gdb_test "python print (fields\[1\].name)" "d" "check class field d name" @@ -94,12 +94,12 @@ proc test_fields {lang} { } # Test normal fields usage in structs. - gdb_py_test_silent_cmd "print (st)" "print value (st)" 1 + gdb_py_test_silent_cmd "print (st)" "print value(st)" 1 gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value (st) from history" 1 gdb_py_test_silent_cmd "python fields = st.type.fields()" "get fields from st.type" 1 gdb_test "python print (st.type.objfile.filename == gdb.current_progspace ().filename)" "True" \ "check type.objfile" - gdb_test "python print (len(fields))" "2" "check number of fields (st)" + gdb_test "python print (len(fields))" "2" "check number of fields, st" gdb_test "python print (fields\[0\].name)" "a" "check structure field a name" gdb_test "python print (fields\[1\].name)" "b" "check structure field b name" @@ -118,7 +118,7 @@ proc test_fields {lang} { "Check that dir includes name" # Test Python mapping behavior of gdb.Type for structs/classes - gdb_test "python print (len(st.type))" "2" "check number of fields (st.type)" + gdb_test "python print (len(st.type))" "2" "check number of fields, st.type" gdb_test "python print (st.type\['a'\].name)" "a" "check fields lookup by name" gdb_test "python print (\[v.bitpos for v in st.type.itervalues()\])" {\[0L?, 32L?\]} "Check fields iteration over values" gdb_test "python print (\[(n, v.bitpos) for (n, v) in st.type.items()\])" {\[\('a', 0L?\), \('b', 32L?\)\]} "Check fields items list" @@ -136,7 +136,7 @@ proc test_fields {lang} { gdb_test "python print (not not st.type\['a'\].type)" "True" # Test regression PR python/10805 - gdb_py_test_silent_cmd "print (ar)" "print value (ar)" 1 + gdb_py_test_silent_cmd "print (ar)" "print value(ar)" 1 gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) from history" 1 gdb_test "python fields = ar.type.fields()" gdb_test "python print (len(fields))" "1" "check the number of fields" @@ -153,10 +153,10 @@ proc test_fields {lang} { # Test gdb.Type.vector. # Note: vectors cast differently than arrays. Here ar[0] is replicated # for the size of the vector. - gdb_py_test_silent_cmd "print (vec_data_1)" "print value (vec_data_1)" 1 + gdb_py_test_silent_cmd "print (vec_data_1)" "print value(vec_data_1)" 1 gdb_py_test_silent_cmd "python vec_data_1 = gdb.history (0)" "get value (vec_data_1) from history" 1 - gdb_py_test_silent_cmd "print (vec_data_2)" "print value (vec_data_2)" 1 + gdb_py_test_silent_cmd "print (vec_data_2)" "print value(vec_data_2)" 1 gdb_py_test_silent_cmd "python vec_data_2 = gdb.history (0)" "get value (vec_data_2) from history" 1 gdb_py_test_silent_cmd "python vec1 = vec_data_1.cast(ar\[0\].type.vector(1))" "set vec1" 1 @@ -179,7 +179,7 @@ proc test_fields {lang} { proc test_enums {} { with_test_prefix "test_enum" { - gdb_py_test_silent_cmd "print (e)" "print value (e)" 1 + gdb_py_test_silent_cmd "print (e)" "print value(e)" 1 gdb_py_test_silent_cmd "python (e) = gdb.history (0)" "get value (e) from history" 1 gdb_py_test_silent_cmd "python fields = e.type.fields()" "extract type fields from e" 1 gdb_test "python print (len(fields))" "3" "check the number of enum fields" @@ -188,8 +188,8 @@ proc test_enums {} { # Ditto but by mapping operations gdb_test "python print (len(e.type))" "3" "check the number of type fields" - gdb_test "python print (e.type\['v1'\].name)" "v1" "check enum field lookup by name (v1)" - gdb_test "python print (e.type\['v3'\].name)" "v3" "check enum field lookup by name (v3)" + gdb_test "python print (e.type\['v1'\].name)" "v1" "check enum field lookup by name, v1" + gdb_test "python print (e.type\['v3'\].name)" "v3" "check enum field lookup by name, v3" gdb_test "python print (\[v.enumval for v in e.type.itervalues()\])" {\[0L?, 1L?, 2L?\]} "Check num fields iteration over values" gdb_test "python print (\[(n, v.enumval) for (n, v) in e.type.items()\])" {\[\('v1', 0L?\), \('v2', 1L?\), \('v3', 2L?\)\]} "Check enum fields items list" } @@ -197,12 +197,12 @@ proc test_enums {} { proc test_base_class {} { with_test_prefix "test_base_class" { - gdb_py_test_silent_cmd "print (d)" "print value (d)" 1 + gdb_py_test_silent_cmd "print (d)" "print value(d)" 1 gdb_py_test_silent_cmd "python d = gdb.history (0)" "get value (d) from history" 1 gdb_py_test_silent_cmd "python fields = d.type.fields()" "extract type fields from d" 1 gdb_test "python print (len(fields))" "3" "check the number of fields" - gdb_test "python print (fields\[0\].is_base_class)" "True" "check base class (fields\[0\])" - gdb_test "python print (fields\[1\].is_base_class)" "False" "check base class (fields\[1\])" + gdb_test "python print (fields\[0\].is_base_class)" "True" {check base class, fields[0]} + gdb_test "python print (fields\[1\].is_base_class)" "False" {check base class, fields[1]} } } @@ -210,7 +210,7 @@ proc test_range {} { with_test_prefix "test_range" { with_test_prefix "on ranged value" { # Test a valid range request. - gdb_py_test_silent_cmd "print (ar)" "print value (ar)" 1 + gdb_py_test_silent_cmd "print (ar)" "print value(ar)" 1 gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) from history" 1 gdb_test "python print (len(ar.type.range()))" "2" "check correct tuple length" gdb_test "python print (ar.type.range()\[0\])" "0" "check range low bound" @@ -219,7 +219,7 @@ proc test_range {} { with_test_prefix "on ranged type" { # Test a range request on a ranged type. - gdb_py_test_silent_cmd "print (ar)" "print value (ar)" 1 + gdb_py_test_silent_cmd "print (ar)" "print value(ar)" 1 gdb_py_test_silent_cmd "python ar = gdb.history (0)" "get value (ar) from history" 1 gdb_py_test_silent_cmd "python fields = ar.type.fields()" "get fields" 1 gdb_test "python print (fields\[0\].type.range()\[0\])" "0" "check range low bound" @@ -228,7 +228,7 @@ proc test_range {} { with_test_prefix "on unranged value" { # Test where a range does not exist. - gdb_py_test_silent_cmd "print (st)" "print value (st)" 1 + gdb_py_test_silent_cmd "print (st)" "print value(st)" 1 gdb_py_test_silent_cmd "python st = gdb.history (0)" "get value (st) from history" 1 gdb_test "python print (st.type.range())" "RuntimeError.*: This type does not have a range.*" "check range for non ranged type." } @@ -324,6 +324,19 @@ proc test_type_equality {} { } } +# Test type identity +proc test_type_identity {} { + gdb_test_no_output "python v1 = gdb.parse_and_eval('global_unsigned_int')" + gdb_test_no_output "python v2 = gdb.parse_and_eval('global_unsigned_int')" + + gdb_test "python print(v1.type is v2.type)" "True" + + gdb_test_no_output "python t1 = gdb.lookup_type ('char')" + gdb_test_no_output "python t2 = gdb.lookup_type ('char')" + + gdb_test "python print(t1 is t2)" "True" +} + # Test the gdb.Type.is_scalar property. proc test_is_scalar { lang } { if {$lang == "c++"} { @@ -376,6 +389,7 @@ if { [build_inferior "${binfile}" "c"] == 0 } { test_is_scalar "c" test_is_signed "c" test_type_equality + test_type_identity } } @@ -392,6 +406,7 @@ if { [build_inferior "${binfile}-cxx" "c++"] == 0 } { test_is_scalar "c++" test_is_signed "c++" test_type_equality + test_type_identity } } diff --git a/gdb/testsuite/gdb.python/py-typeprint.cc b/gdb/testsuite/gdb.python/py-typeprint.cc index af06b54..b77bd8a 100644 --- a/gdb/testsuite/gdb.python/py-typeprint.cc +++ b/gdb/testsuite/gdb.python/py-typeprint.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2008-2024 Free Software Foundation, Inc. + Copyright 2008-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 diff --git a/gdb/testsuite/gdb.python/py-typeprint.exp b/gdb/testsuite/gdb.python/py-typeprint.exp index 5fafe26..74d755f 100644 --- a/gdb/testsuite/gdb.python/py-typeprint.exp +++ b/gdb/testsuite/gdb.python/py-typeprint.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2024 Free Software Foundation, Inc. +# Copyright (C) 2012-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 diff --git a/gdb/testsuite/gdb.python/py-typeprint.py b/gdb/testsuite/gdb.python/py-typeprint.py index 0fd2f0e..dc13210 100644 --- a/gdb/testsuite/gdb.python/py-typeprint.py +++ b/gdb/testsuite/gdb.python/py-typeprint.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2024 Free Software Foundation, Inc. +# Copyright (C) 2012-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 diff --git a/gdb/testsuite/gdb.python/py-unwind-inline.c b/gdb/testsuite/gdb.python/py-unwind-inline.c index 6511a6b..1143e52 100644 --- a/gdb/testsuite/gdb.python/py-unwind-inline.c +++ b/gdb/testsuite/gdb.python/py-unwind-inline.c @@ -1,4 +1,4 @@ -/* Copyright 2019-2024 Free Software Foundation, Inc. +/* Copyright 2019-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 diff --git a/gdb/testsuite/gdb.python/py-unwind-inline.exp b/gdb/testsuite/gdb.python/py-unwind-inline.exp index 1ba1c14..74d4ead 100644 --- a/gdb/testsuite/gdb.python/py-unwind-inline.exp +++ b/gdb/testsuite/gdb.python/py-unwind-inline.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2020-2024 Free Software Foundation, Inc. +# Copyright (C) 2020-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 diff --git a/gdb/testsuite/gdb.python/py-unwind-inline.py b/gdb/testsuite/gdb.python/py-unwind-inline.py index b0a8083..ca6b16e 100644 --- a/gdb/testsuite/gdb.python/py-unwind-inline.py +++ b/gdb/testsuite/gdb.python/py-unwind-inline.py @@ -1,4 +1,4 @@ -# Copyright (C) 2020-2024 Free Software Foundation, Inc. +# Copyright (C) 2020-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 diff --git a/gdb/testsuite/gdb.python/py-unwind-maint.c b/gdb/testsuite/gdb.python/py-unwind-maint.c index 80dc9d9..1b99849 100644 --- a/gdb/testsuite/gdb.python/py-unwind-maint.c +++ b/gdb/testsuite/gdb.python/py-unwind-maint.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2015-2024 Free Software Foundation, Inc. + Copyright 2015-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 diff --git a/gdb/testsuite/gdb.python/py-unwind-maint.exp b/gdb/testsuite/gdb.python/py-unwind-maint.exp index 9e525f6..d9450ef 100644 --- a/gdb/testsuite/gdb.python/py-unwind-maint.exp +++ b/gdb/testsuite/gdb.python/py-unwind-maint.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2024 Free Software Foundation, Inc. +# Copyright (C) 2015-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 diff --git a/gdb/testsuite/gdb.python/py-unwind-maint.py b/gdb/testsuite/gdb.python/py-unwind-maint.py index 1d049a9..4a109d5 100644 --- a/gdb/testsuite/gdb.python/py-unwind-maint.py +++ b/gdb/testsuite/gdb.python/py-unwind-maint.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2024 Free Software Foundation, Inc. +# Copyright (C) 2015-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 diff --git a/gdb/testsuite/gdb.python/py-unwind-user-regs.c b/gdb/testsuite/gdb.python/py-unwind-user-regs.c index be7b2fd..edd9284 100644 --- a/gdb/testsuite/gdb.python/py-unwind-user-regs.c +++ b/gdb/testsuite/gdb.python/py-unwind-user-regs.c @@ -1,6 +1,6 @@ /* This test program is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/py-unwind-user-regs.exp b/gdb/testsuite/gdb.python/py-unwind-user-regs.exp index b27e038..1a464f0 100644 --- a/gdb/testsuite/gdb.python/py-unwind-user-regs.exp +++ b/gdb/testsuite/gdb.python/py-unwind-user-regs.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-unwind-user-regs.py b/gdb/testsuite/gdb.python/py-unwind-user-regs.py index 7e331a8..c6a56b8 100644 --- a/gdb/testsuite/gdb.python/py-unwind-user-regs.py +++ b/gdb/testsuite/gdb.python/py-unwind-user-regs.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/py-unwind.c b/gdb/testsuite/gdb.python/py-unwind.c index 81132f4..f785c5e 100644 --- a/gdb/testsuite/gdb.python/py-unwind.c +++ b/gdb/testsuite/gdb.python/py-unwind.c @@ -1,6 +1,6 @@ /* This test program is part of GDB, the GNU debugger. - Copyright 2015-2024 Free Software Foundation, Inc. + Copyright 2015-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 diff --git a/gdb/testsuite/gdb.python/py-unwind.exp b/gdb/testsuite/gdb.python/py-unwind.exp index d5efc02..b416c2f 100644 --- a/gdb/testsuite/gdb.python/py-unwind.exp +++ b/gdb/testsuite/gdb.python/py-unwind.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2024 Free Software Foundation, Inc. +# Copyright (C) 2015-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 @@ -245,6 +245,13 @@ with_test_prefix "frame-id 'pc' is invalid" { "Python Exception <class 'ValueError'>: invalid literal for int\\(\\) with base 10: 'xyz'\r\n.*" } +with_test_prefix "bad object unwinder" { + gdb_test_no_output "python obj = bad_object_unwinder(\"bad-object\")" + gdb_test_no_output "python gdb.unwinder.register_unwinder(None, obj, replace=True)" + gdb_test "backtrace" \ + "Python Exception <class 'gdb.error'>: an Unwinder should return gdb.UnwindInfo, not Blah\\.\r\n.*" +} + # Gather information about every frame. gdb_test_no_output "python capture_all_frame_information()" gdb_test_no_output "python gdb.newest_frame().select()" diff --git a/gdb/testsuite/gdb.python/py-unwind.py b/gdb/testsuite/gdb.python/py-unwind.py index 62bfb09..0faccf2 100644 --- a/gdb/testsuite/gdb.python/py-unwind.py +++ b/gdb/testsuite/gdb.python/py-unwind.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2024 Free Software Foundation, Inc. +# Copyright (C) 2015-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 @@ -267,4 +267,24 @@ class validating_unwinder(Unwinder): return None +class bad_object_unwinder(Unwinder): + def __init__(self, name): + super().__init__(name) + + def __call__(self, pending_frame): + + if pending_frame.level() != 1: + return None + + class Blah: + def __init__(self): + pass + + @property + def __class__(self): + raise RuntimeError("error in Blah.__class__") + + return Blah() + + print("Python script imported") diff --git a/gdb/testsuite/gdb.python/py-value-cc.cc b/gdb/testsuite/gdb.python/py-value-cc.cc index 08b9915..1a70943 100644 --- a/gdb/testsuite/gdb.python/py-value-cc.cc +++ b/gdb/testsuite/gdb.python/py-value-cc.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2012-2024 Free Software Foundation, Inc. + Copyright 2012-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 diff --git a/gdb/testsuite/gdb.python/py-value-cc.exp b/gdb/testsuite/gdb.python/py-value-cc.exp index b096c75..3d371bc 100644 --- a/gdb/testsuite/gdb.python/py-value-cc.exp +++ b/gdb/testsuite/gdb.python/py-value-cc.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2024 Free Software Foundation, Inc. +# Copyright (C) 2012-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 diff --git a/gdb/testsuite/gdb.python/py-value.c b/gdb/testsuite/gdb.python/py-value.c index c9da6c2..a822346 100644 --- a/gdb/testsuite/gdb.python/py-value.c +++ b/gdb/testsuite/gdb.python/py-value.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2008-2024 Free Software Foundation, Inc. + Copyright 2008-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 diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp index 8ab867a..93985a9 100644 --- a/gdb/testsuite/gdb.python/py-value.exp +++ b/gdb/testsuite/gdb.python/py-value.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 diff --git a/gdb/testsuite/gdb.python/py-varobj.c b/gdb/testsuite/gdb.python/py-varobj.c index da72f9a..6117b35 100644 --- a/gdb/testsuite/gdb.python/py-varobj.c +++ b/gdb/testsuite/gdb.python/py-varobj.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2023-2024 Free Software Foundation, Inc. + Copyright 2023-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 diff --git a/gdb/testsuite/gdb.python/py-varobj.exp b/gdb/testsuite/gdb.python/py-varobj.exp index 4e0e64e..7fb45f9 100644 --- a/gdb/testsuite/gdb.python/py-varobj.exp +++ b/gdb/testsuite/gdb.python/py-varobj.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/py-varobj.py b/gdb/testsuite/gdb.python/py-varobj.py index 9401514..3699bdf 100644 --- a/gdb/testsuite/gdb.python/py-varobj.py +++ b/gdb/testsuite/gdb.python/py-varobj.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/py-warning.exp b/gdb/testsuite/gdb.python/py-warning.exp new file mode 100644 index 0000000..6b26a4e --- /dev/null +++ b/gdb/testsuite/gdb.python/py-warning.exp @@ -0,0 +1,63 @@ +# 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/>. + +# Test the gdb.warning() function. + +load_lib gdb-python.exp + +require allow_python_tests + +clean_restart + +# Basic usage. +gdb_test "python gdb.warning(\"some text\")" \ + "warning: some text" + +# Basic usage with named argument. +gdb_test "python gdb.warning(text=\"a warning message\")" \ + "warning: a warning message" + +# Make sure GDB prints format specifiers correctly. +gdb_test "python gdb.warning(\"%s %d %p\")" \ + "warning: %s %d %p" + +# Empty string gives an error. +gdb_test "python gdb.warning(\"\")" \ + [multi_line \ + "Python Exception <class 'ValueError'>: Empty text string passed to gdb\\.warning" \ + "Error occurred in Python: Empty text string passed to gdb\\.warning"] + +# Missing argument gives an error. +set re1 \ + [multi_line \ + [string_to_regexp \ + [concat \ + "Python Exception <class 'TypeError'>:" \ + "function missing required argument 'text' (pos 1)"]] \ + [string_to_regexp \ + [concat \ + "Error occurred in Python:" \ + "function missing required argument 'text' (pos 1)"]]] +set re2 \ + [multi_line \ + [string_to_regexp \ + [concat \ + "Python Exception <class 'TypeError'>:" \ + "Required argument 'text' (pos 1) not found"]] \ + [string_to_regexp \ + [concat \ + "Error occurred in Python:" \ + "Required argument 'text' (pos 1) not found"]]] +gdb_test "python gdb.warning()" $re1|$re2 diff --git a/gdb/testsuite/gdb.python/py-watchpoint.c b/gdb/testsuite/gdb.python/py-watchpoint.c index 05748b0..9b05601 100644 --- a/gdb/testsuite/gdb.python/py-watchpoint.c +++ b/gdb/testsuite/gdb.python/py-watchpoint.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2022-2024 Free Software Foundation, Inc. + Copyright 2022-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 diff --git a/gdb/testsuite/gdb.python/py-watchpoint.exp b/gdb/testsuite/gdb.python/py-watchpoint.exp index a3c0d7d..ea21020 100644 --- a/gdb/testsuite/gdb.python/py-watchpoint.exp +++ b/gdb/testsuite/gdb.python/py-watchpoint.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 @@ -25,7 +25,7 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} { require allow_python_tests -if ![runto_main] then { +if {![runto_main]} { return } diff --git a/gdb/testsuite/gdb.python/py-watchpoint.py b/gdb/testsuite/gdb.python/py-watchpoint.py index dbb2bfe..d25826f 100644 --- a/gdb/testsuite/gdb.python/py-watchpoint.py +++ b/gdb/testsuite/gdb.python/py-watchpoint.py @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 diff --git a/gdb/testsuite/gdb.python/py-xmethods.cc b/gdb/testsuite/gdb.python/py-xmethods.cc index 52fa2ff..336762e 100644 --- a/gdb/testsuite/gdb.python/py-xmethods.cc +++ b/gdb/testsuite/gdb.python/py-xmethods.cc @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2014-2024 Free Software Foundation, Inc. + Copyright 2014-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 @@ -137,7 +137,7 @@ G<T>::mul (const T1 t1) return t1 * t; } -} // namespace dop +} /* namespace dop */ using namespace dop; diff --git a/gdb/testsuite/gdb.python/py-xmethods.exp b/gdb/testsuite/gdb.python/py-xmethods.exp index 1ff7067..3dafe0e 100644 --- a/gdb/testsuite/gdb.python/py-xmethods.exp +++ b/gdb/testsuite/gdb.python/py-xmethods.exp @@ -1,4 +1,4 @@ -# Copyright 2014-2024 Free Software Foundation, Inc. +# Copyright 2014-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 @@ -179,8 +179,8 @@ gdb_test_no_output "python gdb.set_parameter('max-value-size', 16)" gdb_test "p a1.getarray()" \ "From Python <A_getarray>.*value requires $decimal bytes,\ which is more than max-value-size" \ - "after: a1.getarray (max-value-size)" + "after: a1.getarray, max-value-size" gdb_test "p b1.getarray()" \ "From Python <B_getarray>.*value requires $decimal bytes,\ which is more than max-value-size" \ - "after: b1.getarray (max-value-size)" + "after: b1.getarray, max-value-size" diff --git a/gdb/testsuite/gdb.python/py-xmethods.py b/gdb/testsuite/gdb.python/py-xmethods.py index a2b8d57..33bc41a 100644 --- a/gdb/testsuite/gdb.python/py-xmethods.py +++ b/gdb/testsuite/gdb.python/py-xmethods.py @@ -1,4 +1,4 @@ -# Copyright 2014-2024 Free Software Foundation, Inc. +# Copyright 2014-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 diff --git a/gdb/testsuite/gdb.python/python-1.c b/gdb/testsuite/gdb.python/python-1.c index be736c2..49032ad 100644 --- a/gdb/testsuite/gdb.python/python-1.c +++ b/gdb/testsuite/gdb.python/python-1.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/python.c b/gdb/testsuite/gdb.python/python.c index fda271e..501b25f 100644 --- a/gdb/testsuite/gdb.python/python.c +++ b/gdb/testsuite/gdb.python/python.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2010-2024 Free Software Foundation, Inc. + Copyright 2010-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 diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index 175a6de..6b2f671 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2024 Free Software Foundation, Inc. +# Copyright (C) 2008-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 @@ -561,3 +561,16 @@ if { [use_gdb_stub] == 0 } { } } } + +# Regression test for PR python/32163: several types were not +# previously registered with the module, so could not be inspected +# directly. +foreach type {Instruction LazyString Membuf Record RecordFunctionSegment \ + RecordGap RecordInstruction TuiWindow} { + if { $type == "TuiWindow" && ![allow_tui_tests] } { + continue + } + + gdb_test "python print(type(gdb.$type))" "<class 'type'>" \ + "gdb.$type is registered" +} diff --git a/gdb/testsuite/gdb.python/source1 b/gdb/testsuite/gdb.python/source1 index 6d457b5..b704d92 100644 --- a/gdb/testsuite/gdb.python/source1 +++ b/gdb/testsuite/gdb.python/source1 @@ -1,6 +1,6 @@ # This testcase is part of GDB, the GNU debugger. -# Copyright 2008-2024 Free Software Foundation, Inc. +# Copyright 2008-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 diff --git a/gdb/testsuite/gdb.python/source2.py b/gdb/testsuite/gdb.python/source2.py index 79dc1c2..7ca0bb2 100644 --- a/gdb/testsuite/gdb.python/source2.py +++ b/gdb/testsuite/gdb.python/source2.py @@ -1,6 +1,6 @@ # This testcase is part of GDB, the GNU debugger. -# Copyright 2008-2024 Free Software Foundation, Inc. +# Copyright 2008-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 diff --git a/gdb/testsuite/gdb.python/sys-exit.exp b/gdb/testsuite/gdb.python/sys-exit.exp new file mode 100644 index 0000000..878cf93 --- /dev/null +++ b/gdb/testsuite/gdb.python/sys-exit.exp @@ -0,0 +1,69 @@ +# Copyright 2024-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/>. + +# Check that python sys.exit makes gdb exit, with the correct exit status. + +require allow_python_tests + +# Have this code in a proc avoids clashing with runtest variable exit_status. + +proc do_test { n {expected_exit_status ""} {msg ""}} { + if { $expected_exit_status == "" } { + set expected_exit_status $n + } + + with_test_prefix $n { + clean_restart + + # Regression test for PR python/31946. + set seen_message 0 + gdb_test_multiple "python sys.exit ($n)" "python sys.exit" { + -re "\r\n$msg\r\n" { + set seen_message 1 + exp_continue + } + eof { + set wait_status [wait -i $::gdb_spawn_id] + clear_gdb_spawn_id + + verbose -log "GDB process exited with wait status $wait_status" + + set os_error [lindex $wait_status 2] + set exit_status [lindex $wait_status 3] + + gdb_assert \ + { $os_error == 0 \ + && $exit_status == $expected_exit_status } \ + $gdb_test_name + + if { $msg != "" } { + gdb_assert { $seen_message } + } + } + } + } +} + +# Test sys.exit (<int>). +do_test 0 +do_test 1 +do_test 2 + +# Test sys.exit (None). +do_test None 0 + +# Test sys.exit (<string>). +do_test {"Error Message"} 1 "Error Message" +do_test {""} 1 diff --git a/gdb/testsuite/gdb.python/tui-window-disabled.c b/gdb/testsuite/gdb.python/tui-window-disabled.c index 538c9e8..ed650ca 100644 --- a/gdb/testsuite/gdb.python/tui-window-disabled.c +++ b/gdb/testsuite/gdb.python/tui-window-disabled.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.python/tui-window-disabled.exp b/gdb/testsuite/gdb.python/tui-window-disabled.exp index 750520c..afc9570 100644 --- a/gdb/testsuite/gdb.python/tui-window-disabled.exp +++ b/gdb/testsuite/gdb.python/tui-window-disabled.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/tui-window-disabled.py b/gdb/testsuite/gdb.python/tui-window-disabled.py index aef6f2a..8d140c4 100644 --- a/gdb/testsuite/gdb.python/tui-window-disabled.py +++ b/gdb/testsuite/gdb.python/tui-window-disabled.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Free Software Foundation, Inc. +# Copyright (C) 2021-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 diff --git a/gdb/testsuite/gdb.python/tui-window-factory.exp b/gdb/testsuite/gdb.python/tui-window-factory.exp index 5d8189d..4780fe4 100644 --- a/gdb/testsuite/gdb.python/tui-window-factory.exp +++ b/gdb/testsuite/gdb.python/tui-window-factory.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/tui-window-factory.py b/gdb/testsuite/gdb.python/tui-window-factory.py index edd39a4..7593214 100644 --- a/gdb/testsuite/gdb.python/tui-window-factory.py +++ b/gdb/testsuite/gdb.python/tui-window-factory.py @@ -1,4 +1,4 @@ -# Copyright (C) 2023-2024 Free Software Foundation, Inc. +# Copyright (C) 2023-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 diff --git a/gdb/testsuite/gdb.python/tui-window-names.exp b/gdb/testsuite/gdb.python/tui-window-names.exp index 8236fc9..2a8db69 100644 --- a/gdb/testsuite/gdb.python/tui-window-names.exp +++ b/gdb/testsuite/gdb.python/tui-window-names.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2022-2024 Free Software Foundation, Inc. +# Copyright (C) 2022-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 diff --git a/gdb/testsuite/gdb.python/tui-window.exp b/gdb/testsuite/gdb.python/tui-window.exp index e7ff162..744a09a 100644 --- a/gdb/testsuite/gdb.python/tui-window.exp +++ b/gdb/testsuite/gdb.python/tui-window.exp @@ -1,4 +1,4 @@ -# Copyright (C) 2020-2024 Free Software Foundation, Inc. +# Copyright (C) 2020-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 @@ -43,6 +43,9 @@ if {![Term::enter_tui]} { return } +Term::command "python print('tui_enabled=' + str(tui_enabled))" +Term::check_contents "tui start event" "tui_enabled=True" + Term::command "layout test" Term::check_contents "test title" \ "This Is The Title" @@ -63,3 +66,8 @@ Term::resize 51 51 Term::check_contents "Window was updated" "Test: 2" Term::command "layout fail" + +Term::command "tui disable" +gdb_test "python print('tui_enabled=' + str(tui_enabled))" \ + "tui_enabled=False" \ + "tui disable event" diff --git a/gdb/testsuite/gdb.python/tui-window.py b/gdb/testsuite/gdb.python/tui-window.py index d031f72..d03a8ce 100644 --- a/gdb/testsuite/gdb.python/tui-window.py +++ b/gdb/testsuite/gdb.python/tui-window.py @@ -1,4 +1,4 @@ -# Copyright (C) 2020-2024 Free Software Foundation, Inc. +# Copyright (C) 2020-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 @@ -20,6 +20,9 @@ import gdb the_window = None +tui_enabled = False + + class TestWindow: def __init__(self, win): global the_window @@ -62,3 +65,11 @@ def change_window_title(): gdb.register_window_type("fail", failwin) + + +def set_tui_enabled(ev): + global tui_enabled + tui_enabled = ev.enabled + + +gdb.events.tui_enabled.connect(set_tui_enabled) |