[3/3] gdb: keep internalvars sorted
Commit Message
In a test (downstream in ROCgdb), there was 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 changed 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.
So, change create_internalvar to keep the internalvars vector sorted.
Change-Id: I3a916a641e0d50ff698f5d097ef0cf10637ab8de
---
gdb/value.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
@@ -1920,8 +1920,15 @@ complete_internalvar (completion_tracker &tracker, const char *name)
struct internalvar *
create_internalvar (const char *name)
{
- internalvars.emplace_back (new internalvar);
- internalvar *var = internalvars.back ().get ();
+ auto it = std::lower_bound (internalvars.begin (),
+ internalvars.end (),
+ name,
+ [] (const internalvar_up &var, const char *name_)
+ {
+ return var->name < name_;
+ });
+
+ internalvar *var = internalvars.emplace (it, new internalvar)->get ();
var->name = name;
var->kind = INTERNALVAR_VOID;