libtraceevent(3)

# libtraceevent(3) Manual Page

## NAME

tep_plugin_kvm_get_func, tep_plugin_kvm_put_func - Add function name for instruction pointer of kvm plugin

## SYNOPSIS

    #include <event-parse.h>

    const char *tep_plugin_kvm_get_func(struct tep_event *event,
                                        struct tep_record *record,
                                        unsigned long long *paddr);
    void tep_plugin_kvm_put_func(const char *func);

## DESCRIPTION

The functions tep_plugin_kvm_get_func() and tep_plugin_kvm_put_func() are not to be called by an application, but instead are to be defined by an application.

Certain events (like kvm_exit and kvm_entry) have the instruction pointer of where in the guest the context changed from guest to host. As the host only knows the instruction pointer and does not have information about what function in the guest that instruction pointer belongs to, it can only print the address.

But the application may have more information about the guest, and know where the guest was when the exit occurred, and also even know the function name of that address.

The KVM plugin for libtraceevent is called on these events, and then calls tep_plugin_kvm_get_func() to see if that function can resolve the instruction pointer address to a real function name. If the return is non NULL, it will print the function in the output for that event.

These functions are currently defined as weak functions within the plugin, as to not require them to be defined elsewhere. For an application to override the weak function, it will need to define the function in a file that gets compiled with -rdynamic. That will tell the dynamic linker to examine that object file and use function names to resolve weak functions in other shared objects (in this case the KVM plugin shared object).

If the application defines tep_plugin_kvm_get_func(), it must use the above prototype. The event will hold the KVM event that has the instruction pointer field. The record will be the instance of that event. The application’s function does not need to use these parameters, but they may be useful for finding the function name for the address. The paddr is a pointer to a 64 bit value (where only 32 bits may be used on 32 bit machines). This value is the instruction pointer to look up. If the application knows the start address of the function as well, it can set paddr to that address, and the KVM plugin will also append a "+offset" to the function name where the offset is the original value in paddr minus the value in paddr when it is called. Finally, the application should return the function name as a nul terminated string if one is found.

If the returned string of tep_plugin_kvm_get_func() was allocated, the KVM plugin will call tep_plugin_kvm_put_func() when it is through with it, passing the value returned by tep_plugin_kvm_get_func() as func. This allows the application to free it if necessary.

## RETURN VALUE

The tep_plugin_kvm_get_func() is not to be called by the application but instead is to be defined by the application. It should return a nul terminated string representing the function for the given instruction pointer passed to it by reference in paddr. It can then optionally update the paddr to a value that holds the start of the function. The string returned may be freed by the tep_plugin_kvm_put_func() that the application should define to clean up the string.

The below example needs to be compiled with the -rdynamic flag so that the dynamic linker can resolve the tep_plugin_kvm_get_func() and tep_plugin_kvm_put_func() functions.

When run against a trace.dat file produced by trace-cmd(1) recording the kvm_exit and kvm_entry events on a guest, and then the guest’s /proc/kallsyms file is passed as the second parameter, the output produced will look something like:

But without those callbacks, it would look like:

## EXAMPLE

## FILES

    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.

## SEE ALSO

libtraceevent(3), trace-cmd(1)

## REPORTING BUGS

Report bugs to <linux-trace-devel@vger.kernel.org>

## LICENSE

libtraceevent is Free Software licensed under the GNU LGPL 2.1

## RESOURCES

https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/