mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-30 00:52:16 +08:00
Use std::set in mi-main.c
Change a couple of spots in mi-main.c to use std::set. This simplifies the code and removes some cleanups. gdb/ChangeLog 2017-09-29 Tom Tromey <tom@tromey.com> * mi/mi-main.c (struct print_one_inferior_data) <inferiors>: Now a 'std::set *'. (print_one_inferior): Update. (free_vector_of_ints): Remove. (list_available_thread_groups): Change "ids" to std::set. (mi_cmd_list_thread_groups): Update. (struct collect_cores_data) <core>: Now a std::set. (collect_cores): Update. (unique): Remove. (print_one_inferior): Update.
This commit is contained in:
@ -1,3 +1,16 @@
|
|||||||
|
2017-09-29 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* mi/mi-main.c (struct print_one_inferior_data) <inferiors>: Now a
|
||||||
|
'std::set *'.
|
||||||
|
(print_one_inferior): Update.
|
||||||
|
(free_vector_of_ints): Remove.
|
||||||
|
(list_available_thread_groups): Change "ids" to std::set.
|
||||||
|
(mi_cmd_list_thread_groups): Update.
|
||||||
|
(struct collect_cores_data) <core>: Now a std::set.
|
||||||
|
(collect_cores): Update.
|
||||||
|
(unique): Remove.
|
||||||
|
(print_one_inferior): Update.
|
||||||
|
|
||||||
2017-09-29 Tom Tromey <tom@tromey.com>
|
2017-09-29 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* mi/mi-main.c (mi_execute_cli_command): Use std::string.
|
* mi/mi-main.c (mi_execute_cli_command): Use std::string.
|
||||||
|
@ -62,6 +62,8 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include "progspace-and-thread.h"
|
#include "progspace-and-thread.h"
|
||||||
#include "common/rsp-low.h"
|
#include "common/rsp-low.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -610,8 +612,7 @@ mi_cmd_thread_info (const char *command, char **argv, int argc)
|
|||||||
struct collect_cores_data
|
struct collect_cores_data
|
||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
|
std::set<int> cores;
|
||||||
VEC (int) *cores;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -624,27 +625,16 @@ collect_cores (struct thread_info *ti, void *xdata)
|
|||||||
int core = target_core_of_thread (ti->ptid);
|
int core = target_core_of_thread (ti->ptid);
|
||||||
|
|
||||||
if (core != -1)
|
if (core != -1)
|
||||||
VEC_safe_push (int, data->cores, core);
|
data->cores.insert (core);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int *
|
|
||||||
unique (int *b, int *e)
|
|
||||||
{
|
|
||||||
int *d = b;
|
|
||||||
|
|
||||||
while (++b != e)
|
|
||||||
if (*d != *b)
|
|
||||||
*++d = *b;
|
|
||||||
return ++d;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct print_one_inferior_data
|
struct print_one_inferior_data
|
||||||
{
|
{
|
||||||
int recurse;
|
int recurse;
|
||||||
VEC (int) *inferiors;
|
const std::set<int> *inferiors;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -654,10 +644,9 @@ print_one_inferior (struct inferior *inferior, void *xdata)
|
|||||||
= (struct print_one_inferior_data *) xdata;
|
= (struct print_one_inferior_data *) xdata;
|
||||||
struct ui_out *uiout = current_uiout;
|
struct ui_out *uiout = current_uiout;
|
||||||
|
|
||||||
if (VEC_empty (int, top_data->inferiors)
|
if (top_data->inferiors->empty ()
|
||||||
|| bsearch (&(inferior->pid), VEC_address (int, top_data->inferiors),
|
|| (top_data->inferiors->find (inferior->pid)
|
||||||
VEC_length (int, top_data->inferiors), sizeof (int),
|
!= top_data->inferiors->end ()))
|
||||||
compare_positive_ints))
|
|
||||||
{
|
{
|
||||||
struct collect_cores_data data;
|
struct collect_cores_data data;
|
||||||
ui_out_emit_tuple tuple_emitter (uiout, NULL);
|
ui_out_emit_tuple tuple_emitter (uiout, NULL);
|
||||||
@ -676,28 +665,18 @@ print_one_inferior (struct inferior *inferior, void *xdata)
|
|||||||
inferior->pspace->pspace_exec_filename);
|
inferior->pspace->pspace_exec_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.cores = 0;
|
|
||||||
if (inferior->pid != 0)
|
if (inferior->pid != 0)
|
||||||
{
|
{
|
||||||
data.pid = inferior->pid;
|
data.pid = inferior->pid;
|
||||||
iterate_over_threads (collect_cores, &data);
|
iterate_over_threads (collect_cores, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!VEC_empty (int, data.cores))
|
if (!data.cores.empty ())
|
||||||
{
|
{
|
||||||
int *b, *e;
|
|
||||||
ui_out_emit_list list_emitter (uiout, "cores");
|
ui_out_emit_list list_emitter (uiout, "cores");
|
||||||
|
|
||||||
qsort (VEC_address (int, data.cores),
|
for (int b : data.cores)
|
||||||
VEC_length (int, data.cores), sizeof (int),
|
uiout->field_int (NULL, b);
|
||||||
compare_positive_ints);
|
|
||||||
|
|
||||||
b = VEC_address (int, data.cores);
|
|
||||||
e = b + VEC_length (int, data.cores);
|
|
||||||
e = unique (b, e);
|
|
||||||
|
|
||||||
for (; b != e; ++b)
|
|
||||||
uiout->field_int (NULL, *b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (top_data->recurse)
|
if (top_data->recurse)
|
||||||
@ -722,14 +701,6 @@ output_cores (struct ui_out *uiout, const char *field_name, const char *xcores)
|
|||||||
uiout->field_string (NULL, p);
|
uiout->field_string (NULL, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
free_vector_of_ints (void *xvector)
|
|
||||||
{
|
|
||||||
VEC (int) **vector = (VEC (int) **) xvector;
|
|
||||||
|
|
||||||
VEC_free (int, *vector);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_nothing (splay_tree_key k)
|
do_nothing (splay_tree_key k)
|
||||||
{
|
{
|
||||||
@ -761,7 +732,7 @@ free_splay_tree (void *xt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
list_available_thread_groups (VEC (int) *ids, int recurse)
|
list_available_thread_groups (const std::set<int> &ids, int recurse)
|
||||||
{
|
{
|
||||||
struct osdata *data;
|
struct osdata *data;
|
||||||
struct osdata_item *item;
|
struct osdata_item *item;
|
||||||
@ -830,12 +801,9 @@ list_available_thread_groups (VEC (int) *ids, int recurse)
|
|||||||
/* At present, the target will return all available processes
|
/* At present, the target will return all available processes
|
||||||
and if information about specific ones was required, we filter
|
and if information about specific ones was required, we filter
|
||||||
undesired processes here. */
|
undesired processes here. */
|
||||||
if (ids && bsearch (&pid_i, VEC_address (int, ids),
|
if (!ids.empty () && ids.find (pid_i) != ids.end ())
|
||||||
VEC_length (int, ids),
|
|
||||||
sizeof (int), compare_positive_ints) == NULL)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
ui_out_emit_tuple tuple_emitter (uiout, NULL);
|
ui_out_emit_tuple tuple_emitter (uiout, NULL);
|
||||||
|
|
||||||
uiout->field_fmt ("id", "%s", pid);
|
uiout->field_fmt ("id", "%s", pid);
|
||||||
@ -881,10 +849,9 @@ void
|
|||||||
mi_cmd_list_thread_groups (const char *command, char **argv, int argc)
|
mi_cmd_list_thread_groups (const char *command, char **argv, int argc)
|
||||||
{
|
{
|
||||||
struct ui_out *uiout = current_uiout;
|
struct ui_out *uiout = current_uiout;
|
||||||
struct cleanup *back_to;
|
|
||||||
int available = 0;
|
int available = 0;
|
||||||
int recurse = 0;
|
int recurse = 0;
|
||||||
VEC (int) *ids = 0;
|
std::set<int> ids;
|
||||||
|
|
||||||
enum opt
|
enum opt
|
||||||
{
|
{
|
||||||
@ -936,23 +903,17 @@ mi_cmd_list_thread_groups (const char *command, char **argv, int argc)
|
|||||||
|
|
||||||
if (*end != '\0')
|
if (*end != '\0')
|
||||||
error (_("invalid syntax of group id '%s'"), argv[oind]);
|
error (_("invalid syntax of group id '%s'"), argv[oind]);
|
||||||
VEC_safe_push (int, ids, inf);
|
ids.insert (inf);
|
||||||
}
|
}
|
||||||
if (VEC_length (int, ids) > 1)
|
|
||||||
qsort (VEC_address (int, ids),
|
|
||||||
VEC_length (int, ids),
|
|
||||||
sizeof (int), compare_positive_ints);
|
|
||||||
|
|
||||||
back_to = make_cleanup (free_vector_of_ints, &ids);
|
|
||||||
|
|
||||||
if (available)
|
if (available)
|
||||||
{
|
{
|
||||||
list_available_thread_groups (ids, recurse);
|
list_available_thread_groups (ids, recurse);
|
||||||
}
|
}
|
||||||
else if (VEC_length (int, ids) == 1)
|
else if (ids.size () == 1)
|
||||||
{
|
{
|
||||||
/* Local thread groups, single id. */
|
/* Local thread groups, single id. */
|
||||||
int id = *VEC_address (int, ids);
|
int id = *(ids.begin ());
|
||||||
struct inferior *inf = find_inferior_id (id);
|
struct inferior *inf = find_inferior_id (id);
|
||||||
|
|
||||||
if (!inf)
|
if (!inf)
|
||||||
@ -965,7 +926,7 @@ mi_cmd_list_thread_groups (const char *command, char **argv, int argc)
|
|||||||
struct print_one_inferior_data data;
|
struct print_one_inferior_data data;
|
||||||
|
|
||||||
data.recurse = recurse;
|
data.recurse = recurse;
|
||||||
data.inferiors = ids;
|
data.inferiors = &ids;
|
||||||
|
|
||||||
/* Local thread groups. Either no explicit ids -- and we
|
/* Local thread groups. Either no explicit ids -- and we
|
||||||
print everything, or several explicit ids. In both cases,
|
print everything, or several explicit ids. In both cases,
|
||||||
@ -975,8 +936,6 @@ mi_cmd_list_thread_groups (const char *command, char **argv, int argc)
|
|||||||
update_thread_list ();
|
update_thread_list ();
|
||||||
iterate_over_inferiors (print_one_inferior, &data);
|
iterate_over_inferiors (print_one_inferior, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
do_cleanups (back_to);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user