Skip to content

Commit cd77290

Browse files
mhiramatrostedt
authored andcommitted
libtraceevent: Add __rel_loc relative location attribute support
Add '__rel_loc' new dynamic data location attribute which encodes the data location from the next to the field itself. This is similar to the '__data_loc' but the location offset is not from the event entry but from the next of the field. This patch adds '__rel_loc' decoding support in the libtraceevent. Link: https://lkml.kernel.org/r/163757343994.510314.13241077597729303802.stgit@devnote2 Cc: Beau Belgrave <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Tom Zanussi <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent b466b13 commit cd77290

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

tools/lib/traceevent/event-parse.c

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,14 @@ static int field_is_dynamic(struct tep_format_field *field)
13671367
return 0;
13681368
}
13691369

1370+
static int field_is_relative_dynamic(struct tep_format_field *field)
1371+
{
1372+
if (strncmp(field->type, "__rel_loc", 9) == 0)
1373+
return 1;
1374+
1375+
return 0;
1376+
}
1377+
13701378
static int field_is_long(struct tep_format_field *field)
13711379
{
13721380
/* includes long long */
@@ -1622,6 +1630,8 @@ static int event_read_fields(struct tep_event *event, struct tep_format_field **
16221630
field->flags |= TEP_FIELD_IS_STRING;
16231631
if (field_is_dynamic(field))
16241632
field->flags |= TEP_FIELD_IS_DYNAMIC;
1633+
if (field_is_relative_dynamic(field))
1634+
field->flags |= TEP_FIELD_IS_DYNAMIC | TEP_FIELD_IS_RELATIVE;
16251635
if (field_is_long(field))
16261636
field->flags |= TEP_FIELD_IS_LONG;
16271637

@@ -2928,7 +2938,7 @@ process_str(struct tep_event *event __maybe_unused, struct tep_print_arg *arg,
29282938

29292939
arg->type = TEP_PRINT_STRING;
29302940
arg->string.string = token;
2931-
arg->string.offset = -1;
2941+
arg->string.field = NULL;
29322942

29332943
if (read_expected(TEP_EVENT_DELIM, ")") < 0)
29342944
goto out_err;
@@ -2957,7 +2967,7 @@ process_bitmask(struct tep_event *event __maybe_unused, struct tep_print_arg *ar
29572967

29582968
arg->type = TEP_PRINT_BITMASK;
29592969
arg->bitmask.bitmask = token;
2960-
arg->bitmask.offset = -1;
2970+
arg->bitmask.field = NULL;
29612971

29622972
if (read_expected(TEP_EVENT_DELIM, ")") < 0)
29632973
goto out_err;
@@ -3123,19 +3133,23 @@ process_function(struct tep_event *event, struct tep_print_arg *arg,
31233133
free_token(token);
31243134
return process_int_array(event, arg, tok);
31253135
}
3126-
if (strcmp(token, "__get_str") == 0) {
3136+
if (strcmp(token, "__get_str") == 0 ||
3137+
strcmp(token, "__get_rel_str") == 0) {
31273138
free_token(token);
31283139
return process_str(event, arg, tok);
31293140
}
3130-
if (strcmp(token, "__get_bitmask") == 0) {
3141+
if (strcmp(token, "__get_bitmask") == 0 ||
3142+
strcmp(token, "__get_rel_bitmask") == 0) {
31313143
free_token(token);
31323144
return process_bitmask(event, arg, tok);
31333145
}
3134-
if (strcmp(token, "__get_dynamic_array") == 0) {
3146+
if (strcmp(token, "__get_dynamic_array") == 0 ||
3147+
strcmp(token, "__get_rel_dynamic_array") == 0) {
31353148
free_token(token);
31363149
return process_dynamic_array(event, arg, tok);
31373150
}
3138-
if (strcmp(token, "__get_dynamic_array_len") == 0) {
3151+
if (strcmp(token, "__get_dynamic_array_len") == 0 ||
3152+
strcmp(token, "__get_rel_dynamic_array_len") == 0) {
31393153
free_token(token);
31403154
return process_dynamic_array_len(event, arg, tok);
31413155
}
@@ -4163,14 +4177,16 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
41634177
case TEP_PRINT_STRING: {
41644178
int str_offset;
41654179

4166-
if (arg->string.offset == -1) {
4167-
struct tep_format_field *f;
4180+
if (!arg->string.field)
4181+
arg->string.field = tep_find_any_field(event, arg->string.string);
4182+
if (!arg->string.field)
4183+
break;
41684184

4169-
f = tep_find_any_field(event, arg->string.string);
4170-
arg->string.offset = f->offset;
4171-
}
4172-
str_offset = data2host4(tep, *(unsigned int *)(data + arg->string.offset));
4185+
str_offset = data2host4(tep,
4186+
*(unsigned int *)(data + arg->string.field->offset));
41734187
str_offset &= 0xffff;
4188+
if (arg->string.field->flags & TEP_FIELD_IS_RELATIVE)
4189+
str_offset += arg->string.field->offset + arg->string.field->size;
41744190
print_str_to_seq(s, format, len_arg, ((char *)data) + str_offset);
41754191
break;
41764192
}
@@ -4181,15 +4197,16 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
41814197
int bitmask_offset;
41824198
int bitmask_size;
41834199

4184-
if (arg->bitmask.offset == -1) {
4185-
struct tep_format_field *f;
4186-
4187-
f = tep_find_any_field(event, arg->bitmask.bitmask);
4188-
arg->bitmask.offset = f->offset;
4189-
}
4190-
bitmask_offset = data2host4(tep, *(unsigned int *)(data + arg->bitmask.offset));
4200+
if (!arg->bitmask.field)
4201+
arg->bitmask.field = tep_find_any_field(event, arg->bitmask.bitmask);
4202+
if (!arg->bitmask.field)
4203+
break;
4204+
bitmask_offset = data2host4(tep,
4205+
*(unsigned int *)(data + arg->bitmask.field->offset));
41914206
bitmask_size = bitmask_offset >> 16;
41924207
bitmask_offset &= 0xffff;
4208+
if (arg->bitmask.field->flags & TEP_FIELD_IS_RELATIVE)
4209+
bitmask_offset += arg->bitmask.field->offset + arg->bitmask.field->size;
41934210
print_bitmask_to_seq(tep, s, format, len_arg,
41944211
data + bitmask_offset, bitmask_size);
41954212
break;
@@ -5109,6 +5126,8 @@ void tep_print_field(struct trace_seq *s, void *data,
51095126
offset = val;
51105127
len = offset >> 16;
51115128
offset &= 0xffff;
5129+
if (field->flags & TEP_FIELD_IS_RELATIVE)
5130+
offset += field->offset + field->size;
51125131
}
51135132
if (field->flags & TEP_FIELD_IS_STRING &&
51145133
is_printable_array(data + offset, len)) {
@@ -6987,6 +7006,8 @@ void *tep_get_field_raw(struct trace_seq *s, struct tep_event *event,
69877006
data + offset, field->size);
69887007
*len = offset >> 16;
69897008
offset &= 0xffff;
7009+
if (field->flags & TEP_FIELD_IS_RELATIVE)
7010+
offset += field->offset + field->size;
69907011
} else
69917012
*len = field->size;
69927013

tools/lib/traceevent/event-parse.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ enum tep_format_flags {
125125
TEP_FIELD_IS_LONG = 32,
126126
TEP_FIELD_IS_FLAG = 64,
127127
TEP_FIELD_IS_SYMBOLIC = 128,
128+
TEP_FIELD_IS_RELATIVE = 256,
128129
};
129130

130131
struct tep_format_field {
@@ -153,12 +154,12 @@ struct tep_print_arg_atom {
153154

154155
struct tep_print_arg_string {
155156
char *string;
156-
int offset;
157+
struct tep_format_field *field;
157158
};
158159

159160
struct tep_print_arg_bitmask {
160161
char *bitmask;
161-
int offset;
162+
struct tep_format_field *field;
162163
};
163164

164165
struct tep_print_arg_field {

tools/lib/traceevent/parse-filter.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,8 +1712,11 @@ static const char *get_field_str(struct tep_filter_arg *arg, struct tep_record *
17121712

17131713
if (arg->str.field->flags & TEP_FIELD_IS_DYNAMIC) {
17141714
addr = *(unsigned int *)val;
1715-
val = record->data + (addr & 0xffff);
17161715
size = addr >> 16;
1716+
addr &= 0xffff;
1717+
if (arg->str.field->flags & TEP_FIELD_IS_RELATIVE)
1718+
addr += arg->str.field->offset + arg->str.field->size;
1719+
val = record->data + addr;
17171720
}
17181721

17191722
/*

0 commit comments

Comments
 (0)