diff options
author | Jan Vrany <jan.vrany@labware.com> | 2023-01-18 11:34:37 +0000 |
---|---|---|
committer | Jan Vrany <jan.vrany@labware.com> | 2023-01-18 11:34:37 +0000 |
commit | 722e0dd9e4f03d66666c5b62e162da31cafe6d9f (patch) | |
tree | c9520fd8df787228bb7f21ea6dc5e6ac3dc5522c /gdb | |
parent | 94e76498c3790d90c383621b88268abf9acdd5bf (diff) | |
download | gdb-722e0dd9e4f03d66666c5b62e162da31cafe6d9f.zip gdb-722e0dd9e4f03d66666c5b62e162da31cafe6d9f.tar.gz gdb-722e0dd9e4f03d66666c5b62e162da31cafe6d9f.tar.bz2 |
gdb: care for dynamic objfiles in build_id_bfd_get ()
Accessing gdb.Objfile.build_id caused GDB to crash when objfile is
dynamic, that is created by JIT reader API.
The issue was NULL-pointer dereferencing in build_id_bfd_get () because
dynamic objfiles have no underlaying BFD structure. This commit fixes
the problem by a NULL-check in build_id_bfd_get ().
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/build-id.c | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/jit-reader.exp | 4 |
2 files changed, 10 insertions, 0 deletions
diff --git a/gdb/build-id.c b/gdb/build-id.c index c82f964..801eb00 100644 --- a/gdb/build-id.c +++ b/gdb/build-id.c @@ -32,6 +32,12 @@ const struct bfd_build_id * build_id_bfd_get (bfd *abfd) { + /* Dynamic objfiles such as ones created by JIT reader API + have no underlaying bfd structure (that is, objfile->obfd + is NULL). */ + if (abfd == nullptr) + return nullptr; + if (!bfd_check_format (abfd, bfd_object) && !bfd_check_format (abfd, bfd_core)) return NULL; diff --git a/gdb/testsuite/gdb.base/jit-reader.exp b/gdb/testsuite/gdb.base/jit-reader.exp index fd0c5f5..399cb67 100644 --- a/gdb/testsuite/gdb.base/jit-reader.exp +++ b/gdb/testsuite/gdb.base/jit-reader.exp @@ -227,6 +227,10 @@ proc jit_reader_test {} { gdb_test "python print(list(map(lambda objf : objf.filename, gdb.objfiles())))" \ "$any'<< JIT compiled code at $hex >>'$any" \ "python gdb.Objfile.filename" + + gdb_test "python print( \[o for o in gdb.objfiles() if o.filename.startswith('<< JIT compiled code')\]\[0\].build_id )" \ + "None" \ + "python gdb.Objfile.build_id" } } } |