Compiling gdb for remote debugging - debugging

I'm trying to remote debug an application running on arm9
So far I've been able to cross compile and execute gdbserver on my device.
get gdb (7.2) sources and extract them
./configure --target=arm-none-linux-gnueabi --with-expat=/usr/local/lib/
make
cd gdb/gdbserver
./configure --host=arm-none-linux-gnueabi
make
tftp gdbserver to my device
run and connect via gdb to the device
gdbserver "seems" to start correctly and attach itself to my helloworld application
When I try to gdb to the remote server, I get
"warning: Can not parse XML target description; XML support was disabled at compile time"
Obviously, the compilation didn't take into account expat. I'm really unsure about how to specify the expat library path to the configuration script.

(old question but I stumbled into it via googling the same problem)
The problem is the missing "expat" lib. This is hard to guess because :
this lib is optional for compiling gdb
the "expat" name has no clear connection to XML...
So install "expat-dev" (with your packet manager or anything) and then relaunch ./configure. Be careful to install the "dev" version since we are doing recompilation and need the include files.
To be extra-sure, it's possible to add the "--with-expat" to the ./configure call so that it will stop with an error if expat is not found.

Somehow it worked anyway
Also, create a file ~/.gdbinit with
file /home/username/path/to/exec/exec_name
set sysroot /path/to/libraries/running/on/target/device
target remote HOST:PORT
b main

Related

Add debugging to bochs with macports

I can't seem to get debugging working on bochs. I installed it using macports. Specifically, when I launch bochs, the command line never appears.
I'm pretty sure I included the debugging variant when I installed it; but, I suppose I could have mis-typed it.
When I run port installed bochs, I get this
$ port installed bochs
The following ports are currently installed:
bochs #2.6.8_1+avx+sdl2+smp+term (active)
Which seems to suggest the debugging variant isn't installed; but, when I try to add the debugging variant, the response suggests that nothing need be done:
$ sudo port upgrade --enforce-variants bochs +debugging
---> Scanning binaries for linking errors
---> No broken files found.
Is there another way to verify the presence or absence of debugging, and add it, if necessary?
I believe the variant for bochs debugging is:
+debugger
In a standard bochs ./configure the option would be:
--enable-debugger
↳ https://github.com/macports/macports-ports/blob/master/emulators/bochs/Portfile#L51

compile gopacket on windows 64bit

I am trying to use gopacket on my windows 10.
I'm using it to sniff and inject packets directly to/from the NIC.
I can easily compile and run my code with GOARCH=386 but can't in GOARCH=amd64.
Worth noticing: I am NOT trying to cross-compile.
I'm using go1.6.windows-386 to compile the 32bit version and when I try to compile with GOARCH=amd64 I use go1.6.windows-amd64.
I used TDM-GCC as linux like compile tools.
The error isn't indicative. it just says
c:/WpdPack/Lib/x64/wpcap.lib: error adding symbols: File in wrong format
collect2.exe: error ld returned 1 exit status
Did anyone manage to build this, if it's even possible?
OK so I have figured it out.
In order to compile gopacket 64bit on windows you need to do the following:
Install go_amd64 (add go binaries to your PATH)
Install TDM GCC x64 (add TDM-GCC binaries to your PATH)
Also add TDM-GCC\x86_64-w64-mingw32\bin to your PATH
Install Winpcap
Download Winpcap developer's pack and extract it to C:\
Now the point is that there are missing linux static libraries files
(libwpcap.a and libpacket.a) from lib/x64 folder. I don't know why they weren't
included in the developers pack but anyway that's how we can generate them:
find wpcap.dll and packet.dll in your PC (typically in c:\windows\system32
copy them to some other temp folder or else you'll have to supply Admin privs to the following commands
run gendef on those files gendef wpcap.dll and gendef packet.dll (obtainable with MinGW Installation Manager, package mingw32-gendef)
this will generate .def files
Now we'll generate the static libraries files:
run dlltool --as-flags=--64 -m i386:x86-64 -k --output-lib libwpcap.a --input-def wpcap.def
and dlltool --as-flags=--64 -m i386:x86-64 -k --output-lib libpacket.a --input-def packet.def
Now just copy both libwpcap.a and libpacket.a to c:\WpdPack\Lib\x64
That's it.
Now gopacket should compile with no problems.
Thank you so much for the solution, it saved me a lot of time!
Just wanted to add that you can do the same with Npcap, modify the gopacket source code to point to Npcap and it will work too.
In case you don't know Npcap:
https://nmap.org/npcap/vs-winpcap.html
https://nmap.org/npcap/
I installed Npcap on Windows in "Wpcap API Compatibility Mode" and gopacket now works fine.

linux/bounds.h not found while compiling source of my driver

I am developing drivers for my embedded device that has linux kernel version 2.6.32. In driver code, I am including linux/modules.h but on compiling, It gives me error linux/bounds.h not found.
I have downloaded kernel source from linux git repository. I have checked path settings. They are ok.
I checked my kernel source, there is no bounds.h file. So why my driver is expecting that. Error is coming due to including modules.h.
First, I need to run make command, so that it can generate and link all necessary files.

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!

Compile C file on openwrt

I have built the openwrt firmware and installed it to a device.
Now I want to compile my source code in C in the device (I can ssh into it).
However, openwrt firmware is quite basic and does not include make.
How can I install make/ equivalent to compile my C source code inside the device running openwrt firmware?
OpenWrt is not intended to work as a build server, so you won't find compiler, linker etc. in its root file system. As you mentioned before, you've successfully compiled the firmware. That means you have cross compiler at hand, so you can cross compile your software and then copy it to your system via scp.
Another approach would be to create your own feed, add your software to this feed, so that at the end you'll get an ordinary ipkg package, that you can download and install via web interface. See OpenWrt documentation for more details.
Lots of Cross Compiler are available for host system i.e PC running any Linux OS.
Just install compiler corresponding to Architecture in which Openwrt is running,
e.g If OpenWRT running on ARM architecture,
sudo apt-get install gcc-arm-linux-gnueabi
then compile source code as:
arm-linux-gcc -o yourprogram yourprogram.c

Resources