2 * Copyright (c) 2011 The Chromium OS Authors.
4 * SPDX-License-Identifier: GPL-2.0+
12 static int get_args(int argc, char * const argv[], char **buff,
13 size_t *buff_ptr, size_t *buff_size)
18 *buff_size = getenv_ulong("profsize", 16, 0);
19 *buff = map_sysmem(getenv_ulong("profbase", 16, 0),
21 *buff_ptr = getenv_ulong("profoffset", 16, 0);
23 *buff_size = simple_strtoul(argv[3], NULL, 16);
24 *buff = map_sysmem(simple_strtoul(argv[2], NULL, 16),
31 static int create_func_list(int argc, char * const argv[])
33 size_t buff_size, avail, buff_ptr, 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 (%#x bytes needed)\n", needed);
45 used = min(avail, needed);
46 printf("Function trace dumped to %08lx, size %#zx\n",
47 (ulong)map_to_sysmem(buff + buff_ptr), used);
48 setenv_hex("profbase", map_to_sysmem(buff));
49 setenv_hex("profsize", buff_size);
50 setenv_hex("profoffset", buff_ptr + used);
55 static int create_call_list(int argc, char * const argv[])
57 size_t buff_size, avail, buff_ptr, used;
62 if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
65 avail = buff_size - buff_ptr;
66 err = trace_list_calls(buff + buff_ptr, avail, &needed);
68 printf("Error: truncated (%#x bytes needed)\n", needed);
69 used = min(avail, needed);
70 printf("Call list dumped to %08lx, size %#zx\n",
71 (ulong)map_to_sysmem(buff + buff_ptr), used);
73 setenv_hex("profbase", map_to_sysmem(buff));
74 setenv_hex("profsize", buff_size);
75 setenv_hex("profoffset", buff_ptr + used);
80 int do_trace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
82 const char *cmd = argc < 2 ? NULL : argv[1];
85 return cmd_usage(cmdtp);
91 if (create_call_list(argc, argv))
92 return cmd_usage(cmdtp);
98 if (create_func_list(argc, argv))
99 return cmd_usage(cmdtp);
105 return CMD_RET_USAGE;
112 trace, 4, 1, do_trace,
113 "trace utility commands",
114 "stats - display tracing statistics\n"
115 "trace pause - pause tracing\n"
116 "trace resume - resume tracing\n"
117 "trace funclist [<addr> <size>] - dump function list into buffer\n"
118 "trace calls [<addr> <size>] "
119 "- dump function call trace into buffer"