cmd.c 28 KB

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