libtraceevent: Add the API tep_parse_kallsyms()
PATCH 1/1 libtraceevent: Add the API tep_parse_kallsyms()
From: "Steven Rostedt (VMware)" <[email protected]>
Currently, trace-cmd has a tracecmd_parse_proc_kallsyms() function that reads a string that holds the content of /proc/kallsyms and then passes the function mapping it reads into the tep handler.
There's no reason for this to be specific to trace-cmd as other applications can easily save /proc/kallsyms, or just read it directly and then pass it to the tep handler.
Add the same functionality to libtraceevent as tep_parse_kallsyms().
Signed-off-by Steven Rostedt (VMware) <[email protected]>
--- .../libtraceevent-parse_kallsyms.txt | 97 +++++++++++++++++++ src/event-parse.c | 68 +++++++++++++ src/event-parse.h | 1 + 3 files changed, 166 insertions(+) create mode 100644 Documentation/libtraceevent-parse_kallsyms.txt
Documentation/libtraceevent-parse_kallsyms.txt new file +97 -0
@@ -0,0 +1,97 @@ +libtraceevent(3) +================ + +NAME +---- +tep_parse_kallsyms - Parses mappings of address to function names from kallsyms format file + +SYNOPSIS +-------- +[verse] +-- +*#include <event-parse.h>* + +int *tep_parse_kallsyms*(struct tep_handle pass:[*]_tep_, const char pass:[*]_buf_); +-- + +DESCRIPTION +----------- +*tep_parse_kallsyms* is a helper function to parse the Linux kernel /proc/kallsyms format +(stored in a string buffer passed in by _buf_) and load the functions into the +_tep_ handler such that function IP addresses can be mapped to their name when +parsing events with %pS in the print format field. It parses the string _buf_ that +holds the content of /proc/kallsyms and ends with a nul character ('\0'). + +RETURN VALUE +------------ +The *tep_parse_kallsyms*() function returns 0 in case of success, or -1 +in case of an error. + +EXAMPLE +------- +[source,c] +-- +... +#include <event-parse.h> +#include <stdlib.h> + +int load_kallsyms(struct tep_handle *tep) +{ + char *line = NULL; + char *buf = NULL; + size_t sz = 0; + FILE *fp; + int len = 0; + int r; + + fp = fopen("/proc/kallsyms", "r"); + while ((r = getline(&line, &sz, fp)) >= 0) { + buf = realloc(buf, len + r + 1); + memcpy(buf + len, line, r); + len += r; + } + free(line); + fclose(fp); + if (!buf) + return -1; + buf[len] = 0; + + r = tep_parse_kallsyms(tep, buf); + free(buf); + return r; +} +... +-- + +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. +-- + +SEE ALSO +-------- +_libtraceevent(3)_, _trace-cmd(1)_ + +AUTHOR +------ +[verse] +-- +*Steven Rostedt* <[email protected]>, author of *libtraceevent*. +*Tzvetomir Stoyanov* <[email protected]>, coauthor of *libtraceevent*. +-- +REPORTING BUGS +-------------- +Report bugs to <[email protected]> + +LICENSE +------- +libtraceevent is Free Software licensed under the GNU LGPL 2.1 + +RESOURCES +--------- +https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/
src/event-parse.c +68 -0
74 lines not on this page · raw message
src/event-parse.h +1 -0
@@ -439,6 +439,7 @@ int tep_set_function_resolver(struct tep_handle *tep,void tep_reset_function_resolver (struct tep_handle *tep);int tep_register_comm (struct tep_handle *tep,const char *comm,int pid);int tep_override_comm (struct tep_handle *tep,const char *comm,int pid); +int tep_parse_kallsyms (struct tep_handle *tep,const char *kallsyms);int tep_register_function (struct tep_handle *tep,char *name,unsigned long long addr,char *mod); int tep_register_print_string(struct tep_handle *tep, const char *fmt,
Signature · 1 line
2.29.2