How to debug native code using gdbserver - debugging

I have followed the instructions for debugging native code found here:
http://www.eweek.com/c/a/Linux-and-Open-Source/How-to-Set-Up-Android-Platform-Development-and-Debugging/
To do this, you have to launch gdbserver from an adb shell. I have copied gdbserver to the target filesystem, but can't make it executable (chmod gives permissions errors or 'bad mode' errors).
Do I need to root my device to start gdbserver? (How??)
Do I need to copy gdbserver manually?
Is there an easier way to do this? This is turning into a black hole of productivity. All I want to do is debug my jni code...
TIA for any help.

First of all, /sdcard is mounted with 'noexec' option. Thus, you cannot execute any executable file from /sdcard. You have to put gdbserver to an another file system, like /data/local/tmp.
Second, if you are developing it as an Android application, gdbserver requires proper permission to attach the target process for debug. There are two ways for that. Using run-as or getting root.
Please take a look at Running ndk-gdb with package not found error on motorola phone.

Related

GCC: make sources built-in into binary

I have a program that I need to debug on remote machine.
Due to the issue character it should be run in a certain way, that I can't reproduce simply running there, so I put a sleep before the problematic area.
I am able to attach to the process with gdb during this sleep period, but I don't have source files on the remote machine.
Is it possible to compile program the way that sources will be built-in into binary itself?
AFAIK, that is not possible.
Another way is to just rsync the sources onto the remote machine.

Windows deletes make executable file upon running. Why?

I am trying to get some code running which uses make. I've downloaded and installed both MinGW (standard 32 bit) and TDM-GCCs flavor of MinGW on my 64-bit Windows 7 machine.
When I run make (i.e. mingw32-make.exe) in Administrator mode, I get the following error message:
Windows cannot access the specified path, or file. You may not have the appropriate permissions to access the item.
The weird/scary part is that, upon running, it immediately deletes the exe file.
I ran a checksum SHA1 as recommended in the comments using the Microsoft (R) File Checksum Integrity Verifier V2.05:
C:\path\to\folder>fciv.exe -sha1 mingw32-make.exe
//
// File Checksum Integrity Verifier version 2.05.
//
c8ae5c780ab7bed652883d6443b5bfe5e23d30c9 mingw32-make.exe
I don't understand what this output means, but maybe it's helpful to someone.
Notes:
This happens regardless of where the file is located on my pc.
This behavior is specific to the make program (others such as gfortran and gcc appear to be working fine)
Renaming the file makes no difference.
I am an administrator on the pc
Same behavior when I run the program from the explorer or command line.
My anti-virus program (Avast) does not detect any problems with the file when I scan it.
I got the MinGW setup file from this SourceForge page.
I got the TDM-GCC web installer from this page.
The file size is 219,662 bytes (from both the main MinGW and TDM-GCC packages)
I have run make from the command line where I have started the command prompt by way of selecting Run as Administrator in the context menu.
I have also tried to run make by selecting Run as Administrator when I have it selected.
I run the command mingw32-make when this behavior occurs. I have also tried renaming it to things like make and foo with the same result.
The first time this happened with both MinGW it deleted the original file and I re-installed it using the mingw-get application. From thereon after I started making copies of the original mingw32-make for testing.
For the make executable, I have all permissions (including Read & execute) except the special permissions field.
After using the process manager I found out it was indeed Avast that was the problem :S A couple of lines revealed avast actually deleted the file before windows got around to executing it, which was the reason for the windows message. I put Avast on 'Silent Mode' a while back; I thought the only purpose of this mode was to suppress notifications about minor updates, but apparently it also gave Avast permission to deal with 'threats' silently as well.
After figuring that out the solution was straightforward. I just went into the settings and created an exception for the mingw32-make.exe file. It now runs without issue.
Thanks very much for your help everyone!
User account has administrator privilege but when user started to work , not all privilege are taken in account , just start your application for compiling with run with administrator mode try this : https://technet.microsoft.com/en-in/library/cc781763(v=ws.10).aspx

Different Ways to Run GDB on my embedded platform

I want to run GDB on my ARM embedded board...
I have referred online that we can set up GDB server and can do remote debugging but still i am missing proper steps to set up whole environment for GDB Debugging..
Can anyone please provide me a proper guidance from cross compiling GDB to running my gdb for debugging on embedded board ??
I appreciate any inputs
I assume you have a toolchain that lets you build applications for your embedded linux platform. This should include gdb (named something like arm-linux-gdb).
Next check if linux for your board already includes gdb/gdbserver. If it does, you don't have to build anything. If it does not, configure gdb like this:
./path/to/gdb/source/configure --host=arm-linux --target=arm-linux --prefix=/path/to/installation/directory
Then make and make install.
Note that --host and --target will probably match your toolchains prefix.
As part of this installation you will get gdbserver. Install it on your board.
Then use it, as explained here. It depends on your connection type (TCP, serial), but you need to run program under gdbserver on board (gdbserver binary), then run you toolchain's gdb on PC and connect to board using "target remote" command.
Have you already looked at Buildroot? It will take care of cross-compiler and root file system. You can choose to compile host and target gdb/gdbserver, so that you'll have everything from one hand. See BR's documentation.
Remote debugging of embedded systems:
GDB, as a server, must be compiled into the debugging target build in order to support connected GDB clients. When running on the client side, there must exist a copy of the target source as well as an unstripped (of symbols) version of the executable.
GCC compilation should be done with the -g flag.
On the target/server side, run with
gdbserver <port> --attach <pid> or gdbserver host:<port> <program>
On the client side, run gdb and then
(gdb) target remote IP:PORT
What gdb client to run? Must be built with the right target processor in mind, for example
.../toolchain/bin/powerpc-linux-gdb core/mydaemon/src/mydaemon -x gdb-command-script
-x is a filename option
Hope this helps!
Remote debugging of embedded systems: GDB, as a server, must be compiled into the debugging target build in order to support connected GDB clients. When running on the client side, there must exist a copy of the target source as well as an unstripped (of symbols) version of the executable.
GCC compilation should be done with the -g flag.
On the target/server side, run with
gdbserver --attach or gdbserver host:
On the client side, run gdb and then
(gdb) target remote IP:PORT
What gdb client to run? Must be built with the right target processor in mind, for example
.../toolchain/bin/powerpc-linux-gdb core/mydaemon/src/mydaemon -x gdb-command-script
-x is a filename option
Hope this helps!

can not use gdb debug mac app

I used homebrew installed gdb, and created code sign for it. It seems I have installed it completed. But when I use gdb command to debug the app in /Applicaions, it always prompted me no such file or directory, I have no idea about it. My system is 10.9.4, and GDB version is 7.7.1.
Wait for your help!
GDB does not automatically load application bundle directories. You need to give it the path to the main Mach-O executable. Something like /Applications/Reveal.app/Contents/MacOS/....
I don't know what the main executable for Reveal.app is named, but if it is named Reveal your command would look like this.
gdb /Applications/Reveal.app/Contents/MacOS/Reveal

Can I use my gdb to debug an XCode project

I have a XCode which builds and runs under XCode.
I would like to know if it is possible to debug it using a gdb I build under Mac OSX (gdb 7 to be specified). If yes, can you please tell me how can I do that?
Thank you.
gdb-7.0 reverse debugging currently can only work with two classes of targets:
1) a remote simulator/emulator/virtual-machine that supports going backwards, or
2) the built in "process record" target, which at present has only been ported to x86-linux, x86-64 linux, and moxie linux.
Well, now -- I take that back. I recently discovered that process record can work with any remote x86 target, so if you're connecting with your macintosh target via "target remote", you might just be able to do it!
There is an online tutorial for process record here:
http://www.sourceware.org/gdb/wiki/ProcessRecord/Tutorial
More info about process record here:
http://www.sourceware.org/gdb/wiki/ProcessRecord
And about gdb reverse debugging here:
http://www.sourceware.org/gdb/wiki/ReverseDebug
So you want to use your own version of gdb to debug your executable? Easy!
Open Terminal, and do something like this:
$ cd <directory where Xcode project lives>
$ cd build/Debug (for example - depends on project configuration)
$ /usr/local/bin/my-gdb ./MyExecutable
Of course, specifying the actual path to your custom gdb version.
XCode's debugger is gdb (likely with Apple-specific modifications.) When you debug an application you can get to the gdb command line by opening the Console from the Run menu.
What requirements are imposed on your application that would require you to debug with your own version of gdb?

Resources