]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: add a new build_id_equal function
authorAndrew Burgess <aburgess@redhat.com>
Mon, 6 May 2024 18:54:27 +0000 (19:54 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 9 May 2024 09:09:28 +0000 (10:09 +0100)
Add two versions of a new function build_id_equal which can be used to
compare build-ids, then make use of these functions in GDB.  It seems
better to have a specific function for the task of comparing build-ids
rather than having a length check followed by a memcmp call.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/build-id.c
gdb/build-id.h
gdb/exec.c

index 659801b0865d61311d1efa52997bc96d521c288f..41667d5e5cf3dd9fb3a9f778fb56d21a2e3485c0 100644 (file)
@@ -63,8 +63,7 @@ build_id_verify (bfd *abfd, size_t check_len, const bfd_byte *check)
     warning (_("File \"%ps\" has no build-id, file skipped"),
             styled_string (file_name_style.style (),
                            bfd_get_filename (abfd)));
-  else if (found->size != check_len
-          || memcmp (found->data, check, found->size) != 0)
+  else if (!build_id_equal (found, check_len, check))
     warning (_("File \"%ps\" has a different build-id, file skipped"),
             styled_string (file_name_style.style (),
                            bfd_get_filename (abfd)));
index 15bd8a964dc5f3bbebe061e40ed53a471e0144b9..c5f20f8782e1c3802076f8ec967504c6fe1f89ab 100644 (file)
@@ -70,4 +70,30 @@ build_id_to_string (const bfd_build_id *build_id)
   return bin2hex (build_id->data, build_id->size);
 }
 
+/* Compare the content of two build-ids.  One build-id (A) is passed as a
+   build-id pointer, while the second is passed using BUILD_ID_LEN and
+   BUILD_ID_DATA.  Return true if the build-ids match, otherwise false.  */
+
+static inline bool
+build_id_equal (const bfd_build_id *a, const bfd_size_type build_id_len,
+               const bfd_byte *build_id_data)
+{
+  gdb_assert (a != nullptr);
+  gdb_assert (build_id_data != nullptr);
+
+  return (a->size == build_id_len
+         && memcmp (a->data, build_id_data, a->size) == 0);
+}
+
+/* Like the above, but take two build-id pointers A and B.  */
+
+static inline bool
+build_id_equal (const bfd_build_id *a, const bfd_build_id *b)
+{
+  gdb_assert (a != nullptr);
+  gdb_assert (b != nullptr);
+
+  return build_id_equal (a, b->size, b->data);
+}
+
 #endif /* BUILD_ID_H */
index 3d392b198a1bc185d1b8c183408837d076cfd3f4..88915260d609114fdba306eb6d989b0500b8edb6 100644 (file)
@@ -253,10 +253,8 @@ validate_exec_file (int from_tty)
 
          if (target_exec_file_build_id != nullptr)
            {
-             if (exec_file_build_id->size == target_exec_file_build_id->size
-                 && memcmp (exec_file_build_id->data,
-                            target_exec_file_build_id->data,
-                            exec_file_build_id->size) == 0)
+             if (build_id_equal (exec_file_build_id,
+                                 target_exec_file_build_id))
                {
                  /* Match.  */
                  return;