debugging chdk code - how do you do it? - General Discussion and Assistance - CHDK Forum

debugging chdk code - how do you do it?

  • 32 Replies
  • 8553 Views
debugging chdk code - how do you do it?
« on: 26 / August / 2009, 21:51:08 »
Advertisements
i'm attempting to modify chdk so that a script can be restarted on exit if it exits due to error.

I've examined the script_end fn in kbd.c. I can add an script_console_add_line fn to it but when i try to put one _before_ where script_end is called, it doesn't produce output.

Does anyone know why?

How do people debug chdk?

*

Offline RaduP

  • *****
  • 890
Re: debugging chdk code - how do you do it?
« Reply #1 on: 26 / August / 2009, 22:03:34 »
Well, you can probably use the LEDs to blink if the code execution gets there, and possibly make them blink differently (or make different LEDs blink) depending on what data is expected and stuff.

Re: debugging chdk code - how do you do it?
« Reply #2 on: 26 / August / 2009, 22:10:11 »
Mind providing a hint as to how I might do that?

*

Offline reyalp

  • ******
  • 12737
Re: debugging chdk code - how do you do it?
« Reply #3 on: 26 / August / 2009, 22:10:21 »
How do people debug chdk?
LEDs, misc debug vals (see core/gui.c gui_draw_debug_vals_osd()), log files.

Not sure about your specific problem with kbd.c, it's a mess.
Don't forget what the H stands for.


*

Offline reyalp

  • ******
  • 12737
Re: debugging chdk code - how do you do it?
« Reply #4 on: 26 / August / 2009, 22:12:55 »
In chdk, you can usually use started(); and finished() to turn on and off the blue DP led. For other LEDs, you can write to the MMIO addresses directly, or possibly use the set led function available from script.
Don't forget what the H stands for.

Re: debugging chdk code - how do you do it?
« Reply #5 on: 26 / August / 2009, 22:37:15 »
>>Not sure about your specific problem with kbd.c

I might be looking in the wrong place. kdb.c is definitely where the script execution is triggered but I don't think Lua passes on any error to the OS. This means that I'll need to intercept the error from within Lua.

*

Offline reyalp

  • ******
  • 12737
Re: debugging chdk code - how do you do it?
« Reply #6 on: 26 / August / 2009, 22:47:26 »
>>Not sure about your specific problem with kbd.c

I might be looking in the wrong place. kdb.c is definitely where the script execution is triggered but I don't think Lua passes on any error to the OS. This means that I'll need to intercept the error from within Lua.

It should. In process_script
Code: [Select]
       Lres = lua_resume( Lt, top );
  if (Lres != LUA_YIELD && Lres != 0) {
  script_console_add_line( lua_tostring( Lt, -1 ) );
  wait_and_end();
  return;
  }
aside: the formatting in kbc.c is horrid >:(

see also http://www.lua.org/manual/5.1/manual.html#lua_resume

particularly
Quote
or an error code in case of errors (see lua_pcall). In case of errors, the stack is not unwound, so you can use the debug API over it. The error message is on the top of the stack.
Don't forget what the H stands for.

Re: debugging chdk code - how do you do it?
« Reply #7 on: 27 / August / 2009, 23:29:08 »
YAY!!! I'm successfully restarting the script by replacing wait_and_end() with script_start(). It restarts only on error. If I exit via shutter button push it does not restart.

It restarts a number of times and then crashes the camera. I'm likely _not_ cleaning up properly before starting the script again. How is this cleanup process running? wait_and_end just sets state_kbd_script_run = 3.



Re: debugging chdk code - how do you do it?
« Reply #8 on: 28 / August / 2009, 23:11:39 »
got lua_resume working - not sure if its a good idea to continue executing a script which has produced an error. any thoughts on that?

also trying to figure out a good way to log lua errors.

*

Offline reyalp

  • ******
  • 12737
Re: debugging chdk code - how do you do it?
« Reply #9 on: 28 / August / 2009, 23:44:00 »
got lua_resume working - not sure if its a good idea to continue executing a script which has produced an error. any thoughts on that?
I would suggest not, although I guess it depends on the nature of the error.
Quote
also trying to figure out a good way to log lua errors.
I would suggest using the lua debug C API to gather information, and then dump it to a text file. You can use regular fopen, fwrite etc in CHDK code.
Don't forget what the H stands for.

 

Related Topics