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

debugging chdk code - how do you do it?

  • 32 Replies
  • 15501 Views
Re: debugging chdk code - how do you do it?
« Reply #10 on: 29 / August / 2009, 15:42:13 »
Advertisements
My regular script isn't resuming correctly - no surprise.

Lua_close() seems to cause a crash - the power down kind

I've also experimented with enable_shutdown and script_end with similar results. putting script_start() after wait_and_end() doesn't work ether.

I would like to a) shut down safely or b) restart the script safely. ideas?

I'd also like to introduce a scripting menu pref which provides options for handling script errors. This way others can benefit from this hacking. I poked around trying to make sense of how the menu system works but i came up short. anyone have a map?

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: debugging chdk code - how do you do it?
« Reply #11 on: 30 / August / 2009, 06:36:51 »
I would like to a) shut down safely or b) restart the script safely. ideas?

Related to this, I would like to be able to reboot Canon firmware (and along with it, restart CHDK) from Lua. The reason for doing this would be to force Canon firmware to recreate the image file table, to allow more than 4 DCIM subdirectories to be created during a single timelapse session (that's when my a570 runs out of RAM, meaning I have a limit of 8000 frames before a crash). Autostarting the script from where it left off would then be relatively trivial.

I'd also like to introduce a scripting menu pref which provides options for handling script errors. This way others can benefit from this hacking. I poked around trying to make sense of how the menu system works but i came up short. anyone have a map?

You add a config item to conf.c, text string to gui_lang.c (and I suppose to LANG/*.lng as much as you can?), increment GUI_LANG_ITEMS in gui_lang.h accordingly, then add it to gui somewhere in CMenuItem script_submenu_items_top, I guess. You then use your new config parameter in code, of course.

IMO this menu item belongs somewhere in the debug menu instead of the script menu (script menu should have as little CHDK params as possible, because as many as possible @params of the loaded script should be visible).

I may have missed something, but see past svn commits for examples. E.g. http://tools.assembla.com/chdk/changeset/601 for some RAW menu additions.

Re: debugging chdk code - how do you do it?
« Reply #12 on: 01 / September / 2009, 23:16:46 »
>>Related to this, I would like to be able to reboot Canon firmware (and along with it, restart CHDK) from Lua.

I thought there was a reason why this wasn't possible but maybe i'm wrong. Its certainly be asked about before.

Thanks for the directions on the gui stuff. The debug menu is a good idea. the script menu is a bit full if the goal is easy access to the script params but i don't think i have the knowledge to move things around. I'll try my hand at adding a single menu item.

--

I'll repeat my plea - any ideas for safely shutting down or restarting a lua script? The lua C api hasn't gotten me anywhere.

*

Offline reyalp

  • ******
  • 14134
Re: debugging chdk code - how do you do it?
« Reply #13 on: 02 / September / 2009, 02:39:39 »
I'll repeat my plea - any ideas for safely shutting down or restarting a lua script? The lua C api hasn't gotten me anywhere.
Lua_close should shut it down. If it crashes, I would guess some internal data structure is probably hosed or something. I again suggest you attempt to track down the cause of your mysterious error, rather than band-aid around it.
Don't forget what the H stands for.

Re: debugging chdk code - how do you do it?
« Reply #14 on: 02 / September / 2009, 22:29:11 »
>>I again suggest you attempt to track down the cause of your mysterious error, rather than band-aid around it.

I completely agree with that but I don't have any of the skills required to that. Still, might learn them eventually. I'll take a stab at it in a day or two.

---

lua_close(Lt) -  yields "cannot resume non-suspended coroutine" before the camera shuts down.

wait_and_end() then lua_close(Lt) - push shutter, then camera shuts down

enable_shutdown() - endless repetition of "cannot resume non-suspended coroutine"

script_end() - appears to exit script cleanly on autostart, waits for shutter to exit script on subsequent  script executions

script_end() then enable_shutdown() - same as above

---

what does wait_and_close() do? I find it mysterious even though it has some documentation -

Code: [Select]
static void wait_and_end(void)
{
script_console_add_line("PRESS SHUTTER TO CLOSE");

// We're not running any more, but we have scheduled stuff that
// needs to finish. So keep the script marked as running, but don't
// call any more scripting functions.
state_kbd_script_run = 3;
}
« Last Edit: 02 / September / 2009, 22:35:32 by mattkime »

*

Offline reyalp

  • ******
  • 14134
Re: debugging chdk code - how do you do it?
« Reply #15 on: 03 / September / 2009, 02:24:46 »
You might want to try setting lua_atpanic (see the manual). Normally, panic in lua ends up calling exit(), but this obviously doesn't make sense in CHDK. Keep in mind that the CHDK lua implementation is fairly hacked up to run at all. Diffing it against a stock lua release may be informative.

wait_and_end does what it says on the tin. kbd_process gets run in every ten ms or so (from the physw task). script_process does does various things based on what is on the script stack and the value of state_kbd_script_run. When the state is set to 3, the script isn't run but the code waits for you to press the shutter button.
Don't forget what the H stands for.

Re: debugging chdk code - how do you do it?
« Reply #16 on: 06 / September / 2009, 00:16:46 »
>>wait_and_end does what it says on the tin.

you're clearly much more skilled in reading the side of the tin than i am!

i am successfully writing to a text file which should be very useful for debugging. however, i'm uncertain where to go poking around. i don't see any obvious places to look. I'm fairly certain that my lua code is solid and the error is being propagated from the CHDK side. This is where the code fails -

Code: [Select]
  press("shoot_full")
  sleep(1)
  release("shoot_full")
  sleep(1)
  release("shoot_half")
  repeat
    sleep(1)
  until get_shooting() ~= true

so i need to investigate the get_shooting, release, and press functions. get_shooting is just getting a prop_case so i don't see how that could be corrupt. while i see the luaCB_keyfunc, i'm not making any sense of it.

perhaps you know of other things i should be looking for.

---

On trying to just restart the script -

Code: [Select]
lua_close( L );
L = 0;
Lt = 0;
start_script(0);

seems to be doing the job. doing a more extensive test.

*

Offline reyalp

  • ******
  • 14134
Re: debugging chdk code - how do you do it?
« Reply #17 on: 06 / September / 2009, 00:29:28 »
i am successfully writing to a text file which should be very useful for debugging. however, i'm uncertain where to go poking around. i don't see any obvious places to look. I'm fairly certain that my lua code is solid and the error is being propagated from the CHDK side. This is where the code fails -
I'd suggest using the lua debug API to get information after the script dies.
Quote
On trying to just restart the script -

Code: [Select]
lua_close( L );
L = 0;
Lt = 0;
start_script(0);

seems to be doing the job. doing a more extensive test.
That makes sense, since the other code that does lua_close() does this. If you don't, something probably doesn't notice that it's been closed. So you can disregard my comment about the state being corrupted.
Don't forget what the H stands for.

Re: debugging chdk code - how do you do it?
« Reply #18 on: 06 / September / 2009, 00:42:49 »
>>I'd suggest using the lua debug API to get information after the script dies.

Yes, which I would use to examine script variables, correct? If that is true, I have no idea what to examine as the error has nothing to do with vars. It exits with a (seemingly) random number and no error text.

*

Offline reyalp

  • ******
  • 14134
Re: debugging chdk code - how do you do it?
« Reply #19 on: 06 / September / 2009, 02:29:12 »
Yes, which I would use to examine script variables, correct?
I'd suggest reading the manual.

http://www.lua.org/manual/5.1/manual.html#3.8
You should be able to determine what function was being called.

Also, in lua_resume
Quote
lua_resume returns LUA_YIELD if the coroutine yields, 0 if the coroutine finishes its execution without errors, or an error code in case of errors (see lua_pcall)
In lua_pcall
Quote
The lua_pcall function returns 0 in case of success or one of the following error codes (defined in lua.h):
    * LUA_ERRRUN: a runtime error.
    * LUA_ERRMEM: memory allocation error. For such errors, Lua does not call the error handler function.
    * LUA_ERRERR: error while running the error handler function.

Also in lua_resume
Quote
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.
« Last Edit: 06 / September / 2009, 02:35:09 by reyalp »
Don't forget what the H stands for.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal