To attach to a running process, do:
gdb PROGRAM <pid>
Another way to attach is from within gdb: attach <pid>
To detach, do detach.
If you want to pass arguments to the command, do:
gdb --args prog <args>
Another way is to pass the args to the run command within gdb.
When gdb is loaded, it can read commands from an init file (“site wide” and local). I didn’t note the details here. But useful if you’re debugging a particular program and want to run the same commands often in a debugging session.
You can save a log of your GDB session to a file. Read the manual on how to.