Reduce output differences with Sun's ctfdump
authorSofian Brabez <sbz@FreeBSD.org>
Sat, 12 Nov 2016 05:43:00 +0000 (06:43 +0100)
committerSofian Brabez <sbz@FreeBSD.org>
Mon, 16 Oct 2017 16:09:51 +0000 (18:09 +0200)
ctfdump.c

index 17bcc1fc83029f56ee4bc563fb4d5ef7d7b747b7..92eef883ce1b6885108090e16f657c65d91afd6f 100644 (file)
--- a/ctfdump.c
+++ b/ctfdump.c
@@ -69,6 +69,8 @@ int            elf_getsection(const char *, const char *, const char *,
 char           *decompress(const char *, size_t, off_t);
 #endif /* ZLIB */
 
+void           print_line(const char *);
+
 int
 main(int argc, char *argv[])
 {
@@ -280,6 +282,8 @@ ctf_dump(const char *p, size_t size, uint8_t flags)
        }
 
        if (flags & DUMP_HEADER) {
+               print_line("- CTF Header ");
+
                printf("  cth_magic    = 0x%04x\n", cth->cth_magic);
                printf("  cth_version  = %d\n", cth->cth_version);
                printf("  cth_flags    = 0x%02x\n", cth->cth_flags);
@@ -293,13 +297,14 @@ ctf_dump(const char *p, size_t size, uint8_t flags)
                printf("  cth_typeoff  = %d\n", cth->cth_typeoff);
                printf("  cth_stroff   = %d\n", cth->cth_stroff);
                printf("  cth_strlen   = %d\n", cth->cth_strlen);
-               printf("\n");
        }
 
        if (flags & DUMP_LABEL) {
                unsigned int             lbloff = cth->cth_lbloff;
                struct ctf_lblent       *ctl;
 
+               print_line("- Label Table ");
+
                while (lbloff < cth->cth_objtoff) {
                        ctl = (struct ctf_lblent *)(data + lbloff);
 
@@ -318,6 +323,8 @@ ctf_dump(const char *p, size_t size, uint8_t flags)
                const char              *s;
                int                      l;
 
+               print_line("- Data Objects ");
+
                while (objtoff < cth->cth_funcoff) {
                        dsp = (unsigned short *)(data + objtoff);
 
@@ -338,6 +345,8 @@ ctf_dump(const char *p, size_t size, uint8_t flags)
                const char              *s;
                int                      l;
 
+               print_line("- Functions ");
+
                fsp = (unsigned short *)(data + cth->cth_funcoff);
                while (fsp < (unsigned short *)(data + cth->cth_typeoff)) {
                        kind = CTF_INFO_KIND(*fsp);
@@ -357,12 +366,13 @@ ctf_dump(const char *p, size_t size, uint8_t flags)
                                printf("%u%s", *fsp++, (vlen > 0) ? ", " : "");
                        printf(")\n");
                }
-               printf("\n");
        }
 
        if (flags & DUMP_TYPE) {
                unsigned int             idx = 1, offset = cth->cth_typeoff;
 
+               print_line("- Types ");
+
                while (offset < cth->cth_stroff) {
                        offset += ctf_dump_type(cth, data, dlen, offset, idx++);
                }
@@ -373,6 +383,8 @@ ctf_dump(const char *p, size_t size, uint8_t flags)
                unsigned int             offset = 0;
                const char              *str;
 
+               print_line("- String Table ");
+
                while (offset < cth->cth_strlen) {
                        str = ctf_off2name(cth, data, dlen, offset);
 
@@ -384,7 +396,6 @@ ctf_dump(const char *p, size_t size, uint8_t flags)
                                offset++;
                        }
                }
-               printf("\n");
        }
 
        if (cth->cth_flags & CTF_F_COMPRESS)
@@ -627,3 +638,11 @@ usage(void)
        exit(1);
 }
 
+void
+print_line(const char *str)
+{
+       static int nchar = 78;
+       static const char line[] = "----------------------------------------"
+               "----------------------------------------";
+       printf("\n%s%.*s\n\n", str, (int)(nchar - strlen(str)), line);
+}