From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 1/6] gdb: int to bool conversion in valprint.{c,h}
Date: Tue, 12 May 2026 11:07:22 +0100 [thread overview]
Message-ID: <e2f5ab8d584e59f3d0d9efa98a907ea8b704cc70.1778579473.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1778579473.git.aburgess@redhat.com>
Some int to bool conversion in valprint.c and valprint.h. I also
moved the header comment on val_print_scalar_type_p into the header.
There should be no user visible changes after this commit.
---
gdb/valprint.c | 56 ++++++++++++++++++++++++--------------------------
gdb/valprint.h | 22 +++++++++++---------
2 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 62b1b33bb66..9801f195d13 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -277,11 +277,9 @@ show_symbol_print (struct ui_file *file, int from_tty,
\f
-/* A helper function for val_print. When printing in "summary" mode,
- we want to print scalar arguments, but not aggregate arguments.
- This function distinguishes between the two. */
+/* See valprint.h. */
-int
+bool
val_print_scalar_type_p (struct type *type)
{
type = check_typedef (type);
@@ -297,9 +295,9 @@ val_print_scalar_type_p (struct type *type)
case TYPE_CODE_UNION:
case TYPE_CODE_SET:
case TYPE_CODE_STRING:
- return 0;
+ return false;
default:
- return 1;
+ return true;
}
}
@@ -317,7 +315,7 @@ val_print_scalar_or_string_type_p (struct type *type,
/* See valprint.h. */
-int
+bool
valprint_check_validity (struct ui_file *stream,
struct type *type,
LONGEST embedded_offset,
@@ -328,13 +326,13 @@ valprint_check_validity (struct ui_file *stream,
if (type_not_associated (type))
{
val_print_not_associated (stream);
- return 0;
+ return false;
}
if (type_not_allocated (type))
{
val_print_not_allocated (stream);
- return 0;
+ return false;
}
if (type->code () != TYPE_CODE_UNION
@@ -345,14 +343,14 @@ valprint_check_validity (struct ui_file *stream,
TARGET_CHAR_BIT * type->length ()))
{
val_print_optimized_out (val, stream);
- return 0;
+ return false;
}
if (val->bits_synthetic_pointer (TARGET_CHAR_BIT * embedded_offset,
TARGET_CHAR_BIT * type->length ()))
{
- const int is_ref = type->code () == TYPE_CODE_REF;
- int ref_is_addressable = 0;
+ const bool is_ref = type->code () == TYPE_CODE_REF;
+ bool ref_is_addressable = false;
if (is_ref)
{
@@ -373,11 +371,11 @@ valprint_check_validity (struct ui_file *stream,
if (!val->bytes_available (embedded_offset, type->length ()))
{
val_print_unavailable (stream);
- return 0;
+ return false;
}
}
- return 1;
+ return true;
}
void
@@ -609,9 +607,9 @@ generic_val_print_ref (struct type *type,
const bool value_is_synthetic
= original_value->bits_synthetic_pointer (TARGET_CHAR_BIT * embedded_offset,
TARGET_CHAR_BIT * type->length ());
- const int must_coerce_ref = ((options->addressprint && value_is_synthetic)
- || options->deref_ref);
- const int type_is_defined = elttype->code () != TYPE_CODE_UNDEF;
+ const bool must_coerce_ref = ((options->addressprint && value_is_synthetic)
+ || options->deref_ref);
+ const bool type_is_defined = elttype->code () != TYPE_CODE_UNDEF;
const gdb_byte *valaddr = original_value->contents_for_printing ().data ();
if (must_coerce_ref && type_is_defined)
@@ -687,7 +685,7 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
}
else if (type->is_flag_enum ())
{
- int first = 1;
+ bool first = true;
/* We have a "flag" enum, so we try to decompose it into pieces as
appropriate. The enum may have multiple enumerators representing
@@ -707,7 +705,7 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
if (first)
{
gdb_puts ("(", stream);
- first = 0;
+ first = false;
}
else
gdb_puts (" | ", stream);
@@ -1157,11 +1155,11 @@ val_print_check_max_depth (struct ui_file *stream, int recurse,
return false;
}
-/* Check whether the value VAL is printable. Return 1 if it is;
- return 0 and print an appropriate error message to STREAM according to
- OPTIONS if it is not. */
+/* Check whether the value VAL is printable. Return true if it is;
+ return false and print an appropriate error message to STREAM
+ according to OPTIONS if it is not. */
-static int
+static bool
value_check_printable (struct value *val, struct ui_file *stream,
const struct value_print_options *options)
{
@@ -1169,7 +1167,7 @@ value_check_printable (struct value *val, struct ui_file *stream,
{
fprintf_styled (stream, metadata_style.style (),
_("<address of value unknown>"));
- return 0;
+ return false;
}
if (val->entirely_optimized_out ())
@@ -1178,7 +1176,7 @@ value_check_printable (struct value *val, struct ui_file *stream,
gdb_printf (stream, "...");
else
val_print_optimized_out (val, stream);
- return 0;
+ return false;
}
if (val->entirely_unavailable ())
@@ -1187,7 +1185,7 @@ value_check_printable (struct value *val, struct ui_file *stream,
gdb_printf (stream, "...");
else
val_print_unavailable (stream);
- return 0;
+ return false;
}
if (val->type ()->code () == TYPE_CODE_INTERNAL_FUNCTION)
@@ -1195,16 +1193,16 @@ value_check_printable (struct value *val, struct ui_file *stream,
fprintf_styled (stream, metadata_style.style (),
_("<internal function %s>"),
value_internal_function_name (val));
- return 0;
+ return false;
}
if (type_not_allocated (val->type ()))
{
val_print_not_allocated (stream);
- return 0;
+ return false;
}
- return 1;
+ return true;
}
/* See valprint.h. */
diff --git a/gdb/valprint.h b/gdb/valprint.h
index 0ce3e0781f6..c8f4bd52286 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -197,17 +197,15 @@ extern void print_function_pointer_address (const struct value_print_options *op
/* Helper function to check the validity of some bits of a value.
- If TYPE represents some aggregate type (e.g., a structure), return 1.
+ If TYPE represents some aggregate type (e.g., a structure), return true.
- Otherwise, any of the bytes starting at OFFSET and extending for
- TYPE->length () bytes are invalid, print a message to STREAM and
- return 0. The checking is done using FUNCS.
+ For non-aggregate TYPEs, if any of the bytes starting at EMBEDDED_OFFSET
+ and extending for TYPE->length () bytes are invalid, print a message to
+ STREAM and return false. Otherwise, return true. */
- Otherwise, return 1. */
-
-extern int valprint_check_validity (struct ui_file *stream, struct type *type,
- LONGEST embedded_offset,
- const struct value *val);
+extern bool valprint_check_validity (struct ui_file *stream, struct type *type,
+ LONGEST embedded_offset,
+ const struct value *val);
extern void val_print_optimized_out (const struct value *val,
struct ui_file *stream);
@@ -272,7 +270,11 @@ extern void generic_printstr (struct ui_file *stream, struct type *type,
extern void output_command (const char *args, int from_tty);
-extern int val_print_scalar_type_p (struct type *type);
+/* When printing in "summary" mode we want to print scalar arguments
+ but not aggregate arguments. Return true if TYPE is a scalar type,
+ false if it is an aggregate. */
+
+extern bool val_print_scalar_type_p (struct type *type);
struct format_data
{
--
2.25.4
next prev parent reply other threads:[~2026-05-12 10:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 10:07 [PATCH 0/6] Fix aggregate types, synthetic pointers, and computed locations bug Andrew Burgess
2026-05-12 10:07 ` Andrew Burgess [this message]
2026-05-13 14:48 ` [PATCH 1/6] gdb: int to bool conversion in valprint.{c,h} Tom Tromey
2026-05-12 10:07 ` [PATCH 2/6] gdb: use TARGET_CHAR_BIT more in dwarf2/expr.c Andrew Burgess
2026-05-13 15:05 ` Tom Tromey
2026-05-15 12:00 ` Andrew Burgess
2026-05-15 14:44 ` Tom Tromey
2026-05-12 10:07 ` [PATCH 3/6] gdb: fix coerce_pieced_ref for multi-piece values Andrew Burgess
2026-05-14 18:53 ` Tom Tromey
2026-05-12 10:07 ` [PATCH 4/6] gdb: rename argument in valprint_check_validity Andrew Burgess
2026-05-13 16:23 ` Tom Tromey
2026-05-12 10:07 ` [PATCH 5/6] gdb: remove embedded_offset argument that is always 0 Andrew Burgess
2026-05-13 15:27 ` Tom Tromey
2026-05-12 10:07 ` [PATCH 6/6] gdb: use value::embedded_offset in check_pieced_synthetic_pointer Andrew Burgess
2026-05-14 19:00 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e2f5ab8d584e59f3d0d9efa98a907ea8b704cc70.1778579473.git.aburgess@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox