listing: separate "user" and "debug" flag, add matching debug option

Adding information about the NASM internal state to the list file can
be useful for debugging purposes. Separate the list of options that
are "user" options and those that are "debugging" options. The latter
are not implied by -L+ and are intended for NASM developer use.

Introduce -LX, which lists which instruction patterns are matched by
each instruction.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin (Intel) 2026-03-03 14:12:48 -08:00
parent a4c5b2829c
commit fe9586f201
4 changed files with 27 additions and 4 deletions

View file

@ -872,6 +872,17 @@ static void out_eops(struct out_data *data, const extop *e)
/* This is totally just a wild guess what is reasonable... */
#define INCBIN_MAX_BUF (ZERO_BUF_SIZE * 16)
static void
list_add_template_info(const insn *ins, const struct itemplate *temp)
{
char *buf;
(void)ins;
buf = nasm_asprintf(" ;;; matched insns.xda:%u", temp->xdaline);
lfmt->line(LIST_INFO, -1, buf);
nasm_free(buf);
}
static int64_t assemble(insn *instruction)
{
struct out_data data;
@ -1012,6 +1023,9 @@ static int64_t assemble(insn *instruction)
if (m >= MOK_GOOD) {
/* Matches! */
if (list_option('X'))
list_add_template_info(instruction, temp);
if (unlikely(itemp_has(temp, IF_OBSOLETE))) {
errflags warning;
const char *whathappened;

View file

@ -136,10 +136,15 @@ static inline const_func uint64_t list_option_mask_val(unsigned char x)
static inline const_func uint64_t list_option_mask(unsigned char x)
{
if (x == '+')
return ~(list_option_mask_val('w') | 3);
else
if (x == '+') {
const char *p = "bdefFmps";
uint64_t v = 0;
while (*p)
v |= list_option_mask_val(*p++);
return v;
} else {
return list_option_mask_val(x);
}
}
/* Return true if the listing engine is active and a certain option is set. */

View file

@ -1932,6 +1932,7 @@ static void help(FILE *out, const char *what)
}
if (help_is(with, 'L')) {
fputs(
" -L flags for general usage:\n"
" -Lb show builtin macro packages (standard and %use)\n"
" -Ld show byte and repeat counts in decimal, not hex\n"
" -Le show the preprocessed output\n"
@ -1940,8 +1941,10 @@ static void help(FILE *out, const char *what)
" -Lm show multi-line macro calls with expanded parameters\n"
" -Lp output a list file every pass, in case of errors\n"
" -Ls show all single-line macro definitions\n"
" -L+ enable all of the above listing options (very verbose!)\n"
" -L flags intended for debugging NASM:\n"
" -Lw flush the output after every line (very slow!)\n"
" -L+ enable all listing options except -Lw (very verbose!)\n"
" -LX list instruction pattern line numbers from insns.xda\n"
, out);
}
if (help_optor(with, 'O')) {

View file

@ -526,6 +526,7 @@ static inline char *nasm_skip_identifier(const char *str)
enum {
LIST_READ,
LIST_MACRO,
LIST_INFO,
LIST_INCLUDE,
LIST_INCBIN,
LIST_TIMES