On 13/10/2016 16:07, Yao Qi wrote: > Bernhard Heckel writes: > >> diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c >> index 2cb418d..120163f 100644 >> --- a/gdb/c-valprint.c >> +++ b/gdb/c-valprint.c >> @@ -645,6 +645,28 @@ c_value_print (struct value *val, struct ui_file *stream, >> else >> { >> /* normal case */ >> + if (TYPE_CODE (type) == TYPE_CODE_PTR >> + && 1 == is_dynamic_type (type)) > Use is_dynamic_type return value as bool. > >> + { >> + CORE_ADDR addr; >> + if (NULL != TYPE_DATA_LOCATION (TYPE_TARGET_TYPE (type))) >> + addr = value_address (val); >> + else >> + addr = value_as_address (val); >> + >> + /* We resolve the target-type only when the >> + pointer is associated. */ >> + if ((addr != 0) >> + && (0 == type_not_associated (type))) > !type_not_associated (type) > >> + >> + >> +gdb_breakpoint [gdb_get_line_number "Before pointer assignment"] >> +gdb_continue_to_breakpoint "Before pointer assignment" >> +gdb_test "print logp" "= \\(PTR TO -> \\( $logical \\)\\) 0x0" "print logp, not associated" >> +gdb_test "print *logp" "Cannot access memory at address 0x0" "print *logp, not associated" >> +gdb_test "print comp" "= \\(PTR TO -> \\( $complex \\)\\) 0x0" "print comp, not associated" >> +gdb_test "print *comp" "Cannot access memory at address 0x0" "print *comp, not associated" >> +gdb_test "print charp" "= \\(PTR TO -> \\( character\\*1 \\)\\) 0x0" "print charp, not associated" >> +gdb_test "print *charp" "Cannot access memory at address 0x0" "print *charp, not associated" >> +gdb_test "print charap" "= \\(PTR TO -> \\( character\\*3 \\)\\) 0x0" "print charap, not associated" >> +gdb_test "print *charap" "Cannot access memory at address 0x0" "print *charap, not associated" >> +gdb_test "print intp" "= \\(PTR TO -> \\( $int \\)\\) 0x0" "print intp, not associated" >> +gdb_test "print *intp" "Cannot access memory at address 0x0" "print >> *intp, not associated" > These lines are too long. > >> +set test "print intap, not associated" >> +gdb_test_multiple "print intap" $test { >> + -re " = \\(PTR TO -> \\( $int \\(:,:\\)\\)\\) \r\n$gdb_prompt $" { >> + pass $test >> + } >> + -re " = \r\n$gdb_prompt $" { >> + pass $test >> + } >> +} > Why do we need to different regex here? Need to handle the differences > of different compilers? IMO, the former looks reasonable to me. A pointer to an array (especially to Variable Length Array, VLA) is described in Gfortran's compiled debug info like normal array types + associated property of an pointer. Not sure if this is a bug in Gfortran or not? I was also thinking to make the output equal, and check if an array has pointer attributes but ..... I don't really like this approach. This would cause a lot of "if .. else" construct in the code for example: De-reference this pointer, Address operator, ... >> +gdb_test "print realp" "= \\(PTR TO -> \\( $real \\)\\) 0x0" "print realp, not associated" >> +gdb_test "print *realp" "Cannot access memory at address 0x0" "print *realp, not associated" > They are too long. > >> +gdb_test "print \$my_var = intp" "= \\(PTR TO -> \\( $int \\)\\) 0x0" >> + >> + >> +gdb_breakpoint [gdb_get_line_number "Before value assignment"] >> +gdb_continue_to_breakpoint "Before value assignment" >> +gdb_test "print *(twop)%ivla2" "= " >> + >> + >> +gdb_breakpoint [gdb_get_line_number "After value assignment"] >> +gdb_continue_to_breakpoint "After value assignment" >> +gdb_test "print logp" "= \\(PTR TO -> \\( $logical \\)\\) $hex\( <.*>\)?" >> +gdb_test "print *logp" "= \\.TRUE\\." >> +gdb_test "print comp" "= \\(PTR TO -> \\( $complex \\)\\) $hex\( <.*>\)?" >> +gdb_test "print *comp" "= \\(1,2\\)" >> +gdb_test "print charp" "= \\(PTR TO -> \\( character\\*1 \\)\\) $hex\( <.*>\)?" >> +gdb_test "print *charp" "= 'a'" >> +gdb_test "print charap" "= \\(PTR TO -> \\( character\\*3 \\)\\) $hex\( <.*>\)?" >> +gdb_test "print *charap" "= 'abc'" >> +gdb_test "print intp" "= \\(PTR TO -> \\( $int \\)\\) $hex\( <.*>\)?" >> +gdb_test "print *intp" "= 10" >> +set test_name "print intap, associated" >> +gdb_test_multiple "print intap" $test_name { >> + -re "= \\(\\( 1, 1, 3(, 1){7}\\) \\( 1(, 1){9}\\) \\)\r\n$gdb_prompt $" { >> + pass $test_name >> + } >> + -re "= \\(PTR TO -> \\( $int \\(10,2\\)\\)\\) $hex\( <.*>\)?\r\n$gdb_prompt $" { >> + gdb_test "print *intap" "= \\(\\( 1, 1, 3(, 1){7}\\) \\( 1(, 1){9}\\) \\)" >> + pass $test_name >> + } >> +} > Again, different outputs due to different compilers? The latter looks > reasonable to me. > >> +set test_name "print intvlap, associated" >> +gdb_test_multiple "print intvlap" $test_name { >> + -re "= \\(2, 2, 2, 4(, 2){6}\\)\r\n$gdb_prompt $" { >> + pass $test_name >> + } >> + -re "= \\(PTR TO -> \\( $int \\(10\\)\\)\\) $hex\( <.*>\)?\r\n$gdb_prompt $" { >> + gdb_test "print *intvlap" "= \\(2, 2, 2, 4(, 2){6}\\)" >> + pass $test_name >> + } >> +} > Likewise. > >> diff --git a/gdb/valprint.c b/gdb/valprint.c >> index 6896da2..f592278 100644 >> --- a/gdb/valprint.c >> +++ b/gdb/valprint.c >> @@ -1141,12 +1141,6 @@ value_check_printable (struct value *val, struct ui_file *stream, >> return 0; >> } >> >> - if (type_not_associated (value_type (val))) >> - { >> - val_print_not_associated (stream); >> - return 0; >> - } >> - > Could you explain why do you remove this? I we keep this, we shortcut any additional printing of the target type of a pointer in case it is not associated. > >> if (type_not_allocated (value_type (val))) >> { >> val_print_not_allocated (stream); Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Christian Lamprechter Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928 &j!z޶}yb֫rnr