Re: [RFC][PATCH 06/17 v3] tracing: Add TRACE_DEFINE_ENUM() macro to map enums to their values

Steven Rostedt
2015-04-02T16:25:18Z

I updated the function to handle structures that were saved as well.
Just in case something like REC->my_enum does not get converted.

Also, I found that I never needed to decrement the pointer for those
locations that I did so.

Here's the new function:

static void update_event_printk(struct ftrace_event_call *call,
struct trace_enum_map *map)
{
char *ptr;
int quote = 0;
int len = strlen(map->enum_string);

for (ptr = call->print_fmt; *ptr; ptr++) {
if (*ptr == '\\') {
ptr++;
/* paranoid */
if (!*ptr)
break;
continue;
}
if (*ptr == '"') {
quote ^= 1;
continue;
}
if (quote)
continue;
if (isdigit(*ptr)) {
/* skip numbers */
do {
ptr++;
/* Check for alpha chars like ULL */
} while (isalnum(*ptr));
/*
* A number must have some kind of delimiter after
* it, and we can ignore that too.
*/
continue;
}
if (isalpha(*ptr) || *ptr == '_') {
if (strncmp(map->enum_string, ptr, len) == 0 &&
!isalnum(ptr[len]) && ptr[len] != '_') {
ptr = enum_replace(ptr, map, len);
/* Hmm, enum string smaller than value */
if (WARN_ON_ONCE(!ptr))
return;
/*
* No need to decrement here, as enum_replace()
* returns the pointer to the character passed
* the enum, and two enums can not be placed
* back to back without something in between.
* We can skip that something in between.
*/
continue;
}
skip_more:
do {
ptr++;
} while (isalnum(*ptr) || *ptr == '_');
/*
* If what comes after this variable is a '.' or
* '->' then we can continue to ignore that string.
*/
if (*ptr == '.' || (ptr[0] == '-' && ptr[1] == '>')) {
ptr += *ptr == '.' ? 1 : 2;
goto skip_more;
}
/*
* Once again, we can skip the delimiter that came
* after the string.
*/
continue;
}
}
}