[PATCH v2 37/50] gdbstub/helpers: Convert gdb_get_regl() macro to inlined helper

Philippe Mathieu-Daudé posted 50 patches 1 month ago
Maintainers: Laurent Vivier <laurent@vivier.eu>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Michael Rolnik <mrolnik@gmail.com>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, "Dr. David Alan Gilbert" <dave@treblig.org>, Richard Henderson <richard.henderson@linaro.org>, Brian Cain <brian.cain@oss.qualcomm.com>, Paolo Bonzini <pbonzini@redhat.com>, Song Gao <gaosong@loongson.cn>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <arikalo@gmail.com>, Stafford Horne <shorne@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Yoshinori Sato <yoshinori.sato@nifty.com>, Ilya Leoshkevich <iii@linux.ibm.com>, David Hildenbrand <david@kernel.org>, Thomas Huth <thuth@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Bastian Koppelmann <kbastian@rumtueddeln.de>
[PATCH v2 37/50] gdbstub/helpers: Convert gdb_get_regl() macro to inlined helper
Posted by Philippe Mathieu-Daudé 1 month ago
Rather than checking TARGET_LONG_BITS at build time,
check target_long_bits() at runtime.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/gdbstub/helpers.h | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/include/gdbstub/helpers.h b/include/gdbstub/helpers.h
index 402514716d7..b2f41d6d280 100644
--- a/include/gdbstub/helpers.h
+++ b/include/gdbstub/helpers.h
@@ -88,6 +88,20 @@ static inline int gdb_get_zeroes(GByteArray *array, size_t len)
     return len;
 }
 
+/**
+ * gdb_get_regl: append @val in @buf using 32 or 64-bit, depending on target
+ *
+ * This function is legacy and deprecated, thus should not be used in new code.
+ */
+static inline int gdb_get_regl(GByteArray *buf, uint64_t val)
+{
+    if (target_long_bits() == 64) {
+        return gdb_get_reg64(buf, val);
+    } else {
+        return gdb_get_reg32(buf, val);
+    }
+}
+
 /**
  * gdb_get_reg_ptr: get pointer to start of last element
  * @len: length of element
@@ -101,12 +115,4 @@ static inline uint8_t *gdb_get_reg_ptr(GByteArray *buf, int len)
     return buf->data + buf->len - len;
 }
 
-#ifdef COMPILING_PER_TARGET
-#if TARGET_LONG_BITS == 64
-#define gdb_get_regl(buf, val) gdb_get_reg64(buf, val)
-#else
-#define gdb_get_regl(buf, val) gdb_get_reg32(buf, val)
-#endif
-#endif /* COMPILING_PER_TARGET */
-
 #endif /* _GDBSTUB_HELPERS_H_ */
-- 
2.52.0


Re: [PATCH v2 37/50] gdbstub/helpers: Convert gdb_get_regl() macro to inlined helper
Posted by Pierrick Bouvier 1 month ago
On 2/19/26 11:19 AM, Philippe Mathieu-Daudé wrote:
> Rather than checking TARGET_LONG_BITS at build time,
> check target_long_bits() at runtime.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/gdbstub/helpers.h | 22 ++++++++++++++--------
>   1 file changed, 14 insertions(+), 8 deletions(-)
> 

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>