cmd_trace.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  17. * MA 02111-1307 USA
  18. */
  19. #include <common.h>
  20. #include <command.h>
  21. #include <trace.h>
  22. #include <asm/io.h>
  23. static int get_args(int argc, char * const argv[], char **buff,
  24. size_t *buff_ptr, size_t *buff_size)
  25. {
  26. if (argc < 2)
  27. return -1;
  28. if (argc < 4) {
  29. *buff_size = getenv_ulong("profsize", 16, 0);
  30. *buff = map_sysmem(getenv_ulong("profbase", 16, 0),
  31. *buff_size);
  32. *buff_ptr = getenv_ulong("profoffset", 16, 0);
  33. } else {
  34. *buff_size = simple_strtoul(argv[3], NULL, 16);
  35. *buff = map_sysmem(simple_strtoul(argv[2], NULL, 16),
  36. *buff_size);
  37. *buff_ptr = 0;
  38. };
  39. return 0;
  40. }
  41. static int create_func_list(int argc, char * const argv[])
  42. {
  43. size_t buff_size, avail, buff_ptr, used;
  44. unsigned int needed;
  45. char *buff;
  46. int err;
  47. if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
  48. return -1;
  49. avail = buff_size - buff_ptr;
  50. err = trace_list_functions(buff + buff_ptr, avail, &needed);
  51. if (err)
  52. printf("Error: truncated (%#x bytes needed)\n", needed);
  53. used = min(avail, needed);
  54. printf("Function trace dumped to %08lx, size %#zx\n",
  55. (ulong)map_to_sysmem(buff + buff_ptr), used);
  56. setenv_hex("profbase", map_to_sysmem(buff));
  57. setenv_hex("profsize", buff_size);
  58. setenv_hex("profoffset", buff_ptr + used);
  59. return 0;
  60. }
  61. static int create_call_list(int argc, char * const argv[])
  62. {
  63. size_t buff_size, avail, buff_ptr, used;
  64. unsigned int needed;
  65. char *buff;
  66. int err;
  67. if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
  68. return -1;
  69. avail = buff_size - buff_ptr;
  70. err = trace_list_calls(buff + buff_ptr, avail, &needed);
  71. if (err)
  72. printf("Error: truncated (%#x bytes needed)\n", needed);
  73. used = min(avail, needed);
  74. printf("Call list dumped to %08lx, size %#zx\n",
  75. (ulong)map_to_sysmem(buff + buff_ptr), used);
  76. setenv_hex("profbase", map_to_sysmem(buff));
  77. setenv_hex("profsize", buff_size);
  78. setenv_hex("profoffset", buff_ptr + used);
  79. return 0;
  80. }
  81. int do_trace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  82. {
  83. const char *cmd = argc < 2 ? NULL : argv[1];
  84. if (!cmd)
  85. return cmd_usage(cmdtp);
  86. switch (*cmd) {
  87. case 'p':
  88. trace_set_enabled(0);
  89. break;
  90. case 'c':
  91. if (create_call_list(argc, argv))
  92. return cmd_usage(cmdtp);
  93. break;
  94. case 'r':
  95. trace_set_enabled(1);
  96. break;
  97. case 'f':
  98. if (create_func_list(argc, argv))
  99. return cmd_usage(cmdtp);
  100. break;
  101. case 's':
  102. trace_print_stats();
  103. break;
  104. default:
  105. return CMD_RET_USAGE;
  106. }
  107. return 0;
  108. }
  109. U_BOOT_CMD(
  110. trace, 4, 1, do_trace,
  111. "trace utility commands",
  112. "stats - display tracing statistics\n"
  113. "trace pause - pause tracing\n"
  114. "trace resume - resume tracing\n"
  115. "trace funclist [<addr> <size>] - dump function list into buffer\n"
  116. "trace calls [<addr> <size>] "
  117. "- dump function call trace into buffer"
  118. );