From: Jan Vrany <jan.vrany@fit.cvut.cz>
To: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Subject: Re: [PATCH v2] Fix segfault when invoking -var-info-path-expression on a dynamic varobj
Date: Thu, 28 Jun 2018 09:31:00 -0000 [thread overview]
Message-ID: <ae75d7400e1bc1e4c72c865c933f76b08e927de8.camel@fit.cvut.cz> (raw)
In-Reply-To: <93b2a663-2672-10c0-097d-9a9026fa4e00@simark.ca>
On Tue, 2018-06-26 at 22:24 -0400, Simon Marchi wrote:
> On 2018-06-25 04:59 PM, Jan Vrany wrote:
> > Invoking -var-info-path-expression on a dynamic varobj lead either
> > in wrong
> > (nonsense) result or to a segmentation fault in
> > cplus_describe_child().
> > This was caused by the fact that varobj_get_path_expr() called
> > cplus_path_expr_of_child() ignoring the fact the parent of the
> > variable
> > is dynamic. Then, cplus_describe_child() accessed the underlaying C
> > type
> > members by index, causing (i) either wrong (nonsense) expression
> > being
> > returned (since dynamic child may be completely arbibtrary value)
> > or (ii) segmentation fault (in case the index higher than number of
> > underlaying C type members.
> >
> > This fixes the problem by checking whether a varobj is a child of a
> > dynamic
> > varobj and, if so, reporting an error to MI consumer as described
> > in
> > the documentation.
>
> Hi Jan,
>
> The patch does not compile for me:
>
> CXX varobj.o
> In file included from /home/simark/src/binutils-
> gdb/gdb/common/common-defs.h:90,
> from /home/simark/src/binutils-gdb/gdb/defs.h:28,
> from /home/simark/src/binutils-gdb/gdb/varobj.c:18:
> /home/simark/src/binutils-gdb/gdb/varobj.c: In function âconst char*
> varobj_get_path_expr(const varobj*)â:
> /home/simark/src/binutils-gdb/gdb/varobj.c:969:41: error: âcurâ was
> not declared in this scope
> gdb_assert (!varobj_is_dynamic_p (cur));
> ^~~
> /home/simark/src/binutils-gdb/gdb/common/gdb_assert.h:33:13: note: in
> definition of macro âgdb_assertâ
> ((void) ((expr) ? 0
> : \
>
Hi Simon,
argh, sorry. Forgotten "git add". Will fix.
> ^~~~
> > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> > index 38c59c7e66..fa47387357 100644
> > --- a/gdb/mi/mi-cmd-var.c
> > +++ b/gdb/mi/mi-cmd-var.c
> > @@ -438,7 +438,15 @@ mi_cmd_var_info_path_expression (const char
> > *command, char **argv, int argc)
> >
> > /* Get varobj handle, if a valid var obj name was specified. */
> > var = varobj_get_handle (argv[0]);
> > -
> > +
> > + /* -var-info-path-expression is currently not valid for children
> > of
> > + a dynamic varobj. */
> > + for (struct varobj *cur = var->parent; cur != nullptr; cur =
> > cur->parent)
> > + {
> > + if (varobj_is_dynamic_p (cur))
> > + error (_("Invalid variable object (child of a dynamic
> > varobj)"));
> > + }
> > +
>
> To make it simpler, instead of checking all the parents recursively
> here, have you
> considered adding a check to the varobj_get_path_expr_parent, like
> this? I haven't
> given it a very long though, but it does pass your test :).
>
> diff --git a/gdb/varobj.c b/gdb/varobj.c
> index f2c10ddc57ff..e601cf0b9780 100644
> --- a/gdb/varobj.c
> +++ b/gdb/varobj.c
> @@ -948,6 +948,9 @@ varobj_get_path_expr_parent (const struct varobj
> *var)
> while (!is_root_p (parent) && !is_path_expr_parent (parent))
> parent = parent->parent;
>
> + if (varobj_is_dynamic_p (parent))
> + error (_("Invalid variable object (child of a dynamic
> varobj)"));
> +
> return parent;
> }
>
No, I have not considered this - still learning internals. Generally
I prefer to validate input as soon as possible rather than go on and
fail later but I agree it's a matter of taste.
However, varobj_get_path_expr_parent() is indeed much better place for
the assert (the one that failed to compile :), something like:
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 02441410e8..050c240bef 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -948,6 +948,10 @@ varobj_get_path_expr_parent (const struct varobj
*var)
while (!is_root_p (parent) && !is_path_expr_parent (parent))
parent = parent->parent;
+ /* Computation of full rooted expression for children of dynamic
+ varobjs is not supported. */
+ gdb_assert (!varobj_is_dynamic_p (parent));
+
return parent;
}
What do you think? I'll send a new version once we decide.
Thanks! Jan
next prev parent reply other threads:[~2018-06-28 9:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-25 20:59 Jan Vrany
2018-06-27 2:25 ` Simon Marchi
2018-06-28 9:31 ` Jan Vrany [this message]
2018-06-28 12:17 ` Simon Marchi
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=ae75d7400e1bc1e4c72c865c933f76b08e927de8.camel@fit.cvut.cz \
--to=jan.vrany@fit.cvut.cz \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).