pmachata pushed to ltrace (f21). "Fix tracing of multi-threaded processes without -f"

notifications at fedoraproject.org notifications at fedoraproject.org
Wed Apr 8 14:59:59 UTC 2015


>From 44de39e5d1d6910030f17a159e564874b7fb1618 Mon Sep 17 00:00:00 2001
From: Petr Machata <pmachata at redhat.com>
Date: Wed, 8 Apr 2015 15:10:37 +0200
Subject: Fix tracing of multi-threaded processes without -f


diff --git a/ltrace-0.7.91-multithread-no-f-1.patch b/ltrace-0.7.91-multithread-no-f-1.patch
new file mode 100644
index 0000000..0589f5e
--- /dev/null
+++ b/ltrace-0.7.91-multithread-no-f-1.patch
@@ -0,0 +1,175 @@
+From 4724bd5a4a19db117a1d280b9d1a3508fd4e03fa Mon Sep 17 00:00:00 2001
+From: Petr Machata <pmachata at redhat.com>
+Date: Wed, 8 Apr 2015 07:11:52 -0400
+Subject: [PATCH 1/2] Convert main-threaded test case to new style
+
+---
+ testsuite/ltrace.main/Makefile.am       |   4 +-
+ testsuite/ltrace.main/main-threaded.c   |  30 ----------
+ testsuite/ltrace.main/main-threaded.exp | 103 ++++++++++++++++++++------------
+ 3 files changed, 66 insertions(+), 71 deletions(-)
+ delete mode 100644 testsuite/ltrace.main/main-threaded.c
+
+diff --git a/testsuite/ltrace.main/Makefile.am b/testsuite/ltrace.main/Makefile.am
+index 23ab8ab..06ad613 100644
+--- a/testsuite/ltrace.main/Makefile.am
++++ b/testsuite/ltrace.main/Makefile.am
+@@ -1,4 +1,4 @@
+-# Copyright (C) 1992 - 2001, 2012, 2013 Free Software Foundation, Inc.
++# Copyright (C) 1992 - 2001, 2012, 2013, 2015 Free Software Foundation, Inc.
+ #
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+@@ -17,7 +17,7 @@
+ 
+ EXTRA_DIST = branch_func.c branch_func.exp filters.exp hello-vfork.c	\
+ 	hello-vfork.exp main.c main.exp main-internal.exp main-lib.c	\
+-	main-threaded.c main-threaded.exp main-vfork.c main-vfork.exp	\
++	main-threaded.exp main-vfork.c main-vfork.exp			\
+ 	parameters.c parameters.conf parameters.exp parameters-lib.c	\
+ 	parameters2.exp parameters3.exp signals.c signals.exp		\
+ 	system_calls.c system_calls.exp system_call_params.exp
+diff --git a/testsuite/ltrace.main/main-threaded.c b/testsuite/ltrace.main/main-threaded.c
+deleted file mode 100644
+index 2992d1e..0000000
+--- a/testsuite/ltrace.main/main-threaded.c
++++ /dev/null
+@@ -1,29 +0,0 @@
+-#include <pthread.h>
+-
+-extern void print (char *);
+-
+-#define	PRINT_LOOP	10
+-
+-void *
+-th_main (void *arg)
+-{
+-  int i;
+-  for (i=0; i<PRINT_LOOP; i++)
+-    print (arg);
+-}
+-
+-int
+-main ()
+-{
+-  pthread_t thread1;
+-  pthread_t thread2;
+-  pthread_t thread3;
+-  pthread_create (&thread1, NULL, th_main, "aaa");
+-  pthread_create (&thread2, NULL, th_main, "bbb");
+-  pthread_create (&thread3, NULL, th_main, "ccc");
+-  pthread_join (thread1, NULL);
+-  pthread_join (thread2, NULL);
+-  pthread_join (thread3, NULL);
+-  return 0;
+-}
+-
+diff --git a/testsuite/ltrace.main/main-threaded.exp b/testsuite/ltrace.main/main-threaded.exp
+index 4d5f478..cead82d 100644
+--- a/testsuite/ltrace.main/main-threaded.exp
++++ b/testsuite/ltrace.main/main-threaded.exp
+@@ -1,39 +1,64 @@
+-# This file was written by Yao Qi <qiyao at cn.ibm.com>.
++# This file is part of ltrace.
++# Copyright (C) 2011, 2015 Petr Machata, Red Hat Inc.
++# Copyright (C) 2006 Yao Qi <qiyao at cn.ibm.com>.
++#
++# This program is free software; you can redistribute it and/or
++# modify it under the terms of the GNU General Public License as
++# published by the Free Software Foundation; either version 2 of the
++# License, or (at your option) any later version.
++#
++# This program is distributed in the hope that it will be useful, but
++# WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++# General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
++# 02110-1301 USA
++
++set libprint [ltraceCompile libprint.so [ltraceSource c {
++    #include<stdio.h>
++
++    void
++    print(char* s)
++    {
++	printf("%s\n",s);
++    }
++}]]
++
++set bin [ltraceCompile {} $libprint -lpthread [ltraceSource c {
++    #include <pthread.h>
++
++    extern void print (char *);
++
++    #define	PRINT_LOOP	10
++
++    void *
++    th_main (void *arg)
++    {
++	int i;
++	for (i=0; i<PRINT_LOOP; i++)
++	print (arg);
++	return NULL;
++    }
++
++    int
++    main (void)
++    {
++	pthread_t thread1;
++	pthread_t thread2;
++	pthread_t thread3;
++	pthread_create (&thread1, NULL, th_main, "aaa");
++	pthread_create (&thread2, NULL, th_main, "bbb");
++	pthread_create (&thread3, NULL, th_main, "ccc");
++	pthread_join (thread1, NULL);
++	pthread_join (thread2, NULL);
++	pthread_join (thread3, NULL);
++	return 0;
++    }
++}]]
+ 
+-set testfile "main-threaded"
+-set srcfile ${testfile}.c
+-set binfile ${testfile}
+-set libfile "main-lib"
+-set libsrc $srcdir/$subdir/$libfile.c
+-set lib_sl $objdir/$subdir/lib$testfile.so
+-
+-
+-if [get_compiler_info $binfile] {
+-  return -1
+-}
+-
+-verbose "compiling source file now....."
+-if { [ltrace_compile_shlib $libsrc $lib_sl debug ] != "" 
+-  || [ltrace_compile $srcdir/$subdir/$srcfile $objdir/$subdir/$binfile executable [list debug shlib=$lib_sl ldflags=-pthread] ] != ""} {
+-  send_user "Testcase compile failed, so all tests in this file will automatically fail.\n"
+-}
+-
+-# set options for ltrace.
+-ltrace_options "-l" "lib$testfile.so" "-f"
+-
+-# Run PUT for ltarce.
+-set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile]
+-
+-# Check the output of this program.
+-verbose "ltrace runtest output: $exec_output\n"
+-if [regexp {ELF from incompatible architecture} $exec_output] {
+-	fail "32-bit ltrace can not perform on 64-bit PUTs and rebuild ltrace in 64 bit mode!"
+-	return 
+-} elseif [ regexp {Couldn't get .hash data} $exec_output ] {
+-	fail "Couldn't get .hash data!"
+-	return
+-}
+-
+-# Verify the output by checking numbers of print in main-threaded.ltrace.
+-set pattern "print"
+-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 30
++ltraceMatch1 [ltraceRun -f -l libprint.so -- $bin] {print\(} == 30
++
++ltraceDone
+Only in ltrace.main: main-threaded.exp~
+Only in ltrace.main: .main-threaded.exp.~undo-tree~
diff --git a/ltrace-0.7.91-multithread-no-f-2.patch b/ltrace-0.7.91-multithread-no-f-2.patch
new file mode 100644
index 0000000..af792b9
--- /dev/null
+++ b/ltrace-0.7.91-multithread-no-f-2.patch
@@ -0,0 +1,50 @@
+From 72ee29639c55b5942bc07c8ed0013005f8fc5a97 Mon Sep 17 00:00:00 2001
+From: Petr Machata <pmachata at redhat.com>
+Date: Wed, 8 Apr 2015 07:14:10 -0400
+Subject: [PATCH 2/2] Fix tracing multi-threaded processes without -f
+
+- In handle_syscall, we avoid touching stack of ignored processes.
+  But in handle_sysret, we require a sysret-like stack entry even
+  for ignored processes, even though we then go ahead to not act
+  on that stack entry.  Instead, for ignored processes, avoid looking
+  at stack trace at all.
+---
+ handle_event.c                          | 10 +++++-----
+ testsuite/ltrace.main/main-threaded.exp |  1 +
+ 2 files changed, 6 insertions(+), 5 deletions(-)
+
+diff --git a/handle_event.c b/handle_event.c
+index 6fa7e98..c2550ad 100644
+--- a/handle_event.c
++++ b/handle_event.c
+@@ -619,12 +619,12 @@ handle_x_sysret(Event *event, char *(*name_cb)(struct process *, int))
+ 	debug(DEBUG_FUNCTION, "handle_x_sysret(pid=%d, sysnum=%d)",
+ 	      event->proc->pid, event->e_un.sysnum);
+ 
+-	unsigned d = event->proc->callstack_depth;
+-	assert(d > 0);
+-	struct callstack_element *elem = &event->proc->callstack[d - 1];
+-	assert(elem->is_syscall);
+-
+ 	if (event->proc->state != STATE_IGNORED) {
++		unsigned d = event->proc->callstack_depth;
++		assert(d > 0);
++		struct callstack_element *elem = &event->proc->callstack[d - 1];
++		assert(elem->is_syscall);
++
+ 		struct timedelta spent = calc_time_spent(elem->enter_time);
+ 		if (options.syscalls)
+ 			output_syscall_right(event->proc,
+diff --git a/testsuite/ltrace.main/main-threaded.exp b/testsuite/ltrace.main/main-threaded.exp
+index cead82d..aca7afd 100644
+--- a/testsuite/ltrace.main/main-threaded.exp
++++ b/testsuite/ltrace.main/main-threaded.exp
+@@ -60,5 +60,6 @@ set bin [ltraceCompile {} $libprint -lpthread [ltraceSource c {
+ }]]
+ 
+ ltraceMatch1 [ltraceRun -f -l libprint.so -- $bin] {print\(} == 30
++ltraceMatch1 [ltraceRun -L -- $bin] exited == 1
+ 
+ ltraceDone
+-- 
+2.1.0
diff --git a/ltrace.spec b/ltrace.spec
index fec1494..6524ace 100644
--- a/ltrace.spec
+++ b/ltrace.spec
@@ -1,7 +1,7 @@
 Summary: Tracks runtime library calls from dynamically linked executables
 Name: ltrace
 Version: 0.7.91
-Release: 13%{?dist}
+Release: 14%{?dist}
 URL: http://ltrace.alioth.debian.org/
 License: GPLv2+
 Group: Development/Debuggers
@@ -79,6 +79,12 @@ Patch18: ltrace-0.7.91-x86-unused_label.patch
 # https://bugzilla.redhat.com/show_bug.cgi?id=1170315
 Patch19: ltrace-0.7.91-unwind-elfutils.patch
 
+# https://bugzilla.redhat.com/show_bug.cgi?id=1208351
+# http://anonscm.debian.org/cgit/collab-maint/ltrace.git/commit/?id=4724bd5a4a19db117a1d280b9d1a3508fd4e03fa
+# http://anonscm.debian.org/cgit/collab-maint/ltrace.git/commit/?id=72ee29639c55b5942bc07c8ed0013005f8fc5a97
+Patch20: ltrace-0.7.91-multithread-no-f-1.patch
+Patch21: ltrace-0.7.91-multithread-no-f-2.patch
+
 %description
 Ltrace is a debugging program which runs a specified command until the
 command exits.  While the command is executing, ltrace intercepts and
@@ -110,6 +116,8 @@ execution of processes.
 %patch17 -p1
 %patch18 -p1
 %patch19 -p1
+%patch20 -p1
+%patch21 -p1
 
 %build
 autoreconf -i
-- 
cgit v0.10.2


	http://pkgs.fedoraproject.org/cgit/ltrace.git/commit/?h=f21&id=44de39e5d1d6910030f17a159e564874b7fb1618


More information about the scm-commits mailing list