You don't use a source code editor (even VSCode) to debug a core
dump (because a core
file has not a textual format). You use gdb (or perhaps some other debugger, such as lldb). GDB has a very nice user manual that I strongly recommend to read. You also don't use VSCode to compile your C++ code, but a compiler such as GCC or Clang (probably VSCode could be configured to start g++
for you).
On Linux, if your C or C++ program was built with -g
passed to g++
or gcc
as an executable $HOME/bin/foo
you could try
gdb $HOME/bin/foo core
then use post mortem commands of the gdb
debugger. Read the documentation of gdb
for details. The presence and name of the core dump file is configurable (at the lowest level using setrlimit(2) and thru proc(5), so bash
builtin ulimit
or zsh
builtin limit
). See also core(5). Notice that your login shell could be changed with chsh(1). On Linux, bash
is often (not always) the default shell, but you might switch to zsh
or even to the fish
shell. Read of course about Unix shells.
You also don't need to generate a core dump on purpose. It is often simpler to set a breakpoint under gdb
. You could generate a core of a running process using gcore(1). You could attach gdb
to a running process using the -p
option of gdb(1). I see very few cases where generating a core dump on purpose is useful. But of course abort(3) (also used by assert(3)) generates a core
dump.
Your application should better be compiled (using the -g
option to GCC or Clang) with DWARF debug information. Assume your application executable is some yourapp
executable file. Then you debug the core dump (for a core
file, see core(5) for more; notice that gdb(1) is mentioned in core(5) man
page, given by the man core
command) using gdb yourapp core
Some source code editors are capable of running gdb
(my editor is emacs
and it is capable of running gdb
with M-x gdb
). You should dive into the documentation of your source code editor to understand how to do that.
But I recommend using gdb
on the command line in a terminal. It is a very handy tool. See this answer to a related question.
gdb
is using the very low level ptrace(2) system call to set breakpoints etc etc.. You almost never need ptrace
(except if you write your own debugger, which could take years of work), but you use gdb
which uses ptrace
.
PS. How to run gdb
from VSCode is a different question. Since I don't use VSCode, I cannot answer it. And it might not even worth doing. Even with 30 years of emacs
experience, I often run gdb
in a terminal. Since it is simpler than running it from emacs
(or VSCode).
NB. These days, in 2019, "source code editor" is a near synonym for "IDE". Both locutions in practice refer to the same products, but they differ in the way they present them. You can call emacs an IDE, I (and the GNU community) prefer to call it a source code editor, but we both will use it for the same things: nicely writing and browsing and working on source code and building and debugging it.