From 17df43c8f277805d7571c9c5b6e4ea88326132eb Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Fri, 31 Mar 2017 12:03:57 -0700 Subject: [PATCH] outdbg: add %pragma for maximum size of a raw data dump A raw data dump can potentially be very large, especially when incbin is used. Allow a %pragma for setting the maximum dump size (defaults to 128 bytes.) Signed-off-by: H. Peter Anvin --- asm/directiv.dat | 1 + doc/nasmdoc.src | 14 +++++++++----- output/outdbg.c | 34 +++++++++++++++++++++++++++++----- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/asm/directiv.dat b/asm/directiv.dat index e1378ec7..10ffebcd 100644 --- a/asm/directiv.dat +++ b/asm/directiv.dat @@ -77,3 +77,4 @@ uppercase ; outieee, outobj ; --- Pragma operations subsections_via_symbols ; macho no_dead_strip ; macho +maxdump ; dbg diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index 2d84b64e..fd3c6b6f 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -6217,11 +6217,6 @@ a hint as to where to find requested symbols. \H{dbgfmt} \i\c{dbg}: Debugging Format -The \c{dbg} output format is not built into NASM in the default -configuration. If you are building your own NASM executable from the -sources, you can define \i\c{OF_DBG} in \c{output/outform.h} or on the -compiler command line, and obtain the \c{dbg} output format. - The \c{dbg} format does not output an object file as such; instead, it outputs a text file which contains a complete list of all the transactions between the main body of NASM and the output-format @@ -6262,6 +6257,15 @@ yourself (using \c{EXTERN}, for example) if you really need to get a \c{dbg} accepts any section name and any directives at all, and logs them all to its output file. +\c{dbg} accepts and logs any \c{%pragma}, but the specific +\c{%pragma}: + +\c %pragma dbg maxdump + +where \c{} is either a number or \c{unlimited}, can be used to +control the maximum size for dumping the full contents of a +\c{rawdata} output object. + \C{16bit} Writing 16-bit Code (DOS, Windows 3/3.1) diff --git a/output/outdbg.c b/output/outdbg.c index 5608b446..ffd6b394 100644 --- a/output/outdbg.c +++ b/output/outdbg.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "nasm.h" #include "nasmlib.h" @@ -170,7 +171,7 @@ static void dbg_out(const struct out_data *data) fprintf(ofile, " ins %s(%d)", nasm_insn_names[data->itemp->opcode], data->itemp->operands); } else { - fprintf(ofile, " (data)"); + fprintf(ofile, " no ins (plain data)"); } if (data->type == OUT_ADDRESS || data->type == OUT_RELADDR || @@ -304,6 +305,13 @@ dbg_directive(enum directives directive, char *value, int pass) return DIRR_OK; } +static enum directive_result +dbg_pragma(const struct pragma *pragma); + +static const struct pragma_facility dbg_pragma_list[] = { + { NULL, dbg_pragma } +}; + static enum directive_result dbg_pragma(const struct pragma *pragma) { @@ -313,6 +321,26 @@ dbg_pragma(const struct pragma *pragma) pragma->opname, directive_name(pragma->opcode), pragma->tail); + if (pragma->facility == &dbg_pragma_list[0] && + pragma->opcode == D_MAXDUMP) { + if (!nasm_stricmp(pragma->tail, "unlimited")) { + dbg_max_data_dump = -1UL; + } else { + char *ep; + unsigned long arg; + + errno = 0; + arg = strtoul(pragma->tail, &ep, 0); + if (errno || *nasm_skip_spaces(ep)) { + nasm_error(ERR_WARNING | ERR_WARN_BAD_PRAGMA | ERR_PASS2, + "invalid %%pragma dbg maxdump argument"); + return DIRR_ERROR; + } else { + dbg_max_data_dump = arg; + } + } + } + return DIRR_OK; } @@ -385,10 +413,6 @@ static const struct dfmt * const debug_debug_arr[3] = { NULL }; -static const struct pragma_facility dbg_pragma_list[] = { - { NULL, dbg_pragma } -}; - const struct ofmt of_dbg = { "Trace of all info passed to output stage", "dbg",