forked from laanwj/sundog
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpsys_debug.h
88 lines (71 loc) · 2.87 KB
/
psys_debug.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Copyright (c) 2017 Wladimir J. van der Laan
* Distributed under the MIT software license, see the accompanying
* file COPYING or http://www.opensource.org/licenses/mit-license.php.
*/
#ifndef H_PSYS_DEBUG
#define H_PSYS_DEBUG
#include "psys_types.h"
#include <assert.h>
#ifdef __cplusplus
extern "C" {
#endif
struct psys_state;
#define psys_assert assert
#define PDBG(s, flag) ((s)->debug & PSYS_DBG_##flag)
enum {
PSYS_DBG_CALL = 0x1, /* Extra debugging for calls and returns */
PSYS_DBG_WARNING = 0x2, /* Weirdnesses */
PSYS_DBG_STRINGS = 0x4, /* Strings and arrays */
PSYS_DBG_TASK = 0x10, /* Tasks and synchonization */
PSYS_DBG_RSP = 0x20, /* RSP calls */
PSYS_DBG_REG = 0x40, /* Register writes and reads */
/* These are not used by the interpreter itself,
* but are free for use by the application.
*/
PSYS_DBG_TRACE = 0x8, /* Print every instruction executed */
PSYS_DBG_TRACE_CALLS = 0x80, /* Trace all procedure calls */
};
/** Debug info entry for one procedure */
struct util_debuginfo_entry {
struct psys_function_id proc;
const char *name;
};
/** Top-level debug info structure.
* Procedure entries must be in sorted order by (segment, proc_num) to
* allow for fast searching.
*/
struct util_debuginfo {
const struct util_debuginfo_entry *entry;
unsigned len;
};
/** Exit with a fatal error message. Use this on unrecoverable errors only. */
void psys_panic(const char *fmt, ...);
/** Print formattes string to debug console. */
void psys_debug(const char *fmt, ...);
/** Print a traceback for the current stack to the debug console. */
void psys_print_traceback(struct psys_state *s);
/** Print information about current state of the p-machine and the current
* instruction. */
void psys_print_info(struct psys_state *s);
/** Print information about current instruction, if it is a call
* instruction. The destination procedure as well as arguments will be printed.
* A list of procedures to ignore can be passed, as well as a debug info structure
* (for naming of procedures).
*/
void psys_print_call_info(struct psys_state *s, const struct psys_function_id *ignore, unsigned ignore_len, const struct util_debuginfo *dbginfo);
void psys_debug_hexdump_ofshl(const psys_byte *data, psys_fulladdr offset, unsigned size, psys_byte *hl);
void psys_debug_hexdump_ofs(const psys_byte *data, psys_fulladdr offset, unsigned size);
void psys_debug_hexdump(struct psys_state *s, psys_fulladdr offset, unsigned size);
/** Get current stack depth (number of caller frames on stack).
*/
int psys_debug_stack_depth(struct psys_state *s);
/** Guess number of arguments for a procedure from number of locals and number
* of values removed from stack on return.
* -1 if unknown.
*/
int psys_debug_proc_num_arguments(struct psys_state *s, psys_fulladdr erec, psys_word procedure);
#ifdef __cplusplus
}
#endif
#endif