starting gdb/mi from FE

Bob Rossi
2006-06-05T13:45:18Z

[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]

Hi,

I have an issue that will eventually come up in regards to starting GDB
from a front end. Choosing the correct interpreter that GDB supports
could be potentially non trivial, requiring several starts of GDB.
Currently, for each version of mi that the FE supports, it will have to
start GDB to see if it supports that version of the protocol. As the
list of MI protocol versions get's longer, this action get's longer and
longer. It would be good to solve this problem as early as possible for
obvious reasons.

Attached below is a patch that modified GDB so that it can accept the -i
flag as a comma sepearated list like shown below:

$ ./gdb/gdb -q -i=mi ./main
~"Using host libthread_db library \"/lib/tls/i686/cmov/libthread_db.so.1\".\n"
(gdb)

$ ./gdb/gdb -q -i=mi4,mi3 ./main
mi_protocol_version=mi3
~"Using host libthread_db library \"/lib/tls/i686/cmov/libthread_db.so.1\".\n"
(gdb)

This will allow the FE to start GDB 1 time and to determine which
version of the protocol GDB was compatible with. If you have multiple
interpreter choices on the -i switch, then GDB will output the first
line it writes as
mi_protocol_version=miN
where miN will be the version GDB is going to communicate with.

This change is backwards compatible because users were not able in the
past to have a comma separated list in the -i flag.

How does this look?

Thanks,
Bob Rossi

[-- Attachment #2: mi_protocol_ver.diff --]
[-- Type: text/plain, Size: 2098 bytes --]

Index: gdb/interps.c
===================================================================
RCS file: /cvs/src/src/gdb/interps.c,v
retrieving revision 1.16
diff -u -r1.16 interps.c
--- gdb/interps.c 17 Dec 2005 22:34:01 -0000 1.16
+++ gdb/interps.c 4 Jun 2006 23:54:14 -0000
@@ -216,16 +216,28 @@
interp_lookup (const char *name)
{
struct interp *interp;
+ char *nname = xstrdup (name);
+ char *token = strtok (nname, ",");

- if (name == NULL || strlen (name) == 0)
- return NULL;
-
- for (interp = interp_list; interp != NULL; interp = interp->next)
+ while (token)
{
- if (strcmp (interp->name, name) == 0)
- return interp;
+ if (token == NULL || strlen (token) == 0)
+ return NULL;
+
+ for (interp = interp_list; interp != NULL; interp = interp->next)
+ {
+ if (strcmp (interp->name, token) == 0)
+ {
+ xfree (nname);
+ nname = NULL;
+ return interp;
+ }
+ }
+ token = strtok (NULL, ",");
}

+ xfree (nname);
+ nname = NULL;
return NULL;
}

Index: gdb/main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.58
diff -u -r1.58 main.c
--- gdb/main.c 21 Feb 2006 19:46:48 -0000 1.58
+++ gdb/main.c 4 Jun 2006 23:54:15 -0000
@@ -598,6 +598,7 @@

{
/* Find it. */
+ int multiple_interps = (strchr (interpreter_p, ',') != 0);
struct interp *interp = interp_lookup (interpreter_p);
if (interp == NULL)
error (_("Interpreter `%s' unrecognized"), interpreter_p);
@@ -609,6 +610,17 @@
interpreter_p);
exit (1);
}
+
+ /* Print the mi version chosen by GDB if the user supplied multiple
+ options. Note that the interp_set call above replaces interpreter_p
+ with the value of the chosen interpreter. */
+ if (multiple_interps)
+ {
+ struct ui_file *raw_stdout = stdio_fileopen (stdout);
+
+ fprintf_unfiltered (raw_stdout, "mi_protocol_version=%s\n", interpreter_p);
+ }
+
}

/* FIXME: cagney/2003-02-03: The big hack (part 2 of 2) that lets