core: Make parameter->name a real string

For the threaded code we want to access strings in tags at the same time
that the string table may grow in another thread making the previous
pointer invalid, so, to avoid excessive locking, use plain strings.

The way the tools work will either consume the just produced CU straight
away or keep just one copy of each data structure when we keep all CUs
in memory, so lets try stopping using strings_t for strings.

For the parameter->name case we get the bonus of removing a user of
dwarves__active_loader.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2021-06-24 10:01:27 -03:00
parent f009162fd1
commit 3280cb4176
7 changed files with 12 additions and 15 deletions

View File

@ -541,7 +541,7 @@ static int32_t btf_encoder__add_func_proto(struct btf_encoder *encoder, struct c
/* add parameters */
param_idx = 0;
ftype__for_each_parameter(ftype, param) {
const char *name = dwarves__active_loader->strings__ptr(cu, param->name);
const char *name = parameter__name(param);
type_id = param->tag.type == 0 ? 0 : type_id_off + param->tag.type;
++param_idx;
@ -1135,7 +1135,7 @@ static bool has_arg_names(struct cu *cu, struct ftype *ftype)
const char *name;
ftype__for_each_parameter(ftype, param) {
name = dwarves__active_loader->strings__ptr(cu, param->name);
name = parameter__name(param);
if (name == NULL)
return false;
}

View File

@ -69,7 +69,7 @@ static int cu__load_ftype(struct cu *cu, struct ftype *proto, uint32_t tag, cons
goto out_free_parameters;
p->tag.tag = DW_TAG_formal_parameter;
p->tag.type = param->type;
p->name = param->name_off;
p->name = cu__btf_str(cu, param->name_off);
ftype__add_parameter(proto, p);
}
}

View File

@ -698,14 +698,13 @@ static int function__emit_probes(struct function *func, uint32_t function_id,
continue;
if (member != NULL)
fprintf(fp_methods, "\tif ($%s)\n\t",
parameter__name(pos, cu));
fprintf(fp_methods, "\tif ($%s)\n\t", parameter__name(pos));
fprintf(fp_methods,
"\tctracer__method_hook(%d, %d, $%s%s%s, %d);\n",
probe_type,
function_id,
parameter__name(pos, cu),
parameter__name(pos),
member ? "->" : "", member ?: "",
class__size(mini_class));
break;

View File

@ -913,7 +913,7 @@ static struct parameter *parameter__new(Dwarf_Die *die, struct cu *cu)
if (parm != NULL) {
tag__init(&parm->tag, cu, die);
parm->name = strings__add(strings, attr_string(die, DW_AT_name));
parm->name = strdup_attr_string(die, DW_AT_name);
}
return parm;

View File

@ -720,8 +720,8 @@ size_t lexblock__fprintf(const struct lexblock *lexblock, const struct cu *cu,
const struct conf_fprintf *conf, FILE *fp);
struct parameter {
struct tag tag;
strings_t name;
struct tag tag;
const char *name;
};
static inline struct parameter *tag__parameter(const struct tag *tag)
@ -729,10 +729,9 @@ static inline struct parameter *tag__parameter(const struct tag *tag)
return (struct parameter *)tag;
}
static inline const char *parameter__name(const struct parameter *parm,
const struct cu *cu)
static inline const char *parameter__name(const struct parameter *parm)
{
return cu__string(cu, parm->name);
return parm->name;
}
/*

View File

@ -1084,7 +1084,7 @@ size_t ftype__fprintf_parms(const struct ftype *ftype,
indent, tabs);
} else
first_parm = 0;
name = conf->no_parm_names ? NULL : parameter__name(pos, cu);
name = conf->no_parm_names ? NULL : parameter__name(pos);
type = cu__type(cu, pos->tag.type);
if (type == NULL) {
snprintf(sbf, sizeof(sbf),

View File

@ -77,8 +77,7 @@ static void emit_wrapper(struct function *f, struct cu *cu)
printf("wrap_%s:\n", name);
needs_wrapper = 1;
}
zero_extend(regparm, bt, cu,
parameter__name(parm, cu));
zero_extend(regparm, bt, cu, parameter__name(parm));
}
}
++regparm;