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.
 
 
 
 
 
 

172 lines
5.2 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005, 2007 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include "log.h"
  24. #include "trace.h"
  25. #include "target.h"
  26. int trace_point(target_t *target, uint32_t number)
  27. {
  28. trace_t *trace = target->trace_info;
  29. LOG_DEBUG("tracepoint: %i", (int)number);
  30. if (number < trace->num_trace_points)
  31. trace->trace_points[number].hit_counter++;
  32. if (trace->trace_history_size)
  33. {
  34. trace->trace_history[trace->trace_history_pos++] = number;
  35. if (trace->trace_history_pos == trace->trace_history_size)
  36. {
  37. trace->trace_history_pos = 0;
  38. trace->trace_history_overflowed = 1;
  39. }
  40. }
  41. return ERROR_OK;
  42. }
  43. COMMAND_HANDLER(handle_trace_point_command)
  44. {
  45. target_t *target = get_current_target(cmd_ctx);
  46. trace_t *trace = target->trace_info;
  47. if (argc == 0)
  48. {
  49. uint32_t i;
  50. for (i = 0; i < trace->num_trace_points; i++)
  51. {
  52. command_print(cmd_ctx, "trace point 0x%8.8" PRIx32 " (%lld times hit)",
  53. trace->trace_points[i].address,
  54. (long long)trace->trace_points[i].hit_counter);
  55. }
  56. return ERROR_OK;
  57. }
  58. if (!strcmp(args[0], "clear"))
  59. {
  60. if (trace->trace_points)
  61. {
  62. free(trace->trace_points);
  63. trace->trace_points = NULL;
  64. }
  65. trace->num_trace_points = 0;
  66. trace->trace_points_size = 0;
  67. return ERROR_OK;
  68. }
  69. /* resize array if necessary */
  70. if (!trace->trace_points || (trace->trace_points_size == trace->num_trace_points))
  71. {
  72. trace->trace_points = realloc(trace->trace_points, sizeof(trace_point_t) * (trace->trace_points_size + 32));
  73. trace->trace_points_size += 32;
  74. }
  75. uint32_t address;
  76. COMMAND_PARSE_NUMBER(u32, args[0], address);
  77. trace->trace_points[trace->num_trace_points].address = address;
  78. trace->trace_points[trace->num_trace_points].hit_counter = 0;
  79. trace->num_trace_points++;
  80. return ERROR_OK;
  81. }
  82. COMMAND_HANDLER(handle_trace_history_command)
  83. {
  84. target_t *target = get_current_target(cmd_ctx);
  85. trace_t *trace = target->trace_info;
  86. if (argc > 0)
  87. {
  88. trace->trace_history_pos = 0;
  89. trace->trace_history_overflowed = 0;
  90. if (!strcmp(args[0], "clear"))
  91. {
  92. /* clearing is implicit, we've just reset position anyway */
  93. return ERROR_OK;
  94. }
  95. if (trace->trace_history)
  96. free(trace->trace_history);
  97. COMMAND_PARSE_NUMBER(u32, args[0], trace->trace_history_size);
  98. trace->trace_history = malloc(sizeof(uint32_t) * trace->trace_history_size);
  99. command_print(cmd_ctx, "new trace history size: %i", (int)(trace->trace_history_size));
  100. }
  101. else
  102. {
  103. uint32_t i;
  104. uint32_t first = 0;
  105. uint32_t last = trace->trace_history_pos;
  106. if (!trace->trace_history_size) {
  107. command_print(cmd_ctx, "trace history buffer is not allocated");
  108. return ERROR_OK;
  109. }
  110. if (trace->trace_history_overflowed)
  111. {
  112. first = trace->trace_history_pos;
  113. last = trace->trace_history_pos - 1;
  114. }
  115. for (i = first; (i % trace->trace_history_size) != last; i++)
  116. {
  117. if (trace->trace_history[i % trace->trace_history_size] < trace->num_trace_points)
  118. {
  119. uint32_t address;
  120. address = trace->trace_points[trace->trace_history[i % trace->trace_history_size]].address;
  121. command_print(cmd_ctx, "trace point %i: 0x%8.8" PRIx32 "",
  122. (int)(trace->trace_history[i % trace->trace_history_size]),
  123. address);
  124. }
  125. else
  126. {
  127. command_print(cmd_ctx, "trace point %i: -not defined-", (int)(trace->trace_history[i % trace->trace_history_size]));
  128. }
  129. }
  130. }
  131. return ERROR_OK;
  132. }
  133. int trace_register_commands(struct command_context_s *cmd_ctx)
  134. {
  135. command_t *trace_cmd =
  136. register_command(cmd_ctx, NULL, "trace", NULL, COMMAND_ANY, "trace commands");
  137. register_command(cmd_ctx, trace_cmd, "history", handle_trace_history_command,
  138. COMMAND_EXEC, "display trace history, ['clear'] history or set [size]");
  139. register_command(cmd_ctx, trace_cmd, "point", handle_trace_point_command,
  140. COMMAND_EXEC, "display trace points, ['clear'] list of trace points, or add new tracepoint at [address]");
  141. return ERROR_OK;
  142. }