heap_stop_here.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <stdio.h>
  2. #include "private.h"
  3. #include "context.h"
  4. /*
  5. * This global variable is used to control error output when
  6. * lub_heap_stop_here is called
  7. */
  8. int lub_heap_verbose_errors = 0;
  9. static const char *status_names[] =
  10. {
  11. "LUB_HEAP_OK",
  12. "LUB_HEAP_FAILED",
  13. "LUB_HEAP_DOUBLE_FREE",
  14. "LUB_HEAP_CORRUPTED",
  15. "LUB_HEAP_INVALID_POINTER"
  16. };
  17. /*--------------------------------------------------------- */
  18. void
  19. lub_heap_stop_here(lub_heap_status_t status,
  20. char *old_ptr,
  21. size_t new_size)
  22. {
  23. /* This is provided as a debug aid */
  24. status = status;
  25. old_ptr = old_ptr;
  26. new_size = new_size;
  27. if(lub_heap_verbose_errors)
  28. {
  29. switch(status)
  30. {
  31. case LUB_HEAP_OK:
  32. case LUB_HEAP_FAILED:
  33. {
  34. /* this is normal */
  35. break;
  36. }
  37. case LUB_HEAP_DOUBLE_FREE:
  38. case LUB_HEAP_CORRUPTED:
  39. case LUB_HEAP_INVALID_POINTER:
  40. {
  41. /* obtain the backtrace of the stack */
  42. stackframe_t frame;
  43. long address;
  44. int i;
  45. lub_heap__get_stackframe(&frame,MAX_BACKTRACE);
  46. /* and output it */
  47. printf("lub_heap_stop_here(%s,%p,%"SIZE_FMT")\n",status_names[status],old_ptr,new_size);
  48. for(i = 0;
  49. (address = (long)frame.backtrace[i]);
  50. i++)
  51. {
  52. lub_heap_symShow(address);
  53. printf("\n");
  54. }
  55. }
  56. }
  57. }
  58. }
  59. /*--------------------------------------------------------- */