How would you do the following. 
Author Message
 How would you do the following.

Basically I want to track the number of times that a line is
encountered before the program crashes.

Then I want to set a breakpoint that gets triggered when that
line is called that same number.

So in C++:

void foo()
{
    do_some_stuff();
    static count=0;
    count++;
   so_some_more_stuff();

Quote:
}

run once. Then check what the final value of count is before the
crash.

Recompile with:
void foo()
{
    do_some_stuff();
    static count=0;
    if(count==measured_count)
        halt;
   so_some_more_stuff();

Quote:
}

Obviously halt is not a C++ call but you get the point.
I am having a hard time doing this in ST.
Can anyone make suggestions?


Sat, 05 Feb 2005 14:04:08 GMT  
 How would you do the following.
Thaddeus,

Your recompiled version probably needs a count++;.

One way to do this in Smalltalk is to make a class Counter with a singleton
instance that does the counting and halting. foo could look like this:

foo

        self do_some_stuff.
        Counter increment.
        self do_some_more_stuff.

Counter has a class variable Current and an instance variable count.

Counter class>>increment

        self current increment.

Counter class>>current

        ^Current notNil ifTrue: [
                Current.
        ] ifFalse: [
                Current := self new.
        ].

Counter>>initialize

        super initialize.
        count := 0.
        ^self.

Counter>>increment

        count := count + 1.
        "For the recompiled version."
        count = measured_count ifTrue: [
                self halt.
        ].      

Be sure that initialize is called on Counter class>>new because that is not
necessarily the case.  The usual disclaimers apply, especially since this is
a quick and dirty solution that I have not even tried for real.

Keith Alcock

P.S. I hope this isn't for a class.

Quote:

> Basically I want to track the number of times that a line is
> encountered before the program crashes.

> Then I want to set a breakpoint that gets triggered when that
> line is called that same number.

> So in C++:

> void foo()
> {
>     do_some_stuff();
>     static count=0;
>     count++;
>    so_some_more_stuff();
> }

> run once. Then check what the final value of count is before the
> crash.

> Recompile with:
> void foo()
> {
>     do_some_stuff();
>     static count=0;
>     if(count==measured_count)
>         halt;
>    so_some_more_stuff();
> }

> Obviously halt is not a C++ call but you get the point.
> I am having a hard time doing this in ST.
> Can anyone make suggestions?



Sat, 05 Feb 2005 14:49:51 GMT  
 How would you do the following.

Quote:

> Basically I want to track the number of times that a line is
> encountered before the program crashes.

> Then I want to set a breakpoint that gets triggered when that
> line is called that same number.

> So in C++:

> void foo()
> {
>     do_some_stuff();
>     static count=0;
>     count++;
>    so_some_more_stuff();
> }

> run once. Then check what the final value of count is before the
> crash.

> Recompile with:
> void foo()
> {
>     do_some_stuff();
>     static count=0;
>     if(count==measured_count)
>    halt;
>    so_some_more_stuff();
> }

> Obviously halt is not a C++ call but you get the point.
> I am having a hard time doing this in ST.
> Can anyone make suggestions?

YourClass>>foo
        self doSomeStuff.
        Counter := (Counter ifNil: [0]) + 1.
        Counter >= 12 ifTrue: [self halt].
        self doSomeMoreStuff

When accepting the method it will prompt you for what Counter should be.
Probably a global in this case, since it's just to debug something it
sounds like.

I think you could actually do this with PDP (the upcoming VW de{*filter*})
without changing any code. Terry?

--
Travis Griggs
Key Technology
10 2 letter words: "If it is to be it is up to me"



Sun, 06 Feb 2005 00:21:42 GMT  
 How would you do the following.

Quote:

>> Basically I want to track the number of times that a line is
>> encountered before the program crashes.

>> Then I want to set a breakpoint that gets triggered when that
>> line is called that same number.

>> So in C++:

>> void foo()
>> {
>>     do_some_stuff();
>>     static count=0; count++; so_some_more_stuff(); }

>> run once. Then check what the final value of count is before the
>> crash.

>> Recompile with:
>> void foo()
>> {
>>     do_some_stuff();
>>     static count=0; if(count==measured_count)
>>      halt;
>>    so_some_more_stuff(); }

>> Obviously halt is not a C++ call but you get the point.
>> I am having a hard time doing this in ST.
>> Can anyone make suggestions?

> YourClass>>foo
>      self doSomeStuff.
>      Counter := (Counter ifNil: [0]) + 1.
>      Counter >= 12 ifTrue: [self halt].
>      self doSomeMoreStuff

> When accepting the method it will prompt you for what Counter should be.
> Probably a global in this case, since it's just to debug something it
> sounds like.

> I think you could actually do this with PDP (the upcoming VW de{*filter*})
> without changing any code. Terry?

As long as Counter is used only for debugging you
can do it all in the probes.  The counter could
be a local probe variable or it could be a global
debug variable that is shared between probes.

In the above example it looks like it could all be
done with one probe.

--
Terry
===========================================================
Terry Raymond       Smalltalk Professional Debug Package
Crafted Smalltalk   *Breakpoints* and *Watchpoints* for
80 Lazywood Ln.                  VW and ENVY/Developer
Tiverton, RI  02878

http://www.*-*-*.com/
===========================================================



Sun, 06 Feb 2005 00:32:36 GMT  
 How would you do the following.
if you're just trying to debug something, you could setup a temporary
global variable for DebugCount in the Smalltalk dictionary...
and then zero, increment, test DebugCount as needed in your code

(and use self halt for the breakpoint?)



Sun, 06 Feb 2005 00:44:16 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Doing assembly and really doing assembly

2. Doing assembly and really doing assembly

3. Cross posting well done --> Cross post with follow-up!

4. "White pages" follow-up

5. follow-up for RFD: Comp.os.tpf Moderated.

6. Sports related web site , presentation moved to following week

7. not quite a follow up on `style'.

8. cut leading and/or following blanks

9. Replace character if not followed by?

10. Follow-up to VW UI Thread-Safeness..

11. delete 1 followed by 3 lines

12. Following lines...

 

 
Powered by phpBB® Forum Software