gdb/python: Fix segfault when iterating over empty linetable

symtab-> linetable () is set to null in
buildsym_compunit::end_compunit_symtab_with_blockvector () if the symtab
has no linetable. Attempting to iterate over this linetable using the
Python API caused GDB to segfault.

Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
Toby Lloyd Davies
2024-03-19 11:08:46 +00:00
parent 62fd8eb314
commit c0689161ed
3 changed files with 97 additions and 1 deletions

View File

@@ -397,7 +397,8 @@ ltpy_iternext (PyObject *self)
LTPY_REQUIRE_VALID (iter_obj->source, symtab);
if (iter_obj->current_index >= symtab->linetable ()->nitems)
if (symtab->linetable () == nullptr
|| iter_obj->current_index >= symtab->linetable ()->nitems)
{
PyErr_SetNone (PyExc_StopIteration);
return NULL;