# Buggy code
def iter_phdrs(ehdr):
    if not ehdr:
        raise StopIteration

    phnum, phentsize, phdr = get_phdrs(ehdr.address)

    if not phdr:
        raise StopIteration

    first_phdr = phdr.address
    PhdrType = phdr.type

    for i in range(0, phnum):
        p_phdr = int(first_phdr + (i * phentsize))
        p_phdr = read(PhdrType, p_phdr)
        yield p_phdr


# Traceback (RuntimeError)
pwndbg> target remote localhost:1234
Remote debugging using localhost:1234
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x0000000000000000 in ?? ()
Traceback (most recent call last):
File "/usr/share/pwndbg/pwndbg/elf.py", line 318, in iter_phdrs
raise StopIteration
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/share/pwndbg/pwndbg/events.py", line 169, in caller
func()
File "/usr/share/pwndbg/pwndbg/memoize.py", line 48, in __call__
value = self.func(*args, **kwargs)
File "/usr/share/pwndbg/pwndbg/stack.py", line 81, in update
page  = pwndbg.memory.Page(start, stop-start, 6 if not is_executable() else 7, 0, '[stack]')
File "/usr/share/pwndbg/pwndbg/memoize.py", line 48, in __call__
value = self.func(*args, **kwargs)
File "/usr/share/pwndbg/pwndbg/stack.py", line 131, in is_executable
for phdr in pwndbg.elf.iter_phdrs(ehdr):
RuntimeError: generator raised StopIteration

If that is an issue, you can report it on https://github.com/pwndbg/pwndbg/issues
(Please don't forget to search if it hasn't been reported before)
To generate the report and open a browser, you may run `bugreport --run-browser`
PS: Pull requests are welcome
/usr/share/pwndbg/pwndbg/stack.py(131)is_executable()
-> for phdr in pwndbg.elf.iter_phdrs(ehdr):
(Pdb)
(Pdb) c
Traceback (most recent call last):
File "/usr/share/pwndbg/pwndbg/elf.py", line 318, in iter_phdrs
raise StopIteration
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/share/pwndbg/pwndbg/events.py", line 173, in caller
raise e
File "/usr/share/pwndbg/pwndbg/events.py", line 169, in caller
func()
File "/usr/share/pwndbg/pwndbg/memoize.py", line 48, in __call__
value = self.func(*args, **kwargs)
File "/usr/share/pwndbg/pwndbg/stack.py", line 81, in update
page  = pwndbg.memory.Page(start, stop-start, 6 if not is_executable() else 7, 0, '[stack]')
File "/usr/share/pwndbg/pwndbg/memoize.py", line 48, in __call__
value = self.func(*args, **kwargs)
File "/usr/share/pwndbg/pwndbg/stack.py", line 131, in is_executable
for phdr in pwndbg.elf.iter_phdrs(ehdr):
RuntimeError: generator raised StopIteration
Traceback (most recent call last):
File "/usr/share/pwndbg/pwndbg/elf.py", line 318, in iter_phdrs
raise StopIteration
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/share/pwndbg/pwndbg/events.py", line 169, in caller
func()
File "/usr/share/pwndbg/pwndbg/memoize.py", line 48, in __call__
value = self.func(*args, **kwargs)
File "/usr/share/pwndbg/pwndbg/stack.py", line 131, in is_executable
for phdr in pwndbg.elf.iter_phdrs(ehdr):
RuntimeError: generator raised StopIteration

If that is an issue, you can report it on https://github.com/pwndbg/pwndbg/issues
(Please don't forget to search if it hasn't been reported before)
To generate the report and open a browser, you may run `bugreport --run-browser`
PS: Pull requests are welcome
/usr/share/pwndbg/pwndbg/stack.py(131)is_executable()
-> for phdr in pwndbg.elf.iter_phdrs(ehdr):
(Pdb) c
Traceback (most recent call last):
File "/usr/share/pwndbg/pwndbg/elf.py", line 318, in iter_phdrs
raise StopIteration
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/share/pwndbg/pwndbg/events.py", line 173, in caller
raise e
File "/usr/share/pwndbg/pwndbg/events.py", line 169, in caller
func()
File "/usr/share/pwndbg/pwndbg/memoize.py", line 48, in __call__
value = self.func(*args, **kwargs)
File "/usr/share/pwndbg/pwndbg/stack.py", line 131, in is_executable
for phdr in pwndbg.elf.iter_phdrs(ehdr):
RuntimeError: generator raised StopIteration
Traceback (most recent call last):
File "/usr/share/pwndbg/pwndbg/events.py", line 169, in caller
func()
File "/usr/share/pwndbg/pwndbg/vmmap.py", line 116, in explore_registers
find(pwndbg.regs[regname])
File "/usr/share/pwndbg/pwndbg/memoize.py", line 48, in __call__
value = self.func(*args, **kwargs)
File "/usr/share/pwndbg/pwndbg/vmmap.py", line 75, in find
return explore(address)
File "/usr/share/pwndbg/pwndbg/abi.py", line 165, in caller
return func(*args, **kwargs)
File "/usr/share/pwndbg/pwndbg/vmmap.py", line 105, in explore
page = find_boundaries(address_maybe)
File "/usr/share/pwndbg/pwndbg/vmmap.py", line 366, in find_boundaries
start = pwndbg.memory.find_lower_boundary(addr)
File "/usr/share/pwndbg/pwndbg/memory.py", line 357, in find_lower_boundary
pwndbg.memory.read(addr, 1)
File "/usr/share/pwndbg/pwndbg/memory.py", line 44, in read
result = gdb.selected_inferior().read_memory(addr, count)
gdb.error: Remote connection closed

If that is an issue, you can report it on https://github.com/pwndbg/pwndbg/issues
(Please don't forget to search if it hasn't been reported before)
To generate the report and open a browser, you may run `bugreport --run-browser`
PS: Pull requests are welcome
/usr/share/pwndbg/pwndbg/memory.py(44)read()
-> result = gdb.selected_inferior().read_memory(addr, count)
(Pdb) c
Traceback (most recent call last):
File "/usr/share/pwndbg/pwndbg/events.py", line 173, in caller
raise e
File "/usr/share/pwndbg/pwndbg/events.py", line 169, in caller
func()
File "/usr/share/pwndbg/pwndbg/vmmap.py", line 116, in explore_registers
find(pwndbg.regs[regname])
File "/usr/share/pwndbg/pwndbg/memoize.py", line 48, in __call__
value = self.func(*args, **kwargs)
File "/usr/share/pwndbg/pwndbg/vmmap.py", line 75, in find
return explore(address)
File "/usr/share/pwndbg/pwndbg/abi.py", line 165, in caller
return func(*args, **kwargs)
File "/usr/share/pwndbg/pwndbg/vmmap.py", line 105, in explore
page = find_boundaries(address_maybe)
File "/usr/share/pwndbg/pwndbg/vmmap.py", line 366, in find_boundaries
start = pwndbg.memory.find_lower_boundary(addr)
File "/usr/share/pwndbg/pwndbg/memory.py", line 357, in find_lower_boundary
pwndbg.memory.read(addr, 1)
File "/usr/share/pwndbg/pwndbg/memory.py", line 44, in read
result = gdb.selected_inferior().read_memory(addr, count)
gdb.error: Remote connection closed
[1]    7286 segmentation fault (core dumped)  aarch64-linux-gnu-gdb

# Fixed code
def iter_phdrs(ehdr):
    if not ehdr:
        return

    phnum, phentsize, phdr = get_phdrs(ehdr.address)

    if not phdr:
        return

    first_phdr = phdr.address
    PhdrType = phdr.type

    for i in range(0, phnum):
        p_phdr = int(first_phdr + (i * phentsize))
        p_phdr = read(PhdrType, p_phdr)
        yield p_phdr