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.

print_timeval.c 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
  3. * Copyright (c) 2016-2019 The strace developers.
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: LGPL-2.1-or-later
  7. */
  8. #include "defs.h"
  9. #include DEF_MPERS_TYPE(timeval_t)
  10. typedef struct timeval timeval_t;
  11. #include MPERS_DEFS
  12. #include "xstring.h"
  13. static const char timeval_fmt[] = "{tv_sec=%lld, tv_usec=%llu}";
  14. static void
  15. print_timeval_t(const timeval_t *t)
  16. {
  17. tprintf(timeval_fmt, (long long) t->tv_sec,
  18. zero_extend_signed_to_ull(t->tv_usec));
  19. }
  20. static void
  21. print_timeval_t_utime(const timeval_t *t)
  22. {
  23. print_timeval_t(t);
  24. tprints_comment(sprinttime_usec(t->tv_sec,
  25. zero_extend_signed_to_ull(t->tv_usec)));
  26. }
  27. MPERS_PRINTER_DECL(void, print_struct_timeval, const void *arg)
  28. {
  29. print_timeval_t(arg);
  30. }
  31. MPERS_PRINTER_DECL(bool, print_struct_timeval_data_size,
  32. const void *arg, const size_t size)
  33. {
  34. if (size < sizeof(timeval_t)) {
  35. tprints("?");
  36. return false;
  37. }
  38. print_timeval_t(arg);
  39. return true;
  40. }
  41. MPERS_PRINTER_DECL(int, print_timeval,
  42. struct tcb *const tcp, const kernel_ulong_t addr)
  43. {
  44. timeval_t t;
  45. if (umove_or_printaddr(tcp, addr, &t))
  46. return -1;
  47. print_timeval_t(&t);
  48. return 0;
  49. }
  50. MPERS_PRINTER_DECL(int, print_timeval_utimes,
  51. struct tcb *const tcp, const kernel_ulong_t addr)
  52. {
  53. timeval_t t[2];
  54. if (umove_or_printaddr(tcp, addr, &t))
  55. return -1;
  56. tprints("[");
  57. print_timeval_t_utime(&t[0]);
  58. tprints(", ");
  59. print_timeval_t_utime(&t[1]);
  60. tprints("]");
  61. return 0;
  62. }
  63. MPERS_PRINTER_DECL(const char *, sprint_timeval,
  64. struct tcb *const tcp, const kernel_ulong_t addr)
  65. {
  66. timeval_t t;
  67. static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
  68. if (!addr) {
  69. strcpy(buf, "NULL");
  70. } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
  71. umove(tcp, addr, &t)) {
  72. xsprintf(buf, "%#" PRI_klx, addr);
  73. } else {
  74. xsprintf(buf, timeval_fmt,
  75. (long long) t.tv_sec,
  76. zero_extend_signed_to_ull(t.tv_usec));
  77. }
  78. return buf;
  79. }
  80. MPERS_PRINTER_DECL(int, print_itimerval,
  81. struct tcb *const tcp, const kernel_ulong_t addr)
  82. {
  83. timeval_t t[2];
  84. if (umove_or_printaddr(tcp, addr, &t))
  85. return -1;
  86. tprints("{it_interval=");
  87. print_timeval_t(&t[0]);
  88. tprints(", it_value=");
  89. print_timeval_t(&t[1]);
  90. tprints("}");
  91. return 0;
  92. }
  93. #ifdef ALPHA
  94. void
  95. print_timeval32_t(const timeval32_t *t)
  96. {
  97. tprintf(timeval_fmt, (long long) t->tv_sec,
  98. zero_extend_signed_to_ull(t->tv_usec));
  99. }
  100. static void
  101. print_timeval32_t_utime(const timeval32_t *t)
  102. {
  103. print_timeval32_t(t);
  104. tprints_comment(sprinttime_usec(t->tv_sec,
  105. zero_extend_signed_to_ull(t->tv_usec)));
  106. }
  107. int
  108. print_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
  109. {
  110. timeval32_t t;
  111. if (umove_or_printaddr(tcp, addr, &t))
  112. return -1;
  113. print_timeval32_t(&t);
  114. return 0;
  115. }
  116. int
  117. print_timeval32_utimes(struct tcb *const tcp, const kernel_ulong_t addr)
  118. {
  119. timeval32_t t[2];
  120. if (umove_or_printaddr(tcp, addr, &t))
  121. return -1;
  122. tprints("[");
  123. print_timeval32_t_utime(&t[0]);
  124. tprints(", ");
  125. print_timeval32_t_utime(&t[1]);
  126. tprints("]");
  127. return 0;
  128. }
  129. int
  130. print_itimerval32(struct tcb *const tcp, const kernel_ulong_t addr)
  131. {
  132. timeval32_t t[2];
  133. if (umove_or_printaddr(tcp, addr, &t))
  134. return -1;
  135. tprints("{it_interval=");
  136. print_timeval32_t(&t[0]);
  137. tprints(", it_value=");
  138. print_timeval32_t(&t[1]);
  139. tprints("}");
  140. return 0;
  141. }
  142. const char *
  143. sprint_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
  144. {
  145. timeval32_t t;
  146. static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
  147. if (!addr) {
  148. strcpy(buf, "NULL");
  149. } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
  150. umove(tcp, addr, &t)) {
  151. xsprintf(buf, "%#" PRI_klx, addr);
  152. } else {
  153. xsprintf(buf, timeval_fmt,
  154. (long long) t.tv_sec,
  155. zero_extend_signed_to_ull(t.tv_usec));
  156. }
  157. return buf;
  158. }
  159. #endif /* ALPHA */