Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [pushed 1/2] PR gdb/18002: Fix reinsert of a permanent breakpoints
Date: Fri, 06 Mar 2015 14:31:00 -0000	[thread overview]
Message-ID: <86d24mi4ei.fsf@gmail.com> (raw)
In-Reply-To: <1425598969-7666-2-git-send-email-palves@redhat.com> (Pedro	Alves's message of "Thu, 5 Mar 2015 23:42:48 +0000")

Pedro Alves <palves@redhat.com> writes:

> Permanent breakpoints
> are always marked as inserted.  So if the permanent breakpoint doesn't
> have a shadow yet in its shadow buffer, but we set shadow_len before
> calling target_read_memory, then the still clear shadow_contents
> buffer will be used by the breakpoint masking code...  And then from
> there on, the permanent breakpoint has a broken shadow buffer, and
> thus any memory read out of that address will read bogus code, and
> many random bad things fall out from that.

Yes, that is what I observed on aarch64-linux too.

>
> The fix is just to set shadow_len at the same time shadow_contents is
> set, not one before and another after...
>
> Fixes all gdb.base/bp-permanent.exp FAILs on PPC64 GNU/Linux gdbserver
> and probably any other gdbserver port that doesn't do z0 breakpoints.

This patch fixes gdb.base/bp-permanent.exp FAILs on aarch64-linux too,
but there are some remains, which are not related.

> diff --git a/gdb/mem-break.c b/gdb/mem-break.c
> index aeffc93..0fb53cf 100644
> --- a/gdb/mem-break.c
> +++ b/gdb/mem-break.c
> @@ -53,12 +53,21 @@ default_memory_insert_breakpoint (struct gdbarch *gdbarch,
>  
>    /* Save the memory contents in the shadow_contents buffer and then
>       write the breakpoint instruction.  */
> -  bp_tgt->shadow_len = bplen;
>    readbuf = alloca (bplen);
>    val = target_read_memory (addr, readbuf, bplen);
>    if (val == 0)
>      {
> +      /* These must be set together, either before or after the shadow
> +	 read, so that if we're "reinserting" a breakpoint that
> +	 doesn't have a shadow yet, the breakpoint masking code inside
> +	 target_read_memory doesn't mask out this breakpoint using an
> +	 unfilled shadow buffer.  The core may be trying to reinsert a
> +	 permanent breakpoint, for targets that support breakpoint
> +	 conditions/commands on the target side for some types of
> +	 breakpoints, such as target remote.  */
> +      bp_tgt->shadow_len = bplen;
>        memcpy (bp_tgt->shadow_contents, readbuf, bplen);
> +

Your fix looks right to me, although I am testing a different one, in
which bp_location_has_shadow returns false if bl->permanent is true.
Anyway, Thanks for fixing this bug, Pedro.

-- 
Yao (齐尧)


  reply	other threads:[~2015-03-06 14:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-05 23:42 [pushed 0/2] PR gdb/18002: bp-permanent.exp failures Pedro Alves
2015-03-05 23:42 ` [pushed 2/2] gdb.base/bp-permanent.exp: Tighten regex Pedro Alves
2015-03-05 23:42 ` [pushed 1/2] PR gdb/18002: Fix reinsert of a permanent breakpoints Pedro Alves
2015-03-06 14:31   ` Yao Qi [this message]
2015-03-06 16:43     ` 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=86d24mi4ei.fsf@gmail.com \
    --to=qiyaoltc@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@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