From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2640 invoked by alias); 9 Mar 2010 05:17:56 -0000 Received: (qmail 2626 invoked by uid 22791); 9 Mar 2010 05:17:55 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 09 Mar 2010 05:17:49 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 058E32BAB4E; Tue, 9 Mar 2010 00:17:48 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id drrGCnAazdqO; Tue, 9 Mar 2010 00:17:47 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 075482BAB4B; Tue, 9 Mar 2010 00:17:47 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 71B6BF5894; Tue, 9 Mar 2010 09:17:31 +0400 (RET) Date: Tue, 09 Mar 2010 05:17:00 -0000 From: Joel Brobecker To: Pierre Muller Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] avoid GDB crash on inspection of pascal arrays Message-ID: <20100309051731.GN3081@adacore.com> References: <001801cabee0$31499ca0$93dcd5e0$@muller@ics-cnrs.unistra.fr> <20100308185450.GK3081@adacore.com> <001201cabf17$43e1b960$cba52c20$@muller@ics-cnrs.unistra.fr> <20100309051651.GM3081@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="jho1yZJdad60DJr+" Content-Disposition: inline In-Reply-To: <20100309051651.GM3081@adacore.com> User-Agent: Mutt/1.5.20 (2009-06-14) 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 X-SW-Source: 2010-03/txt/msg00349.txt.bz2 --jho1yZJdad60DJr+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 76 > Attached is a couple of patches: [with the patches, this time] -- Joel --jho1yZJdad60DJr+ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="p-valprint-reformat.diff" Content-length: 6921 diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c index 260b97d..3bc9c55 100644 --- a/gdb/p-valprint.c +++ b/gdb/p-valprint.c @@ -151,105 +151,105 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, break; } elttype = check_typedef (TYPE_TARGET_TYPE (type)); - { - addr = unpack_pointer (type, valaddr + embedded_offset); - print_unpacked_pointer: - elttype = check_typedef (TYPE_TARGET_TYPE (type)); - - if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) - { - /* Try to print what function it points to. */ - print_address_demangle (gdbarch, addr, stream, demangle); - /* Return value is irrelevant except for string pointers. */ - return (0); - } - if (options->addressprint && options->format != 's') - { - fputs_filtered (paddress (gdbarch, addr), stream); - } + addr = unpack_pointer (type, valaddr + embedded_offset); + print_unpacked_pointer: + elttype = check_typedef (TYPE_TARGET_TYPE (type)); - /* For a pointer to char or unsigned char, also print the string - pointed to, unless pointer is null. */ - if (((TYPE_LENGTH (elttype) == 1 - && (TYPE_CODE (elttype) == TYPE_CODE_INT - || TYPE_CODE (elttype) == TYPE_CODE_CHAR)) - || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4) - && TYPE_CODE (elttype) == TYPE_CODE_CHAR)) - && (options->format == 0 || options->format == 's') - && addr != 0) - { - /* no wide string yet */ - i = val_print_string (elttype, addr, -1, stream, options); - } - /* also for pointers to pascal strings */ - /* Note: this is Free Pascal specific: - as GDB does not recognize stabs pascal strings - Pascal strings are mapped to records - with lowercase names PM */ - if (is_pascal_string_type (elttype, &length_pos, &length_size, - &string_pos, &char_type, NULL) - && addr != 0) + if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) + { + /* Try to print what function it points to. */ + print_address_demangle (gdbarch, addr, stream, demangle); + /* Return value is irrelevant except for string pointers. */ + return (0); + } + + if (options->addressprint && options->format != 's') + { + fputs_filtered (paddress (gdbarch, addr), stream); + } + + /* For a pointer to char or unsigned char, also print the string + pointed to, unless pointer is null. */ + if (((TYPE_LENGTH (elttype) == 1 + && (TYPE_CODE (elttype) == TYPE_CODE_INT + || TYPE_CODE (elttype) == TYPE_CODE_CHAR)) + || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4) + && TYPE_CODE (elttype) == TYPE_CODE_CHAR)) + && (options->format == 0 || options->format == 's') + && addr != 0) + { + /* no wide string yet */ + i = val_print_string (elttype, addr, -1, stream, options); + } + /* also for pointers to pascal strings */ + /* Note: this is Free Pascal specific: + as GDB does not recognize stabs pascal strings + Pascal strings are mapped to records + with lowercase names PM */ + if (is_pascal_string_type (elttype, &length_pos, &length_size, + &string_pos, &char_type, NULL) + && addr != 0) + { + ULONGEST string_length; + void *buffer; + buffer = xmalloc (length_size); + read_memory (addr + length_pos, buffer, length_size); + string_length = extract_unsigned_integer (buffer, length_size, + byte_order); + xfree (buffer); + i = val_print_string (char_type ,addr + string_pos, string_length, stream, options); + } + else if (pascal_object_is_vtbl_member (type)) + { + /* print vtbl's nicely */ + CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset); + + struct minimal_symbol *msymbol = + lookup_minimal_symbol_by_pc (vt_address); + if ((msymbol != NULL) + && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol))) { - ULONGEST string_length; - void *buffer; - buffer = xmalloc (length_size); - read_memory (addr + length_pos, buffer, length_size); - string_length = extract_unsigned_integer (buffer, length_size, - byte_order); - xfree (buffer); - i = val_print_string (char_type ,addr + string_pos, string_length, stream, options); + fputs_filtered (" <", stream); + fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream); + fputs_filtered (">", stream); } - else if (pascal_object_is_vtbl_member (type)) + if (vt_address && options->vtblprint) { - /* print vtbl's nicely */ - CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset); + struct value *vt_val; + struct symbol *wsym = (struct symbol *) NULL; + struct type *wtype; + struct block *block = (struct block *) NULL; + int is_this_fld; + + if (msymbol != NULL) + wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block, + VAR_DOMAIN, &is_this_fld); - struct minimal_symbol *msymbol = - lookup_minimal_symbol_by_pc (vt_address); - if ((msymbol != NULL) - && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol))) + if (wsym) { - fputs_filtered (" <", stream); - fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream); - fputs_filtered (">", stream); + wtype = SYMBOL_TYPE (wsym); } - if (vt_address && options->vtblprint) + else { - struct value *vt_val; - struct symbol *wsym = (struct symbol *) NULL; - struct type *wtype; - struct block *block = (struct block *) NULL; - int is_this_fld; - - if (msymbol != NULL) - wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block, - VAR_DOMAIN, &is_this_fld); - - if (wsym) - { - wtype = SYMBOL_TYPE (wsym); - } - else - { - wtype = TYPE_TARGET_TYPE (type); - } - vt_val = value_at (wtype, vt_address); - common_val_print (vt_val, stream, recurse + 1, options, - current_language); - if (options->pretty) - { - fprintf_filtered (stream, "\n"); - print_spaces_filtered (2 + 2 * recurse, stream); - } + wtype = TYPE_TARGET_TYPE (type); + } + vt_val = value_at (wtype, vt_address); + common_val_print (vt_val, stream, recurse + 1, options, + current_language); + if (options->pretty) + { + fprintf_filtered (stream, "\n"); + print_spaces_filtered (2 + 2 * recurse, stream); } } - - /* Return number of characters printed, including the terminating - '\0' if we reached the end. val_print_string takes care including - the terminating '\0' if necessary. */ - return i; } + + /* Return number of characters printed, including the terminating + '\0' if we reached the end. val_print_string takes care including + the terminating '\0' if necessary. */ + return i; + break; case TYPE_CODE_REF: --jho1yZJdad60DJr+ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="p-valprint-reformat-w.diff" Content-length: 691 diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c index 260b97d..3bc9c55 100644 --- a/gdb/p-valprint.c +++ b/gdb/p-valprint.c @@ -151,7 +151,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, break; } elttype = check_typedef (TYPE_TARGET_TYPE (type)); - { + addr = unpack_pointer (type, valaddr + embedded_offset); print_unpacked_pointer: elttype = check_typedef (TYPE_TARGET_TYPE (type)); @@ -249,7 +249,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr, '\0' if we reached the end. val_print_string takes care including the terminating '\0' if necessary. */ return i; - } + break; case TYPE_CODE_REF: --jho1yZJdad60DJr+--