aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog19
-rw-r--r--gdb/ada-valprint.c9
-rw-r--r--gdb/c-valprint.c11
-rw-r--r--gdb/f-valprint.c11
-rw-r--r--gdb/gdbtypes.c45
-rw-r--r--gdb/gdbtypes.h9
-rw-r--r--gdb/p-valprint.c10
-rw-r--r--gdb/valprint.c21
-rw-r--r--gdb/valprint.h4
-rw-r--r--gdb/value.c6
10 files changed, 134 insertions, 11 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0b28b95..d0c85fd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,22 @@
+2006-01-18 Mark Kettenis <kettenis@gnu.org>
+
+ Based on a previous patch form Michal Ludvig:
+ * gdbtypes.c (append_flags_type_flag, init_flags_type): New
+ functions.
+ (is_integral_type, rank_one_type, recursive_dump_type): Add
+ support for TYPE_CODE_FLAGS.
+ * gdbtypes.h (enum type_code): Add TYPE_CODE_FLAGS.
+ (append_flags_type_field, init_flags_type): New prototypes.
+ * ada-valprint.c (ada_val_print_1): Add support for
+ TYPE_CODE_FLAGS.
+ * c-valprint.c (c_val_print): Likewise.
+ * f-valprint.c (f_val_print): Likewise.
+ * p-valprint.c (pascal_val_print): Likewise.
+ * valprint.c (val_print_type_code_flags): New function.
+ * valprint.h (val_print_type_code_flags): New prototype.
+ * value.c (unpack_long, value_from_longest): Add support for
+ TYPE_CODE_FLAGS.
+
2006-01-17 Christopher Faylor <cgf@timesys.com>
* MAINTAINERS: Very belatedly remove myself from from the list of
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index e735a5b..7781fad 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -1,7 +1,7 @@
/* Support for printing Ada values for GDB, the GNU debugger.
Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1997, 2001,
- 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GDB.
@@ -774,6 +774,13 @@ ada_val_print_1 (struct type *type, const gdb_byte *valaddr0,
}
break;
+ case TYPE_CODE_FLAGS:
+ if (format)
+ print_scalar_formatted (valaddr, type, format, 0, stream);
+ else
+ val_print_type_code_flags (type, valaddr, stream);
+ break;
+
case TYPE_CODE_FLT:
if (format)
return c_val_print (type, valaddr0, embedded_offset, address, stream,
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index c17c46c..861e3bf 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -1,8 +1,8 @@
/* Support for printing C values for GDB, the GNU debugger.
Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
- 1997, 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation,
- Inc.
+ 1997, 1998, 1999, 2000, 2001, 2003, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GDB.
@@ -343,6 +343,13 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
}
break;
+ case TYPE_CODE_FLAGS:
+ if (format)
+ print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
+ else
+ val_print_type_code_flags (type, valaddr + embedded_offset, stream);
+ break;
+
case TYPE_CODE_FUNC:
if (format)
{
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index bdf7a8f..e724f76 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -1,7 +1,7 @@
/* Support for printing Fortran values for GDB, the GNU debugger.
- Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2003, 2005 Free
- Software Foundation, Inc.
+ Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2003, 2005, 2006
+ Free Software Foundation, Inc.
Contributed by Motorola. Adapted from the C definitions by Farooq Butt
(fmbutt@engage.sps.mot.com), additionally worked over by Stan Shebs.
@@ -483,6 +483,13 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
}
break;
+ case TYPE_CODE_FLAGS:
+ if (format)
+ print_scalar_formatted (valaddr, type, format, 0, stream);
+ else
+ val_print_type_code_flags (type, valaddr, stream);
+ break;
+
case TYPE_CODE_FLT:
if (format)
print_scalar_formatted (valaddr, type, format, 0, stream);
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 37b4739..b4062b7 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1,6 +1,8 @@
/* Support routines for manipulating internal types for GDB.
- Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
- 2004 Free Software Foundation, Inc.
+
+ Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
+ 2003, 2004, 2006 Free Software Foundation, Inc.
+
Contributed by Cygnus Support, using pieces from other GDB modules.
This file is part of GDB.
@@ -847,6 +849,39 @@ create_set_type (struct type *result_type, struct type *domain_type)
return (result_type);
}
+void
+append_flags_type_flag (struct type *type, int bitpos, char *name)
+{
+ gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS);
+ gdb_assert (bitpos < TYPE_NFIELDS (type));
+ gdb_assert (bitpos >= 0);
+
+ if (name)
+ {
+ TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
+ TYPE_FIELD_BITPOS (type, bitpos) = bitpos;
+ }
+ else
+ {
+ /* Don't show this field to the user. */
+ TYPE_FIELD_BITPOS (type, bitpos) = -1;
+ }
+}
+
+struct type *
+init_flags_type (char *name, int length)
+{
+ int nfields = length * TARGET_CHAR_BIT;
+ struct type *type;
+
+ type = init_type (TYPE_CODE_FLAGS, length, TYPE_FLAG_UNSIGNED, name, NULL);
+ TYPE_NFIELDS (type) = nfields;
+ TYPE_FIELDS (type) = TYPE_ALLOC (type, nfields * sizeof (struct field));
+ memset (TYPE_FIELDS (type), 0, sizeof (struct field));
+
+ return type;
+}
+
/* Construct and return a type of the form:
struct NAME { ELT_TYPE ELT_NAME[N]; }
We use these types for SIMD registers. For example, the type of
@@ -1822,6 +1857,7 @@ is_integral_type (struct type *t)
((t != NULL)
&& ((TYPE_CODE (t) == TYPE_CODE_INT)
|| (TYPE_CODE (t) == TYPE_CODE_ENUM)
+ || (TYPE_CODE (t) == TYPE_CODE_FLAGS)
|| (TYPE_CODE (t) == TYPE_CODE_CHAR)
|| (TYPE_CODE (t) == TYPE_CODE_RANGE)
|| (TYPE_CODE (t) == TYPE_CODE_BOOL)));
@@ -2374,6 +2410,7 @@ rank_one_type (struct type *parm, struct type *arg)
return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
case TYPE_CODE_INT:
case TYPE_CODE_ENUM:
+ case TYPE_CODE_FLAGS:
case TYPE_CODE_CHAR:
case TYPE_CODE_RANGE:
case TYPE_CODE_BOOL:
@@ -2454,6 +2491,7 @@ rank_one_type (struct type *parm, struct type *arg)
else
return INTEGER_CONVERSION_BADNESS;
case TYPE_CODE_ENUM:
+ case TYPE_CODE_FLAGS:
case TYPE_CODE_CHAR:
case TYPE_CODE_RANGE:
case TYPE_CODE_BOOL:
@@ -2888,6 +2926,9 @@ recursive_dump_type (struct type *type, int spaces)
case TYPE_CODE_ENUM:
printf_filtered ("(TYPE_CODE_ENUM)");
break;
+ case TYPE_CODE_FLAGS:
+ printf_filtered ("(TYPE_CODE_FLAGS)");
+ break;
case TYPE_CODE_FUNC:
printf_filtered ("(TYPE_CODE_FUNC)");
break;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 0e5844f..de451d5 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1,7 +1,7 @@
/* Internal type definitions for GDB.
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
@@ -106,6 +106,7 @@ enum type_code
TYPE_CODE_STRUCT, /* C struct or Pascal record */
TYPE_CODE_UNION, /* C union or Pascal variant part */
TYPE_CODE_ENUM, /* Enumeration type */
+ TYPE_CODE_FLAGS, /* Bit flags type */
TYPE_CODE_FUNC, /* Function type */
TYPE_CODE_INT, /* Integer type */
@@ -1190,6 +1191,12 @@ extern struct type *init_composite_type (char *name, enum type_code code);
extern void append_composite_type_field (struct type *t, char *name,
struct type *field);
+/* Helper functions to construct a bit flags type. An initially empty
+ type is created using init_flag_type(). Flags are then added using
+ append_flag_type_flag(). */
+extern struct type *init_flags_type (char *name, int length);
+extern void append_flags_type_flag (struct type *type, int bitpos, char *name);
+
extern struct type *lookup_reference_type (struct type *);
extern struct type *make_reference_type (struct type *, struct type **);
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index 72be1f5..9eef4f7 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -1,6 +1,7 @@
/* Support for printing Pascal values for GDB, the GNU debugger.
- Copyright (C) 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2003, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GDB.
@@ -359,6 +360,13 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
}
break;
+ case TYPE_CODE_FLAGS:
+ if (format)
+ print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
+ else
+ val_print_type_code_flags (type, valaddr + embedded_offset, stream);
+ break;
+
case TYPE_CODE_FUNC:
if (format)
{
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 0e1359a..b3a411a 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -326,6 +326,27 @@ val_print_type_code_int (struct type *type, const gdb_byte *valaddr,
}
}
+void
+val_print_type_code_flags (struct type *type, const gdb_byte *valaddr,
+ struct ui_file *stream)
+{
+ LONGEST val = unpack_long (type, valaddr);
+ int bitpos, nfields = TYPE_NFIELDS (type);
+
+ fputs_filtered ("[ ", stream);
+ for (bitpos = 0; bitpos < nfields; bitpos++)
+ {
+ if (TYPE_FIELD_BITPOS (type, bitpos) != -1 && (val & (1 << bitpos)))
+ {
+ if (TYPE_FIELD_NAME (type, bitpos))
+ fprintf_filtered (stream, "%s ", TYPE_FIELD_NAME (type, bitpos));
+ else
+ fprintf_filtered (stream, "#%d ", bitpos);
+ }
+ }
+ fputs_filtered ("]", stream);
+}
+
/* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g.
The raison d'etre of this function is to consolidate printing of
LONG_LONG's into this one function. The format chars b,h,w,g are
diff --git a/gdb/valprint.h b/gdb/valprint.h
index 5092fc5..fa8c7c7 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -66,6 +66,10 @@ extern void val_print_array_elements (struct type *, const gdb_byte *,
extern void val_print_type_code_int (struct type *, const gdb_byte *,
struct ui_file *);
+extern void val_print_type_code_flags (struct type *type,
+ const gdb_byte *valaddr,
+ struct ui_file *stream);
+
extern void print_binary_chars (struct ui_file *, const gdb_byte *,
unsigned int);
diff --git a/gdb/value.c b/gdb/value.c
index 738d053..801874b 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1,8 +1,8 @@
/* Low level packing and unpacking of values for GDB, the GNU Debugger.
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
- 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005 Free
- Software Foundation, Inc.
+ 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GDB.
@@ -1044,6 +1044,7 @@ unpack_long (struct type *type, const gdb_byte *valaddr)
case TYPE_CODE_TYPEDEF:
return unpack_long (check_typedef (type), valaddr);
case TYPE_CODE_ENUM:
+ case TYPE_CODE_FLAGS:
case TYPE_CODE_BOOL:
case TYPE_CODE_INT:
case TYPE_CODE_CHAR:
@@ -1492,6 +1493,7 @@ retry:
case TYPE_CODE_INT:
case TYPE_CODE_CHAR:
case TYPE_CODE_ENUM:
+ case TYPE_CODE_FLAGS:
case TYPE_CODE_BOOL:
case TYPE_CODE_RANGE:
store_signed_integer (value_contents_raw (val), len, num);