This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

After memory writing, C code not working with that data

Hi

I have  a simple C function,say  -

{int a;

a++;

b=a+10;

}

Through the scripting console, I am giving a new value to the memory location of a in each iteration of a for loop - and then I am debugging it and executing it.

The problem is - after the end of execution, I can see the value of a is the same as that written into the memory location ( I checked this through the Expression window). However, a++ and b=a+10; are not working with the data. b shows a value of 0 at the end. I tried including a breakpoint and giving a pause of 10 seconds after the memory was written into - but it had no effect. Can anybody please explain where I am going wrong?

This is a snippet of what I am doing while reading and writing from the C code -

var firstBP = debugSession.breakpoint.add("main.c", 5); //inserts breakpoint at  line "int a "
                        print("Breakpoint added");
             var a = debugSession.symbol.getAddress("a");
             if (!debugSession.target.isHalted())
                {
                       debugSession.target.halt();
                        }
            debugSession.memory.writeData(0,a,t[j], 32);
            insert_pause(10000);

            debugSession.target.restart();
            
            var secondBP = debugSession.breakpoint.add("main.c", 8); //inserts breakpoint AFTER the line b=a+10
            insert_pause(5000);
            var b = debugSession.symbol.getAddress("b");
            debugSession.target.restart();

               var result = debugSession.memory.readData(Memory.Page.PROGRAM,b, 32, false)
               debugSession.terminate();

  • Hi,

    Sohini Chatterjee said:

    {int a;

    a++;

    b=a+10;

    }

    How is "b" declared? Is this a global variable?

    If b is passed as a parameter to the function, keep in mind that both "a" and "b" will be allocated to registers (they are local variables), therefore the script commands debugSession.symbol.getAddress("a"); and debugSession.symbol.getAddress("b"); will probably return some invalid value as registers do not have addresses.

    If "a" and "b" are globals allocated to memory (use the volatile keyword to guarantee they are not optimized out), then these commands would be probably return correct values.

    Cheers,

    Rafael