Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit debug information for toplevel variables #3473

Merged
merged 1 commit into from
Oct 26, 2016

Conversation

ggiraldez
Copy link
Contributor

When compiling with debug output, emit debug information for toplevel variables both in the main file and in required files. For example, given a file foo.cr:

foo1 = 1
foo2 = 10
foo3 = 100
foo4 = foo1 + foo2 + foo3

puts "foo4 = #{foo4}"

and a file bar.cr:

require "./foo"

bar1 = 2
bar2 = 3
bar3 = 5
bar4 = bar1 * bar2 * bar3

puts "bar4 = #{bar4}"

Compiling bar.cr with debugging information will allow:

(gdb) b foo.cr:1
Breakpoint 1 at 0x100000ce5: file /Users/ggiraldez/ScratchPad/crystal-debug/foo.cr, line 1.
(gdb) b bar.cr:1
Breakpoint 2 at 0x100000d40: file /Users/ggiraldez/ScratchPad/crystal-debug/bar.cr, line 1.
(gdb) run
Starting program: /Users/ggiraldez/ScratchPad/crystal-debug/bar

Breakpoint 1, __crystal_main () at /Users/ggiraldez/ScratchPad/crystal-debug/foo.cr:1
1   foo1 = 1
(gdb) info locals
foo1 = 32767
foo2 = 1900987092
foo3 = 32767
foo4 = -2028132910
(gdb) n
2   foo2 = 10
(gdb) n
3   foo3 = 100
(gdb) n
4   foo4 = foo1 + foo2 + foo3
(gdb) n
6   puts "foo4 = #{foo4}"
(gdb) info locals
foo1 = 1
foo2 = 10
foo3 = 100
foo4 = 111
(gdb) c
Continuing.
foo4 = 111

Breakpoint 2, __crystal_main () at /Users/ggiraldez/ScratchPad/crystal-debug/bar.cr:3
3   bar1 = 2
(gdb) info locals
bar1 = 32767
bar2 = 1606416352
bar3 = 1
bar4 = 34723
(gdb) n
4   bar2 = 3
(gdb) n
5   bar3 = 5
(gdb) n
6   bar4 = bar1 * bar2 * bar3
(gdb) n
8   puts "bar4 = #{bar4}"
(gdb) info locals
bar1 = 2
bar2 = 3
bar3 = 5
bar4 = 30

@asterite
Copy link
Member

Looks really good, thank you! 😄😉

@asterite asterite merged commit 61a3b69 into crystal-lang:master Oct 26, 2016
@ggiraldez ggiraldez deleted the debug/toplevel-vars branch October 27, 2016 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants