diff options
author | midipix <writeonce@midipix.org> | 2015-12-20 03:13:29 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-11-11 00:22:29 -0500 |
commit | 8cfad6a6b15e97d7a753558ebd34f8a9798196f6 (patch) | |
tree | faf7cbfb1bc9024db578fad55c8929991677c42a | |
parent | 7770733c95046ac92b98c632374eaf7642eb1e5d (diff) | |
download | mdso-8cfad6a6b15e97d7a753558ebd34f8a9798196f6.tar.bz2 mdso-8cfad6a6b15e97d7a753558ebd34f8a9798196f6.tar.xz |
output, mdso_output_export_symbols(): initial implementation.
-rw-r--r-- | include/mdso/mdso.h | 1 | ||||
-rw-r--r-- | include/mdso/mdso_output.h | 19 | ||||
-rw-r--r-- | project/common.mk | 1 | ||||
-rw-r--r-- | project/headers.mk | 1 | ||||
-rw-r--r-- | src/driver/mdso_driver_ctx.c | 14 | ||||
-rw-r--r-- | src/internal/mdso_driver_impl.h | 2 | ||||
-rw-r--r-- | src/mdso.c | 7 | ||||
-rw-r--r-- | src/output/mdso_output_export_symbols.c | 49 | ||||
-rw-r--r-- | src/skin/mdso_skin_default.c | 6 |
9 files changed, 100 insertions, 0 deletions
diff --git a/include/mdso/mdso.h b/include/mdso/mdso.h index de0bd89..24159b4 100644 --- a/include/mdso/mdso.h +++ b/include/mdso/mdso.h @@ -81,6 +81,7 @@ mdso_api int mdso_map_input (int fd, const char * path, int prot, struct mdso_ mdso_api int mdso_unmap_input (struct mdso_input *); /* utility api */ +mdso_api int mdso_output_export_symbols(const struct mdso_unit_ctx *, const struct mdso_common_ctx *, FILE *); /* low-level api */ mdso_api uint32_t mdso_crc32_mbstr (const unsigned char * str, size_t * symlen); diff --git a/include/mdso/mdso_output.h b/include/mdso/mdso_output.h new file mode 100644 index 0000000..9b158ed --- /dev/null +++ b/include/mdso/mdso_output.h @@ -0,0 +1,19 @@ +#ifndef MDSO_OUTPUT_H +#define MDSO_OUTPUT_H + +#include <stdint.h> + +#define MDSO_PRETTY(x) ((uint64_t)x << 32) + +/* output actions */ +#define MDSO_OUTPUT_EXPORT_SYMS 0x00000001 + + +/* pretty-printer flags */ +#define MDSO_PRETTY_LIST MDSO_PRETTY(0x00000001) +#define MDSO_PRETTY_TABLE MDSO_PRETTY(0x00000002) +#define MDSO_PRETTY_READOBJ MDSO_PRETTY(0x00000004) +#define MDSO_PRETTY_OBJDUMP MDSO_PRETTY(0x00000008) +#define MDSO_PRETTY_YAML MDSO_PRETTY(0x00000010) + +#endif diff --git a/project/common.mk b/project/common.mk index bf8df42..12c02e4 100644 --- a/project/common.mk +++ b/project/common.mk @@ -4,6 +4,7 @@ COMMON_SRCS = \ src/driver/mdso_driver_ctx.c \ src/driver/mdso_unit_ctx.c \ src/logic/mdso_map_input.c \ + src/output/mdso_output_export_symbols.c \ src/skin/mdso_skin_default.c \ APP_SRCS = \ diff --git a/project/headers.mk b/project/headers.mk index 8cf926a..2722875 100644 --- a/project/headers.mk +++ b/project/headers.mk @@ -3,6 +3,7 @@ API_HEADERS = \ $(PROJECT_DIR)/include/$(PACKAGE)/mdso_api.h \ $(PROJECT_DIR)/include/$(PACKAGE)/mdso_crc32.h \ $(PROJECT_DIR)/include/$(PACKAGE)/mdso_crc64.h \ + $(PROJECT_DIR)/include/$(PACKAGE)/mdso_output.h \ INTERNAL_HEADERS = \ $(PROJECT_DIR)/src/internal/argv/argv.h \ diff --git a/src/driver/mdso_driver_ctx.c b/src/driver/mdso_driver_ctx.c index 9c891de..c1e34ba 100644 --- a/src/driver/mdso_driver_ctx.c +++ b/src/driver/mdso_driver_ctx.c @@ -11,6 +11,7 @@ #define ARGV_DRIVER #include <mdso/mdso.h> +#include <mdso/mdso_output.h> #include "mdso_driver_impl.h" #include "argv/argv.h" @@ -98,6 +99,7 @@ int mdso_get_driver_ctx( struct argv_entry * entry; size_t nunits; const char * program; + const char * pretty; options = mdso_default_options; @@ -105,6 +107,7 @@ int mdso_get_driver_ctx( return -1; nunits = 0; + pretty = 0; program = argv_program_name(argv[0]); memset(&cctx,0,sizeof(cctx)); @@ -122,11 +125,22 @@ int mdso_get_driver_ctx( case TAG_VERSION: cctx.drvflags |= MDSO_DRIVER_VERSION; break; + + case TAG_PRETTY: + pretty = entry->arg; + break; + + case TAG_EXPSYMS: + cctx.fmtflags |= MDSO_OUTPUT_EXPORT_SYMS; + break; } } else nunits++; } + if (pretty && !strcmp(pretty,"yaml")) + cctx.fmtflags |= MDSO_PRETTY_YAML; + if (!(ctx = mdso_driver_ctx_alloc(meta,nunits))) return mdso_get_driver_ctx_fail(meta); diff --git a/src/internal/mdso_driver_impl.h b/src/internal/mdso_driver_impl.h index aa09197..d76f29e 100644 --- a/src/internal/mdso_driver_impl.h +++ b/src/internal/mdso_driver_impl.h @@ -10,6 +10,8 @@ enum app_tags { TAG_HELP, TAG_VERSION, + TAG_PRETTY, + TAG_EXPSYMS, }; struct mdso_expsyms { @@ -7,6 +7,7 @@ #include <stdio.h> #include <unistd.h> #include <mdso/mdso.h> +#include <mdso/mdso_output.h> #include "mdso_version.h" #ifndef MDSO_DRIVER_FLAGS @@ -23,6 +24,12 @@ static ssize_t mdso_version(struct mdso_driver_ctx * dctx) static void mdso_perform_unit_actions(struct mdso_unit_ctx * uctx) { + uint64_t flags = uctx->cctx->fmtflags; + + if (flags & MDSO_OUTPUT_EXPORT_SYMS) { + uctx->status = mdso_output_export_symbols(uctx,uctx->cctx,stdout); + uctx->nerrors += !!uctx->status; + } } static int mdso_exit(struct mdso_driver_ctx * dctx, int nerrors) diff --git a/src/output/mdso_output_export_symbols.c b/src/output/mdso_output_export_symbols.c new file mode 100644 index 0000000..eaac241 --- /dev/null +++ b/src/output/mdso_output_export_symbols.c @@ -0,0 +1,49 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include <mdso/mdso.h> +#include <mdso/mdso_output.h> + +static int pretty_header(const struct mdso_common_ctx * cctx, FILE * fout) +{ + return (cctx->fmtflags & MDSO_PRETTY_YAML) + ? fputs("exports:\n",fout) + : 0; +} + +static int pretty_export_item(const struct mdso_common_ctx * cctx, const char * name, FILE * fout) +{ + if (cctx->fmtflags & MDSO_PRETTY_YAML) + return fprintf(fout,"- %s\n",name); + else + return fprintf(fout,"%s\n",name); +} + +int mdso_output_export_symbols( + const struct mdso_unit_ctx * uctx, + const struct mdso_common_ctx * cctx, + FILE * fout) +{ + const char * const * sym; + + if (!uctx->syms[0]) + return 0; + + if ((pretty_header(cctx,fout)) < 0) + return -1; + + for (sym=uctx->syms; *sym; sym++) + if ((pretty_export_item(cctx,*sym,fout)) < 0) + return -1; + + return 0; +} diff --git a/src/skin/mdso_skin_default.c b/src/skin/mdso_skin_default.c index c12f371..cf65a3f 100644 --- a/src/skin/mdso_skin_default.c +++ b/src/skin/mdso_skin_default.c @@ -8,5 +8,11 @@ const struct argv_option mdso_default_options[] = { {"help", 'h',TAG_HELP,ARGV_OPTARG_OPTIONAL,"short|long",0, "show usage information [listing %s options only]"}, + {"pretty", 'p',TAG_PRETTY,ARGV_OPTARG_REQUIRED,"yaml",0, + "format output for parsing by %s"}, + + {"expsyms", 'e',TAG_EXPSYMS,ARGV_OPTARG_NONE,0,0, + "print exported symbols" }, + {0} }; |