Rev 2937 | Rev 2939 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2911 | svoboda | 1 | /* |
2 | * Copyright (c) 2008 Jiri Svoboda |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
29 | /** @addtogroup debug |
||
30 | * @{ |
||
31 | */ |
||
32 | /** @file |
||
33 | */ |
||
34 | |||
35 | #include <stdio.h> |
||
36 | #include <stdlib.h> |
||
37 | #include <string.h> |
||
38 | #include <bool.h> |
||
2915 | svoboda | 39 | #include <udebug.h> |
40 | #include <sys/types.h> |
||
2911 | svoboda | 41 | |
2915 | svoboda | 42 | #include "main.h" |
2936 | svoboda | 43 | #include "cons.h" |
2938 | svoboda | 44 | #include "dthread.h" |
2923 | svoboda | 45 | #include "include/arch.h" |
2911 | svoboda | 46 | #include "cmd.h" |
47 | |||
48 | static void cmd_break(int argc, char *argv[]); |
||
2937 | svoboda | 49 | static void cmd_ct(int argc, char *argv[]); |
50 | static void cmd_go(int argc, char *argv[]); |
||
2911 | svoboda | 51 | void cmd_help(int argc, char *argv[]); |
2937 | svoboda | 52 | static void cmd_pwt(int argc, char *argv[]); |
2915 | svoboda | 53 | static void cmd_read(int argc, char *argv[]); |
2937 | svoboda | 54 | static void cmd_step(int argc, char *argv[]); |
55 | static void cmd_threads(int argc, char *argv[]); |
||
2911 | svoboda | 56 | static void cmd_quit(int argc, char *argv[]); |
57 | |||
58 | volatile bool quit = false; |
||
59 | |||
60 | cmd_desc_t cmd_table[] = { |
||
61 | { 1, "break", cmd_break }, |
||
2937 | svoboda | 62 | { 1, "ct", cmd_ct }, |
2935 | svoboda | 63 | { 0, "go", cmd_go }, |
2911 | svoboda | 64 | { 0, "help", cmd_help }, |
2937 | svoboda | 65 | { 0, "pwt", cmd_pwt }, |
2915 | svoboda | 66 | { 2, "read", cmd_read }, |
2937 | svoboda | 67 | { 0, "threads", cmd_threads }, |
2911 | svoboda | 68 | { 0, "quit", cmd_quit }, |
69 | { -1, NULL, NULL } |
||
70 | }; |
||
71 | |||
72 | static void cmd_break(int argc, char *argv[]) |
||
73 | { |
||
74 | uintptr_t addr; |
||
75 | |||
76 | (void)argc; |
||
77 | addr = strtoul(argv[1], NULL, 0); |
||
78 | |||
2936 | svoboda | 79 | cons_printf("You requested a breakpoint at 0x%x\n", addr); |
2923 | svoboda | 80 | arch_breakpoint_add(addr); |
2911 | svoboda | 81 | } |
82 | |||
2937 | svoboda | 83 | static void cmd_ct(int argc, char *argv[]) |
84 | { |
||
85 | int tid; |
||
86 | |||
2938 | svoboda | 87 | link_t *cur; |
88 | dthread_t *dt; |
||
89 | |||
2937 | svoboda | 90 | (void)argc; |
91 | tid = strtoul(argv[1], NULL, 0); |
||
92 | |||
2938 | svoboda | 93 | dt = NULL; |
94 | for (cur = dthreads.next; cur != &dthreads; cur = cur->next) { |
||
95 | dt = list_get_instance(cur, dthread_t, link); |
||
96 | if (dt->id == tid) break; |
||
2937 | svoboda | 97 | } |
98 | |||
2938 | svoboda | 99 | if (dt->id == tid) { |
100 | cwt = dt; |
||
2937 | svoboda | 101 | cons_printf("changed working thread to: %d [hash 0x%x]\n", |
2938 | svoboda | 102 | cwt->id, cwt->hash); |
2937 | svoboda | 103 | } else { |
104 | cons_printf("no such thread\n"); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | |||
2935 | svoboda | 109 | void cmd_go(int argc, char *argv[]) |
110 | { |
||
111 | fcv_broadcast(&go_cv); |
||
112 | } |
||
113 | |||
2911 | svoboda | 114 | void cmd_help(int argc, char *argv[]) |
115 | { |
||
116 | int i; |
||
117 | |||
118 | (void)argc; (void)argv; |
||
119 | i = 0; |
||
120 | while (cmd_table[i].name != NULL) { |
||
2936 | svoboda | 121 | cons_printf("%s\n", cmd_table[i].name); |
2911 | svoboda | 122 | ++i; |
123 | } |
||
124 | } |
||
125 | |||
2915 | svoboda | 126 | #define BYTES_PER_LINE 16 |
127 | |||
128 | static void cmd_read(int argc, char *argv[]) |
||
129 | { |
||
130 | uintptr_t addr; |
||
131 | size_t length; |
||
132 | uint8_t buf[BYTES_PER_LINE]; |
||
133 | int to_read, i; |
||
134 | int rc; |
||
135 | |||
136 | (void)argc; |
||
137 | addr = strtoul(argv[1], NULL, 0); |
||
138 | length = strtoul(argv[2], NULL, 0); |
||
139 | |||
140 | while (length > 0) { |
||
141 | to_read = length < BYTES_PER_LINE ? length : BYTES_PER_LINE; |
||
142 | |||
143 | rc = udebug_mem_read(app_phone, buf, addr, to_read); |
||
144 | if (rc < 0) { |
||
2936 | svoboda | 145 | cons_printf("error %d\n", rc); |
2915 | svoboda | 146 | return; |
147 | } |
||
148 | |||
2936 | svoboda | 149 | cons_printf("0x%x:", addr); |
2915 | svoboda | 150 | for (i = 0; i < to_read; ++i) { |
2936 | svoboda | 151 | cons_printf(" %02x", buf[i]); |
2915 | svoboda | 152 | } |
153 | for (i = to_read; i < BYTES_PER_LINE; ++i) { |
||
2936 | svoboda | 154 | cons_printf(" "); |
2915 | svoboda | 155 | } |
156 | |||
157 | putchar ('\t'); |
||
158 | |||
159 | for (i = 0; i < to_read; ++i) { |
||
160 | if (buf[i] >= 32 && buf[i] < 127) |
||
161 | putchar(buf[i]); |
||
162 | else |
||
163 | putchar('.'); |
||
164 | } |
||
2936 | svoboda | 165 | cons_printf("\n"); |
2915 | svoboda | 166 | |
167 | addr += to_read; |
||
168 | length -= to_read; |
||
169 | } |
||
170 | } |
||
171 | |||
2937 | svoboda | 172 | void cmd_step(int argc, char *argv[]) |
173 | { |
||
174 | fcv_broadcast(&go_cv); |
||
175 | } |
||
2915 | svoboda | 176 | |
2937 | svoboda | 177 | void cmd_pwt(int argc, char *argv[]) |
178 | { |
||
179 | (void)argc; (void)argv; |
||
2938 | svoboda | 180 | |
181 | cons_printf("working thread: %d [hash 0x%x]\n", cwt->id, cwt->hash); |
||
2937 | svoboda | 182 | } |
183 | |||
184 | void cmd_threads(int argc, char *argv[]) |
||
185 | { |
||
2938 | svoboda | 186 | link_t *cur; |
187 | dthread_t *dt; |
||
2937 | svoboda | 188 | |
2938 | svoboda | 189 | (void)argc; |
190 | |||
191 | dt = NULL; |
||
192 | for (cur = dthreads.next; cur != &dthreads; cur = cur->next) { |
||
193 | dt = list_get_instance(cur, dthread_t, link); |
||
194 | cons_printf("%d [hash 0x%x]\n", dt->id, dt->hash); |
||
195 | } |
||
2937 | svoboda | 196 | } |
197 | |||
198 | |||
2911 | svoboda | 199 | static void cmd_quit(int argc, char *argv[]) |
200 | { |
||
201 | (void)argc; (void)argv; |
||
202 | quit = true; |
||
203 | } |
||
204 | |||
205 | /** @} |
||
206 | */ |