From: Thiago Jung Bauermann <bauerman@br.ibm.com>
To: tromey@redhat.com
Cc: gdb-patches ml <gdb-patches@sourceware.org>
Subject: Re: [RFA][python] Fixes for existing Python code.
Date: Thu, 05 Feb 2009 16:43:00 -0000 [thread overview]
Message-ID: <1233852201.14735.85.camel@localhost.localdomain> (raw)
In-Reply-To: <m3pri0px4e.fsf@fleche.redhat.com>
El lun, 02-02-2009 a las 10:27 -0700, Tom Tromey escribió:
> >>>>> "Thiago" == Thiago Jung Bauermann <bauerman@br.ibm.com> writes:
> Thiago> This patch has some fixes for the Python code which is currently in.
> Thiago> They are the following:
> Thiago> - add from_tty argument to execute_gdb_command;
> Thiago> - fix error checking of function PyRun_SimpleString;
> Thiago> - reorganize python.c to minimize forward declarations;
> Thiago> - properly check Python booleans.
>
> The code bits are ok. Please wait for Eli to review the documentation
> before committing.
Eli had approved, so I committed this. Except for the boolean fix, which
went in the other patch which I committed earlier. Thanks!
--
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
gdb/
2009-02-05 Tom Tromey <tromey@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com>
* python/python.c (GdbMethods): Move to bottom of file.
(get_parameter, execute_gdb_command, gdbpy_write,
gdbpy_flush): Remove forward declarations.
(eval_python_from_control_command): Fix error checking of function
PyRun_SimpleString. Fix error string.
(python_command): Likewise.
(execute_gdb_command): Added from_tty argument.
gdb/doc/
2009-02-05 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Basic Python): Document execute's from_tty
argument.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 45cad64..2c6c2ea 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18078,11 +18078,15 @@ methods and classes added by @value{GDBN} are placed in this module.
use in all scripts evaluated by the @code{python} command.
@findex gdb.execute
-@defun execute command
+@defun execute command [from_tty]
Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
If a GDB exception happens while @var{command} runs, it is
translated as described in @ref{Exception Handling,,Exception Handling}.
If no exceptions occur, this function returns @code{None}.
+
+@var{from_tty} specifies whether @value{GDBN} ought to consider this
+command as having originated from the user invoking it interactively.
+It must be a boolean value. If omitted, it defaults to @code{False}.
@end defun
@findex gdb.get_parameter
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 991321f..96bb5f5 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -42,31 +42,10 @@ static int gdbpy_should_print_stack = 1;
#include "target.h"
#include "gdbthread.h"
+static PyMethodDef GdbMethods[];
PyObject *gdb_module;
-static PyObject *get_parameter (PyObject *, PyObject *);
-static PyObject *execute_gdb_command (PyObject *, PyObject *);
-static PyObject *gdbpy_write (PyObject *, PyObject *);
-static PyObject *gdbpy_flush (PyObject *, PyObject *);
-
-static PyMethodDef GdbMethods[] =
-{
- { "history", gdbpy_history, METH_VARARGS,
- "Get a value from history" },
- { "execute", execute_gdb_command, METH_VARARGS,
- "Execute a gdb command" },
- { "get_parameter", get_parameter, METH_VARARGS,
- "Return a gdb parameter's value" },
-
- { "write", gdbpy_write, METH_VARARGS,
- "Write a string using gdb's filtered stream." },
- { "flush", gdbpy_flush, METH_NOARGS,
- "Flush gdb's filtered stdout stream." },
-
- {NULL, NULL, 0, NULL}
-};
-
/* Given a command_line, return a command string suitable for passing
to Python. Lines in the string are separated by newlines. The
return value is allocated using xmalloc and the caller is
@@ -102,6 +81,7 @@ compute_python_string (struct command_line *l)
void
eval_python_from_control_command (struct command_line *cmd)
{
+ int ret;
char *script;
struct cleanup *cleanup;
PyGILState_STATE state;
@@ -113,12 +93,12 @@ eval_python_from_control_command (struct command_line *cmd)
cleanup = make_cleanup_py_restore_gil (&state);
script = compute_python_string (cmd->body_list[0]);
- PyRun_SimpleString (script);
+ ret = PyRun_SimpleString (script);
xfree (script);
- if (PyErr_Occurred ())
+ if (ret)
{
gdbpy_print_stack ();
- error (_("error while executing Python code"));
+ error (_("Error while executing Python code."));
}
do_cleanups (cleanup);
@@ -139,11 +119,10 @@ python_command (char *arg, int from_tty)
++arg;
if (arg && *arg)
{
- PyRun_SimpleString (arg);
- if (PyErr_Occurred ())
+ if (PyRun_SimpleString (arg))
{
gdbpy_print_stack ();
- error (_("error while executing Python code"));
+ error (_("Error while executing Python code."));
}
}
else
@@ -256,14 +235,26 @@ execute_gdb_command (PyObject *self, PyObject *args)
{
struct cmd_list_element *alias, *prefix, *cmd;
char *arg, *newarg;
+ PyObject *from_tty_obj = NULL;
+ int from_tty;
+ int cmp;
volatile struct gdb_exception except;
- if (! PyArg_ParseTuple (args, "s", &arg))
+ if (! PyArg_ParseTuple (args, "s|O!", &arg, &PyBool_Type, &from_tty_obj))
return NULL;
+ from_tty = 0;
+ if (from_tty_obj)
+ {
+ cmp = PyObject_IsTrue (from_tty_obj);
+ if (cmp < 0)
+ return NULL;
+ from_tty = cmp;
+ }
+
TRY_CATCH (except, RETURN_MASK_ALL)
{
- execute_command (arg, 0);
+ execute_command (arg, from_tty);
}
GDB_PY_HANDLE_EXCEPTION (except);
@@ -451,3 +442,26 @@ sys.stdout = GdbOutputFile()\n\
#endif /* HAVE_PYTHON */
}
+
+\f
+
+#if HAVE_PYTHON
+
+static PyMethodDef GdbMethods[] =
+{
+ { "history", gdbpy_history, METH_VARARGS,
+ "Get a value from history" },
+ { "execute", execute_gdb_command, METH_VARARGS,
+ "Execute a gdb command" },
+ { "get_parameter", get_parameter, METH_VARARGS,
+ "Return a gdb parameter's value" },
+
+ { "write", gdbpy_write, METH_VARARGS,
+ "Write a string using gdb's filtered stream." },
+ { "flush", gdbpy_flush, METH_NOARGS,
+ "Flush gdb's filtered stdout stream." },
+
+ {NULL, NULL, 0, NULL}
+};
+
+#endif /* HAVE_PYTHON */
next prev parent reply other threads:[~2009-02-05 16:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-02 13:06 Thiago Jung Bauermann
2009-02-02 13:19 ` Thiago Jung Bauermann
2009-02-02 17:28 ` Tom Tromey
2009-02-05 16:43 ` Thiago Jung Bauermann [this message]
2009-02-02 18:30 ` Tom Tromey
2009-02-04 1:01 ` [RFC][python] Fixes and improvements to gdb.Value. (was Re: [RFA][python] Fixes for existing Python code.) Thiago Jung Bauermann
2009-02-04 19:40 ` [RFC][python] Fixes and improvements to gdb.Value Tom Tromey
2009-02-04 21:57 ` Thiago Jung Bauermann
2009-02-02 19:23 ` [RFA][python] Fixes for existing Python code Eli Zaretskii
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=1233852201.14735.85.camel@localhost.localdomain \
--to=bauerman@br.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@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