Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* gdb breaking down at printing variable
@ 2010-08-26 11:41 Vikas Mishra
  2010-08-26 12:25 ` André Pönitz
  0 siblings, 1 reply; 6+ messages in thread
From: Vikas Mishra @ 2010-08-26 11:41 UTC (permalink / raw)
  To: gdb; +Cc: Vikas Mishra

[-- 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;

}

^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <AANLkTimFU22phqb1uScS7PZ5WGJ65+1uD6RtkWMt352h@mail.gmail.com>]

end of thread, other threads:[~2010-08-27 15:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-26 11:41 gdb breaking down at printing variable Vikas Mishra
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox