diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-09-28 11:56:00 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-09-28 14:36:03 -0400 |
commit | e10a935438f282817f0fbe854b7006266a13ef1b (patch) | |
tree | df9f79c42860e8c14228075bdc571e6c3399dcb6 | |
parent | 7592b9711d9b43be64bfb93fb2e91e7b2c4b141f (diff) |
trace-cmd: Do not make trace-cmd have to build with ptrace
If ptrace is not available on an OS or arch, do not fail the build.
Simply do not support the child tracing feature.
Reported-by: Shawn Bohrer <sbohrer@rgmadvisors.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | features.mk | 36 | ||||
-rw-r--r-- | trace-record.c | 62 |
3 files changed, 88 insertions, 24 deletions
@@ -13,7 +13,6 @@ FILE_VERSION = 6 | |||
13 | 13 | ||
14 | MAKEFLAGS += --no-print-directory | 14 | MAKEFLAGS += --no-print-directory |
15 | 15 | ||
16 | |||
17 | # Makefiles suck: This macro sets a default value of $(2) for the | 16 | # Makefiles suck: This macro sets a default value of $(2) for the |
18 | # variable named by $(1), unless the variable has been set by | 17 | # variable named by $(1), unless the variable has been set by |
19 | # environment or command line. This is necessary for CC and AR | 18 | # environment or command line. This is necessary for CC and AR |
@@ -205,9 +204,22 @@ KERNELSHARK_VERSION = $(KS_VERSION).$(KS_PATCHLEVEL).$(KS_EXTRAVERSION) | |||
205 | 204 | ||
206 | INCLUDES = -I. -I/usr/local/include $(CONFIG_INCLUDES) | 205 | INCLUDES = -I. -I/usr/local/include $(CONFIG_INCLUDES) |
207 | 206 | ||
207 | include features.mk | ||
208 | |||
208 | # Set compile option CFLAGS if not set elsewhere | 209 | # Set compile option CFLAGS if not set elsewhere |
209 | CFLAGS ?= -g -Wall | 210 | CFLAGS ?= -g -Wall |
210 | 211 | ||
212 | ifndef NO_PTRACE | ||
213 | ifneq ($(call try-cc,$(SOURCE_PTRACE),),y) | ||
214 | NO_PTRACE = 1 | ||
215 | CFLAGS += -DWARN_NO_PTRACE | ||
216 | endif | ||
217 | endif | ||
218 | |||
219 | ifdef NO_PTRACE | ||
220 | CFLAGS += -DNO_PTRACE | ||
221 | endif | ||
222 | |||
211 | # Append required CFLAGS | 223 | # Append required CFLAGS |
212 | override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) | 224 | override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) |
213 | override CFLAGS += $(udis86-flags) | 225 | override CFLAGS += $(udis86-flags) |
diff --git a/features.mk b/features.mk new file mode 100644 index 0000000..cb2e8bd --- /dev/null +++ b/features.mk | |||
@@ -0,0 +1,36 @@ | |||
1 | |||
2 | # taken from perf which was based on Linux Kbuild | ||
3 | # try-cc | ||
4 | # Usage: option = $(call try-cc, source-to-build, cc-options) | ||
5 | try-cc = $(shell sh -c \ | ||
6 | 'TMP="$(BUILD_OUTPUT)$(TMPOUT).$$$$"; \ | ||
7 | echo "$(1)" | \ | ||
8 | $(CC) -x c - $(2) -o "$$TMP" > /dev/null 2>&1 && echo y; \ | ||
9 | rm -f "$$TMP"') | ||
10 | |||
11 | define SOURCE_PTRACE | ||
12 | #include <stdio.h> | ||
13 | #include <sys/ptrace.h> | ||
14 | |||
15 | int main (void) | ||
16 | { | ||
17 | int ret; | ||
18 | ret = ptrace(PTRACE_ATTACH, 0, NULL, 0); | ||
19 | ptrace(PTRACE_TRACEME, 0, NULL, 0); | ||
20 | ptrace(PTRACE_GETSIGINFO, 0, NULL, NULL); | ||
21 | ptrace(PTRACE_GETEVENTMSG, 0, NULL, NULL); | ||
22 | ptrace(PTRACE_SETOPTIONS, NULL, NULL, | ||
23 | PTRACE_O_TRACEFORK | | ||
24 | PTRACE_O_TRACEVFORK | | ||
25 | PTRACE_O_TRACECLONE | | ||
26 | PTRACE_O_TRACEEXIT); | ||
27 | ptrace(PTRACE_CONT, NULL, NULL, 0); | ||
28 | ptrace(PTRACE_DETACH, 0, NULL, NULL); | ||
29 | ptrace(PTRACE_SETOPTIONS, 0, NULL, | ||
30 | PTRACE_O_TRACEFORK | | ||
31 | PTRACE_O_TRACEVFORK | | ||
32 | PTRACE_O_TRACECLONE | | ||
33 | PTRACE_O_TRACEEXIT); | ||
34 | return ret; | ||
35 | } | ||
36 | endef | ||
diff --git a/trace-record.c b/trace-record.c index 45439f4..90589cf 100644 --- a/trace-record.c +++ b/trace-record.c | |||
@@ -31,7 +31,13 @@ | |||
31 | #include <sys/time.h> | 31 | #include <sys/time.h> |
32 | #include <sys/wait.h> | 32 | #include <sys/wait.h> |
33 | #include <sys/socket.h> | 33 | #include <sys/socket.h> |
34 | #ifndef NO_PTRACE | ||
34 | #include <sys/ptrace.h> | 35 | #include <sys/ptrace.h> |
36 | #else | ||
37 | #ifdef WARN_NO_PTRACE | ||
38 | #warning ptrace not supported. -c feature will not work | ||
39 | #endif | ||
40 | #endif | ||
35 | #include <netdb.h> | 41 | #include <netdb.h> |
36 | #include <pthread.h> | 42 | #include <pthread.h> |
37 | #include <fcntl.h> | 43 | #include <fcntl.h> |
@@ -370,6 +376,30 @@ static void | |||
370 | update_sched_event(struct event_list **event, const char *file, | 376 | update_sched_event(struct event_list **event, const char *file, |
371 | const char *pid_filter, const char *field_filter); | 377 | const char *pid_filter, const char *field_filter); |
372 | 378 | ||
379 | static void update_task_filter(void) | ||
380 | { | ||
381 | int pid = getpid(); | ||
382 | char spid[100]; | ||
383 | |||
384 | if (!filter_task && filter_pid < 0) { | ||
385 | update_ftrace_pid("", 1); | ||
386 | enable_tracing(); | ||
387 | return; | ||
388 | } | ||
389 | |||
390 | if (filter_pid >= 0) | ||
391 | pid = filter_pid; | ||
392 | |||
393 | snprintf(spid, 100, "%d", pid); | ||
394 | |||
395 | update_ftrace_pid(spid, 1); | ||
396 | |||
397 | update_pid_event_filters(spid); | ||
398 | |||
399 | enable_tracing(); | ||
400 | } | ||
401 | |||
402 | #ifndef NO_PTRACE | ||
373 | static char *make_pid_filter(const char *field) | 403 | static char *make_pid_filter(const char *field) |
374 | { | 404 | { |
375 | struct filter_pids *p; | 405 | struct filter_pids *p; |
@@ -430,29 +460,6 @@ static void add_new_filter_pid(int pid) | |||
430 | free(filter); | 460 | free(filter); |
431 | } | 461 | } |
432 | 462 | ||
433 | static void update_task_filter(void) | ||
434 | { | ||
435 | int pid = getpid(); | ||
436 | char spid[100]; | ||
437 | |||
438 | if (!filter_task && filter_pid < 0) { | ||
439 | update_ftrace_pid("", 1); | ||
440 | enable_tracing(); | ||
441 | return; | ||
442 | } | ||
443 | |||
444 | if (filter_pid >= 0) | ||
445 | pid = filter_pid; | ||
446 | |||
447 | snprintf(spid, 100, "%d", pid); | ||
448 | |||
449 | update_ftrace_pid(spid, 1); | ||
450 | |||
451 | update_pid_event_filters(spid); | ||
452 | |||
453 | enable_tracing(); | ||
454 | } | ||
455 | |||
456 | static void ptrace_attach(int pid) | 463 | static void ptrace_attach(int pid) |
457 | { | 464 | { |
458 | int ret; | 465 | int ret; |
@@ -529,6 +536,12 @@ static void ptrace_wait(int main_pid) | |||
529 | } while (!finished && ret > 0 && | 536 | } while (!finished && ret > 0 && |
530 | (!WIFEXITED(status) || pid != main_pid)); | 537 | (!WIFEXITED(status) || pid != main_pid)); |
531 | } | 538 | } |
539 | #else | ||
540 | static inline void ptrace_wait(int main_pid) { } | ||
541 | static inline void enable_ptrace(void) { } | ||
542 | static inline void ptrace_attach(int pid) { } | ||
543 | |||
544 | #endif /* NO_PTRACE */ | ||
532 | 545 | ||
533 | void trace_or_sleep(void) | 546 | void trace_or_sleep(void) |
534 | { | 547 | { |
@@ -2023,6 +2036,9 @@ void trace_record (int argc, char **argv) | |||
2023 | filter_pid = atoi(optarg); | 2036 | filter_pid = atoi(optarg); |
2024 | break; | 2037 | break; |
2025 | case 'c': | 2038 | case 'c': |
2039 | #ifdef NO_PTRACE | ||
2040 | die("-c invalid: ptrace not supported"); | ||
2041 | #endif | ||
2026 | do_ptrace = 1; | 2042 | do_ptrace = 1; |
2027 | break; | 2043 | break; |
2028 | case 'v': | 2044 | case 'v': |