Cygwin GDB gives error 193 when trying to start program - c++

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.

Related

gdb always quit after press any key

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.

Configuring VS Code with Gdb

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).
:(

gdb error in re-settings breakpoint (cannot access memory)

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).

how to configure stl-view in gdb?

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

Strange errors trying using gdb remotely: What am I doing wrong?

I've got a 64-bit remote machine, anvil, and a 32 bit desktop.
I make a program called hello.c
and on anvil I compile it with
$ gcc -ggdb -o hello hello.c
It will run and debug fine on anvil.
But I'd like to debug it from my desktop (so I can use the debugger through emacs)
So :
$gdbserver anvil:24000 hello
Process hello created; pid = 10991
Listening on port 24000
But then on the desktop, I try to connect remotely, and all I get is strange errors
There's some sign of connectivity: after I type target remote anvil:24000 the other end prints 'Remote debugging from host 10.17.20.149', which is my desktop address.
Here's a transcript:
jla#jaspden-desktop$ gdb hello
GNU gdb (GDB) Fedora (7.2-51.fc14)
Copyright (C) 2010 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/jla/myco/chip_test/hello...done.
(gdb) target remote anvil:24000
Remote debugging using anvil:24000
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0x0000003ed0100a80 in ?? ()
(gdb) b main
Breakpoint 1 at 0x4004b7: file hello.c, line 6.
(gdb) run
The "remote" target does not support "run". Try "help target" or "continue".
(gdb) continue
Continuing.
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00000000004003f6 in _start ()
(gdb)
Does anyone know what I'm doing wrong?
Does anyone know what I'm doing wrong?
gcc -ggdb -o hello hello.c
This likely produces a 64-bit binary (though we can't tell for sure from what you've provided so far). As I said before, it doesn't matter that anvil is a 64-bit machine. What matters is what binary you are trying to debug.
What does file hello say?
GNU gdb (GDB) Fedora (7.2-51.fc14)
...
This GDB was configured as "i686-redhat-linux-gnu".
That's a problem: if hello is a 64-bit binary, then you can't debug it with this version of gdb. You will need to build a new version, configured with --host=i686-linux and --target=x86_64-linux.