1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2011 The Chromium OS Authors.
13 static int get_args(int argc, char * const argv[], char **buff,
14 size_t *buff_ptr, size_t *buff_size)
19 *buff_size = env_get_ulong("profsize", 16, 0);
20 *buff = map_sysmem(env_get_ulong("profbase", 16, 0),
22 *buff_ptr = env_get_ulong("profoffset", 16, 0);
24 *buff_size = simple_strtoul(argv[3], NULL, 16);
25 *buff = map_sysmem(simple_strtoul(argv[2], NULL, 16),
32 static int create_func_list(int argc, char * const argv[])
34 size_t buff_size, avail, buff_ptr, needed, used;
38 if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
41 avail = buff_size - buff_ptr;
42 err = trace_list_functions(buff + buff_ptr, avail, &needed);
44 printf("Error: truncated (%#zx bytes needed)\n", needed);
45 used = min(avail, (size_t)needed);
46 printf("Function trace dumped to %08lx, size %#zx\n",
47 (ulong)map_to_sysmem(buff + buff_ptr), used);
48 env_set_hex("profbase", map_to_sysmem(buff));
49 env_set_hex("profsize", buff_size);
50 env_set_hex("profoffset", buff_ptr + used);
55 static int create_call_list(int argc, char * const argv[])
57 size_t buff_size, avail, buff_ptr, needed, used;
61 if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
64 avail = buff_size - buff_ptr;
65 err = trace_list_calls(buff + buff_ptr, avail, &needed);
67 printf("Error: truncated (%#zx bytes needed)\n", needed);
68 used = min(avail, (size_t)needed);
69 printf("Call list dumped to %08lx, size %#zx\n",
70 (ulong)map_to_sysmem(buff + buff_ptr), used);
72 env_set_hex("profbase", map_to_sysmem(buff));
73 env_set_hex("profsize", buff_size);
74 env_set_hex("profoffset", buff_ptr + used);
79 int do_trace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
81 const char *cmd = argc < 2 ? NULL : argv[1];
84 return cmd_usage(cmdtp);
90 if (create_call_list(argc, argv))
91 return cmd_usage(cmdtp);
97 if (create_func_list(argc, argv))
98 return cmd_usage(cmdtp);
104 return CMD_RET_USAGE;
111 trace, 4, 1, do_trace,
112 "trace utility commands",
113 "stats - display tracing statistics\n"
114 "trace pause - pause tracing\n"
115 "trace resume - resume tracing\n"
116 "trace funclist [<addr> <size>] - dump function list into buffer\n"
117 "trace calls [<addr> <size>] "
118 "- dump function call trace into buffer"