Add COPYRIGHT file in top-level directory

Also include lua MIT full license text in COPYRIGHT file,

lua claimed(http://www.lua.org/license.html):

"The above copyright notice and this permission notice shall be included
 in all copies or substantial portions of the Software."

So only copyright notice included in each file header is not
enough.

Note ktap is licensed as GPL v2, this is compatible with MIT license,
and confirmed with official lua team(team@lua.org).

Original discussion:

>> what's this "compatible with GPL" really means?
>> Would I redistribute ktap as GPL licensed with lua MIT Copyright notice put in somewhere? or use "Dual MIT/GPL" license?

> Both solutions are fine.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
update doc/tutorial.md

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
Set PWD in Makefile

When cross-compiling using e.g. buildroot, PWD was not reset in the Makefile.
That caused PWD to have an incorrect value, and thus building the module failed.

Signed-off-by: Anders Darander <anders@chargestorm.se>
interpreter/vm.c: include uaccess.h

otherwise functions, such as copy_from_user, is implicitly defined.

Signed-off-by: Anders Darander <anders@chargestorm.se>
symbol: add elf_section_by_name() helper (based on linux/perf/symbol-elf.c)

Add a helper for searching section in elf by it name.
Drop from original unused arguments, and variables.

Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
symbol: add helpers for sdt probes.

Next helpers was added:
- search_stapsdt_note()
- sdt_note_data()
- sdt_note_name()
- sdt_note_addr()

Based on this patch set: https://lkml.org/lkml/2013/10/23/10

Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
stapsdt: initial support for probing sdt notes.

For parsing ktap scripts, uprobes functions are used for stapsdt probes
too, the only differ between then is type argument, which is bypassed up
to find_symbol() that's it.

Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
scripts: add test script for stapsdt probes

The only library in /lib/x86_64-linux-gnu that have sdt notes is
libgcc_s on by machine, with unwind marker.
So this patch add a simple ktap script that use it.

Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
sdt: replace "stapsdt" to just "sdt"

It more shorter, and simpler.

Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
fix possible segmentation fault without symbol

As Jovi noticed:
    Segmentation fault for "trace sdt:/lib64/libc.so.6 {...}"
    No symbol given in that case.

Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
check libelf dependency in Makefile

If no libelf found, then NO_LIBELF will set, and
disable symbol resolving in ktap(like uprobe and sdt).

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
support run multiple ktap instances concurrently

This patch move percpu global variables and tstring_lock
into ktap_global_state, so we can run multiple ktap
instances concurrently now.
(global percpu variable will make memory corruption,
and global tstring_lock will make system deadlock)

Performance impact(a little overhead):
tesed by test/bench

Before:
247360
247294
248100

After:
243764
242612
243406

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
fix pid() bug when running ktap concurrently

A kernel oops bug found when running two ktap instances concurrently
using below ktap one-liner.

	ktap -e "trace *:* {print(pid()}"

When one ktap instance exited, kernel oops.

 174 [  471.611139] Call Trace:
 175 [  471.611139]  [<ffffffffa004a414>] ktap_lib_pid+0x24/0x50 [ktapvm]
 176 [  471.611139]  [<ffffffffa0045d70>] precall+0xf0/0x320 [ktapvm]
 177 [  471.611139]  [<ffffffffa0046861>] kp_call+0x6d1/0x1950 [ktapvm]
 178 [  471.611139]  [<ffffffffa0046722>] ? kp_call+0x592/0x1950 [ktapvm]
 179 [  471.611139]  [<ffffffffa004a4a0>] ? ktap_lib_print_trace_clock+0x60/0x60      [ktapvm]
 180 [  471.611139]  [<ffffffffa004b0ee>] ktap_overflow_callback+0x10e/0x150 [kt     apvm]
 181 [  471.611139]  [<ffffffff8111fc02>] __perf_event_overflow+0x92/0x270
 182 [  471.611139]  [<ffffffff8111fc02>] ? __perf_event_overflow+0x92/0x270
 183 [  471.611139]  [<ffffffff8111ff71>] perf_swevent_overflow+0x51/0xe0
 184 [  471.611139]  [<ffffffff8112005f>] perf_swevent_event+0x5f/0x90
 185 [  471.611139]  [<ffffffff81120167>] perf_tp_event+0xd7/0x220
 186 [  471.611139]  [<ffffffff8112005f>] ? perf_swevent_event+0x5f/0x90
 187 [  471.611139]  [<ffffffff810b84e4>] perf_trace_lock_acquire+0x134/0x150
 188 [  471.611139]  [<ffffffff810bc848>] ? lock_acquire+0xf8/0x110
 189 [  471.611139]  [<ffffffff810bc848>] lock_acquire+0xf8/0x110
 190 [  471.611139]  [<ffffffff810722c2>] ? free_pid+0x22/0x150
 191 [  471.611139]  [<ffffffff8161c64c>] _raw_spin_lock_irqsave+0x3c/0x50
 192 [  471.611139]  [<ffffffff810722c2>] ? free_pid+0x22/0x150
 193 [  471.611139]  [<ffffffff810722c2>] free_pid+0x22/0x150
 194 [  471.611139]  [<ffffffff8107244a>] __change_pid+0x5a/0x60
 195 [  471.611139]  [<ffffffff81072970>] detach_pid+0x10/0x20
 196 [  471.611139]  [<ffffffff810538c3>] release_task+0x233/0x460
 197 [  471.611139]  [<ffffffff810536a9>] ? release_task+0x19/0x460
 198 [  471.611139]  [<ffffffff810ba23d>] ? trace_hardirqs_on_caller+0xfd/0x1c0
 199 [  471.611139]  [<ffffffff810540de>] do_exit+0x5ee/0xa20
 200 [  471.611139]  [<ffffffff810e3bfc>] ? __audit_syscall_entry+0x9c/0xf0
 201 [  471.611139]  [<ffffffff8100f44d>] ? syscall_trace_enter+0x21d/0x230
 202 [  471.611139]  [<ffffffff810553c7>] SyS_exit+0x17/0x20
 203 [  471.611139]  [<ffffffff81625524>] tracesys+0xdd/0xe2
 204 [  471.611139] Code: 00 55 65 48 8b 04 25 00 ba 00 00 48 8b 80 40 03 00 00      48 89 e5 48 85 c0 74 3a 8b 50 04 48 c1 e2 05 48 85 ff 48 8b 54 10 38 74 31      <8b> 8a 20 08 00 00 31 c0 3b 4f 04 77 0f 48 c1 e1 05 48 8d 4c 0f
 205 [  471.611139] RIP  [<ffffffff81071e0f>] pid_vnr+0x2f/0x70

The reason is ns argument is NULL when tracing callback called in free_pid,
to fix this problem, use current->pid instead of task_tgid_vnr(current).

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
rename file name under interpreter/

prefix core file with "kp_", prefix library file with "lib_".

Also move kp_strfmt function into kp_str.c.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>