summaryrefslogtreecommitdiff
path: root/examples/python
diff options
context:
space:
mode:
Diffstat (limited to 'examples/python')
-rwxr-xr-xexamples/python/crashlog.py2
-rw-r--r--examples/python/scripted_step.py25
-rw-r--r--examples/python/shadow.py57
-rwxr-xr-xexamples/python/symbolication.py2
4 files changed, 84 insertions, 2 deletions
diff --git a/examples/python/crashlog.py b/examples/python/crashlog.py
index 60a6a1f50f005..a557b604afb43 100755
--- a/examples/python/crashlog.py
+++ b/examples/python/crashlog.py
@@ -452,7 +452,7 @@ class CrashLog(symbolication.Symbolicator):
for image in self.images:
if image.identifier == identifier:
return image
- regex_text = '^.*\.%s$' % (identifier)
+ regex_text = '^.*\.%s$' % (re.escape(identifier))
regex = re.compile(regex_text)
for image in self.images:
if regex.match(image.identifier):
diff --git a/examples/python/scripted_step.py b/examples/python/scripted_step.py
index 8affb9e83220d..6be3971887205 100644
--- a/examples/python/scripted_step.py
+++ b/examples/python/scripted_step.py
@@ -184,3 +184,28 @@ class StepCheckingCondition:
def should_step (self):
return True
+# Here's an example that steps out of the current frame, gathers some information
+# and then continues. The information in this case is rax. Currently the thread
+# plans are not a safe place to call lldb command-line commands, so the information
+# is gathered through SB API calls.
+
+class FinishPrintAndContinue:
+ def __init__ (self, thread_plan, dict):
+ self.thread_plan = thread_plan
+ self.step_out_thread_plan = thread_plan.QueueThreadPlanForStepOut(0, True)
+ self.thread = self.thread_plan.GetThread()
+
+ def explains_stop (self, event):
+ return False
+
+ def should_stop (self, event):
+ if self.step_out_thread_plan.IsPlanComplete():
+ frame_0 = self.thread.frames[0]
+ rax_value = frame_0.FindRegister("rax")
+ if rax_value.GetError().Success():
+ print "RAX on exit: ", rax_value.GetValue()
+ else:
+ print "Couldn't get rax value:", rax_value.GetError().GetCString()
+
+ self.thread_plan.SetPlanComplete(True)
+ return False
diff --git a/examples/python/shadow.py b/examples/python/shadow.py
new file mode 100644
index 0000000000000..d1a5878fcef8a
--- /dev/null
+++ b/examples/python/shadow.py
@@ -0,0 +1,57 @@
+#!/usr/bin/python
+
+import lldb
+import shlex
+
+@lldb.command("shadow")
+def check_shadow_command(debugger, command, exe_ctx, result, dict):
+ '''Check the currently selected stack frame for shadowed variables'''
+ process = exe_ctx.GetProcess()
+ state = process.GetState()
+ if state != lldb.eStateStopped:
+ print >>result, "process must be stopped, state is %s" % lldb.SBDebugger.StateAsCString(state)
+ return
+ frame = exe_ctx.GetFrame()
+ if not frame:
+ print >>result, "invalid frame"
+ return
+ # Parse command line args
+ command_args = shlex.split(command)
+ # TODO: add support for using arguments that are passed to this command...
+
+ # Make a dictionary of variable name to "SBBlock and SBValue"
+ shadow_dict = {}
+
+ num_shadowed_variables = 0
+ # Get the deepest most block from the current frame
+ block = frame.GetBlock()
+ # Iterate through the block and all of its parents
+ while block.IsValid():
+ # Get block variables from the current block only
+ block_vars = block.GetVariables(frame, True, True, True, 0)
+ # Iterate through all variables in the current block
+ for block_var in block_vars:
+ # Since we can have multiple shadowed variables, we our variable
+ # name dictionary to have an array or "block + variable" pairs so
+ # We can correctly print out all shadowed variables and whow which
+ # blocks they come from
+ block_var_name = block_var.GetName()
+ if block_var_name in shadow_dict:
+ shadow_dict[block_var_name].append(block_var)
+ else:
+ shadow_dict[block_var_name] = [block_var]
+ # Get the parent block and continue
+ block = block.GetParent()
+
+ num_shadowed_variables = 0
+ if shadow_dict:
+ for name in shadow_dict.keys():
+ shadow_vars = shadow_dict[name]
+ if len(shadow_vars) > 1:
+ print '"%s" is shadowed by the following declarations:' % (name)
+ num_shadowed_variables += 1
+ for shadow_var in shadow_vars:
+ print >>result, str(shadow_var.GetDeclaration())
+ if num_shadowed_variables == 0:
+ print >>result, 'no variables are shadowed'
+
diff --git a/examples/python/symbolication.py b/examples/python/symbolication.py
index 2f2a274dbc41d..88846c99b3a47 100755
--- a/examples/python/symbolication.py
+++ b/examples/python/symbolication.py
@@ -448,7 +448,7 @@ class Symbolicator:
if image.identifier == identifier:
images.append(image)
if len(images) == 0:
- regex_text = '^.*\.%s$' % (identifier)
+ regex_text = '^.*\.%s$' % (re.escape(identifier))
regex = re.compile(regex_text)
for image in self.images:
if regex.match(image.identifier):