The easiest way is to use Python GDB. One liner:
gdb Ξ» py ["attribute" in line and print(line) for line in gdb.execute("p *this", to_string=True).splitlines()]
Assuming you have included command history, you can enter it only once, and then press Ctrl + R b.exec to pull it out of history. Then just change the attribute and *this suit your requirements.
You can also do it this simple:
gdb Ξ» grep_cmd "p *this" attribute
To do this, simply add the following to your .gdbinit file:
py class GrepCmd (gdb.Command): """Execute command, but only show lines matching the pattern Usage: grep_cmd <cmd> <pattern> """ def __init__ (_): super ().__init__ ("grep_cmd", gdb.COMMAND_STATUS) def invoke (_, args_raw, __): args = gdb.string_to_argv(args_raw) if len(args) != 2: print("Wrong parameters number. Usage: grep_cmd <cmd> <pattern>") else: for line in gdb.execute(args[0], to_string=True).splitlines(): if args[1] in line: print(line) GrepCmd()
source share