Re: [PATCH v5 12/30] tools/lib/traceevent: Man pages for function related libtraceevent APIs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 12 Apr 2019 16:37:53 +0300
Tzvetomir Stoyanov <tstoyanov@xxxxxxxxxx> wrote:

> +EXAMPLE
> +-------
> +[source,c]
> +--
> +#include <event-parse.h>
> +...
> +struct tep_handle *tep = tep_alloc();
> +...
> +char *my_resolve_kernel_addr(void *context,
> +			     unsigned long long *addrp, char **modp)
> +{

I would at least have something in there instead of just a stub
function. You can make up a resolver. But just a stub function is not
useful to know.

	struct db *function_database = context;
	struct symbol *sym = sql_lookup(function_database, *addrp);

	if (!sym)
		return NULL;

	*modp = sym->module_name;
	return sym->name;
}


> +	return NULL;
> +}
> +
> +void show_function( unsigned long long addr)
> +{
> +	unsigned long long fstart;
> +	const char *fname;
> +
> +	if (tep_set_function_resolver(tep, my_resolve_kernel_addr, NULL) != 0) {

	tep_set_function_resolver(tep, my_resolve_kernel_addr,
				function_database) != 0) {

This gives an idea on how to use it. Sure it's a fictional database,
but it is much more descriptive than passing in NULL that does nothing.

> +		/* failed to register my_resolve_kernel_addr */
> +	}
> +
> +	/* These APIs use my_resolve_kernel_addr() to resolve the addr */
> +	fname = tep_find_function(tep, addr);
> +	fstart = tep_find_function_address(tep, addr);
> +
> +	/*
> +	   addr is in function named fname, starting at fstart address,
> +	   at offset (addr - fstart)
> +	*/
> +
> +	tep_reset_function_resolver(tep);
> +
> +}
> +...
> +	if (tep_register_function(tep, "kernel_function_foo",
> +				(unsigned long long) 0x12345678, NULL) != 0) {

Prehaps add a module to register too.

Thanks!

-- Steve

> +		/* Failed to register kernel_function_foo address mapping */
> +	}
> +...
> +	if (tep_register_print_string(tep, "print string",
> +				(unsigned long long) 0x87654321, NULL) != 0) {
> +		/* Failed to register "print string" address mapping */
> +	}
> +...
> +--
> +
> +FILES
> +-----
> +[verse]
> +--
> +*event-parse.h*
> +	Header file to include in order to have access to the library APIs.
> +*-ltraceevent*
> +	Linker switch to add when building a program that uses the library.
> +--
> +



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux