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:
parent
477ae4419c
commit
283b3fb15a
4 changed files with 28 additions and 17 deletions
36
nasm.c
36
nasm.c
|
@ -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 nasm_verror_common(int severity, const char *fmt, va_list args);
|
||||||
static void usage(void);
|
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;
|
bool tasm_compatible_mode = false;
|
||||||
int pass0, passn;
|
int pass0, passn;
|
||||||
int globalrel = 0;
|
int globalrel = 0;
|
||||||
|
@ -356,11 +358,21 @@ int main(int argc, char **argv)
|
||||||
return 1;
|
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;
|
dfmt = &null_debug_form;
|
||||||
else if (!dfmt)
|
} else if (!debug_format) {
|
||||||
|
/* Default debug format for this backend */
|
||||||
dfmt = ofmt->default_dfmt;
|
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)
|
if (ofmt->stdmac)
|
||||||
preproc->extra_stdmac(ofmt->stdmac);
|
preproc->extra_stdmac(ofmt->stdmac);
|
||||||
|
@ -666,7 +678,6 @@ static bool process_arg(char *p, char *q)
|
||||||
"unrecognised output format `%s' - "
|
"unrecognised output format `%s' - "
|
||||||
"use -hf for a list", param);
|
"use -hf for a list", param);
|
||||||
}
|
}
|
||||||
dfmt = NULL;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'O': /* Optimization level */
|
case 'O': /* Optimization level */
|
||||||
|
@ -744,14 +755,8 @@ static bool process_arg(char *p, char *q)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'F': /* specify debug format */
|
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;
|
using_debug_info = true;
|
||||||
|
debug_format = param;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'X': /* specify error reporting format */
|
case 'X': /* specify error reporting format */
|
||||||
|
@ -767,6 +772,8 @@ static bool process_arg(char *p, char *q)
|
||||||
|
|
||||||
case 'g':
|
case 'g':
|
||||||
using_debug_info = true;
|
using_debug_info = true;
|
||||||
|
if (p[2])
|
||||||
|
debug_format = nasm_skip_spaces(p + 2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -775,8 +782,7 @@ static bool process_arg(char *p, char *q)
|
||||||
"[-l listfile]\n"
|
"[-l listfile]\n"
|
||||||
" [options...] [--] filename\n"
|
" [options...] [--] filename\n"
|
||||||
" or nasm -v (or --v) for version info\n\n"
|
" or nasm -v (or --v) for version info\n\n"
|
||||||
" -t assemble in SciTech TASM compatible mode\n"
|
" -t assemble in SciTech TASM compatible mode\n");
|
||||||
" -g generate debug information in selected format\n");
|
|
||||||
printf
|
printf
|
||||||
(" -E (or -e) preprocess only (writes output to stdout by default)\n"
|
(" -E (or -e) preprocess only (writes output to stdout by default)\n"
|
||||||
" -a don't preprocess (assemble only)\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"
|
" -MP emit phony target\n\n"
|
||||||
" -Z<file> redirect error messages to file\n"
|
" -Z<file> redirect error messages to file\n"
|
||||||
" -s redirect error messages to stdout\n\n"
|
" -s redirect error messages to stdout\n\n"
|
||||||
|
" -g generate debugging information\n\n"
|
||||||
" -F format select a debugging format\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"
|
" -o outfile write output to an outfile\n\n"
|
||||||
" -f format select an output format\n\n"
|
" -f format select an output format\n\n"
|
||||||
" -l listfile write listing to a listfile\n\n"
|
" -l listfile write listing to a listfile\n\n"
|
||||||
|
|
5
nasm.txt
5
nasm.txt
|
@ -47,7 +47,10 @@ OPTIONS
|
||||||
formats, use the *-y* option (for example *-felf -y*).
|
formats, use the *-y* option (for example *-felf -y*).
|
||||||
|
|
||||||
*-g*::
|
*-g*::
|
||||||
Causes *nasm* to generate debug information in selected format.
|
Causes *nasm* to generate debug information.
|
||||||
|
|
||||||
|
*-g*'format'::
|
||||||
|
Equivalent to **-g -F**__ format__.
|
||||||
|
|
||||||
*-h*::
|
*-h*::
|
||||||
Causes *nasm* to exit immediately, after giving a summary of its
|
Causes *nasm* to exit immediately, after giving a summary of its
|
||||||
|
|
|
@ -72,7 +72,7 @@ struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias)
|
||||||
return NULL;
|
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;
|
struct dfmt **dfp, *df;
|
||||||
|
|
||||||
|
|
|
@ -371,7 +371,7 @@ static struct ofmt_alias ofmt_aliases[] = {
|
||||||
#endif /* BUILD_DRIVERS_ARRAY */
|
#endif /* BUILD_DRIVERS_ARRAY */
|
||||||
|
|
||||||
struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias);
|
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 ofmt_list(struct ofmt *, FILE *);
|
||||||
void dfmt_list(struct ofmt *ofmt, FILE * fp);
|
void dfmt_list(struct ofmt *ofmt, FILE * fp);
|
||||||
extern struct dfmt null_debug_form;
|
extern struct dfmt null_debug_form;
|
||||||
|
|
Loading…
Reference in a new issue