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.
Related
I used VS Linux C ++ development support to create a Linux C ++ project, and then connect Ubuntu remote debugging on Virtualbox. But the console has printed some error messages.
How to make VS2017 correctly print the output of Linux C ++ program?
Environment
Windows 10 Pro x64
Microsoft Visual Studio Community 2017 15.3.3 - VS Linux C ++ development support
Virtualbox 5.1.26
Ubuntu 16.04 LTS x64
Step
Shift + Ctrl + N
Create a new Linux project
ConsoleApplication
Run
Fill out SSH username and password (Ubuntu 16.04 Virtualbox)
main.cpp
#include <cstdio>
int main()
{
printf("hello from ConsoleApplication1!\n");
return 0;
}
Console
=thread-group-added,id="i1"
GNU gdb (GDB) 7.9
Copyright (C) 2015 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=x86_64-linux-gnu".
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".
=cmd-param-changed,param="pagination",value="off"
Loaded 'shared libraries loaded at this time.'. Cannot find or open the symbol file.
Stopped due to shared library event:
Inferior loaded /lib/x86_64-linux-gnu/libc.so.6
/lib64/ld-linux-x86-64.so.2
Loaded '/lib/x86_64-linux-gnu/libc.so.6'. Cannot find or open the symbol file.
Loaded '/lib64/ld-linux-x86-64.so.2'. Cannot find or open the symbol file.
[Inferior 1 (process 14481) exited normally]
程序“”已退出,返回值为 0 (0x0)。
It looks to me like your program ran ok. Have you opened Visual Studio's Linux console? The output you have posted is written to the Output / Debug window, not the console window. Open the Linux console from the Debug menu. Note that it is one of those VS windows that has different position and visibility settings depending on what you are doing (like Find in Files) so you might have to reopen it when you are debugging.
gdb can manage without symbols files so the messages you see are not an error. You'll get less information about what's going on inside the system libraries and, if you really want this, install the debug package from your Linux distro to get the symbols files for libc etc..
It could be a rights problem. Try to attach to a running application from Visual Studio. I got this error: Unable to start debugging. Attaching to process 4626 with GDB failed because of insufficient privileges with error message 'ptrace: Operation not permitted.'.
See here for solving the ptrace error:
Qt Creator, ptrace: Operation not permitted. What is the permanent solution?
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 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).
:(
I'm trying to debug an android app that call native code to do some GL rendering. The native code is existing code that I'm trying to port (and that I don't really know that well). I've got the existing code compiling, linking, and installing correctly, and I've got some native functions that call in to that code that are being correctly called from my Java code. I'm getting a segfault that I'm trying to track down, and having some problems getting gdb to set a breakpoint in the program. This is on windows XP with Cygwin - and I should probably mention I'm still learning gdb.
I started with the directions at http://honeypod.blogspot.com/2008/01/debug-native-application-for-android.html; here's what I'm currently doing.
Start the app in the emulator.
In a cmd prompt:
> adb forward tcp:1234 tcp:1234
> adb shell
# gdbserver localhost:1234 --attach 2120
gdbserver localhost:1234 --attach 2120
Attached; pid = 2120
Listening on port 1234
In a cygwin shell:
arm-eabi-4.2.1/bin/arm-eabi-gdb.exe out/apps/app-android/libDM.so
GNU gdb 6.6
Copyright (C) 2006 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 "--host=i686-pc-cygwin --target=arm-elf-linux"...
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
warning: shared library handler failed to enable breakpoint
0xafe0da04 in AppRefCounted::unref () at ../../stlport/stl/_iosfwd.h:39
39 class basic_ostream;
Current language: auto; currently c++
(gdb) b Java_com_app_AppRenderer_onCreate
Breakpoint 1 at 0xafff1b1a: file apps/app-android/../../../app-Android/jni/DMJNI/DMInterface.cpp, line 75.
(gdb) c
Continuing.
Warning:
Cannot insert breakpoint 1.
Error accessing memory address 0xafff1b1a: Input/Output error.
So it looks like the breakpoint gets set ok, and that the symbols are ok, but maybe the address is wrong when it tries to insert the breakpoint. I've tried several variations of different commands from the webpage referenced above, but so far, no luck.
Any ideas what's going on?
Thanks
Essentially, at this point with NDK 1.6, I've found that there just isn't support for this kind of debugging strictly with the NDK. However, if you use the PDK (platform development kit), you can do this kind of debugging with native code. We haven't tried the PDK, because generating a map file worked well enough for us (see this SO question), but if you do go that route, check the NDK google group for more details.
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.