From ec8a089a3021e52b4e686dd75d84e6ef26511737 Mon Sep 17 00:00:00 2001 From: Pierre Muller Date: Mon, 5 Apr 2010 22:43:49 +0000 Subject: [PATCH] * gdb/stabsread.c (define_symbol): Add support for char 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 | 5 +++ gdb/stabsread.c | 69 +++++++++++++++++++++++++++++++ gdb/testsuite/ChangeLog | 11 +++++ gdb/testsuite/gdb.stabs/aout.sed | 2 +- gdb/testsuite/gdb.stabs/hppa.sed | 2 +- gdb/testsuite/gdb.stabs/weird.def | 14 +++++++ gdb/testsuite/gdb.stabs/weird.exp | 13 +++++- gdb/testsuite/gdb.stabs/xcoff.sed | 2 +- 8 files changed, 114 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 43743d14701..41395bf4ee2 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2010-04-06 Pierre Muller + + * stabsread.c (define_symbol): Add support for char + and string constants. + 2010-04-06 Pierre Muller Remove remaining "%ll" uses. diff --git a/gdb/stabsread.c b/gdb/stabsread.c index 71c168c450a..a6b8881662c 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -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. diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 1b2f8434ea0..2da03edcda7 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2010-04-06 Pierre Muller + + * 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 * gdb.trace/tfile.c: Add a variable split across two blocks, and a diff --git a/gdb/testsuite/gdb.stabs/aout.sed b/gdb/testsuite/gdb.stabs/aout.sed index bbe38bc459a..1bc5b1d7bc3 100644 --- a/gdb/testsuite/gdb.stabs/aout.sed +++ b/gdb/testsuite/gdb.stabs/aout.sed @@ -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/ diff --git a/gdb/testsuite/gdb.stabs/hppa.sed b/gdb/testsuite/gdb.stabs/hppa.sed index 5ca1a003c37..bc1cf90f7b2 100644 --- a/gdb/testsuite/gdb.stabs/hppa.sed +++ b/gdb/testsuite/gdb.stabs/hppa.sed @@ -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/^\./ ./ diff --git a/gdb/testsuite/gdb.stabs/weird.def b/gdb/testsuite/gdb.stabs/weird.def index 71fcff677ff..179b1260aba 100644 --- a/gdb/testsuite/gdb.stabs/weird.def +++ b/gdb/testsuite/gdb.stabs/weird.def @@ -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. diff --git a/gdb/testsuite/gdb.stabs/weird.exp b/gdb/testsuite/gdb.stabs/weird.exp index 114c9ec74b3..04dca7394e1 100644 --- a/gdb/testsuite/gdb.stabs/weird.exp +++ b/gdb/testsuite/gdb.stabs/weird.exp @@ -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 diff --git a/gdb/testsuite/gdb.stabs/xcoff.sed b/gdb/testsuite/gdb.stabs/xcoff.sed index 8a6b4ef1986..6dc81985096 100644 --- a/gdb/testsuite/gdb.stabs/xcoff.sed +++ b/gdb/testsuite/gdb.stabs/xcoff.sed @@ -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. -- 2.30.2