14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
"""Support for running strace against the current process."""
34
33
:return: a tuple: function-result, a StraceResult.
36
return strace_detailed(function, args, kwargs)
39
def strace_detailed(function, args, kwargs, follow_children=True):
40
# FIXME: strace is buggy
41
# (https://bugs.launchpad.net/ubuntu/+source/strace/+bug/103133) and the
42
# test suite hangs if the '-f' is given to strace *and* more than one
43
# thread is running. Using follow_children=False allows the test suite to
44
# disable fork following to work around the bug.
46
35
# capture strace output to a file
47
log_file = tempfile.NamedTemporaryFile()
36
log_file = tempfile.TemporaryFile()
48
37
log_file_fd = log_file.fileno()
51
strace_cmd = ['strace', '-r', '-tt', '-p', str(pid), '-o', log_file.name]
53
strace_args.append('-f')
54
proc = subprocess.Popen(strace_cmd,
55
stdout=subprocess.PIPE,
56
stderr=subprocess.STDOUT)
57
# Wait for strace to attach
58
attached_notice = proc.stdout.readline()
59
# Run the function to strace
40
proc = subprocess.Popen(['strace',
41
'-f', '-r', '-tt', '-p', str(pid),
45
# TODO? confirm its started (test suite should be sufficient)
46
# (can loop on proc.pid, but that may not indicate started and attached.)
60
47
result = function(*args, **kwargs)
62
49
os.kill(proc.pid, signal.SIGQUIT)