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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:30:41+00:00 2026-05-31T20:30:41+00:00

I am testing a function vect_dbg(vector<int>) that returns the contents of a STL vector

  • 0

I am testing a function vect_dbg(vector<int>) that returns the contents of a STL vector as a C string, so I can call it with gdb output vect_dbg(test) or put it in a watch.

#include<vector>
using namespace std;

int main()
{
    vector<int> test; //breakpoint; output vect_dbg(test) ends debugging.
    for (int i=0;i<=10;i++) test.push_back(i);
    return 0;
}

#include<sstream>
const char* vect_dbg(const vector<int> &V)
{
    stringstream ss;
    for (int i=0;i<V.size();i++)
        ss<<"V["<<i<<"]:"<<V[i]<<' ;'; //line 16
    static char sEnu[256];
    ss.getline(sEnu,256);
    return sEnu;
}

Unfortunately, output vect_dbg(test) breaks the debugging.

The program being debugged was signaled while in a function called
from GDB. GDB has restored the context to what it was before the call.
To change this behavior use “set unwindonsignal off” Evaluation of the
expression containing the function (vect_dbg(std::vector > const&)) will be abandoned. Program received
signal SIGSEGV, Segmentation fault. 0x004014b1 in vect_dbg
(V=@0x22ff34) at main.cpp:16

I discovered that the function works if I make test global, but i couldn’t figure out a solution for the locally defined vector. How can i solve this? Many thanks.

EDIT: Mainly solved, the answer was pretty obvious, the vector wasn’t initialized at breakpoint. Now i am wondering if it’s possible to detect that in vect_dbg.
An alternative i found is to declare the vector<int> static.

  • 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-31T20:30:42+00:00Added an answer on May 31, 2026 at 8:30 pm

    Put breakpoint one line after (on for loop). The variable test was not yet initialized when you trying to use it.

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

Sidebar

Related Questions

I have a function that gets a string passed to it. When testing the
CREATE FUNCTION testing(id INT, dsc TEXT) RETURNS TEXT BEGIN DECLARE ntxt TEXT; SET ntxt
I'm attempting to write a performance testing function that can take any function, run
I am testing a function that returns an array. The array could be different
I am testing a function called extractions that operates over any list. extractions ::
<script type=text/javascript> function testing() { $.ajax({ type: POST, url: testing.php, data: call=+$(#abc).val(), success: function(msg){
I'm testing the VB function below that I got from a Google search. I
I am working with a unit-testing suite that hijacks function calls and tests expected
#includeiostream class CMessage { public:int a; CMessage(){} ~CMessage(){} }; void Testing(CMessage *f_pMessage)//l_pMessage is output
I am testing a function that permit to connect to FTP server. Here is

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.