This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: gdb python and 'complete'
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
[..]