RFA: unbreak typedefed bitfield

Vladimir Prus vladimir@codesourcery.com
Fri Dec 18 12:41:00 GMT 2009

GDB presently crashes on any attempt to get a value of a bitfield that
has typedefed type. The bugzilla report is here:


An easier reproducer is this program:

typedef unsigned int uint;

      struct Data {
	  int alloc;
	  int begin;
	  int end;
	  uint sharable : 1;

      int main()
	  Data d = {1, 2, 3, 1};
	  return 0;

and this session:

      ~"Breakpoint 1, main () at div.cpp:13\n"                                                                                                                
      ~"13\t    Data d = {1, 2, 3, 1};\n"                                                                                                                     
      &"During symbol reading, incomplete CFI data; unspecified registers (e.g., eax) at 0x8048497.\n"                                                                             
      ~"14\t    return 0;\n"                                                                                                                                                       
      -var-create V * d                                                                                                                                                            
      -var-list-children V                                                                                                                                                         
      -var-list-children --all-values V.public                                                                                                                                     

      Program received signal SIGFPE, Arithmetic exception.
      0x0813add3 in value_primitive_field (arg1=0x8644840, offset=0, fieldno=3, arg_type=0x85a9d7c) at /home/ghost/Work/CodeSourcery/Projects/egdb/gdb-git/gdb/value.c:1892
      1892          if ((bitpos % container_bitsize) + v->bitsize <= container_bitsize

And here's a trivial patch to fix this problem. I would claim this clearly indicates a design bug in GDB
type mechanism -- and it bites us repeatedly, but I'm not ready to propose a specific way to fix it, yet.

OK to commit?

- Volodya

--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1873,6 +1873,7 @@ value_primitive_field (struct value *arg1, int offset,

   CHECK_TYPEDEF (arg_type);
   type = TYPE_FIELD_TYPE (arg_type, fieldno);
+  check_typedef (type);

   /* Handle packed fields */

More information about the Gdb-patches mailing list