Defer debug format search until after command line parsing

Avoid funnies with ordering of debug format selection by deferring
debug format search until after command line processing.  Also permit
the -gformat syntax used by many C compilers.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2016-03-07 23:18:30 -08:00
parent 477ae4419c
commit 283b3fb15a
4 changed files with 28 additions and 17 deletions

36
nasm.c
View file

@ -85,7 +85,9 @@ static void nasm_verror_vc(int severity, const char *fmt, va_list args);
static void nasm_verror_common(int severity, const char *fmt, va_list args);
static void usage(void);
static int using_debug_info, opt_verbose_info;
static bool using_debug_info, opt_verbose_info;
static const char *debug_format;
bool tasm_compatible_mode = false;
int pass0, passn;
int globalrel = 0;
@ -356,11 +358,21 @@ int main(int argc, char **argv)
return 1;
}
/* If debugging info is disabled, suppress any debug calls */
if (!using_debug_info)
if (!using_debug_info) {
/* No debug info, redirect to the null backend (empty stubs) */
dfmt = &null_debug_form;
else if (!dfmt)
} else if (!debug_format) {
/* Default debug format for this backend */
dfmt = ofmt->default_dfmt;
} else {
dfmt = dfmt_find(ofmt, debug_format);
if (!dfmt) {
nasm_fatal(ERR_NOFILE | ERR_USAGE,
"unrecognized debug format `%s' for"
" output format `%s'",
debug_format, ofmt->shortname);
}
}
if (ofmt->stdmac)
preproc->extra_stdmac(ofmt->stdmac);
@ -666,7 +678,6 @@ static bool process_arg(char *p, char *q)
"unrecognised output format `%s' - "
"use -hf for a list", param);
}
dfmt = NULL;
break;
case 'O': /* Optimization level */
@ -744,14 +755,8 @@ static bool process_arg(char *p, char *q)
break;
case 'F': /* specify debug format */
dfmt = dfmt_find(ofmt, param);
if (!dfmt) {
nasm_fatal(ERR_NOFILE | ERR_USAGE,
"unrecognized debug format `%s' for"
" output format `%s'",
param, ofmt->shortname);
}
using_debug_info = true;
debug_format = param;
break;
case 'X': /* specify error reporting format */
@ -767,6 +772,8 @@ static bool process_arg(char *p, char *q)
case 'g':
using_debug_info = true;
if (p[2])
debug_format = nasm_skip_spaces(p + 2);
break;
case 'h':
@ -775,8 +782,7 @@ static bool process_arg(char *p, char *q)
"[-l listfile]\n"
" [options...] [--] filename\n"
" or nasm -v (or --v) for version info\n\n"
" -t assemble in SciTech TASM compatible mode\n"
" -g generate debug information in selected format\n");
" -t assemble in SciTech TASM compatible mode\n");
printf
(" -E (or -e) preprocess only (writes output to stdout by default)\n"
" -a don't preprocess (assemble only)\n"
@ -789,7 +795,9 @@ static bool process_arg(char *p, char *q)
" -MP emit phony target\n\n"
" -Z<file> redirect error messages to file\n"
" -s redirect error messages to stdout\n\n"
" -g generate debugging information\n\n"
" -F format select a debugging format\n\n"
" -gformat same as -g -F format\n\n"
" -o outfile write output to an outfile\n\n"
" -f format select an output format\n\n"
" -l listfile write listing to a listfile\n\n"

View file

@ -47,7 +47,10 @@ OPTIONS
formats, use the *-y* option (for example *-felf -y*).
*-g*::
Causes *nasm* to generate debug information in selected format.
Causes *nasm* to generate debug information.
*-g*'format'::
Equivalent to **-g -F**__ format__.
*-h*::
Causes *nasm* to exit immediately, after giving a summary of its

View file

@ -72,7 +72,7 @@ struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias)
return NULL;
}
struct dfmt *dfmt_find(struct ofmt *ofmt, char *name)
struct dfmt *dfmt_find(struct ofmt *ofmt, const char *name)
{
struct dfmt **dfp, *df;

View file

@ -371,7 +371,7 @@ static struct ofmt_alias ofmt_aliases[] = {
#endif /* BUILD_DRIVERS_ARRAY */
struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias);
struct dfmt *dfmt_find(struct ofmt *, char *);
struct dfmt *dfmt_find(struct ofmt *, const char *);
void ofmt_list(struct ofmt *, FILE *);
void dfmt_list(struct ofmt *ofmt, FILE * fp);
extern struct dfmt null_debug_form;