Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: asmwarrior <asmwarrior@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] avoid the crash of gdb+pretty printer on initialized local variables
Date: Fri, 02 Dec 2011 16:51:00 -0000	[thread overview]
Message-ID: <m3wrae9au9.fsf@fleche.redhat.com> (raw)
In-Reply-To: <4ED8534D.2050100@gmail.com> (asmwarrior@gmail.com's message of	"Fri, 02 Dec 2011 12:25:49 +0800")

>>>>> ">" == ext asmwarrior <asmwarrior@gmail.com> writes:

>> When debugger with python pretty printer, I sometimes get the gdb crash
>> when I try to show the value of uninitialized local variables.

gdb should not crash.

Is this that mingw-builds-only problem that keeps popping up?
I forget, something to do with not using the right gcc flag?

>> The patch is just a work-around/hack to handle this problem.
>> I just first check if the symbol is a local variable, and then check the
>> current line SAL is smaller than the variable's declaration line. If
>> true, which means this local variable is OK to show, if not, than I just
>> skip it.

This is not ok.  First, due to optimization, lines can be smeared
around, leading to the wrong result here.  Second, a variable can be
trashed for many reasons, like other bugs in the code.  In this second
case it is still unacceptable for gdb to crash.

In theory the existing code will detect memory access errors and cause
printing to stop early.  If you have a case where this doesn't work
properly, make a reproducible test case.

>> void fun()
>> {
>>     wxString *psty = (wxString*) NULL;
>>     wxString wxStr(L"wxString");
>>     wxStr += L" Value";
>>     std::string stdStr("std::string");
>>     stdStr.append(" value");
>>     std::map<int, std::string> m;
>>     m[0] = "000";
>>     m[1] = "111";     //break point here, we stop here

This kind of thing is generally not very reproducible.  It relies on
compiler differences, libraries, runtime differences.  Something that is
plain C and just writes bad values directly would be better.

>> If you try to run "print v", or "info locals", then gdb will crash (I'm
>> using gdb cvs build under WindowsXP, mingw, python 2.7)

>> I believe that this patch will not be applied, because it is just a
>> hack, right?

I think it is actively wrong in some cases.

>> Basically, gdb should alive with out any crash in any condition, but
>> sometimes, I think a workaround is also necessary. I have see that in
>> QTcreator, when they want to show the contents of a stl container, it do
>> many sanity check. like:

>> The length of the std::vector should be positive, and it's size should
>> be limited.
>> Also many other sanity checks

Adding a sanity check to the vector printer would probably be ok.
That is maintained in libstdc++.

Checking the size is probably not ok.  gdb lazily fetch sub-objects; and
respects length limits like "set print elements" or the MI equivalent
for dynamic varobjs.  Having the printer check that the length is "short
enough" is generally wrong for this reason.

Tom


  reply	other threads:[~2011-12-02 16:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4ED379D8.4060808@gmail.com>
2011-12-02  4:32 ` asmwarrior
2011-12-02 16:51   ` Tom Tromey [this message]
2011-12-04  1:41     ` asmwarrior
     [not found]       ` <CAF4KFGqyz0WMWWJt9x1HZpO+urMo9jJLyudcRrHxUTqJf8mvqA@mail.gmail.com>
     [not found]         ` <CAF4KFGp2cDOzKdV62MfX0vpHUAxj1D2W0W3cBZnZpYHPYxZEuA@mail.gmail.com>
2011-12-05 10:13           ` Fwd: " Martin Runge
2011-12-05 12:48             ` André Pönitz
2011-12-20 14:38             ` Tom Tromey
2011-12-05 21:51       ` Tom Tromey
2011-12-06 10:34         ` asmwarrior
2011-12-06 15:41           ` Tom Tromey

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=m3wrae9au9.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=asmwarrior@gmail.com \
    --cc=gdb-patches@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