summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominique Martinet <asmadeus@codewreck.org>2018-08-23 11:16:23 +0900
committerDominique Martinet <asmadeus@codewreck.org>2018-08-23 11:16:23 +0900
commitb50bd2b3cb9a4d72aba38faece8f53d2d24e0303 (patch)
treea5fc0e8f4eb6ffda99c07123969207f9ca00cde2
parentb4c5c1489cacb5f8b23504025fa69d84a97d4774 (diff)
handle '*' as print-all-fields
-rw-r--r--dwarf-extract-struct.c20
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,