]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.multi/multi-target-info-inferiors.py
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.multi / multi-target-info-inferiors.py
1 # Copyright (C) 2021-2024 Free Software Foundation, Inc.
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 import gdb
17
18
19 # Take a gdb.TargetConnection and return the connection number.
20 def conn_num(c):
21 return c.num
22
23
24 # Takes a gdb.TargetConnection and return a string that is either the
25 # type, or the type and details (if the details are not None).
26 def make_target_connection_string(c):
27 if c.details is None:
28 return c.type
29 else:
30 return "%s %s" % (c.type, c.details)
31
32
33 # A Python implementation of 'info connections'. Produce output that
34 # is identical to the output of 'info connections' so we can check
35 # that aspects of gdb.TargetConnection work correctly.
36 def info_connections():
37 all_connections = sorted(gdb.connections(), key=conn_num)
38 current_conn = gdb.selected_inferior().connection
39 what_width = 0
40 for c in all_connections:
41 s = make_target_connection_string(c)
42 if len(s) > what_width:
43 what_width = len(s)
44
45 fmt = " Num %%-%ds Description" % what_width
46 print(fmt % "What")
47 fmt = "%%s%%-3d %%-%ds %%s" % what_width
48 for c in all_connections:
49 if c == current_conn:
50 prefix = "* "
51 else:
52 prefix = " "
53
54 print(fmt % (prefix, c.num, make_target_connection_string(c), c.description))
55
56
57 def inf_num(i):
58 return i.num
59
60
61 # Print information about each inferior, and the connection it is
62 # using.
63 def info_inferiors():
64 all_inferiors = sorted(gdb.inferiors(), key=inf_num)
65 for i in gdb.inferiors():
66 print(
67 "Inferior %d, Connection #%d: %s"
68 % (i.num, i.connection_num, make_target_connection_string(i.connection))
69 )