[CLASSES]: Use strdup for the ->name members
Reducing the memory footprint, but more has to be done, such as to take advantage of the strings table when handling indirect strings. Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
This commit is contained in:
parent
6b82eae556
commit
97385598a6
30
classes.c
30
classes.c
|
@ -66,7 +66,7 @@ struct class *cu__find_class_by_name(struct cu *self, const char *name)
|
|||
struct class *pos;
|
||||
|
||||
list_for_each_entry(pos, &self->classes, node)
|
||||
if (strcmp(pos->name, name) == 0)
|
||||
if (pos->name != NULL && strcmp(pos->name, name) == 0)
|
||||
return pos;
|
||||
|
||||
return NULL;
|
||||
|
@ -154,7 +154,8 @@ static const char *class__name(struct class *self, const struct cu *cu,
|
|||
if (ptr_class != NULL)
|
||||
return class__name(ptr_class, cu, bf, len);
|
||||
} else
|
||||
snprintf(bf, len, "%s%s", tag_name(self->tag), self->name);
|
||||
snprintf(bf, len, "%s%s", tag_name(self->tag),
|
||||
self->name ?: "");
|
||||
return bf;
|
||||
}
|
||||
|
||||
|
@ -173,7 +174,7 @@ static struct class_member *class_member__new(uintmax_t type,
|
|||
self->bit_offset = bit_offset;
|
||||
|
||||
if (name != NULL)
|
||||
strncpy(self->name, name, sizeof(self->name));
|
||||
self->name = strdup(name);
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -197,7 +198,7 @@ static unsigned long class_member__print(struct class_member *self,
|
|||
unsigned long size = -1;
|
||||
|
||||
snprintf(member_name_bf, sizeof(member_name_bf),
|
||||
"%s;", self->name);
|
||||
"%s;", self->name ?: "");
|
||||
|
||||
if (class == NULL)
|
||||
snprintf(bf, sizeof(bf), "<%x>", self->type);
|
||||
|
@ -225,7 +226,7 @@ static unsigned long class_member__print(struct class_member *self,
|
|||
sizeof(class_name_bf));
|
||||
}
|
||||
snprintf(member_name_bf, sizeof(member_name_bf),
|
||||
"(*%s)();", self->name);
|
||||
"(*%s)();", self->name ?: "");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
@ -233,10 +234,12 @@ static unsigned long class_member__print(struct class_member *self,
|
|||
class_name = class__name(class, cu, class_name_bf, sizeof(class_name_bf));
|
||||
if (class->tag == DW_TAG_array_type)
|
||||
snprintf(member_name_bf, sizeof(member_name_bf),
|
||||
"%s[%lu];", self->name, class->nr_entries);
|
||||
"%s[%lu];", self->name ?: "",
|
||||
class->nr_entries);
|
||||
else if (self->bit_size != 0)
|
||||
snprintf(member_name_bf, sizeof(member_name_bf),
|
||||
"%s:%d;", self->name, self->bit_size);
|
||||
"%s:%d;", self->name ?: "",
|
||||
self->bit_size);
|
||||
}
|
||||
out:
|
||||
printf(" %-26s %-21s /* %5d %5lu */\n",
|
||||
|
@ -259,9 +262,9 @@ static struct class *class__new(const unsigned int tag,
|
|||
self->id = cu_offset;
|
||||
self->type = type;
|
||||
self->size = size;
|
||||
self->name[0] = '\0';
|
||||
self->name = NULL;
|
||||
if (name != NULL)
|
||||
strncpy(self->name, name, sizeof(self->name));
|
||||
self->name = strdup(name);
|
||||
self->decl_file = decl_file;
|
||||
self->decl_line = decl_line;
|
||||
self->nr_holes = 0;
|
||||
|
@ -341,7 +344,8 @@ static void class__print_function(struct class *self, const struct cu *cu)
|
|||
type = class__name(class_type, cu, bf, sizeof(bf));
|
||||
}
|
||||
|
||||
printf("%s%s %s(", self->inlined ? "inline " : "", type, self->name);
|
||||
printf("%s%s %s(", self->inlined ? "inline " : "",
|
||||
type, self->name ?: "");
|
||||
list_for_each_entry(pos, &self->members, node) {
|
||||
if (!first_parameter)
|
||||
fputs(", ", stdout);
|
||||
|
@ -351,7 +355,7 @@ static void class__print_function(struct class *self, const struct cu *cu)
|
|||
class_type = cu__find_class_by_id(cu, pos->type);
|
||||
if (class_type != NULL)
|
||||
type = class__name(class_type, cu, bf, sizeof(bf));
|
||||
printf("%s %s", type, pos->name);
|
||||
printf("%s %s", type, pos->name ?: "");
|
||||
}
|
||||
|
||||
/* No parameters? */
|
||||
|
@ -428,7 +432,7 @@ void class__print(struct class *self, const struct cu *cu)
|
|||
class__print_function(self, cu);
|
||||
break;
|
||||
default:
|
||||
printf("%s%s;\n", tag_name(self->tag), self->name);
|
||||
printf("%s%s;\n", tag_name(self->tag), self->name ?: "");
|
||||
break;
|
||||
}
|
||||
putchar('\n');
|
||||
|
@ -467,7 +471,7 @@ void classes__print(const unsigned int tag)
|
|||
struct class *class_pos;
|
||||
|
||||
list_for_each_entry(class_pos, &cu_pos->classes, node)
|
||||
if (class_pos->tag == tag && class_pos->name[0] != '\0') {
|
||||
if (class_pos->tag == tag && class_pos->name != NULL) {
|
||||
if (tag == DW_TAG_structure_type) {
|
||||
class__find_holes(class_pos, cu_pos);
|
||||
if (class_pos->nr_holes == 0)
|
||||
|
|
|
@ -23,7 +23,7 @@ struct cu {
|
|||
struct class {
|
||||
struct list_head node;
|
||||
struct list_head members;
|
||||
char name[128];
|
||||
const char *name;
|
||||
unsigned long size;
|
||||
unsigned int id;
|
||||
unsigned int type;
|
||||
|
@ -43,7 +43,7 @@ struct class {
|
|||
|
||||
struct class_member {
|
||||
struct list_head node;
|
||||
char name[128];
|
||||
char *name;
|
||||
unsigned int type;
|
||||
unsigned int offset;
|
||||
unsigned int bit_size;
|
||||
|
|
15
pfunct.c
15
pfunct.c
|
@ -71,7 +71,7 @@ static int class_iterator(struct cu *cu, struct class *class, void *cookie)
|
|||
if (verbose)
|
||||
class__print(class, cu);
|
||||
else
|
||||
printf("%s\n", class->name);
|
||||
printf("%s\n", class->name ?: "");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ static int sizes_iterator(struct cu *cu, struct class *class, void *cookie)
|
|||
if (class->tag != DW_TAG_subprogram || class->inlined)
|
||||
return 0;
|
||||
|
||||
printf("%s: %u\n", class->name, class->high_pc - class->low_pc);
|
||||
printf("%s: %u\n", class->name ?: "", class->high_pc - class->low_pc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ static int variables_iterator(struct cu *cu, struct class *class, void *cookie)
|
|||
return 0;
|
||||
|
||||
if (class->nr_variables > 0)
|
||||
printf("%s: %u\n", class->name, class->nr_variables);
|
||||
printf("%s: %u\n", class->name ?: "", class->nr_variables);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ static int goto_labels_iterator(struct cu *cu, struct class *class, void *cookie
|
|||
return 0;
|
||||
|
||||
if (class->nr_labels > 0)
|
||||
printf("%s: %u\n", class->name, class->nr_labels);
|
||||
printf("%s: %u\n", class->name ?: "", class->nr_labels);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ static int function_iterator(struct cu *cu, struct class *class, void *cookie)
|
|||
if (class->tag != DW_TAG_subprogram || class->inlined)
|
||||
return 0;
|
||||
|
||||
if (strcmp(class->name, cookie) == 0) {
|
||||
if (class->name != NULL && strcmp(class->name, cookie) == 0) {
|
||||
class__print(class, cu);
|
||||
return 1;
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ static int nr_parameters_iterator(struct cu *cu, struct class *class, void *cook
|
|||
return 0;
|
||||
|
||||
if (class->nr_members > 0)
|
||||
printf("%s: %u\n", class->name, class->nr_members);
|
||||
printf("%s: %u\n", class->name ?: "", class->nr_members);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,8 @@ static int function_name_len_iterator(struct cu *cu, struct class *class, void *
|
|||
if (class->tag != DW_TAG_subprogram || class->inlined)
|
||||
return 0;
|
||||
|
||||
printf("%s: %u\n", class->name, strlen(class->name));
|
||||
if (class->name != NULL)
|
||||
printf("%s: %u\n", class->name, strlen(class->name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue