From: Tom Tromey Date: Sun, 23 Apr 2023 15:58:14 +0000 (-0600) Subject: Simplify cp_print_class_member X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9e11d0220f438b3d739a6ced5c7e092ceb7f1b4;p=thirdparty%2Fbinutils-gdb.git Simplify cp_print_class_member I noticed that cp_print_class_member's calling convention can be simplified. In particular it seems cleaner for it to simply take a value and a stream; and the "prefix" argument is only ever set to one value. This version also renames the function, to indicate a bit more clearly what it actually does. Regression tested on x86-64 Fedora 40. Reviewed-By: Keith Seitz --- diff --git a/gdb/c-lang.h b/gdb/c-lang.h index 9796de437bc..7d9eaf8571b 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -103,8 +103,7 @@ extern void c_type_print_base (struct type *, struct ui_file *, /* These are in cp-valprint.c */ -extern void cp_print_class_member (const gdb_byte *, struct type *, - struct ui_file *, const char *); +extern void cp_print_class_memberptr (struct value *, struct ui_file *); extern void cp_print_value_fields (struct value *, struct ui_file *, int, diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index 0ea8c524079..54b992b3b21 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -682,21 +682,17 @@ cp_find_class_member (struct type **self_p, int *fieldno, } void -cp_print_class_member (const gdb_byte *valaddr, struct type *type, - struct ui_file *stream, const char *prefix) +cp_print_class_memberptr (struct value *val, struct ui_file *stream) { + struct type *type = check_typedef (val->type ()); enum bfd_endian byte_order = type_byte_order (type); - /* VAL is a byte offset into the structure type SELF_TYPE. - Find the name of the field for that offset and - print it. */ struct type *self_type = TYPE_SELF_TYPE (type); - LONGEST val; int fieldno; - val = extract_signed_integer (valaddr, - type->length (), - byte_order); + const gdb_byte *valaddr = val->contents_for_printing ().data (); + LONGEST pos = extract_signed_integer (valaddr, type->length (), + byte_order); /* Pointers to data members are usually byte offsets into an object. Because a data member can have offset zero, and a NULL pointer to @@ -708,19 +704,19 @@ cp_print_class_member (const gdb_byte *valaddr, struct type *type, value. GDB only supports that last form; to add support for another form, make this into a cp-abi hook. */ - if (val == -1) + if (pos == -1) { gdb_printf (stream, "NULL"); return; } - cp_find_class_member (&self_type, &fieldno, val << 3); + cp_find_class_member (&self_type, &fieldno, 8 * pos); if (self_type != NULL) { const char *name; - gdb_puts (prefix, stream); + gdb_puts ("&", stream); name = self_type->name (); if (name) gdb_puts (name, stream); @@ -731,7 +727,7 @@ cp_print_class_member (const gdb_byte *valaddr, struct type *type, variable_name_style.style (), stream); } else - gdb_printf (stream, "%ld", (long) val); + gdb_printf (stream, "%s", plongest (pos)); } #if GDB_SELF_TEST diff --git a/gdb/valprint.c b/gdb/valprint.c index b37b494dec6..cd50f3c31c1 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -965,9 +965,7 @@ generic_value_print_memberptr { /* Member pointers are essentially specific to C++, and so if we encounter one, we should print it according to C++ rules. */ - struct type *type = check_typedef (val->type ()); - const gdb_byte *valaddr = val->contents_for_printing ().data (); - cp_print_class_member (valaddr, type, stream, "&"); + cp_print_class_memberptr (val, stream); } else value_print_scalar_formatted (val, options, 0, stream);