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

  • Home
  • SEARCH
  • 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 6978227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:43:39+00:00 2026-05-27T17:43:39+00:00

I seem to have some kind of multithreading bug in my code that makes

  • 0

I seem to have some kind of multithreading bug in my code that makes it crash once every 30 runs of its test suite. The test suite is non-interactive. I want to run my test suite in gdb, and have gdb exit normally if the program exits normally, or break (and show a debugging prompt) if it crashes. This way I can let the test suite run repeatedly, go grab a cup of coffee, come back, and be presented with a nice debugging prompt. How can I do this with gdb?

  • 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-05-27T17:43:40+00:00Added an answer on May 27, 2026 at 5:43 pm

    This is a little hacky but you could do:

    gdb -ex='set confirm on' -ex=run -ex=quit --args ./a.out
    

    If a.out terminates normally, it will just drop you out of GDB. But if you crash, the program will still be active, so GDB will typically prompt if you really want to quit with an active inferior:

    Program received signal SIGABRT, Aborted.
    0x00007ffff72dad05 in raise (sig=...) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
    64  ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
        in ../nptl/sysdeps/unix/sysv/linux/raise.c
    A debugging session is active.
    
        Inferior 1 [process 15126] will be killed.
    
    Quit anyway? (y or n) 
    

    Like I said, not pretty, but it works, as long as you haven’t toggled off the prompt to quit with an active process. There is probably a way to use gdb’s quit command too: it takes a numeric argument which is the exit code for the debugging session. So maybe you can use –eval-command=”quit stuff”, where stuff is some GDB expression that reflects whether the inferior is running or not.

    This program can be used to test it out:

    #include <signal.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main() {
        if (time(NULL) % 2) {
            raise(SIGINT);
        }
        puts("no crash");
        return EXIT_SUCCESS;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some colors that seem to come from a Delphi TColor variable (e.g
Greetings, I have a problem which would seem to involve some kind of z-index
I'm writing my own shell, and seem to have some kind of problem with
We have some code that is making use of the new postMessage functionality in
I seem to have added the core library to some kind of Autocomplete-Blacklist. If
Let's say I want to have some kind of a cache that did something
I have read through several reviews on Amazon and some books seem outdated. I
I seem to have an app on my Dev server that has lots of
I seem to have a problem understanding how to conditionally test a boolean value
Okay so you have and array A[]... that is passed to you in some

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.