Debugger exit code or action

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
User avatar
aclassifier
Respected Member
Posts: 319
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Debugger exit code or action

Postby aclassifier » Tue Jan 31, 2017 6:29 pm

I am running tests using the startKIT through the debugger.

The code controls heating elements inside the base of an aquarium, and when I quit the debugger it would be _so_ nice to have some code run automatically that does my action. Like switching off the heating elements. I have no fish yet..

Alternatively, doing something with the ports from f.ex. config.xscope? I only need to set two pins low.
henk
Respected Member
Posts: 346
Joined: Wed Jan 27, 2016 5:21 pm

Postby henk » Wed Feb 01, 2017 10:05 am

That is difficult.

You can detach the debugger, upon which the code continues to run where you left it? Ie, it would at least drop back into its control loop.

Alternatively, you can define a command 'quitme' that first calls a function in your program (that switches said pains down) before quitting?
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Postby robertxmos » Wed Feb 01, 2017 10:19 am

Hi,
For exiting during normal execution, you can use atexit() to register a callback function.
xgdb (gdb) has a similar mechanism - user defined command hooks.
see ftp://ftp.gnu.org/old-gnu/Manuals/gdb/h ... tml#SEC194

(gdb) define hook-quit
>echo goodbye...
>call exiting()
>end
(gdb) quit
goodbye...running exit function


N.B.
If gdb can't find the 'exiting()' function it will fail to run the 'quit' command - hence you can't quit.
This can be fixed by redefining the 'hook-quit' viz:
(gdb) define hook-quit
>end
(gdb) quit
User avatar
aclassifier
Respected Member
Posts: 319
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Postby aclassifier » Wed Feb 01, 2017 10:36 am

Henk, I think "detach" is "disconnect" in the menu? Yes, it then runs on fine, thanks (I should have looked for it, the AVR debugger I use at work does this).

Robert: this seems to introduce a command that I need t type into the debugger console, right? Good to know! However, I do have three buttons in the rather packed startKIT-based aquarium controller, so I could just have put switching off in the menu, there. However, that's not really what I was looking for. When the debugger runs and I sit with the code and want to debug again I push the red square and start the debugger again. Then the phone rings.. and my melting fuse may come to the rescue. The heating elements didn't go off automatically. This could be a motor or a robot arm that needed to stop. Not by remembering to run a command. Just stop when the tool downloads new code. I guess this would be a rater nice functionality for safety critical code.
henk
Respected Member
Posts: 346
Joined: Wed Jan 27, 2016 5:21 pm

Postby henk » Wed Feb 01, 2017 11:35 am

"detach" is a command from the command-line; disconnect may well be the IDE equivalent.

There is a general issue with debuggers and real-time control. Imagine you have a class-D amplifier, or a motor control, or anything like that where power transistors are driven by a real-time program (whether xCORE or not). If you put a breakpoint at a place where the transistor is conducting, and the program stops, you will get a large DC current running through the transistor. There is very little you can do about that, other than only using the debugger when you are not having a load on the system, and then use real-time xSCOPE when you get to the point where you need to tune the algorithm with a load.
User avatar
aclassifier
Respected Member
Posts: 319
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Postby aclassifier » Wed Feb 01, 2017 12:07 pm

I really can't wait to use xSCOPE. (Blush.. I haven't yet..)

Even if the general problem you describe is very serious, I think that my suggestion isn't completely off the hook. I simply want to define a predefined set of the pins when or iff the debugger stops. Or a remote procedure call (as the interface) that can set the unit in stopped "safe mode".

Thanks!
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Postby robertxmos » Wed Feb 01, 2017 12:56 pm

Hi,

I'm struggling to understand your use-case - please ignore me if I have totally missed the point.

1. Your using the debugger.
2. code is running in the debugger
3a. The code stops at a breakpoint - you are now looking at it in the debugger
or
3b. The code stops at a breakpoint and you quit the debugger
4. The phone rings
5. The system is in the state it was when you hit the break point viz: heater stuck on as the software is not running

I've described how to set up an automatic call a remote procedure for 3b.
You can do the same for 3a viz: define hook-stop.

The few lines can be placed in a file that is loaded/run when you start the debugger.
see https://www.xmos.com/published/how-run- ... mands-file
If you are using xTimeComposer, you will need to add the above to your debug session details - once.
User avatar
aclassifier
Respected Member
Posts: 319
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Postby aclassifier » Wed Feb 01, 2017 2:42 pm

1 and 2 as above
3. I am not using any breakpoints since I have a good display and three buttons and can see printfs in the debugger console
4. I see some problem and look in the code to fix. Maybe this time..
5. I stop the debugger but fail to see that dangerous output A (by a sw PWM) is on (can't really see it either, no LED)
6. The phone rings
7. When i come back and start to debug again I discover that auch! One 1 ms on every 1000, but that was when I hit the red square stop button, and the something is broken

I wish for some function to be called when I hit the red button, so that my sw could disable the critical PWM.

(None of this has happened me, and I do have a LED with the output. And I have only max 48 Watt spread out beneath a 44 l tank with no fish). But had I had that function I'd use it)

It's really great to see debug breakpoint hook start and stop functions! I didn't know that the debugger allowed me to. I haven't seen that since the debugger for MPP Pascal around 1980, running on a Texas machine! But then I haven't looked in GDB, either. Thanks
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Postby robertxmos » Wed Feb 01, 2017 4:09 pm

I'm not sure what the 'red square stop button' does. Is it stopping the debugger?

> 5. I stop the debugger but fail to see that dangerous output A (by a sw PWM) is on (can't really see it either, no LED)
I would imagine that 'define hook-stop' would trigger when ever the debugger stops - for any reason.
You could trivially test this for your situation to see if it is the right place to call your safeStop() function automatically.
User avatar
aclassifier
Respected Member
Posts: 319
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

Postby aclassifier » Wed Feb 01, 2017 4:19 pm

Yes, the "red button" is to stop the debugger. I will certainly test the "define hook-stop". I will come back with more questions or results within a week I guess. Would the debugger wait for safeStop() to return?

Thanks, Robert!

Who is online

Users browsing this forum: bear118 and 169 guests