I am using Vs Code in Linux. Is it possible to configure Gdb with Code so that I can use the gui for debugging for C/C++ programs.
There is an extension called debug you can install using ext install debug. Im the author of the extension and it supports debugging native applications using GDB. Just follow the README in there and it should be very easy to setup. If you want to build before debugging, just add a preLaunchTask to the config and create a build task that compiles your application.
EDIT: Sorry, strike that since it's just Homebrew's gdb not being signed in Yosemite: http://sourceware.org/gdb/wiki/BuildingOnDarwin
Installed your extension, defined the .json runner and got a terminal stating:
"&"warning: GDB: Failed to set controlling terminal: Operation not permitted\n"...
When typing GDB commands, I'm told that the process is running (despite having set the breakpoint in the editor, red dot).
Then when I close the floating terminal (outside the VSCode builtin one):
GNU gdb (GDB) 7.11
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin14.5.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
=cmd-param-changed,param="confirm",value="off"
=cmd-param-changed,param="output-radix",value="16"
=cmd-param-changed,param="prompt",value="\001\e[;31m\002gdb-peda$ \001\e[0m\002"
=cmd-param-changed,param="history expansion",value="on"
=cmd-param-changed,param="history save",value="on"
=cmd-param-changed,param="disassembly-flavor",value="intel"
=cmd-param-changed,param="follow-fork-mode",value="child"
=cmd-param-changed,param="step-mode",value="on"
=cmd-param-changed,param="print pretty",value="on"
ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". Unable to find Mach task port for process-id 65326: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
The program '/Users/romanvg/dev/bcftools/bcftools' has exited with code 42 (0x0000002a).
:(
Related
The program compiles and executes perfectly, it's just GDB Debugger which break right at the start of the execution, emerging the following dialog:
I can just press Continue and the program will run properly, but it's so annoying to have to do this in every execution.
I am Cross-Compiling remotely to Linux-ARM with this MVS extension and it only happens when I link -lcurl
I have tried to disable every checkbox below "Break When Thrown" in Exception Settings, I though that at least I wouldn't be bothered anymore, but it still emerging the dialog.
I noticed that it wasn't MVS, it was remote GBD on linux instead, since I tried to debug my program from CLI and I got the same issue:
root#server:/.../Debug# gdb --exec=myapp
GNU gdb (Raspbian 7.7.1+dfsg-5+rpi1) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) run
Starting program: /.../Debug/myapp
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
Cannot access memory at address 0x0
Program received signal SIGILL, Illegal instruction.
0x76a5fde8 in ?? () from /usr/lib/arm-linux-gnueabihf/libcrypto.so.1.0.0
(gdb) continue
Continuing.
Hello World
[Inferior 1 (process 5879) exited normally]
(gdb)
After that, I quickly found a workaround to make gdb ignore this signal so it wouldn't bothered me anymore stopping the proccess:
I just added handle SIGILL nostop to /etc/gdb/gdbinit
I checked out the gdb source and compiled successfully with MinGW. When I run the output file gdb.exe, I cannot input anything, any key press would cause it quit:
aj#TERRAN E:\
$ gdb --data-directory=E:\gdb_build\gdb\gdb-7.11\gdb\data-directory
GNU gdb (GDB) 7.11
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-mingw32 --target=arm-linux-androideabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) quit
aj#TERRAN E:\
$
I didn't input the last quit, I just hit the space and it quits.
I downloaded another prebuilt gdb which works fine, but it doesn't support python, so I need to build it myself.
But I tried the tui mode with gdb -tui, it works fine, I can type commands.
Why does non-tui-mode quit?
This is a bug of gdb 7.12, 7.11.1 works just fine.
The older versions of GDB have this bug when building them from sources on Windows. I have this problem with a custom GDB 7.6.1 built with MSYS2.
The problem appears when the GDB is linked with ncurses library. In this case, the function getch() is taken from ncurses and returns EOF because there's no curses window. It is called from readline/input.c:rl_getc().
The latest sources have this fixed and call _getch() from the standard library. This simple fix ends with backspace key not deleting characters. So, there are more fixes in readline to fix that too.
More info: https://www.mail-archive.com/bug-readline#gnu.org/msg01203.html
https://gdb-patches.sourceware.narkive.com/A7CT0KH0/enabled-tui-mode-on-msys2
A simple workaround to build an old version is to disable TUI mode with --disable-tui configure option. This will build GDB without ncurses dependency and not expose this bug.
I am trying to get gdb to set a breakpoint in pcbsd10 (freebsd10).
I have compiled my code with debug symbols, and here is the output from gdb
GNU gdb (GDB) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-freebsd10.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from tor...done.
(gdb) break config.c:3626
Breakpoint 1 at 0xfde72: file src/or/config.c, line 3626.
(gdb) run
Starting program: /usr/home/jon/swdev/apps/tor/src/or/tor -f /home/jon/torrc
Error in re-setting breakpoint 1: Cannot access memory at address 0xfdb90
Error in re-setting breakpoint 1: Cannot access memory at address 0xfdb90
...
And my code continues to run without stopping at the breakpoint.
What is going on here? How can I get more insight into why gdb is failing?
You are possibly looking at this GDB bug.
Although it looks like GDB 7.7 should already have a fix, you may want to try 7.7.1.
Alternatively, build your binary as a non-PIE binary (remove -fPIE from the Makefile).
I have created a new file .gdbinit on my $HOME directory. and when I am execution gdb command I am getting following error.
bld05 abc /users/abc 25 > gdb
GNU gdb Red Hat Linux (6.3.0.0-1.132.EL4rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu"./users/abc/.gdbinit:1: Error in sourced command file:
Undefined command: "TL". Try "help".
I don't know what could have gone wrong. Can anyone tell me?
.gdbinit file contains http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt
Using gdb 6.3 in 2012 does not make much sense (except on Macs). Get something newer, like 7.5. This will also work better with C++.
Also, to load a program in gdb, use gdb --args /your/binary arg1 arg2
When I attempt to debug a simple program with gdb on cygwin I get the following:
C:\Users\Benoit St-Pierre\workspace_cpp\cs454>gdb a.exe
GNU gdb 6.8.0.20080328-cvs (cygwin-special)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-cygwin"...
(gdb) start
Breakpoint 1 at 0x401a51: file server.cc, line 207.
Starting program: /cygdrive/c/Users/Benoit St-Pierre/workspace_cpp/cs454/a.exe
Error creating process /cygdrive/c/Users/Benoit St-Pierre/workspace_cpp/cs454/a.exe, (error 193).
Where the error 193 is a ERROR_BAD_EXE_FORMAT.
The compiled application itself runs great and clients connect and interact with the application. I'm using cygwin 1.7 since I'm using the new getaddrinfo methods for setting up sockets. The application was compiled using gcc 3.4.4 with the following command:
g++ -g3 server.cc
Anyone have a clue what I might be doing wrong?
The problem is that you have space character in your path name. Move the file to a different directory and gdb will be able to start the process.