Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8942389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:30:12+00:00 2026-06-15T11:30:12+00:00

I’d like to write an assert-style macro that stops only if I am running

  • 0

I’d like to write an assert-style macro that stops only if I am running the program in a debugger. AFAIK, the only available debugger on my box is gdb, so I’ll talk about that one.

The documentation for the SIGTRAP signal indicates that it is intended for pausing the debugger, so I should be able to put

if (!assertion) raise(SIGTRAP);

in my code. It works to break GDB at the right point, but just running this from the command line also halts the program, as both bash and zsh helpfully interpret the “trace/breakpoint trap” signal to mean that the program should halt entirely.

Are there any signals that GDB uses but which I can expect that everything else ignores? Or is there a method beyond signals to pause execution in GDB without disrupting non-debugger operation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:30:13+00:00Added an answer on June 15, 2026 at 11:30 am

    Forking a child and trying to ptrace parent is a portable UNIX way to determine whether you are being ptraced, or not, and you can then do raise(signo) only when being traced.

    Note however, that this mechanism will also trigger if you are running under strace or truss, effectively making your program crash under them, which is probably undesirable.

    A Linux-specific way that is easier to implement is to look in /proc/self/status for non-0 TracerPid. This still has the same disadvantage as above.

    Another Linux-specific way is to call getppid, then readlink("/proc/$PARENT_PID/exe", ...), and see if that points to GDB.

    Both Linux-specific examples assume that /proc is mounted, which is usually true, but doesn’t have to be.

    Are there any signals that GDB uses but which I can expect that everything else ignores?

    The SIGWINCH is usually ignored by non-terminal-handling programs. GDB will also ignore it, but you can make GDB stop on SIGWINCH by issuing this command:

    (gdb) handle SIGWINCH stop print nopass
    Signal        Stop  Print   Pass to program   Description
    SIGWINCH      Yes   Yes     No                Window size changed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I am currently running into a problem where an element is coming back from
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.