* gdb/stabsread.c (define_symbol): Add support for char
authorPierre Muller <muller@sourceware.org>
Mon, 5 Apr 2010 22:43:49 +0000 (22:43 +0000)
committerPierre Muller <muller@sourceware.org>
Mon, 5 Apr 2010 22:43:49 +0000 (22:43 +0000)
and string constants.

* gdb/testsuite/gdb.stabs/aout.sed: Convert all backslash to double backslash
within one line, unless it is followed by a double quote.
* gdb/testsuite/gdb.stabs/hppa.sed: Idem.
* gdb/testsuite/gdb.stabs/weird.def: Add char and String constants
* gdb/testsuite/gdb.stabs/weird.exp: Check for correct parsing of
chhar and string constants.
* gdb/testsuite/gdb.stabs/xcoff.sed: Ignore escaped quote quotes
in .stabs to .stabx substitution.

gdb/ChangeLog
gdb/stabsread.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.stabs/aout.sed
gdb/testsuite/gdb.stabs/hppa.sed
gdb/testsuite/gdb.stabs/weird.def
gdb/testsuite/gdb.stabs/weird.exp
gdb/testsuite/gdb.stabs/xcoff.sed

index 43743d1..41395bf 100644 (file)
@@ -1,5 +1,10 @@
 2010-04-06  Pierre Muller  <muller@ics.u-strasbg.fr>
 
+       * stabsread.c (define_symbol): Add support for char
+       and string constants.
+
+2010-04-06  Pierre Muller  <muller@ics.u-strasbg.fr>
+
        Remove remaining "%ll" uses.
        * go32-nat.c (go32_pte_for_address): Replace "0x%llx" using
        hex_string call.
index 71c168c..a6b8881 100644 (file)
@@ -793,6 +793,75 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
            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;
+           int ind = 0;
+           char quote = *p++;
+           char *startp = p;
+           gdb_byte *string_local = (gdb_byte *) alloca (strlen (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[1] == quote)
+                 {
+                   string_local[ind] = (gdb_byte) quote;
+                   ind++;
+                   p += 2;
+                 }
+               else if (*p) 
+                 {
+                   string_local[ind] = (gdb_byte) (*p);
+                   ind++;
+                   p++;
+                 }
+             }
+           if (*p != 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;
+             }
+
+           /* NULL terminate the string.  */
+           string_local[ind] = 0;
+           range_type = create_range_type (NULL,
+                                           objfile_type (objfile)->builtin_int,
+                                           0, ind);
+           SYMBOL_TYPE (sym) = create_array_type (NULL,
+                                 objfile_type (objfile)->builtin_char,
+                                 range_type);
+           string_value = obstack_alloc (&objfile->objfile_obstack, ind + 1);
+           memcpy (string_value, string_local, ind + 1);
+           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 1b2f843..2da03ed 100644 (file)
@@ -1,3 +1,14 @@
+2010-04-06  Pierre Muller  <muller@ics.u-strasbg.fr>
+
+       * gdb.stabs/aout.sed: Convert all backslash to double backslash
+       within one line, unless it is followed by a double quote.
+       * gdb.stabs/hppa.sed: Idem.
+       * gdb.stabs/weird.def: Add char and String constants
+       * gdb.stabs/weird.exp: Check for correct parsing of 
+       chhar and string constants.
+       * gdb.stabs/xcoff.sed: Ignore escaped quote quotes
+       in .stabs to .stabx substitution.
+
 2010-04-05  Stan Shebs  <stan@codesourcery.com>
 
        * gdb.trace/tfile.c: Add a variable split across two blocks, and a
index bbe38bc..1bc5b1d 100644 (file)
@@ -9,7 +9,7 @@ Label0:
 s/N_LSYM/0x80/
 s/N_GSYM/0x20/
 s/# Replace a single backslash with a doubled backslash//
-/\.stabs/s/\\/\\\\/
+/\.stabs/s/\\\([^"]\)/\\\\\1/g
 s/\.begin_common\(.*\)/.stabs \1,0xe2,0,0,0/
 s/\.end_common\(.*\)/.stabs \1,0xe4,0,0,0/
 s/\.align_it/.align 2/
index 5ca1a00..bc1cf90 100644 (file)
@@ -9,7 +9,7 @@ Label0:
 s/N_LSYM/0x80/
 s/N_GSYM/0x20/
 s/# Replace a single backslash with a doubled backslash//
-/\.stabs/s/\\/\\\\/
+/\.stabs/s/\\/\\\\/g
 s/# Only labels should be at the beginning of a line, assembler directives//
 s/# and instructions should start somewhere after column zero.//
 /^\./s/^\./    ./
index 71fcff6..179b126 100644 (file)
@@ -286,6 +286,20 @@ 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=c97", N_LSYM,0,0, 0
+
+# Test string constant
+.stabs "constString1:c=s'Single quote String1'", N_LSYM,0,0, 0
+# Using double quotes requires an escaping, as the stabs string
+# is a double quote delimited string.
+.stabs "constString2:c=s\"Double quote String2\"", N_LSYM,0,0, 0
+# Escaping sinlge quote with is easy
+.stabs "constString3:c=s'String3 with embedded quote \' in the middle'", N_LSYM,0,0, 0
+# Esaping double quotes is less clear...
+.stabs "constString4:c=s\"String4 with embedded quote \\" in the middle\"", N_LSYM,0,0, 0
+
+
 .stabs "attr38:G338=@& !#$%&'()*+,-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~;1",N_GSYM,0,0, 0
 
 # Unrecognized negative type number.  
index 114c9ec..04dca73 100644 (file)
@@ -164,6 +164,12 @@ proc do_tests {} {
 
        gdb_test "p sizeof (const70)" " = 2" "'e' constant with embedded type"
 
+       gdb_test "p constchar" " = 97 'a'" "char constant"
+        gdb_test "p constString1" " = \"Single quote String1\"" "String constant 1"
+        gdb_test "p constString2" " = \"Double quote String2\"" "String constant 2"
+
+        gdb_test "p constString3" " = \"String3 with embedded quote ' in the middle\"" "String constant 3"
+        gdb_test "p constString4" { = "String4 with embedded quote \\" in the middle"} "String constant 4"
        gdb_test "p bad_neg0" " = \{field0 = 42, field2 =.*field3 = 45\}" "p bad_neg0"
 
        gdb_test "ptype inttype" "type = (unsigned int|inttype)" "ptype on inttype"
@@ -251,6 +257,8 @@ proc print_weird_var { var } {
 
 global target_os
 set sedscript ${srcdir}/${subdir}/aout.sed
+set sedoptions ""
+
 switch -glob ${target_triplet} {
     "hppa*-*-*" {
        set sedscript ${srcdir}/${subdir}/hppa.sed
@@ -260,15 +268,18 @@ switch -glob ${target_triplet} {
     }
     "powerpc-*-aix*" {
        set sedscript ${srcdir}/${subdir}/xcoff.sed
+       set sedoptions "-r"
     }
     "rs6000-*-aix*" {
        set sedscript ${srcdir}/${subdir}/xcoff.sed
+       set sedoptions "-r"
     }
     "*-*-aout" {
        set sedscript ${srcdir}/${subdir}/aout.sed
     }
     "*-*-xcoff" {
        set sedscript ${srcdir}/${subdir}/xcoff.sed
+       set sedoptions "-r"
     }
     "alpha-*-*" {
        set sedscript ${srcdir}/${subdir}/ecoff.sed
@@ -276,7 +287,7 @@ switch -glob ${target_triplet} {
 }
 
 # Hope this is a Unix box.
-set exec_output [remote_exec build "sed" "-f ${sedscript}" "${srcdir}/${subdir}/weird.def" "${srcfile}"]
+set exec_output [remote_exec build "sed" "${sedoptions} -f ${sedscript}" "${srcdir}/${subdir}/weird.def" "${srcfile}"]
 if { [lindex $exec_output 0] != 0 } {
     perror "Couldn't make test case. $exec_output"
     return -1
index 8a6b4ef..6dc8198 100644 (file)
@@ -4,7 +4,7 @@
 1i\
        .csect .data[RW]
 # .stabs string,type,0,0,value  ->  .stabx string,value,type,0
-s/^[   ]*\.stabs[      ]*\("[^"]*"\),[         ]*\([^,]*\),[   ]*0,0,[         ]*\(.*\)$/.stabx \1,\3,\2,0/
+s/^[   ]*\.stabs[      ]*("(\"|[^"])*"),[      ]*([^,]*),[     ]*0,0,[         ]*(.*)$/.stabx \1,\4,\3,0/
 s/N_GSYM/128/
 # This needs to be C_DECL, which is used for types, not C_LSYM, which is
 # ignored on the initial scan.