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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Copyright (c) 2015-2017 Dmitry V. Levin <ldv@altlinux.org>
  3. * Copyright (c) 2016-2018 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(void, 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;
  47. print_timeval_t(&t);
  48. }
  49. MPERS_PRINTER_DECL(void, print_timeval_utimes,
  50. struct tcb *const tcp, const kernel_ulong_t addr)
  51. {
  52. timeval_t t[2];
  53. if (umove_or_printaddr(tcp, addr, &t))
  54. return;
  55. tprints("[");
  56. print_timeval_t_utime(&t[0]);
  57. tprints(", ");
  58. print_timeval_t_utime(&t[1]);
  59. tprints("]");
  60. }
  61. MPERS_PRINTER_DECL(const char *, sprint_timeval,
  62. struct tcb *const tcp, const kernel_ulong_t addr)
  63. {
  64. timeval_t t;
  65. static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
  66. if (!addr) {
  67. strcpy(buf, "NULL");
  68. } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
  69. umove(tcp, addr, &t)) {
  70. xsprintf(buf, "%#" PRI_klx, addr);
  71. } else {
  72. xsprintf(buf, timeval_fmt,
  73. (long long) t.tv_sec,
  74. zero_extend_signed_to_ull(t.tv_usec));
  75. }
  76. return buf;
  77. }
  78. MPERS_PRINTER_DECL(void, print_itimerval,
  79. struct tcb *const tcp, const kernel_ulong_t addr)
  80. {
  81. timeval_t t[2];
  82. if (umove_or_printaddr(tcp, addr, &t))
  83. return;
  84. tprints("{it_interval=");
  85. print_timeval_t(&t[0]);
  86. tprints(", it_value=");
  87. print_timeval_t(&t[1]);
  88. tprints("}");
  89. }
  90. #ifdef ALPHA
  91. void
  92. print_timeval32_t(const timeval32_t *t)
  93. {
  94. tprintf(timeval_fmt, (long long) t->tv_sec,
  95. zero_extend_signed_to_ull(t->tv_usec));
  96. }
  97. static void
  98. print_timeval32_t_utime(const timeval32_t *t)
  99. {
  100. print_timeval32_t(t);
  101. tprints_comment(sprinttime_usec(t->tv_sec,
  102. zero_extend_signed_to_ull(t->tv_usec)));
  103. }
  104. void
  105. print_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
  106. {
  107. timeval32_t t;
  108. if (umove_or_printaddr(tcp, addr, &t))
  109. return;
  110. print_timeval32_t(&t);
  111. }
  112. void
  113. print_timeval32_utimes(struct tcb *const tcp, const kernel_ulong_t addr)
  114. {
  115. timeval32_t t[2];
  116. if (umove_or_printaddr(tcp, addr, &t))
  117. return;
  118. tprints("[");
  119. print_timeval32_t_utime(&t[0]);
  120. tprints(", ");
  121. print_timeval32_t_utime(&t[1]);
  122. tprints("]");
  123. }
  124. void
  125. print_itimerval32(struct tcb *const tcp, const kernel_ulong_t addr)
  126. {
  127. timeval32_t t[2];
  128. if (umove_or_printaddr(tcp, addr, &t))
  129. return;
  130. tprints("{it_interval=");
  131. print_timeval32_t(&t[0]);
  132. tprints(", it_value=");
  133. print_timeval32_t(&t[1]);
  134. tprints("}");
  135. }
  136. const char *
  137. sprint_timeval32(struct tcb *const tcp, const kernel_ulong_t addr)
  138. {
  139. timeval32_t t;
  140. static char buf[sizeof(timeval_fmt) + 3 * sizeof(t)];
  141. if (!addr) {
  142. strcpy(buf, "NULL");
  143. } else if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
  144. umove(tcp, addr, &t)) {
  145. xsprintf(buf, "%#" PRI_klx, addr);
  146. } else {
  147. xsprintf(buf, timeval_fmt,
  148. (long long) t.tv_sec,
  149. zero_extend_signed_to_ull(t.tv_usec));
  150. }
  151. return buf;
  152. }
  153. #endif /* ALPHA */