# Debugging using tk.rb

**URL:** <https://www.ruby-forum.com/t/debugging-using-tk-rb/72855>\
**Category:** Ruby\
**Created:** [October 19, 2006, 1:06pm UTC](https://www.ruby-forum.com/t/debugging-using-tk-rb/72855 "2006-10-19T13:06:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [October 19, 2006, 1:06pm UTC](https://www.ruby-forum.com/t/debugging-using-tk-rb/72855/1 "2006-10-19T13:06:38Z")

</div>

Is it possible to use the debug library while using tk.rb?  
It seems to work only as long as the Tk mainloop is not entered…

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [October 20, 2006, 4:24am UTC](https://www.ruby-forum.com/t/debugging-using-tk-rb/72855/2 "2006-10-20T04:24:23Z")

</div>

From: Wybo D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: debugging using tk.rb  
Date: Thu, 19 Oct 2006 20:06:23 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Is it possible to use the debug library while using tk.rb?  
> It seems to work only as long as the Tk mainloop is not entered…

# Maybe, the following cannot help you …

If it is the reason of the trouble that “Tk.mainloop” doesn’t  
return while the root (main) window is alive, please try to start  
“Tk.mainloop” in a Thread (e.g. evloop = Thread.new{Tk.mainloop}).

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [October 21, 2006, 10:12am UTC](https://www.ruby-forum.com/t/debugging-using-tk-rb/72855/3 "2006-10-21T10:12:23Z")

</div>

Hidetoshi NAGAI wrote:

> return while the root (main) window is alive, please try to start  
> “Tk.mainloop” in a Thread (e.g. evloop = Thread.new{Tk.mainloop}).

when I do that literally, the script exits immediately, without any  
messages. When I use () instead of {}: evloop = Thread.new(Tk.mainloop)  
then it starts normally, but there is no difference with just  
Tk.mainloop.

For example, running the Pig Latin Generator from Dave’s book  
(attached): if I try to debug the pig method with  
`break PigBox:pig', then hitting the`Pig It’ button should stop me in  
the pig method, but that doesn’t happen. (I can, however) circumvent  
this by setting the break point on the line number).

And when I hit the `Exit’ button, an error message pops up:

FATAL  
FATAL  
while executing  
“rb\_out c00002”  
invoked from within  
“.w00000.w00004 invoke”  
(“uplevel” body line 1)  
invoked from within  
“uplevel #0 [list $w invoke]”  
(procedure “tk::ButtonUp” line 22)  
invoked from within  
“tk::ButtonUp .w00000.w00004”  
(command bound to event)

One of my real, rather complex, applications says, as soon as I enter  
the Tk-window with my mouse:

/home/wybo/bin/adm/admin:4:$: \<\< File.dirname( **FILE** ) files  
(rdb:1) b ~/bin/admin\_transaction.rb:108  
Set breakpoint 1 at ~/bin/admin\_transaction.rb:108  
(rdb:1) c  
/usr/local/lib/ruby/1.8/tk/event.rb:443: `invalid value for Integer: "??"' (ArgumentError) from /usr/local/lib/ruby/1.8/tk.rb:1323:in`catch’  
from /usr/local/lib/ruby/1.8/tk.rb:1323:in `callback' from /usr/local/lib/ruby/1.8/tk.rb:1557:in`mainloop’  
from /usr/local/lib/ruby/1.8/tk.rb:1557:in `mainloop’  
from /home/wybo/bin/adm/admin:1248  
/usr/local/lib/ruby/1.8/tk/event.rb:443: TkUtil.eval\_cmd(cmd,  
\*(ex\_args \<\< klass.new(\*klass.scan\_args(keys, arg))))  
(rdb:1)

I suspect that this error message is caused by the use of rio(??) (for  
the creation of temporary files)

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [October 21, 2006, 2:09pm UTC](https://www.ruby-forum.com/t/debugging-using-tk-rb/72855/4 "2006-10-21T14:09:06Z")

</div>

Hi –

On Sat, 21 Oct 2006, David V. wrote:

> Wybo D. wrote:
> 
> > When I use () instead of {}: evloop = Thread.new(Tk.mainloop)  
> > then it starts normally, but there is no difference with just Tk.mainloop.
> 
> Duh.

The discourse on this list seems to have drifted toward the impatient,  
critical, and judgmental. Could it perhaps drift back toward  
collegiality, based on the fact that we’re all involved in the ongoing  
process of grasping and productively using various technologies?

David

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [October 21, 2006, 5:38pm UTC](https://www.ruby-forum.com/t/debugging-using-tk-rb/72855/5 "2006-10-21T17:38:03Z")

</div>

removed\_email\_address@domain.invalid wrote:

> > Duh.
> 
> The discourse on this list seems to have drifted toward the impatient,  
> critical, and judgmental. Could it perhaps drift back toward  
> collegiality, based on the fact that we’re all involved in the ongoing  
> process of grasping and productively using various technologies?
> 
> David

thanks, David Black, for your support.  
The problem is, I’m one of those non-professional users who can, with  
their limited knowledge, do a lot with Ruby without understanding all  
it’s ins and outs. For instance, I have no experience with threads at  
all, so when I am suggested a solution using those, I just try, and if  
it works I have another reason to study threads in detail. Before that  
I’m stupid enough to think that Thread.new{…}, which did nothing, may  
have been a typo…

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [October 21, 2006, 6:56pm UTC](https://www.ruby-forum.com/t/debugging-using-tk-rb/72855/6 "2006-10-21T18:56:15Z")

</div>

From: Wybo D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: debugging using tk.rb  
Date: Sat, 21 Oct 2006 17:12:05 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> For example, running the Pig Latin Generator from Dave’s book  
> (attached): if I try to debug the pig method with  
> `break PigBox:pig', then hitting the `Pig It’ button should stop me in  
> the pig method, but that doesn’t happen. (I can, however) circumvent  
> this by setting the break point on the line number).
> 
> And when I hit the `Exit’ button, an error message pops up:
> 
> FATAL

I see. But unfortunately, there is no solution.  
The callback process of Ruby/Tk is a little complex.  
Longjmp must be handled very carefully, because it may break  
consistency of Ruby’s stack, Tcl/Tk’s stack, and Tcl/Tk’s  
internal status.  
If not, such like as your trouble, longjmp causes SEGV easily.

# Which version of Ruby/Tk do you use?

> One of my real, rather complex, applications says, as soon as I enter  
> the Tk-window with my mouse:
> 
> /home/wybo/bin/adm/admin:4:$: \<\< File.dirname( **FILE** ) files  
> (rdb:1) b ~/bin/admin\_transaction.rb:108  
> Set breakpoint 1 at ~/bin/admin\_transaction.rb:108  
> (rdb:1) c  
> /usr/local/lib/ruby/1.8/tk/event.rb:443: `invalid value for Integer:  
> “??”’ (ArgumentError)

That is fail of converting a event parameter to an object.  
Tcl/Tk returns a string “??” for an undefined parameter on a event.  
In that case, Tcl/Tk returns a “??” for the parameter which is  
expected as an integer.  
It may be a bug on Ruby/Tk.  
Could you show me your definition of binding?

# Probably, you will be able to avoid the trouble

# by using “%” substiturion arguments.

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [October 21, 2006, 1:53pm UTC](https://www.ruby-forum.com/t/debugging-using-tk-rb/72855/7 "2006-10-21T13:53:05Z")

</div>

Wybo D. wrote:

> When I use () instead of {}: evloop = Thread.new(Tk.mainloop)  
> then it starts normally, but there is no difference with just Tk.mainloop.

Duh. Ruby is a strictly evaluated language, arguments to a function call  
are evaluated before the call. Tk.mainloop hangs the interpreter before  
Thread.new is ever called.

(You might want to spend some time on learning Ruby syntax and what the  
difference between those brackets is.)

David V.
