gcov.c 946 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #ifdef __GNUC__
  14. cmd = "gcov";
  15. #endif
  16. }
  17. if (!cmd)
  18. return false;
  19. va_start(ap, fmt);
  20. args = tal_vfmt(ctx, fmt, ap);
  21. rc = run_command(ctx, time_ms, output, "%s %s", cmd, args);
  22. tal_free(args);
  23. return rc;
  24. }
  25. const char *gcov_unavailable(void *ctx)
  26. {
  27. const char *err = NULL;
  28. /*
  29. * If the user has specified a path, assume they know what
  30. * they're doing
  31. */
  32. if (gcov)
  33. return NULL;
  34. #ifdef __GNUC__
  35. unsigned int timeleft = default_timeout_ms;
  36. char *output;
  37. if (!run_gcov(ctx, &timeleft, &output, "-h")) {
  38. err = tal_fmt(ctx, "No gcov support: %s", output);
  39. tal_free(output);
  40. }
  41. #else
  42. err = "No coverage support for this compiler";
  43. #endif
  44. return err;
  45. }