Commit 653185d8 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf annotate-data: Add variable_state_str()

So that it can show a proper debug message in the right place.  The
check_variable() is used in other places which don't want to print the
message.

  $ perf --debug type-profile annotate --data-type

Before:
  -----------------------------------------------------------
  find data type for 0x140(reg14) at update_blocked_averages+0x2db
  CU for kernel/sched/fair.c (die:0x12dd892)
  frame base: cfa=1 fbreg=7
  no pointer or no type                                         <<<--- removed
  check variable "__mptr" failed (die: 0x13022f1)
   variable location: base=reg14, offset=0x140
   type='void*' size=0x8 (die:0x12dd8f9)

After:
  -----------------------------------------------------------
  find data type for 0x140(reg14) at update_blocked_averages+0x2db
  CU for kernel/sched/fair.c (die:0x12dd892)
  frame base: cfa=1 fbreg=7
  found "__mptr" (die: 0x13022f1) in scope=4/4 (die: 0x13022e8) failed: no/void pointer  <<<--- here
   variable location: base=reg14, offset=0x140
   type='void*' size=0x8 (die:0x12dd8f9)
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240816235840.2754937-5-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 976862f8
......@@ -354,6 +354,25 @@ enum type_match_result {
PERF_TMR_BAD_OFFSET,
};
static const char *match_result_str(enum type_match_result tmr)
{
switch (tmr) {
case PERF_TMR_OK:
return "Good!";
case PERF_TMR_NO_TYPE:
return "no type information";
case PERF_TMR_NO_POINTER:
return "no/void pointer";
case PERF_TMR_NO_SIZE:
return "type size is unknown";
case PERF_TMR_BAD_OFFSET:
return "offset bigger than size";
case PERF_TMR_UNKNOWN:
default:
return "invalid state";
}
}
/* The type info will be saved in @type_die */
static enum type_match_result check_variable(struct data_loc_info *dloc,
Dwarf_Die *var_die,
......@@ -373,7 +392,6 @@ static enum type_match_result check_variable(struct data_loc_info *dloc,
/* Get the type of the variable */
if (__die_get_real_type(var_die, type_die) == NULL) {
pr_debug_dtp("variable has no type\n");
ann_data_stat.no_typeinfo++;
return PERF_TMR_NO_TYPE;
}
......@@ -387,7 +405,6 @@ static enum type_match_result check_variable(struct data_loc_info *dloc,
if ((dwarf_tag(type_die) != DW_TAG_pointer_type &&
dwarf_tag(type_die) != DW_TAG_array_type) ||
__die_get_real_type(type_die, type_die) == NULL) {
pr_debug_dtp("no pointer or no type\n");
ann_data_stat.no_typeinfo++;
return PERF_TMR_NO_POINTER;
}
......@@ -400,15 +417,12 @@ static enum type_match_result check_variable(struct data_loc_info *dloc,
/* Get the size of the actual type */
if (dwarf_aggregate_size(&sized_type, &size) < 0) {
pr_debug_dtp("type size is unknown\n");
ann_data_stat.invalid_size++;
return PERF_TMR_NO_SIZE;
}
/* Minimal sanity check */
if ((unsigned)offset >= size) {
pr_debug_dtp("offset: %d is bigger than size: %"PRIu64"\n",
offset, size);
ann_data_stat.bad_offset++;
return PERF_TMR_BAD_OFFSET;
}
......@@ -1310,12 +1324,13 @@ static int find_data_type_die(struct data_loc_info *dloc, Dwarf_Die *type_die)
continue;
}
pr_debug_dtp("found \"%s\" (die: %#lx) in scope=%d/%d (die: %#lx) ",
dwarf_diename(&var_die), (long)dwarf_dieoffset(&var_die),
i+1, nr_scopes, (long)dwarf_dieoffset(&scopes[i]));
/* Found a variable, see if it's correct */
result = check_variable(dloc, &var_die, type_die, reg, offset, is_fbreg);
if (result == PERF_TMR_OK) {
pr_debug_dtp("found \"%s\" in scope=%d/%d (die: %#lx) ",
dwarf_diename(&var_die), i+1, nr_scopes,
(long)dwarf_dieoffset(&scopes[i]));
if (reg == DWARF_REG_PC) {
pr_debug_dtp("addr=%#"PRIx64" type_offset=%#x\n",
dloc->var_addr, offset);
......@@ -1325,17 +1340,13 @@ static int find_data_type_die(struct data_loc_info *dloc, Dwarf_Die *type_die)
} else {
pr_debug_dtp("type_offset=%#x\n", offset);
}
pr_debug_location(&var_die, pc, reg);
pr_debug_type_name(type_die, TSR_KIND_TYPE);
ret = 0;
} else {
pr_debug_dtp("check variable \"%s\" failed (die: %#lx)\n",
dwarf_diename(&var_die),
(long)dwarf_dieoffset(&var_die));
pr_debug_location(&var_die, pc, reg);
pr_debug_type_name(type_die, TSR_KIND_TYPE);
pr_debug_dtp("failed: %s\n", match_result_str(result));
ret = -1;
}
pr_debug_location(&var_die, pc, reg);
pr_debug_type_name(type_die, TSR_KIND_TYPE);
dloc->type_offset = offset;
goto out;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment