Skip to content

Commit 44d1a3e

Browse files
committed
perf annotate: Disambiguage offsets and addresses in operands
We were using ins_ops->target for callq addresses and jump offsets, disambiguate by having ins_ops->target.addr and ins_ops->target.offset. For jumps we'll need both to fixup lines that don't have an offset on the <> part. Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 9481ede commit 44d1a3e

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

tools/perf/ui/browsers/annotate.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
112112
ui_browser__set_color(self, color);
113113
if (dl->ins && dl->ins->ops->scnprintf) {
114114
if (ins__is_jump(dl->ins)) {
115-
bool fwd = dl->ops.target > (u64)dl->offset;
115+
bool fwd = dl->ops.target.offset > (u64)dl->offset;
116116

117117
ui_browser__write_graph(self, fwd ? SLSMG_DARROW_CHAR :
118118
SLSMG_UARROW_CHAR);
@@ -156,7 +156,7 @@ static void annotate_browser__draw_current_loop(struct ui_browser *browser)
156156
if (!pos->ins || !ins__is_jump(pos->ins))
157157
continue;
158158

159-
target = ab->offsets[pos->ops.target];
159+
target = ab->offsets[pos->ops.target.offset];
160160
if (!target)
161161
continue;
162162

@@ -360,7 +360,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser,
360360
if (!ins__is_call(dl->ins))
361361
return false;
362362

363-
ip = ms->map->map_ip(ms->map, dl->ops.target);
363+
ip = ms->map->map_ip(ms->map, dl->ops.target.addr);
364364
target = map__find_symbol(ms->map, ip, NULL);
365365
if (target == NULL) {
366366
ui_helpline__puts("The called function was not found.");
@@ -411,7 +411,7 @@ static bool annotate_browser__jump(struct annotate_browser *browser)
411411
if (!ins__is_jump(dl->ins))
412412
return false;
413413

414-
dl = annotate_browser__find_offset(browser, dl->ops.target, &idx);
414+
dl = annotate_browser__find_offset(browser, dl->ops.target.offset, &idx);
415415
if (dl == NULL) {
416416
ui_helpline__puts("Invallid jump offset");
417417
return true;
@@ -692,14 +692,14 @@ static void annotate_browser__mark_jump_targets(struct annotate_browser *browser
692692
if (!dl || !dl->ins || !ins__is_jump(dl->ins))
693693
continue;
694694

695-
if (dl->ops.target >= size) {
695+
if (dl->ops.target.offset >= size) {
696696
ui__error("jump to after symbol!\n"
697697
"size: %zx, jump target: %" PRIx64,
698-
size, dl->ops.target);
698+
size, dl->ops.target.offset);
699699
continue;
700700
}
701701

702-
dlt = browser->offsets[dl->ops.target];
702+
dlt = browser->offsets[dl->ops.target.offset];
703703
/*
704704
* FIXME: Oops, no jump target? Buggy disassembler? Or do we
705705
* have to adjust to the previous offset?

tools/perf/util/annotate.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static int call__parse(struct ins_operands *ops)
2222
{
2323
char *endptr, *tok, *name;
2424

25-
ops->target = strtoull(ops->raw, &endptr, 16);
25+
ops->target.addr = strtoull(ops->raw, &endptr, 16);
2626

2727
name = strchr(endptr, '<');
2828
if (name == NULL)
@@ -35,17 +35,17 @@ static int call__parse(struct ins_operands *ops)
3535
return -1;
3636

3737
*tok = '\0';
38-
ops->target_name = strdup(name);
38+
ops->target.name = strdup(name);
3939
*tok = '>';
4040

41-
return ops->target_name == NULL ? -1 : 0;
41+
return ops->target.name == NULL ? -1 : 0;
4242

4343
indirect_call:
4444
tok = strchr(endptr, '*');
4545
if (tok == NULL)
4646
return -1;
4747

48-
ops->target = strtoull(tok + 1, NULL, 16);
48+
ops->target.addr = strtoull(tok + 1, NULL, 16);
4949
return 0;
5050
}
5151

@@ -55,10 +55,10 @@ static int call__scnprintf(struct ins *ins, char *bf, size_t size,
5555
if (addrs)
5656
return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->raw);
5757

58-
if (ops->target_name)
59-
return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->target_name);
58+
if (ops->target.name)
59+
return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->target.name);
6060

61-
return scnprintf(bf, size, "%-6.6s *%" PRIx64, ins->name, ops->target);
61+
return scnprintf(bf, size, "%-6.6s *%" PRIx64, ins->name, ops->target.addr);
6262
}
6363

6464
static struct ins_ops call_ops = {
@@ -78,7 +78,7 @@ static int jump__parse(struct ins_operands *ops)
7878
if (s++ == NULL)
7979
return -1;
8080

81-
ops->target = strtoll(s, NULL, 16);
81+
ops->target.offset = strtoll(s, NULL, 16);
8282
return 0;
8383
}
8484

@@ -88,7 +88,7 @@ static int jump__scnprintf(struct ins *ins, char *bf, size_t size,
8888
if (addrs)
8989
return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->raw);
9090

91-
return scnprintf(bf, size, "%-6.6s %" PRIx64, ins->name, ops->target);
91+
return scnprintf(bf, size, "%-6.6s %" PRIx64, ins->name, ops->target.offset);
9292
}
9393

9494
static struct ins_ops jump_ops = {
@@ -289,7 +289,7 @@ void disasm_line__free(struct disasm_line *dl)
289289
{
290290
free(dl->line);
291291
free(dl->name);
292-
free(dl->ops.target_name);
292+
free(dl->ops.target.name);
293293
free(dl);
294294
}
295295

tools/perf/util/annotate.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ struct ins;
1111

1212
struct ins_operands {
1313
char *raw;
14-
char *target_name;
15-
u64 target;
14+
struct {
15+
char *name;
16+
u64 offset;
17+
u64 addr;
18+
} target;
1619
};
1720

1821
struct ins_ops {

0 commit comments

Comments
 (0)