public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-multi-breakpoint-2: Implement prompt substitutions
@ 2010-12-20 21:30 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2010-12-20 21:30 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-multi-breakpoint-2 has been updated
       via  04be0f69606a6dc3c72242407b518e083bd80251 (commit)
       via  e372499ce5eb5c5467fe2058e77fbbe5306d90e7 (commit)
       via  7e3d874a1d76af982fe5843bfd0437b7433c30e4 (commit)
       via  60ab8235caad50831d995620291bfca2a7cb79a6 (commit)
       via  b3b9e9cf3dca5882002549b388d9fe88b075876c (commit)
       via  ffa7cb28dedf94aa326f4165133506805424b6ba (commit)
       via  9be4b0d2cc6b15b70fc036c50999c74e507290b3 (commit)
       via  08ba31f6f2a3412185f8abf8f815c2bb2404e293 (commit)
       via  780c0b463247d1ab8e35c028f23fb6536e16d3c6 (commit)
       via  2c1849ef67d28ff04e074a86b1116ac6282e2ca5 (commit)
       via  65da0d279139c947663d9bbb332871668447395b (commit)
       via  aeb1d0e16a16fce756f50e40bac2c77d09a5ebe5 (commit)
       via  d96454914173e99781679779026295b6c53df843 (commit)
       via  c12476e13194bfe8eeda21b0c577459bb9cb394f (commit)
       via  85095b29c0c7efacf813f7476e27c95992e914e3 (commit)
      from  72bd01751b6503f769a7a2f59dd24865075ed8ad (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 04be0f69606a6dc3c72242407b518e083bd80251
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Dec 20 14:07:45 2010 -0700

    Implement prompt substitutions

commit e372499ce5eb5c5467fe2058e77fbbe5306d90e7
Merge: 72bd017 7e3d874
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Dec 20 10:30:25 2010 -0700

    Merge remote branch 'origin/archer-swagiaal-oguz' into archer-tromey-multi-breakpoint-2
    
    Probably does not quite work, waiting for another small event change
    
    Conflicts:
    	gdb/python/py-event.c
    	gdb/python/py-event.h
    	gdb/python/py-inferior.c

-----------------------------------------------------------------------

Summary of changes:
 gdb/Makefile.in                                |   22 ++-
 gdb/data-directory/Makefile.in                 |    4 +-
 gdb/doc/observer.texi                          |    5 +-
 gdb/event-top.c                                |    6 +-
 gdb/python/lib/gdb/__init__.py                 |    1 +
 gdb/python/lib/gdb/command/prompt.py           |   34 +++++
 gdb/python/lib/gdb/prompt.py                   |   99 ++++++++++++++
 gdb/python/py-breakpointevent.c                |   59 ++++++++
 gdb/python/py-breakpointstopevent.c            |  128 ------------------
 gdb/python/py-continueevent.c                  |   64 +--------
 gdb/python/py-event.c                          |  161 +++++-----------------
 gdb/python/py-event.h                          |   93 ++++++++++---
 gdb/python/py-eventregistry.c                  |    3 +
 gdb/python/py-events.c                         |  156 ++++++++++++++++++++++
 gdb/python/{py-event.h => py-events.h}         |   32 ++----
 gdb/python/py-exitedevent.c                    |   91 ++-----------
 gdb/python/py-inferior.c                       |  169 +++++++-----------------
 gdb/python/py-signalevent.c                    |   59 ++++++++
 gdb/python/py-signalstopevent.c                |  122 -----------------
 gdb/python/py-stopevent.c                      |  101 ++-------------
 gdb/python/py-stopevent.h                      |   32 +----
 gdb/python/python-internal.h                   |    5 +-
 gdb/python/python.c                            |   43 ++++++-
 gdb/testsuite/gdb.python/py-events-threads.exp |    4 +
 gdb/testsuite/gdb.python/py-events.py          |   16 ++-
 25 files changed, 698 insertions(+), 811 deletions(-)
 create mode 100644 gdb/python/lib/gdb/command/prompt.py
 create mode 100644 gdb/python/lib/gdb/prompt.py
 create mode 100644 gdb/python/py-breakpointevent.c
 delete mode 100644 gdb/python/py-breakpointstopevent.c
 create mode 100644 gdb/python/py-events.c
 copy gdb/python/{py-event.h => py-events.h} (58%)
 create mode 100644 gdb/python/py-signalevent.c
 delete mode 100644 gdb/python/py-signalstopevent.c

First 500 lines of diff:
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index fb687a8..c299f3d 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -273,11 +273,12 @@ SUBDIR_PYTHON_OBS = \
 	py-auto-load.o \
 	py-block.o \
 	py-breakpoint.o \
-	py-breakpointstopevent.o \
+	py-breakpointevent.o \
 	py-cmd.o \
 	py-continueevent.o \
 	py-event.o \
 	py-eventregistry.o \
+	py-events.o \
 	py-exitedevent.o \
 	py-frame.o \
 	py-function.o \
@@ -288,7 +289,7 @@ SUBDIR_PYTHON_OBS = \
 	py-param.o \
 	py-prettyprint.o \
 	py-progspace.o \
-	py-signalstopevent.o \
+	py-signalevent.o \
 	py-stopevent.o \
 	py-symbol.o \
 	py-symtab.o \
@@ -301,11 +302,12 @@ SUBDIR_PYTHON_SRCS = \
 	python/py-auto-load.c \
 	python/py-block.c \
 	python/py-breakpoint.c \
-	python/py-breakpointstopevent.c \
+	python/py-breakpointevent.c \
 	python/py-cmd.c \
 	python/py-continueevent.c \
 	python/py-event.c \
 	python/py-eventregistry.c \
+	python/py-events.c \
 	python/py-exitedevent.c \
 	python/py-frame.c \
 	python/py-function.c \
@@ -316,7 +318,7 @@ SUBDIR_PYTHON_SRCS = \
 	python/py-param.c \
 	python/py-prettyprint.c \
 	python/py-progspace.c \
-	python/py-signalstopevent.c \
+	python/py-signalevent.c \
 	python/py-stopevent.c \
 	python/py-symbol.c \
 	python/py-symtab.c \
@@ -2015,8 +2017,8 @@ py-breakpoint.o: $(srcdir)/python/py-breakpoint.c
 	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-breakpoint.c
 	$(POSTCOMPILE)
 
-py-breakpointstopevent.o: $(srcdir)/python/py-breakpointstopevent.c
-	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-breakpointstopevent.c
+py-breakpointevent.o: $(srcdir)/python/py-breakpointevent.c
+	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-breakpointevent.c
 	$(POSTCOMPILE)
 
 py-cmd.o: $(srcdir)/python/py-cmd.c
@@ -2035,6 +2037,10 @@ py-eventregistry.o: $(srcdir)/python/py-eventregistry.c
 	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-eventregistry.c
 	$(POSTCOMPILE)
 
+py-events.o: $(srcdir)/python/py-events.c
+	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-events.c
+	$(POSTCOMPILE)
+
 py-exitedevent.o: $(srcdir)/python/py-exitedevent.c
 	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-exitedevent.c
 	$(POSTCOMPILE)
@@ -2075,8 +2081,8 @@ py-progspace.o: $(srcdir)/python/py-progspace.c
 	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-progspace.c
 	$(POSTCOMPILE)
 
-py-signalstopevent.o: $(srcdir)/python/py-signalstopevent.c
-	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-signalstopevent.c
+py-signalevent.o: $(srcdir)/python/py-signalevent.c
+	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/py-signalevent.c
 	$(POSTCOMPILE)
 
 py-stopevent.o: $(srcdir)/python/py-stopevent.c
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
index 4cbb457..221f3e4 100644
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
@@ -56,9 +56,11 @@ PYTHON_FILES = \
 	gdb/printing.py \
 	gdb/inferior.py \
 	gdb/iset.py \
+	gdb/prompt.py \
 	gdb/command/__init__.py \
 	gdb/command/multi.py \
-	gdb/command/pretty_printers.py
+	gdb/command/pretty_printers.py \
+	gdb/command/prompt.py
 
 FLAGS_TO_PASS = \
 	"prefix=$(prefix)" \
diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
index e19b8ed..6c03193 100644
--- a/gdb/doc/observer.texi
+++ b/gdb/doc/observer.texi
@@ -223,8 +223,11 @@ Bytes from @var{data} to @var{data} + @var{len} have been written
 to the current inferior at @var{addr}.
 @end deftypefun
 
+@deftypefun void before_prompt (void)
+Called before a top-level prompt is displayed.
+@end deftypefun
+
 @deftypefun void test_notification (int @var{somearg})
 This observer is used for internal testing.  Do not use.  
 See testsuite/gdb.gdb/observer.exp.
 @end deftypefun
-
diff --git a/gdb/event-top.c b/gdb/event-top.c
index a49bddb..fc07a1f 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -33,6 +33,7 @@
 #include "cli/cli-script.h"     /* for reset_command_nest_depth */
 #include "main.h"
 #include "gdbthread.h"
+#include "observer.h"
 
 /* For dont_repeat() */
 #include "gdbcmd.h"
@@ -259,7 +260,7 @@ void
 display_gdb_prompt (char *new_prompt)
 {
   int prompt_length = 0;
-  char *gdb_prompt = get_prompt ();
+  char *gdb_prompt;
 
   /* Reset the nesting depth used when trace-commands is set.  */
   reset_command_nest_depth ();
@@ -269,6 +270,9 @@ display_gdb_prompt (char *new_prompt)
   if (!current_interp_display_prompt_p ())
     return;
 
+  observer_notify_before_prompt ();
+  gdb_prompt = get_prompt ();
+
   if (sync_execution && is_running (inferior_ptid))
     {
       /* This is to trick readline into not trying to display the
diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index 98abbcd..0f78c74 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -15,5 +15,6 @@
 
 import gdb.command.pretty_printers
 import gdb.command.multi
+import gdb.command.prompt
 
 gdb.command.pretty_printers.register_pretty_printer_commands()
diff --git a/gdb/python/lib/gdb/command/prompt.py b/gdb/python/lib/gdb/command/prompt.py
new file mode 100644
index 0000000..6a56a3b
--- /dev/null
+++ b/gdb/python/lib/gdb/command/prompt.py
@@ -0,0 +1,34 @@
+# Extended prompt.
+# Copyright (C) 2010 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import gdb
+import gdb.prompt
+
+class _ExtendedPrompt(gdb.Parameter):
+
+    def __init__(self):
+        super(_ExtendedPrompt, self).__init__("extended-prompt",
+                                              gdb.COMMAND_SUPPORT,
+                                              gdb.PARAM_STRING_NOESCAPE)
+        gdb.events.before_prompt.connect (self.before_prompt_hook)
+        self.value = gdb.parameter('prompt').replace('\\', '\\\\')
+
+    def before_prompt_hook(self, event):
+        newprompt = gdb.prompt.substitute_prompt(self.value)
+        newprompt = newprompt.replace('\\', '\\\\')
+        gdb.execute('set prompt ' + newprompt)
+
+_ExtendedPrompt()
diff --git a/gdb/python/lib/gdb/prompt.py b/gdb/python/lib/gdb/prompt.py
new file mode 100644
index 0000000..8e6f545
--- /dev/null
+++ b/gdb/python/lib/gdb/prompt.py
@@ -0,0 +1,99 @@
+# Extended prompt utilities.
+# Copyright (C) 2010 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import gdb
+import os
+
+def _prompt_pwd(ignore):
+    return os.getcwdu()
+
+def _prompt_object_attr(func, what, attr, nattr):
+    if attr is None:
+        attr = nattr
+    try:
+        obj = func()
+    except gdb.error:
+        return '<no %s>' % what
+    if hasattr(obj, attr):
+        result = getattr(obj, attr)
+        if callable(result):
+            result = result()
+        return result
+    else:
+        return '<no attribute %s on current %s>' % (attr, what)
+
+def _prompt_frame(attr):
+    return _prompt_object_attr(gdb.selected_frame, 'frame', attr, 'name')
+
+def _prompt_thread(attr):
+    return _prompt_object_attr(gdb.selected_thread, 'thread', attr, 'num')
+
+def _prompt_inferior(attr):
+    return _prompt_object_attr(gdb.selected_inferior, 'inferior', attr, 'num')
+
+prompt_substitutions = {
+    'e': '\033',
+    '\\': '\\',
+    'n': '\n',
+    'r': '\r',
+    'v': gdb.VERSION,
+    'w': _prompt_pwd,
+    'f': _prompt_frame,
+    'i': _prompt_inferior,
+    't': _prompt_thread,
+    'p': gdb.parameter
+    # '!': _prompt_where_history  # no API for this yet
+}
+
+def substitute_prompt(prompt):
+    result = ''
+    plen = len(prompt)
+    i = 0
+    while i < plen:
+        if prompt[i] == '\\':
+            i = i + 1
+            if i >= plen:
+                break
+            cmdch = prompt[i]
+
+            if cmdch in prompt_substitutions:
+                cmd = prompt_substitutions[cmdch]
+                if callable(cmd):
+                    if i + 1 < plen and prompt[i + 1] == '{':
+                        j = i + 1
+                        while j < plen and prompt[j] != '}':
+                            j = j + 1
+                        # Just ignore formatting errors.
+                        if j >= plen or prompt[j] != '}':
+                            arg = None
+                        else:
+                            arg = prompt[i + 2 : j]
+                            i = j
+                    else:
+                        arg = None
+                    result += str(cmd(arg))
+                else:
+                    result += str(cmd)
+            else:
+                # Unrecognized escapes are turned into the escaped
+                # character itself.
+                result += prompt[i]
+        else:
+            result += prompt[i]
+
+        i = i + 1
+
+    return result
diff --git a/gdb/python/py-breakpointevent.c b/gdb/python/py-breakpointevent.c
new file mode 100644
index 0000000..7601955
--- /dev/null
+++ b/gdb/python/py-breakpointevent.c
@@ -0,0 +1,59 @@
+/* Python interface to inferior breakpoint stop events.
+
+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "py-stopevent.h"
+
+static PyTypeObject breakpoint_event_object_type;
+
+static void
+breakpoint_evpy_dealloc (PyObject *self)
+{
+  Py_DECREF (((breakpoint_event_object *) self)->breakpoint);
+  stop_evpy_dealloc (self);
+}
+
+/* Create and initialize a BreakpointEvent object.  */
+
+breakpoint_event_object *
+create_breakpoint_event_object (struct bpstats *bs, thread_object *stopped_thread)
+{
+  breakpoint_event_object *breakpoint_event_obj =
+      (breakpoint_event_object *)
+      create_stop_event_object (&breakpoint_event_object_type,
+                                stopped_thread);
+
+  if (!breakpoint_event_obj)
+    return NULL;
+
+  breakpoint_event_obj->breakpoint = gdbpy_breakpoint_from_bpstats (bs);
+  Py_INCREF (breakpoint_event_obj->breakpoint);
+
+  evpy_add_attribute ((event_object *) breakpoint_event_obj,
+                      "breakpoint",
+                      (PyObject *) breakpoint_event_obj->breakpoint);
+
+  return breakpoint_event_obj;
+}
+
+PY_NEW_EVENT_TYPE (breakpoint,
+                   "gdb.BreakpointEvent",
+                   "BreakpointEvent",
+                   "GDB breakpoint stop event object",
+                   stop_event_object_type,
+                   static);
diff --git a/gdb/python/py-breakpointstopevent.c b/gdb/python/py-breakpointstopevent.c
deleted file mode 100644
index a635369..0000000
--- a/gdb/python/py-breakpointstopevent.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/* Python interface to inferior breakpoint stop events.
-
-   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#include "py-stopevent.h"
-
-static PyTypeObject breakpoint_stop_event_object_type;
-
-static void
-bp_stop_evpy_dealloc (PyObject *self)
-{
-  Py_DECREF (((breakpoint_stop_event_object *) self)->breakpoint);
-  stop_evpy_dealloc (self);
-}
-
-/* Create and initialize a BreakpointStopEvent object.  */
-
-breakpoint_stop_event_object *
-create_breakpoint_event_object (struct bpstats *bs, PyObject *stopped_thread)
-{
-  breakpoint_stop_event_object *breakpoint_stop_event_obj =
-      (breakpoint_stop_event_object *)
-      create_stop_event_object (&breakpoint_stop_event_object_type,
-                                BREAKPOINT);
-
-  if (!breakpoint_stop_event_obj)
-    return NULL;
-
-  breakpoint_stop_event_obj->stop_event.event.inferior_thread =
-        stopped_thread;
-
-  breakpoint_stop_event_obj->breakpoint = gdbpy_breakpoint_from_bpstats (bs);
-  Py_INCREF (breakpoint_stop_event_obj->breakpoint);
-
-  return breakpoint_stop_event_obj;
-}
-
-/* Python function to get the stop event's breakpoint.  */
-
-static PyObject *
-bp_stop_evpy_get_breakpoint (PyObject *self, void *closure)
-{
-  breakpoint_stop_event_object *breakpoint_stop_event_obj =
-    (breakpoint_stop_event_object *) self;
-
-  //FIXME: Where is this reference being freed ?
-  Py_INCREF (breakpoint_stop_event_obj->breakpoint);
-
-  return (PyObject *) (breakpoint_stop_event_obj->breakpoint);
-}
-
-/* Initialize the Python breakpoint stop event code.  */
-
-void
-gdbpy_initialize_breakpoint_stop_event (void)
-{
-  breakpoint_stop_event_object_type.tp_base = &stop_event_object_type;
-  if (PyType_Ready (&breakpoint_stop_event_object_type) < 0)
-    return;
-
-  Py_INCREF (&breakpoint_stop_event_object_type);
-  PyModule_AddObject (gdb_module, "BreakpointStopEvent",
-                      (PyObject *) &breakpoint_stop_event_object_type);
-}
-
-static PyGetSetDef breakpoint_stop_event_object_getset[] =
-{
-  { "breakpoint", bp_stop_evpy_get_breakpoint, NULL, "Breakpoint.", NULL },
-
-  { NULL } /* Sentinel. */
-};
-
-static PyTypeObject breakpoint_stop_event_object_type =
-{
-  PyObject_HEAD_INIT (NULL)
-  0,                                          /* ob_size */
-  "gdb.BreakpointStopEvent",                  /* tp_name */
-  sizeof (breakpoint_stop_event_object),      /* tp_basicsize */
-  0,                                          /* tp_itemsize */
-  bp_stop_evpy_dealloc,                       /* tp_dealloc */
-  0,                                          /* tp_print */
-  0,                                          /* tp_getattr */
-  0,                                          /* tp_setattr */
-  0,                                          /* tp_compare */
-  0,                                          /* tp_repr */
-  0,                                          /* tp_as_number */
-  0,                                          /* tp_as_sequence */
-  0,                                          /* tp_as_mapping */
-  0,                                          /* tp_hash  */
-  0,                                          /* tp_call */
-  0,                                          /* tp_str */
-  0,                                          /* tp_getattro */
-  0,                                          /* tp_setattro */
-  0,                                          /* tp_as_buffer */
-  Py_TPFLAGS_DEFAULT,                         /* tp_flags */
-  "GDB breakpoint stop event object",         /* tp_doc */
-  0,                                          /* tp_traverse */
-  0,                                          /* tp_clear */
-  0,                                          /* tp_richcompare */
-  0,                                          /* tp_weaklistoffset */
-  0,                                          /* tp_iter */
-  0,                                          /* tp_iternext */
-  0,                                          /* tp_methods */
-  0,                                          /* tp_members */
-  breakpoint_stop_event_object_getset,        /* tp_getset */
-  0,                                          /* tp_base */
-  0,                                          /* tp_dict */
-  0,                                          /* tp_descr_get */
-  0,                                          /* tp_descr_set */
-  0,                                          /* tp_dictoffset */


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-12-20 21:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-20 21:30 [SCM] archer-tromey-multi-breakpoint-2: Implement prompt substitutions tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).