You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,7 @@ Table of Contents
8
8
*[Usage](#usage)
9
9
*[My Approach](#my-approach)
10
10
*[Timeline](#timeline)
11
+
*[Debugging the generated program](#debugging-the-generated-program)
11
12
*[Test Programs](#test-programs)
12
13
*[Future Plans?](#future-plans)
13
14
*[Bug Reports?](#bug-reports)
@@ -96,6 +97,50 @@ In the end it took me about four hours to get something I was happy with, and la
96
97
* After that I slowly made improvements
97
98
* Adding a lexer in [#4](https://github.com/skx/bfcc/pull/4)
98
99
* Allowing the generation of either C or assembly in [#6](https://github.com/skx/bfcc/pull/6)
100
+
* Allow generating a breakpoint instruction when using the assembly-backend in [#7](https://github.com/skx/bfcc/pull/7).
101
+
102
+
103
+
### Debugging the generated program
104
+
105
+
If you run the compiler with the `-debug` flag a breakpoint will be generated
106
+
immediately at the start of the program. You can use that breakpoint to easily
107
+
debug the generated binary via `gdb`.
108
+
109
+
$ bfcc -debug ./examples/hello-world.bf
110
+
111
+
Now you can launch that binary under `gdb`, and run it:
112
+
113
+
$ gdb ./a.out
114
+
(gdb) run
115
+
..
116
+
Program received signal SIGTRAP, Trace/breakpoint trap.
117
+
0x00000000004000bb in _start ()
118
+
119
+
Disassemble the code via `disassemble`, and step over instructions one at a time via `stepi`. If your program is long you might see a lot of output from the `disassemble` step.
120
+
121
+
(gdb) disassemble
122
+
Dump of assembler code for function _start:
123
+
0x00000000004000b0 <+0>: movabs $0x600290,%r8
124
+
0x00000000004000ba <+10>: int3
125
+
=> 0x00000000004000bb <+11>: addb $0x8,(%r8)
126
+
0x00000000004000bf <+15>: cmpb $0x0,(%r8)
127
+
0x00000000004000c3 <+19>: je 0x40013f <close_loop_1>
128
+
End of assembler dump.
129
+
130
+
You can set a breakpoint at a line in the future, and continue running till
131
+
you hit it, with something like this:
132
+
133
+
(gdb) break *0x00000000004000c3
134
+
(gdb) cont
135
+
136
+
Once there inspect the registers with commands like these two:
137
+
138
+
(gdb) print $r8
139
+
(gdb) print *$r8
140
+
(gdb) info registers
141
+
142
+
Further documentation can be found in the `gdb` manual, which is worth reading
143
+
if you've an interest in compilers, debuggers, and decompilers.
0 commit comments