The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 1 | /* Copyright (C) 2007-2008 The Android Open Source Project |
| 2 | ** |
| 3 | ** This software is licensed under the terms of the GNU General Public |
| 4 | ** License version 2, as published by the Free Software Foundation, and |
| 5 | ** may be copied, distributed, and modified under those terms. |
| 6 | ** |
| 7 | ** This program is distributed in the hope that it will be useful, |
| 8 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | ** GNU General Public License for more details. |
| 11 | */ |
| 12 | /* |
| 13 | * Virtual hardware for bridging the FUSE kernel module |
| 14 | * in the emulated OS and outside file system |
| 15 | */ |
| 16 | #include "qemu_file.h" |
| 17 | #include "goldfish_trace.h" |
David 'Digit' Turner | 4e024bb | 2010-09-22 14:19:28 +0200 | [diff] [blame] | 18 | #include "sysemu.h" |
| 19 | #include "trace.h" |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 20 | #ifdef CONFIG_MEMCHECK |
| 21 | #include "memcheck/memcheck.h" |
David 'Digit' Turner | 4e024bb | 2010-09-22 14:19:28 +0200 | [diff] [blame] | 22 | #include "memcheck/memcheck_util.h" |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 23 | #endif // CONFIG_MEMCHECK |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 24 | |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 25 | /* Set to 1 to debug tracing */ |
| 26 | #define DEBUG 0 |
| 27 | |
| 28 | #if DEBUG |
| 29 | # define D(...) printf(__VA_ARGS__), fflush(stdout) |
| 30 | #else |
| 31 | # define D(...) ((void)0) |
| 32 | #endif |
| 33 | |
| 34 | /* Set to 1 to debug PID tracking */ |
| 35 | #define DEBUG_PID 0 |
| 36 | |
| 37 | #if DEBUG_PID |
| 38 | # define DPID(...) printf(__VA_ARGS__), fflush(stdout) |
| 39 | #else |
| 40 | # define DPID(...) ((void)0) |
| 41 | #endif |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 42 | |
| 43 | extern void cpu_loop_exit(void); |
| 44 | |
| 45 | extern int tracing; |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 46 | extern const char *trace_filename; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 47 | |
| 48 | /* for execve */ |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 49 | static char exec_path[CLIENT_PAGE_SIZE]; |
| 50 | static char exec_arg[CLIENT_PAGE_SIZE]; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 51 | static unsigned long vstart; // VM start |
| 52 | static unsigned long vend; // VM end |
| 53 | static unsigned long eoff; // offset in EXE file |
| 54 | static unsigned cmdlen; // cmdline length |
| 55 | static unsigned pid; // PID (really thread id) |
| 56 | static unsigned tgid; // thread group id (really process id) |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 57 | static unsigned tid; // current thread id (same as pid, most of the time) |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 58 | static unsigned long dsaddr; // dynamic symbol address |
| 59 | static unsigned long unmap_start; // start address to unmap |
| 60 | |
| 61 | /* for context switch */ |
| 62 | //static unsigned long cs_pid; // context switch PID |
| 63 | |
| 64 | /* I/O write */ |
| 65 | static void trace_dev_write(void *opaque, target_phys_addr_t offset, uint32_t value) |
| 66 | { |
| 67 | trace_dev_state *s = (trace_dev_state *)opaque; |
| 68 | |
David 'Digit' Turner | 4e024bb | 2010-09-22 14:19:28 +0200 | [diff] [blame] | 69 | (void)s; |
| 70 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 71 | switch (offset >> 2) { |
| 72 | case TRACE_DEV_REG_SWITCH: // context switch, switch to pid |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 73 | DPID("QEMU.trace: context switch tid=%u\n", value); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 74 | if (trace_filename != NULL) { |
| 75 | trace_switch(value); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 76 | D("QEMU.trace: kernel, context switch %u\n", value); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 77 | } |
| 78 | #ifdef CONFIG_MEMCHECK |
| 79 | if (memcheck_enabled) { |
| 80 | memcheck_switch(value); |
| 81 | } |
| 82 | #endif // CONFIG_MEMCHECK |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 83 | tid = (unsigned) value; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 84 | break; |
| 85 | case TRACE_DEV_REG_TGID: // save the tgid for the following fork/clone |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 86 | DPID("QEMU.trace: tgid=%u\n", value); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 87 | tgid = value; |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 88 | if (trace_filename != NULL) { |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 89 | D("QEMU.trace: kernel, tgid %u\n", value); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 90 | } |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 91 | break; |
| 92 | case TRACE_DEV_REG_FORK: // fork, fork new pid |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 93 | DPID("QEMU.trace: fork (pid=%d tgid=%d value=%d)\n", pid, tgid, value); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 94 | if (trace_filename != NULL) { |
| 95 | trace_fork(tgid, value); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 96 | D("QEMU.trace: kernel, fork %u\n", value); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 97 | } |
| 98 | #ifdef CONFIG_MEMCHECK |
| 99 | if (memcheck_enabled) { |
| 100 | memcheck_fork(tgid, value); |
| 101 | } |
| 102 | #endif // CONFIG_MEMCHECK |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 103 | break; |
| 104 | case TRACE_DEV_REG_CLONE: // fork, clone new pid (i.e. thread) |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 105 | DPID("QEMU.trace: clone (pid=%d tgid=%d value=%d)\n", pid, tgid, value); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 106 | if (trace_filename != NULL) { |
| 107 | trace_clone(tgid, value); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 108 | D("QEMU.trace: kernel, clone %u\n", value); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 109 | } |
| 110 | #ifdef CONFIG_MEMCHECK |
| 111 | if (memcheck_enabled) { |
| 112 | memcheck_clone(tgid, value); |
| 113 | } |
| 114 | #endif // CONFIG_MEMCHECK |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 115 | break; |
| 116 | case TRACE_DEV_REG_EXECVE_VMSTART: // execve, vstart |
| 117 | vstart = value; |
| 118 | break; |
| 119 | case TRACE_DEV_REG_EXECVE_VMEND: // execve, vend |
| 120 | vend = value; |
| 121 | break; |
| 122 | case TRACE_DEV_REG_EXECVE_OFFSET: // execve, offset in EXE |
| 123 | eoff = value; |
| 124 | break; |
| 125 | case TRACE_DEV_REG_EXECVE_EXEPATH: // init exec, path of EXE |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 126 | vstrcpy(value, exec_path, CLIENT_PAGE_SIZE); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 127 | if (trace_filename != NULL) { |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 128 | trace_init_exec(vstart, vend, eoff, exec_path); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 129 | D("QEMU.trace: kernel, init exec [%lx,%lx]@%lx [%s]\n", |
| 130 | vstart, vend, eoff, exec_path); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 131 | } |
| 132 | #ifdef CONFIG_MEMCHECK |
| 133 | if (memcheck_enabled) { |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 134 | if (exec_path[0] == '\0') { |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 135 | // vstrcpy may fail to copy path. In this case lets do it |
| 136 | // differently. |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 137 | memcheck_get_guest_kernel_string(exec_path, value, CLIENT_PAGE_SIZE); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 138 | } |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 139 | memcheck_mmap_exepath(vstart, vend, eoff, exec_path); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 140 | } |
| 141 | #endif // CONFIG_MEMCHECK |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 142 | exec_path[0] = 0; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 143 | break; |
| 144 | case TRACE_DEV_REG_CMDLINE_LEN: // execve, process cmdline length |
| 145 | cmdlen = value; |
| 146 | break; |
| 147 | case TRACE_DEV_REG_CMDLINE: // execve, process cmdline |
David 'Digit' Turner | 4e024bb | 2010-09-22 14:19:28 +0200 | [diff] [blame] | 148 | cpu_memory_rw_debug(cpu_single_env, value, (uint8_t*)exec_arg, cmdlen, 0); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 149 | if (trace_filename != NULL) { |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 150 | trace_execve(exec_arg, cmdlen); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 151 | } |
| 152 | #ifdef CONFIG_MEMCHECK |
| 153 | if (memcheck_enabled) { |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 154 | memcheck_set_cmd_line(exec_arg, cmdlen); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 155 | } |
| 156 | #endif // CONFIG_MEMCHECK |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 157 | #if DEBUG || DEBUG_PID |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 158 | if (trace_filename != NULL) { |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 159 | int i; |
| 160 | for (i = 0; i < cmdlen; i ++) |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 161 | if (i != cmdlen - 1 && exec_arg[i] == 0) |
| 162 | exec_arg[i] = ' '; |
| 163 | printf("QEMU.trace: kernel, execve %s[%d]\n", exec_arg, cmdlen); |
| 164 | exec_arg[0] = 0; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 165 | } |
| 166 | #endif |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 167 | break; |
| 168 | case TRACE_DEV_REG_EXIT: // exit, exit current process with exit code |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 169 | DPID("QEMU.trace: exit tid=%u\n", value); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 170 | if (trace_filename != NULL) { |
| 171 | trace_exit(value); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 172 | D("QEMU.trace: kernel, exit %x\n", value); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 173 | } |
| 174 | #ifdef CONFIG_MEMCHECK |
| 175 | if (memcheck_enabled) { |
| 176 | memcheck_exit(value); |
| 177 | } |
| 178 | #endif // CONFIG_MEMCHECK |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 179 | break; |
| 180 | case TRACE_DEV_REG_NAME: // record thread name |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 181 | vstrcpy(value, exec_path, CLIENT_PAGE_SIZE); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 182 | DPID("QEMU.trace: thread name=%s\n", exec_path); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 183 | |
| 184 | // Remove the trailing newline if it exists |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 185 | int len = strlen(exec_path); |
| 186 | if (exec_path[len - 1] == '\n') { |
| 187 | exec_path[len - 1] = 0; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 188 | } |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 189 | if (trace_filename != NULL) { |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 190 | trace_name(exec_path); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 191 | D("QEMU.trace: kernel, name %s\n", exec_path); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 192 | } |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 193 | break; |
| 194 | case TRACE_DEV_REG_MMAP_EXEPATH: // mmap, path of EXE, the others are same as execve |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 195 | vstrcpy(value, exec_path, CLIENT_PAGE_SIZE); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 196 | DPID("QEMU.trace: mmap exe=%s\n", exec_path); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 197 | if (trace_filename != NULL) { |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 198 | trace_mmap(vstart, vend, eoff, exec_path); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 199 | D("QEMU.trace: kernel, mmap [%lx,%lx]@%lx [%s]\n", vstart, vend, eoff, exec_path); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 200 | } |
| 201 | #ifdef CONFIG_MEMCHECK |
| 202 | if (memcheck_enabled) { |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 203 | if (exec_path[0] == '\0') { |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 204 | // vstrcpy may fail to copy path. In this case lets do it |
| 205 | // differently. |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 206 | memcheck_get_guest_kernel_string(exec_path, value, CLIENT_PAGE_SIZE); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 207 | } |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 208 | memcheck_mmap_exepath(vstart, vend, eoff, exec_path); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 209 | } |
| 210 | #endif // CONFIG_MEMCHECK |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 211 | exec_path[0] = 0; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 212 | break; |
| 213 | case TRACE_DEV_REG_INIT_PID: // init, name the pid that starts before device registered |
| 214 | pid = value; |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 215 | DPID("QEMU.trace: pid=%d\n", value); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 216 | #ifdef CONFIG_MEMCHECK |
| 217 | if (memcheck_enabled) { |
| 218 | memcheck_init_pid(value); |
| 219 | } |
| 220 | #endif // CONFIG_MEMCHECK |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 221 | break; |
| 222 | case TRACE_DEV_REG_INIT_NAME: // init, the comm of the init pid |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 223 | vstrcpy(value, exec_path, CLIENT_PAGE_SIZE); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 224 | DPID("QEMU.trace: tgid=%d pid=%d name=%s\n", tgid, pid, exec_path); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 225 | if (trace_filename != NULL) { |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 226 | trace_init_name(tgid, pid, exec_path); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 227 | D("QEMU.trace: kernel, init name %u [%s]\n", pid, exec_path); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 228 | } |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 229 | exec_path[0] = 0; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 230 | break; |
| 231 | |
| 232 | case TRACE_DEV_REG_DYN_SYM_ADDR: // dynamic symbol address |
| 233 | dsaddr = value; |
| 234 | break; |
| 235 | case TRACE_DEV_REG_DYN_SYM: // add dynamic symbol |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 236 | vstrcpy(value, exec_arg, CLIENT_PAGE_SIZE); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 237 | if (trace_filename != NULL) { |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 238 | trace_dynamic_symbol_add(dsaddr, exec_arg); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 239 | D("QEMU.trace: dynamic symbol %lx:%s\n", dsaddr, exec_arg); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 240 | } |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 241 | exec_arg[0] = 0; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 242 | break; |
| 243 | case TRACE_DEV_REG_REMOVE_ADDR: // remove dynamic symbol addr |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 244 | if (trace_filename != NULL) { |
| 245 | trace_dynamic_symbol_remove(value); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 246 | D("QEMU.trace: dynamic symbol remove %lx\n", dsaddr); |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 247 | } |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 248 | break; |
| 249 | |
| 250 | case TRACE_DEV_REG_PRINT_STR: // print string |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 251 | vstrcpy(value, exec_arg, CLIENT_PAGE_SIZE); |
| 252 | printf("%s", exec_arg); |
| 253 | exec_arg[0] = 0; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 254 | break; |
| 255 | case TRACE_DEV_REG_PRINT_NUM_DEC: // print number in decimal |
| 256 | printf("%d", value); |
| 257 | break; |
| 258 | case TRACE_DEV_REG_PRINT_NUM_HEX: // print number in hexical |
| 259 | printf("%x", value); |
| 260 | break; |
| 261 | |
| 262 | case TRACE_DEV_REG_STOP_EMU: // stop the VM execution |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 263 | if (trace_filename != NULL) { |
| 264 | // To ensure that the number of instructions executed in this |
| 265 | // block is correct, we pretend that there was an exception. |
| 266 | trace_exception(0); |
| 267 | } |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 268 | cpu_single_env->exception_index = EXCP_HLT; |
| 269 | cpu_single_env->halted = 1; |
| 270 | qemu_system_shutdown_request(); |
| 271 | cpu_loop_exit(); |
| 272 | break; |
| 273 | |
| 274 | case TRACE_DEV_REG_ENABLE: // tracing enable: 0 = stop, 1 = start |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 275 | if (value == 1) { |
| 276 | if (trace_filename != NULL) { |
| 277 | start_tracing(); |
| 278 | } |
| 279 | } |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 280 | else if (value == 0) { |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 281 | if (trace_filename != NULL) { |
| 282 | stop_tracing(); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 283 | |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 284 | // To ensure that the number of instructions executed in this |
| 285 | // block is correct, we pretend that there was an exception. |
| 286 | trace_exception(0); |
| 287 | } |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 288 | } |
| 289 | break; |
| 290 | |
| 291 | case TRACE_DEV_REG_UNMAP_START: |
| 292 | unmap_start = value; |
| 293 | break; |
| 294 | case TRACE_DEV_REG_UNMAP_END: |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 295 | if (trace_filename != NULL) { |
| 296 | trace_munmap(unmap_start, value); |
| 297 | } |
| 298 | #ifdef CONFIG_MEMCHECK |
| 299 | if (memcheck_enabled) { |
| 300 | memcheck_unmap(unmap_start, value); |
| 301 | } |
| 302 | #endif // CONFIG_MEMCHECK |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 303 | break; |
| 304 | |
Jack Veenstra | 9980bbb | 2009-05-05 10:35:03 -0700 | [diff] [blame] | 305 | case TRACE_DEV_REG_METHOD_ENTRY: |
| 306 | case TRACE_DEV_REG_METHOD_EXIT: |
| 307 | case TRACE_DEV_REG_METHOD_EXCEPTION: |
Jack Veenstra | e3ea32f | 2009-05-19 14:41:14 -0700 | [diff] [blame] | 308 | case TRACE_DEV_REG_NATIVE_ENTRY: |
| 309 | case TRACE_DEV_REG_NATIVE_EXIT: |
| 310 | case TRACE_DEV_REG_NATIVE_EXCEPTION: |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 311 | if (trace_filename != NULL) { |
| 312 | if (tracing) { |
| 313 | int call_type = (offset - 4096) >> 2; |
| 314 | trace_interpreted_method(value, call_type); |
| 315 | } |
Jack Veenstra | 9980bbb | 2009-05-05 10:35:03 -0700 | [diff] [blame] | 316 | } |
| 317 | break; |
| 318 | |
Vladimir Chtchetkine | 5389aa1 | 2010-02-16 10:38:35 -0800 | [diff] [blame] | 319 | #ifdef CONFIG_MEMCHECK |
| 320 | case TRACE_DEV_REG_MALLOC: |
| 321 | if (memcheck_enabled) { |
| 322 | memcheck_guest_alloc(value); |
| 323 | } |
| 324 | break; |
| 325 | |
| 326 | case TRACE_DEV_REG_FREE_PTR: |
| 327 | if (memcheck_enabled) { |
| 328 | memcheck_guest_free(value); |
| 329 | } |
| 330 | break; |
| 331 | |
| 332 | case TRACE_DEV_REG_QUERY_MALLOC: |
| 333 | if (memcheck_enabled) { |
| 334 | memcheck_guest_query_malloc(value); |
| 335 | } |
| 336 | break; |
| 337 | |
| 338 | case TRACE_DEV_REG_LIBC_INIT: |
| 339 | if (memcheck_enabled) { |
| 340 | memcheck_guest_libc_initialized(value); |
| 341 | } |
| 342 | break; |
| 343 | |
| 344 | case TRACE_DEV_REG_PRINT_USER_STR: |
| 345 | if (memcheck_enabled) { |
| 346 | memcheck_guest_print_str(value); |
| 347 | } |
| 348 | break; |
| 349 | #endif // CONFIG_MEMCHECK |
| 350 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 351 | default: |
Jack Veenstra | 9980bbb | 2009-05-05 10:35:03 -0700 | [diff] [blame] | 352 | if (offset < 4096) { |
| 353 | cpu_abort(cpu_single_env, "trace_dev_write: Bad offset %x\n", offset); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 354 | } else { |
| 355 | D("%s: offset=%d (0x%x) value=%d (0x%x)\n", __FUNCTION__, offset, |
| 356 | offset, value, value); |
Jack Veenstra | 9980bbb | 2009-05-05 10:35:03 -0700 | [diff] [blame] | 357 | } |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 358 | break; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | /* I/O read */ |
| 363 | static uint32_t trace_dev_read(void *opaque, target_phys_addr_t offset) |
| 364 | { |
| 365 | trace_dev_state *s = (trace_dev_state *)opaque; |
| 366 | |
David 'Digit' Turner | 4e024bb | 2010-09-22 14:19:28 +0200 | [diff] [blame] | 367 | (void)s; |
| 368 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 369 | switch (offset >> 2) { |
| 370 | case TRACE_DEV_REG_ENABLE: // tracing enable |
| 371 | return tracing; |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 372 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 373 | default: |
Jack Veenstra | 9980bbb | 2009-05-05 10:35:03 -0700 | [diff] [blame] | 374 | if (offset < 4096) { |
| 375 | cpu_abort(cpu_single_env, "trace_dev_read: Bad offset %x\n", offset); |
David 'Digit' Turner | 335d2c1 | 2011-03-21 22:24:45 +0100 | [diff] [blame] | 376 | } else { |
| 377 | D("%s: offset=%d (0x%x)\n", __FUNCTION__, offset, offset); |
Jack Veenstra | 9980bbb | 2009-05-05 10:35:03 -0700 | [diff] [blame] | 378 | } |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 379 | return 0; |
| 380 | } |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | static CPUReadMemoryFunc *trace_dev_readfn[] = { |
| 385 | trace_dev_read, |
| 386 | trace_dev_read, |
| 387 | trace_dev_read |
| 388 | }; |
| 389 | |
| 390 | static CPUWriteMemoryFunc *trace_dev_writefn[] = { |
| 391 | trace_dev_write, |
| 392 | trace_dev_write, |
| 393 | trace_dev_write |
| 394 | }; |
| 395 | |
| 396 | /* initialize the trace device */ |
Jack Veenstra | 9980bbb | 2009-05-05 10:35:03 -0700 | [diff] [blame] | 397 | void trace_dev_init() |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 398 | { |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 399 | trace_dev_state *s; |
| 400 | |
| 401 | s = (trace_dev_state *)qemu_mallocz(sizeof(trace_dev_state)); |
Jack Veenstra | 9980bbb | 2009-05-05 10:35:03 -0700 | [diff] [blame] | 402 | s->dev.name = "qemu_trace"; |
| 403 | s->dev.id = -1; |
| 404 | s->dev.base = 0; // will be allocated dynamically |
| 405 | s->dev.size = 0x2000; |
| 406 | s->dev.irq = 0; |
| 407 | s->dev.irq_count = 0; |
| 408 | |
| 409 | goldfish_device_add(&s->dev, trace_dev_readfn, trace_dev_writefn, s); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 410 | |
David Turner | b919805 | 2010-09-10 11:50:34 +0200 | [diff] [blame] | 411 | exec_path[0] = exec_arg[0] = '\0'; |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 412 | } |