From a72c8f6a2934a77223ba77f972f418ec40240d1d Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Tue, 3 Apr 2012 14:39:55 +0000 Subject: [PATCH] gdb/ * cp-valprint.c (cp_print_value_fields): Check valprint_check_validity for TYPE_VPTR_FIELDNO. * valprint.c (valprint_check_validity): Make it global, move the function comment ... * value.h (valprint_check_validity): ... to this new declaration. gdb/testsuite/ * gdb.trace/unavailable.exp (collect globals: print object on: print derived_partial) (collect globals: print object on: print derived_whole) (collect globals: print object off: print derived_partial) (collect globals: print object off: print derived_whole): Update expected output. --- gdb/ChangeLog | 8 ++++++++ gdb/cp-valprint.c | 20 ++++++++++++-------- gdb/testsuite/ChangeLog | 9 +++++++++ gdb/testsuite/gdb.trace/unavailable.exp | 8 ++++---- gdb/valprint.c | 12 ++---------- gdb/value.h | 14 ++++++++++++++ 6 files changed, 49 insertions(+), 22 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c3ebf99..bdfd9b7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2012-04-03 Jan Kratochvil + + * cp-valprint.c (cp_print_value_fields): Check valprint_check_validity + for TYPE_VPTR_FIELDNO. + * valprint.c (valprint_check_validity): Make it global, move the + function comment ... + * value.h (valprint_check_validity): ... to this new declaration. + 2012-04-02 Tristan Gingold * i386-darwin-nat.c (i386_darwin_fetch_inferior_registers): Use diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index cb85b0b..7dd13bb 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -360,14 +360,18 @@ cp_print_value_fields (struct type *type, struct type *real_type, } else if (i == TYPE_VPTR_FIELDNO (type)) { - CORE_ADDR addr - = extract_typed_address (valaddr + offset - + TYPE_FIELD_BITSIZE (type, i) / 8, - TYPE_FIELD_TYPE (type, i)); - - print_function_pointer_address (get_type_arch (type), - addr, stream, - options->addressprint); + int i_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8; + struct type *i_type = TYPE_FIELD_TYPE (type, i); + + if (valprint_check_validity (stream, i_type, i_offset, val)) + { + CORE_ADDR addr; + + addr = extract_typed_address (valaddr + i_offset, i_type); + print_function_pointer_address (get_type_arch (type), + addr, stream, + options->addressprint); + } } else { diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index daed6f0..7fc5abe 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2012-04-03 Jan Kratochvil + + * gdb.trace/unavailable.exp + (collect globals: print object on: print derived_partial) + (collect globals: print object on: print derived_whole) + (collect globals: print object off: print derived_partial) + (collect globals: print object off: print derived_whole): Update + expected output. + 2012-03-30 Keith Seitz * gdb.python: Add test for linespecs with commas. diff --git a/gdb/testsuite/gdb.trace/unavailable.exp b/gdb/testsuite/gdb.trace/unavailable.exp index bc5f893..ca2e9eb 100644 --- a/gdb/testsuite/gdb.trace/unavailable.exp +++ b/gdb/testsuite/gdb.trace/unavailable.exp @@ -542,11 +542,11 @@ proc gdb_collect_globals_test { } { with_test_prefix "collect globals" { # vtable pointer available, but nothing else gdb_test "print derived_partial" \ - " = \\(Derived\\) { = { = , _vptr.Middle = , y = }, _vptr.Derived = $hex, z = }" + " = \\(Derived\\) { = { = , _vptr.Middle = , y = }, _vptr.Derived = $hex , z = }" # whole object available gdb_test "print derived_whole" \ - " = \\(Derived\\) { = { = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}" + " = \\(Derived\\) { = { = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex , z = 4}" } gdb_test_no_output "set print object off" @@ -560,11 +560,11 @@ proc gdb_collect_globals_test { } { with_test_prefix "collect globals" { # vtable pointer available, but nothing else gdb_test "print derived_partial" \ - " = { = { = , _vptr.Middle = , y = }, _vptr.Derived = $hex, z = }" + " = { = { = , _vptr.Middle = , y = }, _vptr.Derived = $hex , z = }" # whole object available gdb_test "print derived_whole" \ - " = { = { = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex, z = 4}" + " = { = { = {x = 2}, _vptr.Middle = $hex, y = 3}, _vptr.Derived = $hex , z = 4}" } # An instance of a virtual class where we collected everything but diff --git a/gdb/valprint.c b/gdb/valprint.c index 0037cb9..738fef4 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -248,17 +248,9 @@ scalar_type_p (struct type *type) } } -/* Helper function to check the validity of some bits of a value. +/* See its definition in value.h. */ - If TYPE represents some aggregate type (e.g., a structure), return 1. - - Otherwise, any of the bytes starting at OFFSET and extending for - TYPE_LENGTH(TYPE) bytes are invalid, print a message to STREAM and - return 0. The checking is done using FUNCS. - - Otherwise, return 1. */ - -static int +int valprint_check_validity (struct ui_file *stream, struct type *type, int embedded_offset, diff --git a/gdb/value.h b/gdb/value.h index d501b52..4d04a20 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -213,6 +213,20 @@ extern struct value *allocate_computed_value (struct type *type, const struct lval_funcs *funcs, void *closure); +/* Helper function to check the validity of some bits of a value. + + If TYPE represents some aggregate type (e.g., a structure), return 1. + + Otherwise, any of the bytes starting at OFFSET and extending for + TYPE_LENGTH(TYPE) bytes are invalid, print a message to STREAM and + return 0. The checking is done using FUNCS. + + Otherwise, return 1. */ + +extern int valprint_check_validity (struct ui_file *stream, struct type *type, + int embedded_offset, + const struct value *val); + extern struct value *allocate_optimized_out_value (struct type *type); /* If VALUE is lval_computed, return its lval_funcs structure. */ -- 2.7.4