cmd.c 26 KB

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