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.
Related
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 am trying to do remote debugging in CDT Environment of Eclipse Juno on Windows 7, whereas the remote machine is running under Linux. So much to the general purpose, unfortunately the exact setting is much more complicated so that I have been struggling for over a week now with this issue and none of the solutions provided in search results is sufficient.
So, here is my exact setting (very sorry for that long text!):
I have a C++ application Y which I develop and build on machine A.
I move the .so file (debug build) to machine B, which is running under Linux. I do not have the source code available there.
I am not starting my application Y explicitely on machine B. There exists another application Z that is started first, then I trigger a specific function so that my application Y is loaded dynamically. Actually it is done from a database stored procedure, but I will leave out these details to avoid fully puzzling you...
I have my local machine C running under Windows from which I want to debug. I have a copy of Y's source code and executable there, but not from application Z.
I cannot change these settings.
Now, I have installed gdbserver (GNU gdbserver (GDB) SUSE (7.2-3.3)) on machine B, gdb on machine C - compiled it with matching target and host as found in common tutorials, the version output says the following:
GNU gdb (GDB) 7.6.50.20130508-cvs (cygwin-special)
Copyright (C) 2013 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-cygwin".
I installed the Eclipse plugin for running and debugging remote applications. I have set up everything as suggested in http://wiki.eclipse.org/CDT/User/FAQ#How_do_I_debug_a_remote_application.3F
When I now start my debugging session, gdbserver and application Z are successfully started on machine B from within Eclipse. I can also trigger my application Y by invoking the stored procedure. But the following problems and questions arise here:
When starting the debugger, it says:
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
Created trace state variable $trace_timestamp for target's variable 1.
I have read something about including shared libraries somewhere, but I did not fully understand what shared libraries are meant here. Maybe that issue is also related to the next point.
I do not know where to include my source code so that it is available for setting breakpoints etc. during the debugging session. Since I do not have an Eclipse project, I know I just need to include the path to it somewhere. I added the code's root folder to the debug configuration's source lookup path, but this does not seem to work.
In Eclipse's debug configuration, I enter the path to the C++ application I want to start. For the command on the remote machine, I need to enter application Z since I cannot start my application Y explicitely. So I entered my application Y's path in the field for my local C++ application. Is that correct?
When starting the debugging session and triggering my application Y from outside, nothing happens in the debugger. My application Y is running and delivers results, but I do not get anything in the debugger's console. I would like to set breakpoints, but since my source code is not found I do not know how...
I tried to do a gdb debugging directly on the remote machine (starting applicatioin Z, triggering application Y from outside) and tried to set breakpoints at specific functions from my application Y. But this did not work either. Nevertheless, I did not get the warning mentioned above.
So now I am stuck here and do not know what to do. I have read lots of threads and blogs, but none of them has such a specific setting as I have, so there is always missing some detail.
I really, really, really appreciate your help.
Instead of breakpoint, put sleep() somewhere in you code then attach it to GDB while it's sleeping.
I'm trying to use Eclipse CDT on Ubuntu for C++ development. I'm working on a large C++ project that leverages Tcl as a scripting language to kick off and control the application.
How can I configure Eclipse to launch the application using shell scripts rather than using a C++ "main" application? The shell scripts launch a Tcl application that in turn calls into the C++ application.
Also, is it possible to debug a C++ application using Eclipse and gdb that's started via a script? If so, how does one go about doing it?
Interesting question. Without being able to provide you a straight solution, but Eclipse (gdb) can be attached to a running program - that may not help in your case.
What about trying to employ some kind of remote debugging? I.e. you start your program with gdb and configure gdb to wait for a remote debugger to attach? The 'remote' debugger will be on your local system, of course.
EDIT:
Start your program via
gdbserver localhost:1234 <executable>
Configure your debug session in Eclipse:
- GDB Hardware Debugging
- I had to select the "Standard GDB Hardware debugging launcher" (Debugger tab at the bottom for Helios)
- Check use remote target: Generic TCP/IP: localhost, port 1234
I didn't manage to resolve symbols yet, that might be a path issue.
I've just spent a whole day trying to find a way to enable GDB debugging from Qt Creator or Eclipse. I learned that there are basically two approaches to launch the target application:
Using ssh (ssh host gdb)
Using gdbserver
I was able to use both approaches to launch gdb remotely and start the application. However, GDB never responds to any breakpoints set in the IDE. Also I can't pause the application to inspect the program state. In Qt Creator I just get an obscure stack trace (I might have been looking at the traces of ssh or gdb actually...).
Can anyone help me to get started?
Progress!
I found that with Qt Creator 2.0 there is an feature called "Attach and debug remote application." It's based on gdbserver. The good thing is that it stops on the IDE's breakpoints. However, there are two issues:
When it hits a breakpoint it only shows assembly code, not the source code.
GDB often quits because of 'signal received'
I should probably mention that the remote executable is compiled with an older version of GCC than the one installed on my local PC. Perhaps some of the problems are related to this.
Update
I should mention that I switched to running cgdb on the remote machine via SSH.
The remote Qt Creator-based solution wasn't stable. GDB tends to quit because of mysterious 'signal received' messages.
So that GDB on your host (the machine you develop and compile on, so where you have Qt Creator) you have to give it access to the "symbol file".
I usually don't use Qt Creator, but GDB and gdbserver directly for cross-compiled programs remote-debugging. You could maybe give this a try to be sure that this works for you and maybe then find the missing option in Qt Creator (or maybe this will help you find what is missing).
On the target machine run:
gdbserver :5000 yourprogram
On the host machine, run gdb and then load the symbol file:
(gdb) symbol-file yourprogram
On GDB on the host machine, you then have to connect to connect GDB to the remote gdbserver:
(gdb) target remote target_ip_address:5000
From then you can use GDB on the host controlling the program on the target.
I hope this helps!
Due to peculiarities in our makefile build system the file references contained in the debugging symbols look like this:
../src/main.cpp
../../src/utils/logger.cpp
This is no problem for GDB, but Qt Creator was unable to map these paths to the actual files. I was able to fix this by adding 'dir' statements in the GDB init file:
dir src
dir src/utils
...
Now it works.
We're using the Eclipse CDT 5 C++ IDE on Windows to develop a C++ application on a remote AIX host.
Eclipse CDT has the ability to perform remote debugging using gdbserver. Unfortunately, gdbserver is not supported on AIX.
Is anyone familiar with a way to debug remotely using Eclipse CDT without gdbserver? Perhaps using an SSH shell connection to gdb?
finally I got gdb run remotly anyhow now. At the Bug-symbol on the taskbar I took Debug Configurations - GDB Hardware Debugging.
In Main C/C++ Applications I set the full path on the Samba share of the executable (X:\abin\vlmi9506). I also set a linked folder on X:\abin in the project. Then I modified my batch-script in GDB Setup. It's not directly calling gdb in the plink-session but a unix-shell-script, which opens gdb. By this I have the possibility to set some unix environment-variables for the program before doing debug. The call in my batch:
plink.exe prevoax1 -l suttera -pw XXXXX -i /proj/user/dev/suttera/vl/9506/test/vlmi9506ddd.run 20155 dev o m
In the unix script I started gdb with the command line params from eclipse, that I found in my former tryals. The call in the shell command looks like this:
gdb -nw -i mi -cd=$LVarPathExec $LVarPathExec/vlmi9506
Then IBM just gives gdb 6.0 for AIX. I found version 6.8 in the net at http://www.perzl.org/aix/index.php?n=Main.Gdb. Our Admin installed it.
I can now step through the program and watch variables. I even can write gdb-commands directly in the console-view. yabadabadooooooo
Hope that helps to others as well. Can not tell, what was really the winner-action.
But each answer gives more new questions. Now I got 3 of them.
When I start the debug config I have to click restart in the toolbar to come really in the main procedure. Is it possible to come directly in main without restarting?
On AIX our programs are first preprocessed for embedded sql. The preprocessed c-source is put in another directory. When I duble-click the line to set a breakpoint, I get the warning "unresolved breakpoint" and in the gdb-console I see, that the break is set to the preprocessed source which is wrong. Is it possible to set the breakpoints on the right source?
We are using CICS on AIX. With the xldb-Debugger and the CDCN-command of CICS we manage that debugging is started, when we come in our programs. Is it possible to get that remotely (in plink) with gdb-eclipse as well?
I wouldn't normally take a shot in the dark on a question I can't really test the answer to, but since this one has sat around for a day, I'll give it a shot. It seems from looking at:
http://wiki.eclipse.org/TM_and_RSE_FAQ#How_can_I_do_Remote_Debugging_with_CDT.3F
...that even if the CDT has changed since that wiki page was made, you should still be able to change the debug command to:
ssh remotehost gdb
instead of using TM which uses gdbserver. This will probably be slightly slower than the TM remote debugging since that actually uses a local gdb, but on the other hand this way you won't have to NFS or SMB mount your source code to make it available to the local debugger (and if you're on a LAN it probably won't matter anyhow).
There's also a reference TCF implementation for linux, which you may or may not have any luck recompiling for AIX, but it allows for remote debugging if gdbserver is otherwise not available:
http://wiki.eclipse.org/DSDP/TM/TCF_FAQ
tried also to remotly debug an aix-appl with windows eclipse-cdt-gdb.
Got blocked at the end with unix/windows path-problems. Maybe my result can help u a little further - maybe you already got it work. I'm interested in your comment. asked on eclipse news portal- following the answer of martin oberhuber (thanks again) tried dsp dd (also blocked with path problem) and set an request in eclipse bugzilla.
here the link to news:
http://www.eclipse.org/newsportal/article.php?id=406&group=eclipse.dsdp.tm
Here my bugzilla:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=252758
At the moment we still debug localy with xldb but I am trying ddd-gdb at the moment. At least locally gdb is running.