* [PATCH v1 06/36] Guile extension language: gdbtypes.c additions
@ 2013-12-24 19:03 Doug Evans
0 siblings, 0 replies; only message in thread
From: Doug Evans @ 2013-12-24 19:03 UTC (permalink / raw)
To: gdb-patches
This patch adds two new functions that are used by the Guile routines.
I may change these to return a value, and split get_signed_type_minmax
into two.
2013-12-24 Doug Evans <xdje42@gmail.com>
* gdbtypes.c (get_unsigned_type_max): New function.
(get_signed_type_minmax): New function.
* gdbtypes.h (get_unsigned_type_max): Declare.
(get_signed_type_minmax): Declare.
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 2470304..2235594 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1446,6 +1446,40 @@ lookup_struct_elt_type (struct type *type, const char *name, int noerr)
error (_("Type %s has no component named %s."), typename, name);
}
+/* Store in *MAX the largest number representable by unsigned integer type
+ TYPE. */
+
+void
+get_unsigned_type_max (struct type *type, ULONGEST *max)
+{
+ unsigned int n;
+
+ CHECK_TYPEDEF (type);
+ gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_UNSIGNED (type));
+ gdb_assert (TYPE_LENGTH (type) <= sizeof (ULONGEST));
+
+ /* Written this way to avoid overflow. */
+ n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
+ *max = ((((ULONGEST) 1 << (n - 1)) - 1) << 1) | 1;
+}
+
+/* Store in *MIN, *MAX the smallest and largest numbers representable by
+ signed integer type TYPE. */
+
+void
+get_signed_type_minmax (struct type *type, LONGEST *min, LONGEST *max)
+{
+ unsigned int n;
+
+ CHECK_TYPEDEF (type);
+ gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && !TYPE_UNSIGNED (type));
+ gdb_assert (TYPE_LENGTH (type) <= sizeof (LONGEST));
+
+ n = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
+ *min = -((ULONGEST) 1 << (n - 1));
+ *max = ((ULONGEST) 1 << (n - 1)) - 1;
+}
+
/* Lookup the vptr basetype/fieldno values for TYPE.
If found store vptr_basetype in *BASETYPEP if non-NULL, and return
vptr_fieldno. Also, if found and basetype is from the same objfile,
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index c7bef5f..2814ca1 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1545,6 +1545,10 @@ extern struct type *lookup_unsigned_typename (const struct language_defn *,
extern struct type *lookup_signed_typename (const struct language_defn *,
struct gdbarch *, const char *);
+extern void get_unsigned_type_max (struct type *, ULONGEST *);
+
+extern void get_signed_type_minmax (struct type *, LONGEST *, LONGEST *);
+
extern struct type *check_typedef (struct type *);
#define CHECK_TYPEDEF(TYPE) \
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2013-12-24 19:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-24 19:03 [PATCH v1 06/36] Guile extension language: gdbtypes.c additions Doug Evans
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).