-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_markers.nim
55 lines (49 loc) · 1.84 KB
/
debug_markers.nim
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
#****h* debug/markers
## PURPOSE
## Debug markers (breakpoints, tracepoints, wactchpoints) that are placed at
## strategic points in source code.
## NOTES
## It looks like @timotheecour is making a LLDB plugin:
## https://github.com/timotheecour/Nim/issues/599
## SEE ALSO
## - https://internet-of-tomohiro.netlify.app/nim/gdb.en.html
## - https://nim-lang.org/blog/2017/10/02/documenting-profiling-and-debugging-nim-code.html
## - manual.html#implementation-specific-pragmas-injectstmt-pragma
## TODO
## - [ ] recall why I wanted a `debugSession` string id as the first arg
#******
import std/[macros, sets]
# when defined(debug):
# {.warning: "DEBUG MODE".}
#from std/posix import [`raise`, SIGTRAP]
# The InjectStmt pragma.
#{.injectStmt: gcInvariants().}
proc isDebuggerPresent*(): bool =
proc detectUsingSigtrap(): bool =
# https://www.oreilly.com/library/view/secure-programming-cookbook/0596003943/ch12s13.html
discard
## https://stackoverflow.com/questions/3596781/how-to-detect-if-the-current-process-is-being-run-by-gdb
discard
macro setBreak*(cond; expr: untyped = nil, tags = HashSet[string]()) =
## Set a break point at the current line.
when defined(debug):
discard
else: discard
macro setTrace*(cond; expr: untyped = nil, tags = HashSet[string]()) =
## Set a trace point at the current line.
## Evaluate the expression each time the trace is called.
when defined(debug):
discard
else: discard
macro setWatch*(cond; expr: untyped = nil, tags = HashSet[string]()) =
## Set a watch point for a location in memory.
## The expression is evaluated for a symbol or address when the watch is set.
when defined(debug):
discard
else: discard
template bp* = setBreak
macro bp*(cond; expr: untyped = nil, tags = HashSet[string]()) =
setBreak(`cond`)
discard
template tp* = setTrace
template wp* = setWatch