render / rpms / qemu

Forked from rpms/qemu 5 months ago
Clone

Blame 0002-gdbstub-Fix-gdb_register_coprocessor-register-counti.patch

298366
From c0c080c5d1ce6c236ba8ab5db3a17043c665d0f6 Mon Sep 17 00:00:00 2001
298366
From: =?UTF-8?q?Andreas=20F=C3=A4rber?= <afaerber@suse.de>
298366
Date: Mon, 12 Aug 2013 18:09:47 +0200
298366
Subject: [PATCH] gdbstub: Fix gdb_register_coprocessor() register counting
298366
MIME-Version: 1.0
298366
Content-Type: text/plain; charset=UTF-8
298366
Content-Transfer-Encoding: 8bit
298366
298366
Commit a0e372f0c49ac01faeaeb73a6e8f50e8ac615f34 reorganized the register
298366
counting for GDB. While it seems correct not to let the total number of
298366
registers skyrocket in an SMP scenario through a static variable, the
298366
distinction between total register count and 'g' packet register count
298366
(last_reg vs. num_g_regs) got lost among the way.
298366
298366
Fix this by introducing CPUState::gdb_num_g_regs and using that in
298366
gdb_handle_packet().
298366
298366
Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
298366
Cc: qemu-stable@nongnu.org (stable-1.6)
298366
Tested-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
298366
Tested-by: Max Filippov <jcmvbkbc@gmail.com>
298366
Tested-by: Peter Maydell <peter.maydell@linaro.org>
298366
Signed-off-by: Andreas Färber <afaerber@suse.de>
298366
(cherry picked from commit 35143f0164e6933a85c7c2b8a89a040d881a9151)
298366
298366
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
298366
---
298366
 gdbstub.c         | 6 ++++--
298366
 include/qom/cpu.h | 2 ++
298366
 qom/cpu.c         | 2 +-
298366
 3 files changed, 7 insertions(+), 3 deletions(-)
298366
298366
diff --git a/gdbstub.c b/gdbstub.c
298366
index 1af25a6..9d067d6 100644
298366
--- a/gdbstub.c
298366
+++ b/gdbstub.c
298366
@@ -621,6 +621,8 @@ void gdb_register_coprocessor(CPUState *cpu,
298366
         if (g_pos != s->base_reg) {
298366
             fprintf(stderr, "Error: Bad gdb register numbering for '%s'\n"
298366
                     "Expected %d got %d\n", xml, g_pos, s->base_reg);
298366
+        } else {
298366
+            cpu->gdb_num_g_regs = cpu->gdb_num_regs;
298366
         }
298366
     }
298366
 }
298366
@@ -902,7 +904,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
298366
     case 'g':
298366
         cpu_synchronize_state(s->g_cpu);
298366
         len = 0;
298366
-        for (addr = 0; addr < s->g_cpu->gdb_num_regs; addr++) {
298366
+        for (addr = 0; addr < s->g_cpu->gdb_num_g_regs; addr++) {
298366
             reg_size = gdb_read_register(s->g_cpu, mem_buf + len, addr);
298366
             len += reg_size;
298366
         }
298366
@@ -914,7 +916,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
298366
         registers = mem_buf;
298366
         len = strlen(p) / 2;
298366
         hextomem((uint8_t *)registers, p, len);
298366
-        for (addr = 0; addr < s->g_cpu->gdb_num_regs && len > 0; addr++) {
298366
+        for (addr = 0; addr < s->g_cpu->gdb_num_g_regs && len > 0; addr++) {
298366
             reg_size = gdb_write_register(s->g_cpu, registers, addr);
298366
             len -= reg_size;
298366
             registers += reg_size;
298366
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
298366
index 0d6e95c..3e49936 100644
298366
--- a/include/qom/cpu.h
298366
+++ b/include/qom/cpu.h
298366
@@ -152,6 +152,7 @@ struct kvm_run;
298366
  * @current_tb: Currently executing TB.
298366
  * @gdb_regs: Additional GDB registers.
298366
  * @gdb_num_regs: Number of total registers accessible to GDB.
298366
+ * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
298366
  * @next_cpu: Next CPU sharing TB cache.
298366
  * @kvm_fd: vCPU file descriptor for KVM.
298366
  *
298366
@@ -188,6 +189,7 @@ struct CPUState {
298366
     struct TranslationBlock *current_tb;
298366
     struct GDBRegisterState *gdb_regs;
298366
     int gdb_num_regs;
298366
+    int gdb_num_g_regs;
298366
     CPUState *next_cpu;
298366
 
298366
     int kvm_fd;
298366
diff --git a/qom/cpu.c b/qom/cpu.c
298366
index aa95108..e71e57b 100644
298366
--- a/qom/cpu.c
298366
+++ b/qom/cpu.c
298366
@@ -240,7 +240,7 @@ static void cpu_common_initfn(Object *obj)
298366
     CPUState *cpu = CPU(obj);
298366
     CPUClass *cc = CPU_GET_CLASS(obj);
298366
 
298366
-    cpu->gdb_num_regs = cc->gdb_num_core_regs;
298366
+    cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs;
298366
 }
298366
 
298366
 static int64_t cpu_common_get_arch_id(CPUState *cpu)