public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Make "backtrace" doesn't print python stack if init python dir get fail
@ 2013-11-28 17:35 Hui Zhu
  2013-12-02 16:05 ` Tom Tromey
  0 siblings, 1 reply; 11+ messages in thread
From: Hui Zhu @ 2013-11-28 17:35 UTC (permalink / raw)
  To: gdb-patches ml

If the python lib dir of GDB has something wrong, each time "backtrace" will output a python error, for example:
Python Exception <type 'exceptions.ImportError'> No module named gdb:

warning:
Could not load the Python gdb module from `/usr/local/share/gdb/python'.
Limited Python support is available from the _gdb module.
Suggest passing --data-directory=/path/to/gdb/data-directory.
(gdb) start
Temporary breakpoint 1 at 0x400507: file 1.c, line 4.
Starting program: /home/teawater/tmp/1

Temporary breakpoint 1, main (argc=1, argv=0x7fffffffe118, envp=0x7fffffffe128) at 1.c:4
4		int	a = 1;
(gdb) bt
Python Exception <type 'exceptions.ImportError'> No module named gdb.frames:
#0  main (argc=1, argv=0x7fffffffe118, envp=0x7fffffffe128) at 1.c:4

This python stack is output by function apply_frame_filter because bootstrap_python_frame_filters got NULL.
The core reason is init python dir get fail.
And if GDB doesn't init python lib in right, python script cannot use any frame filter because "import gdb" will get fail.

So if init python dir get fail, "backtrace" will print python stack.  But GDB already output error when it start.
I make a patch let it doesn't print python stack if init python dir get fail.

Please help me review it.

Thanks,
Hui

2013-11-28  Hui Zhu  <hui@codesourcery.com>

	* python/py-framefilter.c(apply_frame_filter): Add check for
	"gdb_python_module".

--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -1506,7 +1506,10 @@ apply_frame_filter (struct frame_info *f
  	 initialization error.  This return code will trigger a
  	 default backtrace.  */
  
-      gdbpy_print_stack ();
+      if (gdb_python_module != NULL)
+        gdbpy_print_stack ();
+      else
+	PyErr_Clear ();
        do_cleanups (cleanups);
        return PY_BT_NO_FILTERS;
      }

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-01-15 20:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-28 17:35 [PATCH] Make "backtrace" doesn't print python stack if init python dir get fail Hui Zhu
2013-12-02 16:05 ` Tom Tromey
2013-12-03  7:30   ` Hui Zhu
2013-12-03 20:27     ` Tom Tromey
2013-12-04  7:41       ` Hui Zhu
2013-12-11 17:07         ` Tom Tromey
2013-12-13 11:49           ` Hui Zhu
2014-01-14 16:09             ` Tom Tromey
2014-01-14 17:41               ` Tom Tromey
2014-01-14 21:32                 ` Phil Muldoon
2014-01-15 20:06                   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).