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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:31:19+00:00 2026-06-09T22:31:19+00:00

I am debugging a large application and I would like to break before a

  • 0

I am debugging a large application and I would like to break before a certain string is written to std::cerr. I there a way to do this?

There are many places in the code where this string is written.
The string is not always of the form

std::cerr << "some error code";

It might be of other forms such as

std::cerr << write_error_code();

Also note that there are many things being written to std::cerr so I can’t just break on std::cerr.

I also have the same question but for std::cout but I will post another question if the answer does not apply to that as well.

  • 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-09T22:31:20+00:00Added an answer on June 9, 2026 at 10:31 pm

    This is a С++ example I have made on Linux. The example has been built with gcc 4.3.

    #include <iostream>
    #include <stdio.h>
    #include <setjmp.h>
    
    void write_error_code()
    {
      std::cerr << "some error code";
    }
    
    int main()
    {
      std::cout << "Start, main()\n";
      std::cerr << "some error code" << std::endl;
      std::cerr << "some error code?" << std::endl;
      std::cerr << "some error code?" << std::endl;
      write_error_code();
      std::cout << "End, main()\n";
    
      return 0;
    }
    

    I took a look at disassemble and saw that std::cerr << "" is a function with the symbol name _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.
    The function has 2 args: __out and __s.
    So I created a .gdbinit file:

    host: srv2-x64rh5-02, OS: Linux 2.6.18-238.el5>more .gdbinit
    file a.out
    b _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
    commands
    silent
    if strcmp(__s, "some error code") == 0
      print "Some error code has been given as an arg"
      bt
      c
    else
      c
    end
    end
    r
    quit
    

    And here I test my program:

    host: srv2-x64rh5-02, OS: Linux 2.6.18-238.el5>gdb -q ./a.out
    Reading symbols from /import/home/sergey.kurenkov/src/linux.x64.5.0/tests/test.br_on_std_cerr/a.out...done.
    Breakpoint 1 at 0x400710
    warning: no loadable sections found in added symbol-file system-supplied DSO at 0x2aaaaaaab000
    Start, main()
    $1 = "Some error code has been given as an arg"
    #0  std::operator<< <std::char_traits<char> > (__out=..., __s=0x400a4c "some error code")
        at /home/zalex/test/gcc_build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ostream:509
    #1  0x0000000000400873 in main () at main.cpp:13
    some error code
    some error code?
    some error code?
    $2 = "Some error code has been given as an arg"
    #0  std::operator<< <std::char_traits<char> > (__out=..., __s=0x400a4c "some error code")
        at /home/zalex/test/gcc_build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ostream:509
    #1  0x000000000040084f in write_error_code () at main.cpp:7
    #2  0x00000000004008f5 in main () at main.cpp:18
    some error codeEnd, main()
    
    Program exited normally.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large application written using .Net remoting for file transfer. This was
I am debugging on a large code base and I’d like to know what
we're having this big problem with our application. It's a rather large application with
I'm writing a DLL add-on for an application that internally has large parts written
I am working on debugging an application that seems to leak memory like crazy;
I have a large project that executes without problem when not debugging (even when
I am debugging someone else's work and the solution is quite large. When I
Debugging a PHP program, is there any add-on/plug-in for browser which I can view
Debugging experience http://www.dmhermitage.org/wtfborders.png This is making me want to kill myself. I have some
I'm in the process of moving a large classic ASP application to ASP.NET MVC

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.