I am debugging a remote target and it seems like the software breakpoints are not working, however hardware breakpoints do work.
I want to be able to use the stepi command - but gdb seems to insist on using software breakpoints.
Is there a way to force gdb to use hardware breakpoints for stepi?
The target is an ARM STM32 chip debugged through a blackmagic probe.
One solution is to mark the memory region as read only which forces gdb to use hw breakpoints
I.e if my code is running on the addresses 0x8000000-0x8010000 i run
mem 0x8000000 0x8010000 ro
Related
I'm trying to use GDB to debug Qemu running on m68k architecture. I am attempting to make some changes to Qemu source to add some functionality to m68k support, and I am trying to use GDB to test changes I have currently made. Important to note is that I am using Qemu v5.2.0-rc1, as that is the version of Qemu currently utilized in a larger system that I am concurrently working with. Currently, I am using qemu-system-m68k to run buildroot (uClinux kernel) on that architecture, using the "-s -S" options for gdb. In a separate terminal, I am trying to run GDB on that remote target using (gdb) target remote localhost:1234, but I am getting the following error message:
warning: Architecture rejected target-supplied description
The connection to the uClinux Qemu kernel seems to go okay, but I cannot connect to the remote host.
I have tried finding any possible solutions to this problem, including setting the GDB architecture (currently says i386, not sure if this is right), which does not work. I have no idea how to get GDB running on this m68k Qemu emulated Linux kernel, and any help would be great. Thanks!
The error message means that QEMU's gdb stub sent gdb a description of what the CPU is (mostly a list of registers), and gdb didn't understand it. One common cause of this is trying to debug with a gdb for the wrong architecture.
You need to use a gdb which is aware of the the target architecture. On Ubuntu there is a 'gdb-multiarch' package which has a gdb-multiarch binary that knows about more than just x86. Otherwise you might need to build gdb from source. You can check if your gdb knows about m68k by running it with no arguments and typing the command set arch m68k. If it replies The target architecture is assumed to be m68k then it's OK (and your issue is something more complicated); if it gives you an error (eg Undefined item: "m68k") then you need to use a different gdb.
Classic setup: There is a bootloader, and application, compiled separately. If everything is right, the bootloader jumps on the application.
I attach a probe, run the gdbserver, start gdb with the bootloader binary. If I run file application.elf then I lose my symbols for the bootloader.
How can I observe the handover, and what the application does exactly right after the jump, by running one instruction at a time?
Probably possible with an SWD commander by tracing the PC step-by-step and using addr2line to decode each step, but I'm hoping for a more proper way.
You can load the symbols with:
gdb add-symbol-file
I want to write my own hypervisor for Intel Platform based on an open project and I want understand how to debug it.
I have real stend to debug on, but it reboots at faults and it is hard to find mistake. I've found I could use QEMU/KVM with nested hypervisor to debug it. May be there are any other variants? VMware is hanging with faults, as I understand. On AMD platforms I have used SimNow.
It will be good if the host system will be Windows.
Thank you for advices.
It depends on your flavor. The couple Qemu/GDB is a good start. Here are some useful hints if your host platform is Intel CPU, you can:
start qemu like this : qemu-system-x86_64 -enable-kvm -cpu host -s -S .... Qemu will boot the hypervisor along with its gdbserver and pause it until it receives continue command from gdb.
Start GDB like this: gdb /path/to/hypervisor then, target remote :1234 to attach the gdb to the gdbserver
Use hbreak instead of break, but you have only 4 breakpoints left
From this point, you may continue the debugging as for a simple application
I use GDBServer to do a remote debug with an ARM11 CPU. The software breakpoint works well, but we i use "hbreak test.c:5" to set a hardware breakpoint, CPU will never stop.
GDB version: 7.3.1
Target CPU: ARM11
Operation:
arm-linux-gdb ./main
(gdb) target remote 192.168.0.1:2345
(gdb) hbreak test.c:5 => HW breakpoint, it doesn't work. but if change to "b test.c:5", it will works
(gdb) c
Does anybody can tell me how to enable hardware debug with GDB7.3.1? Thanks!
Hardware breakpoints can only be manipulated by JTAG probes. GDB cannot access them, unless you have a JTAG probe (which I doubt you have) connected to your device and a software glue (eg OpenOCD), allowing GDB to communicate with the JTAG probe. On pandaboard, for instance, TI recommends those JTAG probes: http://omapedia.org/wiki/PandaBoard_JTAG_Debugging
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.