gdb: add nullptr check to cooked_index_functions::dump
Since commit
7d82b08e9e0a ("gdb/dwarf: dump cooked index contents in
cooked_index_functions::dump"), we see:
maint print objfiles /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error^M
^M
Object file /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error: Objfile at 0x614000005040, bfd at 0x6120000e08c0, 15 minsyms^M
^M
Cooked index in use:^M
^M
/home/smarchi/src/binutils-gdb/gdb/../gdbsupport/gdb-checked-static-cast.h:58: internal-error: checked_static_cast: Assertion `result != nullptr' failed.^M
A problem internal to GDB has been detected,^M
further debugging may prove unreliable.^M
----- Backtrace -----^M
FAIL: gdb.dwarf2/dw2-error.exp: maint print objfiles /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-error/dw2-error (GDB internal error)
The problem is that when cooked_index_functions fails to build an index,
per_objfile->index_table is nullptr. Therefore, add a nullptr check,
like other methods of cooked_index_functions already do.
Print the "Cooked index in use" message after the nullptr check, such
that if the cooked index failed to build, that message is not printed.
Change-Id: Id67aef592e76c41b1e3bde9838a4e36cef873253