root/modules/module_inspector.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. _run
  2. _module_can_unload
  3. _module_exit_alt
  4. modinspect_unload_cb
  5. gui_module_kbd_process
  6. basic_module_init
  7. gui_module_menu_kbd_process
  8. gui_mem_info
  9. gui_module_draw

   1 #include "camera_info.h"
   2 #include "gui.h"
   3 #include "gui_draw.h"
   4 #include "meminfo.h"
   5 #include "module_load.h"
   6 #include "simple_module.h"
   7 
   8 // =========  MODULE INIT =================
   9 
  10 static int running = 0;
  11 
  12 extern int basic_module_init();
  13 
  14 /***************** BEGIN OF AUXILARY PART *********************
  15   ATTENTION: DO NOT REMOVE OR CHANGE SIGNATURES IN THIS SECTION
  16  **************************************************************/
  17 
  18 int _run()
  19 {
  20     basic_module_init();
  21 
  22     return 0;
  23 }
  24 
  25 int _module_can_unload()
  26 {
  27     return running == 0;
  28 }
  29 
  30 int _module_exit_alt()
  31 {
  32     running = 0;
  33     return 0;
  34 }
  35 
  36 /******************** Module Information structure ******************/
  37 
  38 libsimple_sym _librun =
  39 {
  40     {
  41          0, 0, _module_can_unload, _module_exit_alt, _run
  42     }
  43 };
  44 
  45 ModuleInfo _module_info =
  46 {
  47     MODULEINFO_V1_MAGICNUM,
  48     sizeof(ModuleInfo),
  49     SIMPLE_MODULE_VERSION,              // Module version
  50 
  51     ANY_CHDK_BRANCH, 0, OPT_ARCHITECTURE,                       // Requirements of CHDK version
  52     ANY_PLATFORM_ALLOWED,               // Specify platform dependency
  53 
  54     (int32_t)"Module Inspector",
  55     MTYPE_EXTENSION,            //Show list of loaded modules
  56 
  57     &_librun.base,
  58 
  59     ANY_VERSION,                // CONF version
  60     CAM_SCREEN_VERSION,         // CAM SCREEN version
  61     ANY_VERSION,                // CAM SENSOR version
  62     ANY_VERSION,                // CAM INFO version
  63 };
  64 
  65 /*************** END OF AUXILARY PART *******************/
  66 
  67 /*************** GUI MODULE *******************/
  68 
  69 #include "gui_mbox.h"
  70 #include "keyboard.h"
  71 #include "stdlib.h"
  72 
  73 void gui_module_menu_kbd_process();
  74 int gui_module_kbd_process();
  75 void gui_module_draw();
  76 
  77 gui_handler GUI_MODE_MODULE_INSPECTOR = 
  78 /*GUI_MODE_MODULE_INSPECTOR*/   { GUI_MODE_MODULE, gui_module_draw, gui_module_kbd_process, gui_module_menu_kbd_process, 0, 0 };
  79 
  80 int modinspect_redraw;
  81 gui_handler *modinspect_old_guimode;
  82 
  83 static void modinspect_unload_cb(unsigned int btn)
  84 {
  85     if (btn==MBOX_BTN_YES)
  86     {
  87         running = 0;
  88         module_exit_alt();
  89         gui_set_mode(modinspect_old_guimode);   // if core gui - return to it
  90     }
  91     modinspect_redraw=2;
  92 }
  93 
  94 int gui_module_kbd_process()
  95 {
  96     switch (kbd_get_autoclicked_key())
  97     {
  98     case KEY_SET:
  99         modinspect_redraw = 2;
 100         break;
 101     case KEY_DISPLAY:
 102         gui_mbox_init( (int)"Module Inspector", (int)"Unload all modules?",
 103             MBOX_TEXT_CENTER|MBOX_BTN_YES_NO|MBOX_DEF_BTN2, modinspect_unload_cb);
 104         break;
 105     }
 106     return 0;
 107 }
 108 
 109 //-------------------------------------------------------------------
 110 
 111 int basic_module_init()
 112 {
 113     running = 1;
 114     modinspect_redraw = 2;
 115     modinspect_old_guimode = gui_set_mode(&GUI_MODE_MODULE_INSPECTOR);
 116     return 1;
 117 }
 118 
 119 void gui_module_menu_kbd_process()
 120 {
 121     running = 0;
 122     gui_set_mode(modinspect_old_guimode);
 123 }
 124 
 125 static void gui_mem_info(char *typ, cam_meminfo *meminfo, int showidx)
 126 {
 127     char txt[50];
 128     sprintf(txt,"%-5s: %08x-%08x: %d",typ,meminfo->start_address, meminfo->end_address, meminfo->total_size);
 129     draw_string(camera_screen.disp_left, showidx, txt, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 130         sprintf(txt,"alloc: now=%d(%d) max=%d", meminfo->allocated_size, meminfo->allocated_count, meminfo->allocated_peak);
 131     draw_string(camera_screen.disp_left, showidx+FONT_HEIGHT, txt, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 132         sprintf(txt,"free:  now=%d(%d) max=%d", meminfo->free_size, meminfo->free_block_count, meminfo->free_block_max_size);
 133     draw_string(camera_screen.disp_left, showidx+2*FONT_HEIGHT, txt, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 134 }
 135 
 136 void gui_module_draw()
 137 {
 138     int idx, showidx;
 139 
 140     if (modinspect_redraw) {
 141 
 142         draw_rectangle(camera_screen.disp_left, 0, camera_screen.disp_right, camera_screen.height-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK), RECT_BORDER0|DRAW_FILLED);
 143         draw_string(camera_screen.disp_left+5*FONT_WIDTH, 0, "*** Module Inspector ***", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 144         draw_string(camera_screen.disp_left+FONT_WIDTH, FONT_HEIGHT, "SET-redraw, DISP-unload_all, MENU-exit", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 145         draw_string(camera_screen.disp_left, 2*FONT_HEIGHT, "Idx Name         Addr       Size", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 146 
 147                 showidx=3*FONT_HEIGHT;
 148                 for ( idx=0; idx<MAX_NUM_LOADED_MODULES; idx++)
 149                 {
 150             module_entry* mod = module_get_adr(idx);;
 151                         if (mod == 0) continue;
 152 
 153                         char txt[50], name[13];
 154                         // Module name can include full path, extract just filename and display max of 12 chars
 155                         char *s = strrchr(mod->hMod->name, '/');
 156                         if (s) s = s + 1; else s = mod->hMod->name;
 157                         strncpy(name, s, 12); name[12] = 0;
 158                     sprintf(txt,"%02d: %-12s %08x - %d bytes", idx, name, (unsigned)mod->hdr, mod->hdr->reloc_start+mod->hdr->bss_size);
 159                 draw_string(camera_screen.disp_left, showidx, txt, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 160                         showidx += FONT_HEIGHT;
 161                 }
 162 
 163         showidx += FONT_HEIGHT;
 164 
 165         cam_meminfo meminfo;
 166 
 167         // Display Canon heap memory info
 168         // amount of data displayed may vary depending on GetMemInfo implementation
 169         memset(&meminfo,0,sizeof(meminfo));
 170         GetMemInfo(&meminfo);
 171         gui_mem_info("MEM", &meminfo, showidx);
 172         showidx += 3*FONT_HEIGHT;
 173 
 174         // Display ARAM memory info (only if enabled)
 175         memset(&meminfo,0,sizeof(meminfo));
 176         if (GetARamInfo(&meminfo))
 177         {
 178             gui_mem_info("ARAM", &meminfo, showidx);
 179             showidx += 3*FONT_HEIGHT;
 180                 }
 181 
 182         // Display EXMEM memory info (only if enabled)
 183         memset(&meminfo,0,sizeof(meminfo));
 184         if (GetExMemInfo(&meminfo))
 185         {
 186             gui_mem_info("EXMEM", &meminfo, showidx);
 187                 }
 188         }
 189 
 190         modinspect_redraw = 0;
 191 }
 192 

/* [<][>][^][v][top][bottom][index][help] */