Enables ADBD tracing in the emulator.

When running inside the emulator, guest's adbd can connect to 'adb-debug' qemud
service that can display adb trace messages on condition that emulator has been
started with '-debug adb' option.

This CL enables that functionality in ADB code.

Change-Id: I59b4a76d3c887ad28b8aa8e2a01dfa814e75faa1
This commit is contained in:
Vladimir Chtchetkine 2012-02-27 10:41:53 -08:00
parent c958a7f498
commit 28781b0a52
2 changed files with 70 additions and 0 deletions

View File

@ -131,6 +131,58 @@ void adb_trace_init(void)
}
}
#if !ADB_HOST
/*
* Implements ADB tracing inside the emulator.
*/
#include <stdarg.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. */
static 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));
}
}
#endif /* !ADB_HOST */
apacket *get_apacket(void)
{
@ -1297,6 +1349,9 @@ int main(int argc, char **argv)
D("Handling commandline()\n");
return adb_commandline(argc - 1, argv + 1);
#else
/* If adbd runs inside the emulator this will enable adb tracing via
* adb-debug qemud service in the emulator. */
adb_qemu_trace_init();
if((argc > 1) && (!strcmp(argv[1],"recovery"))) {
adb_device_banner = "recovery";
recovery_mode = 1;

View File

@ -345,6 +345,21 @@ typedef enum {
#if ADB_TRACE
#if !ADB_HOST
/*
* When running inside the emulator, guest's adbd can connect to 'adb-debug'
* qemud service that can display adb trace messages (on condition that emulator
* has been started with '-debug adb' option).
*/
/* Delivers a trace message to the emulator via QEMU pipe. */
void adb_qemu_trace(const char* fmt, ...);
/* Macro to use to send ADB trace messages to the emulator. */
#define DQ(...) adb_qemu_trace(__VA_ARGS__)
#else
#define DQ(...) ((void)0)
#endif /* !ADB_HOST */
extern int adb_trace_mask;
extern unsigned char adb_trace_output_count;
void adb_trace_init(void);