GDB (xrefs)
Loading...
Searching...
No Matches
target-connection.c
Go to the documentation of this file.
1/* List of target connections for GDB.
2
3 Copyright (C) 2017-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "target-connection.h"
22
23#include <map>
24
25#include "inferior.h"
26#include "target.h"
27#include "observable.h"
28
29/* A map between connection number and representative process_stratum
30 target. */
31static std::map<int, process_stratum_target *> process_targets;
32
33/* The highest connection number ever given to a target. */
35
36/* See target-connection.h. */
37
38void
47
48/* See target-connection.h. */
49
50void
52{
53 /* Notify about the connection being removed before we reset the
54 connection number to zero. */
57 t->connection_number = 0;
58}
59
60/* See target-connection.h. */
61
62std::string
64{
65 if (t->connection_string () != NULL)
66 return string_printf ("%s %s", t->shortname (),
67 t->connection_string ());
68 else
69 return t->shortname ();
70}
71
72/* Prints the list of target connections and their details on UIOUT.
73
74 If REQUESTED_CONNECTIONS is not NULL, it's a list of GDB ids of the
75 target connections that should be printed. Otherwise, all target
76 connections are printed. */
77
78static void
79print_connection (struct ui_out *uiout, const char *requested_connections)
80{
81 int count = 0;
82 size_t what_len = 0;
83
84 /* Compute number of lines we will print. */
85 for (const auto &it : process_targets)
86 {
87 if (!number_is_in_list (requested_connections, it.first))
88 continue;
89
90 ++count;
91
92 process_stratum_target *t = it.second;
93
94 size_t l = make_target_connection_string (t).length ();
95 if (l > what_len)
96 what_len = l;
97 }
98
99 if (count == 0)
100 {
101 uiout->message (_("No connections.\n"));
102 return;
103 }
104
105 ui_out_emit_table table_emitter (uiout, 4, process_targets.size (),
106 "connections");
107
108 uiout->table_header (1, ui_left, "current", "");
109 uiout->table_header (4, ui_left, "number", "Num");
110 /* The text in the "what" column may include spaces. Add one extra
111 space to visually separate the What and Description columns a
112 little better. Compare:
113 "* 1 remote :9999 Remote serial target in gdb-specific protocol"
114 "* 1 remote :9999 Remote serial target in gdb-specific protocol"
115 */
116 uiout->table_header (what_len + 1, ui_left, "what", "What");
117 uiout->table_header (17, ui_left, "description", "Description");
118
119 uiout->table_body ();
120
121 for (const auto &it : process_targets)
122 {
123 process_stratum_target *t = it.second;
124
125 if (!number_is_in_list (requested_connections, t->connection_number))
126 continue;
127
128 ui_out_emit_tuple tuple_emitter (uiout, NULL);
129
130 if (current_inferior ()->process_target () == t)
131 uiout->field_string ("current", "*");
132 else
133 uiout->field_skip ("current");
134
135 uiout->field_signed ("number", t->connection_number);
136
137 uiout->field_string ("what", make_target_connection_string (t));
138
139 uiout->field_string ("description", t->longname ());
140
141 uiout->text ("\n");
142 }
143}
144
145/* The "info connections" command. */
146
147static void
148info_connections_command (const char *args, int from_tty)
149{
151}
152
154
155void
157{
158 add_info ("connections", info_connections_command,
159 _("\
160Target connections in use.\n\
161Shows the list of target connections currently in use."));
162}
virtual const char * connection_string()
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
Definition ui-out.c:511
void field_signed(const char *fldname, LONGEST value)
Definition ui-out.c:437
void field_skip(const char *fldname)
Definition ui-out.c:499
void text(const char *string)
Definition ui-out.c:566
void table_header(int width, ui_align align, const std::string &col_name, const std::string &col_hdr)
Definition ui-out.c:363
void table_body()
Definition ui-out.c:376
void message(const char *format,...) ATTRIBUTE_PRINTF(2
Definition ui-out.c:774
struct cmd_list_element * add_info(const char *name, cmd_simple_func_ftype *fun, const char *doc)
int number_is_in_list(const char *list, int number)
Definition cli-utils.c:348
struct inferior * current_inferior(void)
Definition inferior.c:55
observable< process_stratum_target * > connection_removed
const char * longname() const
Definition target.h:459
const char * shortname() const
Definition target.h:456
void _initialize_target_connection()
static void info_connections_command(const char *args, int from_tty)
static std::map< int, process_stratum_target * > process_targets
void connection_list_remove(process_stratum_target *t)
void connection_list_add(process_stratum_target *t)
std::string make_target_connection_string(process_stratum_target *t)
static int highest_target_connection_num
static void print_connection(struct ui_out *uiout, const char *requested_connections)
@ ui_left
Definition ui-out.h:45
#define current_uiout
Definition ui-out.h:40