public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
From: tromey@sourceware.org
To: archer-commits@sourceware.org
Subject: [SCM]  archer-tromey-python: gdb
Date: Thu, 06 Nov 2008 21:11:00 -0000	[thread overview]
Message-ID: <20081106211109.26129.qmail@sourceware.org> (raw)

The branch, archer-tromey-python has been updated
       via  6f0db4dff8d078bd334fc4f364adf0f792687dc1 (commit)
       via  f331e1ef50d42a6919c7c10f2983354b138b3cf0 (commit)
      from  95bc4ef80d85b793a2cc50d39db64f2e7abd8551 (commit)

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

- Log -----------------------------------------------------------------
commit 6f0db4dff8d078bd334fc4f364adf0f792687dc1
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Nov 6 14:09:53 2008 -0700

    gdb
    	* python/python.c (source_python_script): New function.
    	* python/python.h (source_python_script): Declare.
    	* cli/cli-cmds.c (find_argument): New function.
    	(source_command): Always run cleanup.  Use find_argument.  Handle
    	-p argument.  Use make_cleanup_restore_integer.
    	(source_verbose_cleanup): Remove.
    	(source_python): New global.
    	Include python.h.
    	(init_cli_cmds): Update.
    gdb/doc
    	* gdb.texinfo (File Options): Document -x on .py files.
    	(Command Files): Document source -p.

commit f331e1ef50d42a6919c7c10f2983354b138b3cf0
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu Nov 6 13:23:31 2008 -0700

    	* python/python.c (GdbMethods): Make conditional.

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

Summary of changes:
 gdb/ChangeLog       |   16 +++++++++++
 gdb/cli/cli-cmds.c  |   70 +++++++++++++++++++++++++++++++++++++-------------
 gdb/doc/ChangeLog   |    5 +++
 gdb/doc/gdb.texinfo |   13 +++++++--
 gdb/python/python.c |   18 +++++++++++++
 gdb/python/python.h |    2 +
 6 files changed, 103 insertions(+), 21 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9333dcf..210f2af 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,21 @@
 2008-11-06  Tom Tromey  <tromey@redhat.com>
 
+	* python/python.c (source_python_script): New function.
+	* python/python.h (source_python_script): Declare.
+	* cli/cli-cmds.c (find_argument): New function.
+	(source_command): Always run cleanup.  Use find_argument.  Handle
+	-p argument.  Use make_cleanup_restore_integer.
+	(source_verbose_cleanup): Remove.
+	(source_python): New global.
+	Include python.h.
+	(init_cli_cmds): Update.
+
+2008-11-06  Tom Tromey  <tromey@redhat.com>
+
+	* python/python.c (GdbMethods): Make conditional.
+
+2008-11-06  Tom Tromey  <tromey@redhat.com>
+
 	* varobj.c (struct varobj) <constructor>: New field.
 	(varobj_set_display_format): Update.
 	(varobj_get_display_hint): Likewise.
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index d9d2c56..92a59a3 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -45,6 +45,8 @@
 #include "cli/cli-setshow.h"
 #include "cli/cli-cmds.h"
 
+#include "python/python.h"
+
 #ifdef TUI
 #include "tui/tui.h"		/* For tui_active et.al.   */
 #endif
@@ -178,6 +180,7 @@ struct cmd_list_element *showchecklist;
 
 /* Command tracing state.  */
 
+static int source_python = 0;
 int source_verbose = 0;
 int trace_commands = 0;
 \f
@@ -437,6 +440,7 @@ source_script (char *file, int from_tty)
   struct cleanup *old_cleanups;
   char *full_pathname = NULL;
   int fd;
+  int is_python;
 
   if (file == NULL || *file == 0)
     {
@@ -465,8 +469,16 @@ source_script (char *file, int from_tty)
 	return;
     }
 
+  is_python = source_python;
+  if (strlen (file) > 3 && !strcmp (&file[strlen (file) - 3], ".py"))
+    is_python = 1;
+
   stream = fdopen (fd, FOPEN_RT);
-  script_from_file (stream, file);
+
+  if (is_python)
+    source_python_script (stream, file);
+  else
+    script_from_file (stream, file);
 
   do_cleanups (old_cleanups);
 }
@@ -480,15 +492,30 @@ source_verbose_cleanup (void *old_value)
   xfree (old_value);
 }
 
+/* A helper for source_command.  Look for an argument in *ARGS.
+   Update *ARGS by stripping leading whitespace.  If an argument is
+   found, return it (a character).  Otherwise, return 0.  */
+static int
+find_argument (char **args)
+{
+  int result = 0;
+  while (isspace ((*args)[0]))
+    ++*args;
+  if ((*args)[0] == '-' && isalpha ((*args)[1]))
+    {
+      result = (*args)[1];
+      *args += 3;
+    }
+  return result;
+}
+
 static void
 source_command (char *args, int from_tty)
 {
   struct cleanup *old_cleanups;
-  char *file = args;
-  int *old_source_verbose = xmalloc (sizeof(int));
 
-  *old_source_verbose = source_verbose;
-  old_cleanups = make_cleanup (source_verbose_cleanup, old_source_verbose);
+  old_cleanups = make_cleanup_restore_integer (&source_verbose);
+  make_cleanup_restore_integer (&source_python);
 
   /* -v causes the source command to run in verbose mode.
      We still have to be able to handle filenames with spaces in a
@@ -496,23 +523,28 @@ source_command (char *args, int from_tty)
 
   if (args)
     {
-      /* Make sure leading white space does not break the comparisons.  */
-      while (isspace(args[0]))
-	args++;
-
-      /* Is -v the first thing in the string?  */
-      if (args[0] == '-' && args[1] == 'v' && isspace (args[2]))
+      while (1)
 	{
-	  source_verbose = 1;
-
-	  /* Trim -v and whitespace from the filename.  */
-	  file = &args[3];
-	  while (isspace (file[0]))
-	    file++;
+	  int arg = find_argument (&args);
+	  if (!arg)
+	    break;
+	  switch (arg)
+	    {
+	    case 'v':
+	      source_verbose = 1;
+	      break;
+	    case 'p':
+	      source_python = 1;
+	      break;
+	    default:
+	      error (_("unrecognized option -%c"), arg);
+	    }
 	}
     }
 
-  source_script (file, from_tty);
+  source_script (args, from_tty);
+
+  do_cleanups (old_cleanups);
 }
 
 
@@ -1274,6 +1306,8 @@ Commands defined in this way may have up to ten arguments."));
 Read commands from a file named FILE.\n\
 Optional -v switch (before the filename) causes each command in\n\
 FILE to be echoed as it is executed.\n\
+Optional -p switch (before the filename) causes FILE to be evaluated\n\
+as Python code.\n\
 Note that the file \"%s\" is read automatically in this way\n\
 when GDB is started."), gdbinit);
   c = add_cmd ("source", class_support, source_command,
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 9d45150..a25df37 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,5 +1,10 @@
 2008-11-06  Tom Tromey  <tromey@redhat.com>
 
+	* gdb.texinfo (File Options): Document -x on .py files.
+	(Command Files): Document source -p.
+
+2008-11-06  Tom Tromey  <tromey@redhat.com>
+
 	* gdb.texinfo (Pretty Printing): Update.
 	(GDB/MI Variable Objects): Likewise.
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 071c912..a7038b5 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -962,8 +962,10 @@ Connect to process ID @var{number}, as with the @code{attach} command.
 @itemx -x @var{file}
 @cindex @code{--command}
 @cindex @code{-x}
-Execute @value{GDBN} commands from file @var{file}.  @xref{Command
-Files,, Command files}.
+Execute commands from file @var{file}.  If @var{file} ends in
+@samp{.py}, then the file is evaluated as Python code.  If Python
+support is not enabled in this @value{GDBN}, then an error occurs.
+@xref{Command Files,, Command files}.
 
 @item -eval-command @var{command}
 @itemx -ex @var{command}
@@ -17380,7 +17382,7 @@ command:
 @table @code
 @kindex source
 @cindex execute commands from a file
-@item source [@code{-v}] @var{filename}
+@item source [@code{-v}] [@code{-p}] @var{filename}
 Execute the command file @var{filename}.
 @end table
 
@@ -17397,6 +17399,11 @@ If @code{-v}, for verbose mode, is given then @value{GDBN} displays
 each command as it is executed.  The option must be given before
 @var{filename}, and is interpreted as part of the filename anywhere else.
 
+If @var{filename} ends in @samp{.py}, or if @code{-p}, for Python, is
+given then @value{GDBN} evaluates the contents of the file as Python
+code.  If Python support is not compiled in to @value{GDBN}, then an
+error occurs.
+
 Commands that would ask for confirmation if used interactively proceed
 without asking when used in a command file.  Many @value{GDBN} commands that
 normally print messages to say what they are doing omit the messages
diff --git a/gdb/python/python.c b/gdb/python/python.c
index d6cea7e..9f4448b 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -543,6 +543,13 @@ run_python_script (int argc, char **argv)
   exit (0);
 }
 
+void
+source_python_script (FILE *stream, char *file)
+{
+  PyRun_SimpleFile (stream, file);
+  fclose (stream);
+}
+
 \f
 
 /* The "current" objfile.  This is set when gdb detects that a new
@@ -1006,6 +1013,13 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
   return NULL;
 }
 
+void
+source_python_script (FILE *stream)
+{
+  fclose (stream);
+  error (_("Python scripting is not supported in this copy of GDB."));
+}
+
 #endif /* HAVE_PYTHON */
 
 \f
@@ -1175,6 +1189,8 @@ gdb._format_children = _format_children\n\
 
 \f
 
+#if HAVE_PYTHON
+
 static PyMethodDef GdbMethods[] =
 {
   { "get_value_from_history", gdbpy_get_value_from_history, METH_VARARGS,
@@ -1233,3 +1249,5 @@ Note: may later change to return an object." },
 
   {NULL, NULL, 0, NULL}
 };
+
+#endif /* HAVE_PYTHON */
diff --git a/gdb/python/python.h b/gdb/python/python.h
index bcba616..ef0560c 100644
--- a/gdb/python/python.h
+++ b/gdb/python/python.h
@@ -26,6 +26,8 @@ extern struct value *values_in_python;
 
 void eval_python_from_control_command (struct command_line *);
 
+void source_python_script (FILE *stream, char *file);
+
 void run_python_script (int argc, char **argv);
 
 char *apply_pretty_printer (struct value *, struct value **);


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


             reply	other threads:[~2008-11-06 21:11 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-06 21:11 tromey [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-04-07 20:28 tromey
2009-03-24 17:27 tromey
2009-02-05 19:56 tromey
2008-12-17 23:10 tromey
2008-12-15 22:38 tromey
2008-12-13  0:37 tromey
2008-12-12 23:54 tromey
2008-12-10 15:28 tromey
2008-12-09  0:33 tromey
2008-12-02 21:29 tromey
2008-12-01 19:10 tromey
2008-11-25 21:17 tromey
2008-11-21 18:25 tromey
2008-11-18 18:52 tromey
2008-11-18 15:54 tromey
2008-11-17 15:45 tromey
2008-11-16 22:18 tromey
2008-11-16 16:56 tromey
2008-11-12  1:54 tromey
2008-11-10 14:15 tromey
2008-11-06 19:58 tromey
2008-10-23 22:27 tromey
2008-10-23 21:28 tromey
2008-10-22 18:18 tromey
2008-10-21 18:32 tromey

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=20081106211109.26129.qmail@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=archer-commits@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).