This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Make "backtrace" doesn't print python stack if init python dir get fail


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;
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]