in gdb

source <path to python>

then, can use by

python get_pathname()

or pi

#!/usr/bin/env python3

import procmaps
import sys
import gdb

def get_pathname():
    """return the file that contains the indicated address"""
    retval = ''
    address = gdb.selected_frame().pc()
    maps = procmaps.from_pid(gdb.selected_inferior().pid)
    for m in maps:
        if address >= m.begin_address and address < m.end_address:
            retval = m.pathname
            break
    print(f'0x{address:x}\t{retval}')

    return retval

References

sourceware.org inferiors

[writing GDB commands](https://undo.io/resources/gdb-watchpoint/how-write-user-defined-gdb-commands-python/

backtrace backtrace