Home > Net >  VS code conditional breakpoint does not work (python, platformio)
VS code conditional breakpoint does not work (python, platformio)

Time:03-16

I tried to add conditional break point in platformio (nrf51DK arduino) where I had some problems. To check what is wrong I wrote a simple python script. I have installed python, pylance. My python version is 3.9.9.

I wrote simple code:

a=1
a =1
a =1
a =1
a =1
a =1
a =1
a =1
a =1
a =1
a =1
a =1
a =1
a =1
a =1
print(a)

view from debbuging

I tried to add many conditional break-point similarly to tutorial from web. To my script I add e.g. "a>9". I understand this like "when variable a will be greater than 9 program should stop". But nothing was happening.

I also tried to install vs code insiders and there was the same situation. And in platformio the same. Previously I used keil for nrf board where conditional break-point like that works for me.

Now I think that I missed sth but spend time to check without success. I put python easiest example to show what is the nature of problem and because I can't find simple example.

To be pricise. I need to specify condition for example some variable change, or be greater than sth and when it hapenned program sholud stop on line where it was made. It is possible in VScode?

CodePudding user response:

You understand the use of the breakpoint incorrectly。 If the breakpoint condition is true, the program will be interrupted. The value of a at the conditional breakpoint you added is 3. If a > 9 is not met, the execution will continue. You can try to add a conditional breakpoint on the tenth line below. Then the program will break.

CodePudding user response:

Usually, we code like this:

def aaa():
    a = 0
    for i in range(50):
        a  = 1
    print(a)


if __name__ == "__main__":
    aaa()

Then add a condition breakpoint at the line of a =1.

In the example you have provided, you can add the condition breakpoint at each line of a =1. But usually, we will not meet too many lines which contain the same variable. If you meet, you just need to add some more condition breakpoints.

  • Related