diff options
-rw-r--r-- | dwarf-extract-struct.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/dwarf-extract-struct.c b/dwarf-extract-struct.c index 63bb310..e2b8a4f 100644 --- a/dwarf-extract-struct.c +++ b/dwarf-extract-struct.c @@ -11,6 +11,7 @@ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <strings.h> #include <sys/stat.h> #include <sys/types.h> @@ -19,6 +20,10 @@ #include "libdwarf/libdwarf.h" +#define COUNT_ALL (-1) + +static int debug = 0; + static void parse_dwarf(Dwarf_Debug dbg, const char *struct_name, const char *field_names[], int field_count); static void find_struct(Dwarf_Debug dbg, Dwarf_Die die, const char *struct_name, @@ -29,8 +34,6 @@ static void find_fields(Dwarf_Debug dbg, Dwarf_Die struct_die, Dwarf_Die die, static void print_field(Dwarf_Debug dbg, Dwarf_Die die, const char *field_name, int pad_num); -int debug = 0; - void usage(const char *argv[]) { fprintf(stderr, "%s debug_file struct_name [field [field...]]\n", argv[0]); @@ -349,6 +352,11 @@ static void find_fields(Dwarf_Debug dbg, Dwarf_Die struct_die, Dwarf_Die die, int rc, i, printed_count = 0; int size; + if (field_count == 1 && strcmp(field_names[0], "*") == 0) { + /* special value to print all fields */ + field_count = COUNT_ALL; + } + printf("struct %s {\n\tunion {\n", struct_name); @@ -405,6 +413,9 @@ static void find_fields(Dwarf_Debug dbg, Dwarf_Die struct_die, Dwarf_Die die, break; } } + if (field_count == COUNT_ALL) { + print_field(dbg, die, name, printed_count++); + } if (printed_count == field_count) { printf("\t};\n};\n"); exit(0); @@ -421,6 +432,11 @@ static void find_fields(Dwarf_Debug dbg, Dwarf_Die struct_die, Dwarf_Die die, die = next; } while (die); + + if (field_count == COUNT_ALL) { + printf("\t};\n};\n"); + exit(0); + } } static void print_field(Dwarf_Debug dbg, Dwarf_Die die, const char *field_name, |