From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17994 invoked by alias); 24 Mar 2010 22:02:53 -0000 Received: (qmail 17814 invoked by uid 22791); 24 Mar 2010 22:02:51 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40 X-Spam-Check-By: sourceware.org Received: from mail-ew0-f214.google.com (HELO mail-ew0-f214.google.com) (209.85.219.214) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 24 Mar 2010 22:02:47 +0000 Received: by ewy6 with SMTP id 6so2093993ewy.4 for ; Wed, 24 Mar 2010 15:02:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.213.65.65 with SMTP id h1mr6495478ebi.20.1269468164900; Wed, 24 Mar 2010 15:02:44 -0700 (PDT) In-Reply-To: References: <325e93671003240824t3e940773ned358335b9fe1f40@mail.gmail.com> Date: Wed, 24 Mar 2010 22:02:00 -0000 Message-ID: <325e93671003241502u1201dabbx729c5e8a4c719680@mail.gmail.com> Subject: Re: gdb python and 'complete' From: Jeroen Dobbelaere To: tromey@redhat.com Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2010-03/txt/msg00199.txt.bz2 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 [..]