diff options
author | Roland McGrath <roland@redhat.com> | 2008-07-25 22:45:43 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-26 15:00:08 -0400 |
commit | 88ac2921a71f788ed693bcd44731dd6bc1994640 (patch) | |
tree | db7039299713fec545061f884878563f8ae0caa6 /include | |
parent | 267e2a9c71b8e088ac307f9549f71468e86e26c1 (diff) |
tracehook: add linux/tracehook.h
This patch series introduces the "tracehook" interface layer of inlines in
<linux/tracehook.h>. There are more details in the log entry for patch
01/23 and in the header file comments inside that patch. Most of these
changes move code around with little or no change, and they should not
break anything or change any behavior.
This sets a new standard for uniform arch support to enable clean
arch-independent implementations of new debugging and tracing stuff,
denoted by CONFIG_HAVE_ARCH_TRACEHOOK. Patch 20/23 adds that symbol to
arch/Kconfig, with comments listing everything an arch has to do before
setting "select HAVE_ARCH_TRACEHOOK". These are elaborted a bit at:
http://sourceware.org/systemtap/wiki/utrace/arch/HowTo
The new inlines that arch code must define or call have detailed kerneldoc
comments in the generic header files that say what is required.
No arch is obligated to do any work, and no arch's build should be broken
by these changes. There are several steps that each arch should take so
it can set HAVE_ARCH_TRACEHOOK. Most of these are simple. Providing this
support will let new things people add for doing debugging and tracing of
user-level threads "just work" for your arch in the future. For an arch
that does not provide HAVE_ARCH_TRACEHOOK, some new options for such
features will not be available for config.
I have done some arch work and will submit this to the arch maintainers
after the generic tracehook series settles in. For now, that work is
available in my GIT repositories, and in patch and mbox-of-patches form at
http://people.redhat.com/roland/utrace/2.6-current/
This paves the way for my "utrace" work, to be submitted later. But it is
not innately tied to that. I hope that the tracehook series can go in
soon regardless of what eventually does or doesn't go on top of it. For
anyone implementing any kind of new tracing/debugging plan, or just
understanding all the context of the existing ptrace implementation,
having tracehook.h makes things much easier to find and understand.
This patch:
This adds the new kernel-internal header file <linux/tracehook.h>. This
is not yet used at all. The comments in the header introduce what the
following series of patches is about.
The aim is to formalize and consolidate all the places that the core
kernel code and the arch code now ties into the ptrace implementation.
These patches mostly don't cause any functional change. They just move
the details of ptrace logic out of core code into tracehook.h inlines,
where they are mostly compiled away to the same as before. All that
changes is that everything is thoroughly documented and any future
reworking of ptrace, or addition of something new, would not have to touch
core code all over, just change the tracehook.h inlines.
The new linux/ptrace.h inlines are used by the following patches in the
new tracehook_*() inlines. Using these helpers for the ptrace event stops
makes it simple to change or disable the old ptrace implementation of
these stops conditionally later.
Signed-off-by: Roland McGrath <roland@redhat.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Reviewed-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/ptrace.h | 33 | ||||
-rw-r--r-- | include/linux/tracehook.h | 52 |
2 files changed, 85 insertions, 0 deletions
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index c6f5f9dd0cee..c74abfc4c7e8 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h | |||
@@ -121,6 +121,39 @@ static inline void ptrace_unlink(struct task_struct *child) | |||
121 | int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data); | 121 | int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data); |
122 | int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data); | 122 | int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data); |
123 | 123 | ||
124 | /** | ||
125 | * task_ptrace - return %PT_* flags that apply to a task | ||
126 | * @task: pointer to &task_struct in question | ||
127 | * | ||
128 | * Returns the %PT_* flags that apply to @task. | ||
129 | */ | ||
130 | static inline int task_ptrace(struct task_struct *task) | ||
131 | { | ||
132 | return task->ptrace; | ||
133 | } | ||
134 | |||
135 | /** | ||
136 | * ptrace_event - possibly stop for a ptrace event notification | ||
137 | * @mask: %PT_* bit to check in @current->ptrace | ||
138 | * @event: %PTRACE_EVENT_* value to report if @mask is set | ||
139 | * @message: value for %PTRACE_GETEVENTMSG to return | ||
140 | * | ||
141 | * This checks the @mask bit to see if ptrace wants stops for this event. | ||
142 | * If so we stop, reporting @event and @message to the ptrace parent. | ||
143 | * | ||
144 | * Returns nonzero if we did a ptrace notification, zero if not. | ||
145 | * | ||
146 | * Called without locks. | ||
147 | */ | ||
148 | static inline int ptrace_event(int mask, int event, unsigned long message) | ||
149 | { | ||
150 | if (mask && likely(!(current->ptrace & mask))) | ||
151 | return 0; | ||
152 | current->ptrace_message = message; | ||
153 | ptrace_notify((event << 8) | SIGTRAP); | ||
154 | return 1; | ||
155 | } | ||
156 | |||
124 | #ifndef force_successful_syscall_return | 157 | #ifndef force_successful_syscall_return |
125 | /* | 158 | /* |
126 | * System call handlers that, upon successful completion, need to return a | 159 | * System call handlers that, upon successful completion, need to return a |
diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h new file mode 100644 index 000000000000..bea0f3eeff54 --- /dev/null +++ b/include/linux/tracehook.h | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | * Tracing hooks | ||
3 | * | ||
4 | * Copyright (C) 2008 Red Hat, Inc. All rights reserved. | ||
5 | * | ||
6 | * This copyrighted material is made available to anyone wishing to use, | ||
7 | * modify, copy, or redistribute it subject to the terms and conditions | ||
8 | * of the GNU General Public License v.2. | ||
9 | * | ||
10 | * This file defines hook entry points called by core code where | ||
11 | * user tracing/debugging support might need to do something. These | ||
12 | * entry points are called tracehook_*(). Each hook declared below | ||
13 | * has a detailed kerneldoc comment giving the context (locking et | ||
14 | * al) from which it is called, and the meaning of its return value. | ||
15 | * | ||
16 | * Each function here typically has only one call site, so it is ok | ||
17 | * to have some nontrivial tracehook_*() inlines. In all cases, the | ||
18 | * fast path when no tracing is enabled should be very short. | ||
19 | * | ||
20 | * The purpose of this file and the tracehook_* layer is to consolidate | ||
21 | * the interface that the kernel core and arch code uses to enable any | ||
22 | * user debugging or tracing facility (such as ptrace). The interfaces | ||
23 | * here are carefully documented so that maintainers of core and arch | ||
24 | * code do not need to think about the implementation details of the | ||
25 | * tracing facilities. Likewise, maintainers of the tracing code do not | ||
26 | * need to understand all the calling core or arch code in detail, just | ||
27 | * documented circumstances of each call, such as locking conditions. | ||
28 | * | ||
29 | * If the calling core code changes so that locking is different, then | ||
30 | * it is ok to change the interface documented here. The maintainer of | ||
31 | * core code changing should notify the maintainers of the tracing code | ||
32 | * that they need to work out the change. | ||
33 | * | ||
34 | * Some tracehook_*() inlines take arguments that the current tracing | ||
35 | * implementations might not necessarily use. These function signatures | ||
36 | * are chosen to pass in all the information that is on hand in the | ||
37 | * caller and might conceivably be relevant to a tracer, so that the | ||
38 | * core code won't have to be updated when tracing adds more features. | ||
39 | * If a call site changes so that some of those parameters are no longer | ||
40 | * already on hand without extra work, then the tracehook_* interface | ||
41 | * can change so there is no make-work burden on the core code. The | ||
42 | * maintainer of core code changing should notify the maintainers of the | ||
43 | * tracing code that they need to work out the change. | ||
44 | */ | ||
45 | |||
46 | #ifndef _LINUX_TRACEHOOK_H | ||
47 | #define _LINUX_TRACEHOOK_H 1 | ||
48 | |||
49 | #include <linux/sched.h> | ||
50 | #include <linux/ptrace.h> | ||
51 | |||
52 | #endif /* <linux/tracehook.h> */ | ||