I am trying to learn to debug programs written in Crystal with GDB. Here is a sample:
class Demo
@array = [] of String
def bar(url)
ret = url.downcase * 2
if ret == "alsj"
return false
else
return ret
end
end
def do(foo)
@array.push(foo)
html = bar(foo)
puts "HI" # GDB breakpoint here
return html
end
end
a = Demo.new
puts a.do("HI")
I compiled the sample above with the --debug flag and loaded it into GDB. Then I let it run and stopped at the marked line (GDB breakpoint here). Now I have three four questions:
- Printing string values (e.g.
foo): When I inspect a string variable, I often see something like$1 = (struct String *) 0x4b9f18. When I sayprintf "%s", foo, I get nothing back. How can I display the current value of a string variable? - optimized out.
Other times I just see
$1 = <optimized out>when inspecting a variable. What does that mean and how can I see the value in that case? - Accessing object variables
How can I see the value of
@arrayin the given situation?p arraysays no symbol in current context andp @arrayreturns unknown address space modifier. Edit: I found a way: usep self.array - Vanished variables
In the given situation (breaking at the line
puts "HI") I can't see the variable html at all:p htmlreturns no symbol in current context. Why is that and how do I solve it?