|
| 1 | +from idd.driver import Driver |
| 2 | +from idd.debuggers.lldb.lldb_controller import IDDLLDBController |
| 3 | +from idd.debuggers.lldb.lldb_extensions import * |
| 4 | +from concurrent.futures import ThreadPoolExecutor |
| 5 | + |
| 6 | + |
| 7 | +class LLDBNewDriver(Driver): |
| 8 | + def __init__( |
| 9 | + self, base_exe=None, base_pid=None, regressed_exe=None, regressed_pid=None |
| 10 | + ): |
| 11 | + self.base_controller = IDDLLDBController(exe=base_exe) |
| 12 | + self.regressed_controller = IDDLLDBController(exe=regressed_exe) |
| 13 | + |
| 14 | + def run_single_command(self, command, target): |
| 15 | + if target == "base": |
| 16 | + result = self.base_controller.run_lldb_command(command) |
| 17 | + return result |
| 18 | + elif target == "regressed": |
| 19 | + result = self.regressed_controller.run_lldb_command(command) |
| 20 | + return result |
| 21 | + |
| 22 | + def run_parallel_command(self, command): |
| 23 | + with ThreadPoolExecutor() as executor: |
| 24 | + base_future = executor.submit(self.run_single_command, command, "base") |
| 25 | + regressed_future = executor.submit( |
| 26 | + self.run_single_command, command, "regressed" |
| 27 | + ) |
| 28 | + return { |
| 29 | + "base": base_future.result(), |
| 30 | + "regressed": regressed_future.result(), |
| 31 | + } |
| 32 | + |
| 33 | + def insert_stdin(self, text): |
| 34 | + self.base_controller.send_input_to_debuggee(text) |
| 35 | + self.regressed_controller.send_input_to_debuggee(text) |
| 36 | + |
| 37 | + def insert_stdin_single(self, text, target): |
| 38 | + if target == "base": |
| 39 | + self.base_controller.send_input_to_debuggee(text) |
| 40 | + elif target == "regressed": |
| 41 | + self.regressed_controller.send_input_to_debuggee(text) |
| 42 | + |
| 43 | + def get_state(self, target=None): |
| 44 | + if target == "base": |
| 45 | + return { |
| 46 | + "stack_frames": self.get_current_stack_frames(self.base_controller), |
| 47 | + "locals": self.get_current_local_vars(self.base_controller, None), |
| 48 | + "args": self.get_current_args(self.base_controller), |
| 49 | + "instructions": self.get_current_instructions(self.base_controller), |
| 50 | + "registers": self.get_current_registers(self.base_controller), |
| 51 | + } |
| 52 | + if target == "regressed": |
| 53 | + return { |
| 54 | + "stack_frames": self.get_current_stack_frames(self.regressed_controller), |
| 55 | + "locals": self.get_current_local_vars(self.regressed_controller, None), |
| 56 | + "args": self.get_current_args(self.regressed_controller), |
| 57 | + "instructions": self.get_current_instructions(self.regressed_controller), |
| 58 | + "registers": self.get_current_registers(self.regressed_controller), |
| 59 | + } |
| 60 | + |
| 61 | + with ThreadPoolExecutor() as executor: |
| 62 | + base_future = executor.submit(self.get_state, "base") |
| 63 | + regressed_future = executor.submit(self.get_state, "regressed") |
| 64 | + return { |
| 65 | + "base": base_future.result(), |
| 66 | + "regressed": regressed_future.result(), |
| 67 | + } |
| 68 | + |
| 69 | + def get_console_output(self, target=None): |
| 70 | + if target == "base": |
| 71 | + return self.base_controller.get_debuggee_output() |
| 72 | + if target == "regressed": |
| 73 | + return self.regressed_controller.get_debuggee_output() |
| 74 | + |
| 75 | + with ThreadPoolExecutor() as executor: |
| 76 | + base_future = executor.submit(self.get_console_output, "base") |
| 77 | + regressed_future = executor.submit(self.get_console_output, "regressed") |
| 78 | + return { |
| 79 | + "base": base_future.result(), |
| 80 | + "regressed": regressed_future.result(), |
| 81 | + } |
| 82 | + |
| 83 | + def get_current_stack_frames(self, controller): |
| 84 | + target = controller.debugger.GetTargetAtIndex(0) |
| 85 | + return get_current_stack_frame_from_target(target) or [] |
| 86 | + |
| 87 | + def get_current_args(self, controller): |
| 88 | + target = controller.debugger.GetTargetAtIndex(0) |
| 89 | + return get_args_as_list(target) or [] |
| 90 | + |
| 91 | + def get_current_local_vars(self, controller, filters): |
| 92 | + target = controller.debugger.GetTargetAtIndex(0) |
| 93 | + locals = get_local_vars_as_list(target) |
| 94 | + if filters == "ignore-order-declaration": |
| 95 | + locals.sort() |
| 96 | + return locals or [] |
| 97 | + |
| 98 | + def get_current_instructions(self, controller): |
| 99 | + target = controller.debugger.GetTargetAtIndex(0) |
| 100 | + return get_instructions_as_list(target) or [] |
| 101 | + |
| 102 | + def get_current_registers(self, controller): |
| 103 | + target = controller.debugger.GetTargetAtIndex(0) |
| 104 | + return get_registers_as_list(target) or [] |
| 105 | + |
| 106 | + def terminate(self): |
| 107 | + self.base_controller.terminate() |
| 108 | + self.regressed_controller.terminate() |
0 commit comments