gcov.c 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. va_end(ap);
  26. return rc;
  27. }
  28. const char *gcov_unavailable(void *ctx)
  29. {
  30. const char *err = NULL;
  31. /*
  32. * If the user has specified a path, assume they know what
  33. * they're doing
  34. */
  35. if (gcov)
  36. return NULL;
  37. #ifdef __GNUC__
  38. unsigned int timeleft = default_timeout_ms;
  39. char *output;
  40. if (!run_gcov(ctx, &timeleft, &output, "-h")) {
  41. err = tal_fmt(ctx, "No gcov support: %s", output);
  42. tal_free(output);
  43. }
  44. #else
  45. err = "No coverage support for this compiler";
  46. #endif
  47. return err;
  48. }