Skip to content

Add support for executing a script prior to starting GDB. #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions debuggers/gdb/gdb_mi_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
20 changes: 13 additions & 7 deletions debuggers/gdb/idd_gdb_controller.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -14,16 +12,25 @@
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(
"Killing current gdb subprocess (pid %d)" % self.gdb_process.pid
)
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(
Expand All @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion idd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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

Expand Down