Address exception on array of byte - mP 7.0.1

General discussion on mikroPascal PRO for dsPIC30/33 and PIC24.
Author
Message
VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Re: Address exception on array of byte - mP 7.0.1

#16 Post by VCC » 04 Jun 2020 07:03

Hi Dany,
Dany wrote:
03 Jun 2020 18:52
Not only byte size variables tend to be 'misaligned' but also arrays of byte. This sounds logical as long as the bytes in the array are approached as single bytes of course. So, from the compiler's point of view byte (arrays) do not have to be aligned.
If approached as word or Dword things can go wrong of course.
Those are the arrays I'm looking for. :) I'm not saying that misalignment is a bad thing, I just want to know where should I take extra care of using arrays of byte, used as array of Word/DWord. Probably I'll leave arrays of byte to be reported as misaligned, especially for this matter.
Dany wrote:Above is an exerpt of a Pic32 project listfile. However no variables were shown in the Check for Mis alignment tool (generated report from the tool)
Are those variables added in the "Notify on these identifiers" list?

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Address exception on array of byte - mP 7.0.1

#17 Post by Dany » 04 Jun 2020 18:29

VCC wrote:
04 Jun 2020 07:03
Hi Dany,
Are those variables added in the "Notify on these identifiers" list?
No, both lists 'All available variables' and (of course) 'Notify on these identifiers' are empty.
In other PIC32 projects the identifiers are shown in the first list. I do not know why this one is empty for this project.

Additional: I have also a similar PIC18 test project that behaves similar in the tool.

This is the project code:

Code: Select all

program Word_Alignment;

{ Declarations section }

Type TArr = Array[5] of byte;
     TArr2 = array[10] of byte;
     Tarr3 = array[3] of word;
     TArr4 = array[3] of Dword;

Type Trec = record
    Byte1: byte;
    Word1: word;
    Byte2: byte;
    Dword1: dword;
    Byte3: byte;
    Arr1: TArr;
    Byte4: byte;
    Arr2: Tarr2;
    //Byte5: byte;
    Arr3: TArr3;
    Byte6: byte;
    Arr4: TArr4;
    end;
    
Type Trec2 = record
    Dword1: dword;
     Word1: word;
     Arr1: TArr;
    Byte1: byte;
    Byte2: byte;
    Byte3: byte;
    end;

var MyRec: TRec;
MyRec2: TRec2;
    Siz, Siz2: byte;

begin
  { Main program }
  Siz := SizeOf(MyRec);
  Siz2 := SizeOf(Myrec2);
  Myrec.Byte1 := 0;
end.
And this is the config file:

Code: Select all

<?xml version="1.0"?>
<MCU_DEVICE_FLAGS>
  <DEVICE>
    <DEVICE_NAME>P32MX250F128B</DEVICE_NAME>
    <VALUE>
      <COUNT>4</COUNT>
      <VALUE0>
        <VAL>$1FC00BF0:$F0000000</VAL>
      </VALUE0>
      <VALUE1>
        <VAL>$1FC00BF4:$8751</VAL>
      </VALUE1>
      <VALUE2>
        <VAL>$1FC00BF8:$3D4C5A3</VAL>
      </VALUE2>
      <VALUE3>
        <VAL>$1FC00BFC:$1100FC1F</VAL>
      </VALUE3>
    </VALUE>
  </DEVICE>
</MCU_DEVICE_FLAGS>
Last edited by Dany on 04 Jun 2020 18:48, edited 1 time in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Address exception on array of byte - mP 7.0.1

#18 Post by Dany » 04 Jun 2020 18:35

VCC wrote:
04 Jun 2020 07:03
Hi Dany,
Those are the arrays I'm looking for. :) I'm not saying that misalignment is a bad thing, I just want to know where should I take extra care of using arrays of byte, used as array of Word/DWord. Probably I'll leave arrays of byte to be reported as misaligned, especially for this matter.
Ok, you are right. :D
Of course in PIC32 also words and word arrays can give problems if approached as Dwords. This is also a risk I think.

An extra remark: when hovering over one of the 'File Path's the message 'Loaded list from:' plus the name of the tool's .ini file appears. Is that on purpose?
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Re: Address exception on array of byte - mP 7.0.1

#19 Post by VCC » 05 Jun 2020 09:13

It is possible that you are encountering one of the "limitations" of the tool, i.e. it doesn't report all identifiers by default. Probably more of a feature than a limitation :) .
You have two options here: either open the settings dialog and check the "Report on all misaligned identifiers, not only on manually added ones" checkbox, or from the main window, manually add the desired identifiers, by selecting them in the "All available identifiers" list and clicking on "Notify On Selected Identifiers" button.
Once you have a few identifiers in the "Notify on these identifiers" list, you can test the report by selecting the lst file in the first list, and from its popup menu, select "Generate report".
The same report should be generated if the application is started from command line with the desired lst file.

Please confirm all the above, so I don't have to start a bug hunt. Thank you :D

VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Re: Address exception on array of byte - mP 7.0.1

#20 Post by VCC » 05 Jun 2020 09:21

Dany wrote:
04 Jun 2020 18:35
An extra remark: when hovering over one of the 'File Path's the message 'Loaded list from:' plus the name of the tool's .ini file appears. Is that on purpose?
Yes, it is on purpose, because you can have custom lists of lst files, so the application displays what was the list it started with. If you want to pass a custom ini as command line, make sure you have a backup of these ini files, in case something goes wrong and the application overwrites the wrong ini file. Also see chapter 3 of the documentation, for the order of arguments.
:)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Address exception on array of byte - mP 7.0.1

#21 Post by Dany » 05 Jun 2020 13:31

VCC wrote:
05 Jun 2020 09:13
It is possible that you are encountering one of the "limitations" of the tool, i.e. it doesn't report all identifiers by default. Probably more of a feature than a limitation :) .
You have two options here: either open the settings dialog and check the "Report on all misaligned identifiers, not only on manually added ones" checkbox, or from the main window, manually add the desired identifiers, by selecting them in the "All available identifiers" list and clicking on "Notify On Selected Identifiers" button.
Once you have a few identifiers in the "Notify on these identifiers" list, you can test the report by selecting the lst file in the first list, and from its popup menu, select "Generate report".
The same report should be generated if the application is started from command line with the desired lst file.

Please confirm all the above, so I don't have to start a bug hunt. Thank you :D
Found the reason why for some projects no variables/constants were shown in the 'All' list:
they lack the constants definition in their list file (so no constants defined):
//** Constants locations **
//ADDRESS SIZE CONSTANT
Last edited by Dany on 06 Jun 2020 10:32, edited 2 times in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Re: Address exception on array of byte - mP 7.0.1

#22 Post by VCC » 05 Jun 2020 14:56

Dany wrote:
05 Jun 2020 13:31
Found the reason why for some projects no varaibels/constants were shown in the 'All' list:
they lack the constants definition in their list file (no no constants defined):
//** Constants locations **
//ADDRESS SIZE CONSTANT
Those lines are a marker, which is required by the tool, to find the section with constants. I hope everything else works fine.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Address exception on array of byte - mP 7.0.1

#23 Post by Dany » 05 Jun 2020 17:14

VCC wrote:
05 Jun 2020 14:56
Dany wrote:
05 Jun 2020 13:31
Found the reason why for some projects no varaibels/constants were shown in the 'All' list:
they lack the constants definition in their list file (no no constants defined):
//** Constants locations **
//ADDRESS SIZE CONSTANT
Those lines are a marker, which is required by the tool, to find the section with constants. I hope everything else works fine.
Hi Vcc, also the variables are not shown in the 'all' list if the 'constants locations' is not present.That is the problem.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Re: Address exception on array of byte - mP 7.0.1

#24 Post by VCC » 05 Jun 2020 18:54

Thank you for reporting this. There is a new version on Libstock, which should be able to parse now, lst files without one of the two sections (vars or consts).
The old parser was indeed looking for consts section to know where the vars section ends (I wasn't expecting lst files without one section). Since there was no const section, there was no end of vars, so no valid list of vars could be obtained. That is what happened. The latest parser may be a bit slower, but it should be fine. :)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Address exception on array of byte - mP 7.0.1

#25 Post by Dany » 06 Jun 2020 10:25

VCC wrote:
05 Jun 2020 18:54
Thank you for reporting this. There is a new version on Libstock, which should be able to parse now, lst files without one of the two sections (vars or consts).
The old parser was indeed looking for consts section to know where the vars section ends (I wasn't expecting lst files without one section). Since there was no const section, there was no end of vars, so no valid list of vars could be obtained. That is what happened. The latest parser may be a bit slower, but it should be fine. :)
Excellent. Thanks very much! This is a very usefull tool. :D
Any indication from mikroE if there is some kind of solution to minimize these misaligning risks in the future? (e.g. a warning or a compiler switch or ...)
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Address exception on array of byte - mP 7.0.1

#26 Post by Dany » 13 Jun 2021 19:46

Hi, I have added another alignment example in my small article on libstock: https://libstock.mikroe.com/projects/vi ... and-pic32.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Re: Address exception on array of byte - mP 7.0.1

#27 Post by VCC » 18 Jun 2021 12:47

Dany wrote:
13 Jun 2021 19:46
Hi, I have added another alignment example in my small article on libstock: https://libstock.mikroe.com/projects/vi ... and-pic32.
Thank you :D

Post Reply

Return to “mikroPascal PRO for dsPIC30/33 and PIC24 General”