From patchwork Thu Jul 9 15:30:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 7618 Received: (qmail 93390 invoked by alias); 9 Jul 2015 15:30:47 -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 93378 invoked by uid 89); 9 Jul 2015 15:30:46 -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; Thu, 09 Jul 2015 15:30:44 +0000 Received: from EUSAAHC004.ericsson.se (Unknown_Domain [147.117.188.84]) by usevmg21.ericsson.net (Symantec Mail Security) with SMTP id D7.C2.07675.14C2E955; Thu, 9 Jul 2015 10:09:37 +0200 (CEST) Received: from [142.133.110.144] (147.117.188.8) by smtp-am.internal.ericsson.com (147.117.188.86) with Microsoft SMTP Server id 14.3.210.2; Thu, 9 Jul 2015 11:30:41 -0400 Message-ID: <559E93A1.3050704@ericsson.com> Date: Thu, 9 Jul 2015 11:30:41 -0400 From: Simon Marchi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: gdb-patches Subject: Re: [PATCH 2/7] Factor out print_unpacked_pointer from c_val_print References: <1436389629-18754-1-git-send-email-simon.marchi@ericsson.com> <1436389629-18754-3-git-send-email-simon.marchi@ericsson.com> In-Reply-To: <1436389629-18754-3-git-send-email-simon.marchi@ericsson.com> X-IsSubscribed: yes On 15-07-08 05:07 PM, Simon Marchi wrote: > 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: > Update diff of what was pushed. I fixed the formatting of the function comment. From 1033c33c36c5f3d0b89d58aaaa374c76562583f3 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 9 Jul 2015 11:16:22 -0400 Subject: [PATCH] Factor out print_unpacked_pointer from c_val_print 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/ChangeLog | 6 ++ gdb/c-valprint.c | 205 ++++++++++++++++++++++++++++--------------------------- 2 files changed, 112 insertions(+), 99 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 443565a..1c8ec1d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2015-07-09 Simon Marchi + * c-valprint.c (c_val_print): Factor out pointer printing code + to ... + (print_unpacked_pointer): ... this new function. + +2015-07-09 Simon Marchi + * c-valprint.c (c_val_print): Remove an assignment to i and move its declaration. diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index e8a2fc7..4648f17 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: