This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC]: Java tab completion


The attached patch adds support for tab completion for java symbols. There were two changes required. First of all, a set of special symbol characters was added. This is needed because java symbol entries are fully prototyped and make_symbol_completion_list is not prepared for this.

For example, ptype java.l<tab> should complete the various java.l* symbols. In the current model, make_symbol_completion_list backs up to the "." and tries to complete l*. This is completely meaningless as things that start with l like long etc.. are not valid. The same things applies when you try to set the breakpoint for main: e.g. b jmisc.m<tab> won't expand to jmisc.main(java.lang.String[]) which is needed to set the java main breakpoint. With the new patch, this is easy to do and saves a lot of hassle to start debugging the program. The same applies to expanding the myriad of system classes that begin with java.lang, etc..

The second part of the fix is that I had to remove "." from the list of word break characters for java. I do not know if there is any hidden repercussions of doing this, but there are no testsuite regressions. I think a similar thing should be done for C++ concerning ":" so completion of namespaces will work.

I don't know if I should also remove "(", or "," from the word-break characters. These characters also appear in prototypes in the symbol table and one could easily tab after them when dealing with member names having multiple prototypes.

I have added a new scenario to jmisc.exp to test completion of b jmisc.m<tab>
I noticed that the jmisc test-cases were failing on my RHEL3 system because they are currently expecting <init> to be found in the ptype of jmisc, but gdb appears to be doing the right thing and showing the constructor (jmisc()) so I included a fix for that in my gdb.java testsuite patch.


Ok to commit?

-- Jeff J.

2004-05-21 Jeff Johnston <jjohnstn@redhat.com>

	* language.h (language_special_symbol_chars): New prototype.
	(struct language_defn): Add new la_special_symbol_chars field.
	* language.c (language_special_symbol_chars): New function.
	(unknown_language_defn): Default NULL for special symbol chars.
	(auto_language_defn): Ditto.
	(local_language_defn): Ditto.
	* jv-lang.c (java_special_symbol_chars): New function.
	(java_word_break_characters): Ditto.
	(java_language_defn): Add java_special_symbol_chars and
	java_word_break_characters.
	* ada-lang.c (ada_language_defn): Default NULL for special
	symbol chars.
	* c-lang.c (c_language_defn): Ditto.
	(cplus_language_defn): Ditto.
	(asm_language_defn, minimal_language_defn): Ditto.
	* f-lang.c (f_language_defn): Ditto.
	* m2-lang.c (m2_language_defn): Ditto.
	* objc-lang.c (objc_language_defn): Ditto.
	* p-lang.c (pascal_language_defn): Ditto.
	* scm-lang.c (scm_language_defn): Ditto.
	* symtab.c (make_symbol_completion_list): Account for language
	specific special chars that may occur in symbols.

gdb/testsuite/ChangeLog:

2004-05-21 Jeff Johnston <jjohnstn@redhat.com>

	* gdb.java/jmisc.exp: Add java completion test for breaking at java
	main.  Also fix ptype jmisc test to expect the jmisc() constructor.
	* gdb.java/jmisc1.exp: Fix ptype jmisc test to expect constructor.
	* gdb.java/jmisc2.exp: Ditto.
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.35
diff -u -p -r1.35 ada-lang.c
--- ada-lang.c	23 Jan 2004 23:03:28 -0000	1.35
+++ ada-lang.c	21 May 2004 19:23:10 -0000
@@ -8037,6 +8037,7 @@ const struct language_defn ada_language_
   0,				/* String lower bound (FIXME?) */
   &builtin_type_ada_char,
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
Index: c-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/c-lang.c,v
retrieving revision 1.27
diff -u -p -r1.27 c-lang.c
--- c-lang.c	10 Apr 2004 22:10:00 -0000	1.27
+++ c-lang.c	21 May 2004 19:23:10 -0000
@@ -568,6 +568,7 @@ const struct language_defn c_language_de
   0,				/* String lower bound */
   &builtin_type_char,		/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
@@ -627,6 +628,7 @@ const struct language_defn cplus_languag
   0,				/* String lower bound */
   &builtin_type_char,		/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
@@ -663,6 +665,7 @@ const struct language_defn asm_language_
   0,				/* String lower bound */
   &builtin_type_char,		/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
@@ -704,6 +707,7 @@ const struct language_defn minimal_langu
   0,				/* String lower bound */
   &builtin_type_char,		/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
Index: f-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/f-lang.c,v
retrieving revision 1.23
diff -u -p -r1.23 f-lang.c
--- f-lang.c	10 Apr 2004 22:10:00 -0000	1.23
+++ f-lang.c	21 May 2004 19:23:10 -0000
@@ -487,6 +487,7 @@ const struct language_defn f_language_de
   1,				/* String lower bound */
   &builtin_type_f_character,	/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.30
diff -u -p -r1.30 jv-lang.c
--- jv-lang.c	10 Apr 2004 22:10:00 -0000	1.30
+++ jv-lang.c	21 May 2004 19:23:10 -0000
@@ -60,6 +60,8 @@ static char *get_java_utf8_name (struct 
 static int java_class_is_primitive (struct value *clas);
 static struct value *java_value_string (char *ptr, int len);
 
+static char *java_special_symbol_chars (void);
+
 static void java_emit_char (int c, struct ui_file * stream, int quoter);
 
 /* This objfile contains symtabs that have been dynamically created
@@ -975,7 +977,17 @@ static char *java_demangle (const char *
   return cplus_demangle (mangled, options | DMGL_JAVA);
 }
 
+static char *java_special_symbol_chars (void)
+{
+  return ".()[],";
+}
 
+static char *
+java_word_break_characters (void)
+{ 
+  return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/><,-";
+} 
+  
 /* Table mapping opcodes into strings for printing operators
    and precedences of the operators.  */
 
@@ -1057,7 +1069,8 @@ const struct language_defn java_language
   0,				/* not c-style arrays */
   0,				/* String lower bound */
   &builtin_type_char,		/* Type of string elements */
-  default_word_break_characters,
+  java_word_break_characters,
+  java_special_symbol_chars,
   LANG_MAGIC
 };
 
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.44
diff -u -p -r1.44 language.c
--- language.c	10 Apr 2004 22:10:00 -0000	1.44
+++ language.c	21 May 2004 19:23:10 -0000
@@ -1176,6 +1176,17 @@ language_demangle (const struct language
   return NULL;
 }
 
+/* Return a string containing the list of special characters
+   used in symbol entries.  The default is an empty string.  */
+
+char *
+language_special_symbol_chars (const struct language_defn *curr_lang)
+{
+  if (current_language != NULL && current_language->la_special_symbol_chars)
+    return current_language->la_special_symbol_chars ();
+  return "";
+}
+
 /* Return the default string containing the list of characters
    delimiting words.  This is a reasonable default value that
    most languages should be able to use.  */
@@ -1301,6 +1312,7 @@ const struct language_defn unknown_langu
   0,				/* String lower bound */
   &builtin_type_char,		/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
@@ -1338,6 +1350,7 @@ const struct language_defn auto_language
   0,				/* String lower bound */
   &builtin_type_char,		/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
@@ -1374,6 +1387,7 @@ const struct language_defn local_languag
   0,				/* String lower bound */
   &builtin_type_char,		/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
Index: language.h
===================================================================
RCS file: /cvs/src/src/gdb/language.h,v
retrieving revision 1.26
diff -u -p -r1.26 language.h
--- language.h	10 Apr 2004 22:10:01 -0000	1.26
+++ language.h	21 May 2004 19:23:10 -0000
@@ -281,6 +281,9 @@ struct language_defn
     /* The list of characters forming word boundaries.  */
     char *(*la_word_break_characters) (void);
 
+    /* The list of special characters in symbol entries.  */
+    char *(*la_special_symbol_chars) (void);
+
     /* Add fields above this point, so the magic number is always last. */
     /* Magic number for compat checking */
 
@@ -515,6 +518,9 @@ extern CORE_ADDR skip_language_trampolin
 /* Return demangled language symbol, or NULL.  */
 extern char *language_demangle (const struct language_defn *current_language, 
 				const char *mangled, int options);
+
+/* Special characters in symbol entries.  */
+extern char *language_special_symbol_chars (const struct language_defn *curr_lang);
 
 /* Splitting strings into words.  */
 extern char *default_word_break_characters (void);
Index: m2-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/m2-lang.c,v
retrieving revision 1.16
diff -u -p -r1.16 m2-lang.c
--- m2-lang.c	10 Apr 2004 22:10:01 -0000	1.16
+++ m2-lang.c	21 May 2004 19:23:10 -0000
@@ -440,6 +440,7 @@ const struct language_defn m2_language_d
   0,				/* String lower bound */
   &builtin_type_m2_char,	/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
Index: objc-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/objc-lang.c,v
retrieving revision 1.35
diff -u -p -r1.35 objc-lang.c
--- objc-lang.c	10 Apr 2004 22:10:01 -0000	1.35
+++ objc-lang.c	21 May 2004 19:23:10 -0000
@@ -684,6 +684,7 @@ const struct language_defn objc_language
   0,				/* String lower bound */
   &builtin_type_char,		/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
Index: p-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/p-lang.c,v
retrieving revision 1.18
diff -u -p -r1.18 p-lang.c
--- p-lang.c	10 Apr 2004 22:09:59 -0000	1.18
+++ p-lang.c	21 May 2004 19:23:10 -0000
@@ -476,6 +476,7 @@ const struct language_defn pascal_langua
   0,				/* String lower bound */
   &builtin_type_char,		/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
Index: scm-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/scm-lang.c,v
retrieving revision 1.23
diff -u -p -r1.23 scm-lang.c
--- scm-lang.c	10 Apr 2004 22:10:01 -0000	1.23
+++ scm-lang.c	21 May 2004 19:23:10 -0000
@@ -275,6 +275,7 @@ const struct language_defn scm_language_
   0,				/* String lower bound */
   &builtin_type_char,		/* Type of string elements */
   default_word_break_characters,
+  NULL,				/* Special symbol chars.  */
   LANG_MAGIC
 };
 
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.130
diff -u -p -r1.130 symtab.c
--- symtab.c	20 May 2004 09:51:33 -0000	1.130
+++ symtab.c	21 May 2004 19:23:11 -0000
@@ -3441,9 +3441,13 @@ make_symbol_completion_list (char *text,
       {
 	/* It is not a quoted string.  Break it based on the characters
 	   which are in symbols.  */
+	char *special_symbol_chars = language_special_symbol_chars (current_language);
 	while (p > text)
 	  {
 	    if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
+	      --p;
+	    else if (special_symbol_chars[0] != '\0'
+		     && strchr (special_symbol_chars, p[-1]))
 	      --p;
 	    else
 	      break;
Index: gdb.java/jmisc.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.java/jmisc.exp,v
retrieving revision 1.3
diff -u -p -r1.3 jmisc.exp
--- gdb.java/jmisc.exp	24 Feb 2004 16:09:48 -0000	1.3
+++ gdb.java/jmisc.exp	21 May 2004 19:56:59 -0000
@@ -68,11 +68,34 @@ gdb_test "set print sevenbit-strings" ".
 if ![set_lang_java] then {
     # Ref PR gdb:java/1565.  Don't use the simpler "break jmisc.main".
     # As of 2004-02-24 it wasn't working and is being tested separatly.
-    runto "\'${testfile}.main(java.lang.String\[\])\'"
+
+    # Test completion of main entry point.  
+    send_gdb "b jmisc.m\t"
+    sleep 1
+    gdb_expect {
+	-re "^b jmisc.main\\(java.lang.String\\\[]\\) $"
+	  { send_gdb "\n"
+             gdb_expect {
+		-re ".*Breakpoint.*at.*jmisc.java.*$gdb_prompt $"
+		 	{ pass "complete b 'jmisc.m'" }
+		-re ".*$gdb_prompt $" { fail "complete 'b jmisc.m'"}
+		timeout { fail "complete 'b jmisc.m'" }
+             }
+	  }
+        timeout { fail "complete 'b jmisc.m'" }
+    }
+
+    send_gdb "run\n"
+    gdb_expect {   
+	-re ".*Breakpoint.*jmisc\.main\\(java\.lang\.String\\\[]\\).*$gdb_prompt $" 
+	  { pass "runto main" }
+	-re ".*$gdb_prompt $"  { fail "runto main" }
+	timeout { fail "runto main" }
+    }
 
     send_gdb "ptype jmisc\n"   
     gdb_expect {   
-	-re "type = class jmisc  extends java.lang.Object \{\[\r\n\ \t]+void main\\(java\.lang\.String\\\[]\\);\[\r\n\ \t]+void <init>\\(void\\);\[\r\n\ \t]+\}\[\r\n\ \t]+$gdb_prompt $"               { pass "ptype jmisc" }
+	-re "type = class jmisc  extends java.lang.Object \{\[\r\n\ \t]+void main\\(java\.lang\.String\\\[]\\);\[\r\n\ \t]+jmisc\\(\\);\[\r\n\ \t]+\}\[\r\n\ \t]+$gdb_prompt $"               { pass "ptype jmisc" }
 	-re ".*$gdb_prompt $"             { fail "ptype jmisc" }
 	timeout { fail "ptype jmisc (timeout)" ; return }
     }
Index: gdb.java/jmisc1.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.java/jmisc1.exp,v
retrieving revision 1.2
diff -u -p -r1.2 jmisc1.exp
--- gdb.java/jmisc1.exp	14 Aug 2003 19:11:10 -0000	1.2
+++ gdb.java/jmisc1.exp	21 May 2004 19:56:59 -0000
@@ -70,7 +70,7 @@ if ![set_lang_java] then {
 
     send_gdb "ptype jmisc\n"   
     gdb_expect {   
-	-re "type = class jmisc  extends java.lang.Object \{\[\r\n\ \t]+void main\\(java\.lang\.String\\\[]\\);\[\r\n\ \t]+void <init>\\(void\\);\[\r\n\ \t]+\}\[\r\n\ \t]+$gdb_prompt $"               { pass "ptype jmisc" }
+	-re "type = class jmisc  extends java.lang.Object \{\[\r\n\ \t]+void main\\(java\.lang\.String\\\[]\\);\[\r\n\ \t]+jmisc\\(\\);\[\r\n\ \t]+\}\[\r\n\ \t]+$gdb_prompt $"               { pass "ptype jmisc" }
 	-re ".*$gdb_prompt $"             { fail "ptype jmisc" }
 	timeout { fail "ptype jmisc (timeout)" ; return }
     }
Index: gdb.java/jmisc2.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.java/jmisc2.exp,v
retrieving revision 1.1
diff -u -p -r1.1 jmisc2.exp
--- gdb.java/jmisc2.exp	29 Apr 2002 21:33:03 -0000	1.1
+++ gdb.java/jmisc2.exp	21 May 2004 19:56:59 -0000
@@ -68,7 +68,7 @@ gdb_test "set print sevenbit-strings" ".
 if ![set_lang_java] then {
     send_gdb "ptype jmisc\n"   
     gdb_expect {   
-	-re "type = class jmisc  extends java.lang.Object \{\[\r\n\ \t]+void main\\(java\.lang\.String\\\[]\\);\[\r\n\ \t]+void <init>\\(void\\);\[\r\n\ \t]+\}\[\r\n\ \t]+$gdb_prompt $"               { pass "ptype jmisc" }
+	-re "type = class jmisc  extends java.lang.Object \{\[\r\n\ \t]+void main\\(java\.lang\.String\\\[]\\);\[\r\n\ \t]+jmisc\\(\\);\[\r\n\ \t]+\}\[\r\n\ \t]+$gdb_prompt $"               { pass "ptype jmisc" }
 	-re ".*$gdb_prompt $"             { fail "ptype jmisc" }
 	timeout { fail "ptype jmisc (timeout)" ; return }
     }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]