some code cleanup in ktap_types.h

kill _ktap_value, it exist in there for no good reason.
No functional change.

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

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
add sample script scripts/syscalls/execve.kp

Example:

	# ./ktap scripts/syscalls/execve.kp

	[do_execve entry]: (bash) name=/usr/bin/ls
	[do_execve entry]: (bash) name=/usr/bin/top
	[do_execve entry]: (bash) name=/usr/bin/ls
	...

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
introduce sort_pairs for ordered table iteration

sort_pairs is purposed for ordered table iteration,
if only one argument is given, it will use default
compare function <example 1>, otherwise, it use
closure function given by user like <example 2>.

Example 1:
	for (k, v in sort_pairs(s)) {
		print(k)
		print(v)
	}

Example 2:
	function cmp(v1, v2) {
		return (v1 > v2))
	}
	for (k, v in sort_pairs(s, cmp)) {
		print(k)
		print(v)
	}

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
use sort_pairs in stack_profile.kp

dump the stack profile data in ordered format.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
add testcase for sort_pairs built-in function

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

No functional change.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
ktap v0.3 released

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
Add token '`' to support kernel symbol read

When using "`symbol_name`" in the script, parser will read symbol name
from kernel. Then, the symbol is replaced by a constant number, which
indicates its address in the kernel, or makes the compile fail.

Tested:
test/ksym.kp: Parse kernel symbol names.

Signed-off-by: Yicheng Qin <qycqycqycqycqyc@gmail.com>
Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
 - Jovi: Use "ksym" instead of symbol, represent kernel symobl reading,
         not userspace symobl.
         Move read_ksym function to util.c
         better error handing when find symobl failure.
fix performance regression in test/bench/test.sh

ktap overhead increased when using task-bound tracing,
the reason is there have a lot of perf-event schedule
in and schedule out when using task-bound tracing.

So change it back to system tracing.

Before:
run time 30 seconds 200248 worker burns per second

After:
run time 30 seconds 250742 worker burns per second

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
fix prefix matching bug for kernel symbol reading

A bug was found as following:

	# ./ktap -e 'printf("0x%x\n", `sched_clock_`)'
	0xffffffff8106388d

Actually "sched_clock_" symbol is not exist in /proc/kallsyms,
the symbol matched the prefix of "sched_clock_local" wrongly.

	ffffffff8106388d t sched_clock_local
	ffffffff810638ff T sched_clock_init

After this patch:

	# ./ktap -e 'printf("0x%x\n", `sched_clock_`)'
	cannot read kernel symbol "sched_clock_" in /proc/kallsyms

	# ./ktap -e 'printf("0x%x\n", `sched_clock_local`)'
        0xffffffff8106388d

Signed-off-by: Qingping Hou <qingping.hou@gmail.com>
Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
 (Jovi: changelog update; code rewrite)
add new symbol module to search symbols in DSO (for uprobes)

This will allow to don't hardcoding addresses of functions in ktap
scripts, that use uprobes, but instead, use normal function names.

Before this patch:
$ ktap -e 'trace probe:/path/to/bin:0xDEADBEAF' # instead some real address

After this path:
$ ktap -e 'trace probe:/path/to/bin:foo'

Works also for ret probes (%return)
Requires libelf.

Have NO_LIBELF option for makefile, for cross-builds.

Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
minor fix uprobe symbol resloving

- add error handling when symbol not found
- disable symbol resloving when NO_LIBELF enabled
- coding style minor fix

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
add sample script: scripts/userspace/malloc_free.kp

Use symbol(malloc and free) in uprobe sample script,
instead real symbol offset address.

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

Signed-off-by: Qingping Hou <qingping.hou@gmail.com>
Acked-by: Yicheng Qin <qycqycqycqycqyc@gmail.com>
use symbol names instead of hard-coded addresses for uprobe examples

Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
add sample script: scripts/userspace/malloc_size_hist.kp

This sample script aggregate system or process malloc size.

Signed-off-by: Jovi Zhangwei <jovi.zhangwei@gmail.com>
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>