82 lines
1.8 KiB
C
82 lines
1.8 KiB
C
/*
|
|
Copyright (C) 2007 Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
under the terms of version 2 of the GNU General Public License as
|
|
published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <malloc.h>
|
|
|
|
#include "dwarves.h"
|
|
|
|
static int emit_tag(struct tag *self, struct cu *cu, void *cookie)
|
|
{
|
|
if (self->tag != DW_TAG_array_type &&
|
|
self->tag != DW_TAG_base_type &&
|
|
self->tag != DW_TAG_const_type &&
|
|
self->tag != DW_TAG_formal_parameter &&
|
|
self->tag != DW_TAG_pointer_type &&
|
|
self->tag != DW_TAG_reference_type &&
|
|
self->tag != DW_TAG_subroutine_type &&
|
|
self->tag != DW_TAG_volatile_type) {
|
|
if (self->tag == DW_TAG_structure_type)
|
|
class__find_holes(tag__class(self), cu);
|
|
|
|
tag__print(self, cu, NULL, NULL);
|
|
|
|
if (self->tag == DW_TAG_subprogram) {
|
|
const struct function *fn = tag__function(self);
|
|
putchar('\n');
|
|
lexblock__print(&fn->lexblock, cu, 0);
|
|
} else if (self->tag != DW_TAG_structure_type)
|
|
puts(";");
|
|
putchar('\n');
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int cu__emit_tags(struct cu *self, void *cookie)
|
|
{
|
|
cu__for_each_tag(self, emit_tag, NULL, NULL);
|
|
return 0;
|
|
}
|
|
|
|
static void cus__emit_tags(struct cus *self)
|
|
{
|
|
cus__for_each_cu(self, cu__emit_tags, NULL, NULL);
|
|
}
|
|
|
|
static void usage(void)
|
|
{
|
|
printf("usage: pdwtags <filename>\n");
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct cus *cus;
|
|
char *filename = argv[1];
|
|
|
|
if (argc != 2) {
|
|
usage();
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
cus = cus__new(NULL, NULL);
|
|
if (cus == NULL) {
|
|
fputs("pwdtags: insufficient memory\n", stderr);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
if (cus__load(cus, filename) != 0) {
|
|
fprintf(stderr, "pdwtags: couldn't load DWARF info from %s\n",
|
|
filename);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
cus__emit_tags(cus);
|
|
return EXIT_SUCCESS;
|
|
}
|