Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error_prints.h 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * This file contains error printing functions.
  3. * These functions can be used by various binaries included in the strace
  4. * package. Variable 'program_invocation_name' and function 'die()'
  5. * have to be defined globally.
  6. *
  7. * Copyright (c) 2001-2018 The strace developers.
  8. * All rights reserved.
  9. *
  10. * SPDX-License-Identifier: LGPL-2.1-or-later
  11. */
  12. #ifndef STRACE_ERROR_PRINTS_H
  13. # define STRACE_ERROR_PRINTS_H
  14. # include <stdbool.h>
  15. # include "gcc_compat.h"
  16. extern bool debug_flag;
  17. void die(void) ATTRIBUTE_NORETURN;
  18. void error_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
  19. void perror_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
  20. void perror_msg_and_die(const char *fmt, ...)
  21. ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
  22. void error_msg_and_help(const char *fmt, ...)
  23. ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
  24. void error_msg_and_die(const char *fmt, ...)
  25. ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
  26. /* Wrappers for if (debug_flag) error_msg(...) */
  27. # define debug_msg(...) \
  28. do { \
  29. if (debug_flag) \
  30. error_msg(__VA_ARGS__); \
  31. } while (0)
  32. # define debug_perror_msg(...) \
  33. do { \
  34. if (debug_flag) \
  35. perror_msg(__VA_ARGS__); \
  36. } while (0)
  37. /* Simple wrappers for providing function name in error messages */
  38. # define error_func_msg(fmt_, ...) \
  39. error_msg("%s: " fmt_, __func__, ##__VA_ARGS__)
  40. # define perror_func_msg(fmt_, ...) \
  41. perror_msg("%s: " fmt_, __func__, ##__VA_ARGS__)
  42. # define debug_func_msg(fmt_, ...) \
  43. debug_msg("%s: " fmt_, __func__, ##__VA_ARGS__)
  44. # define debug_func_perror_msg(fmt_, ...) \
  45. debug_perror_msg("%s: " fmt_, __func__, ##__VA_ARGS__)
  46. # define error_func_msg_and_die(fmt_, ...) \
  47. error_msg_and_die("%s: " fmt_, __func__, ##__VA_ARGS__)
  48. # define perror_func_msg_and_die(fmt_, ...) \
  49. perror_msg_and_die("%s: " fmt_, __func__, ##__VA_ARGS__)
  50. #endif /* !STRACE_ERROR_PRINTS_H */