public inbox for gdb@sourceware.org
 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

* Re: gdb breaking down at printing variable
  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
  0 siblings, 1 reply; 6+ messages in thread
From: André Pönitz @ 2010-08-26 12:25 UTC (permalink / raw)
  To: gdb

On Thursday 26 August 2010 13:41:29 ext Vikas Mishra wrote:
> 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.

This is most likely http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44731 
i.e. not gdb's fault.

> 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.

This a consequence of above (gdb trying to read data from a wrong
location, triggered by the faulty debug information) but I am pretty
sure it can be triggered independently by uninitialized or corrupted
data in the "real" vector object containing the same "noise".

You should be able to verify that by creating such an object and
purposely corrupt it by overwriting it with the data you currently
get with, say,  p {char[12]}&ret.

Andre'

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gdb breaking down at printing variable
  2010-08-26 12:25 ` André Pönitz
@ 2010-08-26 20:55   ` Tom Tromey
  2010-08-27  9:41     ` André Pönitz
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2010-08-26 20:55 UTC (permalink / raw)
  To: André Pönitz; +Cc: gdb

>>>>> "André" == André Pönitz <andre.poenitz@nokia.com> writes:

André> This is most likely http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44731 
André> i.e. not gdb's fault.

I think there actually is a gdb bug here.  gdb should be resilient even
when the inferior's memory is trashed.

There is a known problem that lazy_string is not fully lazy: it is read
eagerly before printing.  So if you make a very large lazy string, gdb
will internal error.

This wasn't in bugzilla, so I filed:

    http://sourceware.org/bugzilla/show_bug.cgi?id=11948

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gdb breaking down at printing variable
  2010-08-26 20:55   ` Tom Tromey
@ 2010-08-27  9:41     ` André Pönitz
  2010-08-27 15:22       ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: André Pönitz @ 2010-08-27  9:41 UTC (permalink / raw)
  To: gdb

On Thursday 26 August 2010 22:54:58 ext Tom Tromey wrote:
> >>>>> "André" == André Pönitz <andre.poenitz@nokia.com> writes:
> 
> André> This is most likely http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44731 
> André> i.e. not gdb's fault.
> 
> I think there actually is a gdb bug here.  gdb should be resilient even
> when the inferior's memory is trashed.

In my response I also said

  >> [...] I am pretty sure it can be triggered independently by uninitialized 
  >> or corrupted data in the "real" vector object containing the same "noise".

I do acknowledge that there are two independent issues, one gcc and 
one gdb related. I mostly meant to say that even if gdb were not at fault
Vikas Mishra's problem would still exist due to the gcc bug (and I was
assuming that the problems of uninitialized data and gdb's own pretty-
printers had been discussed often enough in the past to not reiterate ;-)).

Andre' 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gdb breaking down at printing variable
  2010-08-27  9:41     ` André Pönitz
@ 2010-08-27 15:22       ` Tom Tromey
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2010-08-27 15:22 UTC (permalink / raw)
  To: André Pönitz; +Cc: gdb

>>>>> "André" == André Pönitz <andre.poenitz@nokia.com> writes:

André> I do acknowledge that there are two independent issues, one gcc
André> and one gdb related. I mostly meant to say that even if gdb were
André> not at fault Vikas Mishra's problem would still exist due to the
André> gcc bug (and I was assuming that the problems of uninitialized
André> data and gdb's own pretty- printers had been discussed often
André> enough in the past to not reiterate ;-)).

Yeah, sorry I misunderstood.

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gdb breaking down at printing variable
       [not found] <AANLkTimFU22phqb1uScS7PZ5WGJ65+1uD6RtkWMt352h@mail.gmail.com>
@ 2010-08-26 15:21 ` Vikas Mishra
  0 siblings, 0 replies; 6+ messages in thread
From: Vikas Mishra @ 2010-08-26 15:21 UTC (permalink / raw)
  To: gdb

Andre'

On Thu, Aug 26, 2010 at 8:47 PM, Vikas Mishra <vikasm@vikasmishra.org> wrote:
> On Thursday 26 August 2010 13:41:29 ext Vikas Mishra wrote:
>> 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.
>
> This is most likely http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44731
> i.e. not gdb's fault.

Thanks a lot for pointing this out. The error of course disappeared if
I did a temporary hack and replaced the return with an assignment and
return. This is good enough for me at the moment.

Regards,
Vikas

^ permalink raw reply	[flat|nested] 6+ messages in thread

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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).