[3/3] gdb: keep internalvars sorted

Message ID 20230214042139.73638-3-simon.marchi@efficios.com
State New
Headers
Series [1/3] gdb: store internalvars in an std::vector |

Commit Message

Simon Marchi Feb. 14, 2023, 4:21 a.m. UTC
  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(-)
  

Patch

diff --git a/gdb/value.c b/gdb/value.c
index 68499896af8c..2c37f94cba99 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -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;