[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH-for-5.0 11/12] gdbstub: Do not use memset() on GByteArray
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH-for-5.0 11/12] gdbstub: Do not use memset() on GByteArray |
Date: |
Tue, 14 Apr 2020 15:30:51 +0200 |
Introduce gdb_get_zeroes() to fill a GByteArray with zeroes.
Fixes: a010bdbe719 ("extend GByteArray to read register helpers")
Suggested-by: Peter Maydell <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
Since v1: Use memset (pm215)
---
include/exec/gdbstub.h | 10 ++++++++++
target/arm/gdbstub.c | 3 +--
target/xtensa/gdbstub.c | 6 ++----
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index 30b909ebd2..f44bdd2270 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -125,6 +125,16 @@ static inline int gdb_get_reg128(GByteArray *buf, uint64_t
val_hi,
return 16;
}
+static inline int gdb_get_zeroes(GByteArray *array, size_t len)
+{
+ guint oldlen = array->len;
+
+ g_byte_array_set_size(array, oldlen + len);
+ memset(array->data + oldlen, 0, len);
+
+ return len;
+}
+
/**
* gdb_get_reg_ptr: get pointer to start of last element
* @len: length of element
diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c
index 8efc535f2a..063551df23 100644
--- a/target/arm/gdbstub.c
+++ b/target/arm/gdbstub.c
@@ -47,8 +47,7 @@ int arm_cpu_gdb_read_register(CPUState *cs, GByteArray
*mem_buf, int n)
if (gdb_has_xml) {
return 0;
}
- memset(mem_buf, 0, 12);
- return 12;
+ return gdb_get_zeroes(mem_buf, 12);
}
switch (n) {
case 24:
diff --git a/target/xtensa/gdbstub.c b/target/xtensa/gdbstub.c
index 0ee3feabe5..4d43f1340a 100644
--- a/target/xtensa/gdbstub.c
+++ b/target/xtensa/gdbstub.c
@@ -105,8 +105,7 @@ int xtensa_cpu_gdb_read_register(CPUState *cs, GByteArray
*mem_buf, int n)
default:
qemu_log_mask(LOG_UNIMP, "%s from reg %d of unsupported size %d\n",
__func__, n, reg->size);
- memset(mem_buf, 0, reg->size);
- return reg->size;
+ return gdb_get_zeroes(mem_buf, reg->size);
}
case xtRegisterTypeWindow: /*a*/
@@ -115,8 +114,7 @@ int xtensa_cpu_gdb_read_register(CPUState *cs, GByteArray
*mem_buf, int n)
default:
qemu_log_mask(LOG_UNIMP, "%s from reg %d of unsupported type %d\n",
__func__, n, reg->type);
- memset(mem_buf, 0, reg->size);
- return reg->size;
+ return gdb_get_zeroes(mem_buf, reg->size);
}
}
--
2.21.1
- Re: [PATCH-for-5.0 10/12] hw/block/pflash: Check return value of blk_pwrite(), (continued)
- [PATCH-for-5.0 06/12] hw/openrisc/pic_cpu: Use qdev gpio rather than qemu_allocate_irqs(), Philippe Mathieu-Daudé, 2020/04/14
- [PATCH-for-5.0 03/12] qga: Extract qmp_guest_file_read() to common commands.c, Philippe Mathieu-Daudé, 2020/04/14
- [PATCH-for-5.0 05/12] vhost-user-gpu: Release memory returned by vu_queue_pop() with free(), Philippe Mathieu-Daudé, 2020/04/14
- [PATCH-for-5.0 02/12] qga: Extract guest_file_handle_find() to commands-common.h, Philippe Mathieu-Daudé, 2020/04/14
- [PATCH-for-5.0 11/12] gdbstub: Do not use memset() on GByteArray,
Philippe Mathieu-Daudé <=
- [PATCH-for-5.0 01/12] Revert "prevent crash when executing guest-file-read with large count", Philippe Mathieu-Daudé, 2020/04/14
- [PATCH-for-5.0 12/12] gdbstub: Introduce gdb_get_freg32() to get float32 registers, Philippe Mathieu-Daudé, 2020/04/14
- Re: [PATCH-for-5.0 00/12] various bugfixes, Michael S. Tsirkin, 2020/04/17