mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-21 02:24:17 +08:00
gdb: store internalvars in an std::map
In a test downstream in ROCgdb, we had a test case failing when GDB_REVERSE_INIT_FUNCTIONS was set. The test was assuming a particular order in the output of "show convenience". And the order changes when running with GDB_REVERSE_INIT_FUNCTIONS. I think that a nice way to fix it is to make the output of "show convenience" sorted, and therefore stable. Ideally, I think that the the user-visible behavior of GDB should not change when using GDB_REVERSE_INIT_FUNCTIONS. Plus, it makes the output of "show convenience" look nice, not that it's really important. Implement this by storing the internal vars in an std::map, which is a sorted container. Change-Id: I1fca7e7877cc984a3a3432c7639d45e68d437241 Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
55
gdb/value.c
55
gdb/value.c
@ -41,6 +41,7 @@
|
|||||||
#include "user-regs.h"
|
#include "user-regs.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "completer.h"
|
#include "completer.h"
|
||||||
@ -1833,7 +1834,6 @@ struct internalvar
|
|||||||
: name (std::move (name))
|
: name (std::move (name))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
struct internalvar *next = nullptr;
|
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
/* We support various different kinds of content of an internal variable.
|
/* We support various different kinds of content of an internal variable.
|
||||||
@ -1845,7 +1845,10 @@ struct internalvar
|
|||||||
union internalvar_data u;
|
union internalvar_data u;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct internalvar *internalvars;
|
/* Use std::map, a sorted container, to make the order of iteration (and
|
||||||
|
therefore the output of "show convenience" stable). */
|
||||||
|
|
||||||
|
static std::map<std::string, internalvar> internalvars;
|
||||||
|
|
||||||
/* If the variable does not already exist create it and give it the
|
/* If the variable does not already exist create it and give it the
|
||||||
value given. If no value is given then the default is zero. */
|
value given. If no value is given then the default is zero. */
|
||||||
@ -1895,13 +1898,11 @@ init_if_undefined_command (const char* args, int from_tty)
|
|||||||
struct internalvar *
|
struct internalvar *
|
||||||
lookup_only_internalvar (const char *name)
|
lookup_only_internalvar (const char *name)
|
||||||
{
|
{
|
||||||
struct internalvar *var;
|
auto it = internalvars.find (name);
|
||||||
|
if (it == internalvars.end ())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
for (var = internalvars; var; var = var->next)
|
return &it->second;
|
||||||
if (var->name == name)
|
|
||||||
return var;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Complete NAME by comparing it to the names of internal
|
/* Complete NAME by comparing it to the names of internal
|
||||||
@ -1910,27 +1911,29 @@ lookup_only_internalvar (const char *name)
|
|||||||
void
|
void
|
||||||
complete_internalvar (completion_tracker &tracker, const char *name)
|
complete_internalvar (completion_tracker &tracker, const char *name)
|
||||||
{
|
{
|
||||||
struct internalvar *var;
|
int len = strlen (name);
|
||||||
int len;
|
|
||||||
|
|
||||||
len = strlen (name);
|
for (auto &pair : internalvars)
|
||||||
|
{
|
||||||
|
const internalvar &var = pair.second;
|
||||||
|
|
||||||
for (var = internalvars; var; var = var->next)
|
if (var.name.compare (0, len, name) == 0)
|
||||||
if (var->name.compare (0, len, name) == 0)
|
tracker.add_completion (make_unique_xstrdup (var.name.c_str ()));
|
||||||
tracker.add_completion (make_unique_xstrdup (var->name.c_str ()));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create an internal variable with name NAME and with a void value.
|
/* Create an internal variable with name NAME and with a void value.
|
||||||
NAME should not normally include a dollar sign. */
|
NAME should not normally include a dollar sign.
|
||||||
|
|
||||||
|
An internal variable with that name must not exist already. */
|
||||||
|
|
||||||
struct internalvar *
|
struct internalvar *
|
||||||
create_internalvar (const char *name)
|
create_internalvar (const char *name)
|
||||||
{
|
{
|
||||||
internalvar *var = new internalvar (name);
|
auto pair = internalvars.emplace (std::make_pair (name, internalvar (name)));
|
||||||
|
gdb_assert (pair.second);
|
||||||
|
|
||||||
var->next = internalvars;
|
return &pair.first->second;
|
||||||
internalvars = var;
|
|
||||||
return var;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create an internal variable with name NAME and register FUN as the
|
/* Create an internal variable with name NAME and register FUN as the
|
||||||
@ -2417,8 +2420,6 @@ preserve_one_varobj (struct varobj *varobj, struct objfile *objfile,
|
|||||||
void
|
void
|
||||||
preserve_values (struct objfile *objfile)
|
preserve_values (struct objfile *objfile)
|
||||||
{
|
{
|
||||||
struct internalvar *var;
|
|
||||||
|
|
||||||
/* Create the hash table. We allocate on the objfile's obstack, since
|
/* Create the hash table. We allocate on the objfile's obstack, since
|
||||||
it is soon to be deleted. */
|
it is soon to be deleted. */
|
||||||
htab_up copied_types = create_copied_types_hash ();
|
htab_up copied_types = create_copied_types_hash ();
|
||||||
@ -2426,8 +2427,8 @@ preserve_values (struct objfile *objfile)
|
|||||||
for (const value_ref_ptr &item : value_history)
|
for (const value_ref_ptr &item : value_history)
|
||||||
item->preserve (objfile, copied_types.get ());
|
item->preserve (objfile, copied_types.get ());
|
||||||
|
|
||||||
for (var = internalvars; var; var = var->next)
|
for (auto &pair : internalvars)
|
||||||
preserve_one_internalvar (var, objfile, copied_types.get ());
|
preserve_one_internalvar (&pair.second, objfile, copied_types.get ());
|
||||||
|
|
||||||
/* For the remaining varobj, check that none has type owned by OBJFILE. */
|
/* For the remaining varobj, check that none has type owned by OBJFILE. */
|
||||||
all_root_varobjs ([&copied_types, objfile] (struct varobj *varobj)
|
all_root_varobjs ([&copied_types, objfile] (struct varobj *varobj)
|
||||||
@ -2443,25 +2444,25 @@ static void
|
|||||||
show_convenience (const char *ignore, int from_tty)
|
show_convenience (const char *ignore, int from_tty)
|
||||||
{
|
{
|
||||||
struct gdbarch *gdbarch = get_current_arch ();
|
struct gdbarch *gdbarch = get_current_arch ();
|
||||||
struct internalvar *var;
|
|
||||||
int varseen = 0;
|
int varseen = 0;
|
||||||
struct value_print_options opts;
|
struct value_print_options opts;
|
||||||
|
|
||||||
get_user_print_options (&opts);
|
get_user_print_options (&opts);
|
||||||
for (var = internalvars; var; var = var->next)
|
for (auto &pair : internalvars)
|
||||||
{
|
{
|
||||||
|
internalvar &var = pair.second;
|
||||||
|
|
||||||
if (!varseen)
|
if (!varseen)
|
||||||
{
|
{
|
||||||
varseen = 1;
|
varseen = 1;
|
||||||
}
|
}
|
||||||
gdb_printf (("$%s = "), var->name.c_str ());
|
gdb_printf (("$%s = "), var.name.c_str ());
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
struct value *val;
|
struct value *val;
|
||||||
|
|
||||||
val = value_of_internalvar (gdbarch, var);
|
val = value_of_internalvar (gdbarch, &var);
|
||||||
value_print (val, gdb_stdout, &opts);
|
value_print (val, gdb_stdout, &opts);
|
||||||
}
|
}
|
||||||
catch (const gdb_exception_error &ex)
|
catch (const gdb_exception_error &ex)
|
||||||
|
Reference in New Issue
Block a user