From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24524 invoked by alias); 24 Dec 2013 19:03:10 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 24412 invoked by uid 89); 24 Dec 2013 19:03:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,MSGID_FROM_MTA_HEADER,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-pd0-f181.google.com Received: from mail-pd0-f181.google.com (HELO mail-pd0-f181.google.com) (209.85.192.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 24 Dec 2013 19:03:08 +0000 Received: by mail-pd0-f181.google.com with SMTP id p10so6510622pdj.26 for ; Tue, 24 Dec 2013 11:03:07 -0800 (PST) X-Received: by 10.68.212.37 with SMTP id nh5mr29526587pbc.16.1387911787013; Tue, 24 Dec 2013 11:03:07 -0800 (PST) Received: from sspiff.org (173-13-178-53-sfba.hfc.comcastbusiness.net. [173.13.178.53]) by mx.google.com with ESMTPSA id zc6sm7422610pab.0.2013.12.24.11.03.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Dec 2013 11:03:05 -0800 (PST) Message-ID: <52b9da69.06a6420a.30bd.16a8@mx.google.com> Received: by sspiff.org (sSMTP sendmail emulation); Tue, 24 Dec 2013 11:02:40 -0800 Date: Tue, 24 Dec 2013 19:03:00 -0000 From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH v1 06/36] Guile extension language: gdbtypes.c additions X-IsSubscribed: yes X-SW-Source: 2013-12/txt/msg00926.txt.bz2 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 * 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) \