From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28333 invoked by alias); 11 Jan 2012 21:28:42 -0000 Received: (qmail 28325 invoked by uid 22791); 11 Jan 2012 21:28:41 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from router-304.cs.umd.edu (HELO bacon.cs.umd.edu) (128.8.127.145) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Jan 2012 21:28:28 +0000 Received: from wireless-206-196-163-53.umd.edu (wireless-206-196-163-53.umd.edu [206.196.163.53]) (Authenticated sender: khooyp) by bacon.cs.umd.edu (Postfix) with ESMTPSA id 7C2C1B411FC; Wed, 11 Jan 2012 16:28:26 -0500 (EST) Subject: Re: Make the "python" command resemble the standard Python interpreter Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Khoo Yit Phang In-Reply-To: Date: Wed, 11 Jan 2012 21:30:00 -0000 Cc: Khoo Yit Phang , gdb-patches@sourceware.org Content-Transfer-Encoding: quoted-printable Message-Id: <0B6537F9-CB85-4BA1-8838-DAA84A86FF5B@cs.umd.edu> References: To: Tom Tromey X-CSD-MailScanner-ID: 7C2C1B411FC.A8311 X-CSD-MailScanner: Found to be clean X-CSD-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-50, required 5, autolearn=not spam, ALL_TRUSTED -50.00) X-CSD-MailScanner-From: khooyp@cs.umd.edu X-CSD-MailScanner-Watermark: 1326922106.64056@pt2Im5hkcf+I/C+N24GblA Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-01/txt/msg00377.txt.bz2 Hi, On Jan 11, 2012, at 3:51 PM, Tom Tromey wrote: > Yit> For "python" with arguments, this prints the results of expressions, > Yit> e.g., "python 1 + 2" will print "3" (previously, it will not print > Yit> anything). >=20 > Did you run the test suite? I'm curious if this caused any failures. >=20 > On balance, I'm ok with this idea, since I don't think we make many > promises about CLI output remaining the same across versions. I'm still trying to figure out how to run the testsuite and understand the = output. Is it possible to just run the Python ones, to not take so long? > Yit> It also hooks GDB's readline wrappers > Yit> (command_line_input) to Python so that line editing and history > Yit> editing works. Additionally, Python's standard readline module is > Yit> stubbed out because it conflicts with GDB's use of readline. >=20 > Can you expand more on how it conflicts? >=20 > I think it would be better to make it not conflict somehow. Both GDB and Python's readline module and methods attempt to configure libr= eadline, clobbering each others configuration. There doesn't seem to be any= support in libreadline for reentrancy. It may be possible to implement a w= rapper around readline for Python, but that's another patch, I think. > Yit> + TRY_CATCH (except, RETURN_MASK_ALL) > Yit> + { > Yit> + struct cleanup *cleanup =3D gdbpy_suspend_sigint_handler (); > Yit> + p =3D command_line_input (prompt, 0, "python"); > Yit> + do_cleanups (cleanup); > Yit> + } > Yit> + > Yit> + /* Detect Ctrl-C and treat as KeyboardInterrupt. */ > Yit> + if (except.reason =3D=3D RETURN_QUIT) > Yit> + return NULL; >=20 > Does this case need the Python exception to be set? If not, I think it > would be good to expand this comment to explain the situation. In this case, no, since PyOS_ReadlineFunctionPointer is supposed to return = NULL upon Ctrl-C, from what I can gather. That comment is misleading, I'll = change it. > Yit> + m =3D PyImport_AddModule ("__main__"); > Yit> + if (m =3D=3D NULL) > Yit> + error (_("Error while executing Python code.")); >=20 > You have to do something with the Python exception here. > Usually we use gdbpy_print_stack, but sometimes other things are > appropriate. Okay. > Yit> + d =3D PyModule_GetDict (m); >=20 > Do we need error checking? > I didn't look at the API docs. Nope, "this function never fails". > Yit> + v =3D PyRun_StringFlags (command, > Yit> + from_tty ? Py_single_input : Py_file_input, > Yit> + d, d, NULL); > Yit> + if (v =3D=3D NULL) > Yit> + { > Yit> + int interrupt =3D PyErr_ExceptionMatches (PyExc_KeyboardInter= rupt); > Yit> + PyErr_Print (); >=20 > gdbpy_print_stack. >=20 > Yit> + if (! interrupt) > Yit> + error (_("Error while executing Python code.")); >=20 > Why the special case for interrupts here? This is because PyErr_Print clears the error, annoyingly enough, so I can't= check whether it's a KeyboardInterrupt after PyErr_Print. Yit January 11, 2012