This repository is a tutorial on how to separate the debugging symbols from the final executable, and still be able to debug it.
Note: some of this tutorial also applies to MinGW.
First, the executable is built, and it contains the debugging symbols.
clang -g main.c -o main
Then the debugging symbols are extracted into a new file.
objcopy --only-keep-debug main main.dbg
The final executable is stripped of debugging symbols.
objcopy --strip-debug main
Additionally, a debug link can be added to allow GDB to find the file with the debugging symbols.
objcopy --add-gnu-debuglink=main.dbg main
If everything works well GDB should say something like:
Reading symbols from main...Reading symbols from /some/directory/separate-symbols/main.dbg...done.
done.
You can also run GDB and add the file manually:
(gdb) exec-file main
(gdb) symbol-file main.dbg
Inspired by this answer on StackOverflow.
Also check the GDB manual.