system/corennnnn
修訂 | 43dd52ffef9283cf7386fd0b77ad98964af958bb (tree) |
---|---|
時間 | 2013-06-16 17:06:07 |
作者 | Ken Lierman <ken.lierman@wind...> |
Commiter | Chih-Wei Huang |
cleanup ADB's debug output
The server was using stderr to talk back to the client to ACK it
starting correctly, which made the debug output from the server get
lost (before it later gets redirected to a file). Change it to stdout
and add a fflush() to force the output.
Add the pid to the output so you can tell which process the output is
coming from.
Add basename to the FILE part of the output to remove the unnecessary
and redundant system/core/adb path info from every output line.
Remove the duplicated fdevents debug output macro so it gets redirected
into the server log file like it should.
Change-Id: I8eaf3c8ccbca62f907b0ee7b52a0e179db5ff82d
@@ -105,6 +105,7 @@ void adb_trace_init(void) | ||
105 | 105 | { "jdwp", TRACE_JDWP }, |
106 | 106 | { "services", TRACE_SERVICES }, |
107 | 107 | { "auth", TRACE_AUTH }, |
108 | + { "fdevents", TRACE_FDEVENT }, | |
108 | 109 | { NULL, 0 } |
109 | 110 | }; |
110 | 111 |
@@ -1009,10 +1010,9 @@ int launch_server(int server_port) | ||
1009 | 1010 | if (pid == 0) { |
1010 | 1011 | // child side of the fork |
1011 | 1012 | |
1012 | - // redirect stderr to the pipe | |
1013 | - // we use stderr instead of stdout due to stdout's buffering behavior. | |
1013 | + // redirect stdout to the pipe | |
1014 | 1014 | adb_close(fd[0]); |
1015 | - dup2(fd[1], STDERR_FILENO); | |
1015 | + dup2(fd[1], STDOUT_FILENO); | |
1016 | 1016 | adb_close(fd[1]); |
1017 | 1017 | |
1018 | 1018 | char str_port[30]; |
@@ -1229,7 +1229,8 @@ int adb_main(int is_daemon, int server_port) | ||
1229 | 1229 | DWORD count; |
1230 | 1230 | WriteFile( GetStdHandle( STD_OUTPUT_HANDLE ), "OK\n", 3, &count, NULL ); |
1231 | 1231 | #elif defined(HAVE_FORKEXEC) |
1232 | - fprintf(stderr, "OK\n"); | |
1232 | + fprintf(stdout, "OK\n"); | |
1233 | + fflush(stdout); | |
1233 | 1234 | #endif |
1234 | 1235 | start_logging(); |
1235 | 1236 | } |
@@ -18,6 +18,7 @@ | ||
18 | 18 | #define __ADB_H |
19 | 19 | |
20 | 20 | #include <limits.h> |
21 | +#include <libgen.h> | |
21 | 22 | |
22 | 23 | #include "transport.h" /* readx(), writex() */ |
23 | 24 |
@@ -359,6 +360,7 @@ typedef enum { | ||
359 | 360 | TRACE_JDWP, /* 0x100 */ |
360 | 361 | TRACE_SERVICES, |
361 | 362 | TRACE_AUTH, |
363 | + TRACE_FDEVENT, | |
362 | 364 | } AdbTrace; |
363 | 365 | |
364 | 366 | #if ADB_TRACE |
@@ -390,8 +392,10 @@ void adb_qemu_trace(const char* fmt, ...); | ||
390 | 392 | if (ADB_TRACING) { \ |
391 | 393 | int save_errno = errno; \ |
392 | 394 | adb_mutex_lock(&D_lock); \ |
393 | - fprintf(stderr, "%s::%s():", \ | |
394 | - __FILE__, __FUNCTION__); \ | |
395 | + fprintf(stderr, "%d::%s::%s():", \ | |
396 | + getpid(), \ | |
397 | + basename(__FILE__), \ | |
398 | + __FUNCTION__); \ | |
395 | 399 | errno = save_errno; \ |
396 | 400 | fprintf(stderr, __VA_ARGS__ ); \ |
397 | 401 | fflush(stderr); \ |
@@ -28,23 +28,22 @@ | ||
28 | 28 | #include <stdarg.h> |
29 | 29 | #include <stddef.h> |
30 | 30 | |
31 | +#define TRACE_TAG TRACE_FDEVENT | |
32 | + | |
31 | 33 | #include "fdevent.h" |
32 | 34 | #include "transport.h" |
33 | 35 | #include "sysdeps.h" |
36 | +#include "adb.h" | |
34 | 37 | |
35 | 38 | |
36 | -/* !!! Do not enable DEBUG for the adb that will run as the server: | |
37 | -** both stdout and stderr are used to communicate between the client | |
38 | -** and server. Any extra output will cause failures. | |
39 | -*/ | |
40 | -#define DEBUG 0 /* non-0 will break adb server */ | |
39 | +#define DEBUG 0 | |
41 | 40 | |
42 | 41 | // This socket is used when a subproc shell service exists. |
43 | 42 | // It wakes up the fdevent_loop() and cause the correct handling |
44 | 43 | // of the shell's pseudo-tty master. I.e. force close it. |
45 | 44 | int SHELL_EXIT_NOTIFY_FD = -1; |
46 | 45 | |
47 | -static void fatal(const char *fn, const char *fmt, ...) | |
46 | +static void ffatal(const char *fn, const char *fmt, ...) | |
48 | 47 | { |
49 | 48 | va_list ap; |
50 | 49 | va_start(ap, fmt); |
@@ -54,19 +53,10 @@ static void fatal(const char *fn, const char *fmt, ...) | ||
54 | 53 | abort(); |
55 | 54 | } |
56 | 55 | |
57 | -#define FATAL(x...) fatal(__FUNCTION__, x) | |
56 | + | |
57 | +#define FATAL(x...) ffatal(__FUNCTION__, x) | |
58 | 58 | |
59 | 59 | #if DEBUG |
60 | -#define D(...) \ | |
61 | - do { \ | |
62 | - adb_mutex_lock(&D_lock); \ | |
63 | - int save_errno = errno; \ | |
64 | - fprintf(stderr, "%s::%s():", __FILE__, __FUNCTION__); \ | |
65 | - errno = save_errno; \ | |
66 | - fprintf(stderr, __VA_ARGS__); \ | |
67 | - adb_mutex_unlock(&D_lock); \ | |
68 | - errno = save_errno; \ | |
69 | - } while(0) | |
70 | 60 | static void dump_fde(fdevent *fde, const char *info) |
71 | 61 | { |
72 | 62 | adb_mutex_lock(&D_lock); |
@@ -78,7 +68,6 @@ static void dump_fde(fdevent *fde, const char *info) | ||
78 | 68 | adb_mutex_unlock(&D_lock); |
79 | 69 | } |
80 | 70 | #else |
81 | -#define D(...) ((void)0) | |
82 | 71 | #define dump_fde(fde, info) do { } while(0) |
83 | 72 | #endif |
84 | 73 |