1
0

heap_symShow.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <symLib.h>
  5. #include <sysSymTbl.h>
  6. #include <taskLib.h>
  7. #include "../private.h"
  8. #include "../context.h"
  9. /*--------------------------------------------------------- */
  10. /* VxWorks version of this doesn't use the program_name */
  11. void
  12. lub_heap_init(const char *program_name)
  13. {
  14. program_name = program_name;
  15. /* switch on leak detection */
  16. lub_heap__set_framecount(MAX_BACKTRACE);
  17. }
  18. /*--------------------------------------------------------- */
  19. void
  20. lub_heap_symShow(unsigned address)
  21. {
  22. int value;
  23. char * name;
  24. SYM_TYPE type;
  25. if(OK == symByValueFind(sysSymTbl,address,&name,&value,&type))
  26. {
  27. printf(" %s+%d",name,address-value);
  28. free(name);
  29. }
  30. else
  31. {
  32. printf("UNKNOWN @ %p",(void*)address);
  33. }
  34. }
  35. /*--------------------------------------------------------- */
  36. bool_t
  37. lub_heap_symMatch(unsigned address,
  38. const char *substring)
  39. {
  40. bool_t result = BOOL_FALSE;
  41. int value;
  42. char * name;
  43. SYM_TYPE type;
  44. if(OK == symByValueFind(sysSymTbl,address,&name,&value,&type))
  45. {
  46. if(strstr(name,substring))
  47. {
  48. result = TRUE;
  49. }
  50. free(name);
  51. }
  52. return result;
  53. }
  54. /*--------------------------------------------------------- */
  55. int
  56. leakEnable(unsigned frame_count)
  57. {
  58. taskLock();
  59. lub_heap__set_framecount(frame_count ? frame_count : MAX_BACKTRACE);
  60. taskUnlock();
  61. return 0;
  62. }
  63. /*--------------------------------------------------------- */
  64. int
  65. leakDisable(void)
  66. {
  67. taskLock();
  68. lub_heap__set_framecount(0);
  69. taskUnlock();
  70. return 0;
  71. }
  72. /*--------------------------------------------------------- */
  73. int
  74. leakShow(unsigned how,
  75. const char *substring)
  76. {
  77. /* let's go low priority for this... */
  78. int old_priority = taskPriorityGet(taskIdSelf(),&old_priority);
  79. taskPrioritySet(taskIdSelf(),254);
  80. lub_heap_leak_report(how,substring);
  81. taskPrioritySet(taskIdSelf(),old_priority);
  82. return 0;
  83. }
  84. /*--------------------------------------------------------- */
  85. int
  86. leakScan(unsigned how,
  87. const char *substring)
  88. {
  89. /* let's go low priority for this... */
  90. int old_priority = taskPriorityGet(taskIdSelf(),&old_priority);
  91. taskPrioritySet(taskIdSelf(),254);
  92. lub_heap_leak_scan();
  93. lub_heap_leak_report(how,substring);
  94. taskPrioritySet(taskIdSelf(),old_priority);
  95. return 0;
  96. }
  97. /*--------------------------------------------------------- */
  98. int
  99. leakHelp(void)
  100. {
  101. printf("The following commands can be used for leak detection:\n\n");
  102. printf(" leakHelp - Display this command summary.\n\n");
  103. printf(" leakEnable [frame_count] - Enable leak detection collecting the \n"
  104. " specified number of stack frames.\n\n");
  105. printf(" leakDisable - Disable leak detection, clearing out \n"
  106. " any currently monitored allocations\n\n");
  107. printf(" leakScan [how] [,substring] - Scan and show memory leak details.\n"
  108. " 'how' can be 0 - leaks only [default]\n"
  109. " 1 - leaks and partials\n"
  110. " 2 - all monitored allocations\n\n"
  111. " 'substring' can be specified to only display contexts\n"
  112. " which contain the string in their backtrace\n\n");
  113. printf(" leakShow [how] [,substring] - Display details for currently monitored allocations.\n"
  114. " Leak information will be as per the last scan performed.\n\n");
  115. printf("A 'leak' occurs when there is no reference to any of the memory\n"
  116. "within an allocated block.\n\n"
  117. "A 'partial' leak occurs when there is no reference to the start of\n"
  118. "an allocated block of memory.\n\n");
  119. return 0;
  120. }
  121. /*--------------------------------------------------------- */