[PATCH 07/12] Generic print unavailable or optimized out function.

Andrew Burgess
2013-08-12T12:28:29Z

Following on from the patch #6, this factors out a common pattern:
given a value print either <optimized-out> or <unavailable>.

OK to apply?

Thanks,
Andrew

gdb/ChangeLog

2013-08-08 Andrew Burgess <aburgess@broadcom.com>

* cp-valprint.c (cp_print_value_fields): Use
val_print_unavailability_reason.
* jv-valprint.c (java_print_value_fields): Use
val_print_unavailability_reason.
* p-valprint.c (pascal_object_print_value_fields): Use
val_print_unavailability_reason.
* valprint.c (valprint_check_validity, value_check_printable)
(val_print_scalar_formatted): Use val_print_unavailability_reason.
(val_print_unavailability_reason): New function.
* valprint.h (val_print_unavailability_reason): New function.

diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 5dd98b0..6b66092 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -298,13 +298,7 @@ cp_print_value_fields (struct type *type, struct
type *real_type,
TYPE_FIELD_BITPOS (type, i),
TYPE_FIELD_BITSIZE (type, i)))
{
- int optimizedp, unavailablep;
-
- value_availability_flags (val, &optimizedp, &unavailablep);
- if (optimizedp)
- val_print_optimized_out (stream);
- else
- val_print_unavailable (stream);
+ val_print_unavailability_reason (val, stream);
}
else
{
diff --git a/gdb/jv-valprint.c b/gdb/jv-valprint.c
index edcd769..dfa2d38 100644
--- a/gdb/jv-valprint.c
+++ b/gdb/jv-valprint.c
@@ -394,15 +394,7 @@ java_print_value_fields (struct type *type, const
gdb_byte *valaddr,
}
else if (!value_bits_available (val, TYPE_FIELD_BITPOS (type, i),
TYPE_FIELD_BITSIZE (type, i)))
- {
- int optimizedp, unavailablep;
-
- value_availability_flags (val, &optimizedp, &unavailablep);
- if (optimizedp)
- val_print_optimized_out (stream);
- else
- val_print_unavailable (stream);
- }
+ val_print_unavailability_reason (val, stream);
else
{
struct value_print_options opts;
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index bc57541..0bd0022 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -628,15 +628,7 @@ pascal_object_print_value_fields (struct type
*type, const gdb_byte *valaddr,
}
else if (!value_bits_available (val, TYPE_FIELD_BITPOS (type, i),
TYPE_FIELD_BITSIZE (type, i)))
- {
- int optimizedp, unavailablep;
- - value_availability_flags (val, &optimizedp, &unavailablep);
- if (optimizedp)
- val_print_optimized_out (stream);
- else
- val_print_unavailable (stream);
- }
+ val_print_unavailability_reason (val, stream);
else
{
struct value_print_options opts = *options;
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 4e165b4..0443737 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -314,13 +314,7 @@ valprint_check_validity (struct ui_file *stream,
if (!value_bits_available (val, TARGET_CHAR_BIT * embedded_offset,
TARGET_CHAR_BIT * TYPE_LENGTH (type)))
{
- int optimizedp, unavailablep;
- - value_availability_flags (val, &optimizedp, &unavailablep);
- if (optimizedp)
- val_print_optimized_out (stream);
- else
- val_print_unavailable (stream);
+ val_print_unavailability_reason (val, stream);
return 0;
}
@@ -353,6 +347,19 @@ val_print_invalid_address (struct ui_file *stream)
fprintf_filtered (stream, _("<invalid address>"));
}
+void
+val_print_unavailability_reason (const struct value *value,
+ struct ui_file *stream)
+{
+ int optimizedp, unavailablep;
+
+ value_availability_flags (value, &optimizedp, &unavailablep);
+ if (optimizedp)
+ val_print_optimized_out (stream);
+ else
+ val_print_unavailable (stream);
+}
+
/* A generic val_print that is suitable for use by language
implementations of the la_val_print method. This function can
handle most type codes, though not all, notably exception
@@ -805,15 +812,7 @@ value_check_printable (struct value *val, struct
ui_file *stream,
if (options->summary && !scalar_type_p (value_type (val)))
fprintf_filtered (stream, "...");
else
- {
- int optimizedp, unavailablep;
-
- value_availability_flags (val, &optimizedp, &unavailablep);
- if (optimizedp)
- val_print_optimized_out (stream);
- else
- val_print_unavailable (stream);
- }
+ val_print_unavailability_reason (val, stream);
return 0;
}
@@ -973,15 +972,7 @@ val_print_scalar_formatted (struct type *type,
/* A scalar object that does not have all bits available can't be
printed, because all bits contribute to its representation. */
if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
- {
- int optimizedp, unavailablep;
- - value_availability_flags (val, &optimizedp, &unavailablep);
- if (optimizedp)
- val_print_optimized_out (stream);
- else
- val_print_unavailable (stream);
- }
+ val_print_unavailability_reason (val, stream);
else
print_scalar_formatted (valaddr + embedded_offset, type,
options, size, stream);
diff --git a/gdb/valprint.h b/gdb/valprint.h
index 2959098..5d7f211 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -166,6 +166,12 @@ extern void val_print_unavailable (struct ui_file
*stream);
extern void val_print_invalid_address (struct ui_file *stream);
+/* For VALUE call the most appropriate of val_print_optimized_out or
+ val_print_unavailable on STREAM. */
+
+void val_print_unavailability_reason (const struct value *value,
+ struct ui_file *stream);
+
/* An instance of this is passed to generic_val_print and describes
some language-specific ways to print things. */