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