Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Bob Rossi <bob_rossi@cox.net>
To: gdb-patches@sources.redhat.com
Subject: starting gdb/mi from FE
Date: Mon, 05 Jun 2006 13:45:00 -0000	[thread overview]
Message-ID: <20060605134517.GA25925@brasko.net> (raw)

[-- 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

             reply	other threads:[~2006-06-05 13:45 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-05 13:45 Bob Rossi [this message]
2006-06-05 19:56 ` Eli Zaretskii
2006-06-05 19:58   ` Bob Rossi
2006-06-05 20:23     ` Eli Zaretskii
2006-06-05 21:25   ` Daniel Jacobowitz
2006-06-05 21:28     ` Bob Rossi
2006-06-06  3:44     ` Eli Zaretskii
2006-06-05 19:59 ` Daniel Jacobowitz
2006-06-05 20:49   ` Bob Rossi
2006-06-06  0:55 Nick Roberts
2006-06-06  1:20 ` Daniel Jacobowitz
2006-06-06  1:56   ` Bob Rossi
2006-06-06  3:16     ` Daniel Jacobowitz
2006-06-06  2:03   ` Nick Roberts
2006-06-06  2:04     ` Bob Rossi
2006-06-06 17:22     ` Jim Ingham
2006-06-06 17:30       ` Daniel Jacobowitz
2006-06-06 17:41         ` Jim Ingham
2006-06-06  1:33 ` Bob Rossi
2006-06-06  1:56   ` Nick Roberts
2006-06-06  2:01     ` Bob Rossi
2006-06-06  2:30       ` Nick Roberts

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=20060605134517.GA25925@brasko.net \
    --to=bob_rossi@cox.net \
    --cc=gdb-patches@sources.redhat.com \
    /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