gcov.c 1002 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "tools.h"
  2. #include <stdlib.h>
  3. #include <stdarg.h>
  4. const char *gcov; /* = NULL */
  5. bool run_gcov(const void *ctx, unsigned int *time_ms, char **output,
  6. const char *fmt, ...)
  7. {
  8. const char *cmd = gcov;
  9. char *args;
  10. va_list ap;
  11. bool rc;
  12. if (!gcov) {
  13. #if defined(__clang__)
  14. cmd = "llvm-cov gcov";
  15. #elif defined(__GNUC__)
  16. cmd = "gcov";
  17. #endif
  18. }
  19. if (!cmd)
  20. return false;
  21. va_start(ap, fmt);
  22. args = tal_vfmt(ctx, fmt, ap);
  23. rc = run_command(ctx, time_ms, output, "%s %s", cmd, args);
  24. tal_free(args);
  25. return rc;
  26. }
  27. const char *gcov_unavailable(void *ctx)
  28. {
  29. const char *err = NULL;
  30. /*
  31. * If the user has specified a path, assume they know what
  32. * they're doing
  33. */
  34. if (gcov)
  35. return NULL;
  36. #ifdef __GNUC__
  37. unsigned int timeleft = default_timeout_ms;
  38. char *output;
  39. if (!run_gcov(ctx, &timeleft, &output, "-h")) {
  40. err = tal_fmt(ctx, "No gcov support: %s", output);
  41. tal_free(output);
  42. }
  43. #else
  44. err = "No coverage support for this compiler";
  45. #endif
  46. return err;
  47. }