Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SIGTRAP despite no set breakpoints; hidden hardware breakpoint?

I am debugging this piece of software for an STM32 embedded system. In one of the functions my programs keeps hitting some sort of breakpoint:

SIGTRAP, Trace/breakpoint trap

However, in GDB, when I do info breakpoints I get No breakpoints or watchpoints. The breakpoint actually corresponds to a breakpoint I had set quite some time ago, in another version of the executable. When I set that breakpoint, GDB told me automatically using a hardware breakpoint on read-only memory (or a similar message).

I think the hardware breakpoint remains on my chip, despite having loaded a new version of the software. If there is indeed a spurious breakpoint, how can I locate and remove it?

like image 425
Randomblue Avatar asked Mar 23 '12 10:03

Randomblue


People also ask

What is Sigtrap signal?

SIGTRAP. The SIGTRAP signal is sent to a process when an exception (or trap) occurs: a condition that a debugger has requested to be informed of — for example, when a particular function is executed, or when a particular variable changes value.

How to add breakpoint in Visual Studio?

Set data breakpoints (native C++ only) If the value is read but not changed, execution doesn't break. To set a data breakpoint: In a C++ project, start debugging, and wait until a breakpoint is reached. On the Debug menu, choose New Breakpoint > Data Breakpoint.

How to skip a line while debugging in Visual Studio?

You can also click on the line you want to skip to and hit Ctrl+F10 (Run to Cursor). It will jump directly to that line.

How to move from one breakpoint to another in Visual Studio?

Press Ctrl+Alt+F9 or choose ReSharper | Navigate | Breakpoints… from the main menu . Alternatively, you can press Ctrl+Shift+A , start typing the command name in the popup, and then choose it there.


2 Answers

Ok. Long answer: Hardware breakpoints are usually set by writing to some special CPU registers. This is done by gdb. If gdb dies, it can left those installed in CPU. I guess your implementation (of gdb) does not either clear or examine those, when it connects to your target. To locate them, you would need to list the contents of hardware breakpoints registers on your CPU (don't know how to do this on STM32). Workaround would be (informed guess) be this: set few HW breakpoints (typically there are only a few, seldom more than 8) using gdb, then remove all of them. This should overwrite and then clean those hw registers. Once you do set those breakpoints (before removing them), do "continue" (just in case, as gdb sets breakpoints only at that time).

like image 190
dbrank0 Avatar answered Sep 19 '22 15:09

dbrank0


The following helped me:

# Ones I hit the SIGTRAP: (gdb) f 0  # Show the current stack frame of the current thread. #0  0x4003ed70 in pthread_create@@GLIBC_2.4 () from /opt/CodeSourcery/arm-2011.09/arm-none-linux-gnueabi/libc/lib/libpthread.so.0  # The fragment of interest is the current address: 0x4003ed70. # Set the hardware assisted breakpoint at the current address: (gdb) hbreak *0x4003ed70  # Continue execution (without hitting SIGTRAP): (gdb) c # Continuing. 
like image 25
Robin Kuzmin Avatar answered Sep 23 '22 15:09

Robin Kuzmin