Temporary breakpoints

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Temporary breakpoints

Karsten Kusche
Hi,

I want to create temporary breakpoints that only fire once and then
remove themselves from the method.
So far it's opening the debugger at the beginning of the method. This is
basically done with this method:

actOn: aContext
        | mDef method |
        (self test: aContext)
          ifTrue:
                [mDef := aContext method definition.
                method := mDef method.
                method removeProbe: self.
                method hasAnyProbes
                  ifFalse:
                        [method mclass addSelector: method selector
                                withMethod: method originalMethod].
                aContext restartWith: mDef method.
                ^self breakOn: aContext label: self labelString.]

As the debugger is capable of removing a breakpoint while a method is
running, i'd like to use this functionality.
I would like to remove the probe in the shown method because this is
right before the debugger opens and the #breakOn:label: never returns,
so I can't remove it afterwards in this method.

In the method
DebugProbeInserter>>#adjustDynamicsReplacing:with:from:atPC:addProbe:originalPCMap:
is a reference to 'debugger context supposedHome' and to 'debugger
topContext'. As I don't have a debugger open at this point, I donno what
the values of these contexts are. If I just assume that both values are
aContext from the above method, the method does not find the map-index
for a given pc in #findMapIndexFor:inMap:.

Can someone please explain to me, what these values are supposed to be,
or if I'm doing something completely wrong.

Thanks in advance
Karsten

Reply | Threaded
Open this post in threaded view
|

RE: Temporary breakpoints

Terry Raymond
Karsten

A simpler solution it to use a one shot conditional
expresssion. You will find it in the TestLib.st in
the PDP directory. Use the Debug->Test Library->Load...
menu command to load the library. This is also documented
in the App Dev Guide in the Debugging Techniques/Global
Probe Management section.

Also, if you read the Debugging Techniques you will find
a discussion of Temporary probes. They are intended to exist
only in an active Context, i.e. one that is on the send stack.
When the context exits the probe disappears.

Terry
 
===========================================================
Terry Raymond       Smalltalk Professional Debug Package
Crafted Smalltalk
80 Lazywood Ln.
Tiverton, RI  02878
(401) 624-4517      [hidden email]
<http://www.craftedsmalltalk.com>
===========================================================

> -----Original Message-----
> From: Karsten [mailto:[hidden email]]
> Sent: Thursday, September 14, 2006 12:02 PM
> To: VWNC
> Subject: Temporary breakpoints
>
> Hi,
>
> I want to create temporary breakpoints that only fire once and then
> remove themselves from the method.
> So far it's opening the debugger at the beginning of the method. This is
> basically done with this method:
>
> actOn: aContext
> | mDef method |
> (self test: aContext)
>  ifTrue:
> [mDef := aContext method definition.
> method := mDef method.
> method removeProbe: self.
> method hasAnyProbes
>  ifFalse:
> [method mclass addSelector: method selector
> withMethod: method originalMethod].
> aContext restartWith: mDef method.
> ^self breakOn: aContext label: self labelString.]
>
> As the debugger is capable of removing a breakpoint while a method is
> running, i'd like to use this functionality.
> I would like to remove the probe in the shown method because this is
> right before the debugger opens and the #breakOn:label: never returns,
> so I can't remove it afterwards in this method.
>
> In the method
> DebugProbeInserter>>#adjustDynamicsReplacing:with:from:atPC:addProbe:origi
> nalPCMap:
> is a reference to 'debugger context supposedHome' and to 'debugger
> topContext'. As I don't have a debugger open at this point, I donno what
> the values of these contexts are. If I just assume that both values are
> aContext from the above method, the method does not find the map-index
> for a given pc in #findMapIndexFor:inMap:.
>
> Can someone please explain to me, what these values are supposed to be,
> or if I'm doing something completely wrong.
>
> Thanks in advance
> Karsten

Reply | Threaded
Open this post in threaded view
|

AW: Temporary breakpoints

Georg Heeg
Terry,

I spoke with Karsten before he sent the message. So please let me comment:
Global probe management and temporary breakpoints do not solve his idea of a
one time breakpoint; as you describe a temporary breakpoint is created while
an execution method alredy exists. A one time breakpoint is created while
there is no execution context; when the next execution occurs, the
breakpoint fires and disappears.

You might use the following statement to represent a one time breakpoint.

        NotFirstTime ifNil: [NotFirstTime := true. self halt].

One example is to execute an SUnit test case in debugger control. This means
that the debugger should open before the first statement of the test method
regardless of any error or failure.

Georg

-----Ursprüngliche Nachricht-----
Von: Terry Raymond [mailto:[hidden email]]
Gesendet: Donnerstag, 14. September 2006 18:30
An: 'Karsten'; 'VWNC'
Betreff: RE: Temporary breakpoints

Karsten

A simpler solution it to use a one shot conditional
expresssion. You will find it in the TestLib.st in
the PDP directory. Use the Debug->Test Library->Load...
menu command to load the library. This is also documented
in the App Dev Guide in the Debugging Techniques/Global
Probe Management section.

Also, if you read the Debugging Techniques you will find
a discussion of Temporary probes. They are intended to exist
only in an active Context, i.e. one that is on the send stack.
When the context exits the probe disappears.

Terry
 
===========================================================
Terry Raymond       Smalltalk Professional Debug Package
Crafted Smalltalk
80 Lazywood Ln.
Tiverton, RI  02878
(401) 624-4517      [hidden email]
<http://www.craftedsmalltalk.com>
===========================================================

> -----Original Message-----
> From: Karsten [mailto:[hidden email]]
> Sent: Thursday, September 14, 2006 12:02 PM
> To: VWNC
> Subject: Temporary breakpoints
>
> Hi,
>
> I want to create temporary breakpoints that only fire once and then
> remove themselves from the method.
> So far it's opening the debugger at the beginning of the method. This is
> basically done with this method:
>
> actOn: aContext
> | mDef method |
> (self test: aContext)
>  ifTrue:
> [mDef := aContext method definition.
> method := mDef method.
> method removeProbe: self.
> method hasAnyProbes
>  ifFalse:
> [method mclass addSelector: method selector
> withMethod: method originalMethod].
> aContext restartWith: mDef method.
> ^self breakOn: aContext label: self labelString.]
>
> As the debugger is capable of removing a breakpoint while a method is
> running, i'd like to use this functionality.
> I would like to remove the probe in the shown method because this is
> right before the debugger opens and the #breakOn:label: never returns,
> so I can't remove it afterwards in this method.
>
> In the method
> DebugProbeInserter>>#adjustDynamicsReplacing:with:from:atPC:addProbe:origi
> nalPCMap:
> is a reference to 'debugger context supposedHome' and to 'debugger
> topContext'. As I don't have a debugger open at this point, I donno what
> the values of these contexts are. If I just assume that both values are
> aContext from the above method, the method does not find the map-index
> for a given pc in #findMapIndexFor:inMap:.
>
> Can someone please explain to me, what these values are supposed to be,
> or if I'm doing something completely wrong.
>
> Thanks in advance
> Karsten


Reply | Threaded
Open this post in threaded view
|

RE: Temporary breakpoints

Terry Raymond
Georg

Your description of the one time breakpoint is provided
for in the TestLib.st library.

The library has a conditional expression for one-shot probes.
You can do a tremendous amount of stuff with the probe
conditional expression. You don't need to remove the probe,
just disable it.

Terry
 
===========================================================
Terry Raymond       Smalltalk Professional Debug Package
Crafted Smalltalk
80 Lazywood Ln.
Tiverton, RI  02878
(401) 624-4517      [hidden email]
<http://www.craftedsmalltalk.com>
===========================================================

> -----Original Message-----
> From: Georg Heeg [mailto:[hidden email]]
> Sent: Thursday, September 14, 2006 1:26 PM
> To: 'Terry Raymond'; 'Karsten'; 'VWNC'
> Subject: AW: Temporary breakpoints
>
> Terry,
>
> I spoke with Karsten before he sent the message. So please let me comment:
> Global probe management and temporary breakpoints do not solve his idea of
> a
> one time breakpoint; as you describe a temporary breakpoint is created
> while
> an execution method alredy exists. A one time breakpoint is created while
> there is no execution context; when the next execution occurs, the
> breakpoint fires and disappears.
>
> You might use the following statement to represent a one time breakpoint.
>
> NotFirstTime ifNil: [NotFirstTime := true. self halt].
>
> One example is to execute an SUnit test case in debugger control. This
> means
> that the debugger should open before the first statement of the test
> method
> regardless of any error or failure.
>
> Georg
>
> -----Ursprüngliche Nachricht-----
> Von: Terry Raymond [mailto:[hidden email]]
> Gesendet: Donnerstag, 14. September 2006 18:30
> An: 'Karsten'; 'VWNC'
> Betreff: RE: Temporary breakpoints
>
> Karsten
>
> A simpler solution it to use a one shot conditional
> expresssion. You will find it in the TestLib.st in
> the PDP directory. Use the Debug->Test Library->Load...
> menu command to load the library. This is also documented
> in the App Dev Guide in the Debugging Techniques/Global
> Probe Management section.
>
> Also, if you read the Debugging Techniques you will find
> a discussion of Temporary probes. They are intended to exist
> only in an active Context, i.e. one that is on the send stack.
> When the context exits the probe disappears.
>
> Terry
>
> ===========================================================
> Terry Raymond       Smalltalk Professional Debug Package
> Crafted Smalltalk
> 80 Lazywood Ln.
> Tiverton, RI  02878
> (401) 624-4517      [hidden email]
> <http://www.craftedsmalltalk.com>
> ===========================================================
> > -----Original Message-----
> > From: Karsten [mailto:[hidden email]]
> > Sent: Thursday, September 14, 2006 12:02 PM
> > To: VWNC
> > Subject: Temporary breakpoints
> >
> > Hi,
> >
> > I want to create temporary breakpoints that only fire once and then
> > remove themselves from the method.
> > So far it's opening the debugger at the beginning of the method. This is
> > basically done with this method:
> >
> > actOn: aContext
> > | mDef method |
> > (self test: aContext)
> >  ifTrue:
> > [mDef := aContext method definition.
> > method := mDef method.
> > method removeProbe: self.
> > method hasAnyProbes
> >  ifFalse:
> > [method mclass addSelector: method selector
> > withMethod: method originalMethod].
> > aContext restartWith: mDef method.
> > ^self breakOn: aContext label: self labelString.]
> >
> > As the debugger is capable of removing a breakpoint while a method is
> > running, i'd like to use this functionality.
> > I would like to remove the probe in the shown method because this is
> > right before the debugger opens and the #breakOn:label: never returns,
> > so I can't remove it afterwards in this method.
> >
> > In the method
> >
> DebugProbeInserter>>#adjustDynamicsReplacing:with:from:atPC:addProbe:origi
> > nalPCMap:
> > is a reference to 'debugger context supposedHome' and to 'debugger
> > topContext'. As I don't have a debugger open at this point, I donno what
> > the values of these contexts are. If I just assume that both values are
> > aContext from the above method, the method does not find the map-index
> > for a given pc in #findMapIndexFor:inMap:.
> >
> > Can someone please explain to me, what these values are supposed to be,
> > or if I'm doing something completely wrong.
> >
> > Thanks in advance
> > Karsten


Reply | Threaded
Open this post in threaded view
|

Re: Temporary breakpoints

Karsten Kusche
Hi Terry,
> Your description of the one time breakpoint is provided
> for in the TestLib.st library
> The library has a conditional expression for one-shot probes.
> You can do a tremendous amount of stuff with the probe
> conditional expression. You don't need to remove the probe,
> just disable it.
>  
this is exactly what i don't want to do. I fully understand that
conditional probes can do a lot of useful stuff and also solve my
problem in a way, but not in the way i want to solve it. i don't want my
methods to contain a lot of disabled breakpoints. i just want them to be
probed while i start them, then i want them to be the normal method they
were before. i see this is possible in the debugger, so why not also
before the debugger opens? i mean it's still smalltalk and one can
change almost about everything, so why not give it a try?

Karsten


> Terry
>  
> ===========================================================
> Terry Raymond       Smalltalk Professional Debug Package
> Crafted Smalltalk
> 80 Lazywood Ln.
> Tiverton, RI  02878
> (401) 624-4517      [hidden email]
> <http://www.craftedsmalltalk.com>
> ===========================================================
>
>  
>> -----Original Message-----
>> From: Georg Heeg [mailto:[hidden email]]
>> Sent: Thursday, September 14, 2006 1:26 PM
>> To: 'Terry Raymond'; 'Karsten'; 'VWNC'
>> Subject: AW: Temporary breakpoints
>>
>> Terry,
>>
>> I spoke with Karsten before he sent the message. So please let me comment:
>> Global probe management and temporary breakpoints do not solve his idea of
>> a
>> one time breakpoint; as you describe a temporary breakpoint is created
>> while
>> an execution method alredy exists. A one time breakpoint is created while
>> there is no execution context; when the next execution occurs, the
>> breakpoint fires and disappears.
>>
>> You might use the following statement to represent a one time breakpoint.
>>
>> NotFirstTime ifNil: [NotFirstTime := true. self halt].
>>
>> One example is to execute an SUnit test case in debugger control. This
>> means
>> that the debugger should open before the first statement of the test
>> method
>> regardless of any error or failure.
>>
>> Georg
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Terry Raymond [mailto:[hidden email]]
>> Gesendet: Donnerstag, 14. September 2006 18:30
>> An: 'Karsten'; 'VWNC'
>> Betreff: RE: Temporary breakpoints
>>
>> Karsten
>>
>> A simpler solution it to use a one shot conditional
>> expresssion. You will find it in the TestLib.st in
>> the PDP directory. Use the Debug->Test Library->Load...
>> menu command to load the library. This is also documented
>> in the App Dev Guide in the Debugging Techniques/Global
>> Probe Management section.
>>
>> Also, if you read the Debugging Techniques you will find
>> a discussion of Temporary probes. They are intended to exist
>> only in an active Context, i.e. one that is on the send stack.
>> When the context exits the probe disappears.
>>
>> Terry
>>
>> ===========================================================
>> Terry Raymond       Smalltalk Professional Debug Package
>> Crafted Smalltalk
>> 80 Lazywood Ln.
>> Tiverton, RI  02878
>> (401) 624-4517      [hidden email]
>> <http://www.craftedsmalltalk.com>
>> ===========================================================
>>    
>>> -----Original Message-----
>>> From: Karsten [mailto:[hidden email]]
>>> Sent: Thursday, September 14, 2006 12:02 PM
>>> To: VWNC
>>> Subject: Temporary breakpoints
>>>
>>> Hi,
>>>
>>> I want to create temporary breakpoints that only fire once and then
>>> remove themselves from the method.
>>> So far it's opening the debugger at the beginning of the method. This is
>>> basically done with this method:
>>>
>>> actOn: aContext
>>> | mDef method |
>>> (self test: aContext)
>>>  ifTrue:
>>> [mDef := aContext method definition.
>>> method := mDef method.
>>> method removeProbe: self.
>>> method hasAnyProbes
>>>  ifFalse:
>>> [method mclass addSelector: method selector
>>> withMethod: method originalMethod].
>>> aContext restartWith: mDef method.
>>> ^self breakOn: aContext label: self labelString.]
>>>
>>> As the debugger is capable of removing a breakpoint while a method is
>>> running, i'd like to use this functionality.
>>> I would like to remove the probe in the shown method because this is
>>> right before the debugger opens and the #breakOn:label: never returns,
>>> so I can't remove it afterwards in this method.
>>>
>>> In the method
>>>
>>>      
>> DebugProbeInserter>>#adjustDynamicsReplacing:with:from:atPC:addProbe:origi
>>    
>>> nalPCMap:
>>> is a reference to 'debugger context supposedHome' and to 'debugger
>>> topContext'. As I don't have a debugger open at this point, I donno what
>>> the values of these contexts are. If I just assume that both values are
>>> aContext from the above method, the method does not find the map-index
>>> for a given pc in #findMapIndexFor:inMap:.
>>>
>>> Can someone please explain to me, what these values are supposed to be,
>>> or if I'm doing something completely wrong.
>>>
>>> Thanks in advance
>>> Karsten
>>>      
>
>
>
>  

Reply | Threaded
Open this post in threaded view
|

RE: Temporary breakpoints

Terry Raymond
In reply to this post by Karsten Kusche
Karsten

I can't tell what your problem is from the information
in your message. I can see your #actOn: method may have
a problem because your are restarting it and then doing
a #breakOn:. Also, the debugger will expect pc to be pointing
to the bytecode after the #actOn: message send and it will
be expecting that it needs to adjust the return stack for
nothing being pushed on it.

How did you try to invoke the DebugProbeInserter?

I think the easiest solution would be to create a MockDebugger
object so it works with the DebugProbeInserter and use it
to remove your probe. It appears to me that both 'topContext'
and 'context' would be aContext, as you had assumed.

Terry
 
===========================================================
Terry Raymond       Smalltalk Professional Debug Package
Crafted Smalltalk
80 Lazywood Ln.
Tiverton, RI  02878
(401) 624-4517      [hidden email]
<http://www.craftedsmalltalk.com>
===========================================================

> -----Original Message-----
> From: Karsten [mailto:[hidden email]]
> Sent: Thursday, September 14, 2006 12:02 PM
> To: VWNC
> Subject: Temporary breakpoints
>
> Hi,
>
> I want to create temporary breakpoints that only fire once and then
> remove themselves from the method.
> So far it's opening the debugger at the beginning of the method. This is
> basically done with this method:
>
> actOn: aContext
> | mDef method |
> (self test: aContext)
>  ifTrue:
> [mDef := aContext method definition.
> method := mDef method.
> method removeProbe: self.
> method hasAnyProbes
>  ifFalse:
> [method mclass addSelector: method selector
> withMethod: method originalMethod].
> aContext restartWith: mDef method.
> ^self breakOn: aContext label: self labelString.]
>
> As the debugger is capable of removing a breakpoint while a method is
> running, i'd like to use this functionality.
> I would like to remove the probe in the shown method because this is
> right before the debugger opens and the #breakOn:label: never returns,
> so I can't remove it afterwards in this method.
>
> In the method
> DebugProbeInserter>>#adjustDynamicsReplacing:with:from:atPC:addProbe:origi
> nalPCMap:
> is a reference to 'debugger context supposedHome' and to 'debugger
> topContext'. As I don't have a debugger open at this point, I donno what
> the values of these contexts are. If I just assume that both values are
> aContext from the above method, the method does not find the map-index
> for a given pc in #findMapIndexFor:inMap:.
>
> Can someone please explain to me, what these values are supposed to be,
> or if I'm doing something completely wrong.
>
> Thanks in advance
> Karsten

Reply | Threaded
Open this post in threaded view
|

Re: Temporary breakpoints

Karsten Kusche
Ok, i got it working, it also works in blocks.

basically i copy the current context and assign a newTempMethod to this
context, or a dcopy of the block, if the context contains a block.

then i remove the probe from the original method and call a debugger on
the previously created new context. if the context is already under
debugging i just raise the normal break signal.

If you want to have a closer look at the implementation you may have a
look at the public repository. The Package is called TempCodeProbe.

have a nice weekend everyone
Karsten



Terry Raymond schrieb:

> Karsten
>
> I can't tell what your problem is from the information
> in your message. I can see your #actOn: method may have
> a problem because your are restarting it and then doing
> a #breakOn:. Also, the debugger will expect pc to be pointing
> to the bytecode after the #actOn: message send and it will
> be expecting that it needs to adjust the return stack for
> nothing being pushed on it.
>
> How did you try to invoke the DebugProbeInserter?
>
> I think the easiest solution would be to create a MockDebugger
> object so it works with the DebugProbeInserter and use it
> to remove your probe. It appears to me that both 'topContext'
> and 'context' would be aContext, as you had assumed.
>
> Terry
>  
> ===========================================================
> Terry Raymond       Smalltalk Professional Debug Package
> Crafted Smalltalk
> 80 Lazywood Ln.
> Tiverton, RI  02878
> (401) 624-4517      [hidden email]
> <http://www.craftedsmalltalk.com>
> ===========================================================
>
>> -----Original Message-----
>> From: Karsten [mailto:[hidden email]]
>> Sent: Thursday, September 14, 2006 12:02 PM
>> To: VWNC
>> Subject: Temporary breakpoints
>>
>> Hi,
>>
>> I want to create temporary breakpoints that only fire once and then
>> remove themselves from the method.
>> So far it's opening the debugger at the beginning of the method. This is
>> basically done with this method:
>>
>> actOn: aContext
>> | mDef method |
>> (self test: aContext)
>>  ifTrue:
>> [mDef := aContext method definition.
>> method := mDef method.
>> method removeProbe: self.
>> method hasAnyProbes
>>  ifFalse:
>> [method mclass addSelector: method selector
>> withMethod: method originalMethod].
>> aContext restartWith: mDef method.
>> ^self breakOn: aContext label: self labelString.]
>>
>> As the debugger is capable of removing a breakpoint while a method is
>> running, i'd like to use this functionality.
>> I would like to remove the probe in the shown method because this is
>> right before the debugger opens and the #breakOn:label: never returns,
>> so I can't remove it afterwards in this method.
>>
>> In the method
>> DebugProbeInserter>>#adjustDynamicsReplacing:with:from:atPC:addProbe:origi
>> nalPCMap:
>> is a reference to 'debugger context supposedHome' and to 'debugger
>> topContext'. As I don't have a debugger open at this point, I donno what
>> the values of these contexts are. If I just assume that both values are
>> aContext from the above method, the method does not find the map-index
>> for a given pc in #findMapIndexFor:inMap:.
>>
>> Can someone please explain to me, what these values are supposed to be,
>> or if I'm doing something completely wrong.
>>
>> Thanks in advance
>> Karsten
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Temporary breakpoints

Runar Jordahl
Great to hear you got this working. I tried doing the same a while
ago. I wanted to use breakpoints as a quick way to test code coverage.
The idea was to (manually) add breakpoints to methods I had modified,
and then run the application. Afterwards, no breakpoints would exists
if all (modified) methods were executed:
http://www.cincomsmalltalk.com/userblogs/runarj/blogView?showComments=true&entry=3320316301

I used the condition below to have the breakpoint removed:
DOITCONTEXT method basicRemoveProbe: ThisProbe.
false

Sadly, as Terry points out, my method is not safe. It could crash the
image. I never had this problem, but I trust Terry's information.

Runar Jordahl

Reply | Threaded
Open this post in threaded view
|

RE: Temporary breakpoints

Terry Raymond
Runar

I have a code coverage tool that uses probes to record
the entrance and exit from each block in a method.
The inserting and removing the probes is done as an
install/deinstall by the user.

Terry
 
===========================================================
Terry Raymond       Smalltalk Professional Debug Package
Crafted Smalltalk
80 Lazywood Ln.
Tiverton, RI  02878
(401) 624-4517      [hidden email]
<http://www.craftedsmalltalk.com>
===========================================================

> -----Original Message-----
> From: Runar Jordahl [mailto:[hidden email]]
> Sent: Sunday, September 17, 2006 5:22 AM
> To: Karsten
> Cc: VWNC
> Subject: Re: Temporary breakpoints
>
> Great to hear you got this working. I tried doing the same a while
> ago. I wanted to use breakpoints as a quick way to test code coverage.
> The idea was to (manually) add breakpoints to methods I had modified,
> and then run the application. Afterwards, no breakpoints would exists
> if all (modified) methods were executed:
> http://www.cincomsmalltalk.com/userblogs/runarj/blogView?showComments=true
> &entry=3320316301
>
> I used the condition below to have the breakpoint removed:
> DOITCONTEXT method basicRemoveProbe: ThisProbe.
> false
>
> Sadly, as Terry points out, my method is not safe. It could crash the
> image. I never had this problem, but I trust Terry's information.
>
> Runar Jordahl