From: Jeroen Dobbelaere <jeroen.dobbelaere@gmail.com>
To: tromey@redhat.com
Cc: gdb@sourceware.org
Subject: Re: gdb python and 'complete'
Date: Wed, 24 Mar 2010 22:02:00 -0000 [thread overview]
Message-ID: <325e93671003241502u1201dabbx729c5e8a4c719680@mail.gmail.com> (raw)
In-Reply-To: <m3k4t1k3d5.fsf@fleche.redhat.com>
Would it help if we modify gdb.execute to do the redirection when we
call it with a 'from_tty==false' ?
Or do we need a new command for it ?
Following patch implements the redirection in gdb.execute :
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 9a89eed..9280038 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -313,6 +313,9 @@ execute_gdb_command (PyObject *self, PyObject *args)
int cmp;
volatile struct gdb_exception except;
+ char* strresult=0;
+ long strlength=0;
+
if (! PyArg_ParseTuple (args, "s|O!", &arg, &PyBool_Type, &from_tty_obj))
return NULL;
@@ -330,7 +333,28 @@ execute_gdb_command (PyObject *self, PyObject *args)
/* Copy the argument text in case the command modifies it. */
char *copy = xstrdup (arg);
struct cleanup *cleanup = make_cleanup (xfree, copy);
- execute_command (copy, from_tty);
+
+ if (from_tty)
+ {
+ execute_command (copy, from_tty);
+ }
+ else
+ {
+ struct cleanup *io_cleanup;
+ struct ui_file *io_out;
+ struct ui_file *io_backup;
+ io_out = mem_fileopen ();
+ io_cleanup = make_cleanup_ui_file_delete (io_out);
+ io_backup = gdb_stdout;
+ gdb_stdout = io_out;
+
+ execute_command (copy, from_tty);
+
+ gdb_stdout = io_backup;
+ strresult = ui_file_xstrdup (io_out, &strlength);
+ do_cleanups (io_cleanup);
+ }
+
do_cleanups (cleanup);
}
GDB_PY_HANDLE_EXCEPTION (except);
@@ -338,7 +362,17 @@ execute_gdb_command (PyObject *self, PyObject *args)
/* Do any commands attached to breakpoint we stopped at. */
bpstat_do_actions ();
- Py_RETURN_NONE;
+ if (strresult)
+ {
+ PyObject* result;
+ result = PyUnicode_Decode (strresult, strlength, host_charset (), NULL);
+ xfree (strresult);
+ return result;
+ }
+ else
+ {
+ Py_RETURN_NONE;
+ }
}
/* Parse a string and evaluate it as an expression. */
----
It does have as a drawback that a
python gdb.execute("bt")
will not display anything any more.
This should now become a :
python print gdb.execute("bt")
Maybe, in that case, the 'python foo' should be handle as a :
result=foo
if result != None:
print result
Greetings,
Jeroen
[..]
next prev parent reply other threads:[~2010-03-24 22:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-24 15:24 Jeroen Dobbelaere
2010-03-24 15:54 ` Michel METZGER
2010-03-24 16:35 ` Jeroen Dobbelaere
2010-03-24 17:16 ` Daniel Jacobowitz
2010-03-24 17:59 ` Tom Tromey
2010-03-24 22:02 ` Jeroen Dobbelaere [this message]
2010-03-24 22:55 ` Tom 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=325e93671003241502u1201dabbx729c5e8a4c719680@mail.gmail.com \
--to=jeroen.dobbelaere@gmail.com \
--cc=gdb@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