Code "disappeares" during runtime

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Ephreal
Posts: 28
Joined: Tue Jan 15, 2019 1:41 pm

Code "disappeares" during runtime

Post by Ephreal » Thu Mar 10, 2022 10:10 am

Hi

This is a bit odd problem. What I see is that FE a class with inheritance loses all the methods it inherits from initializing to when it is used. If I, however, move the initialization close to where it's used it works just fine.

I also see a list that is initialized during the __init__ phase and only, from what I can see read once, and when it read sometimes it is gone. it no longer registers as a list.

How do I debug this? I seem to me like code is getting overwritten during runtime.

Regards

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Code "disappeares" during runtime

Post by Roberthh » Thu Mar 10, 2022 10:37 am

Please tell us, which port and Version you use. If you have a short example which fails, please show that as well.

Ephreal
Posts: 28
Joined: Tue Jan 15, 2019 1:41 pm

Re: Code "disappeares" during runtime

Post by Ephreal » Thu Mar 10, 2022 10:43 am

It this one, I'm trying to start again

viewtopic.php?f=2&t=11795

Just move over here because I think it belongs here.


I do not have a small code that fails, since I can't get my code to fail unless I run their entire application. If I just run that code part it works just fine.

that is why I would like to know who to debug the C code.

Where do I find a version number.? It's a custom port it runs on a NIOS II software core processor.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Code "disappeares" during runtime

Post by Roberthh » Thu Mar 10, 2022 10:56 am

version number by ctrl-b in REPL or uos.uname().

Ephreal
Posts: 28
Joined: Tue Jan 15, 2019 1:41 pm

Re: Code "disappeares" during runtime

Post by Ephreal » Thu Mar 10, 2022 11:45 am

Roberthh wrote:
Thu Mar 10, 2022 10:56 am
version number by ctrl-b in REPL or uos.uname().
MicroPython 5616a9e3-dirty on 2022-03-10;

I do not think this is correct because we have not updated our micropython SDK this year. I think the last time was January 2021.

Ephreal
Posts: 28
Joined: Tue Jan 15, 2019 1:41 pm

Re: Code "disappeares" during runtime

Post by Ephreal » Thu Mar 10, 2022 1:23 pm

Hi

I've made some debugging on my missing List variable.

The list is created in the __init__ method

Code: Select all

self.gen_io_vic_int = [0x00000020, 0x00000040, 0x00000080, 0x00000100, 0x00000200,
                       0x00002000, 0x00004000, 0x00008000, 0x00010000, 0x00020000
And later used in a class function:

Code: Select all

for mask in reversed(self.gen_io_vic_int):
     ....
I have around this code made an try/exception handler which triggers on TypeError

Code: Select all

try:
    for mask in reversed(self.gen_io_vic_int):
        if vic_int & mask:
            gen_io_int = (gen_io_int << 1) | 1
        else:
            gen_io_int = gen_io_int << 1
except TypeError as te:
    print(te)
    print(type(self.gen_io_vic_int))
    print(self.gen_io_vic_int)
    print(self.__dict__)
    raise te
The printouts when the exception is triggered are following:

print(te) -> "object of type '' has no len()"
print(type(self.gen_io_vic_int)) -> "(nil)"
print(self.gen_io_vic_int) -> "<>"

print(self.__dict__) -> {........, 'gen_io_vic_int': <>, ......... }

As I can see the variable is still in the __dict__. but something has happened to it.

I know I could just move the constant values to the method and this might fix the problem. but I'm interested in the underlying cause since I have other similar problems

Regards

Ephreal
Posts: 28
Joined: Tue Jan 15, 2019 1:41 pm

Re: Code "disappeares" during runtime

Post by Ephreal » Thu Mar 10, 2022 7:49 pm

I can also see that one list out of two also gets messed up.

In the __init__ method I have the following code.

Code: Select all

        
        self._int_status_offset = list()
        for offset in range(256, 256 + 32 * 16, 16):
            self._int_status_offset.append(offset)
        self._int_setup_offset = list()
        for offset in range(1280, 1280 + 32 * 16, 16):
            self._int_setup_offset.append(offset)
When I get the exception I print out the entire __dict__
and the two lists looks as following

Code: Select all

    
'_int_status_offset': [256, 272, 288, 304, 320, 336, 352, 368, 384, 400, 416, 432, 448, 464, 480, 496, 512, 528, 544, 560, 576, 592, 608, 624, 640, 656, 672, 688, 704, 720, 736, 752],

the first one is correct however the other looks like

Code: Select all

'_int_setup_offset': [(nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil), (nil)],

but should have looked like this

Code: Select all

'_int_setup_offset': [1280, 1296, 1312, 1328, 1344, 1360, 1376, 1392, 1408, 1424, 1440, 1456, 1472, 1488, 1504, 1520, 1536, 1552, 1568, 1584, 1600, 1616, 1632, 1648, 1664, 1680, 1696, 1712, 1728, 1744, 1760, 1776],


I looks more and more like some data is getting overwritten I just do not know how.

Ephreal
Posts: 28
Joined: Tue Jan 15, 2019 1:41 pm

Re: Code "disappeares" during runtime

Post by Ephreal » Mon Mar 14, 2022 6:11 pm

So I tried making the class a singleton. and this somehow worked. It's not a memory problem because only 20% of memory is used at the point in time.

It would really be helpful with some insight. or an idea on how to debug this issue.

Regards

Post Reply