diff mbox series

[v2,08/21] gdbstub: move fromhex/tohex routines to internals

Message ID 20230105164320.2164095-9-alex.bennee@linaro.org
State Superseded
Headers show
Series gdbstub: re-organise to for better compilation behaviour | expand

Commit Message

Alex Bennée Jan. 5, 2023, 4:43 p.m. UTC
These will be needed from multiple places in the code. They are
declared as inline so move to the header and fix up to modern coding
style.

The only other place that messes with hex stuff at the moment is the
URI handling in utils but that would be more code churn so leave for
now.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 gdbstub/internals.h | 27 +++++++++++++++++++++++++++
 gdbstub/gdbstub.c   | 20 --------------------
 2 files changed, 27 insertions(+), 20 deletions(-)

Comments

Richard Henderson Jan. 6, 2023, 8:43 p.m. UTC | #1
On 1/5/23 08:43, Alex Bennée wrote:
> These will be needed from multiple places in the code. They are
> declared as inline so move to the header and fix up to modern coding
> style.
> 
> The only other place that messes with hex stuff at the moment is the
> URI handling in utils but that would be more code churn so leave for
> now.
> 
> Signed-off-by: Alex Bennée<alex.bennee@linaro.org>
> ---
>   gdbstub/internals.h | 27 +++++++++++++++++++++++++++
>   gdbstub/gdbstub.c   | 20 --------------------
>   2 files changed, 27 insertions(+), 20 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

diff --git a/gdbstub/internals.h b/gdbstub/internals.h
index 9784db2dc5..c8bb85cf34 100644
--- a/gdbstub/internals.h
+++ b/gdbstub/internals.h
@@ -74,6 +74,33 @@  typedef struct GDBState {
     int supported_sstep_flags;
 } GDBState;
 
+
+/*
+ * Inline utility function, convert from int to hex and back
+ */
+
+static inline int fromhex(int v)
+{
+    if (v >= '0' && v <= '9') {
+        return v - '0';
+    } else if (v >= 'A' && v <= 'F') {
+        return v - 'A' + 10;
+    } else if (v >= 'a' && v <= 'f') {
+        return v - 'a' + 10;
+    } else {
+        return 0;
+    }
+}
+
+static inline int tohex(int v)
+{
+    if (v < 10) {
+        return v + '0';
+    } else {
+        return v - 10 + 'a';
+    }
+}
+
 /*
  * Break/Watch point support - there is an implementation for softmmu
  * and user mode.
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 92b2f5c3db..d4ee23b51c 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -531,26 +531,6 @@  static void put_buffer(const uint8_t *buf, int len)
 #endif
 }
 
-static inline int fromhex(int v)
-{
-    if (v >= '0' && v <= '9')
-        return v - '0';
-    else if (v >= 'A' && v <= 'F')
-        return v - 'A' + 10;
-    else if (v >= 'a' && v <= 'f')
-        return v - 'a' + 10;
-    else
-        return 0;
-}
-
-static inline int tohex(int v)
-{
-    if (v < 10)
-        return v + '0';
-    else
-        return v - 10 + 'a';
-}
-
 /* writes 2*len+1 bytes in buf */
 static void memtohex(GString *buf, const uint8_t *mem, int len)
 {