Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import lldb
  2. import tempfile
  3. import subprocess
  4.  
  5. def get_gst_parent(gst_obj):
  6. return gst_obj.GetChildMemberWithName("parent")
  7.  
  8. def get_gst_name(gst_obj):
  9. return gst_object.GetChildMemberWithName("name")
  10.  
  11. def get_gst_root(gst_obj):
  12. parent = get_gst_parent(gst_obj)
  13. while parent.GetValueAsUnsigned() != 0:
  14. gst_obj = parent
  15. parent = get_gst_parent(gst_obj)
  16. return gst_obj
  17.  
  18. def gst_dot(debugger, command, result, dict):
  19. error = lldb.SBError()
  20.  
  21. gst_obj = lldb.frame.FindVariable(command).GetChildMemberWithName("object")
  22. root = get_gst_root(gst_obj)
  23.  
  24. # FIXME: There must be a better way than EvaluateExpression
  25. # to execute a function.
  26. GST_DEBUG_GRAPH_SHOW_ALL = "(GstDebugGraphDetails)15";
  27. dot_data = lldb.frame.EvaluateExpression(
  28. 'gst_debug_bin_to_dot_data((GstBin*){}, {})'
  29. .format(
  30. root.GetValueAsUnsigned(),
  31. GST_DEBUG_GRAPH_SHOW_ALL))
  32.  
  33. if dot_data.GetError().Fail():
  34. # Can happen if GStreamer is static and gst_debug_bin_to_dot_data is not referenced
  35. print dot_data.GetError().GetCString()
  36. return
  37.  
  38. if dot_data.GetValueAsUnsigned() == 0:
  39. print "Error generating Graphviz data for {}".format(command)
  40. return
  41.  
  42. dot_str = lldb.process.ReadCStringFromMemory(dot_data.GetValueAsUnsigned(), 0xffffff, error)
  43. if not error.Success:
  44. print "Error reading Graphviz data from memory!"
  45. return
  46.  
  47. f = tempfile.NamedTemporaryFile(suffix = ".dot")
  48. f.write(dot_str)
  49. opener = "open"
  50. subprocess.call([opener, f.name])
  51.  
  52. def __lldb_init_module (debugger, dict):
  53. debugger.HandleCommand('command script add -f gst.gst_dot gst_dot')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement