From: Vikas Mishra <vikasm@vikasmishra.org>
To: gdb@sourceware.org
Cc: Vikas Mishra <vikasm@vikasmishra.org>
Subject: gdb breaking down at printing variable
Date: Thu, 26 Aug 2010 11:41:00 -0000 [thread overview]
Message-ID: <AANLkTikOMH8JmwpDMNj2M2-4eK5Pq3+Vc8BGk0Pxk84y@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1009 bytes --]
Hello Folks,
I am new to C++ but have used gdb in the past. I am using the python
pretty print extensions to the GDB to print STL containers. I wanted
to check with the mailing list about an issue that I was seeing
recently. I am seeing the issue both on Cygwin as well as in Linux.
Problem : Unable to print a vector during debugging.
How to reproduce it : I have attached a program which has two
functions - main and split, It is a very simple program that takes a
string and splits it into words (like Perl's split function). I am not
able to print the variable "ret" anywhere in the "split" function.
What is observed : Error seen is "virtual memory exahusted: can't
allocate xxxx bytes".
If I try to print "list_of_words" anywhere in the main function, it is
behaving as expected.
Version used : g++ 4.3.4 / gdb 7.1 (Cygwin). ; g++(4.5.1) / gdb-cvs (Linux)
Could someone let me know what is the issue here. Am I missing
something basic in which case could someone point me to it.
Regards,
Vikas
[-- Attachment #2: split.cc --]
[-- Type: application/octet-stream, Size: 1044 bytes --]
#include<iostream>
#include<cctype>
#include<string>
#include<vector>
using std::cout;
using std::vector;
using std::string;
using std::endl;
using std::isspace;
vector<string> split(const string& s);
int main()
{
string input_string = "gdb breaks on this program. ";
vector<string> list_of_words;
list_of_words = split(input_string);
// prepare for printing the vector
std::vector<string>::size_type i = 0;
while (i != list_of_words.size()) {
cout << list_of_words[i] << endl;
i++;
}
return 1;
}
vector<string> split(const string& s)
{
vector<string> ret;
typedef vector<string>::size_type string_size;
string_size i = 0;
while (i != s.size()) {
// Ignore initial spaces
while (i != s.size() && isspace(s[i]))
++i;
// Fix it on the beginning of the next word.
string_size j = i;
// Find the end of the next word.
while (j != s.size() && !isspace(s[j]))
++j;
// If we found some non whitespace char.
if (i != j) {
ret.push_back(s.substr(i,j-i));
i = j;
}
}
i = 0;
return ret;
}
next reply other threads:[~2010-08-26 11:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-26 11:41 Vikas Mishra [this message]
2010-08-26 12:25 ` André Pönitz
2010-08-26 20:55 ` Tom Tromey
2010-08-27 9:41 ` André Pönitz
2010-08-27 15:22 ` Tom Tromey
[not found] <AANLkTimFU22phqb1uScS7PZ5WGJ65+1uD6RtkWMt352h@mail.gmail.com>
2010-08-26 15:21 ` Vikas Mishra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTikOMH8JmwpDMNj2M2-4eK5Pq3+Vc8BGk0Pxk84y@mail.gmail.com \
--to=vikasm@vikasmishra.org \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox