Dump string table if "-s" is given
authorMartin Pieuchot <mpi@openbsd.org>
Tue, 15 Mar 2016 08:42:59 +0000 (09:42 +0100)
committerMartin Pieuchot <mpi@openbsd.org>
Wed, 16 Mar 2016 08:18:37 +0000 (09:18 +0100)
ctfdump.c

index 0474b562fe92169721573ba6087b63e6704d355a..99f5fc7a460780e14c555f14ca6742548773053f 100644 (file)
--- a/ctfdump.c
+++ b/ctfdump.c
@@ -41,6 +41,7 @@
 #define DUMP_FUNCTION  (1 << 1)
 #define DUMP_HEADER    (1 << 2)
 #define DUMP_LABEL     (1 << 3)
+#define DUMP_STRTAB    (1 << 4)
 
 int             dump(const char *, uint32_t);
 int             iself(const char *, size_t);
@@ -85,6 +86,9 @@ main(int argc, char *argv[])
                case 'l':
                        flags |= DUMP_LABEL;
                        break;
+               case 's':
+                       flags |= DUMP_STRTAB;
+                       break;
                default:
                        usage();
                }
@@ -462,6 +466,23 @@ ctf_dump(const char *p, size_t size, uint32_t flags)
                }
        }
 
+       if (flags & DUMP_STRTAB) {
+               unsigned int             offset = 0;
+               const char              *str;
+
+               while (offset < cth->cth_strlen) {
+                       str = data + cth->cth_stroff + offset;
+
+                       printf("[%u] ", offset);
+                       if (*str != '\0')
+                               offset += printf("%s\n", str);
+                       else {
+                               printf("\\0\n");
+                               offset++;
+                       }
+               }
+       }
+
        if (cth->cth_flags & CTF_F_COMPRESS)
                free(data);