cmd.c 30 KB

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