Skip to content

Instantly share code, notes, and snippets.

@anfernee
Created May 8, 2020 05:08
Show Gist options
  • Save anfernee/7936d21ec8dd2b4823e370c3c0b41011 to your computer and use it in GitHub Desktop.
Save anfernee/7936d21ec8dd2b4823e370c3c0b41011 to your computer and use it in GitHub Desktop.
Kernel-Note

Interface

Ref: https://elixir.bootlin.com/linux/v2.6.39/source/kernel/trace/trace.h#L246

Examples

nop tracer

struct tracer nop_trace __read_mostly =
{
	.name		= "nop",
	.init		= nop_trace_init,
	.reset		= nop_trace_reset,
	.wait_pipe	= poll_wait_pipe,
	.flags		= &nop_flags,
	.set_flag	= nop_set_flag
};
/* Our two options */
enum {
	TRACE_NOP_OPT_ACCEPT = 0x1,
	TRACE_NOP_OPT_REFUSE = 0x2
};

/* Options for the tracer (see trace_options file) */
static struct tracer_opt nop_opts[] = {
	/* Option that will be accepted by set_flag callback */
	{ TRACER_OPT(test_nop_accept, TRACE_NOP_OPT_ACCEPT) },
	/* Option that will be refused by set_flag callback */
	{ TRACER_OPT(test_nop_refuse, TRACE_NOP_OPT_REFUSE) },
	{ } /* Always set a last empty entry */
};

static struct tracer_flags nop_flags = {
	/* You can check your flags value here when you want. */
	.val = 0, /* By default: all flags disabled */
	.opts = nop_opts
};

Ref: https://elixir.bootlin.com/linux/v2.6.39/source/kernel/trace/trace_nop.c

Uprobe

# Start uprobe
echo 'p:readline /bin/bash:0xad610' >> uprobe_events

# Tracing
cat trace_pipe

# End uprobe
echo -:readline >> uprobe_events

Ref: https://opensource.com/article/17/7/dynamic-tracing-linux-user-and-kernel-space Ref: https://elixir.bootlin.com/linux/v3.19.8/source/kernel/trace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment