* [PATCH] Eliminate -var-create error for optzd ptr to struct @ 2016-02-24 0:19 Don Breazeal 2016-02-24 1:14 ` Luis Machado 0 siblings, 1 reply; 26+ messages in thread From: Don Breazeal @ 2016-02-24 0:19 UTC (permalink / raw) To: gdb-patches Problem: This patch eliminates an error thrown when accessing the value of a pointer to a structure where the pointer has been optimized out. The error shows up as the rather ugly value of the pointer variable in Eclipse. With this change such an access will return "<optimized out>" like other optimized out variables. We should throw an error when dereferencing an optimized-out pointer, but not when just looking at its value. Cause: The error only occurs when '-gdb-set print object on' has been set. This setting requires GDB to "identify the actual (derived) type of the object rather than the declared type". Part of this process is to dereference the pointer in order to get the type of the thing that is pointed-to. Since the pointer has been optimized out, this is impossible, and an error is thrown. Fix: The fix is to simply ignore the 'print object on' setting for pointers or references to structures when they have been optimized out. This means we just get the declared type instead of the actual type, because in this case that's the best that we can do. Results: Attempts to dereference the optimized-out pointer using -var-create or -data-evaluate-expression will throw an error, but a dereference using -var-evaluate-expression will return an empty value. To be consistent, this last case would also throw an error. I looked into this some, enough to confirm that there isn't an obvious fix. Given that my goal is just to eliminate the unnecessary error, I stopped here. I'm working on setting things in motion for a patch to Eclipse that recognizes optimized-out pointer-to-struct in this scenario and prevents any subsequent attempt to dereference it from that end. Testing: I looked at creating a test case for this, but so far haven't been able to create anything general enough to include in the test suite. Tested on bare-metal powerpc board with Linux x86_64 host. OK? thanks --Don gdb/ChangeLog: 2016-02-23 Don Breazeal <donb@codesourcery.com> * gdb/value.c (value_actual_type): Ignore the 'print object on' setting for pointers and references to structures. --- gdb/value.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index 738b2b2..50e4f8a 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1203,9 +1203,10 @@ value_actual_type (struct value *value, int resolve_simple_types, /* If result's target type is TYPE_CODE_STRUCT, proceed to fetch its rtti type. */ if ((TYPE_CODE (result) == TYPE_CODE_PTR - || TYPE_CODE (result) == TYPE_CODE_REF) + || TYPE_CODE (result) == TYPE_CODE_REF) && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) - == TYPE_CODE_STRUCT) + == TYPE_CODE_STRUCT + && !value_optimized_out (value)) { struct type *real_type; -- 1.8.1.1 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-02-24 0:19 [PATCH] Eliminate -var-create error for optzd ptr to struct Don Breazeal @ 2016-02-24 1:14 ` Luis Machado 2016-02-24 16:31 ` Don Breazeal 0 siblings, 1 reply; 26+ messages in thread From: Luis Machado @ 2016-02-24 1:14 UTC (permalink / raw) To: Don Breazeal, gdb-patches On 02/23/2016 09:19 PM, Don Breazeal wrote: > Problem: > This patch eliminates an error thrown when accessing the value of a > pointer to a structure where the pointer has been optimized out. > The error shows up as the rather ugly value of the pointer variable > in Eclipse. > > With this change such an access will return "<optimized out>" like > other optimized out variables. We should throw an error when > dereferencing an optimized-out pointer, but not when just looking > at its value. > > Cause: > The error only occurs when '-gdb-set print object on' has been set. > This setting requires GDB to "identify the actual (derived) type of > the object rather than the declared type". Part of this process > is to dereference the pointer in order to get the type of the thing > that is pointed-to. Since the pointer has been optimized out, this > is impossible, and an error is thrown. > > Fix: > The fix is to simply ignore the 'print object on' setting for > pointers or references to structures when they have been optimized > out. This means we just get the declared type instead of the actual > type, because in this case that's the best that we can do. > > Results: > Attempts to dereference the optimized-out pointer using -var-create > or -data-evaluate-expression will throw an error, but a dereference > using -var-evaluate-expression will return an empty value. To be > consistent, this last case would also throw an error. I looked into > this some, enough to confirm that there isn't an obvious fix. Given > that my goal is just to eliminate the unnecessary error, I stopped here. > > I'm working on setting things in motion for a patch to Eclipse that > recognizes optimized-out pointer-to-struct in this scenario and > prevents any subsequent attempt to dereference it from that end. > > Testing: > I looked at creating a test case for this, but so far haven't been > able to create anything general enough to include in the test suite. > > Tested on bare-metal powerpc board with Linux x86_64 host. > > OK? > > thanks > --Don > > gdb/ChangeLog: > 2016-02-23 Don Breazeal <donb@codesourcery.com> > > * gdb/value.c (value_actual_type): Ignore the 'print object > on' setting for pointers and references to structures. > > --- > gdb/value.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/gdb/value.c b/gdb/value.c > index 738b2b2..50e4f8a 100644 > --- a/gdb/value.c > +++ b/gdb/value.c > @@ -1203,9 +1203,10 @@ value_actual_type (struct value *value, int resolve_simple_types, > /* If result's target type is TYPE_CODE_STRUCT, proceed to > fetch its rtti type. */ > if ((TYPE_CODE (result) == TYPE_CODE_PTR > - || TYPE_CODE (result) == TYPE_CODE_REF) > + || TYPE_CODE (result) == TYPE_CODE_REF) Is this just a formatting change? > && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) > - == TYPE_CODE_STRUCT) > + == TYPE_CODE_STRUCT > + && !value_optimized_out (value)) > { > struct type *real_type; > Otherwise looks OK to me. As for the testcase, how about one that creates a few pointer variables (to basic types, structures, arrays and other meaningful ones) and tries to print their original values with the "print object" enabled. This would be in MI mode, of course. I'd expect the error to be thrown in an unpatched gdb and a <optimized out> string for the patched debugger. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-02-24 1:14 ` Luis Machado @ 2016-02-24 16:31 ` Don Breazeal 2016-02-25 12:22 ` Pedro Alves 2016-03-29 12:01 ` [PATCH] Eliminate -var-create error for optzd ptr to struct Yao Qi 0 siblings, 2 replies; 26+ messages in thread From: Don Breazeal @ 2016-02-24 16:31 UTC (permalink / raw) To: Gustavo, Luis, gdb-patches On 2/23/2016 5:14 PM, Gustavo, Luis wrote: > On 02/23/2016 09:19 PM, Don Breazeal wrote: >> Problem: >> This patch eliminates an error thrown when accessing the value of a >> pointer to a structure where the pointer has been optimized out. >> The error shows up as the rather ugly value of the pointer variable >> in Eclipse. >> >> With this change such an access will return "<optimized out>" like >> other optimized out variables. We should throw an error when >> dereferencing an optimized-out pointer, but not when just looking >> at its value. >> >> Cause: >> The error only occurs when '-gdb-set print object on' has been set. >> This setting requires GDB to "identify the actual (derived) type of >> the object rather than the declared type". Part of this process >> is to dereference the pointer in order to get the type of the thing >> that is pointed-to. Since the pointer has been optimized out, this >> is impossible, and an error is thrown. >> >> Fix: >> The fix is to simply ignore the 'print object on' setting for >> pointers or references to structures when they have been optimized >> out. This means we just get the declared type instead of the actual >> type, because in this case that's the best that we can do. >> >> Results: >> Attempts to dereference the optimized-out pointer using -var-create >> or -data-evaluate-expression will throw an error, but a dereference >> using -var-evaluate-expression will return an empty value. To be >> consistent, this last case would also throw an error. I looked into >> this some, enough to confirm that there isn't an obvious fix. Given >> that my goal is just to eliminate the unnecessary error, I stopped here. >> >> I'm working on setting things in motion for a patch to Eclipse that >> recognizes optimized-out pointer-to-struct in this scenario and >> prevents any subsequent attempt to dereference it from that end. >> >> Testing: >> I looked at creating a test case for this, but so far haven't been >> able to create anything general enough to include in the test suite. >> >> Tested on bare-metal powerpc board with Linux x86_64 host. >> >> OK? >> >> thanks >> --Don >> >> gdb/ChangeLog: >> 2016-02-23 Don Breazeal <donb@codesourcery.com> >> >> * gdb/value.c (value_actual_type): Ignore the 'print object >> on' setting for pointers and references to structures. >> >> --- >> gdb/value.c | 5 +++-- >> 1 file changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/gdb/value.c b/gdb/value.c >> index 738b2b2..50e4f8a 100644 >> --- a/gdb/value.c >> +++ b/gdb/value.c >> @@ -1203,9 +1203,10 @@ value_actual_type (struct value *value, int resolve_simple_types, >> /* If result's target type is TYPE_CODE_STRUCT, proceed to >> fetch its rtti type. */ >> if ((TYPE_CODE (result) == TYPE_CODE_PTR >> - || TYPE_CODE (result) == TYPE_CODE_REF) >> + || TYPE_CODE (result) == TYPE_CODE_REF) > > Is this just a formatting change? Yes. I should have documented that in the ChangeLog. > >> && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) >> - == TYPE_CODE_STRUCT) >> + == TYPE_CODE_STRUCT >> + && !value_optimized_out (value)) >> { >> struct type *real_type; >> > > Otherwise looks OK to me. Thanks for the review, Luis. > > As for the testcase, how about one that creates a few pointer variables > (to basic types, structures, arrays and other meaningful ones) and tries > to print their original values with the "print object" enabled. This > would be in MI mode, of course. > > I'd expect the error to be thrown in an unpatched gdb and a <optimized > out> string for the patched debugger. > The main problem so far has been to get the compiler to optimize out the variables that I want it to optimize out, with a target that is generic enough that I can generate some assembly code that will run on something other than a specific version of a CPU. Trial and error. ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-02-24 16:31 ` Don Breazeal @ 2016-02-25 12:22 ` Pedro Alves 2016-03-28 21:33 ` [PATCH v2 0/2] Optzd-out ptr: Error handling improvement Don Breazeal 2016-03-29 12:01 ` [PATCH] Eliminate -var-create error for optzd ptr to struct Yao Qi 1 sibling, 1 reply; 26+ messages in thread From: Pedro Alves @ 2016-02-25 12:22 UTC (permalink / raw) To: Don Breazeal, Gustavo, Luis, gdb-patches On 02/24/2016 04:31 PM, Don Breazeal wrote: > The main problem so far has been to get the compiler to optimize out the > variables that I want it to optimize out, with a target that is generic > enough that I can generate some assembly code that will run on something > other than a specific version of a CPU. Trial and error. Sounds like a job for the testsuite's dwarf assembler? Thanks, Pedro Alves ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 0/2] Optzd-out ptr: Error handling improvement 2016-02-25 12:22 ` Pedro Alves @ 2016-03-28 21:33 ` Don Breazeal 2016-03-28 21:34 ` [PATCH v2 2/2] Optzd-out ptr: Eliminate -var-create error Don Breazeal 2016-03-28 21:34 ` [PATCH v2 1/2] Optzd-out ptr: New test for error handling Don Breazeal 0 siblings, 2 replies; 26+ messages in thread From: Don Breazeal @ 2016-03-28 21:33 UTC (permalink / raw) To: gdb-patches, palves, lgustavo This patchset is follows up on a patch submitted about a month ago, which eliminated an error caused by an MI -var-create request for an optimized-out pointer-to-struct. When 'set print object' is 'on', GDB tries to obtain the actual type rather than the declared type, and to do so must dereference the pointer, which is impossible because it has been optimized out. The original patch did not include a test; that has now been added. Patch 1/1: New test for accessing optimized-out pointer-to-struct. Patch 2/2: The original patch, which eliminates the error when accessing an optimized-out-pointer. The fix was regression tested on a PowerPC board with a Linux x86 host, and the test was tested on native Linux x86_64. Thanks, --Don ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 2/2] Optzd-out ptr: Eliminate -var-create error 2016-03-28 21:33 ` [PATCH v2 0/2] Optzd-out ptr: Error handling improvement Don Breazeal @ 2016-03-28 21:34 ` Don Breazeal 2016-03-28 21:34 ` [PATCH v2 1/2] Optzd-out ptr: New test for error handling Don Breazeal 1 sibling, 0 replies; 26+ messages in thread From: Don Breazeal @ 2016-03-28 21:34 UTC (permalink / raw) To: gdb-patches, palves, lgustavo This version of the patch is unchanged from the previous version, except that the description has been revised to be more concise and the ChangeLog has been updated to note the formatting change made by the patch. Luis reviewed this patch, but it still needs to be OK'd by a maintainer. thanks --Don ---- This patch eliminates an error thrown when accessing the value of a pointer to a structure where the pointer has been optimized out and 'set print object' is 'on'. The error shows up as the rather ugly value of the pointer variable in Eclipse. If 'set print object' is 'on', GDB tries to determine the actual (derived) type of the object rather than the declared type, which requires dereferencing the pointer, which in this cases throws an error because the pointer has been optimized out. The fix is to simply ignore the 'print object on' setting for pointers or references to structures when they have been optimized out. This means we just get the declared type instead of the actual type, because in this case that's the best that we can do. I'm working on setting things in motion for a patch to Eclipse that recognizes optimized-out pointer-to-struct in this scenario and prevents any subsequent attempt to dereference it from that end. Tested on bare-metal powerpc board with Linux x86 host. OK? thanks --Don gdb/ChangeLog: 2016-03-28 Don Breazeal <donb@codesourcery.com> * gdb/value.c (value_actual_type): Ignore the 'print object on' setting if the object is a pointer to or reference to a structure. Fix a formatting issue. --- gdb/value.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index 738b2b2..50e4f8a 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1203,9 +1203,10 @@ value_actual_type (struct value *value, int resolve_simple_types, /* If result's target type is TYPE_CODE_STRUCT, proceed to fetch its rtti type. */ if ((TYPE_CODE (result) == TYPE_CODE_PTR - || TYPE_CODE (result) == TYPE_CODE_REF) + || TYPE_CODE (result) == TYPE_CODE_REF) && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) - == TYPE_CODE_STRUCT) + == TYPE_CODE_STRUCT + && !value_optimized_out (value)) { struct type *real_type; -- 1.8.1.1 ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 1/2] Optzd-out ptr: New test for error handling 2016-03-28 21:33 ` [PATCH v2 0/2] Optzd-out ptr: Error handling improvement Don Breazeal 2016-03-28 21:34 ` [PATCH v2 2/2] Optzd-out ptr: Eliminate -var-create error Don Breazeal @ 2016-03-28 21:34 ` Don Breazeal 2016-03-29 11:58 ` Yao Qi 1 sibling, 1 reply; 26+ messages in thread From: Don Breazeal @ 2016-03-28 21:34 UTC (permalink / raw) To: gdb-patches, palves, lgustavo The previous version of this patch was a single patch rather than a patchset, and lacked any test case. This patch adds a new test to address Luis' and Pedro's comments on the original patch: On 2/23/2016 5:14 PM, Gustavo, Luis wrote: > On 02/23/2016 09:19 PM, Don Breazeal wrote: >> Testing: >> I looked at creating a test case for this, but so far haven't been >> able to create anything general enough to include in the test suite. > As for the testcase, how about one that creates a few pointer variables > (to basic types, structures, arrays and other meaningful ones) and tries > to print their original values with the "print object" enabled. This > would be in MI mode, of course. > > I'd expect the error to be thrown in an unpatched gdb and a <optimized > out> string for the patched debugger. On 2/25/2016 4:22 AM, Pedro Alves wrote: > On 02/24/2016 04:31 PM, Don Breazeal wrote: >> The main problem so far has been to get the compiler to optimize out the >> variables that I want it to optimize out, with a target that is generic >> enough that I can generate some assembly code that will run on something >> other than a specific version of a CPU. Trial and error. > > Sounds like a job for the testsuite's dwarf assembler? ------- This patch implements a test that ensures that with "set print object on", -var-create returns "<optimized out>" for an optimized out pointer to structure, rather than throwing an error, while also ensuring that any attempt to dereference the pointer *will* throw an error. It uses the dwarf assembler to construct the appropriate debug info to represent a pointer-to-struct in the program as optimized out, and then accesses that pointer in various ways. The test uses both the console interpreter and the MI interpreter. Tested on native Linux x86_64. WDYT? thanks --Don 2016-03-28 Don Breazeal <donb@codesourcery.com> * gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c: New test program. * gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp: New test script. --- gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c | 50 +++++ gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp | 255 +++++++++++++++++++++++++ 2 files changed, 305 insertions(+) diff --git a/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c b/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c new file mode 100644 index 0000000..003fdc0 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c @@ -0,0 +1,50 @@ +/* Copyright 2016 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +struct foo +{ + int a; + int x[5]; + struct foo *y; +}; + +asm (".section \".text\""); +asm (".balign 8"); +asm ("func01_start: .globl func01_start"); + +int +func01 (void) +{ + struct foo *ptr; + + ptr = (struct foo *) 0x0; + return 0; +} + +asm ("func01_end: .globl func01_end"); + +asm ("main_start: .globl main_start"); +int +main () +{ + int i; + + i = func01 (); + return 0; +} + +asm ("main_end: .globl main_end"); diff --git a/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp b/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp new file mode 100644 index 0000000..51fdb14 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp @@ -0,0 +1,255 @@ +# Copyright 2016 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# This test ensures that with "set print object on", -var-create will +# return "<optimized out>" for an optimized out pointer to structure, +# rather than attempting to dereference the pointer to determine its +# actual type (instead of its declared type). We want to test that GDB +# can display such a pointer without throwing an error, while also +# ensuring that any attempt to dereference the pointer *will* throw an +# error. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +standard_testfile dw2-opt-structptr.c dw2-opt-structptr-dw.S + +# Generate a test program with dwarf information showing the variable +# 'ptr', a pointer-to-struct, as optimized out. The dwarf will also +# describe the structure as have a scalar, array, and pointer-to-struct +# members. + +proc build_test_program {} { + global testfile + global srcfile + global srcfile2 + + # Make some DWARF for the test. + set asm_file [standard_output_file $srcfile2] + Dwarf::assemble $asm_file { + # Creating a CU with 4-byte addresses lets this test link on + # both 32- and 64-bit machines. + cu { addr_size 4 } { + extern func01_start func01_end main_start main_end + + DW_TAG_compile_unit { + {DW_AT_language @DW_LANG_C99} + {DW_AT_name dw2-opt-structptr.c} + {DW_AT_comp_dir /tmp} + {low_pc func01_start addr} + {high_pc main_end addr} + } { + declare_labels int_label struct_label pointer_label \ + array_label + + int_label: DW_TAG_base_type { + {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_signed} + {DW_AT_name integer} + } + + array_label: DW_TAG_array_type { + {DW_AT_name foo__array_type} + {DW_AT_type :$int_label} + } { + DW_TAG_subrange_type { + {DW_AT_type :$int_label} + {DW_AT_lower_bound 0 DW_FORM_data1} + {DW_AT_upper_bound 127 DW_FORM_data1} + } + } + + struct_label: DW_TAG_structure_type { + {DW_AT_name "foo"} + {DW_AT_byte_size 12 DW_FORM_sdata} + } { + member { + {name a} + {type :$int_label} + {data_member_location 0 data1} + } + member { + {name x} + {type :$array_label} + {data_member_location 4 data1} + } + member { + {name y} + {type :$pointer_label} + {data_member_location 8 data1} + } + } + + pointer_label: DW_TAG_pointer_type { + {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_type :$struct_label} + } + + DW_TAG_subprogram { + {DW_AT_name func01} + {DW_AT_type :$int_label} + {external 1 flag} + {low_pc func01_start addr} + {high_pc func01_end addr} + } { + DW_TAG_variable { + {DW_AT_name ptr} + {DW_AT_type :$pointer_label} + {DW_AT_location {} DW_FORM_block1} + } + } + + DW_TAG_subprogram { + {DW_AT_name main} + {DW_AT_type :$int_label} + {external 1 flag} + {low_pc main_start addr} + {high_pc main_end addr} + } { + } + } + } + } + + set sources "$srcfile $asm_file" + if {[build_executable $testfile.exp $testfile $sources {nodebug}]} { + untested $testfile.exp + return -1 + } +} + +# Test access to an optimized-out pointer-to-struct using the +# console interpreter. + +proc do_console_test {} { + global binfile + + clean_restart $binfile + + with_test_prefix "console" { + gdb_test_no_output "set print object on" + + if {![runto_main]} { + return -1 + } + + if {![runto func01]} { + return -1 + } + + gdb_test "info addr ptr" "Symbol \"ptr\" is optimized out." + + gdb_test "print ptr" "<optimized out>" + + gdb_test "print *ptr" "value has been optimized out" + + gdb_test "print ptr->a" "value has been optimized out" + + gdb_test "print ptr->x" "value has been optimized out" + + gdb_test "print ptr->y" "value has been optimized out" + } +} + +# Test access to an optimized-out pointer-to-struct using the +# MI interpreter. + +proc do_mi_test {} { + + load_lib mi-support.exp + set MIFLAGS "-i=mi" + + global mi_gdb_prompt + global srcdir + global subdir + global binfile + + with_test_prefix "mi" { + gdb_exit + if {[mi_gdb_start]} { + return -1 + } + + mi_delete_breakpoints + mi_gdb_reinitialize_dir $srcdir/$subdir + mi_gdb_load $binfile + + # This causes GDB to dereference a pointer-to-structure when doing + # -var-create. + mi_gdb_test "-gdb-set print object on" ".*" "set print object on" + + mi_gdb_test "-break-insert main" ".*" "insert breakpoint main" + mi_gdb_test "-break-insert func01" ".*" "insert breakpoint func01" + + # Run to main. Use an explicit expect here since the limited + # debug info will result in output that isn't handled by the + # MI test utilities. + set test "run to main" + mi_run_cmd + gdb_expect { + -re "\\*stopped,reason=\"breakpoint-hit\".*func=\"main\".*$mi_gdb_prompt$" { + pass "$test" + } + timeout { + fail "$test (timeout)" + } + } + + # Run to func01. Use an explicit expect here as above. + set test "continue to func01" + mi_send_resuming_command "exec-continue" "$test" + gdb_expect { + -re "\\*stopped,reason=\"breakpoint-hit\".*func=\"func01\".*$mi_gdb_prompt$" { + pass "$test" + } + timeout { + fail "$test (timeout)" + } + } + + # Test that -var-create for 'ptr' is successful. + mi_create_varobj "var1" "ptr" "create varobj for ptr" + + # Test that -var-list-children of 'ptr' is successful. + mi_list_varobj_children "var1" { \ + {var1.a a 0 integer} \ + {var1.x x 128 foo__array_type} \ + {var1.y y 3 "struct foo \\*"} \ + } "get children of var1 (ptr)" + + # Test that dereferencing 'ptr' will throw an error. + mi_gdb_test "-var-create var2 * &((ptr)->a)" \ + "\\^error,msg=\"value has been optimized out\"" \ + "throw error, dereference ptr to access integer member " + + # Test that dereferencing 'ptr' will throw an error. + mi_gdb_test "-var-create var3 * &((ptr)->x)" \ + "\\^error,msg=\"value has been optimized out\"" \ + "throw error, dereference ptr to access array member " + + # Test that dereferencing 'ptr' will throw an error. + mi_gdb_test "-var-create var4 * &((ptr)->y)" \ + "\\^error,msg=\"value has been optimized out\"" \ + "throw error, dereference ptr to access pointer member " + } +} + +build_test_program +do_console_test +do_mi_test -- 1.8.1.1 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/2] Optzd-out ptr: New test for error handling 2016-03-28 21:34 ` [PATCH v2 1/2] Optzd-out ptr: New test for error handling Don Breazeal @ 2016-03-29 11:58 ` Yao Qi 2016-03-29 17:13 ` Don Breazeal 0 siblings, 1 reply; 26+ messages in thread From: Yao Qi @ 2016-03-29 11:58 UTC (permalink / raw) To: Don Breazeal; +Cc: gdb-patches, palves, lgustavo Don Breazeal <donb@codesourcery.com> writes: > + DW_TAG_subprogram { > + {DW_AT_name func01} > + {DW_AT_type :$int_label} > + {external 1 flag} > + {low_pc func01_start addr} > + {high_pc func01_end addr} Please use MACRO_AT_func so that the low_pc and high_pc can be got correctly. > + } { > + DW_TAG_variable { > + {DW_AT_name ptr} > + {DW_AT_type :$pointer_label} > + {DW_AT_location {} DW_FORM_block1} > + } > + } > + > + DW_TAG_subprogram { > + {DW_AT_name main} > + {DW_AT_type :$int_label} > + {external 1 flag} > + {low_pc main_start addr} > + {high_pc main_end addr} Likewise. > + } { > + } -- Yao (齐尧) ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/2] Optzd-out ptr: New test for error handling 2016-03-29 11:58 ` Yao Qi @ 2016-03-29 17:13 ` Don Breazeal 2016-03-30 14:37 ` Yao Qi 0 siblings, 1 reply; 26+ messages in thread From: Don Breazeal @ 2016-03-29 17:13 UTC (permalink / raw) To: Yao Qi, Breazeal, Don; +Cc: gdb-patches, palves, Gustavo, Luis On 3/29/2016 4:57 AM, Yao Qi wrote: > Don Breazeal <donb@codesourcery.com> writes: > >> + DW_TAG_subprogram { >> + {DW_AT_name func01} >> + {DW_AT_type :$int_label} >> + {external 1 flag} >> + {low_pc func01_start addr} >> + {high_pc func01_end addr} > > Please use MACRO_AT_func so that the low_pc and high_pc can be got correctly. > >> + } { >> + DW_TAG_variable { >> + {DW_AT_name ptr} >> + {DW_AT_type :$pointer_label} >> + {DW_AT_location {} DW_FORM_block1} >> + } >> + } >> + >> + DW_TAG_subprogram { >> + {DW_AT_name main} >> + {DW_AT_type :$int_label} >> + {external 1 flag} >> + {low_pc main_start addr} >> + {high_pc main_end addr} > > Likewise. > >> + } { >> + } > Hi Yao, Here is the patch updated to use MACRO_AT_func. Thanks, --Don ---- This patch implements a test that ensures that with "set print object on", -var-create returns "<optimized out>" for an optimized out pointer to structure, rather than throwing an error, while also ensuring that any attempt to dereference the pointer *will* throw an error. It uses the dwarf assembler to construct the appropriate debug info to represent a pointer-to-struct in the program as optimized out, and then accesses that pointer in various ways. The test uses both the console interpreter and the MI interpreter. Tested on native Linux x86_64. 2016-03-29 Don Breazeal <donb@codesourcery.com> * gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c: New test program. * gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp: New test script. --- gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c | 41 ++++ gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp | 250 +++++++++++++++++++++++++ 2 files changed, 291 insertions(+) diff --git a/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c b/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c new file mode 100644 index 0000000..ff6fae0 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c @@ -0,0 +1,41 @@ +/* Copyright 2016 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +struct foo +{ + int a; + int x[5]; + struct foo *y; +}; + +void +func01 (void) +{ + struct foo *ptr; + + asm ("func01_label: .globl func01_label"); + ptr = (struct foo *) 0x0; + return; +} + +int +main () +{ + asm ("main_label: .globl main_label"); + func01 (); + return 0; +} diff --git a/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp b/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp new file mode 100644 index 0000000..44f1df1 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp @@ -0,0 +1,250 @@ +# Copyright 2016 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# This test ensures that with "set print object on", -var-create will +# return "<optimized out>" for an optimized out pointer to structure, +# rather than attempting to dereference the pointer to determine its +# actual type (instead of its declared type). We want to test that GDB +# can display such a pointer without throwing an error, while also +# ensuring that any attempt to dereference the pointer *will* throw an +# error. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + return 0 +} + +standard_testfile dw2-opt-structptr.c dw2-opt-structptr-dw.S + +# Generate a test program with dwarf information showing the variable +# 'ptr', a pointer-to-struct, as optimized out. The dwarf will also +# describe the structure as have a scalar, array, and pointer-to-struct +# members. + +proc build_test_program {} { + global testfile srcfile srcfile2 + + # Make some DWARF for the test. + set asm_file [standard_output_file $srcfile2] + Dwarf::assemble $asm_file { + global srcdir subdir srcfile + + # Creating a CU with 4-byte addresses lets this test link on + # both 32- and 64-bit machines. + cu { addr_size 4 } { + + DW_TAG_compile_unit { + {DW_AT_language @DW_LANG_C99} + {DW_AT_name dw2-opt-structptr.c} + {DW_AT_comp_dir /tmp} + } { + declare_labels int_label struct_label pointer_label \ + array_label + + int_label: DW_TAG_base_type { + {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_encoding @DW_ATE_signed} + {DW_AT_name integer} + } + + array_label: DW_TAG_array_type { + {DW_AT_name foo__array_type} + {DW_AT_type :$int_label} + } { + DW_TAG_subrange_type { + {DW_AT_type :$int_label} + {DW_AT_lower_bound 0 DW_FORM_data1} + {DW_AT_upper_bound 127 DW_FORM_data1} + } + } + + struct_label: DW_TAG_structure_type { + {DW_AT_name "foo"} + {DW_AT_byte_size 12 DW_FORM_sdata} + } { + member { + {name a} + {type :$int_label} + {data_member_location 0 data1} + } + member { + {name x} + {type :$array_label} + {data_member_location 4 data1} + } + member { + {name y} + {type :$pointer_label} + {data_member_location 8 data1} + } + } + + pointer_label: DW_TAG_pointer_type { + {DW_AT_byte_size 4 DW_FORM_sdata} + {DW_AT_type :$struct_label} + } + + DW_TAG_subprogram { + {DW_AT_name func01} + {DW_AT_type :$int_label} + {external 1 flag} + {MACRO_AT_func {func01 ${srcdir}/${subdir}/${srcfile}}} + } { + DW_TAG_variable { + {DW_AT_name ptr} + {DW_AT_type :$pointer_label} + {DW_AT_location {} DW_FORM_block1} + } + } + + DW_TAG_subprogram { + {DW_AT_name main} + {DW_AT_type :$int_label} + {external 1 flag} + {MACRO_AT_func {main ${srcdir}/${subdir}/${srcfile}}} + } { + } + } + } + } + + set sources "$srcfile $asm_file" + if {[build_executable $testfile.exp $testfile $sources {nodebug}]} { + untested $testfile.exp + return -1 + } +} + +# Test access to an optimized-out pointer-to-struct using the +# console interpreter. + +proc do_console_test {} { + global binfile + + clean_restart $binfile + + with_test_prefix "console" { + gdb_test_no_output "set print object on" + + if {![runto_main]} { + return -1 + } + + if {![runto func01]} { + return -1 + } + + gdb_test "info addr ptr" "Symbol \"ptr\" is optimized out." + + gdb_test "print ptr" "<optimized out>" + + gdb_test "print *ptr" "value has been optimized out" + + gdb_test "print ptr->a" "value has been optimized out" + + gdb_test "print ptr->x" "value has been optimized out" + + gdb_test "print ptr->y" "value has been optimized out" + } +} + +# Test access to an optimized-out pointer-to-struct using the +# MI interpreter. + +proc do_mi_test {} { + + load_lib mi-support.exp + set MIFLAGS "-i=mi" + + global mi_gdb_prompt + global srcdir + global subdir + global binfile + + with_test_prefix "mi" { + gdb_exit + if {[mi_gdb_start]} { + return -1 + } + + mi_delete_breakpoints + mi_gdb_reinitialize_dir $srcdir/$subdir + mi_gdb_load $binfile + + # This causes GDB to dereference a pointer-to-structure when doing + # -var-create. + mi_gdb_test "-gdb-set print object on" ".*" "set print object on" + + mi_gdb_test "-break-insert main" ".*" "insert breakpoint main" + mi_gdb_test "-break-insert func01" ".*" "insert breakpoint func01" + + # Run to main. Use an explicit expect here since the limited + # debug info will result in output that isn't handled by the + # MI test utilities. + set test "run to main" + mi_run_cmd + gdb_expect { + -re "\\*stopped,reason=\"breakpoint-hit\".*func=\"main\".*$mi_gdb_prompt$" { + pass "$test" + } + timeout { + fail "$test (timeout)" + } + } + + # Run to func01. Use an explicit expect here as above. + set test "continue to func01" + mi_send_resuming_command "exec-continue" "$test" + gdb_expect { + -re "\\*stopped,reason=\"breakpoint-hit\".*func=\"func01\".*$mi_gdb_prompt$" { + pass "$test" + } + timeout { + fail "$test (timeout)" + } + } + + # Test that -var-create for 'ptr' is successful. + mi_create_varobj "var1" "ptr" "create varobj for ptr" + + # Test that -var-list-children of 'ptr' is successful. + mi_list_varobj_children "var1" { \ + {var1.a a 0 integer} \ + {var1.x x 128 foo__array_type} \ + {var1.y y 3 "struct foo \\*"} \ + } "get children of var1 (ptr)" + + # Test that dereferencing 'ptr' will throw an error. + mi_gdb_test "-var-create var2 * &((ptr)->a)" \ + "\\^error,msg=\"value has been optimized out\"" \ + "throw error, dereference ptr to access integer member " + + # Test that dereferencing 'ptr' will throw an error. + mi_gdb_test "-var-create var3 * &((ptr)->x)" \ + "\\^error,msg=\"value has been optimized out\"" \ + "throw error, dereference ptr to access array member " + + # Test that dereferencing 'ptr' will throw an error. + mi_gdb_test "-var-create var4 * &((ptr)->y)" \ + "\\^error,msg=\"value has been optimized out\"" \ + "throw error, dereference ptr to access pointer member " + } +} + +build_test_program +do_console_test +do_mi_test -- 1.8.1.1 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/2] Optzd-out ptr: New test for error handling 2016-03-29 17:13 ` Don Breazeal @ 2016-03-30 14:37 ` Yao Qi 2016-04-06 21:34 ` Don Breazeal 0 siblings, 1 reply; 26+ messages in thread From: Yao Qi @ 2016-03-30 14:37 UTC (permalink / raw) To: Don Breazeal; +Cc: Yao Qi, Breazeal, Don, gdb-patches, palves, Gustavo, Luis Don Breazeal <donb@codesourcery.com> writes: > 2016-03-29 Don Breazeal <donb@codesourcery.com> > > * gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c: New test program. > * gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp: New test script. "gdb/testsuite/" is not needed. Patch is good to me. -- Yao (齐尧) ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/2] Optzd-out ptr: New test for error handling 2016-03-30 14:37 ` Yao Qi @ 2016-04-06 21:34 ` Don Breazeal 0 siblings, 0 replies; 26+ messages in thread From: Don Breazeal @ 2016-04-06 21:34 UTC (permalink / raw) To: Yao Qi; +Cc: gdb-patches, palves, Machado, Luis On 3/30/2016 7:37 AM, Yao Qi wrote: > Don Breazeal <donb@codesourcery.com> writes: > >> 2016-03-29 Don Breazeal <donb@codesourcery.com> >> >> * gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.c: New test program. >> * gdb/testsuite/gdb.dwarf2/dw2-opt-structptr.exp: New test script. > > "gdb/testsuite/" is not needed. > > Patch is good to me. > Thanks Yao. ChangeLog has been corrected and this is now pushed in. --Don ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-02-24 16:31 ` Don Breazeal 2016-02-25 12:22 ` Pedro Alves @ 2016-03-29 12:01 ` Yao Qi 2016-03-29 17:14 ` Don Breazeal 1 sibling, 1 reply; 26+ messages in thread From: Yao Qi @ 2016-03-29 12:01 UTC (permalink / raw) To: Don Breazeal; +Cc: Gustavo, Luis, gdb-patches Don Breazeal <donb@codesourcery.com> writes: >>> @@ -1203,9 +1203,10 @@ value_actual_type (struct value *value, int resolve_simple_types, >>> /* If result's target type is TYPE_CODE_STRUCT, proceed to >>> fetch its rtti type. */ >>> if ((TYPE_CODE (result) == TYPE_CODE_PTR >>> - || TYPE_CODE (result) == TYPE_CODE_REF) >>> + || TYPE_CODE (result) == TYPE_CODE_REF) >> >> Is this just a formatting change? > > Yes. I should have documented that in the ChangeLog. If it is just a format change, you can move it to a separate patch, and commit it as obvious. Don't mix format change with your bug fix patch. -- Yao (齐尧) ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-03-29 12:01 ` [PATCH] Eliminate -var-create error for optzd ptr to struct Yao Qi @ 2016-03-29 17:14 ` Don Breazeal 2016-03-30 14:35 ` Yao Qi 0 siblings, 1 reply; 26+ messages in thread From: Don Breazeal @ 2016-03-29 17:14 UTC (permalink / raw) To: Yao Qi, Breazeal, Don; +Cc: Gustavo, Luis, gdb-patches On 3/29/2016 5:01 AM, Yao Qi wrote: > Don Breazeal <donb@codesourcery.com> writes: > >>>> @@ -1203,9 +1203,10 @@ value_actual_type (struct value *value, int resolve_simple_types, >>>> /* If result's target type is TYPE_CODE_STRUCT, proceed to >>>> fetch its rtti type. */ >>>> if ((TYPE_CODE (result) == TYPE_CODE_PTR >>>> - || TYPE_CODE (result) == TYPE_CODE_REF) >>>> + || TYPE_CODE (result) == TYPE_CODE_REF) >>> >>> Is this just a formatting change? >> >> Yes. I should have documented that in the ChangeLog. > > If it is just a format change, you can move it to a separate patch, and > commit it as obvious. Don't mix format change with your bug fix patch. > Hi Yao, Here is the patch with the formatting change removed, and with the more concise patch description posted most recent patchset. Thanks, --Don ---- This patch eliminates an error thrown when accessing the value of a pointer to a structure where the pointer has been optimized out and 'set print object' is 'on'. The error shows up as the rather ugly value of the pointer variable in Eclipse. If 'set print object' is 'on', GDB tries to determine the actual (derived) type of the object rather than the declared type, which requires dereferencing the pointer, which in this cases throws an error because the pointer has been optimized out. The fix is to simply ignore the 'print object on' setting for pointers or references to structures when they have been optimized out. This means we just get the declared type instead of the actual type, because in this case that's the best that we can do. I'm working on setting things in motion for a patch to Eclipse that recognizes optimized-out pointer-to-struct in this scenario and prevents any subsequent attempt to dereference it from that end. Tested on bare-metal powerpc board with Linux x86 host. gdb/ChangeLog: 2016-03-29 Don Breazeal <donb@codesourcery.com> * gdb/value.c (value_actual_type): Ignore the 'print object on' setting if the object is a pointer to or reference to a structure. --- gdb/value.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gdb/value.c b/gdb/value.c index 738b2b2..95bfdb2 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1205,7 +1205,8 @@ value_actual_type (struct value *value, int resolve_simple_types, if ((TYPE_CODE (result) == TYPE_CODE_PTR || TYPE_CODE (result) == TYPE_CODE_REF) && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) - == TYPE_CODE_STRUCT) + == TYPE_CODE_STRUCT + && !value_optimized_out (value)) { struct type *real_type; -- 1.8.1.1 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-03-29 17:14 ` Don Breazeal @ 2016-03-30 14:35 ` Yao Qi 2016-04-01 16:01 ` Don Breazeal 2016-04-04 21:28 ` Don Breazeal 0 siblings, 2 replies; 26+ messages in thread From: Yao Qi @ 2016-03-30 14:35 UTC (permalink / raw) To: Don Breazeal; +Cc: Yao Qi, Breazeal, Don, Gustavo, Luis, gdb-patches Don Breazeal <donb@codesourcery.com> writes: > Tested on bare-metal powerpc board with Linux x86 host. > Please run regression test on x86-linux. If the test is regression free, the patch is good to me. > gdb/ChangeLog: > 2016-03-29 Don Breazeal <donb@codesourcery.com> > > * gdb/value.c (value_actual_type): Ignore the 'print object > on' setting if the object is a pointer to or reference to > a structure. We should mention the object is optimized out. -- Yao (齐尧) ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-03-30 14:35 ` Yao Qi @ 2016-04-01 16:01 ` Don Breazeal 2016-04-04 10:42 ` Yao Qi 2016-04-04 21:28 ` Don Breazeal 1 sibling, 1 reply; 26+ messages in thread From: Don Breazeal @ 2016-04-01 16:01 UTC (permalink / raw) To: gdb-patches, qiyaoltc Hi Yao, Thanks for the review. > Please run regression test on x86-linux. If the test is regression > free, the patch is good to me. Well, that was a good call, the test was not regression-free. There were failures in gdb.mi/mi-var-list-children-invalid-grandchild.exp. The test resulted in a memory access error in the call to value_optimized_out that I had added. Before my change there was a memory access error caught in value_rtti_indirect_type, which returned NULL in that case. The fix was to catch and ignore errors from value_optimized_out. Details: The test had a pointer to a structure (p_outer), and the structure contained a pointer to another structure (p_outer->inner). The p_outer pointer was set to 0x0, and -var-create and -var-list-children were called for p_outer. With 'set print object' set to 'on', GDB wants to check the actual (rtti) type of p_outer->inner for -var-list-children. Without my change, value_rtti_indirect_type handled the memory access error when it dereferenced p_outer (0x0). With my change, value_optimized_out threw an error trying to get the value of p_outer->inner, since p_outer == 0x0. The fix is to catch errors from value_optimized_out. If we get an error, then we can't tell if the value is optimized out and we default to 'not optimized out'. We let value_rtti_indirect_type handle the memory error. I assume that I didn't see this with my bare-metal testing because it wasn't an error to access address 0x0. I'll be sure to keep that in mind in future testing. Updated patch, patch description, and ChangeLog below. OK with these changes? BTW I will hold off pushing in the corresponding test until this patch is finalized, to avoid introducing new failures. thanks --Don ---- This patch eliminates an error thrown when accessing the value of a pointer to a structure where the pointer has been optimized out and 'set print object' is 'on'. The error shows up as the rather ugly value of the pointer variable in Eclipse. If 'set print object' is 'on', GDB tries to determine the actual (derived) type of the object rather than the declared type, which requires dereferencing the pointer, which in this cases throws an error because the pointer has been optimized out. The fix is to simply ignore the 'print object on' setting for pointers or references to structures when they have been optimized out. This means we just get the declared type instead of the actual type, because in this case that's the best that we can do. Note that we if value_optimized_out throws an error we just assume the value is not optimized out. We let value_rtti_indirect_type handle any errors, and don't try to duplicate its error handling. I'm working on setting things in motion for a patch to Eclipse that recognizes optimized-out pointer-to-struct in this scenario and prevents any subsequent attempt to dereference it from that end. Tested on bare-metal powerpc board with Linux x86 host and Linux native x86_64. gdb/ChangeLog: 2016-04-01 Don Breazeal <donb@codesourcery.com> * value.c (value_actual_type): Don't try to get rtti type of the value if it has been optimized out. --- gdb/value.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index 8268b08..018896e 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1192,6 +1192,7 @@ value_actual_type (struct value *value, int resolve_simple_types, { struct value_print_options opts; struct type *result; + int value_optzd_out; get_user_print_options (&opts); @@ -1200,12 +1201,26 @@ value_actual_type (struct value *value, int resolve_simple_types, result = value_type (value); if (opts.objectprint) { - /* If result's target type is TYPE_CODE_STRUCT, proceed to - fetch its rtti type. */ - if ((TYPE_CODE (result) == TYPE_CODE_PTR - || TYPE_CODE (result) == TYPE_CODE_REF) - && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) - == TYPE_CODE_STRUCT) + TRY + { + value_optzd_out = value_optimized_out (value); + } + CATCH (ex, RETURN_MASK_ERROR) + { + /* If we get an error, assume the value is not optimized out. + If we call value_rtti_indirect_type, it will handle any + errors there; otherwise it won't matter. */ + value_optzd_out = 0; + } + END_CATCH + + /* If result's target type is TYPE_CODE_STRUCT, proceed to + fetch its rtti type. */ + if ((TYPE_CODE (result) == TYPE_CODE_PTR + || TYPE_CODE (result) == TYPE_CODE_REF) + && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) + == TYPE_CODE_STRUCT + && !value_optzd_out) { struct type *real_type; -- 1.8.1.1 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-04-01 16:01 ` Don Breazeal @ 2016-04-04 10:42 ` Yao Qi 2016-04-04 17:16 ` Don Breazeal 0 siblings, 1 reply; 26+ messages in thread From: Yao Qi @ 2016-04-04 10:42 UTC (permalink / raw) To: Don Breazeal; +Cc: gdb-patches, qiyaoltc Don Breazeal <donb@codesourcery.com> writes: > Note that we if value_optimized_out throws an error we just assume > the value is not optimized out. We let value_rtti_indirect_type > handle any errors, and don't try to duplicate its error handling. I am wondering why does value_optimized_out have to throw an error? Can't we catch the error in value_optimized_out thrown by value_fetch_lazy? I am not very sure on this idea, but I searched the archive, and didn't find anything say we can't do that. -- Yao (齐尧) ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-04-04 10:42 ` Yao Qi @ 2016-04-04 17:16 ` Don Breazeal 0 siblings, 0 replies; 26+ messages in thread From: Don Breazeal @ 2016-04-04 17:16 UTC (permalink / raw) To: Yao Qi; +Cc: gdb-patches On 4/4/2016 3:41 AM, Yao Qi wrote: > Don Breazeal <donb@codesourcery.com> writes: > >> Note that we if value_optimized_out throws an error we just assume >> the value is not optimized out. We let value_rtti_indirect_type >> handle any errors, and don't try to duplicate its error handling. > > I am wondering why does value_optimized_out have to throw an error? > Can't we catch the error in value_optimized_out thrown by > value_fetch_lazy? > > I am not very sure on this idea, but I searched the archive, and didn't > find anything say we can't do that. > I looked briefly at all the call sites for value_optimized_out. It looks like if value_optimized_out were to just return 'false' when it got a memory error, the result in most cases would be that a subsequent memory read would throw an error. It might be that this could prevent a scenario similar to the -var-create error elsewhere in GDB, but there wasn't anything obvious in my quick scan. I'll change the patch accordingly and run the testsuite. --Don ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-03-30 14:35 ` Yao Qi 2016-04-01 16:01 ` Don Breazeal @ 2016-04-04 21:28 ` Don Breazeal 2016-04-05 12:53 ` Yao Qi 1 sibling, 1 reply; 26+ messages in thread From: Don Breazeal @ 2016-04-04 21:28 UTC (permalink / raw) To: qiyaoltc, gdb-patches Hi Yao, On 4/4/2016 10:16 AM, Don Breazeal wrote: > On 4/4/2016 3:41 AM, Yao Qi wrote: >> Don Breazeal <donb@codesourcery.com> writes: >> >>> Note that we if value_optimized_out throws an error we just assume >>> the value is not optimized out. We let value_rtti_indirect_type >>> handle any errors, and don't try to duplicate its error handling. >> >> I am wondering why does value_optimized_out have to throw an error? >> Can't we catch the error in value_optimized_out thrown by >> value_fetch_lazy? >> >> I am not very sure on this idea, but I searched the archive, and didn't >> find anything say we can't do that. >> > I looked briefly at all the call sites for value_optimized_out. It > looks like if value_optimized_out were to just return 'false' when it > got a memory error, the result in most cases would be that a subsequent > memory read would throw an error. It might be that this could prevent a > scenario similar to the -var-create error elsewhere in GDB, but there > wasn't anything obvious in my quick scan. > > I'll change the patch accordingly and run the testsuite. Also note that in my scan of value_optimized_out call sites, I didn't notice anywhere that it was explicitly wrapped in a TRY/CATCH block. I made the changes described above, ran the testsuite on x86_64 Linux (no regressions), and updated the patch description and ChangeLog. The updated patch follows below. Thanks --Don ---- This patch eliminates an error thrown when accessing the value of a pointer to a structure where the pointer has been optimized out and 'set print object' is 'on'. The error shows up as the rather ugly value of the pointer variable in Eclipse. If 'set print object' is 'on', GDB tries to determine the actual (derived) type of the object rather than the declared type, which requires dereferencing the pointer, which in this cases throws an error because the pointer has been optimized out. The fix is to simply ignore the 'print object on' setting for pointers or references to structures when they have been optimized out. This means we just get the declared type instead of the actual type, because in this case that's the best that we can do. To implement the fix, value_optimized_out was modified so that it no longer throws an error when it fails to fetch the specified value. Instead, it just returns 'false'. If we can't definitively say that the value is optimized out, then we assume it is not. Note that this affects other parts of GDB that call value_optimized_out; however, visual inspection of the code shows that in all of those cases an error occurring in value_optimized_out will likely recur in a subsequent attempt to access memory, and the error will be thrown there. Meanwhile this change will prevent other scenarios similar to the one that's fixed here. I'm working on setting things in motion for a patch to Eclipse that recognizes optimized-out pointer-to-struct in this scenario and prevents any subsequent attempt to dereference it from that end. Tested on bare-metal powerpc board with Linux x86 host and Linux native x86_64. gdb/ChangeLog: 2016-04-04 Don Breazeal <donb@codesourcery.com> * value.c (value_actual_type): Don't try to get rtti type of the value if it has been optimized out. (value_optimized_out): Return zero if a memory access error occurs. --- gdb/value.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index 8268b08..90ae193 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1205,7 +1205,8 @@ value_actual_type (struct value *value, int resolve_simple_types, if ((TYPE_CODE (result) == TYPE_CODE_PTR || TYPE_CODE (result) == TYPE_CODE_REF) && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) - == TYPE_CODE_STRUCT) + == TYPE_CODE_STRUCT + && !value_optimized_out (value)) { struct type *real_type; @@ -1433,7 +1434,18 @@ value_optimized_out (struct value *value) /* We can only know if a value is optimized out once we have tried to fetch it. */ if (VEC_empty (range_s, value->optimized_out) && value->lazy) - value_fetch_lazy (value); + { + TRY + { + value_fetch_lazy (value); + } + CATCH (ex, RETURN_MASK_ERROR) + { + /* If we get an error, assume the value is not optimized out. */ + return 0; + } + END_CATCH + } return !VEC_empty (range_s, value->optimized_out); } -- 1.8.1.1 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-04-04 21:28 ` Don Breazeal @ 2016-04-05 12:53 ` Yao Qi 2016-04-05 18:51 ` Don Breazeal 0 siblings, 1 reply; 26+ messages in thread From: Yao Qi @ 2016-04-05 12:53 UTC (permalink / raw) To: Don Breazeal; +Cc: qiyaoltc, gdb-patches Don Breazeal <donb@codesourcery.com> writes: Hi Don, > @@ -1433,7 +1434,18 @@ value_optimized_out (struct value *value) > /* We can only know if a value is optimized out once we have tried to > fetch it. */ > if (VEC_empty (range_s, value->optimized_out) && value->lazy) > - value_fetch_lazy (value); > + { > + TRY > + { > + value_fetch_lazy (value); > + } > + CATCH (ex, RETURN_MASK_ERROR) > + { > + /* If we get an error, assume the value is not optimized out. */ > + return 0; Why don't we fall back to checking value->optimized_out below? Some bits/pieces of value are optimized out, but reading the rest of bits/piece may trigger the memory error. In this case, the value is optimized out too. We can do this... TRY { value_fetch_lazy (value); } CATCH (ex, RETURN_MASK_ERROR) { /* Fall back to checking value->optimized_out. */ } END_CATCH What do you think? > + } > + END_CATCH > + } > > return !VEC_empty (range_s, value->optimized_out); Note that, after this patch, value_optimized_out will no longer throw exceptions, some TRY/CATCH in value_optimized_out's callers can be removed, such as gdbscm_value_optimized_out_p and valpy_get_is_optimized_out. This can be done in a follow-up patch. -- Yao (齐尧) ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-04-05 12:53 ` Yao Qi @ 2016-04-05 18:51 ` Don Breazeal 2016-04-05 19:00 ` Pedro Alves 0 siblings, 1 reply; 26+ messages in thread From: Don Breazeal @ 2016-04-05 18:51 UTC (permalink / raw) To: gdb-patches, qiyaoltc Hi Yao, On 4/5/2016 5:52 AM, Yao Qi wrote: > Don Breazeal <donb@codesourcery.com> writes: >> + CATCH (ex, RETURN_MASK_ERROR) >> + { >> + /* If we get an error, assume the value is not optimized out. */ >> + return 0; > > Why don't we fall back to checking value->optimized_out below? Some > bits/pieces of value are optimized out, but reading the rest of > bits/piece may trigger the memory error. In this case, the value is > optimized out too. We can do this... > > TRY > { > value_fetch_lazy (value); > } > CATCH (ex, RETURN_MASK_ERROR) > { > /* Fall back to checking value->optimized_out. */ > } > END_CATCH > > What do you think? Of course, that makes more sense, thanks. > Note that, after this patch, value_optimized_out will no longer throw > exceptions, some TRY/CATCH in value_optimized_out's callers can be > removed, such as gdbscm_value_optimized_out_p and > valpy_get_is_optimized_out. This can be done in a follow-up patch. I've done a more thorough audit of the call sites for value_optimized_out than I did previously, and the only places where an enclosing TRY/CATCH can be removed are the two you name. There is one other place where it is called inside a TRY/CATCH, but there are other functions that could throw errors called there as well. I will create a follow-up patch. I changed this patch as you suggest above, as well as changing RETURN_MASK_ERROR to RETURN_MASK_ALL. The TRY/CATCH blocks that are going to be removed use RETURN_MASK_ALL, and I thought that this patch should maintain the same level of coverage. Re-tested on native Linux x86_64. Thanks, --Don ---- This patch eliminates an error thrown when accessing the value of a pointer to a structure where the pointer has been optimized out and 'set print object' is 'on'. The error shows up as the rather ugly value of the pointer variable in Eclipse. If 'set print object' is 'on', GDB tries to determine the actual (derived) type of the object rather than the declared type, which requires dereferencing the pointer, which in this cases throws an error because the pointer has been optimized out. The fix is to simply ignore the 'print object on' setting for pointers or references to structures when they have been optimized out. This means we just get the declared type instead of the actual type, because in this case that's the best that we can do. To implement the fix, value_optimized_out was modified so that it no longer throws an error when it fails to fetch the specified value. If we can't definitively say that the value is optimized out, then we assume it is not. I'm working on setting things in motion for a patch to Eclipse that recognizes optimized-out pointer-to-struct in this scenario and prevents any subsequent attempt to dereference it from that end. Tested on bare-metal powerpc board with Linux x86 host and Linux native x86_64. gdb/ChangeLog: 2016-04-05 Don Breazeal <donb@codesourcery.com> * value.c (value_actual_type): Don't try to get rtti type of the value if it has been optimized out. (value_optimized_out): If a memory access error occurs, fall back to just checking value->optimized_out. --- gdb/value.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index 8268b08..8a210e7 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1205,7 +1205,8 @@ value_actual_type (struct value *value, int resolve_simple_types, if ((TYPE_CODE (result) == TYPE_CODE_PTR || TYPE_CODE (result) == TYPE_CODE_REF) && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) - == TYPE_CODE_STRUCT) + == TYPE_CODE_STRUCT + && !value_optimized_out (value)) { struct type *real_type; @@ -1433,7 +1434,17 @@ value_optimized_out (struct value *value) /* We can only know if a value is optimized out once we have tried to fetch it. */ if (VEC_empty (range_s, value->optimized_out) && value->lazy) - value_fetch_lazy (value); + { + TRY + { + value_fetch_lazy (value); + } + CATCH (ex, RETURN_MASK_ALL) + { + /* Fall back to checking value->optimized_out. */ + } + END_CATCH + } return !VEC_empty (range_s, value->optimized_out); } -- 1.8.1.1 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-04-05 18:51 ` Don Breazeal @ 2016-04-05 19:00 ` Pedro Alves 2016-04-05 20:39 ` Don Breazeal 0 siblings, 1 reply; 26+ messages in thread From: Pedro Alves @ 2016-04-05 19:00 UTC (permalink / raw) To: Don Breazeal, gdb-patches, qiyaoltc On 04/05/2016 07:50 PM, Don Breazeal wrote: > Hi Yao, > > On 4/5/2016 5:52 AM, Yao Qi wrote: >> Don Breazeal <donb@codesourcery.com> writes: > >>> + CATCH (ex, RETURN_MASK_ERROR) >>> + { >>> + /* If we get an error, assume the value is not optimized out. */ >>> + return 0; >> >> Why don't we fall back to checking value->optimized_out below? Some >> bits/pieces of value are optimized out, but reading the rest of >> bits/piece may trigger the memory error. In this case, the value is >> optimized out too. We can do this... >> >> TRY >> { >> value_fetch_lazy (value); >> } >> CATCH (ex, RETURN_MASK_ERROR) >> { >> /* Fall back to checking value->optimized_out. */ >> } >> END_CATCH >> >> What do you think? > > Of course, that makes more sense, thanks. > >> Note that, after this patch, value_optimized_out will no longer throw >> exceptions, some TRY/CATCH in value_optimized_out's callers can be >> removed, such as gdbscm_value_optimized_out_p and >> valpy_get_is_optimized_out. This can be done in a follow-up patch. > > I've done a more thorough audit of the call sites for value_optimized_out > than I did previously, and the only places where an enclosing TRY/CATCH can > be removed are the two you name. There is one other place where it is > called inside a TRY/CATCH, but there are other functions that could throw > errors called there as well. > > I will create a follow-up patch. > > I changed this patch as you suggest above, as well as changing > RETURN_MASK_ERROR to RETURN_MASK_ALL. The TRY/CATCH blocks that are > going to be removed use RETURN_MASK_ALL, and I thought that this patch > should maintain the same level of coverage. Please don't. A RETURN_MASK_ALL swallows Ctrl-C/QUIT, and that's almost always a bug. The cases you mention translate a QUIT to a python/scheme exception, which is not the same as just swallowing the exception. Thanks, Pedro Alves ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-04-05 19:00 ` Pedro Alves @ 2016-04-05 20:39 ` Don Breazeal 2016-04-06 9:05 ` Yao Qi 0 siblings, 1 reply; 26+ messages in thread From: Don Breazeal @ 2016-04-05 20:39 UTC (permalink / raw) To: gdb-patches, qiyaoltc, palves On 4/5/2016 12:00 PM, Pedro Alves wrote: > On 04/05/2016 07:50 PM, Don Breazeal wrote: >> Hi Yao, >> >> On 4/5/2016 5:52 AM, Yao Qi wrote: >>> Don Breazeal <donb@codesourcery.com> writes: >> >>>> + CATCH (ex, RETURN_MASK_ERROR) >>>> + { >>>> + /* If we get an error, assume the value is not optimized out. */ >>>> + return 0; >>> >>> Why don't we fall back to checking value->optimized_out below? Some >>> bits/pieces of value are optimized out, but reading the rest of >>> bits/piece may trigger the memory error. In this case, the value is >>> optimized out too. We can do this... >>> >>> TRY >>> { >>> value_fetch_lazy (value); >>> } >>> CATCH (ex, RETURN_MASK_ERROR) >>> { >>> /* Fall back to checking value->optimized_out. */ >>> } >>> END_CATCH >>> >>> What do you think? >> >> Of course, that makes more sense, thanks. >> >>> Note that, after this patch, value_optimized_out will no longer throw >>> exceptions, some TRY/CATCH in value_optimized_out's callers can be >>> removed, such as gdbscm_value_optimized_out_p and >>> valpy_get_is_optimized_out. This can be done in a follow-up patch. >> >> I've done a more thorough audit of the call sites for value_optimized_out >> than I did previously, and the only places where an enclosing TRY/CATCH can >> be removed are the two you name. There is one other place where it is >> called inside a TRY/CATCH, but there are other functions that could throw >> errors called there as well. >> >> I will create a follow-up patch. >> >> I changed this patch as you suggest above, as well as changing >> RETURN_MASK_ERROR to RETURN_MASK_ALL. The TRY/CATCH blocks that are >> going to be removed use RETURN_MASK_ALL, and I thought that this patch >> should maintain the same level of coverage. > > Please don't. A RETURN_MASK_ALL swallows Ctrl-C/QUIT, and that's almost > always a bug. The cases you mention translate a QUIT to a python/scheme > exception, which is not the same as just swallowing the exception. Patch below changes that back. Pedro, thanks for clarifying. --Don ---- This patch eliminates an error thrown when accessing the value of a pointer to a structure where the pointer has been optimized out and 'set print object' is 'on'. The error shows up as the rather ugly value of the pointer variable in Eclipse. If 'set print object' is 'on', GDB tries to determine the actual (derived) type of the object rather than the declared type, which requires dereferencing the pointer, which in this cases throws an error because the pointer has been optimized out. The fix is to simply ignore the 'print object on' setting for pointers or references to structures when they have been optimized out. This means we just get the declared type instead of the actual type, because in this case that's the best that we can do. To implement the fix, value_optimized_out was modified so that it no longer throws an error when it fails to fetch the specified value. Instead, it just checks value->optimized_out. If we can't definitively say that the value is optimized out, then we assume it is not. I'm working on setting things in motion for a patch to Eclipse that recognizes optimized-out pointer-to-struct in this scenario and prevents any subsequent attempt to dereference it from that end. Tested on bare-metal powerpc board with Linux x86 host and Linux native x86_64. gdb/ChangeLog: 2016-04-05 Don Breazeal <donb@codesourcery.com> * value.c (value_actual_type): Don't try to get rtti type of the value if it has been optimized out. (value_optimized_out): If a memory access error occurs, just check vaue->optimized_out. --- gdb/value.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index 8268b08..8a210e7 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1205,7 +1205,8 @@ value_actual_type (struct value *value, int resolve_simple_types, if ((TYPE_CODE (result) == TYPE_CODE_PTR || TYPE_CODE (result) == TYPE_CODE_REF) && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) - == TYPE_CODE_STRUCT) + == TYPE_CODE_STRUCT + && !value_optimized_out (value)) { struct type *real_type; @@ -1433,7 +1434,17 @@ value_optimized_out (struct value *value) /* We can only know if a value is optimized out once we have tried to fetch it. */ if (VEC_empty (range_s, value->optimized_out) && value->lazy) - value_fetch_lazy (value); + { + TRY + { + value_fetch_lazy (value); + } + CATCH (ex, RETURN_MASK_ALL) + { + /* Fall back to checking value->optimized_out. */ + } + END_CATCH + } return !VEC_empty (range_s, value->optimized_out); } -- 1.8.1.1 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-04-05 20:39 ` Don Breazeal @ 2016-04-06 9:05 ` Yao Qi 2016-04-06 21:41 ` Don Breazeal 0 siblings, 1 reply; 26+ messages in thread From: Yao Qi @ 2016-04-06 9:05 UTC (permalink / raw) To: Don Breazeal; +Cc: gdb-patches, qiyaoltc, palves Don Breazeal <donb@codesourcery.com> writes: >> Please don't. A RETURN_MASK_ALL swallows Ctrl-C/QUIT, and that's almost >> always a bug. The cases you mention translate a QUIT to a python/scheme >> exception, which is not the same as just swallowing the exception. > > Patch below changes that back. Pedro, thanks for clarifying. > No, it doesn't. > @@ -1433,7 +1434,17 @@ value_optimized_out (struct value *value) > /* We can only know if a value is optimized out once we have tried to > fetch it. */ > if (VEC_empty (range_s, value->optimized_out) && value->lazy) > - value_fetch_lazy (value); > + { > + TRY > + { > + value_fetch_lazy (value); > + } > + CATCH (ex, RETURN_MASK_ALL) It should be RETURN_MASK_ERROR. > + { > + /* Fall back to checking value->optimized_out. */ > + } > + END_CATCH > + } Otherwise, patch is good to me. -- Yao (齐尧) ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-04-06 9:05 ` Yao Qi @ 2016-04-06 21:41 ` Don Breazeal 2016-04-06 22:24 ` Pedro Alves 2016-04-07 14:12 ` Yao Qi 0 siblings, 2 replies; 26+ messages in thread From: Don Breazeal @ 2016-04-06 21:41 UTC (permalink / raw) To: Yao Qi; +Cc: gdb-patches, palves On 4/6/2016 2:04 AM, Yao Qi wrote: > Don Breazeal <donb@codesourcery.com> writes: > >>> Please don't. A RETURN_MASK_ALL swallows Ctrl-C/QUIT, and that's almost >>> always a bug. The cases you mention translate a QUIT to a python/scheme >>> exception, which is not the same as just swallowing the exception. >> >> Patch below changes that back. Pedro, thanks for clarifying. >> > > No, it doesn't. > >> @@ -1433,7 +1434,17 @@ value_optimized_out (struct value *value) >> /* We can only know if a value is optimized out once we have tried to >> fetch it. */ >> if (VEC_empty (range_s, value->optimized_out) && value->lazy) >> - value_fetch_lazy (value); >> + { >> + TRY >> + { >> + value_fetch_lazy (value); >> + } >> + CATCH (ex, RETURN_MASK_ALL) > > It should be RETURN_MASK_ERROR. Sorry about that. /me shakes head at self for goofing up the easy stuff. > >> + { >> + /* Fall back to checking value->optimized_out. */ >> + } >> + END_CATCH >> + } > > Otherwise, patch is good to me. > Thanks Yao. This is now corrected and pushed in. Question: in light of Pedro's comments regarding gdbscm_value_optimized_out_p and valpy_get_is_optimized_out: > A RETURN_MASK_ALL swallows Ctrl-C/QUIT, and that's almost > always a bug. The cases you mention translate a QUIT to > a python/scheme exception, which is not the same as just > swallowing the exception. Would you still like for me to follow up with a patch to remove the TRY/CATCH blocks around the calls to value_optimized_out in those two functions? Or do we want to leave it as-is so that the QUIT handling remains unchanged? Thanks --Don ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-04-06 21:41 ` Don Breazeal @ 2016-04-06 22:24 ` Pedro Alves 2016-04-07 14:12 ` Yao Qi 1 sibling, 0 replies; 26+ messages in thread From: Pedro Alves @ 2016-04-06 22:24 UTC (permalink / raw) To: Don Breazeal, Yao Qi; +Cc: gdb-patches On 04/06/2016 10:41 PM, Don Breazeal wrote: > On 4/6/2016 2:04 AM, Yao Qi wrote: > Question: in light of Pedro's comments regarding > gdbscm_value_optimized_out_p and valpy_get_is_optimized_out: > >> A RETURN_MASK_ALL swallows Ctrl-C/QUIT, and that's almost >> always a bug. The cases you mention translate a QUIT to >> a python/scheme exception, which is not the same as just >> swallowing the exception. > > Would you still like for me to follow up with a patch to remove the > TRY/CATCH blocks around the calls to value_optimized_out in those two > functions? Or do we want to leave it as-is so that the QUIT handling > remains unchanged? Please leave them as is. We need to translate gdb exceptions to Python/Scheme exceptions at the gdb <-> extension-language boundaries. Those gdb functions in question will be returning to the Python/Scheme runtimes, which are not prepared to unwind correctly on a gdb exception. Thanks, Pedro Alves ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Eliminate -var-create error for optzd ptr to struct 2016-04-06 21:41 ` Don Breazeal 2016-04-06 22:24 ` Pedro Alves @ 2016-04-07 14:12 ` Yao Qi 1 sibling, 0 replies; 26+ messages in thread From: Yao Qi @ 2016-04-07 14:12 UTC (permalink / raw) To: Don Breazeal; +Cc: gdb-patches, palves On 06/04/16 22:41, Don Breazeal wrote: > Would you still like for me to follow up with a patch to remove the > TRY/CATCH blocks around the calls to value_optimized_out in those two > functions? Or do we want to leave it as-is so that the QUIT handling > remains unchanged? No, I was wrong on that point. Please leave it as-is. -- Yao (é½å°§) ^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2016-04-07 14:12 UTC | newest] Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-02-24 0:19 [PATCH] Eliminate -var-create error for optzd ptr to struct Don Breazeal 2016-02-24 1:14 ` Luis Machado 2016-02-24 16:31 ` Don Breazeal 2016-02-25 12:22 ` Pedro Alves 2016-03-28 21:33 ` [PATCH v2 0/2] Optzd-out ptr: Error handling improvement Don Breazeal 2016-03-28 21:34 ` [PATCH v2 2/2] Optzd-out ptr: Eliminate -var-create error Don Breazeal 2016-03-28 21:34 ` [PATCH v2 1/2] Optzd-out ptr: New test for error handling Don Breazeal 2016-03-29 11:58 ` Yao Qi 2016-03-29 17:13 ` Don Breazeal 2016-03-30 14:37 ` Yao Qi 2016-04-06 21:34 ` Don Breazeal 2016-03-29 12:01 ` [PATCH] Eliminate -var-create error for optzd ptr to struct Yao Qi 2016-03-29 17:14 ` Don Breazeal 2016-03-30 14:35 ` Yao Qi 2016-04-01 16:01 ` Don Breazeal 2016-04-04 10:42 ` Yao Qi 2016-04-04 17:16 ` Don Breazeal 2016-04-04 21:28 ` Don Breazeal 2016-04-05 12:53 ` Yao Qi 2016-04-05 18:51 ` Don Breazeal 2016-04-05 19:00 ` Pedro Alves 2016-04-05 20:39 ` Don Breazeal 2016-04-06 9:05 ` Yao Qi 2016-04-06 21:41 ` Don Breazeal 2016-04-06 22:24 ` Pedro Alves 2016-04-07 14:12 ` Yao Qi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).