diff options
-rw-r--r-- | gdb/dwarf2/index-write.c | 17 | ||||
-rw-r--r-- | gdb/testsuite/gdb.gdb/index-file.exp | 8 |
2 files changed, 22 insertions, 3 deletions
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index e3ddb8d..b77f4f9 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -454,6 +454,11 @@ public: return strcmp (m_cstr, other.m_cstr) == 0; } + bool operator< (const c_str_view &other) const + { + return strcmp (m_cstr, other.m_cstr) < 0; + } + /* Return the underlying C string. Note, the returned string is only a reference with lifetime of this object. */ const char *c_str () const @@ -773,10 +778,18 @@ public: } for (size_t bucket_ix = 0; bucket_ix < bucket_hash.size (); ++bucket_ix) { - const std::forward_list<hash_it_pair> &hashitlist - = bucket_hash[bucket_ix]; + std::forward_list<hash_it_pair> &hashitlist = bucket_hash[bucket_ix]; if (hashitlist.empty ()) continue; + + /* Sort the items within each bucket. This ensures that the + generated index files will be the same no matter the order in + which symbols were added into the index. */ + hashitlist.sort ([] (const hash_it_pair &a, const hash_it_pair &b) + { + return a.it->first < b.it->first; + }); + uint32_t &bucket_slot = m_bucket_table[bucket_ix]; /* The hashes array is indexed starting at 1. */ store_unsigned_integer (reinterpret_cast<gdb_byte *> (&bucket_slot), diff --git a/gdb/testsuite/gdb.gdb/index-file.exp b/gdb/testsuite/gdb.gdb/index-file.exp index 0841592..7154d23 100644 --- a/gdb/testsuite/gdb.gdb/index-file.exp +++ b/gdb/testsuite/gdb.gdb/index-file.exp @@ -44,6 +44,9 @@ remote_exec host "mkdir -p ${dir1}" with_timeout_factor $timeout_factor { gdb_test_no_output "save gdb-index $dir1" \ "create gdb-index file" + + gdb_test_no_output "save gdb-index -dwarf-5 $dir1" \ + "create dwarf-index files" } # Close GDB. @@ -140,13 +143,16 @@ if { $worker_threads > 1 } { with_timeout_factor $timeout_factor { gdb_test_no_output "save gdb-index $dir2" \ "create second gdb-index file" + + gdb_test_no_output "save gdb-index -dwarf-5 $dir2" \ + "create second dwarf-index files" } # Close GDB. gdb_exit # Now check that the index files are identical. - foreach suffix { gdb-index } { + foreach suffix { gdb-index debug_names debug_str } { set result \ [remote_exec host \ "cmp -s \"$dir1/${index_filename_base}.${suffix}\" \"$dir2/${index_filename_base}.${suffix}\""] |