From: Pedro Alves <palves@redhat.com>
To: Mark Wielaard <mark@klomp.org>
Cc: Markus Trippelsdorf <markus@trippelsdorf.de>,
gdb-patches@sourceware.org, Nathan Sidwell <nathan@acm.org>,
Ian Lance Taylor <iant@google.com>,
Nick Clifton <nickc@redhat.com>
Subject: Re: [PATCH] libiberty: Initialize d_printing in all cplus_demangle_* functions.
Date: Tue, 14 Mar 2017 10:50:00 -0000 [thread overview]
Message-ID: <ceed1687-0bdd-3888-d806-223109a7eceb@redhat.com> (raw)
In-Reply-To: <1489482296.21350.77.camel@klomp.org>
On 03/14/2017 09:04 AM, Mark Wielaard wrote:
> That looks good. But note that there is one behavioral change.
> cplus_demangle_fill_component is defined as:
>
> /* Fill in most component types with a left subtree and a right
> subtree. Returns non-zero on success, zero on failure, such as an
> unrecognized or inappropriate component type. */
>
> And gdb/cp-name-parser.y fill_comp does:
>
> i = cplus_demangle_fill_component (ret, d_type, lhs, rhs);
> gdb_assert (i);
>
> So you have an extra sanity check. Where before you might have silently
> created a bogus demangle_component. Which I assume is what you want.
Indeed, and I think it is.
> But it might depend on what gdb_assert precisely does
gdb_assert triggers the infamous:
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
> and if the parser input is normally "sane" or not.
The only thing that is validated is that we don't create
a component with a left/right subtree when that doesn't make sense
for the component type. I think trying to create such a component
would be a parser/grammar/production bug, even with invalid input.
I had run into that assert in fill_comp yesterday actually, with a slightly
different/larger patch. At first I saw the cplus_demangle_fill_component
declaration in demangle.h, but didn't see the implementation in cp-demangle.c, and
thought that was just some oversight/left over. So I though I'd add one. I factored
out a cplus_demangle_fill_component out of cp-demangle.c:d_make_comp, following the
same pattern used by the other cplus_demangle_fill* / d_make* function pairs.
Only after did I notice that actually, there's an implementation of
cplus_demangle_fill_component in cplus-demint.c... AFAICS, that's only
used by GDB. No other tool in the binutils-gdb repo, nor GCC's repo uses it, AFAICS.
So I figured that I'd remove the cplus-demint.c implementation, in favor of
the new implementation in cp-demangle.c based on d_make_comp. And _that_ ran into the
assertion, because the implementations are exactly the same. GDB fills in some types with
NULL left components and fills them in later. For example, for DEMANGLE_COMPONENT_POINTER:
ptr_operator : '*' qualifiers_opt
- { $$.comp = make_empty (DEMANGLE_COMPONENT_POINTER);
- $$.comp->u.s_binary.left = $$.comp->u.s_binary.right = NULL;
+ { $$.comp = fill_comp (DEMANGLE_COMPONENT_POINTER, NULL, NULL);
$$.last = &d_left ($$.comp);
$$.comp = d_qualify ($$.comp, $2, 0); }
Note how cp-demangle.c:d_make_comp's validations are stricter than
cp-demint.c:cplus_demangle_fill_component's. The former only allows
lazy-filling for a few cases:
[...]
/* These are allowed to have no parameters--in some cases they
will be filled in later. */
case DEMANGLE_COMPONENT_FUNCTION_TYPE:
[...]
While cp-demint.c:cplus_demangle_fill_component, the version that
GDB uses, allows that in all cases. IOW, passing in a NULL left/right subtree
to cplus_demangle_fill_component when the component type expects one is OK, assuming
that the caller will fill them in afterwards. I crossed checked the types in
the new fill_comp calls with the checks inside cplus_demangle_fill_component now,
and I believe they're all OK.
Maybe it'd be possible to avoid this lazy filling in, but I didn't
bother trying.
Thanks,
Pedro Alves
next prev parent reply other threads:[~2017-03-14 10:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1489356354-27648-1-git-send-email-mark@klomp.org>
[not found] ` <20170313181150.GA287@x4>
[not found] ` <20170313182959.GC2167@stream>
[not found] ` <a3993cdc-dbb0-e377-3e46-a84d8cf971a0@redhat.com>
2017-03-13 20:35 ` Mark Wielaard
2017-03-14 1:26 ` Pedro Alves
2017-03-14 9:05 ` Mark Wielaard
2017-03-14 10:50 ` Pedro Alves [this message]
2017-03-27 14:28 ` [pushed/ob] cplus_demangle_fill_component: Handle DEMANGLE_COMPONENT_RVALUE_REFERENCE (Re: [PATCH] libiberty: Initialize d_printing in all cplus_demangle_* functions.) Pedro Alves
2017-03-27 14:36 ` [pushed] gdb/cp-name-parser.y: Eliminate make_empty, use cplus_demangle_fill_component " Pedro Alves
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=ceed1687-0bdd-3888-d806-223109a7eceb@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=iant@google.com \
--cc=mark@klomp.org \
--cc=markus@trippelsdorf.de \
--cc=nathan@acm.org \
--cc=nickc@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