def METHOD_NAME(obj, field):
    # Dereference once
    if obj.type.code == gdb.TYPE_CODE_PTR:
        obj = obj.dereference()
    for f in re.split(r"(->|\.|\[\d+\])", field):
        if not f:
            continue
        if f == "->":
            obj = obj.dereference()
        elif f == ".":
            pass
        elif f.startswith("["):
            n = int(f.strip("[]"))
            obj = obj.cast(obj.dereference().type.pointer())
            obj += n
            obj = obj.dereference()
        else:
            obj = obj[f]
    return obj