[bitbake-devel] [PATCH] bitbake: enable pdb tracing

joe at deserted.net joe at deserted.net
Thu Aug 1 14:19:46 UTC 2013


From: Joe MacDonald <joe at deserted.net>

Based on:

   http://blog.devork.be/2009/07/how-to-bring-running-python-program.html

register a signal handler to dynamically start pdb tracing on receiving
SIGUSR1.

Signed-off-by: Joe MacDonald <joe at deserted.net>
---

I've been spending the last week or so looking at some perplexing hangs
(for lack of a more descriptive word) with bitbake.  The behaviour is
difficult to characterize and even harder to reproduce, but over the
course of a day with a dozen machines or so doing various builds maybe a
dozen times we'll get in a scenario where bitbake itself appears to be
completely idle and waiting on something.  Occasionally it's been when
doing a 'bitbake -g' or 'bitbake -e', most recently I saw this on a
'bitbake core-image-minimal'.

Given the difficulty I've had in actually making the hang occur in
controlled circumstances, I can't say for certain, but it appears that
enabling any level of debugging makes the problem disappear.  So I've been
watching for it to happen then attaching gdb and investigating that way.

That's when it occurred to me that it might actually be useful to others
to have pdb available as an option, rather than needing to resort to
attaching gdb/python and debugging that way.

I did a quick search of the mailing list archives and didn't see this
discussed before, but if it has been and dismissed, sorry.

 -J.

 bitbake/bin/bitbake |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/bitbake/bin/bitbake b/bitbake/bin/bitbake
index 60c4b96..e40fe28 100755
--- a/bitbake/bin/bitbake
+++ b/bitbake/bin/bitbake
@@ -24,6 +24,7 @@
 
 import os
 import sys, logging
+import signal
 sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                 'lib'))
 
@@ -57,6 +58,13 @@ try:
 except:
     pass
 
+# start pdb tracing if we receive SIGUSR1.
+def handle_pdb(sig, frame):
+    try:
+        import pdb
+        pdb.Pdb().set_trace(frame)
+    except ImportError:
+        logger.debug(2, 'Unable to import pdb module, interactive debugging of bitbake will not be possible')
 
 def get_ui(config):
     if not config.ui:
@@ -338,6 +346,7 @@ def main():
 
 if __name__ == "__main__":
     try:
+        signal.signal(signal.SIGUSR1, handle_pdb)
         ret = main()
     except Exception:
         ret = 1
-- 
1.7.10.4




More information about the bitbake-devel mailing list