From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20822 invoked by alias); 8 Oct 2010 19:12:07 -0000 Received: (qmail 20813 invoked by uid 22791); 8 Oct 2010 19:12:05 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,T_FILL_THIS_FORM_SHORT,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 08 Oct 2010 19:12:00 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o98JBwNO014572 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 8 Oct 2010 15:11:58 -0400 Received: from host1.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o98JBui8000671 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 8 Oct 2010 15:11:58 -0400 Received: from host1.dyn.jankratochvil.net (localhost [127.0.0.1]) by host1.dyn.jankratochvil.net (8.14.4/8.14.4) with ESMTP id o98JBuwM014887 for ; Fri, 8 Oct 2010 21:11:56 +0200 Received: (from jkratoch@localhost) by host1.dyn.jankratochvil.net (8.14.4/8.14.4/Submit) id o98JBtVE014886 for gdb-patches@sourceware.org; Fri, 8 Oct 2010 21:11:55 +0200 Date: Fri, 08 Oct 2010 19:12:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] python(+solib error): save/restore error state Message-ID: <20101008191154.GA13058@host1.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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: 2010-10/txt/msg00153.txt.bz2 Hi, downstream Bug: https://bugzilla.redhat.com/show_bug.cgi?id=639089 currently some unhandled errors are printed in an unrelated context later. Patch goals: * ensure_python_env now saves/restores the Python error state of its caller. * ensure_python_env now internal-error warns on unhandled error in general. internal_warning is almost never used as it dumps GDB core the same way as internal_error. Not targeted by this patch and used again: warning (_("internal error: [...]")); * source_python_script_for_objfile handles forgotten error explicitly. (as suggested by Tom) * solib_read_symbols prints GDB exceptions even for from_tty == 0. I understand "Loaded symbols for %s" should not be printed for from_tty == 0 but I do not understand why exceptions should be hidden, even for scripts. This is since - no specific message about such change there: e12b767fb287127671d514eef227486777f0a972 Author: Pedro Alves Group errors for many missing shared libraries. http://sourceware.org/ml/gdb-patches/2010-04/msg00342.html http://sourceware.org/ml/gdb-cvs/2010-04/msg00126.html run_command_1 calls post_create_inferior with from_tty == 0 - this is why from_tty == 0 is in solib_read_symbols. /* Pass zero for FROM_TTY, because at this point the "run" command has done its thing; now we are setting up the running program. */ post_create_inferior (¤t_target, 0); I do not agree with but this part is not required for this patch after the fix of solib_read_symbols. There is more the problem of excessive "Reading symbols..." slowing GDB even 2x during startup just by the uninteresting messages - this may have been the goal for from_tty == 0 there. * Currently generally in use: if (value == NULL) { gdbpy_print_stack (); error (_("Error while executing Python code.")); } should catch the gdbpy_print_stack output into a string variable and use it in the error call. Not targeted by this patch. Unfortunately this fix has no real testcase. You can `yum install gdb-heap' at least on Fedora 14 x86_64 and the provided testcase should show: (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: .../gdb/testsuite/gdb.python/py-shared LookupError: unknown encoding: IBM1047 Error while reading shared library symbols: Error reading python script /usr/local/share/gdb/auto-load/lib64/ld-2.12.90.so-gdb.py for object file /lib64/ld-linux-x86-64.so.2 Breakpoint 3, main (argc=1, argv=0x7fffffffdf58) at ./gdb.python/py-shared.c:25 25 func1 (); (gdb) testcase ./gdb.python/py-shared.exp completed in 0 seconds But nobody guarantees IBM1047 is an invalid charset for Python && supported charset by glibc. GDB does not accept a charset name unsupported by glibc. And for example an invalid Python expression does not cause this kind of delayed Python error state. No regressions on {x86_64,x86_64-m32,i686}-fedora14snapshot-linux-gnu. "Error while reading shared library symbols:" does not happen anywhere there. Thanks, Jan 2010-10-08 Jan Kratochvil * python/python.c (struct python_env) : New fields. (restore_python_env): Handle PyErr_Occurred. Call PyErr_Restore. (ensure_python_env): Call PyErr_Fetch. (source_python_script_for_objfile): Handle PyErr_Occurred. * solib.c (solib_read_symbols): Call exception_fprintf even without FROM_TTY. --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -79,6 +79,7 @@ struct python_env PyGILState_STATE state; struct gdbarch *gdbarch; const struct language_defn *language; + PyObject *error_type, *error_value, *error_traceback; }; static void @@ -86,6 +87,16 @@ restore_python_env (void *p) { struct python_env *env = (struct python_env *)p; + /* Leftover Python error is forbidden by Python Exception Handling. */ + if (PyErr_Occurred ()) + { + /* This order is similar to the one calling error afterwards. */ + gdbpy_print_stack (); + warning (_("internal error: Unhandled Python exception")); + } + + PyErr_Restore (env->error_type, env->error_value, env->error_traceback); + PyGILState_Release (env->state); python_gdbarch = env->gdbarch; python_language = env->language; @@ -108,6 +119,9 @@ ensure_python_env (struct gdbarch *gdbarch, python_gdbarch = gdbarch; python_language = language; + /* Save it and ensure ! PyErr_Occurred () afterwards. */ + PyErr_Fetch (&env->error_type, &env->error_value, &env->error_traceback); + return make_cleanup (restore_python_env, env); } @@ -768,6 +782,13 @@ source_python_script_for_objfile (struct objfile *objfile, clear the error indicator. */ PyRun_SimpleFile (stream, file); + if (PyErr_Occurred ()) + { + gdbpy_print_stack (); + error (_("Error reading python script %s for object file %s"), file, + objfile->name); + } + do_cleanups (cleanups); gdbpy_current_objfile = NULL; } --- a/gdb/solib.c +++ b/gdb/solib.c @@ -652,12 +652,8 @@ solib_read_symbols (struct so_list *so, int flags) } if (e.reason < 0) - { - if (from_tty) - exception_fprintf - (gdb_stderr, e, - _("Error while reading shared library symbols:\n")); - } + exception_fprintf (gdb_stderr, e, + _("Error while reading shared library symbols:\n")); else { if (from_tty || info_verbose) --- a/gdb/testsuite/gdb.python/py-shared.exp +++ b/gdb/testsuite/gdb.python/py-shared.exp @@ -66,3 +66,11 @@ gdb_test "python print gdb.solib_name(long(func1))" "gdb/testsuite/gdb.python/py gdb_test "p &main" "" "main address" gdb_py_test_silent_cmd "python main = gdb.history(0)" "Aquire main address" 1 gdb_test "python print gdb.solib_name(long(main))" "None" "test main solib location" + +# Test error while loading *-gdb.py + +gdb_breakpoint main + +gdb_test_no_output "set host-charset IBM1047" + +runto_main