2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/types.h>
24 // This is the pathname to the sysfs file that enables and disables
25 // tracing on the qemu emulator.
26 #define SYS_QEMU_TRACE_STATE "/sys/qemu_trace/state"
29 // This is the pathname to the sysfs file that adds new (address, symbol)
30 // pairs to the trace.
31 #define SYS_QEMU_TRACE_SYMBOL "/sys/qemu_trace/symbol"
33 // The maximum length of a symbol name
34 #define MAX_SYMBOL_NAME_LENGTH (4 * 1024)
36 // Allow space in the buffer for the address plus whitespace.
37 #define MAX_BUF_SIZE (MAX_SYMBOL_NAME_LENGTH + 20)
39 // return 0 on success, or an error if the qemu driver cannot be opened
40 int qemu_start_tracing()
42 int fd = open(SYS_QEMU_TRACE_STATE, O_WRONLY);
50 int qemu_stop_tracing()
52 int fd = open(SYS_QEMU_TRACE_STATE, O_WRONLY);
60 int qemu_add_mapping(unsigned int addr, const char *name)
62 char buf[MAX_BUF_SIZE];
64 if (strlen(name) > MAX_SYMBOL_NAME_LENGTH)
66 int fd = open(SYS_QEMU_TRACE_SYMBOL, O_WRONLY);
69 sprintf(buf, "%x %s\n", addr, name);
70 write(fd, buf, strlen(buf));
75 int qemu_remove_mapping(unsigned int addr)
77 char buf[MAX_BUF_SIZE];
79 int fd = open(SYS_QEMU_TRACE_SYMBOL, O_WRONLY);
82 sprintf(buf, "%x\n", addr);
83 write(fd, buf, strlen(buf));