qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	peterx@redhat.com
Subject: [PATCH v2 1/2] gdbstub: Assert len read from each register
Date: Thu,  9 Apr 2020 14:25:37 -0400	[thread overview]
Message-ID: <20200409182538.40816-2-peterx@redhat.com> (raw)
In-Reply-To: <20200409182538.40816-1-peterx@redhat.com>

This can expose the issue earlier on which register returned the wrong
result.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 gdbstub.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 171e150950..69656e1052 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -911,17 +911,23 @@ static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)
     CPUClass *cc = CPU_GET_CLASS(cpu);
     CPUArchState *env = cpu->env_ptr;
     GDBRegisterState *r;
+    int len = 0, orig_len = buf->len;
 
     if (reg < cc->gdb_num_core_regs) {
-        return cc->gdb_read_register(cpu, buf, reg);
+        len = cc->gdb_read_register(cpu, buf, reg);
+        goto out;
     }
 
     for (r = cpu->gdb_regs; r; r = r->next) {
         if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) {
-            return r->get_reg(env, buf, reg - r->base_reg);
+            len = r->get_reg(env, buf, reg - r->base_reg);
+            break;
         }
     }
-    return 0;
+
+out:
+    assert(len == buf->len - orig_len);
+    return len;
 }
 
 static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg)
-- 
2.24.1



  reply	other threads:[~2020-04-09 18:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 18:25 [PATCH v2 0/2] gdbstub: Unbreak i386 with gdb remote Peter Xu
2020-04-09 18:25 ` Peter Xu [this message]
2020-04-09 18:25 ` [PATCH v2 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb Peter Xu
2020-04-09 18:56   ` Peter Xu

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=20200409182538.40816-2-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).