perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
|
|
* Convert sample address to data type using DWARF debug info.
|
|
|
|
*
|
|
|
|
* Written by Namhyung Kim <namhyung@kernel.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2024-01-16 22:26:51 -08:00
|
|
|
#include "annotate.h"
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
#include "annotate-data.h"
|
|
|
|
#include "debuginfo.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "dso.h"
|
2024-01-16 22:26:53 -08:00
|
|
|
#include "dwarf-regs.h"
|
2023-12-12 16:13:17 -08:00
|
|
|
#include "evsel.h"
|
|
|
|
#include "evlist.h"
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
#include "map.h"
|
|
|
|
#include "map_symbol.h"
|
|
|
|
#include "strbuf.h"
|
|
|
|
#include "symbol.h"
|
2023-12-12 16:13:20 -08:00
|
|
|
#include "symbol_conf.h"
|
2024-03-18 22:51:03 -07:00
|
|
|
#include "thread.h"
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
|
2024-03-18 22:51:00 -07:00
|
|
|
#define pr_debug_dtp(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
if (debug_type_profile) \
|
|
|
|
pr_info(fmt, ##__VA_ARGS__); \
|
|
|
|
else \
|
|
|
|
pr_debug3(fmt, ##__VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void pr_debug_type_name(Dwarf_Die *die)
|
|
|
|
{
|
|
|
|
struct strbuf sb;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (!debug_type_profile && verbose < 3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
strbuf_init(&sb, 32);
|
|
|
|
die_get_typename_from_type(die, &sb);
|
|
|
|
str = strbuf_detach(&sb, NULL);
|
|
|
|
pr_info(" type=%s (die:%lx)\n", str, (long)dwarf_dieoffset(die));
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
|
2024-03-18 22:51:05 -07:00
|
|
|
/*
|
|
|
|
* Type information in a register, valid when @ok is true.
|
|
|
|
* The @caller_saved registers are invalidated after a function call.
|
|
|
|
*/
|
2024-03-18 22:51:01 -07:00
|
|
|
struct type_state_reg {
|
|
|
|
Dwarf_Die type;
|
|
|
|
bool ok;
|
2024-03-18 22:51:05 -07:00
|
|
|
bool caller_saved;
|
2024-03-18 22:51:01 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Type information in a stack location, dynamically allocated */
|
|
|
|
struct type_state_stack {
|
|
|
|
struct list_head list;
|
|
|
|
Dwarf_Die type;
|
|
|
|
int offset;
|
|
|
|
int size;
|
|
|
|
bool compound;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* FIXME: This should be arch-dependent */
|
|
|
|
#define TYPE_STATE_MAX_REGS 16
|
|
|
|
|
|
|
|
/*
|
|
|
|
* State table to maintain type info in each register and stack location.
|
|
|
|
* It'll be updated when new variable is allocated or type info is moved
|
|
|
|
* to a new location (register or stack). As it'd be used with the
|
|
|
|
* shortest path of basic blocks, it only maintains a single table.
|
|
|
|
*/
|
|
|
|
struct type_state {
|
2024-03-18 22:51:02 -07:00
|
|
|
/* state of general purpose registers */
|
2024-03-18 22:51:01 -07:00
|
|
|
struct type_state_reg regs[TYPE_STATE_MAX_REGS];
|
2024-03-18 22:51:02 -07:00
|
|
|
/* state of stack location */
|
2024-03-18 22:51:01 -07:00
|
|
|
struct list_head stack_vars;
|
2024-03-18 22:51:05 -07:00
|
|
|
/* return value register */
|
|
|
|
int ret_reg;
|
2024-03-18 22:51:01 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool has_reg_type(struct type_state *state, int reg)
|
|
|
|
{
|
|
|
|
return (unsigned)reg < ARRAY_SIZE(state->regs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These declarations will be remove once they are changed to static */
|
|
|
|
void init_type_state(struct type_state *state, struct arch *arch __maybe_unused);
|
|
|
|
void exit_type_state(struct type_state *state);
|
|
|
|
void update_var_state(struct type_state *state, struct data_loc_info *dloc,
|
|
|
|
u64 addr, u64 insn_offset, struct die_var_type *var_types);
|
2024-03-18 22:51:02 -07:00
|
|
|
void update_insn_state(struct type_state *state, struct data_loc_info *dloc,
|
2024-03-18 22:51:04 -07:00
|
|
|
Dwarf_Die *cu_die, struct disasm_line *dl);
|
2024-03-18 22:51:01 -07:00
|
|
|
|
2024-03-18 22:51:05 -07:00
|
|
|
void init_type_state(struct type_state *state, struct arch *arch)
|
2024-03-18 22:51:01 -07:00
|
|
|
{
|
|
|
|
memset(state, 0, sizeof(*state));
|
|
|
|
INIT_LIST_HEAD(&state->stack_vars);
|
2024-03-18 22:51:05 -07:00
|
|
|
|
|
|
|
if (arch__is(arch, "x86")) {
|
|
|
|
state->regs[0].caller_saved = true;
|
|
|
|
state->regs[1].caller_saved = true;
|
|
|
|
state->regs[2].caller_saved = true;
|
|
|
|
state->regs[4].caller_saved = true;
|
|
|
|
state->regs[5].caller_saved = true;
|
|
|
|
state->regs[8].caller_saved = true;
|
|
|
|
state->regs[9].caller_saved = true;
|
|
|
|
state->regs[10].caller_saved = true;
|
|
|
|
state->regs[11].caller_saved = true;
|
|
|
|
state->ret_reg = 0;
|
|
|
|
}
|
2024-03-18 22:51:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void exit_type_state(struct type_state *state)
|
|
|
|
{
|
|
|
|
struct type_state_stack *stack, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(stack, tmp, &state->stack_vars, list) {
|
|
|
|
list_del(&stack->list);
|
|
|
|
free(stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
perf annotate-data: Add dso->data_types tree
To aggregate accesses to the same data type, add 'data_types' tree in
DSO to maintain data types and find it by name and size.
It might have different data types that happen to have the same name,
so it also compares the size of the type.
Even if it doesn't 100% guarantee, it reduces the possibility of
mis-handling of such conflicts.
And I don't think it's common to have different types with the same
name.
Committer notes:
Very few cases on the Linux kernel, but there are some different types
with the same name, unsure if there is a debug mode in libbpf dedup that
warns about such cases, but there are provisions in pahole for that,
see:
"emit: Notice type shadowing, i.e. multiple types with the same name (enum, struct, union, etc)"
https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=4f332dbfd02072e4f410db7bdcda8d6e3422974b
$ pahole --compile > vmlinux.h
$ rm -f a ; make a
cc a.c -o a
$ grep __[0-9] vmlinux.h
union irte__1 {
struct map_info__1;
struct map_info__1 {
struct map_info__1 * next; /* 0 8 */
$
drivers/iommu/amd/amd_iommu_types.h 'union irte'
include/linux/dmar.h 'struct irte'
include/linux/device-mapper.h:
union map_info {
void *ptr;
};
include/linux/mtd/map.h:
struct map_info {
const char *name;
unsigned long size;
resource_size_t phys;
<SNIP>
kernel/events/uprobes.c:
struct map_info {
struct map_info *next;
struct mm_struct *mm;
unsigned long vaddr;
};
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:10 -08:00
|
|
|
/*
|
|
|
|
* Compare type name and size to maintain them in a tree.
|
|
|
|
* I'm not sure if DWARF would have information of a single type in many
|
|
|
|
* different places (compilation units). If not, it could compare the
|
|
|
|
* offset of the type entry in the .debug_info section.
|
|
|
|
*/
|
|
|
|
static int data_type_cmp(const void *_key, const struct rb_node *node)
|
|
|
|
{
|
|
|
|
const struct annotated_data_type *key = _key;
|
|
|
|
struct annotated_data_type *type;
|
|
|
|
|
|
|
|
type = rb_entry(node, struct annotated_data_type, node);
|
|
|
|
|
2023-12-12 16:13:16 -08:00
|
|
|
if (key->self.size != type->self.size)
|
|
|
|
return key->self.size - type->self.size;
|
|
|
|
return strcmp(key->self.type_name, type->self.type_name);
|
perf annotate-data: Add dso->data_types tree
To aggregate accesses to the same data type, add 'data_types' tree in
DSO to maintain data types and find it by name and size.
It might have different data types that happen to have the same name,
so it also compares the size of the type.
Even if it doesn't 100% guarantee, it reduces the possibility of
mis-handling of such conflicts.
And I don't think it's common to have different types with the same
name.
Committer notes:
Very few cases on the Linux kernel, but there are some different types
with the same name, unsure if there is a debug mode in libbpf dedup that
warns about such cases, but there are provisions in pahole for that,
see:
"emit: Notice type shadowing, i.e. multiple types with the same name (enum, struct, union, etc)"
https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=4f332dbfd02072e4f410db7bdcda8d6e3422974b
$ pahole --compile > vmlinux.h
$ rm -f a ; make a
cc a.c -o a
$ grep __[0-9] vmlinux.h
union irte__1 {
struct map_info__1;
struct map_info__1 {
struct map_info__1 * next; /* 0 8 */
$
drivers/iommu/amd/amd_iommu_types.h 'union irte'
include/linux/dmar.h 'struct irte'
include/linux/device-mapper.h:
union map_info {
void *ptr;
};
include/linux/mtd/map.h:
struct map_info {
const char *name;
unsigned long size;
resource_size_t phys;
<SNIP>
kernel/events/uprobes.c:
struct map_info {
struct map_info *next;
struct mm_struct *mm;
unsigned long vaddr;
};
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool data_type_less(struct rb_node *node_a, const struct rb_node *node_b)
|
|
|
|
{
|
|
|
|
struct annotated_data_type *a, *b;
|
|
|
|
|
|
|
|
a = rb_entry(node_a, struct annotated_data_type, node);
|
|
|
|
b = rb_entry(node_b, struct annotated_data_type, node);
|
|
|
|
|
2023-12-12 16:13:16 -08:00
|
|
|
if (a->self.size != b->self.size)
|
|
|
|
return a->self.size < b->self.size;
|
|
|
|
return strcmp(a->self.type_name, b->self.type_name) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recursively add new members for struct/union */
|
|
|
|
static int __add_member_cb(Dwarf_Die *die, void *arg)
|
|
|
|
{
|
|
|
|
struct annotated_member *parent = arg;
|
|
|
|
struct annotated_member *member;
|
|
|
|
Dwarf_Die member_type, die_mem;
|
|
|
|
Dwarf_Word size, loc;
|
|
|
|
Dwarf_Attribute attr;
|
|
|
|
struct strbuf sb;
|
|
|
|
int tag;
|
|
|
|
|
|
|
|
if (dwarf_tag(die) != DW_TAG_member)
|
|
|
|
return DIE_FIND_CB_SIBLING;
|
|
|
|
|
|
|
|
member = zalloc(sizeof(*member));
|
|
|
|
if (member == NULL)
|
|
|
|
return DIE_FIND_CB_END;
|
|
|
|
|
|
|
|
strbuf_init(&sb, 32);
|
|
|
|
die_get_typename(die, &sb);
|
|
|
|
|
|
|
|
die_get_real_type(die, &member_type);
|
|
|
|
if (dwarf_aggregate_size(&member_type, &size) < 0)
|
|
|
|
size = 0;
|
|
|
|
|
|
|
|
if (!dwarf_attr_integrate(die, DW_AT_data_member_location, &attr))
|
|
|
|
loc = 0;
|
|
|
|
else
|
|
|
|
dwarf_formudata(&attr, &loc);
|
|
|
|
|
|
|
|
member->type_name = strbuf_detach(&sb, NULL);
|
|
|
|
/* member->var_name can be NULL */
|
|
|
|
if (dwarf_diename(die))
|
|
|
|
member->var_name = strdup(dwarf_diename(die));
|
|
|
|
member->size = size;
|
|
|
|
member->offset = loc + parent->offset;
|
|
|
|
INIT_LIST_HEAD(&member->children);
|
|
|
|
list_add_tail(&member->node, &parent->children);
|
|
|
|
|
|
|
|
tag = dwarf_tag(&member_type);
|
|
|
|
switch (tag) {
|
|
|
|
case DW_TAG_structure_type:
|
|
|
|
case DW_TAG_union_type:
|
|
|
|
die_find_child(&member_type, __add_member_cb, member, &die_mem);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return DIE_FIND_CB_SIBLING;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_member_types(struct annotated_data_type *parent, Dwarf_Die *type)
|
|
|
|
{
|
|
|
|
Dwarf_Die die_mem;
|
|
|
|
|
|
|
|
die_find_child(type, __add_member_cb, &parent->self, &die_mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_members(struct annotated_member *member)
|
|
|
|
{
|
|
|
|
struct annotated_member *child, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(child, tmp, &member->children, node) {
|
|
|
|
list_del(&child->node);
|
|
|
|
delete_members(child);
|
|
|
|
free(child->type_name);
|
|
|
|
free(child->var_name);
|
|
|
|
free(child);
|
|
|
|
}
|
perf annotate-data: Add dso->data_types tree
To aggregate accesses to the same data type, add 'data_types' tree in
DSO to maintain data types and find it by name and size.
It might have different data types that happen to have the same name,
so it also compares the size of the type.
Even if it doesn't 100% guarantee, it reduces the possibility of
mis-handling of such conflicts.
And I don't think it's common to have different types with the same
name.
Committer notes:
Very few cases on the Linux kernel, but there are some different types
with the same name, unsure if there is a debug mode in libbpf dedup that
warns about such cases, but there are provisions in pahole for that,
see:
"emit: Notice type shadowing, i.e. multiple types with the same name (enum, struct, union, etc)"
https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=4f332dbfd02072e4f410db7bdcda8d6e3422974b
$ pahole --compile > vmlinux.h
$ rm -f a ; make a
cc a.c -o a
$ grep __[0-9] vmlinux.h
union irte__1 {
struct map_info__1;
struct map_info__1 {
struct map_info__1 * next; /* 0 8 */
$
drivers/iommu/amd/amd_iommu_types.h 'union irte'
include/linux/dmar.h 'struct irte'
include/linux/device-mapper.h:
union map_info {
void *ptr;
};
include/linux/mtd/map.h:
struct map_info {
const char *name;
unsigned long size;
resource_size_t phys;
<SNIP>
kernel/events/uprobes.c:
struct map_info {
struct map_info *next;
struct mm_struct *mm;
unsigned long vaddr;
};
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct annotated_data_type *dso__findnew_data_type(struct dso *dso,
|
|
|
|
Dwarf_Die *type_die)
|
|
|
|
{
|
|
|
|
struct annotated_data_type *result = NULL;
|
|
|
|
struct annotated_data_type key;
|
|
|
|
struct rb_node *node;
|
|
|
|
struct strbuf sb;
|
|
|
|
char *type_name;
|
|
|
|
Dwarf_Word size;
|
|
|
|
|
|
|
|
strbuf_init(&sb, 32);
|
|
|
|
if (die_get_typename_from_type(type_die, &sb) < 0)
|
|
|
|
strbuf_add(&sb, "(unknown type)", 14);
|
|
|
|
type_name = strbuf_detach(&sb, NULL);
|
|
|
|
dwarf_aggregate_size(type_die, &size);
|
|
|
|
|
|
|
|
/* Check existing nodes in dso->data_types tree */
|
2023-12-12 16:13:16 -08:00
|
|
|
key.self.type_name = type_name;
|
|
|
|
key.self.size = size;
|
perf annotate-data: Add dso->data_types tree
To aggregate accesses to the same data type, add 'data_types' tree in
DSO to maintain data types and find it by name and size.
It might have different data types that happen to have the same name,
so it also compares the size of the type.
Even if it doesn't 100% guarantee, it reduces the possibility of
mis-handling of such conflicts.
And I don't think it's common to have different types with the same
name.
Committer notes:
Very few cases on the Linux kernel, but there are some different types
with the same name, unsure if there is a debug mode in libbpf dedup that
warns about such cases, but there are provisions in pahole for that,
see:
"emit: Notice type shadowing, i.e. multiple types with the same name (enum, struct, union, etc)"
https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=4f332dbfd02072e4f410db7bdcda8d6e3422974b
$ pahole --compile > vmlinux.h
$ rm -f a ; make a
cc a.c -o a
$ grep __[0-9] vmlinux.h
union irte__1 {
struct map_info__1;
struct map_info__1 {
struct map_info__1 * next; /* 0 8 */
$
drivers/iommu/amd/amd_iommu_types.h 'union irte'
include/linux/dmar.h 'struct irte'
include/linux/device-mapper.h:
union map_info {
void *ptr;
};
include/linux/mtd/map.h:
struct map_info {
const char *name;
unsigned long size;
resource_size_t phys;
<SNIP>
kernel/events/uprobes.c:
struct map_info {
struct map_info *next;
struct mm_struct *mm;
unsigned long vaddr;
};
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:10 -08:00
|
|
|
node = rb_find(&key, &dso->data_types, data_type_cmp);
|
|
|
|
if (node) {
|
|
|
|
result = rb_entry(node, struct annotated_data_type, node);
|
|
|
|
free(type_name);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If not, add a new one */
|
|
|
|
result = zalloc(sizeof(*result));
|
|
|
|
if (result == NULL) {
|
|
|
|
free(type_name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-12-12 16:13:16 -08:00
|
|
|
result->self.type_name = type_name;
|
|
|
|
result->self.size = size;
|
|
|
|
INIT_LIST_HEAD(&result->self.children);
|
|
|
|
|
2023-12-12 16:13:20 -08:00
|
|
|
if (symbol_conf.annotate_data_member)
|
|
|
|
add_member_types(result, type_die);
|
perf annotate-data: Add dso->data_types tree
To aggregate accesses to the same data type, add 'data_types' tree in
DSO to maintain data types and find it by name and size.
It might have different data types that happen to have the same name,
so it also compares the size of the type.
Even if it doesn't 100% guarantee, it reduces the possibility of
mis-handling of such conflicts.
And I don't think it's common to have different types with the same
name.
Committer notes:
Very few cases on the Linux kernel, but there are some different types
with the same name, unsure if there is a debug mode in libbpf dedup that
warns about such cases, but there are provisions in pahole for that,
see:
"emit: Notice type shadowing, i.e. multiple types with the same name (enum, struct, union, etc)"
https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=4f332dbfd02072e4f410db7bdcda8d6e3422974b
$ pahole --compile > vmlinux.h
$ rm -f a ; make a
cc a.c -o a
$ grep __[0-9] vmlinux.h
union irte__1 {
struct map_info__1;
struct map_info__1 {
struct map_info__1 * next; /* 0 8 */
$
drivers/iommu/amd/amd_iommu_types.h 'union irte'
include/linux/dmar.h 'struct irte'
include/linux/device-mapper.h:
union map_info {
void *ptr;
};
include/linux/mtd/map.h:
struct map_info {
const char *name;
unsigned long size;
resource_size_t phys;
<SNIP>
kernel/events/uprobes.c:
struct map_info {
struct map_info *next;
struct mm_struct *mm;
unsigned long vaddr;
};
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:10 -08:00
|
|
|
|
|
|
|
rb_add(&result->node, &dso->data_types, data_type_less);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
static bool find_cu_die(struct debuginfo *di, u64 pc, Dwarf_Die *cu_die)
|
|
|
|
{
|
|
|
|
Dwarf_Off off, next_off;
|
|
|
|
size_t header_size;
|
|
|
|
|
|
|
|
if (dwarf_addrdie(di->dbg, pc, cu_die) != NULL)
|
|
|
|
return cu_die;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There are some kernels don't have full aranges and contain only a few
|
|
|
|
* aranges entries. Fallback to iterate all CU entries in .debug_info
|
|
|
|
* in case it's missing.
|
|
|
|
*/
|
|
|
|
off = 0;
|
|
|
|
while (dwarf_nextcu(di->dbg, off, &next_off, &header_size,
|
|
|
|
NULL, NULL, NULL) == 0) {
|
|
|
|
if (dwarf_offdie(di->dbg, off + header_size, cu_die) &&
|
|
|
|
dwarf_haspc(cu_die, pc))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
off = next_off;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The type info will be saved in @type_die */
|
2024-01-16 22:26:53 -08:00
|
|
|
static int check_variable(Dwarf_Die *var_die, Dwarf_Die *type_die, int offset,
|
|
|
|
bool is_pointer)
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
{
|
|
|
|
Dwarf_Word size;
|
|
|
|
|
|
|
|
/* Get the type of the variable */
|
|
|
|
if (die_get_real_type(var_die, type_die) == NULL) {
|
2024-03-18 22:51:00 -07:00
|
|
|
pr_debug_dtp("variable has no type\n");
|
2023-12-12 16:13:22 -08:00
|
|
|
ann_data_stat.no_typeinfo++;
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2024-01-16 22:26:53 -08:00
|
|
|
* Usually it expects a pointer type for a memory access.
|
|
|
|
* Convert to a real type it points to. But global variables
|
2024-01-16 22:26:56 -08:00
|
|
|
* and local variables are accessed directly without a pointer.
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
*/
|
2024-01-16 22:26:53 -08:00
|
|
|
if (is_pointer) {
|
|
|
|
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) {
|
2024-03-18 22:51:00 -07:00
|
|
|
pr_debug_dtp("no pointer or no type\n");
|
2024-01-16 22:26:53 -08:00
|
|
|
ann_data_stat.no_typeinfo++;
|
|
|
|
return -1;
|
|
|
|
}
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the size of the actual type */
|
|
|
|
if (dwarf_aggregate_size(type_die, &size) < 0) {
|
2024-03-18 22:51:00 -07:00
|
|
|
pr_debug_dtp("type size is unknown\n");
|
2023-12-12 16:13:22 -08:00
|
|
|
ann_data_stat.invalid_size++;
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Minimal sanity check */
|
|
|
|
if ((unsigned)offset >= size) {
|
2024-03-18 22:51:00 -07:00
|
|
|
pr_debug_dtp("offset: %d is bigger than size: %"PRIu64"\n",
|
|
|
|
offset, size);
|
2023-12-12 16:13:22 -08:00
|
|
|
ann_data_stat.bad_offset++;
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-03-18 22:51:01 -07:00
|
|
|
static struct type_state_stack *find_stack_state(struct type_state *state,
|
|
|
|
int offset)
|
|
|
|
{
|
|
|
|
struct type_state_stack *stack;
|
|
|
|
|
|
|
|
list_for_each_entry(stack, &state->stack_vars, list) {
|
|
|
|
if (offset == stack->offset)
|
|
|
|
return stack;
|
|
|
|
|
|
|
|
if (stack->compound && stack->offset < offset &&
|
|
|
|
offset < stack->offset + stack->size)
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_stack_state(struct type_state_stack *stack, int offset,
|
|
|
|
Dwarf_Die *type_die)
|
|
|
|
{
|
|
|
|
int tag;
|
|
|
|
Dwarf_Word size;
|
|
|
|
|
|
|
|
if (dwarf_aggregate_size(type_die, &size) < 0)
|
|
|
|
size = 0;
|
|
|
|
|
|
|
|
tag = dwarf_tag(type_die);
|
|
|
|
|
|
|
|
stack->type = *type_die;
|
|
|
|
stack->size = size;
|
|
|
|
stack->offset = offset;
|
|
|
|
|
|
|
|
switch (tag) {
|
|
|
|
case DW_TAG_structure_type:
|
|
|
|
case DW_TAG_union_type:
|
|
|
|
stack->compound = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
stack->compound = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct type_state_stack *findnew_stack_state(struct type_state *state,
|
|
|
|
int offset, Dwarf_Die *type_die)
|
|
|
|
{
|
|
|
|
struct type_state_stack *stack = find_stack_state(state, offset);
|
|
|
|
|
|
|
|
if (stack) {
|
|
|
|
set_stack_state(stack, offset, type_die);
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
stack = malloc(sizeof(*stack));
|
|
|
|
if (stack) {
|
|
|
|
set_stack_state(stack, offset, type_die);
|
|
|
|
list_add(&stack->list, &state->stack_vars);
|
|
|
|
}
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
2024-03-18 22:51:03 -07:00
|
|
|
static bool get_global_var_type(Dwarf_Die *cu_die, struct data_loc_info *dloc,
|
|
|
|
u64 ip, u64 var_addr, int *var_offset,
|
|
|
|
Dwarf_Die *type_die)
|
|
|
|
{
|
|
|
|
u64 pc, mem_addr;
|
|
|
|
int offset;
|
|
|
|
bool is_pointer = false;
|
|
|
|
const char *var_name = NULL;
|
|
|
|
Dwarf_Die var_die;
|
|
|
|
struct addr_location al;
|
|
|
|
struct symbol *sym;
|
|
|
|
|
|
|
|
/* Try to get the variable by address first */
|
|
|
|
if (die_find_variable_by_addr(cu_die, var_addr, &var_die, &offset) &&
|
|
|
|
check_variable(&var_die, type_die, offset, is_pointer) == 0) {
|
|
|
|
*var_offset = offset;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Kernel symbols might be relocated */
|
|
|
|
mem_addr = var_addr + map__reloc(dloc->ms->map);
|
|
|
|
|
|
|
|
addr_location__init(&al);
|
|
|
|
sym = thread__find_symbol_fb(dloc->thread, dloc->cpumode,
|
|
|
|
mem_addr, &al);
|
|
|
|
if (sym) {
|
|
|
|
var_name = sym->name;
|
|
|
|
/* Calculate type offset from the start of variable */
|
|
|
|
*var_offset = mem_addr - map__unmap_ip(al.map, sym->start);
|
|
|
|
}
|
|
|
|
addr_location__exit(&al);
|
|
|
|
if (var_name == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
pc = map__rip_2objdump(dloc->ms->map, ip);
|
|
|
|
|
|
|
|
/* Try to get the name of global variable */
|
|
|
|
if (die_find_variable_at(cu_die, var_name, pc, &var_die) &&
|
|
|
|
check_variable(&var_die, type_die, *var_offset, is_pointer) == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-03-18 22:51:01 -07:00
|
|
|
/**
|
|
|
|
* update_var_state - Update type state using given variables
|
|
|
|
* @state: type state table
|
|
|
|
* @dloc: data location info
|
|
|
|
* @addr: instruction address to match with variable
|
|
|
|
* @insn_offset: instruction offset (for debug)
|
|
|
|
* @var_types: list of variables with type info
|
|
|
|
*
|
|
|
|
* This function fills the @state table using @var_types info. Each variable
|
|
|
|
* is used only at the given location and updates an entry in the table.
|
|
|
|
*/
|
|
|
|
void update_var_state(struct type_state *state, struct data_loc_info *dloc,
|
|
|
|
u64 addr, u64 insn_offset, struct die_var_type *var_types)
|
|
|
|
{
|
|
|
|
Dwarf_Die mem_die;
|
|
|
|
struct die_var_type *var;
|
|
|
|
int fbreg = dloc->fbreg;
|
|
|
|
int fb_offset = 0;
|
|
|
|
|
|
|
|
if (dloc->fb_cfa) {
|
|
|
|
if (die_get_cfa(dloc->di->dbg, addr, &fbreg, &fb_offset) < 0)
|
|
|
|
fbreg = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var = var_types; var != NULL; var = var->next) {
|
|
|
|
if (var->addr != addr)
|
|
|
|
continue;
|
|
|
|
/* Get the type DIE using the offset */
|
|
|
|
if (!dwarf_offdie(dloc->di->dbg, var->die_off, &mem_die))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (var->reg == DWARF_REG_FB) {
|
|
|
|
findnew_stack_state(state, var->offset, &mem_die);
|
|
|
|
|
2024-03-18 22:51:02 -07:00
|
|
|
pr_debug_dtp("var [%"PRIx64"] -%#x(stack)",
|
2024-03-18 22:51:01 -07:00
|
|
|
insn_offset, -var->offset);
|
|
|
|
pr_debug_type_name(&mem_die);
|
|
|
|
} else if (var->reg == fbreg) {
|
|
|
|
findnew_stack_state(state, var->offset - fb_offset, &mem_die);
|
|
|
|
|
2024-03-18 22:51:02 -07:00
|
|
|
pr_debug_dtp("var [%"PRIx64"] -%#x(stack)",
|
2024-03-18 22:51:01 -07:00
|
|
|
insn_offset, -var->offset + fb_offset);
|
|
|
|
pr_debug_type_name(&mem_die);
|
|
|
|
} else if (has_reg_type(state, var->reg) && var->offset == 0) {
|
|
|
|
struct type_state_reg *reg;
|
|
|
|
|
|
|
|
reg = &state->regs[var->reg];
|
|
|
|
reg->type = mem_die;
|
|
|
|
reg->ok = true;
|
|
|
|
|
2024-03-18 22:51:02 -07:00
|
|
|
pr_debug_dtp("var [%"PRIx64"] reg%d",
|
2024-03-18 22:51:01 -07:00
|
|
|
insn_offset, var->reg);
|
|
|
|
pr_debug_type_name(&mem_die);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-18 22:51:02 -07:00
|
|
|
static void update_insn_state_x86(struct type_state *state,
|
2024-03-18 22:51:04 -07:00
|
|
|
struct data_loc_info *dloc, Dwarf_Die *cu_die,
|
2024-03-18 22:51:02 -07:00
|
|
|
struct disasm_line *dl)
|
|
|
|
{
|
|
|
|
struct annotated_insn_loc loc;
|
|
|
|
struct annotated_op_loc *src = &loc.ops[INSN_OP_SOURCE];
|
|
|
|
struct annotated_op_loc *dst = &loc.ops[INSN_OP_TARGET];
|
|
|
|
struct type_state_reg *tsr;
|
|
|
|
Dwarf_Die type_die;
|
|
|
|
u32 insn_offset = dl->al.offset;
|
|
|
|
int fbreg = dloc->fbreg;
|
|
|
|
int fboff = 0;
|
|
|
|
|
|
|
|
if (annotate_get_insn_location(dloc->arch, dl, &loc) < 0)
|
|
|
|
return;
|
|
|
|
|
2024-03-18 22:51:05 -07:00
|
|
|
if (ins__is_call(&dl->ins)) {
|
|
|
|
struct symbol *func = dl->ops.target.sym;
|
|
|
|
|
|
|
|
if (func == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* __fentry__ will preserve all registers */
|
|
|
|
if (!strcmp(func->name, "__fentry__"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
pr_debug_dtp("call [%x] %s\n", insn_offset, func->name);
|
|
|
|
|
|
|
|
/* Otherwise invalidate caller-saved registers after call */
|
|
|
|
for (unsigned i = 0; i < ARRAY_SIZE(state->regs); i++) {
|
|
|
|
if (state->regs[i].caller_saved)
|
|
|
|
state->regs[i].ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update register with the return type (if any) */
|
|
|
|
if (die_find_func_rettype(cu_die, func->name, &type_die)) {
|
|
|
|
tsr = &state->regs[state->ret_reg];
|
|
|
|
tsr->type = type_die;
|
|
|
|
tsr->ok = true;
|
|
|
|
|
|
|
|
pr_debug_dtp("call [%x] return -> reg%d",
|
|
|
|
insn_offset, state->ret_reg);
|
|
|
|
pr_debug_type_name(&type_die);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-18 22:51:02 -07:00
|
|
|
if (strncmp(dl->ins.name, "mov", 3))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (dloc->fb_cfa) {
|
|
|
|
u64 ip = dloc->ms->sym->start + dl->al.offset;
|
|
|
|
u64 pc = map__rip_2objdump(dloc->ms->map, ip);
|
|
|
|
|
|
|
|
if (die_get_cfa(dloc->di->dbg, pc, &fbreg, &fboff) < 0)
|
|
|
|
fbreg = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Case 1. register to register transfers */
|
|
|
|
if (!src->mem_ref && !dst->mem_ref) {
|
|
|
|
if (!has_reg_type(state, dst->reg1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
tsr = &state->regs[dst->reg1];
|
|
|
|
if (!has_reg_type(state, src->reg1) ||
|
|
|
|
!state->regs[src->reg1].ok) {
|
|
|
|
tsr->ok = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tsr->type = state->regs[src->reg1].type;
|
|
|
|
tsr->ok = true;
|
|
|
|
|
|
|
|
pr_debug_dtp("mov [%x] reg%d -> reg%d",
|
|
|
|
insn_offset, src->reg1, dst->reg1);
|
|
|
|
pr_debug_type_name(&tsr->type);
|
|
|
|
}
|
|
|
|
/* Case 2. memory to register transers */
|
|
|
|
if (src->mem_ref && !dst->mem_ref) {
|
|
|
|
int sreg = src->reg1;
|
|
|
|
|
|
|
|
if (!has_reg_type(state, dst->reg1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
tsr = &state->regs[dst->reg1];
|
|
|
|
|
|
|
|
retry:
|
|
|
|
/* Check stack variables with offset */
|
|
|
|
if (sreg == fbreg) {
|
|
|
|
struct type_state_stack *stack;
|
|
|
|
int offset = src->offset - fboff;
|
|
|
|
|
|
|
|
stack = find_stack_state(state, offset);
|
|
|
|
if (stack == NULL) {
|
|
|
|
tsr->ok = false;
|
|
|
|
return;
|
|
|
|
} else if (!stack->compound) {
|
|
|
|
tsr->type = stack->type;
|
|
|
|
tsr->ok = true;
|
|
|
|
} else if (die_get_member_type(&stack->type,
|
|
|
|
offset - stack->offset,
|
|
|
|
&type_die)) {
|
|
|
|
tsr->type = type_die;
|
|
|
|
tsr->ok = true;
|
|
|
|
} else {
|
|
|
|
tsr->ok = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_debug_dtp("mov [%x] -%#x(stack) -> reg%d",
|
|
|
|
insn_offset, -offset, dst->reg1);
|
|
|
|
pr_debug_type_name(&tsr->type);
|
|
|
|
}
|
|
|
|
/* And then dereference the pointer if it has one */
|
|
|
|
else if (has_reg_type(state, sreg) && state->regs[sreg].ok &&
|
|
|
|
die_deref_ptr_type(&state->regs[sreg].type,
|
|
|
|
src->offset, &type_die)) {
|
|
|
|
tsr->type = type_die;
|
|
|
|
tsr->ok = true;
|
|
|
|
|
|
|
|
pr_debug_dtp("mov [%x] %#x(reg%d) -> reg%d",
|
|
|
|
insn_offset, src->offset, sreg, dst->reg1);
|
|
|
|
pr_debug_type_name(&tsr->type);
|
|
|
|
}
|
2024-03-18 22:51:04 -07:00
|
|
|
/* Or check if it's a global variable */
|
|
|
|
else if (sreg == DWARF_REG_PC) {
|
|
|
|
struct map_symbol *ms = dloc->ms;
|
|
|
|
u64 ip = ms->sym->start + dl->al.offset;
|
|
|
|
u64 addr;
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
addr = annotate_calc_pcrel(ms, ip, src->offset, dl);
|
|
|
|
|
|
|
|
if (!get_global_var_type(cu_die, dloc, ip, addr, &offset,
|
|
|
|
&type_die) ||
|
|
|
|
!die_get_member_type(&type_die, offset, &type_die)) {
|
|
|
|
tsr->ok = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tsr->type = type_die;
|
|
|
|
tsr->ok = true;
|
|
|
|
|
|
|
|
pr_debug_dtp("mov [%x] global addr=%"PRIx64" -> reg%d",
|
|
|
|
insn_offset, addr, dst->reg1);
|
|
|
|
pr_debug_type_name(&type_die);
|
|
|
|
}
|
2024-03-18 22:51:02 -07:00
|
|
|
/* Or try another register if any */
|
|
|
|
else if (src->multi_regs && sreg == src->reg1 &&
|
|
|
|
src->reg1 != src->reg2) {
|
|
|
|
sreg = src->reg2;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
/* It failed to get a type info, mark it as invalid */
|
|
|
|
else {
|
|
|
|
tsr->ok = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Case 3. register to memory transfers */
|
|
|
|
if (!src->mem_ref && dst->mem_ref) {
|
|
|
|
if (!has_reg_type(state, src->reg1) ||
|
|
|
|
!state->regs[src->reg1].ok)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Check stack variables with offset */
|
|
|
|
if (dst->reg1 == fbreg) {
|
|
|
|
struct type_state_stack *stack;
|
|
|
|
int offset = dst->offset - fboff;
|
|
|
|
|
|
|
|
stack = find_stack_state(state, offset);
|
|
|
|
if (stack) {
|
|
|
|
/*
|
|
|
|
* The source register is likely to hold a type
|
|
|
|
* of member if it's a compound type. Do not
|
|
|
|
* update the stack variable type since we can
|
|
|
|
* get the member type later by using the
|
|
|
|
* die_get_member_type().
|
|
|
|
*/
|
|
|
|
if (!stack->compound)
|
|
|
|
set_stack_state(stack, offset,
|
|
|
|
&state->regs[src->reg1].type);
|
|
|
|
} else {
|
|
|
|
findnew_stack_state(state, offset,
|
|
|
|
&state->regs[src->reg1].type);
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_debug_dtp("mov [%x] reg%d -> -%#x(stack)",
|
|
|
|
insn_offset, src->reg1, -offset);
|
|
|
|
pr_debug_type_name(&state->regs[src->reg1].type);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Ignore other transfers since it'd set a value in a struct
|
|
|
|
* and won't change the type.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
/* Case 4. memory to memory transfers (not handled for now) */
|
|
|
|
}
|
|
|
|
|
2024-03-18 22:51:04 -07:00
|
|
|
/**
|
|
|
|
* update_insn_state - Update type state for an instruction
|
|
|
|
* @state: type state table
|
|
|
|
* @dloc: data location info
|
|
|
|
* @cu_die: compile unit debug entry
|
|
|
|
* @dl: disasm line for the instruction
|
|
|
|
*
|
|
|
|
* This function updates the @state table for the target operand of the
|
|
|
|
* instruction at @dl if it transfers the type like MOV on x86. Since it
|
|
|
|
* tracks the type, it won't care about the values like in arithmetic
|
|
|
|
* instructions like ADD/SUB/MUL/DIV and INC/DEC.
|
|
|
|
*
|
|
|
|
* Note that ops->reg2 is only available when both mem_ref and multi_regs
|
|
|
|
* are true.
|
|
|
|
*/
|
2024-03-18 22:51:02 -07:00
|
|
|
void update_insn_state(struct type_state *state, struct data_loc_info *dloc,
|
2024-03-18 22:51:04 -07:00
|
|
|
Dwarf_Die *cu_die, struct disasm_line *dl)
|
2024-03-18 22:51:02 -07:00
|
|
|
{
|
|
|
|
if (arch__is(dloc->arch, "x86"))
|
2024-03-18 22:51:04 -07:00
|
|
|
update_insn_state_x86(state, dloc, cu_die, dl);
|
2024-03-18 22:51:02 -07:00
|
|
|
}
|
|
|
|
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
/* The result will be saved in @type_die */
|
2024-03-18 22:50:58 -07:00
|
|
|
static int find_data_type_die(struct data_loc_info *dloc, Dwarf_Die *type_die)
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
{
|
2024-03-18 22:50:58 -07:00
|
|
|
struct annotated_op_loc *loc = dloc->op;
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
Dwarf_Die cu_die, var_die;
|
|
|
|
Dwarf_Die *scopes = NULL;
|
2024-01-16 22:26:51 -08:00
|
|
|
int reg, offset;
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
int ret = -1;
|
|
|
|
int i, nr_scopes;
|
2024-01-16 22:26:56 -08:00
|
|
|
int fbreg = -1;
|
|
|
|
int fb_offset = 0;
|
2024-03-18 22:50:58 -07:00
|
|
|
bool is_fbreg = false;
|
|
|
|
u64 pc;
|
2024-03-18 22:51:00 -07:00
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
if (dloc->op->multi_regs)
|
|
|
|
snprintf(buf, sizeof(buf), " or reg%d", dloc->op->reg2);
|
|
|
|
else if (dloc->op->reg1 == DWARF_REG_PC)
|
|
|
|
snprintf(buf, sizeof(buf), " (PC)");
|
|
|
|
else
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
|
|
|
pr_debug_dtp("-----------------------------------------------------------\n");
|
|
|
|
pr_debug_dtp("%s [%"PRIx64"] for reg%d%s offset=%#x in %s\n",
|
|
|
|
__func__, dloc->ip - dloc->ms->sym->start,
|
|
|
|
dloc->op->reg1, buf, dloc->op->offset, dloc->ms->sym->name);
|
2024-03-18 22:50:58 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IP is a relative instruction address from the start of the map, as
|
|
|
|
* it can be randomized/relocated, it needs to translate to PC which is
|
|
|
|
* a file address for DWARF processing.
|
|
|
|
*/
|
|
|
|
pc = map__rip_2objdump(dloc->ms->map, dloc->ip);
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
|
|
|
|
/* Get a compile_unit for this address */
|
2024-03-18 22:50:58 -07:00
|
|
|
if (!find_cu_die(dloc->di, pc, &cu_die)) {
|
2024-03-18 22:51:00 -07:00
|
|
|
pr_debug_dtp("cannot find CU for address %"PRIx64"\n", pc);
|
2023-12-12 16:13:22 -08:00
|
|
|
ann_data_stat.no_cuinfo++;
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-01-16 22:26:51 -08:00
|
|
|
reg = loc->reg1;
|
|
|
|
offset = loc->offset;
|
|
|
|
|
2024-03-18 22:51:00 -07:00
|
|
|
pr_debug_dtp("CU die offset: %#lx\n", (long)dwarf_dieoffset(&cu_die));
|
|
|
|
|
2024-01-16 22:26:54 -08:00
|
|
|
if (reg == DWARF_REG_PC) {
|
2024-03-18 22:51:03 -07:00
|
|
|
if (get_global_var_type(&cu_die, dloc, dloc->ip, dloc->var_addr,
|
|
|
|
&offset, type_die)) {
|
2024-03-18 22:50:58 -07:00
|
|
|
dloc->type_offset = offset;
|
2024-03-18 22:51:00 -07:00
|
|
|
|
|
|
|
pr_debug_dtp("found PC-rel by addr=%#"PRIx64" offset=%#x\n",
|
|
|
|
dloc->var_addr, offset);
|
2024-01-16 22:26:54 -08:00
|
|
|
goto out;
|
|
|
|
}
|
2024-01-16 22:26:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a list of nested scopes - i.e. (inlined) functions and blocks. */
|
|
|
|
nr_scopes = die_get_scopes(&cu_die, pc, &scopes);
|
|
|
|
|
2024-01-16 22:26:56 -08:00
|
|
|
if (reg != DWARF_REG_PC && dwarf_hasattr(&scopes[0], DW_AT_frame_base)) {
|
|
|
|
Dwarf_Attribute attr;
|
|
|
|
Dwarf_Block block;
|
|
|
|
|
|
|
|
/* Check if the 'reg' is assigned as frame base register */
|
|
|
|
if (dwarf_attr(&scopes[0], DW_AT_frame_base, &attr) != NULL &&
|
|
|
|
dwarf_formblock(&attr, &block) == 0 && block.length == 1) {
|
|
|
|
switch (*block.data) {
|
|
|
|
case DW_OP_reg0 ... DW_OP_reg31:
|
2024-03-18 22:50:58 -07:00
|
|
|
fbreg = dloc->fbreg = *block.data - DW_OP_reg0;
|
2024-01-16 22:26:56 -08:00
|
|
|
break;
|
|
|
|
case DW_OP_call_frame_cfa:
|
2024-03-18 22:50:58 -07:00
|
|
|
dloc->fb_cfa = true;
|
|
|
|
if (die_get_cfa(dloc->di->dbg, pc, &fbreg,
|
2024-01-16 22:26:56 -08:00
|
|
|
&fb_offset) < 0)
|
|
|
|
fbreg = -1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2024-03-18 22:51:00 -07:00
|
|
|
|
|
|
|
pr_debug_dtp("frame base: cfa=%d fbreg=%d\n",
|
|
|
|
dloc->fb_cfa, fbreg);
|
2024-01-16 22:26:56 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-16 22:26:51 -08:00
|
|
|
retry:
|
2024-01-16 22:26:56 -08:00
|
|
|
is_fbreg = (reg == fbreg);
|
|
|
|
if (is_fbreg)
|
|
|
|
offset = loc->offset - fb_offset;
|
|
|
|
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
/* Search from the inner-most scope to the outer */
|
|
|
|
for (i = nr_scopes - 1; i >= 0; i--) {
|
2024-01-16 22:26:53 -08:00
|
|
|
if (reg == DWARF_REG_PC) {
|
2024-03-18 22:50:58 -07:00
|
|
|
if (!die_find_variable_by_addr(&scopes[i], dloc->var_addr,
|
2024-01-16 22:26:53 -08:00
|
|
|
&var_die, &offset))
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/* Look up variables/parameters in this scope */
|
|
|
|
if (!die_find_variable_by_reg(&scopes[i], pc, reg,
|
2024-01-16 22:26:56 -08:00
|
|
|
&offset, is_fbreg, &var_die))
|
2024-01-16 22:26:53 -08:00
|
|
|
continue;
|
|
|
|
}
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
|
|
|
|
/* Found a variable, see if it's correct */
|
2024-01-16 22:26:53 -08:00
|
|
|
ret = check_variable(&var_die, type_die, offset,
|
2024-01-16 22:26:56 -08:00
|
|
|
reg != DWARF_REG_PC && !is_fbreg);
|
2024-03-18 22:51:00 -07:00
|
|
|
if (ret == 0) {
|
|
|
|
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("%#x(PC) offset=%#x", loc->offset, offset);
|
|
|
|
else if (reg == DWARF_REG_FB || is_fbreg)
|
|
|
|
pr_debug_dtp("%#x(reg%d) stack fb_offset=%#x offset=%#x",
|
|
|
|
loc->offset, reg, fb_offset, offset);
|
|
|
|
else
|
|
|
|
pr_debug_dtp("%#x(reg%d)", loc->offset, reg);
|
|
|
|
pr_debug_type_name(type_die);
|
|
|
|
}
|
2024-03-18 22:50:58 -07:00
|
|
|
dloc->type_offset = offset;
|
2023-12-12 16:13:22 -08:00
|
|
|
goto out;
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
}
|
2024-01-16 22:26:51 -08:00
|
|
|
|
|
|
|
if (loc->multi_regs && reg == loc->reg1 && loc->reg1 != loc->reg2) {
|
|
|
|
reg = loc->reg2;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2024-03-18 22:51:00 -07:00
|
|
|
if (ret < 0) {
|
|
|
|
pr_debug_dtp("no variable found\n");
|
2023-12-12 16:13:22 -08:00
|
|
|
ann_data_stat.no_var++;
|
2024-03-18 22:51:00 -07:00
|
|
|
}
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
|
2023-12-12 16:13:22 -08:00
|
|
|
out:
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
free(scopes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* find_data_type - Return a data type at the location
|
2024-03-18 22:50:58 -07:00
|
|
|
* @dloc: data location
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
*
|
|
|
|
* This functions searches the debug information of the binary to get the data
|
2024-03-18 22:50:58 -07:00
|
|
|
* type it accesses. The exact location is expressed by (ip, reg, offset)
|
|
|
|
* for pointer variables or (ip, addr) for global variables. Note that global
|
|
|
|
* variables might update the @dloc->type_offset after finding the start of the
|
|
|
|
* variable. If it cannot find a global variable by address, it tried to find
|
|
|
|
* a declaration of the variable using var_name. In that case, @dloc->offset
|
|
|
|
* won't be updated.
|
2024-01-16 22:26:54 -08:00
|
|
|
*
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
* It return %NULL if not found.
|
|
|
|
*/
|
2024-03-18 22:50:58 -07:00
|
|
|
struct annotated_data_type *find_data_type(struct data_loc_info *dloc)
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
{
|
|
|
|
struct annotated_data_type *result = NULL;
|
2024-03-18 22:50:58 -07:00
|
|
|
struct dso *dso = map__dso(dloc->ms->map);
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
Dwarf_Die type_die;
|
|
|
|
|
2024-03-18 22:50:58 -07:00
|
|
|
dloc->di = debuginfo__new(dso->long_name);
|
|
|
|
if (dloc->di == NULL) {
|
2024-03-18 22:51:00 -07:00
|
|
|
pr_debug_dtp("cannot get the debug info\n");
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2024-03-18 22:50:58 -07:00
|
|
|
* The type offset is the same as instruction offset by default.
|
|
|
|
* But when finding a global variable, the offset won't be valid.
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
*/
|
2024-03-18 22:51:03 -07:00
|
|
|
dloc->type_offset = dloc->op->offset;
|
2024-03-18 22:50:58 -07:00
|
|
|
|
|
|
|
dloc->fbreg = -1;
|
|
|
|
|
|
|
|
if (find_data_type_die(dloc, &type_die) < 0)
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
goto out;
|
|
|
|
|
perf annotate-data: Add dso->data_types tree
To aggregate accesses to the same data type, add 'data_types' tree in
DSO to maintain data types and find it by name and size.
It might have different data types that happen to have the same name,
so it also compares the size of the type.
Even if it doesn't 100% guarantee, it reduces the possibility of
mis-handling of such conflicts.
And I don't think it's common to have different types with the same
name.
Committer notes:
Very few cases on the Linux kernel, but there are some different types
with the same name, unsure if there is a debug mode in libbpf dedup that
warns about such cases, but there are provisions in pahole for that,
see:
"emit: Notice type shadowing, i.e. multiple types with the same name (enum, struct, union, etc)"
https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=4f332dbfd02072e4f410db7bdcda8d6e3422974b
$ pahole --compile > vmlinux.h
$ rm -f a ; make a
cc a.c -o a
$ grep __[0-9] vmlinux.h
union irte__1 {
struct map_info__1;
struct map_info__1 {
struct map_info__1 * next; /* 0 8 */
$
drivers/iommu/amd/amd_iommu_types.h 'union irte'
include/linux/dmar.h 'struct irte'
include/linux/device-mapper.h:
union map_info {
void *ptr;
};
include/linux/mtd/map.h:
struct map_info {
const char *name;
unsigned long size;
resource_size_t phys;
<SNIP>
kernel/events/uprobes.c:
struct map_info {
struct map_info *next;
struct mm_struct *mm;
unsigned long vaddr;
};
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:10 -08:00
|
|
|
result = dso__findnew_data_type(dso, &type_die);
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
|
|
|
|
out:
|
2024-03-18 22:50:58 -07:00
|
|
|
debuginfo__delete(dloc->di);
|
perf annotate-data: Add find_data_type() to get type from memory access
The find_data_type() is to get a data type from the memory access at the
given address (IP) using a register and an offset.
It requires DWARF debug info in the DSO and searches the list of
variables and function parameters in the scope.
In a pseudo code, it does basically the following:
find_data_type(dso, ip, reg, offset)
{
pc = map__rip_2objdump(ip);
CU = dwarf_addrdie(dso->dwarf, pc);
scopes = die_get_scopes(CU, pc);
for_each_scope(S, scopes) {
V = die_find_variable_by_reg(S, pc, reg);
if (V && V.type == pointer_type) {
T = die_get_real_type(V);
if (offset < T.size)
return T;
}
}
return NULL;
}
Committer notes:
The 'size' variable in check_variable() is 64-bit, so use PRIu64 and
inttypes.h to debug it.
Ditto at find_data_type_die().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:09 -08:00
|
|
|
return result;
|
|
|
|
}
|
perf annotate-data: Add dso->data_types tree
To aggregate accesses to the same data type, add 'data_types' tree in
DSO to maintain data types and find it by name and size.
It might have different data types that happen to have the same name,
so it also compares the size of the type.
Even if it doesn't 100% guarantee, it reduces the possibility of
mis-handling of such conflicts.
And I don't think it's common to have different types with the same
name.
Committer notes:
Very few cases on the Linux kernel, but there are some different types
with the same name, unsure if there is a debug mode in libbpf dedup that
warns about such cases, but there are provisions in pahole for that,
see:
"emit: Notice type shadowing, i.e. multiple types with the same name (enum, struct, union, etc)"
https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=4f332dbfd02072e4f410db7bdcda8d6e3422974b
$ pahole --compile > vmlinux.h
$ rm -f a ; make a
cc a.c -o a
$ grep __[0-9] vmlinux.h
union irte__1 {
struct map_info__1;
struct map_info__1 {
struct map_info__1 * next; /* 0 8 */
$
drivers/iommu/amd/amd_iommu_types.h 'union irte'
include/linux/dmar.h 'struct irte'
include/linux/device-mapper.h:
union map_info {
void *ptr;
};
include/linux/mtd/map.h:
struct map_info {
const char *name;
unsigned long size;
resource_size_t phys;
<SNIP>
kernel/events/uprobes.c:
struct map_info {
struct map_info *next;
struct mm_struct *mm;
unsigned long vaddr;
};
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:10 -08:00
|
|
|
|
2023-12-12 16:13:17 -08:00
|
|
|
static int alloc_data_type_histograms(struct annotated_data_type *adt, int nr_entries)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
size_t sz = sizeof(struct type_hist);
|
|
|
|
|
|
|
|
sz += sizeof(struct type_hist_entry) * adt->self.size;
|
|
|
|
|
|
|
|
/* Allocate a table of pointers for each event */
|
|
|
|
adt->nr_histograms = nr_entries;
|
|
|
|
adt->histograms = calloc(nr_entries, sizeof(*adt->histograms));
|
|
|
|
if (adt->histograms == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each histogram is allocated for the whole size of the type.
|
|
|
|
* TODO: Probably we can move the histogram to members.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < nr_entries; i++) {
|
|
|
|
adt->histograms[i] = zalloc(sz);
|
|
|
|
if (adt->histograms[i] == NULL)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
while (--i >= 0)
|
|
|
|
free(adt->histograms[i]);
|
|
|
|
free(adt->histograms);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_data_type_histograms(struct annotated_data_type *adt)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < adt->nr_histograms; i++)
|
|
|
|
free(adt->histograms[i]);
|
|
|
|
free(adt->histograms);
|
|
|
|
}
|
|
|
|
|
perf annotate-data: Add dso->data_types tree
To aggregate accesses to the same data type, add 'data_types' tree in
DSO to maintain data types and find it by name and size.
It might have different data types that happen to have the same name,
so it also compares the size of the type.
Even if it doesn't 100% guarantee, it reduces the possibility of
mis-handling of such conflicts.
And I don't think it's common to have different types with the same
name.
Committer notes:
Very few cases on the Linux kernel, but there are some different types
with the same name, unsure if there is a debug mode in libbpf dedup that
warns about such cases, but there are provisions in pahole for that,
see:
"emit: Notice type shadowing, i.e. multiple types with the same name (enum, struct, union, etc)"
https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=4f332dbfd02072e4f410db7bdcda8d6e3422974b
$ pahole --compile > vmlinux.h
$ rm -f a ; make a
cc a.c -o a
$ grep __[0-9] vmlinux.h
union irte__1 {
struct map_info__1;
struct map_info__1 {
struct map_info__1 * next; /* 0 8 */
$
drivers/iommu/amd/amd_iommu_types.h 'union irte'
include/linux/dmar.h 'struct irte'
include/linux/device-mapper.h:
union map_info {
void *ptr;
};
include/linux/mtd/map.h:
struct map_info {
const char *name;
unsigned long size;
resource_size_t phys;
<SNIP>
kernel/events/uprobes.c:
struct map_info {
struct map_info *next;
struct mm_struct *mm;
unsigned long vaddr;
};
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:10 -08:00
|
|
|
void annotated_data_type__tree_delete(struct rb_root *root)
|
|
|
|
{
|
|
|
|
struct annotated_data_type *pos;
|
|
|
|
|
|
|
|
while (!RB_EMPTY_ROOT(root)) {
|
|
|
|
struct rb_node *node = rb_first(root);
|
|
|
|
|
|
|
|
rb_erase(node, root);
|
|
|
|
pos = rb_entry(node, struct annotated_data_type, node);
|
2023-12-12 16:13:16 -08:00
|
|
|
delete_members(&pos->self);
|
2023-12-12 16:13:17 -08:00
|
|
|
delete_data_type_histograms(pos);
|
2023-12-12 16:13:16 -08:00
|
|
|
free(pos->self.type_name);
|
perf annotate-data: Add dso->data_types tree
To aggregate accesses to the same data type, add 'data_types' tree in
DSO to maintain data types and find it by name and size.
It might have different data types that happen to have the same name,
so it also compares the size of the type.
Even if it doesn't 100% guarantee, it reduces the possibility of
mis-handling of such conflicts.
And I don't think it's common to have different types with the same
name.
Committer notes:
Very few cases on the Linux kernel, but there are some different types
with the same name, unsure if there is a debug mode in libbpf dedup that
warns about such cases, but there are provisions in pahole for that,
see:
"emit: Notice type shadowing, i.e. multiple types with the same name (enum, struct, union, etc)"
https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?id=4f332dbfd02072e4f410db7bdcda8d6e3422974b
$ pahole --compile > vmlinux.h
$ rm -f a ; make a
cc a.c -o a
$ grep __[0-9] vmlinux.h
union irte__1 {
struct map_info__1;
struct map_info__1 {
struct map_info__1 * next; /* 0 8 */
$
drivers/iommu/amd/amd_iommu_types.h 'union irte'
include/linux/dmar.h 'struct irte'
include/linux/device-mapper.h:
union map_info {
void *ptr;
};
include/linux/mtd/map.h:
struct map_info {
const char *name;
unsigned long size;
resource_size_t phys;
<SNIP>
kernel/events/uprobes.c:
struct map_info {
struct map_info *next;
struct mm_struct *mm;
unsigned long vaddr;
};
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-toolchains@vger.kernel.org
Cc: linux-trace-devel@vger.kernel.org
Link: https://lore.kernel.org/r/20231213001323.718046-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-12-12 16:13:10 -08:00
|
|
|
free(pos);
|
|
|
|
}
|
|
|
|
}
|
2023-12-12 16:13:17 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* annotated_data_type__update_samples - Update histogram
|
|
|
|
* @adt: Data type to update
|
|
|
|
* @evsel: Event to update
|
|
|
|
* @offset: Offset in the type
|
|
|
|
* @nr_samples: Number of samples at this offset
|
|
|
|
* @period: Event count at this offset
|
|
|
|
*
|
|
|
|
* This function updates type histogram at @ofs for @evsel. Samples are
|
|
|
|
* aggregated before calling this function so it can be called with more
|
|
|
|
* than one samples at a certain offset.
|
|
|
|
*/
|
|
|
|
int annotated_data_type__update_samples(struct annotated_data_type *adt,
|
|
|
|
struct evsel *evsel, int offset,
|
|
|
|
int nr_samples, u64 period)
|
|
|
|
{
|
|
|
|
struct type_hist *h;
|
|
|
|
|
|
|
|
if (adt == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (adt->histograms == NULL) {
|
|
|
|
int nr = evsel->evlist->core.nr_entries;
|
|
|
|
|
|
|
|
if (alloc_data_type_histograms(adt, nr) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset < 0 || offset >= adt->self.size)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
h = adt->histograms[evsel->core.idx];
|
|
|
|
|
|
|
|
h->nr_samples += nr_samples;
|
|
|
|
h->addr[offset].nr_samples += nr_samples;
|
|
|
|
h->period += period;
|
|
|
|
h->addr[offset].period += period;
|
|
|
|
return 0;
|
|
|
|
}
|