Search code examples
linuxdebuggingprocessgdbassociate

Linux: How to setup association between gdb and executables?


I wish to enable the functionality that when some programs (like my own prog1, prog2,...) when they are brought up by linux as a service daemon, or started within shell, a gdb is automatically started to run these programs.

On windows I can do this with gflags to associated executable files with debuggers. How to do this on linux? I'm running ubuntu 16.04

Thanks!


Solution

  • You may consider writing a simple wrapper to automatically run gdb after starting a deamon.

    Please have a look into man gdb.

       You can, instead, specify a process ID as a second argument, if you want to debug a running process:
    
       gdb program 1234
    
       would attach GDB to process 1234 (unless you also have a file named 1234; GDB does check for a core file first).