dynamic_debug: add trim_prefix() to provide source-root relative paths

trim_prefix(path) skips past the absolute source path root, and
returns the pointer to the relative path from there.  It is used to
shorten the displayed path in $DBGMT/dynamic_debug/control via
ddebug_proc_show(), and in ddebug_change() to allow relative filenames
to be used in applied queries.  For example:

  ~# echo file kernel/freezer.c +p > $DBGMT/dynamic_debug/control

  kernel/freezer.c:128 [freezer]cancel_freezing p "  clean up: %s\012"

trim_prefix(path) insures common prefix before trimming it, so
out-of-tree module paths are shown as full absolute paths.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Jim Cromie 2011-12-19 17:13:12 -05:00 committed by Greg Kroah-Hartman
parent 7281491c59
commit 2b6783191d
2 changed files with 19 additions and 6 deletions

View File

@ -144,11 +144,12 @@ func
func svc_tcp_accept func svc_tcp_accept
file file
The given string is compared against either the full The given string is compared against either the full pathname, the
pathname or the basename of the source file of each src-root relative pathname, or the basename of the source file of
callsite. Examples: each callsite. Examples:
file svcsock.c file svcsock.c
file kernel/freezer.c
file /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svcsock.c file /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svcsock.c
module module

View File

@ -69,6 +69,17 @@ static inline const char *basename(const char *path)
return tail ? tail+1 : path; return tail ? tail+1 : path;
} }
/* Return the path relative to source root */
static inline const char *trim_prefix(const char *path)
{
int skip = strlen(__FILE__) - strlen("lib/dynamic_debug.c");
if (strncmp(path, __FILE__, skip))
skip = 0; /* prefix mismatch, don't skip */
return path + skip;
}
static struct { unsigned flag:8; char opt_char; } opt_array[] = { static struct { unsigned flag:8; char opt_char; } opt_array[] = {
{ _DPRINTK_FLAGS_PRINT, 'p' }, { _DPRINTK_FLAGS_PRINT, 'p' },
{ _DPRINTK_FLAGS_INCL_MODNAME, 'm' }, { _DPRINTK_FLAGS_INCL_MODNAME, 'm' },
@ -125,7 +136,8 @@ static void ddebug_change(const struct ddebug_query *query,
/* match against the source filename */ /* match against the source filename */
if (query->filename && if (query->filename &&
strcmp(query->filename, dp->filename) && strcmp(query->filename, dp->filename) &&
strcmp(query->filename, basename(dp->filename))) strcmp(query->filename, basename(dp->filename)) &&
strcmp(query->filename, trim_prefix(dp->filename)))
continue; continue;
/* match against the function */ /* match against the function */
@ -154,7 +166,7 @@ static void ddebug_change(const struct ddebug_query *query,
dp->flags = newflags; dp->flags = newflags;
if (verbose) if (verbose)
pr_info("changed %s:%d [%s]%s =%s\n", pr_info("changed %s:%d [%s]%s =%s\n",
dp->filename, dp->lineno, trim_prefix(dp->filename), dp->lineno,
dt->mod_name, dp->function, dt->mod_name, dp->function,
ddebug_describe_flags(dp, flagbuf, ddebug_describe_flags(dp, flagbuf,
sizeof(flagbuf))); sizeof(flagbuf)));
@ -714,7 +726,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
} }
seq_printf(m, "%s:%u [%s]%s =%s \"", seq_printf(m, "%s:%u [%s]%s =%s \"",
dp->filename, dp->lineno, trim_prefix(dp->filename), dp->lineno,
iter->table->mod_name, dp->function, iter->table->mod_name, dp->function,
ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf))); ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf)));
seq_escape(m, dp->format, "\t\r\n\""); seq_escape(m, dp->format, "\t\r\n\"");