2009-06-29 08:25:15 +08:00
|
|
|
/* ----------------------------------------------------------------------- *
|
2017-04-01 02:32:53 +08:00
|
|
|
*
|
2018-05-31 05:43:46 +08:00
|
|
|
* Copyright 1996-2018 The NASM Authors - All Rights Reserved
|
2009-06-29 08:25:15 +08:00
|
|
|
* See the file AUTHORS included with the NASM distribution for
|
|
|
|
* the specific copyright holders.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials provided
|
|
|
|
* with the distribution.
|
2017-04-01 02:32:53 +08:00
|
|
|
*
|
2009-06-29 08:25:15 +08:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
|
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2002-05-01 04:51:32 +08:00
|
|
|
*
|
2009-06-29 08:25:15 +08:00
|
|
|
* ----------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* outdbg.c output routines for the Netwide Assembler to produce
|
|
|
|
* a debugging trace
|
2002-05-01 04:51:32 +08:00
|
|
|
*/
|
|
|
|
|
2007-10-03 12:53:51 +08:00
|
|
|
#include "compiler.h"
|
|
|
|
|
2002-05-01 04:51:32 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2017-04-01 03:03:57 +08:00
|
|
|
#include <errno.h>
|
2002-05-01 04:51:32 +08:00
|
|
|
|
|
|
|
#include "nasm.h"
|
|
|
|
#include "nasmlib.h"
|
2016-05-26 03:06:29 +08:00
|
|
|
#include "outform.h"
|
2016-09-25 00:46:47 +08:00
|
|
|
#include "outlib.h"
|
2017-04-01 02:32:53 +08:00
|
|
|
#include "insns.h"
|
2002-05-01 04:51:32 +08:00
|
|
|
|
|
|
|
#ifdef OF_DBG
|
|
|
|
|
2002-05-01 04:52:49 +08:00
|
|
|
struct Section {
|
|
|
|
struct Section *next;
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t number;
|
2007-04-14 00:47:53 +08:00
|
|
|
char *name;
|
2002-05-01 04:52:49 +08:00
|
|
|
} *dbgsect;
|
|
|
|
|
2017-04-01 02:32:53 +08:00
|
|
|
static unsigned long dbg_max_data_dump = 128;
|
2017-05-04 08:32:02 +08:00
|
|
|
static bool section_labels = true;
|
2018-05-31 05:43:46 +08:00
|
|
|
static bool subsections_via_symbols = false;
|
|
|
|
static int32_t init_seg;
|
2017-04-01 02:32:53 +08:00
|
|
|
|
2016-02-18 12:59:22 +08:00
|
|
|
const struct ofmt of_dbg;
|
2009-07-19 09:07:17 +08:00
|
|
|
static void dbg_init(void)
|
2002-05-01 04:51:32 +08:00
|
|
|
{
|
2002-05-01 04:52:49 +08:00
|
|
|
dbgsect = NULL;
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, "NASM Output format debug dump\n");
|
2017-12-21 05:33:49 +08:00
|
|
|
fprintf(ofile, "input file = %s\n", inname);
|
|
|
|
fprintf(ofile, "output file = %s\n", outname);
|
2018-05-31 05:43:46 +08:00
|
|
|
init_seg = seg_alloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dbg_reset(void)
|
|
|
|
{
|
2018-06-16 08:51:39 +08:00
|
|
|
fprintf(ofile, "*** pass reset: pass0 = %d, passn = %"PRId64"\n",
|
|
|
|
pass0, passn);
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2016-03-08 14:53:06 +08:00
|
|
|
static void dbg_cleanup(void)
|
2002-05-01 04:51:32 +08:00
|
|
|
{
|
2016-02-18 12:55:08 +08:00
|
|
|
dfmt->cleanup();
|
2002-05-01 04:52:49 +08:00
|
|
|
while (dbgsect) {
|
2005-01-16 06:15:51 +08:00
|
|
|
struct Section *tmp = dbgsect;
|
|
|
|
dbgsect = dbgsect->next;
|
|
|
|
nasm_free(tmp->name);
|
|
|
|
nasm_free(tmp);
|
2002-05-01 04:52:49 +08:00
|
|
|
}
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2017-05-04 08:32:02 +08:00
|
|
|
static int32_t dbg_add_section(char *name, int pass, int *bits,
|
|
|
|
const char *whatwecallit)
|
2002-05-01 04:51:32 +08:00
|
|
|
{
|
2002-05-01 04:52:49 +08:00
|
|
|
int seg;
|
|
|
|
|
2002-05-01 04:51:32 +08:00
|
|
|
/*
|
|
|
|
* We must have an initial default: let's make it 16.
|
|
|
|
*/
|
|
|
|
if (!name)
|
2005-01-16 06:15:51 +08:00
|
|
|
*bits = 16;
|
2002-05-01 04:51:32 +08:00
|
|
|
|
2017-05-04 08:32:02 +08:00
|
|
|
if (!name) {
|
2018-05-31 05:43:46 +08:00
|
|
|
fprintf(ofile, "section_name on init: returning %d\n", init_seg);
|
|
|
|
seg = init_seg;
|
2017-05-04 08:32:02 +08:00
|
|
|
} else {
|
2005-01-16 06:15:51 +08:00
|
|
|
int n = strcspn(name, " \t");
|
2007-04-14 00:47:53 +08:00
|
|
|
char *sname = nasm_strndup(name, n);
|
2017-05-04 08:32:02 +08:00
|
|
|
char *tail = nasm_skip_spaces(name+n);
|
2005-01-16 06:15:51 +08:00
|
|
|
struct Section *s;
|
|
|
|
|
|
|
|
seg = NO_SEG;
|
|
|
|
for (s = dbgsect; s; s = s->next)
|
|
|
|
if (!strcmp(s->name, sname))
|
|
|
|
seg = s->number;
|
|
|
|
|
|
|
|
if (seg == NO_SEG) {
|
|
|
|
s = nasm_malloc(sizeof(*s));
|
|
|
|
s->name = sname;
|
|
|
|
s->number = seg = seg_alloc();
|
|
|
|
s->next = dbgsect;
|
|
|
|
dbgsect = s;
|
2017-05-04 08:32:02 +08:00
|
|
|
fprintf(ofile, "%s %s (%s) pass %d: returning %d\n",
|
|
|
|
whatwecallit, name, tail, pass, seg);
|
|
|
|
|
|
|
|
if (section_labels)
|
2018-06-02 09:02:54 +08:00
|
|
|
backend_label(s->name, s->number + 1, 0);
|
2005-01-16 06:15:51 +08:00
|
|
|
}
|
2002-05-01 04:52:49 +08:00
|
|
|
}
|
|
|
|
return seg;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2017-05-04 08:32:02 +08:00
|
|
|
static int32_t dbg_section_names(char *name, int pass, int *bits)
|
|
|
|
{
|
|
|
|
return dbg_add_section(name, pass, bits, "section_names");
|
|
|
|
}
|
|
|
|
|
2018-06-02 09:02:54 +08:00
|
|
|
static int32_t dbg_herelabel(const char *name, enum label_type type,
|
2018-06-28 11:20:21 +08:00
|
|
|
int32_t oldseg, int32_t *subsection,
|
|
|
|
bool *copyoffset)
|
2018-05-31 05:43:46 +08:00
|
|
|
{
|
2018-06-15 08:04:32 +08:00
|
|
|
int32_t newseg = oldseg;
|
2018-05-31 05:43:46 +08:00
|
|
|
|
2018-06-15 08:04:32 +08:00
|
|
|
if (subsections_via_symbols && type != LBL_LOCAL) {
|
|
|
|
newseg = *subsection;
|
2018-06-28 11:20:21 +08:00
|
|
|
if (newseg == NO_SEG) {
|
2018-06-15 08:04:32 +08:00
|
|
|
newseg = *subsection = seg_alloc();
|
2018-06-28 11:20:21 +08:00
|
|
|
*copyoffset = true; /* Minic MachO for now */
|
|
|
|
}
|
2018-06-15 08:04:32 +08:00
|
|
|
}
|
2018-06-02 09:02:54 +08:00
|
|
|
fprintf(ofile, "herelabel %s type %d (seg %08x) -> %08x\n",
|
2018-06-15 08:04:32 +08:00
|
|
|
name, type, oldseg, newseg);
|
2018-05-31 05:43:46 +08:00
|
|
|
|
|
|
|
return newseg;
|
|
|
|
}
|
|
|
|
|
2009-06-28 12:05:42 +08:00
|
|
|
static void dbg_deflabel(char *name, int32_t segment, int64_t offset,
|
2007-04-14 00:47:53 +08:00
|
|
|
int is_global, char *special)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, "deflabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
|
2005-01-16 06:15:51 +08:00
|
|
|
name, segment, offset,
|
|
|
|
is_global == 2 ? "common" : is_global ? "global" : "local",
|
|
|
|
is_global, special ? ": " : "", special);
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2017-04-01 02:32:53 +08:00
|
|
|
static const char *out_type(enum out_type type)
|
|
|
|
{
|
|
|
|
static const char *out_types[] = {
|
|
|
|
"rawdata",
|
|
|
|
"reserve",
|
2017-05-04 08:32:02 +08:00
|
|
|
"zerodata",
|
2017-04-01 02:32:53 +08:00
|
|
|
"address",
|
|
|
|
"reladdr",
|
|
|
|
"segment"
|
|
|
|
};
|
|
|
|
static char invalid_buf[64];
|
|
|
|
|
|
|
|
if (type >= sizeof(out_types)/sizeof(out_types[0])) {
|
|
|
|
sprintf(invalid_buf, "[invalid type %d]", type);
|
|
|
|
return invalid_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return out_types[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *out_sign(enum out_sign sign)
|
|
|
|
{
|
|
|
|
static const char *out_signs[] = {
|
|
|
|
"wrap",
|
|
|
|
"signed",
|
|
|
|
"unsigned"
|
|
|
|
};
|
|
|
|
static char invalid_buf[64];
|
|
|
|
|
|
|
|
if (sign >= sizeof(out_signs)/sizeof(out_signs[0])) {
|
|
|
|
sprintf(invalid_buf, "[invalid sign %d]", sign);
|
|
|
|
return invalid_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
return out_signs[sign];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dbg_out(const struct out_data *data)
|
|
|
|
{
|
|
|
|
fprintf(ofile,
|
|
|
|
"out to %"PRIx32":%"PRIx64" %s %s bits %d insoffs %d/%d "
|
|
|
|
"size %"PRIu64,
|
|
|
|
data->segment, data->offset,
|
2017-04-17 11:24:39 +08:00
|
|
|
out_type(data->type), out_sign(data->sign),
|
2017-04-01 02:32:53 +08:00
|
|
|
data->bits, data->insoffs, data->inslen, data->size);
|
|
|
|
if (data->itemp) {
|
|
|
|
fprintf(ofile, " ins %s(%d)",
|
|
|
|
nasm_insn_names[data->itemp->opcode], data->itemp->operands);
|
|
|
|
} else {
|
2017-04-01 03:03:57 +08:00
|
|
|
fprintf(ofile, " no ins (plain data)");
|
2017-04-01 02:32:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data->type == OUT_ADDRESS || data->type == OUT_RELADDR ||
|
|
|
|
data->type == OUT_SEGMENT) {
|
|
|
|
fprintf(ofile, " target %"PRIx32":%"PRIx64,
|
|
|
|
data->tsegment, data->toffset);
|
|
|
|
if (data->twrt != NO_SEG)
|
|
|
|
fprintf(ofile, " wrt %"PRIx32, data->twrt);
|
|
|
|
}
|
|
|
|
if (data->type == OUT_RELADDR)
|
2017-06-23 14:00:38 +08:00
|
|
|
fprintf(ofile, " relbase %"PRIx64, data->relbase);
|
2017-04-01 02:32:53 +08:00
|
|
|
|
|
|
|
putc('\n', ofile);
|
|
|
|
|
|
|
|
if (data->type == OUT_RAWDATA) {
|
|
|
|
if ((size_t)data->size != data->size) {
|
|
|
|
fprintf(ofile, " data: <error: impossible size>\n");
|
|
|
|
} else if (!data->data) {
|
|
|
|
fprintf(ofile, " data: <error: null pointer>\n");
|
|
|
|
} else if (dbg_max_data_dump != -1UL &&
|
|
|
|
data->size > dbg_max_data_dump) {
|
|
|
|
fprintf(ofile, " data: <%"PRIu64" bytes>\n", data->size);
|
|
|
|
} else {
|
|
|
|
size_t i, j;
|
|
|
|
const uint8_t *bytes = data->data;
|
|
|
|
for (i = 0; i < data->size; i += 16) {
|
|
|
|
fprintf(ofile, " data:");
|
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
if (i+j >= data->size)
|
|
|
|
fprintf(ofile, " ");
|
|
|
|
else
|
|
|
|
fprintf(ofile, "%c%02x",
|
|
|
|
(j == 8) ? '-' : ' ', bytes[i+j]);
|
|
|
|
}
|
|
|
|
fprintf(ofile," ");
|
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
if (i+j >= data->size) {
|
|
|
|
putc(' ', ofile);
|
|
|
|
} else {
|
|
|
|
if (bytes[i+j] >= 32 && bytes[i+j] <= 126)
|
|
|
|
putc(bytes[i+j], ofile);
|
|
|
|
else
|
|
|
|
putc('.', ofile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
putc('\n', ofile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is probably the only place were we'll call this this way... */
|
|
|
|
nasm_do_legacy_output(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dbg_legacy_out(int32_t segto, const void *data,
|
|
|
|
enum out_type type, uint64_t size,
|
|
|
|
int32_t segment, int32_t wrt)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2007-04-12 10:40:54 +08:00
|
|
|
int32_t ldata;
|
2002-05-01 04:52:49 +08:00
|
|
|
|
2013-11-27 10:09:56 +08:00
|
|
|
if (type == OUT_ADDRESS)
|
2017-04-01 02:32:53 +08:00
|
|
|
fprintf(ofile, " legacy: out to %"PRIx32", len = %d: ",
|
|
|
|
segto, (int)abs((int)size));
|
2013-11-27 10:09:56 +08:00
|
|
|
else
|
2017-06-23 14:00:38 +08:00
|
|
|
fprintf(ofile, " legacy: out to %"PRIx32", len = %"PRId64" (0x%"PRIx64"): ",
|
|
|
|
segto, (int64_t)size, size);
|
2005-01-16 06:15:51 +08:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case OUT_RESERVE:
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, "reserved.\n");
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case OUT_RAWDATA:
|
2017-04-01 02:32:53 +08:00
|
|
|
fprintf(ofile, "rawdata\n"); /* Already have a data dump */
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case OUT_ADDRESS:
|
2007-11-14 01:37:59 +08:00
|
|
|
ldata = *(int64_t *)data;
|
2013-11-27 10:09:56 +08:00
|
|
|
fprintf(ofile, "addr %08"PRIx32" (seg %08"PRIx32", wrt %08"PRIx32")\n",
|
|
|
|
ldata, segment, wrt);
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
2010-05-07 06:25:43 +08:00
|
|
|
case OUT_REL1ADR:
|
|
|
|
fprintf(ofile, "rel1adr %02"PRIx8" (seg %08"PRIx32")\n",
|
|
|
|
(uint8_t)*(int64_t *)data, segment);
|
|
|
|
break;
|
2005-01-16 06:15:51 +08:00
|
|
|
case OUT_REL2ADR:
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, "rel2adr %04"PRIx16" (seg %08"PRIx32")\n",
|
2009-07-08 01:24:52 +08:00
|
|
|
(uint16_t)*(int64_t *)data, segment);
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
|
|
|
case OUT_REL4ADR:
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, "rel4adr %08"PRIx32" (seg %08"PRIx32")\n",
|
2009-07-08 01:24:52 +08:00
|
|
|
(uint32_t)*(int64_t *)data,
|
2005-01-16 06:15:51 +08:00
|
|
|
segment);
|
|
|
|
break;
|
2009-07-08 01:24:52 +08:00
|
|
|
case OUT_REL8ADR:
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, "rel8adr %016"PRIx64" (seg %08"PRIx32")\n",
|
2009-07-08 01:24:52 +08:00
|
|
|
(uint64_t)*(int64_t *)data, segment);
|
|
|
|
break;
|
2005-01-16 06:15:51 +08:00
|
|
|
default:
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, "unknown\n");
|
2005-01-16 06:15:51 +08:00
|
|
|
break;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-21 17:45:32 +08:00
|
|
|
static void dbg_sectalign(int32_t seg, unsigned int value)
|
2010-04-21 04:51:22 +08:00
|
|
|
{
|
2013-03-31 18:00:09 +08:00
|
|
|
fprintf(ofile, "set alignment (%d) for segment (%u)\n",
|
|
|
|
seg, value);
|
2010-04-21 04:51:22 +08:00
|
|
|
}
|
|
|
|
|
2017-03-08 14:40:00 +08:00
|
|
|
static enum directive_result
|
2017-04-03 15:09:58 +08:00
|
|
|
dbg_directive(enum directive directive, char *value, int pass)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2017-05-04 08:32:02 +08:00
|
|
|
switch (directive) {
|
|
|
|
/*
|
|
|
|
* The .obj GROUP directive is nontrivial to emulate in a macro.
|
|
|
|
* It effectively creates a "pseudo-section" containing the first
|
|
|
|
* space-separated argument; the rest we ignore.
|
|
|
|
*/
|
|
|
|
case D_GROUP:
|
|
|
|
{
|
|
|
|
int dummy;
|
|
|
|
dbg_add_section(value, pass, &dummy, "directive:group");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, "directive [%s] value [%s] (pass %d)\n",
|
2017-04-03 15:09:58 +08:00
|
|
|
directive_dname(directive), value, pass);
|
2017-04-01 02:32:53 +08:00
|
|
|
return DIRR_OK;
|
|
|
|
}
|
|
|
|
|
2017-04-01 03:03:57 +08:00
|
|
|
static enum directive_result
|
|
|
|
dbg_pragma(const struct pragma *pragma);
|
|
|
|
|
|
|
|
static const struct pragma_facility dbg_pragma_list[] = {
|
|
|
|
{ NULL, dbg_pragma }
|
|
|
|
};
|
|
|
|
|
2017-04-01 02:32:53 +08:00
|
|
|
static enum directive_result
|
|
|
|
dbg_pragma(const struct pragma *pragma)
|
|
|
|
{
|
|
|
|
fprintf(ofile, "pragma %s(%s) %s[%s] %s\n",
|
|
|
|
pragma->facility_name,
|
|
|
|
pragma->facility->name ? pragma->facility->name : "<default>",
|
2017-04-03 15:09:58 +08:00
|
|
|
pragma->opname, directive_dname(pragma->opcode),
|
2017-04-01 02:32:53 +08:00
|
|
|
pragma->tail);
|
|
|
|
|
2017-05-04 08:32:02 +08:00
|
|
|
if (pragma->facility == &dbg_pragma_list[0]) {
|
|
|
|
switch (pragma->opcode) {
|
|
|
|
case D_MAXDUMP:
|
|
|
|
if (!nasm_stricmp(pragma->tail, "unlimited")) {
|
|
|
|
dbg_max_data_dump = -1UL;
|
2017-04-01 03:03:57 +08:00
|
|
|
} else {
|
2017-05-04 08:32:02 +08:00
|
|
|
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;
|
|
|
|
}
|
2017-04-01 03:03:57 +08:00
|
|
|
}
|
2017-05-04 08:32:02 +08:00
|
|
|
break;
|
|
|
|
case D_NOSECLABELS:
|
|
|
|
section_labels = false;
|
|
|
|
break;
|
2018-05-31 05:43:46 +08:00
|
|
|
case D_SUBSECTIONS_VIA_SYMBOLS:
|
|
|
|
subsections_via_symbols = true;
|
|
|
|
break;
|
2017-05-04 08:32:02 +08:00
|
|
|
default:
|
|
|
|
break;
|
2017-04-01 03:03:57 +08:00
|
|
|
}
|
|
|
|
}
|
2017-03-08 14:40:00 +08:00
|
|
|
return DIRR_OK;
|
2002-05-01 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2016-02-18 18:28:15 +08:00
|
|
|
static const char * const types[] = {
|
2005-01-16 06:15:51 +08:00
|
|
|
"unknown", "label", "byte", "word", "dword", "float", "qword", "tbyte"
|
2002-05-01 04:53:55 +08:00
|
|
|
};
|
2014-11-26 04:09:19 +08:00
|
|
|
static void dbgdbg_init(void)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, " With debug info\n");
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
|
|
|
static void dbgdbg_cleanup(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-04-14 00:47:53 +08:00
|
|
|
static void dbgdbg_linnum(const char *lnfname, int32_t lineno, int32_t segto)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2017-04-01 02:32:53 +08:00
|
|
|
fprintf(ofile, "dbglinenum %s(%"PRId32") segment %"PRIx32"\n",
|
2009-06-28 12:05:42 +08:00
|
|
|
lnfname, lineno, segto);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2007-04-14 00:47:53 +08:00
|
|
|
static void dbgdbg_deflabel(char *name, int32_t segment,
|
2009-06-28 12:05:42 +08:00
|
|
|
int64_t offset, int is_global, char *special)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, "dbglabel %s := %08"PRIx32":%016"PRIx64" %s (%d)%s%s\n",
|
2005-01-16 06:15:51 +08:00
|
|
|
name,
|
2002-05-01 04:53:55 +08:00
|
|
|
segment, offset,
|
2005-01-16 06:15:51 +08:00
|
|
|
is_global == 2 ? "common" : is_global ? "global" : "local",
|
|
|
|
is_global, special ? ": " : "", special);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2007-04-14 00:47:53 +08:00
|
|
|
static void dbgdbg_define(const char *type, const char *params)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, "dbgdirective [%s] value [%s]\n", type, params);
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2005-01-16 06:15:51 +08:00
|
|
|
static void dbgdbg_output(int output_type, void *param)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2005-01-16 06:15:51 +08:00
|
|
|
(void)output_type;
|
|
|
|
(void)param;
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2007-04-12 10:40:54 +08:00
|
|
|
static void dbgdbg_typevalue(int32_t type)
|
2002-05-01 04:53:55 +08:00
|
|
|
{
|
2009-07-19 09:07:17 +08:00
|
|
|
fprintf(ofile, "new type: %s(%"PRIX32")\n",
|
2005-01-16 06:15:51 +08:00
|
|
|
types[TYM_TYPE(type) >> 3], TYM_ELEMENTS(type));
|
2002-05-01 04:53:55 +08:00
|
|
|
}
|
2017-04-01 02:32:53 +08:00
|
|
|
|
|
|
|
static const struct pragma_facility dbgdbg_pragma_list[] = {
|
|
|
|
{ "dbgdbg", dbg_pragma },
|
|
|
|
{ NULL, dbg_pragma } /* Won't trigger, "debug" is a reserved ns */
|
|
|
|
};
|
|
|
|
|
2016-02-18 18:16:36 +08:00
|
|
|
static const struct dfmt debug_debug_form = {
|
2002-05-01 04:53:55 +08:00
|
|
|
"Trace of all info passed to debug stage",
|
|
|
|
"debug",
|
|
|
|
dbgdbg_init,
|
|
|
|
dbgdbg_linnum,
|
|
|
|
dbgdbg_deflabel,
|
|
|
|
dbgdbg_define,
|
|
|
|
dbgdbg_typevalue,
|
|
|
|
dbgdbg_output,
|
|
|
|
dbgdbg_cleanup,
|
2017-04-01 02:32:53 +08:00
|
|
|
dbgdbg_pragma_list
|
2002-05-01 04:53:55 +08:00
|
|
|
};
|
|
|
|
|
2016-02-18 18:16:36 +08:00
|
|
|
static const struct dfmt * const debug_debug_arr[3] = {
|
2005-01-16 06:15:51 +08:00
|
|
|
&debug_debug_form,
|
|
|
|
&null_debug_form,
|
|
|
|
NULL
|
2002-05-01 04:53:55 +08:00
|
|
|
};
|
2009-06-28 12:05:42 +08:00
|
|
|
|
2017-05-04 08:32:02 +08:00
|
|
|
extern macros_t dbg_stdmac[];
|
|
|
|
|
2016-02-18 12:59:22 +08:00
|
|
|
const struct ofmt of_dbg = {
|
2002-05-01 04:51:32 +08:00
|
|
|
"Trace of all info passed to output stage",
|
|
|
|
"dbg",
|
2017-12-21 05:33:49 +08:00
|
|
|
".dbg",
|
2009-07-06 05:45:12 +08:00
|
|
|
OFMT_TEXT,
|
2016-02-12 12:40:07 +08:00
|
|
|
64,
|
2002-05-01 04:53:55 +08:00
|
|
|
debug_debug_arr,
|
2008-11-05 21:11:46 +08:00
|
|
|
&debug_debug_form,
|
2017-05-04 08:32:02 +08:00
|
|
|
dbg_stdmac,
|
2002-05-01 04:51:32 +08:00
|
|
|
dbg_init,
|
2018-05-31 05:43:46 +08:00
|
|
|
dbg_reset,
|
2002-05-01 04:51:32 +08:00
|
|
|
dbg_out,
|
2017-04-01 02:32:53 +08:00
|
|
|
dbg_legacy_out,
|
2002-05-01 04:51:32 +08:00
|
|
|
dbg_deflabel,
|
|
|
|
dbg_section_names,
|
2018-05-31 05:43:46 +08:00
|
|
|
dbg_herelabel,
|
2010-04-21 17:45:32 +08:00
|
|
|
dbg_sectalign,
|
2018-06-15 13:41:00 +08:00
|
|
|
null_segbase,
|
2002-05-01 04:51:32 +08:00
|
|
|
dbg_directive,
|
2017-03-08 13:32:37 +08:00
|
|
|
dbg_cleanup,
|
2017-04-01 02:32:53 +08:00
|
|
|
dbg_pragma_list
|
2002-05-01 04:51:32 +08:00
|
|
|
};
|
|
|
|
|
2005-01-16 06:15:51 +08:00
|
|
|
#endif /* OF_DBG */
|