+ +

Frame recognizers allow retrieving information about special frames based on + ABI, arguments or other special properties of that frame, even without source + code or debug info. Currently, they can extract function arguments that would + otherwise be unaccesible.

+ +

Adding a custom frame recognizer is possible by implementing a Python class + and using the 'frame recognizer add' command. The Python class should have a + 'get_recognized_arguments' method and it will receive an argument of type + lldb.SBFrame representing the current frame that we are trying to recognize. + The method should return a (possibly empty) list of lldb.SBValue objects that + represent the recognized arguments.

+ +

An example of a recognizer that retrieves the file descriptor values from libc + functions 'read', 'write' and 'close' follows:

+ +
  class LibcFdRecognizer(object):
+    def get_recognized_arguments(self, frame):
+      if frame.name in ["read", "write", "close"]:
+        fd = frame.EvaluateExpression("$arg1").unsigned
+        value = lldb.target.CreateValueFromExpression("fd", "(int)%d" % fd)
+        return [value]
+      return []
+
+ +

The file containing this implementation can be imported via 'command script + import' and then we can register this recognizer with 'frame recognizer add'. + It's important to restrict the recognizer to the libc library (which is + libsystem_kernel.dylib on macOS):

+ +
(lldb) command script import .../fd_recognizer.py
+(lldb) frame recognizer add -l fd_recognizer.LibcFdRecognizer -n read -m libsystem_kernel.dylib
+
-