tags:

views:

60

answers:

1

In my c++ program I'm using a library which will "send?" a Sigtrap on a certain operations when I'm dubugging it ( using gdb as debugger). I can then choose weather I wish to Continue or Stop the program. If I choose to continue the program works as expected but setting custum breakpoints, after a Sigtrap has been caught, causes the debugger / program to crash....

So here my questions:

  1. What causes such a Sigtrap? Is it a leftover line of code that can be removed, or is it caused by the debugger when he "finds something he doesn't like" ?
  2. Is a sigtrap, generally speaking, a bad thing, and if so: Why does the program run flawless when I compile a Release and not a Debug Version.
  3. What does a Sigtrap indicate?

This is a more general aproach to a question I posted yesterday http://stackoverflow.com/questions/3469463/boost-filesystem-recursive-directory-iterator-constructor-causes-sigtraps-and-de.
I think my question was far to specific, and I don't want you to solve my problem but help me (and hopefully others) to understand the background....

Thanks a lot

+1  A: 

With processors that support instruction breakpoints or data watchpoints, the debugger will ask the CPU to watch for instruction accesses to a specific address, or data reads/writes to a specific address, and then run full-speed.

When the processor detects the event, it will trap into the kernel, and the kernel will send SIGTRAP to the process being debugged. Normally, SIGTRAP would kill the process, but because it is being debugged, the debugger will be notified of the signal and handle it, mostly by letting you inspect the state of the process before continuing execution.

With processors that don't support breakpoints or watchpoints, the entire debugging environment is probably done through code interpretation and memory emulation, which is immensely slower. (I imagine clever tricks could be done by setting pagetable flags to forbid reading or writing, whichever needs to be trapped, and letting the kernel fix up the pagetables, signaling the debugger, and then restricting the page flags again. This could probably support near-arbitrary number of watchpoints and breakpoints, and run only marginally slower for cases when the watchpoint or breakpoint aren't frequently accessed.)

The question I placed into the comment field looks apropos here, only because Windows isn't actually sending a SIGTRAP, but rather signaling a breakpoint in its own native way. I assume when you're debugging programs, that debug versions of system libraries are used, and ensure that memory accesses appear to make sense. You might have a bug in your program that is papered-over at runtime, but may in fact be causing further problems elsewhere.

I haven't done development on Windows, but perhaps you could get further details by looking through your Windows Event Log?

sarnold
Fist of all: thank you for your reply. It helped me to understand the basic Idea behind Sigtraps.I don't think that there's an problem with my code, not because I code so good, but because I can trigger the Sigtrap in a program consisting of only 1 method call to the library... ( and I assume that the boost library is very unlikely to contain such flaws )There's probably something wrong with the way I link the static libraries into my project
zitroneneis