Fandom

Magic Lantern Firmware Wiki

Debugging Magic Lantern

328pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

This is a guide for developers who want to enhance Magic Lantern.

Since you can't run the Magic Lantern code step by step inside the camera, debugging may be a little difficult. This page will try to help.

Some simple debugging tools:

  • DebugMsg (DryOS call) and DEBUG() macro (wrapper around DebugMsg): these write a message to the internal camera log; DebugMsg is also used by Canon functions)
  • bmp_printf (Magic Lantern function, writes a message on the screen)
  • Dumping data from RAM
  • Script console (console.c; for now, only present in LUA-enabled build)

DebugMsg and DEBUG() macroEdit

Juicy info here: http://chdk.setepontos.com/index.php?topic=3637.0.

Call examplesEdit

  • DebugMsg:
DebugMsg(DM_MAGIC, 3, "This is a message")
DebugMsg(DM_MAGIC, 3, "This is an integer: %d", 5)
  • DEBUG macro:

This is a very handy wrapper around DebugMsg; recommended for all new development. It will print the function name and line number, and then your message (which is optional).

DEBUG();                 // prints only function name and line number
DEBUG("x=%d", x);        // prints also a printf-like string

This was defined by Trammell for debugging LUA code, and it's included in dryos.h in latest 550D builds.

How to useEdit

To see the output messages, you have to call dumpf(). In the menu, Debug->Dump dmlog does that.

If you don't have acces to the menu, the simplest way to do this is to write this into the config file (usually magic.cfg):

debug.timed-dump = 10

This means Magic Lantern will call dumpf() in 10 seconds after booting. After the card activity light turns off, remove the card, put it into the card reader and you'll find a debugging log like this one: [1]. The debug log will contain Magic Lantern calls interleaved with Canon's DebugMsg's.

If there are too many debug messages, the log file will be trimmed. To inhibit some them, put this in debug.c, dump_task:

dm_set_store_level( DM_DISP, 7 );
dm_set_store_level( DM_LVFD, 7 );
dm_set_store_level( DM_LVCFG, 7 );
dm_set_store_level( DM_LVCDEV, 7 );

and those messages won't appear in the log file any more.

7 is a magic number and seems to work :)

DebugMsg codesEdit

 50 [MAGIC]      # ./debug.h:64:#define DM_MAGIC	50 // Replaces PTPCOM with MAGIC
 24 [IMP]
130 [DISP]
131 [GUI]
156 [MC]
... (lots of codes) ...

bmp_printfEdit

This is for writing messages on the screen, and is documented here: http://magiclantern.wikia.com/wiki/Magic_Lantern_API#bmp.h_and_bmp.c

Note that after writing a message, it might be erased by Canon's drawing routines.

bfnt_putsEdit

This writes messages with Canon's builtin Fonts (useful if you have trouble with ML fonts).

bfnt_puts("Hello, world!", x, y, foreground_color, background_color);

Dumping data from RAMEdit

Code mix from AJ and Arm.Indy:

void dump_seg(start, size, filename)
{
    FILE *f;
    FIO_RemoveFile(filename);
    f = FIO_CreateFile(filename);
    if (f == INVALID_PTR)
    {
       bmp_printf(FONT_SMALL, 120, 40, "FCreate: Err %s", filename);
       return;
    }
    FIO_WriteFile(f, start, size);
    FIO_CloseFile(f);
}

Example (to be called while in Live View mode, e.g. from draw_zebra):

dump_seg(0x40D07800, 1440*480, "B:/vram1.dat");

This is how I've found the YUV 4:2:2 buffer (for zebra and histogram).

Debug consoleEdit

This is present in recent 550D builds. Code is 99% identical to the script console from LUA-enabled builds.

API:

  • console_show() / console_hide()
  • console_puts(const char* str)
  • console_printf(const char* fmt, ...)

DebugMsg's from ML are also displayed to the debug console. The contents of the console is saved to CONSOLE.LOG; it's updated as soon as a new message appears (which allows you to spy the shutdown sequence, for example).

Further readingEdit

debug.c

DryOS shell debug functions

Also on Fandom

Random Wiki