returns the value of a variable :scope: can be BY_ID, EXPRESSION, GLOBAL, LOCAL, FRAME BY_ID means we'll traverse the list of all objects alive to get the object. :locator: after reaching the proper scope, we have to get the attributes until we find the proper locatio
(dbg, thread_id, frame_id, scope, locator)
| 49 | |
| 50 | @silence_warnings_decorator |
| 51 | def getVariable(dbg, thread_id, frame_id, scope, locator): |
| 52 | """ |
| 53 | returns the value of a variable |
| 54 | |
| 55 | :scope: can be BY_ID, EXPRESSION, GLOBAL, LOCAL, FRAME |
| 56 | |
| 57 | BY_ID means we'll traverse the list of all objects alive to get the object. |
| 58 | |
| 59 | :locator: after reaching the proper scope, we have to get the attributes until we find |
| 60 | the proper location (i.e.: obj\tattr1\tattr2) |
| 61 | |
| 62 | :note: when BY_ID is used, the frame_id is considered the id of the object to find and |
| 63 | not the frame (as we don't care about the frame in this case). |
| 64 | """ |
| 65 | if scope == "BY_ID": |
| 66 | if thread_id != get_current_thread_id(threading.current_thread()): |
| 67 | raise VariableError("getVariable: must execute on same thread") |
| 68 | |
| 69 | try: |
| 70 | import gc |
| 71 | |
| 72 | objects = gc.get_objects() |
| 73 | except: |
| 74 | pass # Not all python variants have it. |
| 75 | else: |
| 76 | frame_id = int(frame_id) |
| 77 | for var in objects: |
| 78 | if id(var) == frame_id: |
| 79 | if locator is not None: |
| 80 | locator_parts = locator.split("\t") |
| 81 | for k in locator_parts: |
| 82 | _type, _type_name, resolver = get_type(var) |
| 83 | var = resolver.resolve(var, k) |
| 84 | |
| 85 | return var |
| 86 | |
| 87 | # If it didn't return previously, we coudn't find it by id (i.e.: already garbage collected). |
| 88 | sys.stderr.write("Unable to find object with id: %s\n" % (frame_id,)) |
| 89 | return None |
| 90 | |
| 91 | frame = dbg.find_frame(thread_id, frame_id) |
| 92 | if frame is None: |
| 93 | return {} |
| 94 | |
| 95 | if locator is not None: |
| 96 | locator_parts = locator.split("\t") |
| 97 | else: |
| 98 | locator_parts = [] |
| 99 | |
| 100 | for attr in locator_parts: |
| 101 | attr.replace("@_@TAB_CHAR@_@", "\t") |
| 102 | |
| 103 | if scope == "EXPRESSION": |
| 104 | for count in range(len(locator_parts)): |
| 105 | if count == 0: |
| 106 | # An Expression can be in any scope (globals/locals), therefore it needs to evaluated as an expression |
| 107 | var = evaluate_expression(dbg, frame, locator_parts[count], False) |
| 108 | else: |
no test coverage detected