cmd.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. /*
  2. * RT-Thread finsh shell commands
  3. *
  4. * COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
  5. *
  6. * This file is part of RT-Thread (http://www.rt-thread.org)
  7. * Maintainer: bernard.xiong <bernard.xiong at gmail.com>
  8. *
  9. * All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. *
  25. * Change Logs:
  26. * Date Author Notes
  27. * 2006-04-30 Bernard first implementation
  28. * 2006-05-04 Bernard add list_thread,
  29. * list_sem,
  30. * list_timer
  31. * 2006-05-20 Bernard add list_mutex,
  32. * list_mailbox,
  33. * list_msgqueue,
  34. * list_event,
  35. * list_fevent,
  36. * list_mempool
  37. * 2006-06-03 Bernard display stack information in list_thread
  38. * 2006-08-10 Bernard change version to invoke rt_show_version
  39. * 2008-09-10 Bernard update the list function for finsh syscall
  40. * list and sysvar list
  41. * 2009-05-30 Bernard add list_device
  42. * 2010-04-21 yi.qiu add list_module
  43. * 2012-04-29 goprife improve the command line auto-complete feature.
  44. * 2012-06-02 lgnq add list_memheap
  45. * 2012-10-22 Bernard add MS VC++ patch.
  46. */
  47. #include <rtthread.h>
  48. #include "finsh.h"
  49. rt_inline unsigned int rt_list_len(const rt_list_t *l)
  50. {
  51. unsigned int len = 0;
  52. const rt_list_t *p = l;
  53. while (p->next != l)
  54. {
  55. p = p->next;
  56. len ++;
  57. }
  58. return len;
  59. }
  60. long hello(void)
  61. {
  62. rt_kprintf("Hello RT-Thread!\n");
  63. return 0;
  64. }
  65. FINSH_FUNCTION_EXPORT(hello, say hello world);
  66. extern void rt_show_version(void);
  67. long version(void)
  68. {
  69. rt_show_version();
  70. return 0;
  71. }
  72. FINSH_FUNCTION_EXPORT(version, show RT-Thread version information);
  73. MSH_CMD_EXPORT(version, show RT-Thread version information);
  74. extern struct rt_object_information rt_object_container[];
  75. static long _list_thread(struct rt_list_node *list)
  76. {
  77. struct rt_thread *thread;
  78. struct rt_list_node *node;
  79. rt_uint8_t *ptr;
  80. rt_kprintf(" thread pri status sp stack size max used left tick error\n");
  81. rt_kprintf("-------- ---- ------- ---------- ---------- ---------- ---------- ---\n");
  82. for (node = list->next; node != list; node = node->next)
  83. {
  84. thread = rt_list_entry(node, struct rt_thread, list);
  85. rt_kprintf("%-8.*s 0x%02x", RT_NAME_MAX, thread->name, thread->current_priority);
  86. if (thread->stat == RT_THREAD_READY) rt_kprintf(" ready ");
  87. else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
  88. else if (thread->stat == RT_THREAD_INIT) rt_kprintf(" init ");
  89. else if (thread->stat == RT_THREAD_CLOSE) rt_kprintf(" close ");
  90. ptr = (rt_uint8_t*)thread->stack_addr;
  91. while (*ptr == '#')ptr ++;
  92. rt_kprintf(" 0x%08x 0x%08x 0x%08x 0x%08x %03d\n",
  93. thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp),
  94. thread->stack_size,
  95. thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr),
  96. thread->remaining_tick,
  97. thread->error);
  98. }
  99. return 0;
  100. }
  101. long list_thread(void)
  102. {
  103. return _list_thread(&rt_object_container[RT_Object_Class_Thread].object_list);
  104. }
  105. FINSH_FUNCTION_EXPORT(list_thread, list thread);
  106. MSH_CMD_EXPORT(list_thread, list thread);
  107. static void show_wait_queue(struct rt_list_node *list)
  108. {
  109. struct rt_thread *thread;
  110. struct rt_list_node *node;
  111. for (node = list->next; node != list; node = node->next)
  112. {
  113. thread = rt_list_entry(node, struct rt_thread, tlist);
  114. rt_kprintf("%s", thread->name);
  115. if (node->next != list)
  116. rt_kprintf("/");
  117. }
  118. }
  119. #ifdef RT_USING_SEMAPHORE
  120. static long _list_sem(struct rt_list_node *list)
  121. {
  122. struct rt_semaphore *sem;
  123. struct rt_list_node *node;
  124. rt_kprintf("semaphore v suspend thread\n");
  125. rt_kprintf("-------- --- --------------\n");
  126. for (node = list->next; node != list; node = node->next)
  127. {
  128. sem = (struct rt_semaphore *)(rt_list_entry(node, struct rt_object, list));
  129. if (!rt_list_isempty(&sem->parent.suspend_thread))
  130. {
  131. rt_kprintf("%-8.*s %03d %d:",
  132. RT_NAME_MAX,
  133. sem->parent.parent.name,
  134. sem->value,
  135. rt_list_len(&sem->parent.suspend_thread));
  136. show_wait_queue(&(sem->parent.suspend_thread));
  137. rt_kprintf("\n");
  138. }
  139. else
  140. {
  141. rt_kprintf("%-8.*s %03d %d\n",
  142. RT_NAME_MAX,
  143. sem->parent.parent.name,
  144. sem->value,
  145. rt_list_len(&sem->parent.suspend_thread));
  146. }
  147. }
  148. return 0;
  149. }
  150. long list_sem(void)
  151. {
  152. return _list_sem(&rt_object_container[RT_Object_Class_Semaphore].object_list);
  153. }
  154. FINSH_FUNCTION_EXPORT(list_sem, list semaphone in system);
  155. MSH_CMD_EXPORT(list_sem, list semaphore in system);
  156. #endif
  157. #ifdef RT_USING_EVENT
  158. static long _list_event(struct rt_list_node *list)
  159. {
  160. struct rt_event *e;
  161. struct rt_list_node *node;
  162. rt_kprintf("event set suspend thread\n");
  163. rt_kprintf("-------- ---------- --------------\n");
  164. for (node = list->next; node != list; node = node->next)
  165. {
  166. e = (struct rt_event *)(rt_list_entry(node, struct rt_object, list));
  167. if (!rt_list_isempty(&e->parent.suspend_thread))
  168. {
  169. rt_kprintf("%-8.*s 0x%08x %03d:",
  170. RT_NAME_MAX,
  171. e->parent.parent.name,
  172. e->set,
  173. rt_list_len(&e->parent.suspend_thread));
  174. show_wait_queue(&(e->parent.suspend_thread));
  175. rt_kprintf("\n");
  176. }
  177. else
  178. {
  179. rt_kprintf("%-8.*s 0x%08x 0\n",
  180. RT_NAME_MAX, e->parent.parent.name, e->set);
  181. }
  182. }
  183. return 0;
  184. }
  185. long list_event(void)
  186. {
  187. return _list_event(&rt_object_container[RT_Object_Class_Event].object_list);
  188. }
  189. FINSH_FUNCTION_EXPORT(list_event, list event in system);
  190. MSH_CMD_EXPORT(list_event, list event in system);
  191. #endif
  192. #ifdef RT_USING_MUTEX
  193. static long _list_mutex(struct rt_list_node *list)
  194. {
  195. struct rt_mutex *m;
  196. struct rt_list_node *node;
  197. rt_kprintf("mutex owner hold suspend thread\n");
  198. rt_kprintf("-------- -------- ---- --------------\n");
  199. for (node = list->next; node != list; node = node->next)
  200. {
  201. m = (struct rt_mutex *)(rt_list_entry(node, struct rt_object, list));
  202. rt_kprintf("%-8.*s %-8.*s %04d %d\n",
  203. RT_NAME_MAX,
  204. m->parent.parent.name,
  205. RT_NAME_MAX,
  206. m->owner->name,
  207. m->hold,
  208. rt_list_len(&m->parent.suspend_thread));
  209. }
  210. return 0;
  211. }
  212. long list_mutex(void)
  213. {
  214. return _list_mutex(&rt_object_container[RT_Object_Class_Mutex].object_list);
  215. }
  216. FINSH_FUNCTION_EXPORT(list_mutex, list mutex in system);
  217. MSH_CMD_EXPORT(list_mutex, list mutex in system);
  218. #endif
  219. #ifdef RT_USING_MAILBOX
  220. static long _list_mailbox(struct rt_list_node *list)
  221. {
  222. struct rt_mailbox *m;
  223. struct rt_list_node *node;
  224. rt_kprintf("mailbox entry size suspend thread\n");
  225. rt_kprintf("-------- ---- ---- --------------\n");
  226. for (node = list->next; node != list; node = node->next)
  227. {
  228. m = (struct rt_mailbox *)(rt_list_entry(node, struct rt_object, list));
  229. if (!rt_list_isempty(&m->parent.suspend_thread))
  230. {
  231. rt_kprintf("%-8.*s %04d %04d %d:",
  232. RT_NAME_MAX,
  233. m->parent.parent.name,
  234. m->entry,
  235. m->size,
  236. rt_list_len(&m->parent.suspend_thread));
  237. show_wait_queue(&(m->parent.suspend_thread));
  238. rt_kprintf("\n");
  239. }
  240. else
  241. {
  242. rt_kprintf("%-8.*s %04d %04d %d\n",
  243. RT_NAME_MAX,
  244. m->parent.parent.name,
  245. m->entry,
  246. m->size,
  247. rt_list_len(&m->parent.suspend_thread));
  248. }
  249. }
  250. return 0;
  251. }
  252. long list_mailbox(void)
  253. {
  254. return _list_mailbox(&rt_object_container[RT_Object_Class_MailBox].object_list);
  255. }
  256. FINSH_FUNCTION_EXPORT(list_mailbox, list mail box in system);
  257. MSH_CMD_EXPORT(list_mailbox, list mail box in system);
  258. #endif
  259. #ifdef RT_USING_MESSAGEQUEUE
  260. static long _list_msgqueue(struct rt_list_node *list)
  261. {
  262. struct rt_messagequeue *m;
  263. struct rt_list_node *node;
  264. rt_kprintf("msgqueue entry suspend thread\n");
  265. rt_kprintf("-------- ---- --------------\n");
  266. for (node = list->next; node != list; node = node->next)
  267. {
  268. m = (struct rt_messagequeue *)(rt_list_entry(node, struct rt_object, list));
  269. if (!rt_list_isempty(&m->parent.suspend_thread))
  270. {
  271. rt_kprintf("%-8.*s %04d %d:",
  272. RT_NAME_MAX,
  273. m->parent.parent.name,
  274. m->entry,
  275. rt_list_len(&m->parent.suspend_thread));
  276. show_wait_queue(&(m->parent.suspend_thread));
  277. rt_kprintf("\n");
  278. }
  279. else
  280. {
  281. rt_kprintf("%-8.*s %04d %d\n",
  282. RT_NAME_MAX,
  283. m->parent.parent.name,
  284. m->entry,
  285. rt_list_len(&m->parent.suspend_thread));
  286. }
  287. }
  288. return 0;
  289. }
  290. long list_msgqueue(void)
  291. {
  292. return _list_msgqueue(&rt_object_container[RT_Object_Class_MessageQueue].object_list);
  293. }
  294. FINSH_FUNCTION_EXPORT(list_msgqueue, list message queue in system);
  295. MSH_CMD_EXPORT(list_msgqueue, list message queue in system);
  296. #endif
  297. #ifdef RT_USING_MEMHEAP
  298. static long _list_memheap(struct rt_list_node *list)
  299. {
  300. struct rt_memheap *mh;
  301. struct rt_list_node *node;
  302. rt_kprintf("memheap pool size max used size available size\n");
  303. rt_kprintf("-------- ---------- ------------- --------------\n");
  304. for (node = list->next; node != list; node = node->next)
  305. {
  306. mh = (struct rt_memheap *)rt_list_entry(node, struct rt_object, list);
  307. rt_kprintf("%-8.*s %-010d %-013d %-05d\n",
  308. RT_NAME_MAX,
  309. mh->parent.name,
  310. mh->pool_size,
  311. mh->max_used_size,
  312. mh->available_size);
  313. }
  314. return 0;
  315. }
  316. long list_memheap(void)
  317. {
  318. return _list_memheap(&rt_object_container[RT_Object_Class_MemHeap].object_list);
  319. }
  320. FINSH_FUNCTION_EXPORT(list_memheap, list memory heap in system);
  321. MSH_CMD_EXPORT(list_memheap, list memory heap in system);
  322. #endif
  323. #ifdef RT_USING_MEMPOOL
  324. static long _list_mempool(struct rt_list_node *list)
  325. {
  326. struct rt_mempool *mp;
  327. struct rt_list_node *node;
  328. rt_kprintf("mempool block total free suspend thread\n");
  329. rt_kprintf("-------- ---- ---- ---- --------------\n");
  330. for (node = list->next; node != list; node = node->next)
  331. {
  332. mp = (struct rt_mempool *)rt_list_entry(node, struct rt_object, list);
  333. if (mp->suspend_thread_count > 0)
  334. {
  335. rt_kprintf("%-8.*s %04d %04d %04d %d:",
  336. RT_NAME_MAX,
  337. mp->parent.name,
  338. mp->block_size,
  339. mp->block_total_count,
  340. mp->block_free_count,
  341. mp->suspend_thread_count);
  342. show_wait_queue(&(mp->suspend_thread));
  343. rt_kprintf("\n");
  344. }
  345. else
  346. {
  347. rt_kprintf("%-8.*s %04d %04d %04d %d\n",
  348. RT_NAME_MAX,
  349. mp->parent.name,
  350. mp->block_size,
  351. mp->block_total_count,
  352. mp->block_free_count,
  353. mp->suspend_thread_count);
  354. }
  355. }
  356. return 0;
  357. }
  358. long list_mempool(void)
  359. {
  360. return _list_mempool(&rt_object_container[RT_Object_Class_MemPool].object_list);
  361. }
  362. FINSH_FUNCTION_EXPORT(list_mempool, list memory pool in system)
  363. MSH_CMD_EXPORT(list_mempool, list memory pool in system);
  364. #endif
  365. static long _list_timer(struct rt_list_node *list)
  366. {
  367. struct rt_timer *timer;
  368. struct rt_list_node *node;
  369. rt_kprintf("timer periodic timeout flag\n");
  370. rt_kprintf("-------- ---------- ---------- -----------\n");
  371. for (node = list->next; node != list; node = node->next)
  372. {
  373. timer = (struct rt_timer *)(rt_list_entry(node, struct rt_object, list));
  374. rt_kprintf("%-8.*s 0x%08x 0x%08x ",
  375. RT_NAME_MAX,
  376. timer->parent.name,
  377. timer->init_tick,
  378. timer->timeout_tick);
  379. if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
  380. rt_kprintf("activated\n");
  381. else
  382. rt_kprintf("deactivated\n");
  383. }
  384. rt_kprintf("current tick:0x%08x\n", rt_tick_get());
  385. return 0;
  386. }
  387. long list_timer(void)
  388. {
  389. return _list_timer(&rt_object_container[RT_Object_Class_Timer].object_list);
  390. }
  391. FINSH_FUNCTION_EXPORT(list_timer, list timer in system);
  392. MSH_CMD_EXPORT(list_timer, list timer in system);
  393. #ifdef RT_USING_DEVICE
  394. static long _list_device(struct rt_list_node *list)
  395. {
  396. struct rt_device *device;
  397. struct rt_list_node *node;
  398. char * const device_type_str[] =
  399. {
  400. "Character Device",
  401. "Block Device",
  402. "Network Interface",
  403. "MTD Device",
  404. "CAN Device",
  405. "RTC",
  406. "Sound Device",
  407. "Graphic Device",
  408. "I2C Bus",
  409. "USB Slave Device",
  410. "USB Host Bus",
  411. "SPI Bus",
  412. "SPI Device",
  413. "SDIO Bus",
  414. "PM Pseudo Device",
  415. "Pipe",
  416. "Portal Device",
  417. "Miscellaneous Device",
  418. "Unknown"
  419. };
  420. rt_kprintf("device type ref count\n");
  421. rt_kprintf("-------- -------------------- ----------\n");
  422. for (node = list->next; node != list; node = node->next)
  423. {
  424. device = (struct rt_device *)(rt_list_entry(node, struct rt_object, list));
  425. rt_kprintf("%-8.*s %-20s %-8d\n",
  426. RT_NAME_MAX,
  427. device->parent.name,
  428. (device->type <= RT_Device_Class_Unknown) ?
  429. device_type_str[device->type] :
  430. device_type_str[RT_Device_Class_Unknown],
  431. device->ref_count);
  432. }
  433. return 0;
  434. }
  435. long list_device(void)
  436. {
  437. return _list_device(&rt_object_container[RT_Object_Class_Device].object_list);
  438. }
  439. FINSH_FUNCTION_EXPORT(list_device, list device in system);
  440. MSH_CMD_EXPORT(list_device, list device in system);
  441. #endif
  442. #ifdef RT_USING_MODULE
  443. #include <rtm.h>
  444. int list_module(void)
  445. {
  446. struct rt_module *module;
  447. struct rt_list_node *list, *node;
  448. list = &rt_object_container[RT_Object_Class_Module].object_list;
  449. rt_kprintf("module name ref\n");
  450. rt_kprintf("------------ --------\n");
  451. for (node = list->next; node != list; node = node->next)
  452. {
  453. module = (struct rt_module *)(rt_list_entry(node, struct rt_object, list));
  454. rt_kprintf("%-16.*s %-04d\n",
  455. RT_NAME_MAX, module->parent.name, module->nref);
  456. }
  457. return 0;
  458. }
  459. FINSH_FUNCTION_EXPORT(list_module, list module in system);
  460. MSH_CMD_EXPORT(list_module, list module in system);
  461. int list_mod_detail(const char *name)
  462. {
  463. int i;
  464. struct rt_module *module;
  465. /* find module */
  466. if ((module = rt_module_find(name)) != RT_NULL)
  467. {
  468. /* module has entry point */
  469. if (!(module->parent.flag & RT_MODULE_FLAG_WITHOUTENTRY))
  470. {
  471. struct rt_thread *thread;
  472. struct rt_list_node *tlist;
  473. rt_uint8_t *ptr;
  474. /* list main thread in module */
  475. if (module->module_thread != RT_NULL)
  476. {
  477. rt_kprintf("main thread pri status sp stack size max used left tick error\n");
  478. rt_kprintf("------------- ---- ------- ---------- ---------- ---------- ---------- ---\n");
  479. thread = module->module_thread;
  480. rt_kprintf("%-8.*s 0x%02x", RT_NAME_MAX, thread->name, thread->current_priority);
  481. if (thread->stat == RT_THREAD_READY) rt_kprintf(" ready ");
  482. else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
  483. else if (thread->stat == RT_THREAD_INIT) rt_kprintf(" init ");
  484. ptr = (rt_uint8_t*)thread->stack_addr;
  485. while (*ptr == '#')ptr ++;
  486. rt_kprintf(" 0x%08x 0x%08x 0x%08x 0x%08x %03d\n",
  487. thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp),
  488. thread->stack_size,
  489. thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr),
  490. thread->remaining_tick,
  491. thread->error);
  492. }
  493. /* list sub thread in module */
  494. tlist = &module->module_object[RT_Object_Class_Thread].object_list;
  495. if (!rt_list_isempty(tlist)) _list_thread(tlist);
  496. #ifdef RT_USING_SEMAPHORE
  497. /* list semaphored in module */
  498. tlist = &module->module_object[RT_Object_Class_Semaphore].object_list;
  499. if (!rt_list_isempty(tlist)) _list_sem(tlist);
  500. #endif
  501. #ifdef RT_USING_MUTEX
  502. /* list mutex in module */
  503. tlist = &module->module_object[RT_Object_Class_Mutex].object_list;
  504. if (!rt_list_isempty(tlist)) _list_mutex(tlist);
  505. #endif
  506. #ifdef RT_USING_EVENT
  507. /* list event in module */
  508. tlist = &module->module_object[RT_Object_Class_Event].object_list;
  509. if (!rt_list_isempty(tlist)) _list_event(tlist);
  510. #endif
  511. #ifdef RT_USING_MAILBOX
  512. /* list mailbox in module */
  513. tlist = &module->module_object[RT_Object_Class_MailBox].object_list;
  514. if (!rt_list_isempty(tlist)) _list_mailbox(tlist);
  515. #endif
  516. #ifdef RT_USING_MESSAGEQUEUE
  517. /* list message queue in module */
  518. tlist = &module->module_object[RT_Object_Class_MessageQueue].object_list;
  519. if (!rt_list_isempty(tlist)) _list_msgqueue(tlist);
  520. #endif
  521. #ifdef RT_USING_MEMHEAP
  522. /* list memory heap in module */
  523. tlist = &module->module_object[RT_Object_Class_MemHeap].object_list;
  524. if (!rt_list_isempty(tlist)) _list_memheap(tlist);
  525. #endif
  526. #ifdef RT_USING_MEMPOOL
  527. /* list memory pool in module */
  528. tlist = &module->module_object[RT_Object_Class_MemPool].object_list;
  529. if (!rt_list_isempty(tlist)) _list_mempool(tlist);
  530. #endif
  531. #ifdef RT_USING_DEVICE
  532. /* list device in module */
  533. tlist = &module->module_object[RT_Object_Class_Device].object_list;
  534. if (!rt_list_isempty(tlist)) _list_device(tlist);
  535. #endif
  536. /* list timer in module */
  537. tlist = &module->module_object[RT_Object_Class_Timer].object_list;
  538. if (!rt_list_isempty(tlist)) _list_timer(tlist);
  539. }
  540. if (module->nsym > 0)
  541. {
  542. rt_kprintf("symbol address \n");
  543. rt_kprintf("-------- ----------\n");
  544. /* list module export symbols */
  545. for (i=0; i<module->nsym; i++)
  546. {
  547. rt_kprintf("%s 0x%x\n",
  548. module->symtab[i].name, module->symtab[i].addr);
  549. }
  550. }
  551. }
  552. return 0;
  553. }
  554. FINSH_FUNCTION_EXPORT(list_mod_detail, list module objects in system)
  555. #endif
  556. long list(void)
  557. {
  558. #ifndef FINSH_USING_MSH_ONLY
  559. struct finsh_syscall_item *syscall_item;
  560. struct finsh_sysvar_item *sysvar_item;
  561. #endif
  562. rt_kprintf("--Function List:\n");
  563. {
  564. struct finsh_syscall *index;
  565. for (index = _syscall_table_begin;
  566. index < _syscall_table_end;
  567. FINSH_NEXT_SYSCALL(index))
  568. {
  569. /* skip the internal command */
  570. if (strncmp((char*)index->name, "__", 2) == 0) continue;
  571. #ifdef FINSH_USING_DESCRIPTION
  572. rt_kprintf("%-16s -- %s\n", index->name, index->desc);
  573. #else
  574. rt_kprintf("%s\n", index->name);
  575. #endif
  576. }
  577. }
  578. #ifndef FINSH_USING_MSH_ONLY
  579. /* list syscall list */
  580. syscall_item = global_syscall_list;
  581. while (syscall_item != NULL)
  582. {
  583. rt_kprintf("[l] %s\n", syscall_item->syscall.name);
  584. syscall_item = syscall_item->next;
  585. }
  586. rt_kprintf("--Variable List:\n");
  587. {
  588. struct finsh_sysvar *index;
  589. for (index = _sysvar_table_begin;
  590. index < _sysvar_table_end;
  591. FINSH_NEXT_SYSVAR(index))
  592. {
  593. #ifdef FINSH_USING_DESCRIPTION
  594. rt_kprintf("%-16s -- %s\n", index->name, index->desc);
  595. #else
  596. rt_kprintf("%s\n", index->name);
  597. #endif
  598. }
  599. }
  600. sysvar_item = global_sysvar_list;
  601. while (sysvar_item != NULL)
  602. {
  603. rt_kprintf("[l] %s\n", sysvar_item->sysvar.name);
  604. sysvar_item = sysvar_item->next;
  605. }
  606. #endif
  607. return 0;
  608. }
  609. FINSH_FUNCTION_EXPORT(list, list all symbol in system)
  610. #ifndef FINSH_USING_MSH_ONLY
  611. static int str_is_prefix(const char *prefix, const char *str)
  612. {
  613. while ((*prefix) && (*prefix == *str))
  614. {
  615. prefix ++;
  616. str ++;
  617. }
  618. if (*prefix == 0)
  619. return 0;
  620. return -1;
  621. }
  622. static int str_common(const char *str1, const char *str2)
  623. {
  624. const char *str = str1;
  625. while ((*str != 0) && (*str2 != 0) && (*str == *str2))
  626. {
  627. str ++;
  628. str2 ++;
  629. }
  630. return (str - str1);
  631. }
  632. void list_prefix(char *prefix)
  633. {
  634. struct finsh_syscall_item *syscall_item;
  635. struct finsh_sysvar_item *sysvar_item;
  636. rt_uint16_t func_cnt, var_cnt;
  637. int length, min_length;
  638. const char *name_ptr;
  639. func_cnt = 0;
  640. var_cnt = 0;
  641. min_length = 0;
  642. name_ptr = RT_NULL;
  643. /* checks in system function call */
  644. {
  645. struct finsh_syscall *index;
  646. for (index = _syscall_table_begin;
  647. index < _syscall_table_end;
  648. FINSH_NEXT_SYSCALL(index))
  649. {
  650. /* skip internal command */
  651. if (str_is_prefix("__", index->name) == 0) continue;
  652. if (str_is_prefix(prefix, index->name) == 0)
  653. {
  654. if (func_cnt == 0)
  655. {
  656. rt_kprintf("--function:\n");
  657. if (*prefix != 0)
  658. {
  659. /* set name_ptr */
  660. name_ptr = index->name;
  661. /* set initial length */
  662. min_length = strlen(name_ptr);
  663. }
  664. }
  665. func_cnt ++;
  666. if (*prefix != 0)
  667. {
  668. length = str_common(name_ptr, index->name);
  669. if (length < min_length)
  670. min_length = length;
  671. }
  672. #ifdef FINSH_USING_DESCRIPTION
  673. rt_kprintf("%-16s -- %s\n", index->name, index->desc);
  674. #else
  675. rt_kprintf("%s\n", index->name);
  676. #endif
  677. }
  678. }
  679. }
  680. /* checks in dynamic system function call */
  681. syscall_item = global_syscall_list;
  682. while (syscall_item != NULL)
  683. {
  684. if (str_is_prefix(prefix, syscall_item->syscall.name) == 0)
  685. {
  686. if (func_cnt == 0)
  687. {
  688. rt_kprintf("--function:\n");
  689. if (*prefix != 0 && name_ptr == NULL)
  690. {
  691. /* set name_ptr */
  692. name_ptr = syscall_item->syscall.name;
  693. /* set initial length */
  694. min_length = strlen(name_ptr);
  695. }
  696. }
  697. func_cnt ++;
  698. if (*prefix != 0)
  699. {
  700. length = str_common(name_ptr, syscall_item->syscall.name);
  701. if (length < min_length)
  702. min_length = length;
  703. }
  704. rt_kprintf("[l] %s\n", syscall_item->syscall.name);
  705. }
  706. syscall_item = syscall_item->next;
  707. }
  708. /* checks in system variable */
  709. {
  710. struct finsh_sysvar* index;
  711. for (index = _sysvar_table_begin;
  712. index < _sysvar_table_end;
  713. FINSH_NEXT_SYSVAR(index))
  714. {
  715. if (str_is_prefix(prefix, index->name) == 0)
  716. {
  717. if (var_cnt == 0)
  718. {
  719. rt_kprintf("--variable:\n");
  720. if (*prefix != 0 && name_ptr == NULL)
  721. {
  722. /* set name_ptr */
  723. name_ptr = index->name;
  724. /* set initial length */
  725. min_length = strlen(name_ptr);
  726. }
  727. }
  728. var_cnt ++;
  729. if (*prefix != 0)
  730. {
  731. length = str_common(name_ptr, index->name);
  732. if (length < min_length)
  733. min_length = length;
  734. }
  735. #ifdef FINSH_USING_DESCRIPTION
  736. rt_kprintf("%-16s -- %s\n", index->name, index->desc);
  737. #else
  738. rt_kprintf("%s\n", index->name);
  739. #endif
  740. }
  741. }
  742. }
  743. /* checks in dynamic system variable */
  744. sysvar_item = global_sysvar_list;
  745. while (sysvar_item != NULL)
  746. {
  747. if (str_is_prefix(prefix, sysvar_item->sysvar.name) == 0)
  748. {
  749. if (var_cnt == 0)
  750. {
  751. rt_kprintf("--variable:\n");
  752. if (*prefix != 0 && name_ptr == NULL)
  753. {
  754. /* set name_ptr */
  755. name_ptr = sysvar_item->sysvar.name;
  756. /* set initial length */
  757. min_length = strlen(name_ptr);
  758. }
  759. }
  760. var_cnt ++;
  761. if (*prefix != 0)
  762. {
  763. length = str_common(name_ptr, sysvar_item->sysvar.name);
  764. if (length < min_length)
  765. min_length = length;
  766. }
  767. rt_kprintf("[v] %s\n", sysvar_item->sysvar.name);
  768. }
  769. sysvar_item = sysvar_item->next;
  770. }
  771. /* only one matched */
  772. if (name_ptr != NULL)
  773. {
  774. rt_strncpy(prefix, name_ptr, min_length);
  775. }
  776. }
  777. #endif
  778. #if defined(FINSH_USING_SYMTAB) && !defined(FINSH_USING_MSH_ONLY)
  779. static int dummy = 0;
  780. FINSH_VAR_EXPORT(dummy, finsh_type_int, dummy variable for finsh)
  781. #endif