heap_stop_here.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. "LUB_HEAP_OK",
  11. "LUB_HEAP_FAILED",
  12. "LUB_HEAP_DOUBLE_FREE",
  13. "LUB_HEAP_CORRUPTED",
  14. "LUB_HEAP_INVALID_POINTER"
  15. };
  16. /*--------------------------------------------------------- */
  17. void
  18. lub_heap_stop_here(lub_heap_status_t status, char *old_ptr, size_t new_size)
  19. {
  20. /* This is provided as a debug aid */
  21. status = status;
  22. old_ptr = old_ptr;
  23. new_size = new_size;
  24. if (lub_heap_verbose_errors) {
  25. switch (status) {
  26. case LUB_HEAP_OK:
  27. case LUB_HEAP_FAILED:
  28. {
  29. /* this is normal */
  30. break;
  31. }
  32. case LUB_HEAP_DOUBLE_FREE:
  33. case LUB_HEAP_CORRUPTED:
  34. case LUB_HEAP_INVALID_POINTER:
  35. {
  36. /* obtain the backtrace of the stack */
  37. stackframe_t frame;
  38. long address;
  39. int i;
  40. lub_heap__get_stackframe(&frame, MAX_BACKTRACE);
  41. /* and output it */
  42. printf("lub_heap_stop_here(%s,%p,%" SIZE_FMT
  43. ")\n", status_names[status], old_ptr,
  44. new_size);
  45. for (i = 0;
  46. (address = (long)frame.backtrace[i]);
  47. i++) {
  48. lub_heap_symShow(address);
  49. printf("\n");
  50. }
  51. }
  52. }
  53. }
  54. }
  55. /*--------------------------------------------------------- */