How do i find out the line number of a bug

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

How do i find out the line number of a bug

Post by rhubarbdog » Sat Apr 07, 2018 5:09 am

When developing new micro python how do you debug it.
When a program crashes how do you find the line number and exception code?

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: How do i find out the line number of a bug

Post by stijn » Sat Apr 07, 2018 7:25 am

There is no debugger.

If the program crashes (as in segfaults) then you remove code until it doesn't crash anymore, then add code one by one. And report a bug on github.com/micropython because it's not supposed to crash.

If the program terminates because of an unhandled exception, that gets printed e.g. on the command line including stack trace with files and line numbers.

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

Re: How do i find out the line number of a bug

Post by rhubarbdog » Sat Apr 07, 2018 7:30 am

I'm getting nothing just a pyboard with no led on or flashing. Nothing is being passed back up the usb or at least linux handles it without printing the text in a terminal.

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: How do i find out the line number of a bug

Post by stijn » Sat Apr 07, 2018 10:08 am

No experience with pyboard, did you look in the 'pyboard is dead' and other threads on the forum for hints?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How do i find out the line number of a bug

Post by pythoncoder » Sun Apr 08, 2018 6:48 am

@rhubarbdog It would help if you could explain exactly what you are doing. You mention Linux: what program are you using to connect to the Pyboard and how are you invoking it? Are you seeing a REPL prompt? If so, does a one-line program work?

Code: Select all

>>> print('Hello')
Hello
>>> 
If you're not getting a REPL prompt have you checked your USB cable?
Peter Hinch
Index to my micropython libraries.

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

Re: How do i find out the line number of a bug

Post by rhubarbdog » Sun Apr 08, 2018 6:59 am

Doing some further searching accross the internet. I've found the following putting your main loop into a function called 'main' put you program into a file called 'something.py' (never main.py or boot.py).
From a repl prompt type the following [/code]import something
something.main() [/code]

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How do i find out the line number of a bug

Post by pythoncoder » Sun Apr 08, 2018 7:09 am

That's correct. Once your program is debugged, if you want it to run automatically at power up, you make main.py read:

Code: Select all

import my_module
my_module.main()
To go back to debugging the program you can simply replace main.py with a version with those lines deleted or commented out.
Peter Hinch
Index to my micropython libraries.

Post Reply