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 "replacements.h"
  24. #include "log.h"
  25. #include "trace.h"
  26. #include "target.h"
  27. #include "command.h"
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <inttypes.h>
  31. int trace_point(target_t *target, int number)
  32. {
  33. trace_t *trace = target->trace_info;
  34. LOG_DEBUG("tracepoint: %i", number);
  35. if (number < trace->num_trace_points)
  36. trace->trace_points[number].hit_counter++;
  37. if (trace->trace_history_size)
  38. {
  39. trace->trace_history[trace->trace_history_pos++] = number;
  40. if (trace->trace_history_pos == trace->trace_history_size)
  41. {
  42. trace->trace_history_pos = 0;
  43. trace->trace_history_overflowed = 1;
  44. }
  45. }
  46. return ERROR_OK;
  47. }
  48. int handle_trace_point_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  49. {
  50. target_t *target = get_current_target(cmd_ctx);
  51. trace_t *trace = target->trace_info;
  52. if (argc == 0)
  53. {
  54. int i;
  55. for (i = 0; i < trace->num_trace_points; i++)
  56. {
  57. command_print(cmd_ctx, "trace point 0x%8.8x (%"PRIi64" times hit)",
  58. trace->trace_points[i].address,
  59. trace->trace_points[i].hit_counter);
  60. }
  61. return ERROR_OK;
  62. }
  63. if (!strcmp(args[0], "clear"))
  64. {
  65. if (trace->trace_points)
  66. {
  67. free(trace->trace_points);
  68. trace->trace_points = NULL;
  69. }
  70. trace->num_trace_points = 0;
  71. trace->trace_points_size = 0;
  72. return ERROR_OK;
  73. }
  74. /* resize array if necessary */
  75. if (!trace->trace_points || (trace->trace_points_size == trace->num_trace_points))
  76. {
  77. trace->trace_points = realloc(trace->trace_points, sizeof(trace_point_t) * (trace->trace_points_size + 32));
  78. trace->trace_points_size += 32;
  79. }
  80. trace->trace_points[trace->num_trace_points].address = strtoul(args[0], NULL, 0);
  81. trace->trace_points[trace->num_trace_points].hit_counter = 0;
  82. trace->num_trace_points++;
  83. return ERROR_OK;
  84. }
  85. int handle_trace_history_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  86. {
  87. target_t *target = get_current_target(cmd_ctx);
  88. trace_t *trace = target->trace_info;
  89. if (argc > 0)
  90. {
  91. trace->trace_history_pos = 0;
  92. trace->trace_history_overflowed = 0;
  93. if (!strcmp(args[0], "clear"))
  94. {
  95. /* clearing is implicit, we've just reset position anyway */
  96. return ERROR_OK;
  97. }
  98. if (trace->trace_history)
  99. free(trace->trace_history);
  100. trace->trace_history_size = strtoul(args[0], NULL, 0);
  101. trace->trace_history = malloc(sizeof(u32) * trace->trace_history_size);
  102. command_print(cmd_ctx, "new trace history size: %i", trace->trace_history_size);
  103. }
  104. else
  105. {
  106. int i;
  107. int first = 0;
  108. int last = trace->trace_history_pos;
  109. if (trace->trace_history_overflowed)
  110. {
  111. first = trace->trace_history_pos;
  112. last = trace->trace_history_pos - 1;
  113. }
  114. for (i = first; (i % trace->trace_history_size) != last; i++)
  115. {
  116. if (trace->trace_history[i % trace->trace_history_size] < trace->num_trace_points)
  117. {
  118. u32 address;
  119. address = trace->trace_points[trace->trace_history[i % trace->trace_history_size]].address;
  120. command_print(cmd_ctx, "trace point %i: 0x%8.8x",
  121. trace->trace_history[i % trace->trace_history_size],
  122. address);
  123. }
  124. else
  125. {
  126. command_print(cmd_ctx, "trace point %i: -not defined-", trace->trace_history[i % trace->trace_history_size]);
  127. }
  128. }
  129. }
  130. return ERROR_OK;
  131. }
  132. int trace_register_commands(struct command_context_s *cmd_ctx)
  133. {
  134. command_t *trace_cmd =
  135. register_command(cmd_ctx, NULL, "trace", NULL, COMMAND_ANY, "trace commands");
  136. register_command(cmd_ctx, trace_cmd, "history", handle_trace_history_command,
  137. COMMAND_EXEC, "display trace history, ['clear'] history or set [size]");
  138. register_command(cmd_ctx, trace_cmd, "point", handle_trace_point_command,
  139. COMMAND_EXEC, "display trace points, ['clear'] list of trace points, or add new tracepoint at [address]");
  140. return ERROR_OK;
  141. }