From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24847 invoked by alias); 16 Mar 2010 21:10:38 -0000 Received: (qmail 24839 invoked by uid 22791); 16 Mar 2010 21:10:37 -0000 X-SWARE-Spam-Status: No, hits=1.9 required=5.0 tests=AWL,BAYES_00,KAM_STOCKTIP,MSGID_MULTIPLE_AT X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.153) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 16 Mar 2010 21:10:33 +0000 Received: from baal.u-strasbg.fr (baal.u-strasbg.fr [IPv6:2001:660:2402::41]) by mailhost.u-strasbg.fr (8.14.2/jtpda-5.5pre1) with ESMTP id o2GLATGo079150 for ; Tue, 16 Mar 2010 22:10:29 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms3.u-strasbg.fr [IPv6:2001:660:2402:d::12]) by baal.u-strasbg.fr (8.14.0/jtpda-5.5pre1) with ESMTP id o2GLATQE082803 for ; Tue, 16 Mar 2010 22:10:29 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from d620muller (lec67-4-82-230-53-140.fbx.proxad.net [82.230.53.140]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o2GLAS06051337 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Tue, 16 Mar 2010 22:10:28 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: Subject: [RFC] Support for const char and strings in stabs reader Date: Tue, 16 Mar 2010 21:10:00 -0000 Message-ID: <000201cac54d$246dcdd0$6d496970$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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/msg00610.txt.bz2 Stabs reader currently only supports constants of integer, real or enum types. This patch adds support for char and string types, as described in http://sourceware.org/gdb/current/onlinedocs/stabs/Constants.html#Constants I tried to implement support for both single and double quote in the code. The string type is currently used for Free Pascal compiler, so I could directly test it. I also tried to add some check to gdb.stabs testsuite, but I got caught by some typical tcl expansion problems while trying to test the second form using double quotes... The original lines in gdb.stabs/weird.def # Test string constant .stabs "constString1:c=s'String1'", N_LSYM,0,0, 0 .stabs "constString2:c=s\"String2\"", N_LSYM,0,0, 0 .stabs "constString3:c=s'String3 with embedded quote \' in the middle'", N_LSYM,0,0, 0 become .stabs "constString1:c=s'String1'", 0x80,0,0, 0 .stabs "constString2:c=s\\"String2\"", 0x80,0,0, 0 .stabs "constString3:c=s'String3 with embedded quote \\' in the middle'", 0x80,0,0, 0 Note the fact that only one of the two escaped double quote is transformed into \\".. I tried all combination, and nothing seemed to work... Comments welcome, Pierre Muller Pascal language support maintainer for GDB PS: I left the boolean support out because currently objfile builtin_types do not have a builtin_bool, which would be required here. 2010-03-16 Pierre Muller * stabsread.c (define_symbol): Add support for char and string constants. Index: stabsread.c =================================================================== RCS file: /cvs/src/src/gdb/stabsread.c,v retrieving revision 1.123 diff -u -p -r1.123 stabsread.c --- stabsread.c 8 Jan 2010 08:55:16 -0000 1.123 +++ stabsread.c 16 Mar 2010 21:07:48 -0000 @@ -793,6 +793,56 @@ define_symbol (CORE_ADDR valu, char *str SYMBOL_CLASS (sym) = LOC_CONST; } break; + + case 'c': + { + SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_char; + SYMBOL_VALUE (sym) = atoi (p); + SYMBOL_CLASS (sym) = LOC_CONST; + } + break; + + case 's': + { + struct type *range_type; + char quote = *p++; + char *startp = p; + gdb_byte *string_value; + if (quote != '\'' && quote != '"') + { + SYMBOL_CLASS (sym) = LOC_CONST; + SYMBOL_TYPE (sym) = error_type (&p, objfile); + SYMBOL_DOMAIN (sym) = VAR_DOMAIN; + add_symbol_to_list (sym, &file_symbols); + return sym; + } + /* Find matching quote, rejecting escaped quotes. */ + while (*p && *p != quote) + { + if (*p == '\\') + p++; + if (*p) + p++; + } + *p = '\0'; + range_type = create_range_type (NULL, + objfile_type (objfile)->builtin_int, + 0, strlen(startp)); + SYMBOL_TYPE (sym) = create_array_type (NULL, + objfile_type (objfile)->builtin_char, + range_type); + string_value = + obstack_alloc (&objfile->objfile_obstack, + strlen (startp) + 1); + strcpy ((char *)string_value, startp); + *p = quote; + p++; + + SYMBOL_VALUE_BYTES (sym) = string_value; + SYMBOL_CLASS (sym) = LOC_CONST_BYTES; + } + break; + case 'e': /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value can be represented as integral. Index: testsuite/gdb.stabs/weird.def =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.stabs/weird.def,v retrieving revision 1.3 diff -u -p -r1.3 weird.def --- testsuite/gdb.stabs/weird.def 8 Jan 2010 08:55:16 -0000 1.3 +++ testsuite/gdb.stabs/weird.def 16 Mar 2010 21:07:49 -0000 @@ -286,6 +286,15 @@ attr69: # Test constant with the type embedded. .stabs "const70:c=e190=bs2;0;16;,70", N_LSYM,0,0, 0 +# Test char constant +.stabs "constchar:c=70", N_LSYM,0,0, 0 + +# Test string constant +.stabs "constString1:c=s'String1'", N_LSYM,0,0, 0 +.stabs "constString2:c=s\"String2\"", N_LSYM,0,0, 0 +.stabs "constString3:c=s'String3 with embedded quote \' in the middle'", N_LSYM,0,0, 0 + + .stabs "attr38:G338=@& !#$%&'()*+,-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmno pqrstuvwxyz{|}~;1",N_GSYM,0,0, 0 # Unrecognized negative type number. Index: testsuite/gdb.stabs/weird.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.stabs/weird.exp,v retrieving revision 1.18 diff -u -p -r1.18 weird.exp --- testsuite/gdb.stabs/weird.exp 1 Jan 2010 07:32:06 -0000 1.18 +++ testsuite/gdb.stabs/weird.exp 16 Mar 2010 21:07:49 -0000 @@ -164,6 +164,11 @@ proc do_tests {} { gdb_test "p sizeof (const70)" " = 2" "'e' constant with embedded type" + gdb_test "p /x constchar" " = 0x46" "char constant" + gdb_test "p constString1" " = \"String1\"" "String constant 1" + gdb_test "p constString2" " = \"String2\"" "String constant 2" + gdb_test "p constString3" " = \"String3 with embedded quote ' in the middle\"" "String constant 3" + gdb_test "p bad_neg0" " = \{field0 = 42, field2 =.*field3 = 45\}" "p bad_neg0" gdb_test "ptype inttype" "type = (unsigned int|inttype)" "ptype on inttype"