[CLASSES]: Allow struct cus instances to share a list of defs and fwd_decls
So that we can extract bits from one and combine it bits from other instances, like we'll do in ctracer, where we want to have a cus instance just to get the kprobes definitions and forward declarations but not handle the methods in it. Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
This commit is contained in:
parent
5f2af297df
commit
b0e2c51ec8
17
classes.c
17
classes.c
|
@ -433,7 +433,7 @@ struct class *cus__find_definition(const struct cus *self, const char *name)
|
|||
if (name == NULL)
|
||||
return NULL;
|
||||
|
||||
list_for_each_entry(pos, &self->definitions, node)
|
||||
list_for_each_entry(pos, self->definitions, node)
|
||||
if (pos->name != NULL && strcmp(pos->name, name) == 0)
|
||||
return pos;
|
||||
|
||||
|
@ -444,7 +444,7 @@ struct class *cus__find_fwd_decl(const struct cus *self, const char *name)
|
|||
{
|
||||
struct class *pos;
|
||||
|
||||
list_for_each_entry(pos, &self->fwd_decls, node)
|
||||
list_for_each_entry(pos, self->fwd_decls, node)
|
||||
if (strcmp(pos->name, name) == 0)
|
||||
return pos;
|
||||
|
||||
|
@ -456,14 +456,14 @@ static void cus__add_definition(struct cus *self, struct class *class)
|
|||
class->visited = 1;
|
||||
if (!list_empty(&class->node))
|
||||
list_del(&class->node);
|
||||
list_add_tail(&class->node, &self->definitions);
|
||||
list_add_tail(&class->node, self->definitions);
|
||||
}
|
||||
|
||||
static void cus__add_fwd_decl(struct cus *self, struct class *class)
|
||||
{
|
||||
class->fwd_decl_emitted = 1;
|
||||
if (list_empty(&class->node))
|
||||
list_add_tail(&class->node, &self->fwd_decls);
|
||||
list_add_tail(&class->node, self->fwd_decls);
|
||||
}
|
||||
|
||||
struct class *cu__find_class_by_id(const struct cu *self, const Dwarf_Off id)
|
||||
|
@ -2139,14 +2139,17 @@ out:
|
|||
return err;
|
||||
}
|
||||
|
||||
struct cus *cus__new(void)
|
||||
struct cus *cus__new(struct list_head *definitions,
|
||||
struct list_head *fwd_decls)
|
||||
{
|
||||
struct cus *self = malloc(sizeof(*self));
|
||||
|
||||
if (self != NULL) {
|
||||
INIT_LIST_HEAD(&self->cus);
|
||||
INIT_LIST_HEAD(&self->definitions);
|
||||
INIT_LIST_HEAD(&self->fwd_decls);
|
||||
INIT_LIST_HEAD(&self->priv_definitions);
|
||||
INIT_LIST_HEAD(&self->priv_fwd_decls);
|
||||
self->definitions = definitions ?: &self->priv_definitions;
|
||||
self->fwd_decls = fwd_decls ?: &self->priv_fwd_decls;
|
||||
}
|
||||
|
||||
return self;
|
||||
|
|
15
classes.h
15
classes.h
|
@ -18,8 +18,10 @@
|
|||
|
||||
struct cus {
|
||||
struct list_head cus;
|
||||
struct list_head definitions;
|
||||
struct list_head fwd_decls;
|
||||
struct list_head priv_definitions;
|
||||
struct list_head priv_fwd_decls;
|
||||
struct list_head *definitions;
|
||||
struct list_head *fwd_decls;
|
||||
};
|
||||
|
||||
struct cu {
|
||||
|
@ -160,10 +162,11 @@ extern void function__print(const struct function *self, int show_stats,
|
|||
const int show_variables,
|
||||
const int show_inline_expansions);
|
||||
|
||||
extern struct cus *cus__new(void);
|
||||
extern int cus__load(struct cus *self, const char *filename);
|
||||
extern struct cu *cus__find_cu_by_name(const struct cus *self,
|
||||
const char *name);
|
||||
extern struct cus *cus__new(struct list_head *definitions,
|
||||
struct list_head *fwd_decls);
|
||||
extern int cus__load(struct cus *self, const char *filename);
|
||||
extern struct cu *cus__find_cu_by_name(const struct cus *self,
|
||||
const char *name);
|
||||
extern struct function *cus__find_function_by_name(const struct cus *self,
|
||||
const char *name);
|
||||
extern int cus__emit_function_definitions(struct cus *self,
|
||||
|
|
4
codiff.c
4
codiff.c
|
@ -514,8 +514,8 @@ int main(int argc, char *argv[])
|
|||
show_terse_type_changes == 0)
|
||||
show_function_diffs = show_struct_diffs = 1;
|
||||
|
||||
old_cus = cus__new();
|
||||
new_cus = cus__new();
|
||||
old_cus = cus__new(NULL, NULL);
|
||||
new_cus = cus__new(NULL, NULL);
|
||||
if (old_cus == NULL || new_cus == NULL) {
|
||||
fputs("codiff: insufficient memory\n", stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
@ -297,7 +297,7 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cus = cus__new();
|
||||
cus = cus__new(NULL, NULL);
|
||||
if (cus == NULL) {
|
||||
fputs("ctracer: insufficient memory\n", stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
|
2
pahole.c
2
pahole.c
|
@ -322,7 +322,7 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cus = cus__new();
|
||||
cus = cus__new(NULL, NULL);
|
||||
if (cus == NULL) {
|
||||
fputs("pahole: insufficient memory\n", stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
|
2
pfunct.c
2
pfunct.c
|
@ -352,7 +352,7 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
cus = cus__new();
|
||||
cus = cus__new(NULL, NULL);
|
||||
if (cus == NULL) {
|
||||
fputs("pfunct: insufficient memory\n", stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
|
Loading…
Reference in New Issue