You should add the path "c:\mingw\bin" in your environment variable. This way whenever you type gdb on command prompt, it would search from the above path.
And the same for valgrind?
Till date Valgrind does not run on Windows platform.
Answer from Mantosh Kumar on Stack OverflowVideos
There are multiple ways of doing this. The easiest is to check whether gdb is in your $PATH:
which -a gdb
However, the program could be installed and not in your user's $PATH. To quickly search for an executable called gdb do this:
locate -eb '\gdb'
From man locate:
NAME
locate - find files by name
-b, --basename
Match only the base name against the specified
patterns. This is the opposite of --whole‐
name.
-e, --existing
Print only entries that refer to files exist‐
ing at the time locate is run.
EXAMPLES
To search for a file named exactly NAME (not *NAME*),
use
locate -b '\NAME'
Because \ is a globbing character, this disables the
implicit replacement of NAME by *NAME*.
That literally means gdb isn't in $PATH or is not executable.
But yeah it should be installed to /usr/bin/gdb which would be in the PATH and the directory /etc/gdb should exist.
Moreover, the usual, which distro are you using?
Use the info source command to get info for the current stack frame.
Here is an example of its output:
(gdb) info source Current source file is /build/gtk+2.0-LJ3oCC/gtk+2.0-2.24.30/modules/input/gtkimcontextxim.c Located in /home/sashoalm/Desktop/compile/gtk+2.0-2.24.30/modules/input/gtkimcontextxim.c Contains 1870 lines. Source language is c. Producer is GNU C11 5.3.1 20160225 -mtune=generic -march=i686 -g -g -O2 -O2 -fstack-protector-strong -fPIC -fstack-protector-strong. Compiled with DWARF 2 debugging format. Does not include preprocessor macro info.
Excellent answer from Ciro Santill. However, the script needed a small correction to work with my gdb 8.0.1.
I also changed it to copy the text to the clipboard so I can use it in vim straight away. It works nicely with file_line.vim plugin. This is an example of the clipboard content produced by the script:
/home/ops1/projects/test01/main.cpp:5
The script is below:
import pyperclip
class Clippath (gdb.Command):
"""print absolute path"""
def __init__(self):
super(Clippath, self).__init__("clippath", gdb.COMMAND_USER)
def invoke(self, arg, from_tty):
symtabline = gdb.selected_frame().find_sal()
pyperclip.copy(symtabline.symtab.fullname() + ":" + str(symtabline.line))
Clippath()
Here are the steps to make it all work:
- Install pyperclip python library sudo zypper in python3-pyperclip
- Save the script above to a file, say file-path.py and copy it to ~/.gdb
- Update ~/.gdbinit with adding the following lines: source ~/.gdb/file-path.py
- Now you can copy the path and line to the clipboard with
clippathin gdb
And read more about GDB Python API - link
No idea what MinGW Installation Manager is or why you were trying to use it when you are using msys2.
To install mingw64 gdb in msys2, you really just need to:
pacman -S mingw-w64-x86_64-gdb
You should probably run pacman -Syu twice before you run the above though.
As you can see, if you need other mingw64 builds of programs (toolchain programs or not), their package names would be prefixed with mingw-w64-x86_64-. There's also the package group mingw-w64-x86_64-toolchain which you can pacman -S --needed instead to get a somewhat full toolchain.
You may also want to use the urt64 toolchain instead. See this page for more details. (You can e.g. pacman -Ss gdb to find out what's the package name prefix for each of the variants.)
Note that to use any of the toolchain (or any non-msys2 builds of programs), you should use the corresponding "launcher" of shell/terminal instead of msys2.exe.
Check by restarting your PC, if it didn't work download the *.gdb file from its website (I guess it's a *.rar or some file), now update with MSYS and restart. It have solved for me, I guess it helps....