From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6426 invoked by alias); 8 Jul 2015 21:08:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 6379 invoked by uid 89); 8 Jul 2015 21:08:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: usevmg21.ericsson.net Received: from usevmg21.ericsson.net (HELO usevmg21.ericsson.net) (198.24.6.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 08 Jul 2015 21:08:22 +0000 Received: from EUSAAHC005.ericsson.se (Unknown_Domain [147.117.188.87]) by usevmg21.ericsson.net (Symantec Mail Security) with SMTP id 2B.A4.07675.7E92D955; Wed, 8 Jul 2015 15:47:19 +0200 (CEST) Received: from elxcz23q12-y4.dyn.mo.ca.am.ericsson.se (147.117.188.8) by smtps-am.internal.ericsson.com (147.117.188.87) with Microsoft SMTP Server (TLS) id 14.3.210.2; Wed, 8 Jul 2015 17:08:12 -0400 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH 5/7] Factor out struct and union printing code from c_val_print Date: Wed, 08 Jul 2015 21:08:00 -0000 Message-ID: <1436389629-18754-6-git-send-email-simon.marchi@ericsson.com> In-Reply-To: <1436389629-18754-1-git-send-email-simon.marchi@ericsson.com> References: <1436389629-18754-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2015-07/txt/msg00266.txt.bz2 gdb/ChangeLog: * c-valprint.c (c_val_print): Factor out struct and union printing code to ... (c_val_print_struct): ... this new function ... (c_val_print_union): ... and this new function. --- gdb/c-valprint.c | 88 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 30 deletions(-) diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 9f68815..d950de3 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -369,6 +369,58 @@ c_val_print_ptr (struct type *type, const gdb_byte *valaddr, } } +/* c_val_print helper for TYPE_CODE_STRUCT. */ + +static void +c_val_print_struct (struct type *type, const gdb_byte *valaddr, + int embedded_offset, CORE_ADDR address, + struct ui_file *stream, int recurse, + const struct value *original_value, + const struct value_print_options *options) +{ + if (options->vtblprint && cp_is_vtbl_ptr_type (type)) + { + /* Print the unmangled name if desired. */ + /* Print vtable entry - we only get here if NOT using + -fvtable_thunks. (Otherwise, look under + TYPE_CODE_PTR.) */ + struct gdbarch *gdbarch = get_type_arch (type); + int offset = (embedded_offset + + TYPE_FIELD_BITPOS (type, + VTBL_FNADDR_OFFSET) / 8); + struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET); + CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type); + + print_function_pointer_address (options, gdbarch, addr, stream); + } + else + cp_print_value_fields_rtti (type, valaddr, + embedded_offset, address, + stream, recurse, + original_value, options, + NULL, 0); +} + +/* c_val_print helper for TYPE_CODE_UNION. */ + +static void +c_val_print_union (struct type *type, const gdb_byte *valaddr, + int embedded_offset, CORE_ADDR address, + struct ui_file *stream, int recurse, + const struct value *original_value, + const struct value_print_options *options) +{ + if (recurse && !options->unionprint) + { + fprintf_filtered (stream, "{...}"); + } + else + { + c_val_print_struct (type, valaddr, embedded_offset, address, stream, + recurse, original_value, options); + } +} + /* See val_print for a description of the various parameters of this function; they are identical. */ @@ -379,7 +431,6 @@ c_val_print (struct type *type, const gdb_byte *valaddr, const struct value *original_value, const struct value_print_options *options) { - struct gdbarch *gdbarch = get_type_arch (type); struct type *unresolved_type = type; CHECK_TYPEDEF (type); @@ -400,36 +451,13 @@ c_val_print (struct type *type, const gdb_byte *valaddr, break; case TYPE_CODE_UNION: - if (recurse && !options->unionprint) - { - fprintf_filtered (stream, "{...}"); - break; - } - /* Fall through. */ + c_val_print_union (type, valaddr, embedded_offset, address, stream, + recurse, original_value, options); + break; + case TYPE_CODE_STRUCT: - /*FIXME: Abstract this away. */ - if (options->vtblprint && cp_is_vtbl_ptr_type (type)) - { - /* Print the unmangled name if desired. */ - /* Print vtable entry - we only get here if NOT using - -fvtable_thunks. (Otherwise, look under - TYPE_CODE_PTR.) */ - int offset = (embedded_offset - + TYPE_FIELD_BITPOS (type, - VTBL_FNADDR_OFFSET) / 8); - struct type *field_type = TYPE_FIELD_TYPE (type, - VTBL_FNADDR_OFFSET); - CORE_ADDR addr - = extract_typed_address (valaddr + offset, field_type); - - print_function_pointer_address (options, gdbarch, addr, stream); - } - else - cp_print_value_fields_rtti (type, valaddr, - embedded_offset, address, - stream, recurse, - original_value, options, - NULL, 0); + c_val_print_struct (type, valaddr, embedded_offset, address, stream, + recurse, original_value, options); break; case TYPE_CODE_INT: -- 2.1.4