gdb attach到正在运行的程序上进行调试,

gdb program <pid_of_program>
 
# examples
gdb firefox 1234
gdb -p 1234
gdb -p `pidof firefox` # combined with pidof

使用pidof <pattern>可以直接返回命令的pid,在只运行一个实例的情况下,很好用。

gdb调试coredump

gdb program <corefile>

From gdb manual,

   You can run "gdb" with no arguments or options; but the most usual way to start GDB is with one argument or two, specifying an executable program as the argument:

           gdb program

   You can also start with both an executable program and a core file specified:

           gdb program core

   You can, instead, specify a process ID as a second argument or use option "-p", if you want to debug a running process:

           gdb program 1234
           gdb -p 1234

   would attach GDB to process 1234.  With option -p you can omit the program filename.