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] | |
Hi,
If a struct member is at an offset greater than or equal to
0x10000000, the resulting bit position within the struct overflows and
causes an invalid access. The following program demonstrates this
problem:
-----------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BSIZE (0x10000000)
struct s {
char buf1[BSIZE];
char buf2[8];
char buf3[8];
char buf4[8];
};
int main()
{
struct s *p = malloc(sizeof(struct s));
memset(p,0,sizeof(struct s));
printf("%p %x\n", &p->buf2[0], p->buf2[0]);
return(0);
}
-----------------------------------------------
Compile and run the program under gdb:
(gdb) b 18
Breakpoint 1 at 0x400554: file test.c, line 18.
(gdb) run
Starting program: /root/gdb/a.out
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x2aaaaaac7000
Breakpoint 1, main () at test.c:18
18 printf("%p %x\n", &p->buf2[0], p->buf2[0]);
(gdb) p p->buf2
Cannot access memory at address 0x2aaa9b022010
-----------------------------------------------
This happens because the bitpos in field_location within the struct
main_type.field is declared as an int, limiting it to just 4 bytes. I
have attached a patch that expands this to LONGEST and adjusted this
change in the code. The testsuite does not report any regressions due
to this patch and it fixes the problem.
Regards,
Siddhesh
gdb/ChangeLog:
2012-02-20 Siddhesh Poyarekar <siddhesh@redhat.com>
* gdbtypes.h (struct main_type.field.field_location): Expand
bitpos to LONGEST.
* value.h (modify_field): Adjust to accept LONGEST as bitpos.
(value_primitive_field, val_print): Adjust to accept LONGEST as
offset.
* value.c (modify_field, value_primitive_field, val_print): Ditto.
(value_bits_synthetic_pointer, value_bits_valid): Ditto.
(unpack_value_bits_as_long_1): Ditto.
* valprint.c (val_print_scalar_formatted, val_print): Ditto.
* valprint.h (val_print_scalar_formatted): Ditto.
* valops.c (search_struct_field, search_struct_method): Ditto.
(value_struct_elt_for_reference, find_method_list): Ditto.
* regcache.h (regcache_cooked_read_part): Ditto.
(regcache_cooked_write_part): Ditto.
* regcache.c (regcache_cooked_read_part): Ditto.
(regcache_cooked_write_part, regcache_xfer_part): Ditto.
* ax-gdb.c (gen_offset, gen_bitfield_ref):Ditto.
(gen_primitive_ref, gen_struct_ref_recursive): Ditto.
* ada-lang.c (ada_value_primitive_packed_val): Ditto.
(ada_value_primitive_field, find_struct_field): Ditto.
(ada_search_struct_field, ada_template_to_fixed_record_type_1):
Ditto.
* p-lang.c (is_pascal_string_type): Ditto.
* mips-tdep.c (mips_xfer_register): Adjust to accept LONGEST as
offset. Adjust format specifier for bitpos.
(mips_n32n64_fp_arg_chunk_p): Adjust to accept LONGEST as offset.
(mips_n32n64_return_value): Store bitpos in LONGEST.
* sparc64-tdep.c (sparc64_store_floating_fields): Adjust to accept
LONGEST as bitpos.
(sparc64_extract_floating_fields): Ditto.
* gdbtypes.c (recursive_dump_type): Adjust format specifier to
print bitpos.
* ada-typeprint.c (print_enum_type): Ditto.
* c-typeprint.c (c_type_print_base): Ditto.
* m2-typeprint.c (m2_enum): Ditto.
* p-typeprint.c (pascal_type_print_base): Ditto.
* language.h (struct language_defn): Adjust la_val_print to accept
LONGEST as embedded_offset.
* language.c (unk_lang_val_print): Adjust for change in
la_val_print.
* ada-lang.h (ada_val_print): Ditto.
* ada-valprint.c (ada_val_print, ada_val_print_1): Ditto.
(print_variant_part, print_field_values): Ditto.
* c-lang.h (c_val_print): Ditto.
* c-valprint.c (c_val_print): Ditto.
* d-lang.h (d_val_print): Ditto.
* d-valprint.c (d_val_print): Ditto.
* f-lang.h (f_val_print): Ditto.
* f-valprint.c (f_val_print): Ditto.
* jv-lang.h (java_val_print): Ditto.
* jv-valprint.c (java_val_print, java_print_value_fields): Ditto.
* m2-lang.h (m2_val_print): Ditto.
* m2-valprint.c (m2_print_array_contents, m2_val_print):Ditto.
(m2_print_unbounded_array, m2_print_array_contents): Ditto.
(m2_print_long_set): Ditto.
* p-lang.h (pascal_val_print, is_pascal_string_type): Ditto.
* p-valprint.c (pascal_val_print): Ditto.
* eval.c (evaluate_struct_tuple): Expand bitsize and bitpos to
LONGEST.
Attachment:
gdb-longest-bitpos.patch
Description: Text document
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |