Message ID | 1459526505-19291-1-git-send-email-donb@codesourcery.com |
---|---|
State | New |
Headers | show |
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.
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
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;