This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit/Ada 07/11] rewrite ada_val_print_ref to reduce if/else block nesting depth
- From: Joel Brobecker <brobecker at adacore dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 7 Jan 2014 08:21:51 +0400
- Subject: [commit/Ada 07/11] rewrite ada_val_print_ref to reduce if/else block nesting depth
- Authentication-results: sourceware.org; auth=none
- References: <1389068515-10129-1-git-send-email-brobecker at adacore dot com>
The logic as currently implemented in this function was a little
difficult to follow, due to the nested of if/else conditions,
but most of the time, the "else" block was very simple. So this
patch re-organizes the code to use fewer levels of nesting by
using return statements, and writing the code as a sequence of
"if something simple, then handle it and return" blocks.
While touching this code, this patch changes the cryptic "???"
printed when trying to print a reference pointing to an undefined
type. This should only ever happen if the debugging information
was corrupted or improperly read. But in case that happens, we now
print "<ref to undefined type>" instead. This is more in line
with how we print other conditions such as optimized out pieces,
or synthetic pointers.
gdb/ChangeLog:
* ada-valprint.c (ada_val_print_ref): Rewrite by mostly
re-organizing the code. Change the "???" message printed
when target type is a TYPE_CODE_UNDEF into
"<ref to undefined type>".
---
gdb/ChangeLog | 7 ++++++
gdb/ada-valprint.c | 65 +++++++++++++++++++++++++++---------------------------
2 files changed, 39 insertions(+), 33 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4c1978c..ece68cc 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
2014-01-07 Joel Brobecker <brobecker@adacore.com>
+ * ada-valprint.c (ada_val_print_ref): Rewrite by mostly
+ re-organizing the code. Change the "???" message printed
+ when target type is a TYPE_CODE_UNDEF into
+ "<ref to undefined type>".
+
+2014-01-07 Joel Brobecker <brobecker@adacore.com>
+
* ada-valprint.c (print_record): Delete, implementation inlined...
(ada_val_print_struct_union): ... here. Remove call to
ada_check_typedef in inlined implementation.
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 22ec9c0..12c84da 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -1015,45 +1015,44 @@ ada_val_print_ref (struct type *type, const gdb_byte *valaddr,
So, for Ada values, we print the actual dereferenced value
regardless. */
struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
+ struct value *deref_val;
+ CORE_ADDR deref_val_int;
- if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
+ if (TYPE_CODE (elttype) == TYPE_CODE_UNDEF)
{
- CORE_ADDR deref_val_int;
- struct value *deref_val;
+ fputs_filtered ("<ref to undefined type>", stream);
+ return;
+ }
- deref_val = coerce_ref_if_computed (original_value);
- if (deref_val)
- {
- if (ada_is_tagged_type (value_type (deref_val), 1))
- deref_val = ada_tag_value_at_base_address (deref_val);
+ deref_val = coerce_ref_if_computed (original_value);
+ if (deref_val)
+ {
+ if (ada_is_tagged_type (value_type (deref_val), 1))
+ deref_val = ada_tag_value_at_base_address (deref_val);
- common_val_print (deref_val, stream, recurse + 1, options,
- current_language);
- return;
- }
+ common_val_print (deref_val, stream, recurse + 1, options,
+ language);
+ return;
+ }
- deref_val_int = unpack_pointer (type, valaddr + offset_aligned);
- if (deref_val_int != 0)
- {
- deref_val =
- ada_value_ind (value_from_pointer
- (lookup_pointer_type (elttype),
- deref_val_int));
-
- if (ada_is_tagged_type (value_type (deref_val), 1))
- deref_val = ada_tag_value_at_base_address (deref_val);
-
- val_print (value_type (deref_val),
- value_contents_for_printing (deref_val),
- value_embedded_offset (deref_val),
- value_address (deref_val), stream, recurse + 1,
- deref_val, options, current_language);
- }
- else
- fputs_filtered ("(null)", stream);
+ deref_val_int = unpack_pointer (type, valaddr + offset_aligned);
+ if (deref_val_int == 0)
+ {
+ fputs_filtered ("(null)", stream);
+ return;
}
- else
- fputs_filtered ("???", stream);
+
+ deref_val
+ = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype),
+ deref_val_int));
+ if (ada_is_tagged_type (value_type (deref_val), 1))
+ deref_val = ada_tag_value_at_base_address (deref_val);
+
+ val_print (value_type (deref_val),
+ value_contents_for_printing (deref_val),
+ value_embedded_offset (deref_val),
+ value_address (deref_val), stream, recurse + 1,
+ deref_val, options, language);
}
/* See the comment on ada_val_print. This function differs in that it
--
1.8.3.2