diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-05-06 19:54:27 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-05-09 10:09:28 +0100 |
commit | cb1a6b85b84359419e7fcf9069c3ba9d27a856c7 (patch) | |
tree | f62c7dd55dc6e1eb8f04799d8d6cbab44ccb965d /gdb/build-id.h | |
parent | e5b12a313fdbbf9b628e920e40feb6613a9d6905 (diff) | |
download | gdb-cb1a6b85b84359419e7fcf9069c3ba9d27a856c7.zip gdb-cb1a6b85b84359419e7fcf9069c3ba9d27a856c7.tar.gz gdb-cb1a6b85b84359419e7fcf9069c3ba9d27a856c7.tar.bz2 |
gdb: add a new build_id_equal function
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>
Diffstat (limited to 'gdb/build-id.h')
-rw-r--r-- | gdb/build-id.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/gdb/build-id.h b/gdb/build-id.h index 15bd8a9..c5f20f8 100644 --- a/gdb/build-id.h +++ b/gdb/build-id.h @@ -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 */ |