From c3f6f8b79f5efde93939cd055afe91daa733f055 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Wed, 1 Oct 2008 11:26:51 -0300 Subject: [PATCH] dwarves_emit: Introduce type_emissions We may want to work on just one object file, not on a multi cu. Signed-off-by: Arnaldo Carvalho de Melo --- codiff.c | 4 ++-- ctracer.c | 7 ++++--- dtagnames.c | 2 +- dwarves.c | 21 ++++++++++++++------- dwarves.h | 20 ++++++++++++-------- dwarves_emit.c | 8 ++++---- pahole.c | 2 +- pdwtags.c | 2 +- pfunct.c | 2 +- pglobal.c | 2 +- prefcnt.c | 2 +- syscse.c | 2 +- 12 files changed, 43 insertions(+), 31 deletions(-) diff --git a/codiff.c b/codiff.c index 37ebb38..fbda042 100644 --- a/codiff.c +++ b/codiff.c @@ -695,8 +695,8 @@ failure: dwarves__init(0); structs_printed = strlist__new(false); - old_cus = cus__new(NULL, NULL); - new_cus = cus__new(NULL, NULL); + old_cus = cus__new(NULL); + new_cus = cus__new(NULL); if (old_cus == NULL || new_cus == NULL || structs_printed == NULL) { fputs("codiff: insufficient memory\n", stderr); return EXIT_FAILURE; diff --git a/ctracer.c b/ctracer.c index 0ab8b72..6b50a90 100644 --- a/ctracer.c +++ b/ctracer.c @@ -61,8 +61,7 @@ static FILE *fp_classes; * List of definitions and forward declarations already emitted for * methods_cus, to avoid duplication. */ -static LIST_HEAD(cus__definitions); -static LIST_HEAD(cus__fwd_decls); +static struct type_emissions cus__emissions; /* * CU blacklist: if a "blacklist.cu" file is present, don't consider the @@ -910,13 +909,15 @@ failure: */ dwarves__init(0); + type_emissions__init(&cus__emissions); + /* * Create the methods_cus (Compilation Units) object where we will * load the objects where we'll look for functions pointers to the * specified class, i.e. to find its "methods", where we'll insert * the entry and exit hooks. */ - methods_cus = cus__new(&cus__definitions, &cus__fwd_decls); + methods_cus = cus__new(&cus__emissions); if (methods_cus == NULL) { fputs("ctracer: insufficient memory\n", stderr); return EXIT_FAILURE; diff --git a/dtagnames.c b/dtagnames.c index f89a287..7610e77 100644 --- a/dtagnames.c +++ b/dtagnames.c @@ -42,7 +42,7 @@ static void cus__dump_class_tag_names(struct cus *self) int main(int argc, char *argv[]) { int err; - struct cus *cus = cus__new(NULL, NULL); + struct cus *cus = cus__new(NULL); if (cus == NULL) { fputs("dtagnames: insufficient memory\n", stderr); diff --git a/dwarves.c b/dwarves.c index cc7f408..321d2b7 100644 --- a/dwarves.c +++ b/dwarves.c @@ -2489,6 +2489,12 @@ size_t tag__fprintf(struct tag *self, const struct cu *cu, return printed; } +void type_emissions__init(struct type_emissions *self) +{ + INIT_LIST_HEAD(&self->definitions); + INIT_LIST_HEAD(&self->fwd_decls); +} + int cu__for_each_tag(struct cu *self, int (*iterator)(struct tag *tag, struct cu *cu, void *cookie), @@ -2615,17 +2621,18 @@ void cus__print_error_msg(const char *progname, const struct cus *cus, fprintf(stderr, "%s: %s\n", progname, strerror(err)); } -struct cus *cus__new(struct list_head *definitions, - struct list_head *fwd_decls) +struct cus *cus__new(struct type_emissions *emissions) { - struct cus *self = malloc(sizeof(*self)); + struct cus *self = malloc(sizeof(*self) + (emissions ? 0 : sizeof(*emissions))); if (self != NULL) { INIT_LIST_HEAD(&self->cus); - 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; + if (emissions != NULL) + self->emissions = emissions; + else { + self->emissions = (struct type_emissions *)(self + 1); + type_emissions__init(self->emissions); + } } return self; diff --git a/dwarves.h b/dwarves.h index dc2eda2..d49204f 100644 --- a/dwarves.h +++ b/dwarves.h @@ -20,14 +20,20 @@ struct argp; -struct cus { - struct list_head cus; - struct list_head priv_definitions; /* struct type entries */ - struct list_head priv_fwd_decls; /* struct class entries */ - struct list_head *definitions; - struct list_head *fwd_decls; +struct type_emissions { + struct list_head definitions; /* struct type entries */ + struct list_head fwd_decls; /* struct class entries */ }; +void type_emissions__init(struct type_emissions *self); + +struct cus { + struct list_head cus; + struct type_emissions *emissions; +}; + +struct cus *cus__new(struct type_emissions *emissions); + #define HASHTAGS__BITS 8 #define HASHTAGS__SIZE (1UL << HASHTAGS__BITS) #define hashtags__fn(key) hash_64(key, HASHTAGS__BITS) @@ -522,8 +528,6 @@ extern size_t lexblock__fprintf(const struct lexblock *self, const struct cu *cu, struct function *function, uint16_t indent, FILE *fp); -extern struct cus *cus__new(struct list_head *definitions, - struct list_head *fwd_decls); extern int cus__loadfl(struct cus *self, struct argp *argp, int argc, char *argv[]); extern int cus__load(struct cus *self, const char *filename); diff --git a/dwarves_emit.c b/dwarves_emit.c index d56b11c..29f812b 100644 --- a/dwarves_emit.c +++ b/dwarves_emit.c @@ -20,14 +20,14 @@ static void cus__add_definition(struct cus *self, struct type *type) type->definition_emitted = 1; if (!list_empty(&type->node)) list_del(&type->node); - list_add_tail(&type->node, self->definitions); + list_add_tail(&type->node, &self->emissions->definitions); } static void cus__add_fwd_decl(struct cus *self, struct type *type) { type->fwd_decl_emitted = 1; if (list_empty(&type->node)) - list_add_tail(&type->node, self->fwd_decls); + list_add_tail(&type->node, &self->emissions->fwd_decls); } struct type *cus__find_definition(const struct cus *self, const char *name) @@ -37,7 +37,7 @@ struct type *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->emissions->definitions, node) if (type__name(pos, NULL) != NULL && strcmp(type__name(pos, NULL), name) == 0) return pos; @@ -50,7 +50,7 @@ static struct type *cus__find_fwd_decl(const struct cus *self, { struct type *pos; - list_for_each_entry(pos, self->fwd_decls, node) + list_for_each_entry(pos, &self->emissions->fwd_decls, node) if (strcmp(type__name(pos, NULL), name) == 0) return pos; diff --git a/pahole.c b/pahole.c index d4c92ae..d296155 100644 --- a/pahole.c +++ b/pahole.c @@ -959,7 +959,7 @@ int main(int argc, char *argv[]) struct cus *cus; int err; - cus = cus__new(NULL, NULL); + cus = cus__new(NULL); if (cus == NULL) { fputs("pahole: insufficient memory\n", stderr); return EXIT_FAILURE; diff --git a/pdwtags.c b/pdwtags.c index beb44d8..9b1aa94 100644 --- a/pdwtags.c +++ b/pdwtags.c @@ -89,7 +89,7 @@ static struct argp pdwtags__argp = { int main(int argc, char *argv[]) { int err; - struct cus *cus = cus__new(NULL, NULL); + struct cus *cus = cus__new(NULL); if (cus == NULL) { fputs("pwdtags: insufficient memory\n", stderr); diff --git a/pfunct.c b/pfunct.c index c6ad4b4..78ddad8 100644 --- a/pfunct.c +++ b/pfunct.c @@ -492,7 +492,7 @@ int main(int argc, char *argv[]) { int err; - cus = cus__new(NULL, NULL); + cus = cus__new(NULL); if (cus == NULL) { fputs("pfunct: insufficient memory\n", stderr); return EXIT_FAILURE; diff --git a/pglobal.c b/pglobal.c index f3991ca..a023f41 100644 --- a/pglobal.c +++ b/pglobal.c @@ -310,7 +310,7 @@ static struct argp pglobal__argp = { int main(int argc, char *argv[]) { int err; - struct cus *cus = cus__new(NULL, NULL); + struct cus *cus = cus__new(NULL); if (cus == NULL) { fputs("pglobal: insufficient memory\n", stderr); diff --git a/prefcnt.c b/prefcnt.c index c140545..60bd411 100644 --- a/prefcnt.c +++ b/prefcnt.c @@ -150,7 +150,7 @@ static int cu_lost_iterator(struct cu *cu, void *cookie) int main(int argc, char *argv[]) { int err; - struct cus *cus = cus__new(NULL, NULL); + struct cus *cus = cus__new(NULL); if (cus == NULL) { fputs("prefcnt: insufficient memory\n", stderr); diff --git a/syscse.c b/syscse.c index 71a4368..cc1f785 100644 --- a/syscse.c +++ b/syscse.c @@ -143,7 +143,7 @@ static struct argp argp = { int main(int argc, char *argv[]) { int err; - struct cus *cus = cus__new(NULL, NULL); + struct cus *cus = cus__new(NULL); if (cus == NULL) { fprintf(stderr, "%s: insufficient memory\n", argv[0]);