Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hui Zhu <hui_zhu@mentor.com>
To: gdb-patches ml <gdb-patches@sourceware.org>
Subject: [PATCH] Make "backtrace" doesn't print python stack if init python dir get fail
Date: Thu, 28 Nov 2013 17:35:00 -0000	[thread overview]
Message-ID: <52974146.70805@mentor.com> (raw)

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


             reply	other threads:[~2013-11-28 13:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-28 17:35 Hui Zhu [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52974146.70805@mentor.com \
    --to=hui_zhu@mentor.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox