From patchwork Wed Jul 8 21:07:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 7597 Received: (qmail 5868 invoked by alias); 8 Jul 2015 21:08:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 5800 invoked by uid 89); 8 Jul 2015 21:08:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, SPF_PASS autolearn=no 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:17 +0000 Received: from EUSAAHC005.ericsson.se (Unknown_Domain [147.117.188.87]) by usevmg21.ericsson.net (Symantec Mail Security) with SMTP id 3A.A4.07675.6E92D955; Wed, 8 Jul 2015 15:47:18 +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:11 -0400 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH 2/7] Factor out print_unpacked_pointer from c_val_print Date: Wed, 8 Jul 2015 17:07:04 -0400 Message-ID: <1436389629-18754-3-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 X-IsSubscribed: yes Turn this code into a function, instead of a goto. gdb/ChangeLog: * c-valprint.c (c_val_print): Factor out pointer printing code to ... (print_unpacked_pointer): ... this new function. --- gdb/c-valprint.c | 205 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 106 insertions(+), 99 deletions(-) diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index e8a2fc7..41950ee 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -127,6 +127,104 @@ static const struct generic_val_print_decorations c_decorations = "void" }; +/* Print a pointer based on the type of its target. + * + * Arguments to this functions are roughly the same as those in c_val_print. + * A difference is that ADDRESS is the address to print, with embedded_offset + * already added. UNRESOLVED_ELTTYPE and ELTTYPE represent the pointed type, + * respectively before and after check_typedef. */ + +static void +print_unpacked_pointer (struct type *type, struct type *elttype, + struct type *unresolved_elttype, + const gdb_byte *valaddr, int embedded_offset, + CORE_ADDR address, struct ui_file *stream, int recurse, + const struct value_print_options *options) +{ + int want_space = 0; + struct gdbarch *gdbarch = get_type_arch (type); + + if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) + { + /* Try to print what function it points to. */ + print_function_pointer_address (options, gdbarch, address, stream); + return; + } + + if (options->symbol_print) + want_space = print_address_demangle (options, gdbarch, address, stream, + demangle); + else if (options->addressprint) + { + fputs_filtered (paddress (gdbarch, address), stream); + want_space = 1; + } + + /* For a pointer to a textual type, also print the string + pointed to, unless pointer is null. */ + + if (c_textual_element_type (unresolved_elttype, options->format) + && address != 0) + { + if (want_space) + fputs_filtered (" ", stream); + val_print_string (unresolved_elttype, NULL, address, -1, stream, options); + } + else if (cp_is_vtbl_member (type)) + { + /* Print vtbl's nicely. */ + CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset); + struct bound_minimal_symbol msymbol = + lookup_minimal_symbol_by_pc (vt_address); + + /* If 'symbol_print' is set, we did the work above. */ + if (!options->symbol_print + && (msymbol.minsym != NULL) + && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol))) + { + if (want_space) + fputs_filtered (" ", stream); + fputs_filtered (" <", stream); + fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), stream); + fputs_filtered (">", stream); + want_space = 1; + } + + if (vt_address && options->vtblprint) + { + struct value *vt_val; + struct symbol *wsym = (struct symbol *) NULL; + struct type *wtype; + struct block *block = (struct block *) NULL; + struct field_of_this_result is_this_fld; + + if (want_space) + fputs_filtered (" ", stream); + + if (msymbol.minsym != NULL) + wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME(msymbol.minsym), block, + VAR_DOMAIN, &is_this_fld); + + if (wsym) + { + wtype = SYMBOL_TYPE (wsym); + } + else + { + wtype = unresolved_elttype; + } + vt_val = value_at (wtype, vt_address); + common_val_print (vt_val, stream, recurse + 1, options, + current_language); + if (options->prettyformat) + { + fprintf_filtered (stream, "\n"); + print_spaces_filtered (2 + 2 * recurse, stream); + } + } + } +} + /* See val_print for a description of the various parameters of this function; they are identical. */ @@ -237,10 +335,11 @@ c_val_print (struct type *type, const gdb_byte *valaddr, } break; } - /* Array of unspecified length: treat like pointer to first - elt. */ - addr = address + embedded_offset; - goto print_unpacked_pointer; + /* Array of unspecified length: treat like pointer to first elt. */ + print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr, + embedded_offset, address + embedded_offset, + stream, recurse, options); + break; case TYPE_CODE_METHODPTR: cplus_print_method_ptr (valaddr + embedded_offset, type, stream); @@ -267,101 +366,9 @@ c_val_print (struct type *type, const gdb_byte *valaddr, } unresolved_elttype = TYPE_TARGET_TYPE (type); elttype = check_typedef (unresolved_elttype); - { - int want_space; - - addr = unpack_pointer (type, valaddr + embedded_offset); - print_unpacked_pointer: - - want_space = 0; - - if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) - { - /* Try to print what function it points to. */ - print_function_pointer_address (options, gdbarch, addr, stream); - return; - } - - if (options->symbol_print) - want_space = print_address_demangle (options, gdbarch, addr, - stream, demangle); - else if (options->addressprint) - { - fputs_filtered (paddress (gdbarch, addr), stream); - want_space = 1; - } - - /* For a pointer to a textual type, also print the string - pointed to, unless pointer is null. */ - - if (c_textual_element_type (unresolved_elttype, - options->format) - && addr != 0) - { - if (want_space) - fputs_filtered (" ", stream); - val_print_string (unresolved_elttype, NULL, - addr, -1, - stream, options); - } - else if (cp_is_vtbl_member (type)) - { - /* Print vtbl's nicely. */ - CORE_ADDR vt_address = unpack_pointer (type, - valaddr - + embedded_offset); - struct bound_minimal_symbol msymbol = - lookup_minimal_symbol_by_pc (vt_address); - - /* If 'symbol_print' is set, we did the work above. */ - if (!options->symbol_print - && (msymbol.minsym != NULL) - && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol))) - { - if (want_space) - fputs_filtered (" ", stream); - fputs_filtered (" <", stream); - fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), stream); - fputs_filtered (">", stream); - want_space = 1; - } - - if (vt_address && options->vtblprint) - { - struct value *vt_val; - struct symbol *wsym = (struct symbol *) NULL; - struct type *wtype; - struct block *block = (struct block *) NULL; - struct field_of_this_result is_this_fld; - - if (want_space) - fputs_filtered (" ", stream); - - if (msymbol.minsym != NULL) - wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME (msymbol.minsym), - block, VAR_DOMAIN, - &is_this_fld); - - if (wsym) - { - wtype = SYMBOL_TYPE (wsym); - } - else - { - wtype = unresolved_elttype; - } - vt_val = value_at (wtype, vt_address); - common_val_print (vt_val, stream, recurse + 1, - options, current_language); - if (options->prettyformat) - { - fprintf_filtered (stream, "\n"); - print_spaces_filtered (2 + 2 * recurse, stream); - } - } - } - return; - } + addr = unpack_pointer (type, valaddr + embedded_offset); + print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr, + embedded_offset, addr, stream, recurse, options); break; case TYPE_CODE_UNION: