Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Ross Morley <ross@tensilica.com>
To: gdb@sources.redhat.com
Subject: -var-create on invalid expression causes seg. fault
Date: Sat, 19 Feb 2005 08:33:00 -0000	[thread overview]
Message-ID: <42168F31.3020805@tensilica.com> (raw)

Hi,

One of our customers reported GDB crashing when an MI
variable is created on an invalid address and then referenced.
I've debugged to the point of finding the cause, but am not
knowledgable enough on the MI variables to know the right
way to fix it. I filed a bug report because this needs
to get fixed in the latest sources. I'd appreciate any
insight so I can fix it in our 5.2.1 based sources.
I don't have the time to look deeper, but someone on this
list is familiar with this stuff I'm sure.

-var-create on an expression that's invalid (eg. "(*1)")
creates a variable and retains a ptr in var->value. That
gets freed by free_all_values() next command. Later a
-var-update or -var-evaluate-expression on that variable
dereferences the freed memory, causing a seg. fault.

Here's the relevant code snippet from varobj_create():

  /* We definitively need to catch errors here.
     If evaluate_expression succeeds we got the value we wanted.
     But if it fails, we still go on with a call to evaluate_type()  */
  if (gdb_evaluate_expression (var->root->exp, &var->value))
    {
      /* no error */
      release_value (var->value);
      if (VALUE_LAZY (var->value))
    gdb_value_fetch_lazy (var->value);
    }
  else
    var->value = evaluate_type (var->root->exp);

  var->type = VALUE_TYPE (var->value);

gdb_evaluate_expression() fails, and GDB goes on to call
evaluate_type(). I don't think simply clearing var->value
is correct. Maybe release_value()? I don't have the time
to acquire enough knowledge of GDB varobj.

I looked at the GDB 6.3 source and it seems to be the same.

Now why would anyone try to evaluate *1? It's some tool that
uses MI, one of our customers reported. I'm not clear on why
GDB even creates the variable in this case, but it does.
GDB should report an error, not crash.

Thanks for any insight.

---------------
Ross Morley
Tensilica, Inc.
ross@tensilica.com



             reply	other threads:[~2005-02-19  1:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-19  8:33 Ross Morley [this message]
2005-02-19 23:10 Nick Roberts
2005-02-20 17:44 ` Ross Morley
2005-02-23 16:23   ` Daniel Jacobowitz
2005-02-24  3:23     ` Ross Morley
2005-02-24  6:54       ` Ross Morley
2005-02-25 11:29     ` Nick Roberts

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=42168F31.3020805@tensilica.com \
    --to=ross@tensilica.com \
    --cc=gdb@sources.redhat.com \
    /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