From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: <gdb-patches@sourceware.org>
Subject: [RFC] Support for const char and strings in stabs reader
Date: Tue, 16 Mar 2010 21:10:00 -0000 [thread overview]
Message-ID: <000201cac54d$246dcdd0$6d496970$@muller@ics-cnrs.unistra.fr> (raw)
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 <muller@ics.u-strasbg.fr>
* 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"
next reply other threads:[~2010-03-16 21:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-16 21:10 Pierre Muller [this message]
2010-03-22 21:56 ` PING " Pierre Muller
2010-03-22 22:19 ` Joel Brobecker
2010-03-23 18:53 ` Joel Brobecker
2010-03-24 22:55 ` [RFC-v2] " Pierre Muller
2010-04-05 15:19 ` Joel Brobecker
2010-04-05 22:48 ` Pierre Muller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='000201cac54d$246dcdd0$6d496970$@muller@ics-cnrs.unistra.fr' \
--to=pierre.muller@ics-cnrs.unistra.fr \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox