Alter the program counter via Studio 7 GUI

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a fault code where my micro jumps when something, well, fault.

It's a non exiting function, at the end of it there is a while (1) to just refresh the watchdog.

At the beginning of the function I read the stack to save the calling address of the fault function and in the function I just have a serial line to communicate with the PC to acquire the calling program counter which caused the fault.

While I was using the Studio 4 I used to just break, read the progem counter, write the number in the program counter in the Processor status window and press enter and the code jump to the caller of fault.

I tried to do the same in Studio 7 and the program counter changes, but the code won't, so it's really difficult to know where the program was before calling the fault function.

Any idea?

Last Edited: Tue. Apr 19, 2016 - 09:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so it's really difficult to know where the program was before calling the fault function.

Any idea?

Is the return address not on the stack?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, of course.

As I wrote at the beginning of the function I read the stack to save the calling address of the fault function:

typedef union
{
   ulong long_data;
   uchar byte[4];
} long_char;

void fault(void)
{
long_char calling_address;
uchar *p;

p = (uchar *)CPU.SP;
p += 1;
calling_address.byte[3] = 0;
calling_address.byte[2] = *p++;
calling_address.byte[1] = *p++;
calling_address.byte[0] = *p;
calling_address.long_data -= 2;

---SNIP---
}

Then I pause the debugger and I want to jump to the code where the fault function was called.

In Studio 4 I just write the program counter by hand with the value read from the stack and the GUI will jump to the correct file. In Studio 7 it doesn't work ando I don't know how to do that.

Any idea?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Set a breakpoint at the point of call and restart the debugging session?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that the program counter actually updates, but you need to issue 1 Step before the GUI follows...

 

It should also be possible to use the call stack window to jump back and forth in the stack....

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@meolsen: I tried to issue 1 step, but it doesn't work.

I don't uderstand what you mean with jump back in the stack.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Where are you setting the program counter? I just went into the processor status, wrote a new PC value, and did 1 step, The current line then jumped away onto the correct line (+1 instruction for the Step)

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wrote the PC in the processor status window.

The new PC you wrote points to a piece of code in the same file you have already opened?

Can you please try to write a PC that points to a file in the same project, but not open and see if the GUI opens the file and displays it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Aside: I sort of cringe by the thought of setting the PC to a location outside of "the current stack frame context". Will the stack pointer be moved so that it points at the correct stack frame?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't care.

My fault function is a non exiting function and the firmware loops indefinitey in it. The only way to exit from fault is by switching off the equipment.

I need a way to check the caller in debug post mortem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

effemmeffe wrote:
I need a way to check the caller in debug post mortem.

Do you need to re-execute code before the call, or are you content with analyzing variable values at the point of call?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just need to know where in the code the function was called.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

effemmeffe wrote:
I just need to know where in the code the function was called.

THen just place a breakpoint in the error function, and then "walk the stack". The complete stack is available to be "walked" in a debug session in Studio. Just double-click on entries in the call stack window to see where in the code that call was done.

 

I did a quick test to verify that this functionality is supported by AS7. It is - you will be able to investigate the complete call chain, all the way from main() to the point of failure. (Unfortunately it does not handle the automatic / local variables panes correctly - looks like the old problem with register-allocated variables.)

 

Let me know if I should mock up a small demo with screen shots showing how this works.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow, that would be a huge feature, I wasn't aware of that, thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Most any IDE (MS Visual Studio for C#, VB.NET, C++. Eclipse. NetBeans. I would be surprised if Code::Blocks didn't also support it.)

 

I'll think a small demo/tutorial through, compose and post soon (tomorrow?).

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]