Topic : Local variables watch in simulator.

Forum : ST7/STM8

Original Post
Post Information Post
March 13, 2007 - 6:42pm
Guest

Hi all.

Im trying to debug this so-big application for the STLITE39 MCU using the simulator:

void main ()
{
   int i;
   
   while (1)
   {
      int a;
      
      a = 0;
      a++;

      i = 0;
      i++;
   }
}

In the watch window i can see how variable i goes from 0 to 1, but there is no row for row a and i cant include it. I can change "i" to "a" in the "i" row from the watch window so i can trace variable "a" but i think both variables must appear once they are defined, isnt it?

There is the same problem with Conv_Data1 and array_Val_Gauge in RBuilds ADC example application:

void main ( void ) {
   
   /* Configure the internal peripherals */
   PeriphInit();


   while ( 1 ){
      {
      
         /* * * * Sample code for the ADC * * *
         This code works with the REva evaluation board. It performs the following:
            a. Measurement of the voltage set by the potentiometer
            b. Translation to a value that fits into the range [0,7] 
            c. Copy of the resulting value to the Port A (LEDs as a gauge). */
         int Conv_Data1;
         const char array_Val_Gauge [8] = {0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00};
         
         ADC_Select_Channel(1);                    /* Select channel 1  */
         ADC_Enable();                             /* Start conversion ADON bit is set */
         while ( !ADC_Test_Conversn_Complete() ) ; /* Wait till conversion completes */
         Conv_Data1 = ADC_Conversn_Read();         /* Read converted value */
         if ( !Conv_Data1 ) {
            IO_ByteWrite(IO_PORT_A, 0xff);         /* Write Port A: all LEDs switched off */
         }
         else {
            Conv_Data1 >>= 7;                    /* Keep the 3 Most Significant Bits */
            IO_ByteWrite(IO_PORT_A, array_Val_Gauge[Conv_Data1]);   /* Write Port A */
         }
         ADC_Disable();
      }
      
      
      /* Insert your code here... */

   }
}/* end of main */

Im using BN746_P1_P2 version. I think i have seen this problem in other posts, but i havent found an answer.

Thanks in advance.

Jorge MC

Replies
Post Information Post
+1
0
-1
March 14, 2007 - 3:35pm
Guest

Hello,

it seems to work perfectly here. See these screenshots:

did you try to right-click in the watch window and select "Add" ?

regards,
Lionel

+1
0
-1
March 14, 2007 - 4:03pm
Raisonance Support Team

Hi,

The local variables in such simple codes are most of the time optimized out. And then they don't physically exist anymore and therefore you cannot watch them. Look at the disassembly to check that.

Now, whether or not it is optimized out depends on a lot of things, including the compiler you are using (RCST7, CXST7, etc.) and the options you give it. (mostly the optimization options, but not only) This is probably why Lionel sees them and Jorgem doesn't.

Now, if you really want to watch them, you have several solutions:

1. Disable optimization in the compiler options.
This will slow down your code a lot but should allow to watch all variables.

2. Declare the variable(s) you want to watch as volatile.
This will slow down your code a little (the parts that use this variable) and will allow you to watch the variable that you declared as volatile.

3. Look at the disassembly and try to understand where your variable goes and maybe you'll be able to find out how it's handled.
This doesn't work all the time and only if you know the assembler quite well, but it doesn't require you to change your code.

Best Regards,

Vincent

+1
0
-1
March 14, 2007 - 8:55pm
Guest

Hi again.

This is the listing file from my example:

RC-ST7 COMPILER V1.00.00, EJEMPLO 03/14/07 20:42:40

QCW(0x0000BF00)

RC-ST7 COMPILER V1.00.00, COMPILATION OF MODULE EJEMPLO
OBJECT MODULE PLACED IN c:\ride\proyectos\st7lite39f2\ejemplo\ejemplo.obj
COMPILER INVOKED BY: OBJECT("C:\RIDE\PROYECTOS\ST7LITE39F2\EJEMPLO\EJEMPLO.OBJ") PIN(C:\RIDE\INC;C:\RIDE\INC\ST7) CODE DEBUG ST7 DGC(DATA) DLC(PAGE0) GENDEP IP NOIS SIGNEDCHAR LARGEOBJECT ET(CHAR) OT(7,SIZE) DB PR(C:\RIDE\PROYECTOS\ST7LITE39F2\EJEMPLO\EJEMPLO.LST) CD QUIET

stmt level source
1 void main ()
2 {
3 1 int i;
4 1
5 1 while (1)
6 1 {
7 2 int a;
8 2
9 2 a = 0;
10 2 a++;
11 2
12 2 i = 0;
13 2 i++;
14 2 }
15 1 }
16
17

ASSEMBLY LISTING OF GENERATED OBJECT CODE

; FUNCTION main (BEGIN)
; BX is assigned to i
0000 ?WHILE_0001:
; CX is assigned to a
; SOURCE LINE # 9
0000 3F05 F CLR ?CH
0002 3F06 F CLR ?CL
; SOURCE LINE # 10
0004 CD0000 F CALL ?C?inc_cx
; SOURCE LINE # 12
0007 3F03 F CLR ?BH
0009 3F04 F CLR ?BL
; SOURCE LINE # 13
000B CD0000 F CALL ?C?inc_bx
; a short (size=2-Alg). Automatic variable in DATA0
000E 20F0 JRA ?WHILE_0001
; i short (size=2-Alg). Automatic variable in DATA0

; FUNCTION main (END)

Lionel and Vincent, you are right. I can add ?BL and ?CL into my watch window as global variables so i can see how they go from 0 to 1 and again, and again... :P. The only point is that "a" and "i" variables are defined in the same way but "i" can be watched as local and "a" cant. Its not a very important thing, but i wonder why.

Thanks a lot.

Jorge.