Using Eclipse to remotely debug with gdbserver - gdb

Does anyone know why I can't use Eclipse CDT to remotely debug a device when I manage it on the command-line with gdb using target remote command? I do get a warning when connecting, but other than that it seems to work fine.
With Eclipse I should have the correct settings and gdbserver informs me on the remote machine that a connection was establised but after that Eclipse gives an error: 'Launching Debug' has encountered a problem. The request failed: Target is not responding (timed out). Remote device also says "Killing inferior" (which I don't get with gdb). The error log shows nothing else either.
I am using the same process, binary and gdb executable in both cases and connecting to the same device & port. I'm using gdb 7.1 and the host is 64-bit Ubuntu Lucid.

I had same issue and found that iptables was generating issues.
Have you tried stopping or disabling your firewall? In case of iptables you have to do:
/etc/init.d/iptables stop
On the other hand, after you start your application (before connecting your debugger) have you checked the debug port availability through netstat?
#On linux
netstat -nap
#On windows
netstat -nab
Hope to help.

Related

Connection to valgrind embedded gdb server is failing with an error "Connection reset by peer"

I trying to follow the instruction on connecting to valgrind using gdb.
Valgrind memcheck is starts properly and asks to connect using following gdb command:
target remote | vgdb --pid=53181
but when I run this command, I get an error
Remote communication error. Target disconnected.: Connection reset by
peer
what is my mistake?
It appears that error
Remote communication error. Target disconnected.: Connection reset by peer.
is general and may indicate invalid command as well. If you run in gdb
target remote | something
it will give you the same error message.
It appeared for me, that extra space after | symbol was excess.
Correct command was actually
target remote |vgdb --pid=53181
My GDB version is GNU gdb (Ubuntu 10.2-0ubuntu1~18.04~2) 10.2

GDB connection timeout when attaching to QEMU

I am trying to attach GDB to QEMU for my bare-metal project on RISC-V. However, it is unable to connect. My host is a Ubuntu by WSL on a Windows machine. I am using the firmware supplied by openSBI to launch my custom "bootloader" (boot.bin).
I run QEMU (in Ubuntu WSL):
qemu-system-riscv64.exe --machine virt -m 256 -bios ./opensbi/build/platform/generic/firmware/fw_jump.bin -kernel ./boot.bin --nographic -s -S
Then I open a new command line (new Ubuntu WSL window) and start GDB:
riscv-gnu/bin/riscv64-unknown-elf-gdb
and specify a target:
target remote localhost:1234
After a few seconds this gives me the error: localhost:1234: Connection timed out.
Has anyone else had this issue, would be greatful for your help!
Usually WSL has an IP address in a different network so if you want to make a connection between WSL and Windows you need to provide correct IP and not just localhost.
Check ipconfig under Windows and in gdb provide IP of the correct network.
In my case Windows has a local address of 192.168.1.24 and WSL has 172.190.0.1. So to connect gdb from WSL to qemu running on Windows I need to type target remote 192.168.1.24.

How to run Boost.Asio server on port 80?

I have a simple boost.asio server which I am trying to run it on port 80. I am running the code inside a try-catch and I get a "bind" exception error. The value of boost::error_code is 13 which I think is "access denied".
I am running the code from Xcode on Mac running Yosemite. I also tried to run Xcode with sudo.
How can I fix this issue ?
Run as root.
The problem is that you don't have the permission to bind to a privileged port (<1024 on most systems).
If you're certain that the child process of Xcode runs as root, find out which process is already listening on port 80 (lsof and netstat)

GDB Connection Timeout

I used to the St-write to burn .bin to the STM32F4 and saw the message which I expected. Now, I hope to understand how GPIO init. Hence, I use OpenOCD and arm-none-eabi-gdb to do that. Here, it is my process.
$ minicom
$ openocd -f /opt/openocd/share/openocd/scripts/board/stm32f4discovery.cfg
$ arm-none-eabi-gdb main.elf
(gdb) target remote localhost:3333
(gdb) localhost:3333: Connection timed out.
How do I check the port of OpenOCD? Why does it occur timeout?
That certainly means that openocd did not start or that the port is busy.
Usually, you use :
openocd -f board/stm32f4discovery.cfg
You should check that your session is running.
Are you running a virtual linux machine on a windows host?
If so, you probably need to replace localhost with 10.0.0.2 (or whatever your windows IP is).
A good way to know, is to telnet to the openOCD address and port 4444 and see if you get the openOCD prompt, and can type a few commands.

Two-machine GDB debugging between Macs over Ethernet - transaction timed out

I am trying to debug a device driver which is crashing the kernel on a Mac using a remote machine running gdb (trying to follow the instructions here). Both machines are connected to the same network by Ethernet (same router even, and both can access the network). I have also set nvram boot-args="debug=0x144" on the target and restarted.
I then load the kernel extension on the target as usual. On the host machine I start gdb like this:
$ gdb -arch i386 /Volumes/KernelDebugKit/mach_kernel
Once in gdb, I load the kernel macros and set up for remote attachment
(gdb) source /Volumes/KernelDebugKit/kgmacros
(gdb) target remote-kdp
(gdb) kdp-reattach 11.22.33.44
However, the last command then does not make a connection and I get an endless spool of
kdp_reply_wait: error from kdp_receive: receive timeout exceeded
kdp_transaction (remote_connect): transaction timed out
kdp_transaction (remote_connect): re-sending transaction
What is the correct way to get gdb connected to the target machine?
There are a number of ways to break into the target, including:
Kernel panic, as stated in your answer above.
Non-maskable interrupt, which is triggered by the cmd-option-ctrl-shift-esc key combination.
Code a break in your kernel extension using PE_enter_debugger(), which is declared in pexpert/pexpert.h
Halt at boot by setting DB_HALT (0x01) in the NVRAM boot-args value.
Additionally, you may need to set a persistent ARP table entry, as the target is unable to respond to ARP requests while stopped in the debugger. I use the following in my debugger-launch shell script to set the ARP entry if it doesn't already exist:
if !(arp -a -n -i en0 | grep '10\.211\.55\.10[)] at 0:1c:42:d7:29:47 on en0 permanent' > /dev/null) ; then
echo "Adding arp entry"
sudo arp -s 10.211.55.10 00:1c:42:d7:29:47
fi
Someone more expert could probably improve on my bit of shell script.
All of the above is documented in http://developer.apple.com/library/mac/documentation/Darwin/Conceptual/KernelProgramming/KernelProgramming.pdf.
The answer is simply to make sure the target has a kernel panic before you try to attach gdb from the host.