mtrace.awk 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #
  2. # Awk program to analyze mtrace.c output.
  3. #
  4. {
  5. if ($1 == "@") {
  6. where = " (" $2 ")"
  7. n = 3
  8. } else {
  9. where = ""
  10. n = 1
  11. }
  12. if ($n == "+") {
  13. if (allocated[$(n+1)] != "")
  14. print "+", $(n+1), "Alloc", NR, "duplicate:", allocated[$(n+1)], wherewas[$(n+1)], where;
  15. else {
  16. wherewas[$(n+1)] = where;
  17. allocated[$(n+1)] = $(n+2);
  18. }
  19. } else if ($n == "-") {
  20. if (allocated[$(n+1)] != "") {
  21. wherewas[$(n+1)] = "";
  22. allocated[$(n+1)] = "";
  23. if (allocated[$(n+1)] != "")
  24. print "DELETE FAILED", $(n+1), allocated[$(n+1)];
  25. } else
  26. print "-", $(n+1), "Free", NR, "was never alloc'd", where;
  27. } else if ($n == "<") {
  28. if (allocated[$(n+1)] != "") {
  29. wherewas[$(n+1)] = "";
  30. allocated[$(n+1)] = "";
  31. } else
  32. print "-", $(n+1), "Realloc", NR, "was never alloc'd", where;
  33. } else if ($n == ">") {
  34. if (allocated[$(n+1)] != "")
  35. print "+", $(n+1), "Realloc", NR, "duplicate:", allocated[$(n+1)], where;
  36. else {
  37. wherewas[$(n+1)] = $(n+2);
  38. allocated[$(n+1)] = $(n+2);
  39. }
  40. } else if ($n == "=") {
  41. # Ignore "= Start"
  42. } else if ($n == "!") {
  43. # Ignore failed realloc attempts for now
  44. }
  45. }
  46. END {
  47. for (x in allocated)
  48. if (allocated[x] != "")
  49. print "+", x, allocated[x], wherewas[x];
  50. }