WinDBG/Exts/CodeAnalyzer/gdbplus/gdb-7.7/gdb/gdb_dep.c
// Display the struct's data member at offset
Display the struct's data member at offset
Display the struct ' s data member at offset
static void
print_struct_field(const struct object_reference* ref, struct type *type, size_t offset)
{
	CHECK_TYPEDEF (type);
	if (offset == 0 && (ref->value==0 || !get_segment(ref->value, 1)) )
		return;
	if (TYPE_CODE(type) == TYPE_CODE_ARRAY)
	{
		struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
		struct type *range_type;
		if (TYPE_NFIELDS (type) == 1
			&& (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type)) == TYPE_CODE_RANGE))
		{
			const LONGEST low_bound = TYPE_LOW_BOUND (range_type);
			const LONGEST high_bound = TYPE_HIGH_BOUND (range_type);
			unsigned int elem_sz = TYPE_LENGTH(target_type);
			unsigned int index = low_bound + offset / elem_sz;
			if (offset == 0)
			{
				print_type_name(type, NULL, " (type=\"", "\")");
				return;
			}
			else if (index <= high_bound)
				printf_filtered(_("[%d]"), index);
			else
				printf_filtered(_("[?]"));
			print_struct_field(ref, target_type, offset - index * elem_sz);
		}
		else
			printf_filtered(_("[??]"));
		return;
	}
	else if (TYPE_CODE(type) == TYPE_CODE_STRUCT || TYPE_CODE(type) == TYPE_CODE_UNION)
	{
		int i, num_fields, num_baseclasses;
		num_fields = TYPE_NFIELDS (type);
		num_baseclasses = TYPE_N_BASECLASSES (type);
		for (i = 0; i < num_fields; i++)
		{
			struct type* field_type = TYPE_FIELD_TYPE (type, i);
			size_t pos, field_size;
			CHECK_TYPEDEF(TYPE_FIELD_TYPE (type, i));
			pos = TYPE_FIELD_BITPOS(type, i) / 8;
			field_size = field_type->length;
			if (TYPE_FIELD_LOC_KIND(type, i) != FIELD_LOC_KIND_BITPOS)	
				continue;
			if ( i+1 < num_fields
				&& field_size == 1
				&& (TYPE_FIELD_BITPOS(type, i+1) / 8) == pos )
				continue;
			else if (field_size > 0 && offset >= pos && offset < pos + field_size)
			{
				if (i < num_baseclasses)
				{
					const char* name = TYPE_NAME(field_type);
					if (strstr(name, "::"))
						printf_filtered(_("::\"%s\""), name);
					else
						printf_filtered(_("::%s"), name);
				}
				else
					printf_filtered(_(".%s"), TYPE_FIELD_NAME(type, i));
				print_struct_field(ref, field_type, offset - pos);
				break;
			}
		}
	}
	else if (TYPE_CODE(type) == TYPE_CODE_PTR || TYPE_CODE(type) == TYPE_CODE_REF)
		add_addr_type(ref->value, TYPE_TARGET_TYPE(type), NULL);
}
static void print_struct_field ( const struct object_reference * ref , struct type * type , size_t offset ) { CHECK_TYPEDEF ( type ) ; if ( offset == 0 && ( ref -> value == 0 || ! get_segment ( ref -> value , 1 ) ) ) return ; if ( TYPE_CODE ( type ) == TYPE_CODE_ARRAY ) { struct type * target_type = check_typedef ( TYPE_TARGET_TYPE ( type ) ) ; struct type * range_type ; if ( TYPE_NFIELDS ( type ) == 1 && ( TYPE_CODE ( range_type = TYPE_INDEX_TYPE ( type ) ) == TYPE_CODE_RANGE ) ) { const LONGEST low_bound = TYPE_LOW_BOUND ( range_type ) ; const LONGEST high_bound = TYPE_HIGH_BOUND ( range_type ) ; unsigned int elem_sz = TYPE_LENGTH ( target_type ) ; unsigned int index = low_bound + offset / elem_sz ; if ( offset == 0 ) { print_type_name ( type , NULL , " \" " , " \" " ) ; return ; } else if ( index <= high_bound ) printf_filtered ( _ ( " " ) , index ) ; else printf_filtered ( _ ( " " ) ) ; print_struct_field ( ref , target_type , offset - index * elem_sz ) ; } else printf_filtered ( _ ( " " ) ) ; return ; } else if ( TYPE_CODE ( type ) == TYPE_CODE_STRUCT || TYPE_CODE ( type ) == TYPE_CODE_UNION ) { int i , num_fields , num_baseclasses ; num_fields = TYPE_NFIELDS ( type ) ; num_baseclasses = TYPE_N_BASECLASSES ( type ) ; for ( i = 0 ; i < num_fields ; i ++ ) { struct type * field_type = TYPE_FIELD_TYPE ( type , i ) ; size_t pos , field_size ; CHECK_TYPEDEF ( TYPE_FIELD_TYPE ( type , i ) ) ; pos = TYPE_FIELD_BITPOS ( type , i ) / 8 ; field_size = field_type -> length ; if ( TYPE_FIELD_LOC_KIND ( type , i ) != FIELD_LOC_KIND_BITPOS ) continue ; if ( i + 1 < num_fields && field_size == 1 && ( TYPE_FIELD_BITPOS ( type , i + 1 ) / 8 ) == pos ) continue ; else if ( field_size > 0 && offset >= pos && offset < pos + field_size ) { if ( i < num_baseclasses ) { const char * name = TYPE_NAME ( field_type ) ; if ( strstr ( name , " " ) ) printf_filtered ( _ ( " \" \" " ) , name ) ; else printf_filtered ( _ ( " " ) , name ) ; } else printf_filtered ( _ ( " " ) , TYPE_FIELD_NAME ( type , i ) ) ; print_struct_field ( ref , field_type , offset - pos ) ; break ; } } } else if ( TYPE_CODE ( type ) == TYPE_CODE_PTR || TYPE_CODE ( type ) == TYPE_CODE_REF ) add_addr_type ( ref -> value , TYPE_TARGET_TYPE ( type ) , NULL ) ; }
Display the struct's data member at offset
Display the struct ' s data member at offset
// If there is nothing referenced, don't drill down to sub field // The first num_baseclasses fields are base classes, followed by type's data member // Their sum is num_fields // Also make sure field type is fleshed out before use // static member // base classes come first in the type's fields // quote the base name that consists of namespace specifier