This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
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. 2014-01-20 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 042c17d..622eff0 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 61ddeff..643c610 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) \
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |