Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
Open
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
29 changes: 20 additions & 9 deletions pyringe/inferior.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import subprocess
import tempfile
import time
import distutils.spawn


# Setting these overrides the defaults. See _SymbolFilePath.
Expand Down Expand Up @@ -151,23 +152,24 @@ def __init__(self, args=None, arch='i386:x86-64'):
self._outfile_r = open(outfile_w.name)
self._errfile_r = open(errfile_w.name)

self._process = subprocess.Popen(
if self.is_installed:
self._process = subprocess.Popen(
bufsize=0,
args=arglist,
stdin=subprocess.PIPE,
stdout=outfile_w.file,
stderr=errfile_w.file,
close_fds=True,
preexec_fn=os.setpgrp,
)
outfile_w.close()
errfile_w.close()
)
outfile_w.close()
errfile_w.close()

self._poller = select.poll()
self._poller.register(self._outfile_r.fileno(),
select.POLLIN | select.POLLPRI)
self._poller.register(self._errfile_r.fileno(),
select.POLLIN | select.POLLPRI)
self._poller = select.poll()
self._poller.register(self._outfile_r.fileno(),
select.POLLIN | select.POLLPRI)
self._poller.register(self._errfile_r.fileno(),
select.POLLIN | select.POLLPRI)

def __getattr__(self, name):
"""Handles transparent proxying to gdb subprocess.
Expand Down Expand Up @@ -202,6 +204,15 @@ def Kill(self):
self._errfile_r.close()
self._outfile_r.close()

@property
def is_installed(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is only used once in __init__ (as soon as we know it's installed, we don't have to check anymore), I propose inlining this in the form of

executable_name = _GDB_ARGS[0]
if not distutils.spawn.find_executable(executable_name):
  raise OSError('executable could not be found, is gdb installed?')

(Also, a gentle reminder towards CONTRIBUTING.md. As this project is owned by Google, you'll have to sign a CLA before we can accept pull requests.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TehMillhouse Hi CLA signed I will try to push refactored code tomorrow.

""" Check if gdb is installed """
gdb_path = distutils.spawn.find_executable("gdb")
if not gdb_path:
raise OSError("I can not find gdb")
else:
return True

@property
def is_running(self):
return self._process.poll() is None
Expand Down