summaryrefslogtreecommitdiffstats
path: root/adb/qemu_tracing.cpp
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2015-02-25 17:51:28 -0800
committerDan Albert <danalbert@google.com>2015-03-09 14:06:11 -0700
commitbac3474a8256cb32a29e8d46f78cad95a5502692 (patch)
tree9763c3cb2f5e640c7061cffb47d61274a37baab8 /adb/qemu_tracing.cpp
parent9b1fd969a7b7f1c6f1ed19719f21d57001d3c461 (diff)
downloadsystem_core-bac3474a8256cb32a29e8d46f78cad95a5502692.zip
system_core-bac3474a8256cb32a29e8d46f78cad95a5502692.tar.gz
system_core-bac3474a8256cb32a29e8d46f78cad95a5502692.tar.bz2
Move adb to C++.
I keep trying to clean things up and needing std::strings. Might as well just do this now. usb_linux_client.c is going to stay as C because GCC isn't smart enough to deal with the designated initializers it uses (though for some reason it is in C mode). The Darwin files are staying as C because I don't have a way to test that they build. The Windows files are staying as C because while I can actually build for them, it's slow and painful. Change-Id: I75367d29205a9049d34460032b3bb36384f43941
Diffstat (limited to 'adb/qemu_tracing.cpp')
-rw-r--r--adb/qemu_tracing.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/adb/qemu_tracing.cpp b/adb/qemu_tracing.cpp
new file mode 100644
index 0000000..f31eae8
--- /dev/null
+++ b/adb/qemu_tracing.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Implements ADB tracing inside the emulator.
+ */
+
+#include <stdarg.h>
+
+#include "sysdeps.h"
+#include "qemu_tracing.h"
+
+/*
+ * Redefine open and write for qemu_pipe.h that contains inlined references
+ * to those routines. We will redifine them back after qemu_pipe.h inclusion.
+ */
+
+#undef open
+#undef write
+#define open adb_open
+#define write adb_write
+#include <hardware/qemu_pipe.h>
+#undef open
+#undef write
+#define open ___xxx_open
+#define write ___xxx_write
+
+/* A handle to adb-debug qemud service in the emulator. */
+int adb_debug_qemu = -1;
+
+/* Initializes connection with the adb-debug qemud service in the emulator. */
+int adb_qemu_trace_init(void)
+{
+ char con_name[32];
+
+ if (adb_debug_qemu >= 0) {
+ return 0;
+ }
+
+ /* adb debugging QEMUD service connection request. */
+ snprintf(con_name, sizeof(con_name), "qemud:adb-debug");
+ adb_debug_qemu = qemu_pipe_open(con_name);
+ return (adb_debug_qemu >= 0) ? 0 : -1;
+}
+
+void adb_qemu_trace(const char* fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ char msg[1024];
+
+ if (adb_debug_qemu >= 0) {
+ vsnprintf(msg, sizeof(msg), fmt, args);
+ adb_write(adb_debug_qemu, msg, strlen(msg));
+ }
+}