diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:50:09 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:50:09 +0000 |
| commit | f3fbd1c0586ff6ec7895991e6c28f61a503c36a8 (patch) | |
| tree | 48d008fd3df8c0e73271a4b18474e0aac6dbfe33 /examples | |
| parent | 2fc5d2d1dfaf623ce4e24cd8590565902f8c557c (diff) | |
Diffstat (limited to 'examples')
| -rwxr-xr-x | examples/python/crashlog.py | 2 | ||||
| -rw-r--r-- | examples/python/scripted_step.py | 25 | ||||
| -rw-r--r-- | examples/python/shadow.py | 57 | ||||
| -rwxr-xr-x | examples/python/symbolication.py | 2 | ||||
| -rw-r--r-- | examples/synthetic/gnu_libstdcpp.py | 11 |
5 files changed, 90 insertions, 7 deletions
diff --git a/examples/python/crashlog.py b/examples/python/crashlog.py index 60a6a1f50f00..a557b604afb4 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 8affb9e83220..6be397188720 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 000000000000..d1a5878fcef8 --- /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 2f2a274dbc41..88846c99b3a4 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): diff --git a/examples/synthetic/gnu_libstdcpp.py b/examples/synthetic/gnu_libstdcpp.py index b6bf42235acd..9f26282be01f 100644 --- a/examples/synthetic/gnu_libstdcpp.py +++ b/examples/synthetic/gnu_libstdcpp.py @@ -237,11 +237,12 @@ class StdVectorSynthProvider: def get_child_at_index(self, index): if index >= self.num_children(): return None - byte_offset = index / 8 - bit_offset = index % 8 - element_size = self.start_p.GetType().GetPointeeType().GetByteSize() - data = self.start_p.GetPointeeData(byte_offset / element_size) - bit = data.GetUnsignedInt8(lldb.SBError(), byte_offset % element_size) & (1 << bit_offset) + element_type = self.start_p.GetType().GetPointeeType() + element_bits = 8 * element_type.GetByteSize() + element_offset = (index / element_bits) * element_type.GetByteSize() + bit_offset = index % element_bits + element = self.start_p.CreateChildAtOffset('['+str(index)+']',element_offset,element_type) + bit = element.GetValueAsUnsigned(0) & (1 << bit_offset) if bit != 0: value_expr = "(bool)true" else: |
