diff --git a/debuggers/gdb/gdb_mi_driver.py b/debuggers/gdb/gdb_mi_driver.py index 4d3c846..399ccec 100755 --- a/debuggers/gdb/gdb_mi_driver.py +++ b/debuggers/gdb/gdb_mi_driver.py @@ -16,9 +16,9 @@ class GDBMiDebugger(Driver): gdb_instances = None - def __init__(self, base_args, regression_args): - self.base_gdb_instance = IDDGdbController() - self.regressed_gdb_instance = IDDGdbController() + def __init__(self, base_args, base_script_file_path, regression_args, regression_script_file_path): + self.base_gdb_instance = IDDGdbController(base_script_file_path) + self.regressed_gdb_instance = IDDGdbController(regression_script_file_path) self.gdb_instances = { 'base': self.base_gdb_instance, 'regressed': self.regressed_gdb_instance } diff --git a/debuggers/gdb/idd_gdb_controller.py b/debuggers/gdb/idd_gdb_controller.py index 841925b..fe5b024 100644 --- a/debuggers/gdb/idd_gdb_controller.py +++ b/debuggers/gdb/idd_gdb_controller.py @@ -1,8 +1,6 @@ import logging import subprocess -import os -from distutils.spawn import find_executable -from typing import Union, List, Optional + from pygdbmi.gdbcontroller import GdbController from pygdbmi.IoManager import IoManager from pygdbmi.constants import ( @@ -14,6 +12,12 @@ logger = logging.getLogger(__name__) class IDDGdbController(GdbController): + script_file_path = None + + def __init__(self, script_file_path = None): + self.script_file_path = script_file_path + super().__init__( None, DEFAULT_TIME_TO_CHECK_FOR_ADDITIONAL_OUTPUT_SEC) + def spawn_new_gdb_subprocess(self) -> int: if self.gdb_process: logger.debug( @@ -21,9 +25,12 @@ def spawn_new_gdb_subprocess(self) -> int: ) self.exit() - logger.debug(f'Launching gdb: {" ".join(self.command)}') + if self.script_file_path: + logger.debug(f'Configuring to run bash script: {self.script_file_path} before starting GDB') + # The modified command will source the script and then run gdb + self.command = ["/bin/bash", "-c", f"source {self.script_file_path} && {' '.join(self.command)}"] - my_env = os.environ.copy() + logger.debug(f'Launching gdb: {" ".join(self.command)}') # Use pipes to the standard streams self.gdb_process = subprocess.Popen( @@ -32,8 +39,7 @@ def spawn_new_gdb_subprocess(self) -> int: stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, - bufsize=0, - env=my_env + bufsize=0 ) self.io_manager = IoManager( diff --git a/idd.py b/idd.py index 6249d08..c88521b 100755 --- a/idd.py +++ b/idd.py @@ -200,7 +200,9 @@ async def execute_debugger_command(self, event: Input.Changed) -> None: parser = argparse.ArgumentParser(description='Diff Debug for simple debugging!') parser.add_argument('-c','--comparator', help='Choose a comparator', default='gdb') parser.add_argument('-ba','--base-args', help='Base executable args', default='[]', nargs='+') + parser.add_argument('-bs','--base-script-path', help='Base preliminary script file path', default='[]', nargs='+') parser.add_argument('-ra','--regression-args', help='Regression executable args', default='[]', nargs='+') + parser.add_argument('-rs','--regression-script-path', help='Regression prelimminary script file path', default='[]', nargs='+') parser.add_argument('-r','--remote_host', help='The host of the remote server', default='localhost') parser.add_argument('-p','--platform', help='The platform of the remote server: macosx, linux', default='linux') parser.add_argument('-t','--triple', help='The target triple: x86_64-apple-macosx, x86_64-gnu-linux', default='x86_64-gnu-linux') @@ -209,12 +211,14 @@ async def execute_debugger_command(self, event: Input.Changed) -> None: comperator = args['comparator'] ba = ' '.join(args['base_args']) + bs = ' '.join(args['base_script_path']) ra = ' '.join(args['regression_args']) + rs = ' '.join(args['regression_script_path']) if comperator == 'gdb': from debuggers.gdb.gdb_mi_driver import GDBMiDebugger - Debugger = GDBMiDebugger(ba, ra) + Debugger = GDBMiDebugger(ba, bs, ra, rs) elif comperator == 'lldb': from debuggers.lldb.lldb_driver import LLDBDebugger