Debugging: Stop program if variable = value ?

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
User avatar
fox73
Posts: 7
Joined: Tuesday 9th February 2021 1:27am

Debugging: Stop program if variable = value ?

Post by fox73 »

Hello out there.
I am a newbie to Gambas and try to find out, if the following is possible:

While debugging, I want the program to stop/break if variable xy has a determined value.
Can you do that with the Gambas IDE?

Thanks a lot.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Debugging: Stop program if variable = value ?

Post by cogier »

Just put a Stop in the code where you want it to stop and then highlight the variable to see its value.
Public Sub Form_Open()

  Dim sDir As String[] = Dir(User.Home &/ "Pictures")

  Stop

End
Image
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Debugging: Stop program if variable = value ?

Post by stevedee »

fox73 wrote: Tuesday 27th April 2021 2:30pm ...While debugging, I want the program to stop/break if variable xy has a determined value.
Can you do that with the Gambas IDE?
That's a great question.
It doesn't look like this feature is included in Gambas breakpoint options.

I did find that if you run code until it stops at a line breakpoint, the breakpoint window changes, and you get an "Add Expression" option via an eye-ball icon.
But I can't see how to use this.
GambasAddExpression.png
GambasAddExpression.png (73.84 KiB) Viewed 11114 times
Breaking on a variable value would be a valuable inclusion to the Gambas IDE. Its far more useful in some situations than a line breakpoint.

For example in this code, it would be great to be able to break when (say) x = 2000:-
  For x = 0 To 10000
    'do stuff
  Next
01McAc
Posts: 75
Joined: Sunday 24th January 2021 8:25pm

Re: Debugging: Stop program if variable = value ?

Post by 01McAc »

I suppose a
if x=0 then stop
will do the trick.
User avatar
fox73
Posts: 7
Joined: Tuesday 9th February 2021 1:27am

Re: Debugging: Stop program if variable = value ?

Post by fox73 »

Hello cogier,
thanks for your reply. I know the possibility to place a break on a line and then display the value by clicking on the variable.
But this "hard break" is not, what I am looking for.

I am looking for a "smart break" that stops at the line, where an determined condition is reached, without knowing in advance at what line of the code.
It's as stevedee wrote in his example.I know this feature from tibe IBM z/OS mainframe tool DEBUG and it would be great to have it in Gambas, too :-)
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Debugging: Stop program if variable = value ?

Post by stevedee »

01McAc wrote: Tuesday 27th April 2021 4:30pm I suppose a
if x=0 then stop
will do the trick.
Yes, that's the kind of workaround I would use, but I'm beginning to suspect there are existing features (which are pretty standard in other languages IDEs) that I either don't know how to enable or maybe they are broken.

For example there is both an Add Expression and an Add Watches button that I can't figure out.

I've only just discovered that after you stop program execution, you can then change the current value of variables...that's handy!

That is why I said fox73's question was a good one...its got me thinking about things I've taken for granted for years.
01McAc
Posts: 75
Joined: Sunday 24th January 2021 8:25pm

Re: Debugging: Stop program if variable = value ?

Post by 01McAc »

stevedee wrote: Tuesday 27th April 2021 4:46pm I've only just discovered that after you stop program execution, you can then change the current value of variables...that's handy!
Sounds interesting, I didn't know this. VB is able to change values in debug mode - but Gambas? How would you do this?
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Debugging: Stop program if variable = value ?

Post by stevedee »

01McAc wrote: Tuesday 27th April 2021 5:21pm ...VB is able to change values in debug mode - but Gambas? How would you do this?
Pause execution using a line breakpoint, then double click on the variable's value in the Local variable list and type the new value.
GambasChangeVar.png
GambasChangeVar.png (32.29 KiB) Viewed 11105 times
Yes, VB6 was great for debugging; you could pause execution, drag the execution point back a few lines, and then get it to re-execute the lines again!
ak2766
Posts: 7
Joined: Sunday 3rd April 2022 4:59am
Location: Melbourne, Australia

Re: Debugging: Stop program if variable = value ?

Post by ak2766 »

What you are looking for is called a conditional breakpoint. I see it's in the TODO list in the Gitlab repo page:
https://gitlab.com/gambas/gambas/-/blob ... 7f29b/TODO - line 36 as off right now.

Hopefully that'll be implemented soon(ish).
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: Debugging: Stop program if variable = value ?

Post by thatbruce »

Dont hold your breath. It's been there for some years now.
But it would be nice. :roll:
Have you ever noticed that software is never advertised using the adjective "spreadable".
Post Reply