]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-autoloaded-pretty-printers-in-newobjfile-event.py
x86 TLS relocation checks
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-autoloaded-pretty-printers-in-newobjfile-event.py
CommitLineData
1d506c26 1# Copyright (C) 2021-2024 Free Software Foundation, Inc.
2c473def
MW
2
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.
7#
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.
12#
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/>.
15
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
19# is called.
20
2c473def
MW
21import os
22
c2cf30e7
TT
23import gdb
24
2c473def
MW
25
26def new_objfile_handler(event):
27 assert isinstance(event, gdb.NewObjFileEvent)
28 objfile = event.new_objfile
29
30 # Only observe the custom test library.
31 libname = "libpy-autoloaded-pretty-printers-in-newobjfile-event"
32 if libname in os.path.basename(objfile.filename):
33 # If everything went well and the pretty-printer auto-load happened
34 # before notifying the Python listeners, we expect to see one pretty
35 # printer, and it must be ours.
36 all_good = (
37 len(objfile.pretty_printers) == 1
38 and objfile.pretty_printers[0].name == "my_library"
39 )
40
41 if all_good:
42 gdb.parse_and_eval("all_good = 1")
43 else:
44 print("Oops, not all good:")
45 print("pretty printer count: {}".format(len(objfile.pretty_printers)))
46
47 for pp in objfile.pretty_printers:
48 print(" - {}".format(pp.name))
49
50
51gdb.events.new_objfile.connect(new_objfile_handler)