cmd.c 30 KB

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