From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26226 invoked by alias); 6 Nov 2008 21:11:10 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 26147 invoked by uid 306); 6 Nov 2008 21:11:09 -0000 Date: Thu, 06 Nov 2008 21:11:00 -0000 Message-ID: <20081106211109.26129.qmail@sourceware.org> From: tromey@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] archer-tromey-python: gdb X-Git-Refname: refs/heads/archer-tromey-python X-Git-Reftype: branch X-Git-Oldrev: 95bc4ef80d85b793a2cc50d39db64f2e7abd8551 X-Git-Newrev: 6f0db4dff8d078bd334fc4f364adf0f792687dc1 X-SW-Source: 2008-q4/txt/msg00074.txt.bz2 List-Id: 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 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 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 + * 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 + + * python/python.c (GdbMethods): Make conditional. + +2008-11-06 Tom Tromey + * varobj.c (struct varobj) : 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; @@ -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 + * gdb.texinfo (File Options): Document -x on .py files. + (Command Files): Document source -p. + +2008-11-06 Tom Tromey + * 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); +} + /* 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 */ @@ -1175,6 +1189,8 @@ gdb._format_children = _format_children\n\ +#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.