Ohm-Management - Projektarbeit B-ME
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.

usdt_dof_sections.c 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright (c) 2012, Chris Andrews. All rights reserved.
  3. */
  4. #include "usdt_internal.h"
  5. int
  6. usdt_dof_probes_sect(usdt_dof_section_t *probes,
  7. usdt_provider_t *provider, usdt_strtab_t *strtab)
  8. {
  9. usdt_probedef_t *pd;
  10. dof_probe_t p;
  11. dof_stridx_t type, argv;
  12. uint8_t argc, i;
  13. uint32_t argidx = 0;
  14. uint32_t offidx = 0;
  15. usdt_dof_section_init(probes, DOF_SECT_PROBES, 1);
  16. for (pd = provider->probedefs; pd != NULL; pd = pd->next) {
  17. argc = 0;
  18. argv = 0;
  19. type = 0;
  20. for (i = 0; i < pd->argc; i++) {
  21. type = usdt_strtab_add(strtab, pd->types[i]);
  22. argc++;
  23. if (argv == 0)
  24. argv = type;
  25. }
  26. if (usdt_create_tracepoints(pd->probe) < 0) {
  27. usdt_error(provider, USDT_ERROR_VALLOC);
  28. return (-1);
  29. }
  30. #ifdef __x86_64__
  31. p.dofpr_addr = (uint64_t) pd->probe->isenabled_addr;
  32. #elif __i386__ || __i386
  33. p.dofpr_addr = (uint32_t) pd->probe->isenabled_addr;
  34. #else
  35. #error "only x86_64 and i386 supported"
  36. #endif
  37. p.dofpr_func = usdt_strtab_add(strtab, pd->function);
  38. p.dofpr_name = usdt_strtab_add(strtab, pd->name);
  39. p.dofpr_nargv = argv;
  40. p.dofpr_xargv = argv;
  41. p.dofpr_argidx = argidx;
  42. p.dofpr_offidx = offidx;
  43. p.dofpr_nargc = argc;
  44. p.dofpr_xargc = argc;
  45. p.dofpr_noffs = 1;
  46. p.dofpr_enoffidx = offidx;
  47. p.dofpr_nenoffs = 1;
  48. p.dofpr_pad1 = 0;
  49. p.dofpr_pad2 = 0;
  50. usdt_dof_section_add_data(probes, &p, sizeof(dof_probe_t));
  51. probes->entsize = sizeof(dof_probe_t);
  52. argidx += argc;
  53. offidx++;
  54. }
  55. return (0);
  56. }
  57. int
  58. usdt_dof_prargs_sect(usdt_dof_section_t *prargs, usdt_provider_t *provider)
  59. {
  60. usdt_probedef_t *pd;
  61. uint8_t i;
  62. usdt_dof_section_init(prargs, DOF_SECT_PRARGS, 2);
  63. prargs->entsize = 1;
  64. for (pd = provider->probedefs; pd != NULL; pd = pd->next) {
  65. for (i = 0; i < pd->argc; i++)
  66. usdt_dof_section_add_data(prargs, &i, 1);
  67. }
  68. if (prargs->size == 0) {
  69. i = 0;
  70. if (usdt_dof_section_add_data(prargs, &i, 1) < 0) {
  71. usdt_error(provider, USDT_ERROR_MALLOC);
  72. return (-1);
  73. }
  74. }
  75. return (0);
  76. }
  77. int
  78. usdt_dof_proffs_sect(usdt_dof_section_t *proffs,
  79. usdt_provider_t *provider, char *dof)
  80. {
  81. usdt_probedef_t *pd;
  82. uint32_t off;
  83. usdt_dof_section_init(proffs, DOF_SECT_PROFFS, 3);
  84. proffs->entsize = 4;
  85. for (pd = provider->probedefs; pd != NULL; pd = pd->next) {
  86. off = usdt_probe_offset(pd->probe, dof, pd->argc);
  87. if (usdt_dof_section_add_data(proffs, &off, 4) < 0) {
  88. usdt_error(provider, USDT_ERROR_MALLOC);
  89. return (-1);
  90. }
  91. }
  92. return (0);
  93. }
  94. int
  95. usdt_dof_prenoffs_sect(usdt_dof_section_t *prenoffs,
  96. usdt_provider_t *provider, char *dof)
  97. {
  98. usdt_probedef_t *pd;
  99. uint32_t off;
  100. usdt_dof_section_init(prenoffs, DOF_SECT_PRENOFFS, 4);
  101. prenoffs->entsize = 4;
  102. for (pd = provider->probedefs; pd != NULL; pd = pd->next) {
  103. off = usdt_is_enabled_offset(pd->probe, dof);
  104. if (usdt_dof_section_add_data(prenoffs, &off, 4) < 0) {
  105. usdt_error(provider, USDT_ERROR_MALLOC);
  106. return (-1);
  107. }
  108. }
  109. return (0);
  110. }
  111. int
  112. usdt_dof_provider_sect(usdt_dof_section_t *provider_s, usdt_provider_t *provider)
  113. {
  114. dof_provider_t p;
  115. usdt_dof_section_init(provider_s, DOF_SECT_PROVIDER, 5);
  116. p.dofpv_strtab = 0;
  117. p.dofpv_probes = 1;
  118. p.dofpv_prargs = 2;
  119. p.dofpv_proffs = 3;
  120. p.dofpv_prenoffs = 4;
  121. p.dofpv_name = 1; /* provider name always first strtab entry. */
  122. /*
  123. * Stability is something of a hack. Everything is marked *
  124. * "stable" here to permit use of the "args" array, which is *
  125. * needed to access arguments past "arg9".
  126. *
  127. * It should be up to the creator of the provider to decide
  128. * this, though, and it should be possible to set the
  129. * appropriate stability at creation time.
  130. */
  131. p.dofpv_provattr = DOF_ATTR(DTRACE_STABILITY_STABLE,
  132. DTRACE_STABILITY_STABLE,
  133. DTRACE_STABILITY_STABLE);
  134. p.dofpv_modattr = DOF_ATTR(DTRACE_STABILITY_STABLE,
  135. DTRACE_STABILITY_STABLE,
  136. DTRACE_STABILITY_STABLE);
  137. p.dofpv_funcattr = DOF_ATTR(DTRACE_STABILITY_STABLE,
  138. DTRACE_STABILITY_STABLE,
  139. DTRACE_STABILITY_STABLE);
  140. p.dofpv_nameattr = DOF_ATTR(DTRACE_STABILITY_STABLE,
  141. DTRACE_STABILITY_STABLE,
  142. DTRACE_STABILITY_STABLE);
  143. p.dofpv_argsattr = DOF_ATTR(DTRACE_STABILITY_STABLE,
  144. DTRACE_STABILITY_STABLE,
  145. DTRACE_STABILITY_STABLE);
  146. if ((usdt_dof_section_add_data(provider_s, &p, sizeof(p))) < 0) {
  147. usdt_error(provider, USDT_ERROR_MALLOC);
  148. return (-1);
  149. }
  150. return (0);
  151. }