Messages in this thread | | | Date | Mon, 11 May 2015 09:24:19 +0900 | From | Masami Hiramatsu <> | Subject | Re: vsprintf: Add support for userspace strings |
| |
On 2015/05/11 4:42, Richard Weinberger wrote: > While debugging issues I often add (trace_)printks to strategic positions. > Dealing with user provided string is complicated as an extra buffer a > copy_from_user() is needed. > This adds a new format string to allow direct printing of such strings. > > My initial plan was to use %pU but 'U' is already taken, therefore > I used the next letter which comes in mind when one thinks of userpace, > 'L'. > The %pL format string works exactly like %s.
BTW, if you need to do this for debug, you can also use ftrace's kprobe-tracer (and perf probe) which allows you to dump userspace strings :)
Here is an example. ----- [mhiramat@localhost perf]$ ./perf probe -L do_sys_open:0-3 <do_sys_open@/usr/src/debug/kernel-3.10.0-229.1.2.el7/linux-3.10.0-229.1.2.el7.x 0 long do_sys_open(int dfd, const char __user *filename, int flags, umode 1 { struct open_flags op; 3 int lookup = build_open_flags(flags, mode, &op); [mhiramat@localhost perf]$ ./perf probe -V do_sys_open Available variables at do_sys_open @<do_sys_open+0> char* filename int dfd int flags int lookup struct open_flags op umode_t mode [mhiramat@localhost perf]$ sudo ./perf probe do_sys_open filename:string Added new event: probe:do_sys_open (on do_sys_open with filename:string)
You can now use it in all perf tools, such as:
perf record -e probe:do_sys_open -aR sleep 1
[mhiramat@localhost perf]$ sudo ./perf record -e probe:do_sys_open -a ls &> /dev/null [mhiramat@localhost perf]$ sudo ./perf script | more ls 7238 [003] 1629305.250347: probe:do_sys_open: (ffffffff811c5e40) filename_string="/etc/ld.so.cache" ls 7238 [003] 1629305.250384: probe:do_sys_open: (ffffffff811c5e40) filename_string="/lib64/libselinux.so.1" ls 7238 [003] 1629305.250501: probe:do_sys_open: (ffffffff811c5e40) filename_string="/lib64/libcap.so.2" ls 7238 [003] 1629305.250562: probe:do_sys_open: (ffffffff811c5e40) filename_string="/lib64/libacl.so.1" ls 7238 [003] 1629305.250631: probe:do_sys_open: (ffffffff811c5e40) filename_string="/lib64/libc.so.6" ls 7238 [003] 1629305.250706: probe:do_sys_open: (ffffffff811c5e40) filename_string="/lib64/libpcre.so.1" ls 7238 [003] 1629305.250769: probe:do_sys_open: (ffffffff811c5e40) filename_string="/lib64/liblzma.so.5" ls 7238 [003] 1629305.250838: probe:do_sys_open: (ffffffff811c5e40) filename_string="/lib64/libdl.so.2" ls 7238 [003] 1629305.250898: probe:do_sys_open: (ffffffff811c5e40) filename_string="/lib64/libattr.so.1" ls 7238 [003] 1629305.250959: probe:do_sys_open: (ffffffff811c5e40) filename_string="/lib64/libpthread.so.0" ls 7238 [003] 1629305.251591: probe:do_sys_open: (ffffffff811c5e40) filename_string="" ls 7238 [003] 1629305.251695: probe:do_sys_open: (ffffffff811c5e40) filename_string="." [mhiramat@localhost perf]$ sudo ./perf probe -d \* Removed event: probe:do_sys_open -----
Thank you,
-- Masami HIRAMATSU Linux Technology Research Center, System Productivity Research Dept. Center for Technology Innovation - Systems Engineering Hitachi, Ltd., Research & Development Group E-mail: masami.hiramatsu.pt@hitachi.com
| |