2 * Copyright (c) 2011 The Chromium OS Authors.
4 * SPDX-License-Identifier: GPL-2.0+
13 static int get_args(int argc, char * const argv[], char **buff,
14 size_t *buff_ptr, size_t *buff_size)
19 *buff_size = getenv_ulong("profsize", 16, 0);
20 *buff = map_sysmem(getenv_ulong("profbase", 16, 0),
22 *buff_ptr = getenv_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, used;
39 if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
42 avail = buff_size - buff_ptr;
43 err = trace_list_functions(buff + buff_ptr, avail, &needed);
45 printf("Error: truncated (%#x bytes needed)\n", needed);
46 used = min(avail, (size_t)needed);
47 printf("Function trace dumped to %08lx, size %#zx\n",
48 (ulong)map_to_sysmem(buff + buff_ptr), used);
49 setenv_hex("profbase", map_to_sysmem(buff));
50 setenv_hex("profsize", buff_size);
51 setenv_hex("profoffset", buff_ptr + used);
56 static int create_call_list(int argc, char * const argv[])
58 size_t buff_size, avail, buff_ptr, used;
63 if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
66 avail = buff_size - buff_ptr;
67 err = trace_list_calls(buff + buff_ptr, avail, &needed);
69 printf("Error: truncated (%#x bytes needed)\n", needed);
70 used = min(avail, (size_t)needed);
71 printf("Call list dumped to %08lx, size %#zx\n",
72 (ulong)map_to_sysmem(buff + buff_ptr), used);
74 setenv_hex("profbase", map_to_sysmem(buff));
75 setenv_hex("profsize", buff_size);
76 setenv_hex("profoffset", buff_ptr + used);
81 int do_trace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
83 const char *cmd = argc < 2 ? NULL : argv[1];
86 return cmd_usage(cmdtp);
92 if (create_call_list(argc, argv))
93 return cmd_usage(cmdtp);
99 if (create_func_list(argc, argv))
100 return cmd_usage(cmdtp);
106 return CMD_RET_USAGE;
113 trace, 4, 1, do_trace,
114 "trace utility commands",
115 "stats - display tracing statistics\n"
116 "trace pause - pause tracing\n"
117 "trace resume - resume tracing\n"
118 "trace funclist [<addr> <size>] - dump function list into buffer\n"
119 "trace calls [<addr> <size>] "
120 "- dump function call trace into buffer"