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 86915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:19:15+00:00 2026-05-10T22:19:15+00:00

Is there a way to identify at run-time of an executable is being run

  • 0

Is there a way to identify at run-time of an executable is being run from within valgrind? I have a set of C++ unit tests, and one of them expects std::vector::reserve to throw std::bad_alloc. When I run this under valgrind, it bails out completely, preventing me from testing for both memory leaks (using valgrind) and behavior (expecting the exception to be thrown).

Here’s a minimal example that reproduces it:

#include <vector> int main() {     size_t uint_max = static_cast<size_t>(-1);     std::vector<char> v;     v.reserve(uint_max); } 

Running valgrind, I get this output:

Warning: silly arg (-1) to __builtin_new() new/new[] failed and should throw an exception, but Valgrind    cannot throw exceptions and so is aborting instead.  Sorry.    at 0x40192BC: VALGRIND_PRINTF_BACKTRACE (valgrind.h:319)    by 0x401C823: operator new(unsigned) (vg_replace_malloc.c:164)    by 0x80487BF: std::vector<char, std::allocator<char> >::reserve(unsigned) new_allocator.h:92)    by 0x804874D: main (vg.cxx:6) 

I’d like to modify my unit test to simply skip the offending code when it’s being run from within valgrind. Is this possible?

  • 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. 2026-05-10T22:19:16+00:00Added an answer on May 10, 2026 at 10:19 pm

    You should look at this page from the Valgrind manual, it contains a RUNNING_ON_VALGRIND macro (included from valgrind.h) which does what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen How to identify CAAnimation within the animationDidStop delegate? , this is
I have several variables of type char (array), int, and double. Is there a
Being a bit of a C++ fanatic, i am in desperate need of using
My LAMP application seems to eventually use up all of my server's memory and
I'm hoping someone can enlighten me as to what could possibly be causing this
I am essentially attempting to replace all of the footnotes in a large text.
I want to verify binary compatibility between 2 JARs. Following the suggestions in this
I'm developing ASP.NET 4.0 Website using SQL server 2008 with Membership Framework. It runs
My application has been successfully updating for ages, and I've been making changes, releasing
I'm developing a complex website with users having multiple roles. The users are also

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.