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 <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2008-10-01 11:26:51 -03:00
parent 993bcbde35
commit c3f6f8b79f
12 changed files with 43 additions and 31 deletions

View File

@ -695,8 +695,8 @@ failure:
dwarves__init(0); dwarves__init(0);
structs_printed = strlist__new(false); structs_printed = strlist__new(false);
old_cus = cus__new(NULL, NULL); old_cus = cus__new(NULL);
new_cus = cus__new(NULL, NULL); new_cus = cus__new(NULL);
if (old_cus == NULL || new_cus == NULL || structs_printed == NULL) { if (old_cus == NULL || new_cus == NULL || structs_printed == NULL) {
fputs("codiff: insufficient memory\n", stderr); fputs("codiff: insufficient memory\n", stderr);
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@ -61,8 +61,7 @@ static FILE *fp_classes;
* List of definitions and forward declarations already emitted for * List of definitions and forward declarations already emitted for
* methods_cus, to avoid duplication. * methods_cus, to avoid duplication.
*/ */
static LIST_HEAD(cus__definitions); static struct type_emissions cus__emissions;
static LIST_HEAD(cus__fwd_decls);
/* /*
* CU blacklist: if a "blacklist.cu" file is present, don't consider the * CU blacklist: if a "blacklist.cu" file is present, don't consider the
@ -910,13 +909,15 @@ failure:
*/ */
dwarves__init(0); dwarves__init(0);
type_emissions__init(&cus__emissions);
/* /*
* Create the methods_cus (Compilation Units) object where we will * Create the methods_cus (Compilation Units) object where we will
* load the objects where we'll look for functions pointers to the * load the objects where we'll look for functions pointers to the
* specified class, i.e. to find its "methods", where we'll insert * specified class, i.e. to find its "methods", where we'll insert
* the entry and exit hooks. * the entry and exit hooks.
*/ */
methods_cus = cus__new(&cus__definitions, &cus__fwd_decls); methods_cus = cus__new(&cus__emissions);
if (methods_cus == NULL) { if (methods_cus == NULL) {
fputs("ctracer: insufficient memory\n", stderr); fputs("ctracer: insufficient memory\n", stderr);
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@ -42,7 +42,7 @@ static void cus__dump_class_tag_names(struct cus *self)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int err; int err;
struct cus *cus = cus__new(NULL, NULL); struct cus *cus = cus__new(NULL);
if (cus == NULL) { if (cus == NULL) {
fputs("dtagnames: insufficient memory\n", stderr); fputs("dtagnames: insufficient memory\n", stderr);

View File

@ -2489,6 +2489,12 @@ size_t tag__fprintf(struct tag *self, const struct cu *cu,
return printed; 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 cu__for_each_tag(struct cu *self,
int (*iterator)(struct tag *tag, struct cu *cu, int (*iterator)(struct tag *tag, struct cu *cu,
void *cookie), 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)); fprintf(stderr, "%s: %s\n", progname, strerror(err));
} }
struct cus *cus__new(struct list_head *definitions, struct cus *cus__new(struct type_emissions *emissions)
struct list_head *fwd_decls)
{ {
struct cus *self = malloc(sizeof(*self)); struct cus *self = malloc(sizeof(*self) + (emissions ? 0 : sizeof(*emissions)));
if (self != NULL) { if (self != NULL) {
INIT_LIST_HEAD(&self->cus); INIT_LIST_HEAD(&self->cus);
INIT_LIST_HEAD(&self->priv_definitions); if (emissions != NULL)
INIT_LIST_HEAD(&self->priv_fwd_decls); self->emissions = emissions;
self->definitions = definitions ?: &self->priv_definitions; else {
self->fwd_decls = fwd_decls ?: &self->priv_fwd_decls; self->emissions = (struct type_emissions *)(self + 1);
type_emissions__init(self->emissions);
}
} }
return self; return self;

View File

@ -20,14 +20,20 @@
struct argp; struct argp;
struct cus { struct type_emissions {
struct list_head cus; struct list_head definitions; /* struct type entries */
struct list_head priv_definitions; /* struct type entries */ struct list_head fwd_decls; /* struct class entries */
struct list_head priv_fwd_decls; /* struct class entries */
struct list_head *definitions;
struct list_head *fwd_decls;
}; };
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__BITS 8
#define HASHTAGS__SIZE (1UL << HASHTAGS__BITS) #define HASHTAGS__SIZE (1UL << HASHTAGS__BITS)
#define hashtags__fn(key) hash_64(key, 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, const struct cu *cu, struct function *function,
uint16_t indent, FILE *fp); 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, extern int cus__loadfl(struct cus *self, struct argp *argp,
int argc, char *argv[]); int argc, char *argv[]);
extern int cus__load(struct cus *self, const char *filename); extern int cus__load(struct cus *self, const char *filename);

View File

@ -20,14 +20,14 @@ static void cus__add_definition(struct cus *self, struct type *type)
type->definition_emitted = 1; type->definition_emitted = 1;
if (!list_empty(&type->node)) if (!list_empty(&type->node))
list_del(&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) static void cus__add_fwd_decl(struct cus *self, struct type *type)
{ {
type->fwd_decl_emitted = 1; type->fwd_decl_emitted = 1;
if (list_empty(&type->node)) 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) 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) if (name == NULL)
return 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 && if (type__name(pos, NULL) != NULL &&
strcmp(type__name(pos, NULL), name) == 0) strcmp(type__name(pos, NULL), name) == 0)
return pos; return pos;
@ -50,7 +50,7 @@ static struct type *cus__find_fwd_decl(const struct cus *self,
{ {
struct type *pos; 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) if (strcmp(type__name(pos, NULL), name) == 0)
return pos; return pos;

View File

@ -959,7 +959,7 @@ int main(int argc, char *argv[])
struct cus *cus; struct cus *cus;
int err; int err;
cus = cus__new(NULL, NULL); cus = cus__new(NULL);
if (cus == NULL) { if (cus == NULL) {
fputs("pahole: insufficient memory\n", stderr); fputs("pahole: insufficient memory\n", stderr);
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@ -89,7 +89,7 @@ static struct argp pdwtags__argp = {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int err; int err;
struct cus *cus = cus__new(NULL, NULL); struct cus *cus = cus__new(NULL);
if (cus == NULL) { if (cus == NULL) {
fputs("pwdtags: insufficient memory\n", stderr); fputs("pwdtags: insufficient memory\n", stderr);

View File

@ -492,7 +492,7 @@ int main(int argc, char *argv[])
{ {
int err; int err;
cus = cus__new(NULL, NULL); cus = cus__new(NULL);
if (cus == NULL) { if (cus == NULL) {
fputs("pfunct: insufficient memory\n", stderr); fputs("pfunct: insufficient memory\n", stderr);
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@ -310,7 +310,7 @@ static struct argp pglobal__argp = {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int err; int err;
struct cus *cus = cus__new(NULL, NULL); struct cus *cus = cus__new(NULL);
if (cus == NULL) { if (cus == NULL) {
fputs("pglobal: insufficient memory\n", stderr); fputs("pglobal: insufficient memory\n", stderr);

View File

@ -150,7 +150,7 @@ static int cu_lost_iterator(struct cu *cu, void *cookie)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int err; int err;
struct cus *cus = cus__new(NULL, NULL); struct cus *cus = cus__new(NULL);
if (cus == NULL) { if (cus == NULL) {
fputs("prefcnt: insufficient memory\n", stderr); fputs("prefcnt: insufficient memory\n", stderr);

View File

@ -143,7 +143,7 @@ static struct argp argp = {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int err; int err;
struct cus *cus = cus__new(NULL, NULL); struct cus *cus = cus__new(NULL);
if (cus == NULL) { if (cus == NULL) {
fprintf(stderr, "%s: insufficient memory\n", argv[0]); fprintf(stderr, "%s: insufficient memory\n", argv[0]);