summaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorDavid Carlton <carlton@bactrian.org>2002-11-24 18:47:19 +0000
committerDavid Carlton <carlton@bactrian.org>2002-11-24 18:47:19 +0000
commit926cef753154b32ae49d68d5cc7e84bddb29562e (patch)
tree01f282948304f811f4c3fa1b27a072e857229ae6 /gdb
parentacf8336196beecd58dc203333066961fb2962e70 (diff)
downloadgdb-926cef753154b32ae49d68d5cc7e84bddb29562e.tar.gz
2002-11-24 David Carlton <carlton@bactrian.org>
* Makefile.in (c-typeprint.o): Depend on gdb_assert_h. * c-typeprint.c: #include "gdb_assert.h" * gdbtypes.c (recursive_dump_type): Handle TYPE_CODE_NAMESPACE. * c-typeprint.c (c_type_print_varspec_prefix): Ditto. (c_type_print_varspec_suffix): Ditto. (c_type_print_base): Ditto. * typeprint.c (print_type_scalar): Ditto. * printcmd.c (print_formatted): Ditto. * language.c (structured_type): Ditto. * cp-support.c (cp_check_namespace_symbol): Allocate type via init_type. * gdbtypes.c (init_type): Handle TYPE_CODE_NAMESPACE. * valops.c (value_namespace_elt): Handle sym == NULL. 2002-11-24 David Carlton <carlton@bactrian.org> * gdb.c++/namespace.exp: Eliminate some of the single quotes, and duplicate some of the single quote tests without the quotes. Change "print E::ce" test. Add some ptype <namespace> tests. * carlton_runnamespace: Use different files for compiler with and without debug info.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog16
-rw-r--r--gdb/Makefile.in2
-rw-r--r--gdb/c-typeprint.c9
-rw-r--r--gdb/cp-support.c11
-rw-r--r--gdb/gdbtypes.c6
-rw-r--r--gdb/language.c7
-rw-r--r--gdb/printcmd.c3
-rw-r--r--gdb/testsuite/ChangeLog9
-rwxr-xr-xgdb/testsuite/carlton_runnamespace8
-rw-r--r--gdb/testsuite/gdb.c++/namespace.exp70
-rw-r--r--gdb/typeprint.c1
-rw-r--r--gdb/valops.c6
12 files changed, 113 insertions, 35 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a942ce4ba2b..26ea576e5ea 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,19 @@
+2002-11-24 David Carlton <carlton@bactrian.org>
+
+ * Makefile.in (c-typeprint.o): Depend on gdb_assert_h.
+ * c-typeprint.c: #include "gdb_assert.h"
+ * gdbtypes.c (recursive_dump_type): Handle TYPE_CODE_NAMESPACE.
+ * c-typeprint.c (c_type_print_varspec_prefix): Ditto.
+ (c_type_print_varspec_suffix): Ditto.
+ (c_type_print_base): Ditto.
+ * typeprint.c (print_type_scalar): Ditto.
+ * printcmd.c (print_formatted): Ditto.
+ * language.c (structured_type): Ditto.
+ * cp-support.c (cp_check_namespace_symbol): Allocate type via
+ init_type.
+ * gdbtypes.c (init_type): Handle TYPE_CODE_NAMESPACE.
+ * valops.c (value_namespace_elt): Handle sym == NULL.
+
2002-11-22 David Carlton <carlton@math.stanford.edu>
* linespec.c (examine_compound_token): Rewrite as switch
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 3d3428476a0..3c79b81a55c 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1566,7 +1566,7 @@ c-lang.o: c-lang.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \
c-typeprint.o: c-typeprint.c $(defs_h) $(gdb_obstack_h) $(bfd_h) $(symtab_h) \
$(gdbtypes_h) $(expression_h) $(value_h) $(gdbcore_h) $(target_h) \
$(language_h) $(demangle_h) $(c_lang_h) $(typeprint_h) $(cp_abi_h) \
- $(gdb_string_h)
+ $(gdb_string_h) $(gdb_assert_h)
c-valprint.o: c-valprint.c $(defs_h) $(gdb_string_h) $(symtab_h) \
$(gdbtypes_h) $(expression_h) $(value_h) $(valprint_h) $(language_h) \
$(c_lang_h) $(cp_abi_h)
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 6c5e815e2af..e2997386660 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -37,6 +37,7 @@
#include "gdb_string.h"
#include <errno.h>
+#include "gdb_assert.h"
/* Flag indicating target was compiled by HP compiler */
extern int hp_som_som_object_present;
@@ -281,6 +282,7 @@ c_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
case TYPE_CODE_COMPLEX:
case TYPE_CODE_TYPEDEF:
case TYPE_CODE_TEMPLATE:
+ case TYPE_CODE_NAMESPACE:
/* These types need no prefix. They are listed here so that
gcc -Wall will reveal any types that haven't been handled. */
break;
@@ -613,6 +615,7 @@ c_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
case TYPE_CODE_COMPLEX:
case TYPE_CODE_TYPEDEF:
case TYPE_CODE_TEMPLATE:
+ case TYPE_CODE_NAMESPACE:
/* These types do not need a suffix. They are listed so that
gcc -Wall will report types that may not have been considered. */
break;
@@ -1171,6 +1174,12 @@ c_type_print_base (struct type *type, struct ui_file *stream, int show,
}
break;
+ case TYPE_CODE_NAMESPACE:
+ gdb_assert (TYPE_NAME (type) != NULL);
+ fputs_filtered ("namespace ", stream);
+ fputs_filtered (TYPE_NAME (type), stream);
+ break;
+
default:
/* Handle types not explicitly handled by the other cases,
such as fundamental types. For these, just print whatever
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index f5dfedb24ec..43ed49c3d3f 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -463,13 +463,10 @@ cp_check_namespace_symbol (const char *name, int len)
if (sym == NULL)
{
- struct type *type = alloc_type (objfile);
- INIT_CPLUS_SPECIFIC (type);
- TYPE_TAG_NAME (type) = obsavestring (name, len, &objfile->type_obstack);
- TYPE_NAME (type) = TYPE_TAG_NAME (type);
- TYPE_CODE (type) = TYPE_CODE_NAMESPACE;
- TYPE_LENGTH (type) = 0;
-
+ struct type *type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
+ name_copy, objfile);
+ TYPE_TAG_NAME (type) = TYPE_NAME (type);
+
sym = obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
memset (sym, 0, sizeof (struct symbol));
SYMBOL_LANGUAGE (sym) = language_cplus;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index c9cae4cda8d..1df5c21c9e2 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1879,7 +1879,8 @@ init_type (enum type_code code, int length, int flags, char *name,
/* C++ fancies. */
- if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
+ if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION
+ || code == TYPE_CODE_NAMESPACE)
{
INIT_CPLUS_SPECIFIC (type);
}
@@ -3104,6 +3105,9 @@ recursive_dump_type (struct type *type, int spaces)
case TYPE_CODE_TEMPLATE_ARG:
printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
break;
+ case TYPE_CODE_NAMESPACE:
+ printf_filtered ("(TYPE_CODE_NAMESPACE)");
+ break;
default:
printf_filtered ("(UNKNOWN TYPE CODE)");
break;
diff --git a/gdb/language.c b/gdb/language.c
index 8eee8f6d4a5..39419201080 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -910,9 +910,10 @@ structured_type (struct type *type)
case language_c:
case language_cplus:
case language_objc:
- return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
- (TYPE_CODE (type) == TYPE_CODE_UNION) ||
- (TYPE_CODE (type) == TYPE_CODE_ARRAY);
+ return (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+ || (TYPE_CODE (type) == TYPE_CODE_UNION)
+ || (TYPE_CODE (type) == TYPE_CODE_ARRAY)
+ || (TYPE_CODE (type) == TYPE_CODE_NAMESPACE);
case language_pascal:
return (TYPE_CODE(type) == TYPE_CODE_STRUCT) ||
(TYPE_CODE(type) == TYPE_CODE_UNION) ||
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 71ad8a166c2..b4753d000f7 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -321,7 +321,8 @@ print_formatted (struct value *val, register int format, int size,
|| TYPE_CODE (type) == TYPE_CODE_ARRAY
|| TYPE_CODE (type) == TYPE_CODE_STRING
|| TYPE_CODE (type) == TYPE_CODE_STRUCT
- || TYPE_CODE (type) == TYPE_CODE_UNION)
+ || TYPE_CODE (type) == TYPE_CODE_UNION
+ || TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
/* If format is 0, use the 'natural' format for
* that type of value. If the type is non-scalar,
* we have to use language rules to print it as
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 3fd752f2041..20ea0920900 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2002-11-24 David Carlton <carlton@bactrian.org>
+
+ * gdb.c++/namespace.exp: Eliminate some of the single quotes, and
+ duplicate some of the single quote tests without the quotes.
+ Change "print E::ce" test.
+ Add some ptype <namespace> tests.
+ * carlton_runnamespace: Use different files for compiler with and
+ without debug info.
+
2002-11-22 David Carlton <carlton@math.stanford.edu>
* gdb.c++/namespace.exp: Change a couple of tests to not use
diff --git a/gdb/testsuite/carlton_runnamespace b/gdb/testsuite/carlton_runnamespace
index 37a836422f3..4ec2202d470 100755
--- a/gdb/testsuite/carlton_runnamespace
+++ b/gdb/testsuite/carlton_runnamespace
@@ -5,13 +5,13 @@
# info. Maybe eventually I should run this on one which generates
# stabs info, too?
-EXTRACOMPPATH=/usr/local/testbed/gcc3/bin
+EXTRADEBUGPATH=/usr/local/testbed/gcc3/bin
echo "Running tests using regular compiler."
-runtest namespace.exp 2>&1 | grep -v "^Test Run By" > /tmp/namespaceout
+runtest gdb.c++/namespace.exp 2>&1 | grep -v "^Test Run By" > /tmp/namespaceout
diff -u {carlton_,/tmp/}namespaceout
echo "Running tests using compiler with extra debug info."
-PATH=${EXTRACOMPPATH}:${PATH} runtest namespace.exp 2>&1 | grep -v "^Test Run By" > /tmp/namespaceout
-diff -u {carlton_,/tmp/}namespaceout
+PATH=${EXTRADEBUGPATH}:${PATH} runtest gdb.c++/namespace.exp 2>&1 | grep -v "^Test Run By" > /tmp/namespacedebugout
+diff -u {carlton_,/tmp/}namespacedebugout
echo "Done."
diff --git a/gdb/testsuite/gdb.c++/namespace.exp b/gdb/testsuite/gdb.c++/namespace.exp
index ce1e088dd80..354668c5df8 100644
--- a/gdb/testsuite/gdb.c++/namespace.exp
+++ b/gdb/testsuite/gdb.c++/namespace.exp
@@ -78,7 +78,10 @@ gdb_test "up" ".*main.*" "up from marker1"
# Access a data item inside a namespace using colons and
# single quotes. :-(
-# NOTE: carlton/2002-11-22: the colons are becoming less necessary.
+# NOTE: carlton/2002-11-24: the colons are becoming less necessary (or
+# even desirable.) For tests where it should still work with colons,
+# I'm including versions both with and without colons; for tests that
+# shouldn't work with colons, I'm only including one version.
send_gdb "print 'AAA::c'\n"
gdb_expect {
@@ -131,6 +134,15 @@ gdb_expect {
# Call a function in a namespace
+send_gdb "print 'AAA::xyzq'('x')\n"
+gdb_expect {
+ -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
+ pass "print 'AAA::xyzq'('x')"
+ }
+ -re ".*$gdb_prompt $" { fail "print 'AAA::xyzq'('x')" }
+ timeout { fail "(timeout) print 'AAA::xyzq'('x')" }
+}
+
send_gdb "print AAA::xyzq('x')\n"
gdb_expect {
-re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
@@ -162,6 +174,15 @@ gdb_expect {
timeout { fail "(timeout) print 'BBB::CCC::xyzq'('x')" }
}
+send_gdb "print BBB::CCC::xyzq('x')\n"
+gdb_expect {
+ -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
+ pass "print 'BBB::CCC::xyzq'('x')"
+ }
+ -re ".*$gdb_prompt $" { fail "print BBB::CCC::xyzq('x')" }
+ timeout { fail "(timeout) print BBB::CCC::xyzq('x')" }
+}
+
# Break on a function in a nested namespace
send_gdb "break BBB::CCC::xyzq\n"
@@ -184,6 +205,15 @@ gdb_expect {
timeout { fail "(timeout) print 'BBB::Class::xyzq'" }
}
+send_gdb "print BBB::Class::xyzq\n"
+gdb_expect {
+ -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" {
+ pass "print BBB::Class::xyzq"
+ }
+ -re ".*$gdb_prompt $" { fail "print BBB::Class::xyzq" }
+ timeout { fail "(timeout) print BBB::Class::xyzq" }
+}
+
# Break on a function in a class in a namespace
send_gdb "break BBB::Class::xyzq\n"
@@ -199,38 +229,42 @@ gdb_expect {
# to print out stuff from within a function defined within a
# namespace.
-if ![runto "'C::D::marker2'"] then {
+if ![runto "C::D::marker2"] then {
perror "couldn't run to marker2"
continue
}
gdb_test "print c" "\\$\[0-9\].* = 1" "print c"
gdb_test "print cc" "No symbol \"cc\" in current context." "print cc"
-gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2" "print C::cc"
+gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2" "print 'C::cc'"
+gdb_test "print C::cc" "\\$\[0-9\].* = 2" "print C::cc"
gdb_test "print cd" "\\$\[0-9\].* = 3" "print cd"
-gdb_test "print 'C::D::cd'" "\\$\[0-9\].* = 3" "print C::D::cd"
-gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5" "print E::cde"
+gdb_test "print 'C::D::cd'" "\\$\[0-9\].* = 3" "print 'C::D::cd'"
+gdb_test "print C::D::cd" "\\$\[0-9\].* = 3" "print C::D::cd"
+gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5" "print 'E::cde'"
+gdb_test "print E::cde" "\\$\[0-9\].* = 5" "print E::cde"
gdb_test "print shadow" "\\$\[0-9\].* = 13" "print shadow"
-
-# NOTE: carlton/2002-10-17: This one won't get fixed until namespaces
-# are first-class objects. The PR isn't right, either.
-
-setup_kfail "gdb/827"
-gdb_test "print 'E::ce'" "No symbol \"E::ce\" in current context." "print E::ce"
+gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"." "print E::ce"
+gdb_test "ptype C" "type = namespace C::C" "ptype C::C"
+gdb_test "ptype E" "type = namespace C::D::E" "ptype C::D::E"
# Some anonymous namespace tests.
gdb_test "print cX" "\\$\[0-9\].* = 6" "print cX"
-gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7" "print F::cXf"
-gdb_test "print 'F::cXfX'" "\\$\[0-9\].* = 8" "print F::cXfX"
+gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7" "print 'F::cXf'"
+gdb_test "print F::cXf" "\\$\[0-9\].* = 7" "print F::cXf"
+gdb_test "print 'F::cXfX'" "\\$\[0-9\].* = 8" "print 'F::cXfX'"
+gdb_test "print F::cXfX" "\\$\[0-9\].* = 8" "print F::cXfX"
gdb_test "print X" "\\$\[0-9\].* = 9" "print X"
-gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10" "print G::Xg"
-gdb_test "print 'G::XgX'" "\\$\[0-9\].* = 11" "print G::XgX"
+gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10" "print 'G::Xg'"
+gdb_test "print G::Xg" "\\$\[0-9\].* = 10" "print G::Xg"
+gdb_test "print 'G::XgX'" "\\$\[0-9\].* = 11" "print 'G::XgX'"
+gdb_test "print G::XgX" "\\$\[0-9\].* = 11" "print G::XgX"
# Test namespace renaming.
setup_kfail "gdb/830"
-gdb_test "print 'I::h'" "\\$\[0-9\].* = 14" "print I::h"
+gdb_test "print I::h" "\\$\[0-9\].* = 14" "print I::h"
# Test using directives.
@@ -241,13 +275,13 @@ gdb_test "print 'I::h'" "\\$\[0-9\].* = 14" "print I::h"
setup_kfail "gdb/829"
gdb_test "print j" "\\$\[0-9\].* = 15" "print j"
setup_kfail "gdb/829"
-gdb_test "print 'L::k'" "\\$\[0-9\].* = 16" "print L::k"
+gdb_test "print L::k" "\\$\[0-9\].* = 16" "print L::k"
setup_kfail "gdb/829"
gdb_test "print k" "No symbol \"k\" in current context." "print k"
setup_kfail "gdb/829"
gdb_test "print cdm" "\\$\[0-9\].* = 17" "print cdm"
setup_kfail "gdb/829"
-gdb_test "print 'Q::o'" "\\$\[0-9\].* = 18" "print Q::o"
+gdb_test "print Q::o" "\\$\[0-9\].* = 18" "print Q::o"
setup_kfail "gdb/829"
gdb_test "print o" "No symbol \"o\" in current context." "print o"
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index c4262d99016..787737cfe95 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -317,6 +317,7 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
case TYPE_CODE_MEMBER:
case TYPE_CODE_METHOD:
case TYPE_CODE_REF:
+ case TYPE_CODE_NAMESPACE:
error ("internal error: unhandled type in print_type_scalar");
break;
diff --git a/gdb/valops.c b/gdb/valops.c
index ce5faed3d59..bddb999529f 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3284,6 +3284,12 @@ value_namespace_elt (const struct type *curtype,
cp_free_usings (usings);
+ /* FIXME: carlton/2002-11-24: Should this really be here, or should
+ it be in c-exp.y like the other similar messages? Hmm... */
+
+ if (sym == NULL)
+ error ("No symbol \"%s\" in namespace \"%s\".", name, namespace_name);
+
return value_of_variable (sym, block);
}