File: dbg-interp.c

package info (click to toggle)
libi8x 0.0.5-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 7,192 kB
  • ctags: 1,365
  • sloc: ansic: 6,874; python: 1,339; makefile: 146; sh: 102
file content (70 lines) | stat: -rw-r--r-- 2,218 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Copyright (C) 2016 Red Hat, Inc.
   This file is part of the Infinity Note Execution Library.

   The Infinity Note Execution Library is free software; you can
   redistribute it and/or modify it under the terms of the GNU Lesser
   General Public License as published by the Free Software
   Foundation; either version 2.1 of the License, or (at your option)
   any later version.

   The Infinity Note Execution Library is distributed in the hope that
   it will be useful, but WITHOUT ANY WARRANTY; without even the
   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
   PURPOSE.  See the GNU Lesser General Public License for more
   details.

   You should have received a copy of the GNU Lesser General Public
   License along with the Infinity Note Execution Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#include "libi8x-private.h"
#include "interp-private.h"

static void i8x_xctx_trace (struct i8x_xctx *xctx,
			    struct i8x_funcref *ref,
			    struct i8x_code *code,
			    struct i8x_instr *op,
			    union i8x_value *vsp,
			    union i8x_value *vsp_floor,
			    union i8x_value *csp);

#define DEBUG_INTERPRETER
#include "interp.c"

#include <stdio.h>

#define SLOT_TO_STR(buf, slot)					\
  do {								\
    if (STACK_DEPTH () > slot)					\
      snprintf (buf, sizeof (buf),				\
		"0x%08" LONG_FMT "x", STACK (slot).u);		\
    else							\
      strncpy (buf, "----------", sizeof (buf));		\
    buf [sizeof (buf) - 1] = '\0';				\
  } while (0)

static void
i8x_xctx_trace (struct i8x_xctx *xctx,  struct i8x_funcref *ref,
		struct i8x_code *code, struct i8x_instr *op,
		union i8x_value *vsp, union i8x_value *vsp_floor,
		union i8x_value *csp)
{
  struct i8x_ctx *ctx = i8x_xctx_get_ctx (xctx);

  xctx->bytecode_count++;

  if (i8x_ctx_get_log_priority (ctx) < LOG_TRACE)
    return;

  char offset[32], depth[32], stack0[32], stack1[32];

  snprintf (offset, sizeof (offset), "" LHEX "", ip_to_so (code, op));
  snprintf (depth, sizeof (depth), "[" LDEC "]", STACK_DEPTH ());

  SLOT_TO_STR (stack0, 0);
  SLOT_TO_STR (stack1, 1);

  trace (ctx, "%-39s %10s\t%-23s %4s\t%-18s\t%-18s\n",
	 ref->fullname, offset, op->desc->name,
	 depth, stack0, stack1);
}