]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.py
1 # Copyright (C) 2021-2023 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file is part of the GDB testsuite. It tests that python pretty
17 # printers defined in a python script that is autoloaded have been
18 # registered when a custom event handler for the new_objfile event
25 def new_objfile_handler(event
):
26 assert isinstance(event
, gdb
.NewObjFileEvent
)
27 objfile
= event
.new_objfile
29 # Only observe the custom test library.
30 libname
= "libpy-autoloaded-pretty-printers-in-newobjfile-event"
31 if libname
in os
.path
.basename(objfile
.filename
):
32 # If everything went well and the pretty-printer auto-load happened
33 # before notifying the Python listeners, we expect to see one pretty
34 # printer, and it must be ours.
36 len(objfile
.pretty_printers
) == 1
37 and objfile
.pretty_printers
[0].name
== "my_library"
41 gdb
.parse_and_eval("all_good = 1")
43 print("Oops, not all good:")
44 print("pretty printer count: {}".format(len(objfile
.pretty_printers
)))
46 for pp
in objfile
.pretty_printers
:
47 print(" - {}".format(pp
.name
))
50 gdb
.events
.new_objfile
.connect(new_objfile_handler
)