Skip to content

Commit 702b1d1

Browse files
[debug] make debug features work again
1 parent 991ea11 commit 702b1d1

File tree

4 files changed

+96
-113
lines changed

4 files changed

+96
-113
lines changed

docs/static/debugging.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,15 @@ Here are some examples:
2727
2828
To view the output of these functions within `CEmu <https://ce-programming.github.io/CEmu>`_, enable the console using **Docks > Console**.
2929

30+
debug.h
31+
=======
32+
33+
.. code-block:: c
34+
35+
#include <debug.h>
36+
37+
API Documentation
38+
-----------------
39+
40+
.. doxygenfile:: debug.h
41+
:project: CE C/C++ Toolchain

src/ce/debug.src

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
assume adl=1
2+
3+
section .text
4+
public _dbg_Debugger
5+
_dbg_Debugger:
6+
scf
7+
sbc hl,hl
8+
ld (hl),2
9+
ret
10+
11+
section .text
12+
public _dbg_WatchpointSet
13+
_dbg_WatchpointSet:
14+
; currently have to do stupid stuff until CEmu is updated to be less dumb
15+
ld iy,0
16+
add iy,sp
17+
scf
18+
sbc hl,hl
19+
ld de,(iy + 3) ; addr
20+
ld bc,(iy + 6) ; size (must be 1 right now)
21+
ld a,(iy + 9) ; mask
22+
ld (hl),8
23+
ld (hl),4
24+
or a,a ; 0 = remove
25+
ret z
26+
bit 0,a ; read
27+
jr z,.noread
28+
bit 1,a ; write
29+
jr z,.noreadwrite
30+
ld (hl),7
31+
jr .checkexecute
32+
.noreadwrite:
33+
ld (hl),5
34+
jr .checkexecute
35+
.noread:
36+
bit 1,a ; write
37+
jr z,.checkexecute
38+
ld (hl),6
39+
.checkexecute:
40+
bit 2,a ; execute
41+
ret z
42+
ld (hl),3
43+
ret
44+
45+
section .text
46+
public _dbg_WatchpointRemoveAll
47+
_dbg_WatchpointRemoveAll:
48+
scf
49+
sbc hl,hl
50+
ld (hl),9
51+
ld (hl),10
52+
ret

src/ce/include/debug.h

Lines changed: 32 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/**
22
* @file
3-
* @author Matt "MateoConLechuga" Waltz
4-
* @brief Contains debugging features for use with a compatible debugger
53
*
64
* These debug functions are provided to help in the process of debugging
7-
* an application. To enable them, use 'make debug' when compiling a program.
5+
* an application. To enable them, use `make debug` when compiling a program.
86
*/
97

108
#include <stdio.h>
@@ -16,16 +14,20 @@ extern "C" {
1614
#ifndef NDEBUG
1715

1816
/** Standard debug output */
19-
#define dbgout ((char*)0xFB0000)
17+
#define dbgout ((void*)0xFB0000)
2018
/** Standard error debug output */
21-
#define dbgerr ((char*)0xFC0000)
19+
#define dbgerr ((void*)0xFC0000)
2220

2321
/** Break on read. */
2422
#define DBG_WATCHPOINT_READ (1 << 0)
2523
/** Break on write. */
2624
#define DBG_WATCHPOINT_WRITE (1 << 1)
27-
/** Break on read or write. */
28-
#define DBG_WATCHPOINT_RW ((1 << 0) | (1 << 1))
25+
/** Break on execute. */
26+
#define DBG_WATCHPOINT_EXECUTE (1 << 2)
27+
/** Break on read, write, or execute. */
28+
#define DBG_WATCHPOINT_ALL (DBG_WATCHPOINT_READ | DBG_WATCHPOINT_WRITE | DBG_WATCHPOINT_EXECUTE)
29+
/** Remove watchpoint. */
30+
#define DBG_WATCHPOINT_NONE 0
2931

3032
/**
3133
* Used to print to the emulator console.
@@ -34,110 +36,58 @@ extern "C" {
3436
* @param[in] ... Uses printf-formated specifier string.
3537
* @note Does not support floats unless `HAS_PRINTF = YES`.
3638
*/
37-
#define dbg_printf(...) sprintf(dbgout, ##__VA_ARGS__)
39+
#define dbg_printf(...) \
40+
sprintf(dbgout, ##__VA_ARGS__)
3841

3942
/**
4043
* Used to print to the emulator console.
4144
*
4245
* See the syntax for 'printf' for format specifiers.
43-
* @param[in] out Can be dbgout (black) or dbgerr (red).
46+
* @param[in] out Use \p dbgout for normal output and \p dbgerr for errors.
4447
* @param[in] ... Uses printf-formated specifier string.
4548
* @note Does not support floats unless `HAS_PRINTF = YES`.
4649
*/
47-
#define dbg_sprintf(out, ...) sprintf(out, ##__VA_ARGS__)
50+
#define dbg_sprintf(out, ...) \
51+
sprintf(out, ##__VA_ARGS__)
4852

4953
/**
50-
* Clears the emulation console
54+
* Clears the emulation console.
5155
*/
5256
#define dbg_ClearConsole() \
5357
do { \
54-
*(volatile unsigned char*)0xFFFFE0 = 10; \
58+
*(volatile unsigned char*)0xFD0000 = 1; \
5559
} while (0)
5660

5761
/**
58-
* Opens the emulator's debugger.
62+
* Opens the emulator's debugger immediately
5963
*/
60-
#define dbg_Debugger() \
61-
do { \
62-
*(volatile unsigned char*)0xFFFFE0 = (unsigned char)~0; \
63-
} while (0)
64-
65-
/**
66-
* Sets an emulated breakpoint.
67-
*
68-
* @param[in] address Breakpoint address to set.
69-
*/
70-
#define dbg_SetBreakpoint(address) \
71-
do { \
72-
*(volatile unsigned int*)0xFFFFE4 = (unsigned int)(address); \
73-
*(volatile unsigned char*)0xFFFFE0 = 1; \
74-
} while (0)
75-
76-
/**
77-
* Removes an emulated breakpoint.
78-
*
79-
* @param[in] address Breakpoint address to remove.
80-
*/
81-
#define dbg_RemoveBreakpoint(address) \
82-
do { \
83-
*(volatile unsigned int*)0xFFFFE4 = (address); \
84-
*(volatile unsigned char*)0xFFFFE0 = 2; \
85-
} while (0)
86-
87-
/**
88-
* Sets an emulated watchpoint.
89-
*
90-
* @param[in] address Watchpoint address to set.
91-
* @param[in] length The size of the data at the address.
92-
* @param[in] flags DBG_WATCHPOINT_READ, DBG_WATCHPOINT_WRITE, or
93-
* DBG_WATCHPOINT_RW. (or 0 to disable).
94-
*/
95-
#define dbg_SetWatchpoint(address, length, flags) \
96-
do { \
97-
*(volatile unsigned int*)0xFFFFE4 = (unsigned int)(address); \
98-
*(volatile unsigned int*)0xFFFFE8 = ((unsigned int)(address) + (length) - 1); \
99-
*(volatile unsigned char*)0xFFFFEC = (unsigned char)(flags); \
100-
*(volatile unsigned char*)0xFFFFE0 = 3; \
101-
} while (0)
64+
void dbg_Debugger(void);
10265

10366
/**
104-
* Removes an emulated watchpoint.
105-
*
106-
* @param[in] address Watchpoint address to remove.
67+
* Sets a watchpoint to open the debugger when an address
68+
* is read, written, or executed. Use the masks DBG_WATCHPOINT_READ,
69+
* DBG_WATCHPOINT_WRITE, and DBG_WATCHPOINT_EXECUTE respectively to
70+
* configure the watchpoint.
71+
*
72+
* @param[in] address Watchpoint address.
73+
* @param[in] size Watchpoint size in bytes. Currently must be 1.
74+
* @param[in] mask Watchpoint mask, use DBG_WATCHPOINT_NONE to remove
75+
* the watchpoint.
10776
*/
108-
#define dbg_RemoveWatchpoint(address) \
109-
do { \
110-
*(volatile unsigned int*)0xFFFFE4 = (unsigned int)(address); \
111-
*(volatile unsigned char*)0xFFFFE0 = 4; \
112-
} while (0)
77+
void dbg_WatchpointSet(void *address, size_t size, uint8_t mask);
11378

11479
/**
115-
* Removes all emulated breakpoints.
80+
* Removes all watchpoints.
11681
*/
117-
#define dbg_RemoveAllBreakpoints() \
118-
do { \
119-
*(volatile unsigned char*)0xFFFFE0 = 5; \
120-
} while (0)
121-
122-
/**
123-
* Removes all emulated watchpoints.
124-
*/
125-
#define dbg_RemoveAllWatchpoints() \
126-
do { \
127-
*(volatile unsigned char*)0xFFFFE0 = 6; \
128-
} while (0)
82+
void dbg_WatchpointRemoveAll(void);
12983

13084
#else
13185
#define dbg_printf(...) ((void)0)
13286
#define dbg_sprintf(...) ((void)0)
13387
#define dbg_ClearConsole(...) ((void)0)
13488
#define dbg_Debugger(...) ((void)0)
135-
#define dbg_SetBreakpoint(...) ((void)0)
136-
#define dbg_RemoveBreakpoint(...) ((void)0)
137-
#define dbg_SetWatchpoint(...) ((void)0)
138-
#define dbg_RemoveWatchpoint(...) ((void)0)
139-
#define dbg_RemoveAllBreakpoints(...) ((void)0)
140-
#define dbg_RemoveAllWatchpoints(...) ((void)0)
89+
#define dbg_WatchpointSet(...) ((void)0)
90+
#define dbg_WatchpointRemoveAll(...) ((void)0)
14191
#endif
14292

14393
#ifdef __cplusplus

src/ce/include/ti/debug.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)