aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2024-02-09 15:51:24 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2024-02-09 15:51:24 -0300
commit08fc8e3285733ec8f4e76656a11b1e9dcc412de1 (patch)
tree8fc46c0ab2942df36a89c8b0c58d39a54f578178
parentbd8d0536b4352b5d72c5bc67637fd68238cf2cca (diff)
downloadpahole-08fc8e3285733ec8f4e76656a11b1e9dcc412de1.tar.gz
fprintf: Introduce method to print info about type of last member
So far no change in output, the info printed about a struct type is just its padding (unused space at the end of the struct). Now we have everything in place to print holes, bit holes, etc. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--dwarves_fprintf.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c
index cfee786a..6ba0e9fc 100644
--- a/dwarves_fprintf.c
+++ b/dwarves_fprintf.c
@@ -1467,6 +1467,40 @@ struct member_types_holes {
uint32_t sum_paddings;
};
+static size_t class__fprintf_member_type_holes(struct class *class, const struct cu *cu,
+ struct member_types_holes *holes,
+ uint8_t *newline, const struct conf_fprintf *conf, FILE *fp)
+{
+ size_t printed = 0;
+ uint16_t padding;
+ /*
+ * We may not yet have looked for holes and paddings in this member's
+ * struct type.
+ */
+ class__find_holes(class);
+ class__infer_packed_attributes(class, cu);
+
+ padding = class->padding;
+ if (!padding)
+ return 0;
+
+ if (!(*newline)++) {
+ fputc('\n', fp);
+ ++printed;
+ }
+
+ printed += fprintf(fp, "\n%.*s/* XXX last struct has", conf->indent, tabs);
+
+ if (padding) {
+ ++holes->nr_paddings;
+ holes->sum_paddings += padding;
+
+ printed += fprintf(fp, " %d byte%s of padding", padding, padding != 1 ? "s" : "");
+ }
+
+ return printed + fprintf(fp, " */");
+}
+
static size_t __class__fprintf(struct class *class, const struct cu *cu,
const struct conf_fprintf *conf, FILE *fp)
{
@@ -1687,29 +1721,9 @@ static size_t __class__fprintf(struct class *class, const struct cu *cu,
if (tag__is_struct(pos_type) && !cconf.suppress_comments) {
struct class *tclass = tag__class(pos_type);
- uint16_t padding;
- /*
- * We may not yet have looked for holes and paddings
- * in this member's struct type.
- */
- class__find_holes(tclass);
- class__infer_packed_attributes(tclass, cu);
-
- padding = tclass->padding;
- if (padding > 0) {
- ++member_types_holes.nr_paddings;
- member_types_holes.sum_paddings += padding;
- if (!newline++) {
- fputc('\n', fp);
- ++printed;
- }
- printed += fprintf(fp, "\n%.*s/* XXX last "
- "struct has %d byte%s of "
- "padding */", cconf.indent,
- tabs, padding,
- padding != 1 ? "s" : "");
- }
+ printed += class__fprintf_member_type_holes(tclass, cu, &member_types_holes,
+ &newline, &cconf, fp);
}
if (pos->bit_hole != 0 && !cconf.suppress_comments) {