2007-01-19 00:13:56 +01:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2007-05-26 15:29:02 +02:00
|
|
|
#include <argp.h>
|
2007-01-19 00:13:56 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
|
|
|
|
#include "dwarves.h"
|
|
|
|
|
2007-05-26 15:29:02 +02:00
|
|
|
static struct conf_fprintf conf = {
|
2007-05-24 22:19:21 +02:00
|
|
|
.emit_stats = 1,
|
|
|
|
};
|
|
|
|
|
2007-01-29 13:42:03 +01:00
|
|
|
static int emit_tag(struct tag *self, struct cu *cu, void *cookie __unused)
|
2007-01-19 00:13:56 +01:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2007-05-24 22:19:21 +02:00
|
|
|
tag__fprintf(self, cu, &conf, stdout);
|
2007-01-19 00:13:56 +01:00
|
|
|
|
|
|
|
if (self->tag == DW_TAG_subprogram) {
|
|
|
|
const struct function *fn = tag__function(self);
|
|
|
|
putchar('\n');
|
2007-02-15 14:56:16 +01:00
|
|
|
lexblock__fprintf(&fn->lexblock, cu, 0, stdout);
|
2007-01-19 00:13:56 +01:00
|
|
|
} else if (self->tag != DW_TAG_structure_type)
|
|
|
|
puts(";");
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-29 13:42:03 +01:00
|
|
|
static int cu__emit_tags(struct cu *self, void *cookie __unused)
|
2007-01-19 00:13:56 +01:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-05-26 15:29:02 +02:00
|
|
|
static const struct argp_option pdwtags__options[] = {
|
|
|
|
{
|
|
|
|
.key = 'V',
|
|
|
|
.name = "verbose",
|
|
|
|
.doc = "show details",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = NULL,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static error_t pdwtags__options_parser(int key, char *arg __unused,
|
|
|
|
struct argp_state *state)
|
|
|
|
{
|
|
|
|
switch (key) {
|
|
|
|
case ARGP_KEY_INIT: state->child_inputs[0] = state->input; break;
|
|
|
|
case 'V': conf.show_decl_info = 1; break;
|
|
|
|
default: return ARGP_ERR_UNKNOWN;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char pdwtags__args_doc[] = "[FILE]";
|
|
|
|
|
|
|
|
static struct argp pdwtags__argp = {
|
|
|
|
.options = pdwtags__options,
|
|
|
|
.parser = pdwtags__options_parser,
|
|
|
|
.args_doc = pdwtags__args_doc,
|
|
|
|
};
|
|
|
|
|
2007-01-19 00:13:56 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2007-04-24 21:09:34 +02:00
|
|
|
int err;
|
2007-03-30 18:54:59 +02:00
|
|
|
struct cus *cus = cus__new(NULL, NULL);
|
2007-01-19 00:41:25 +01:00
|
|
|
|
2007-01-19 00:13:56 +01:00
|
|
|
if (cus == NULL) {
|
|
|
|
fputs("pwdtags: insufficient memory\n", stderr);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-05-26 15:29:02 +02:00
|
|
|
err = cus__loadfl(cus, &pdwtags__argp, argc, argv);
|
2007-03-30 18:54:59 +02:00
|
|
|
if (err != 0)
|
2007-01-19 00:13:56 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2007-03-30 18:54:59 +02:00
|
|
|
dwarves__init(0);
|
2007-01-19 00:13:56 +01:00
|
|
|
cus__emit_tags(cus);
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|