Blame view
cmd/trace.c
2.87 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
cabcbb56c Add a trace command |
2 3 |
/* * Copyright (c) 2011 The Chromium OS Authors. |
cabcbb56c Add a trace command |
4 5 6 7 |
*/ #include <common.h> #include <command.h> |
c7694dd48 env: Move env_set... |
8 |
#include <env.h> |
0eb25b619 common: Make sure... |
9 |
#include <mapmem.h> |
cabcbb56c Add a trace command |
10 11 12 13 14 15 16 17 18 |
#include <trace.h> #include <asm/io.h> static int get_args(int argc, char * const argv[], char **buff, size_t *buff_ptr, size_t *buff_size) { if (argc < 2) return -1; if (argc < 4) { |
bfebc8c96 env: Rename geten... |
19 20 |
*buff_size = env_get_ulong("profsize", 16, 0); *buff = map_sysmem(env_get_ulong("profbase", 16, 0), |
cabcbb56c Add a trace command |
21 |
*buff_size); |
bfebc8c96 env: Rename geten... |
22 |
*buff_ptr = env_get_ulong("profoffset", 16, 0); |
cabcbb56c Add a trace command |
23 24 25 26 27 28 29 30 31 32 33 |
} else { *buff_size = simple_strtoul(argv[3], NULL, 16); *buff = map_sysmem(simple_strtoul(argv[2], NULL, 16), *buff_size); *buff_ptr = 0; }; return 0; } static int create_func_list(int argc, char * const argv[]) { |
2b7a3882e trace: do not lim... |
34 |
size_t buff_size, avail, buff_ptr, needed, used; |
cabcbb56c Add a trace command |
35 36 37 38 39 40 41 42 43 |
char *buff; int err; if (get_args(argc, argv, &buff, &buff_ptr, &buff_size)) return -1; avail = buff_size - buff_ptr; err = trace_list_functions(buff + buff_ptr, avail, &needed); if (err) |
2b7a3882e trace: do not lim... |
44 45 |
printf("Error: truncated (%#zx bytes needed) ", needed); |
5eca97793 trace: Fix compil... |
46 |
used = min(avail, (size_t)needed); |
cabcbb56c Add a trace command |
47 48 49 |
printf("Function trace dumped to %08lx, size %#zx ", (ulong)map_to_sysmem(buff + buff_ptr), used); |
018f53032 env: Rename commo... |
50 51 52 |
env_set_hex("profbase", map_to_sysmem(buff)); env_set_hex("profsize", buff_size); env_set_hex("profoffset", buff_ptr + used); |
cabcbb56c Add a trace command |
53 54 55 56 57 58 |
return 0; } static int create_call_list(int argc, char * const argv[]) { |
2b7a3882e trace: do not lim... |
59 |
size_t buff_size, avail, buff_ptr, needed, used; |
cabcbb56c Add a trace command |
60 61 62 63 64 65 66 67 68 |
char *buff; int err; if (get_args(argc, argv, &buff, &buff_ptr, &buff_size)) return -1; avail = buff_size - buff_ptr; err = trace_list_calls(buff + buff_ptr, avail, &needed); if (err) |
2b7a3882e trace: do not lim... |
69 70 |
printf("Error: truncated (%#zx bytes needed) ", needed); |
5eca97793 trace: Fix compil... |
71 |
used = min(avail, (size_t)needed); |
cabcbb56c Add a trace command |
72 73 74 |
printf("Call list dumped to %08lx, size %#zx ", (ulong)map_to_sysmem(buff + buff_ptr), used); |
018f53032 env: Rename commo... |
75 76 77 |
env_set_hex("profbase", map_to_sysmem(buff)); env_set_hex("profsize", buff_size); env_set_hex("profoffset", buff_ptr + used); |
cabcbb56c Add a trace command |
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
return 0; } int do_trace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { const char *cmd = argc < 2 ? NULL : argv[1]; if (!cmd) return cmd_usage(cmdtp); switch (*cmd) { case 'p': trace_set_enabled(0); break; case 'c': if (create_call_list(argc, argv)) return cmd_usage(cmdtp); break; case 'r': trace_set_enabled(1); break; case 'f': if (create_func_list(argc, argv)) return cmd_usage(cmdtp); break; case 's': trace_print_stats(); break; default: return CMD_RET_USAGE; } return 0; } U_BOOT_CMD( trace, 4, 1, do_trace, "trace utility commands", "stats - display tracing statistics " "trace pause - pause tracing " "trace resume - resume tracing " "trace funclist [<addr> <size>] - dump function list into buffer " "trace calls [<addr> <size>] " "- dump function call trace into buffer" ); |