aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport/common-utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'gdbsupport/common-utils.h')
-rw-r--r--gdbsupport/common-utils.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
index a168458..10bf9f4 100644
--- a/gdbsupport/common-utils.h
+++ b/gdbsupport/common-utils.h
@@ -196,6 +196,16 @@ in_inclusive_range (T value, T low, T high)
extern ULONGEST align_up (ULONGEST v, int n);
extern ULONGEST align_down (ULONGEST v, int n);
+/* Sign-extend the value V, using N as the number of valid bits. That
+ is, bit N-1 is the sign bit. The higher-order bits (those outside
+ 0..N-1) must be zero. */
+static inline ULONGEST
+sign_extend (ULONGEST v, int n)
+{
+ ULONGEST mask = (ULONGEST) 1 << (n - 1);
+ return (v ^ mask) - mask;
+}
+
/* Convert hex digit A to a number, or throw an exception. */
extern int fromhex (int a);