Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 Google Inc. | 1 // Copyright (c) 2012 Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 #include "client/linux/log/log.h" | 30 #include "client/linux/log/log.h" |
| 31 | 31 |
| 32 #if defined(__ANDROID__) | 32 #if defined(__ANDROID__) |
| 33 #include <android/log.h> | 33 #include <android/log.h> |
| 34 #include <dlfcn.h> | |
| 35 | |
| 36 // From Android system/core/include/log/log.h | |
|
Lei Zhang
2015/08/13 21:07:57
Might be good to mention __android_log_buf_write()
Lei Zhang
2015/08/13 21:07:57
nit: Move these out of a #if block for #includes.
Primiano Tucci (use gerrit)
2015/08/14 09:16:45
Done.
Primiano Tucci (use gerrit)
2015/08/14 09:16:46
Moved below in the anonymous namespace
Primiano Tucci (use gerrit)
2015/08/14 09:16:46
Done.
| |
| 37 using AndroidLogBufferWriteFunc = int (*)(int bufID, int prio, const char *tag, | |
| 38 const char *text); | |
| 39 static const char kAndroidLogTag[] = "google-breakpad"; | |
| 34 #else | 40 #else |
| 35 #include "third_party/lss/linux_syscall_support.h" | 41 #include "third_party/lss/linux_syscall_support.h" |
| 36 #endif | 42 #endif |
| 37 | 43 |
| 38 namespace logger { | 44 namespace logger { |
| 39 | 45 |
| 40 int write(const char* buf, size_t nbytes) { | 46 int write(const char* buf, size_t nbytes) { |
| 41 #if defined(__ANDROID__) | 47 #if defined(__ANDROID__) |
| 42 return __android_log_write(ANDROID_LOG_WARN, "google-breakpad", buf); | 48 return __android_log_write(ANDROID_LOG_WARN, kAndroidLogTag, buf); |
| 43 #else | 49 #else |
| 44 return sys_write(2, buf, nbytes); | 50 return sys_write(2, buf, nbytes); |
| 45 #endif | 51 #endif |
| 46 } | 52 } |
| 47 | 53 |
| 54 #if defined(__ANDROID__) | |
| 55 namespace { | |
|
Lei Zhang
2015/08/13 21:07:57
nit: blank lines after the start of the namespace
Primiano Tucci (use gerrit)
2015/08/14 09:16:45
Done.
| |
| 56 bool g_crash_log_initialized = false; | |
| 57 AndroidLogBufferWriteFunc g_android_log_buf_write = nullptr; | |
| 58 } // namespace | |
| 59 | |
| 60 void initializeCrashLogWriter() { | |
| 61 if (g_crash_log_initialized) | |
| 62 return; | |
| 63 g_android_log_buf_write = reinterpret_cast<AndroidLogBufferWriteFunc>( | |
| 64 dlsym(RTLD_DEFAULT, "__android_log_buf_write")); | |
| 65 g_crash_log_initialized = true; | |
| 66 } | |
| 67 | |
| 68 int writeToCrashLog(const char* buf) { | |
| 69 // Try writing to the crash log ring buffer. If not available, fall back using | |
|
Lei Zhang
2015/08/13 21:07:57
nit: "fall back to" parses slightly better in my m
Primiano Tucci (use gerrit)
2015/08/14 09:16:45
Done.
| |
| 70 // the standard log buffer. | |
| 71 if (g_crash_log_initialized && g_android_log_buf_write) { | |
|
Lei Zhang
2015/08/13 21:07:57
Do you really need to check |g_crash_log_initializ
Primiano Tucci (use gerrit)
2015/08/14 09:16:45
Nah not really. Done.
| |
| 72 const int kAndroidCrashLogId = 4; | |
|
Lei Zhang
2015/08/13 21:07:57
Where did this magical value come from? Add a comm
Primiano Tucci (use gerrit)
2015/08/14 09:16:46
Done.
| |
| 73 return g_android_log_buf_write(kAndroidCrashLogId, ANDROID_LOG_FATAL, | |
| 74 kAndroidLogTag, buf); | |
| 75 } | |
| 76 return __android_log_write(ANDROID_LOG_FATAL, kAndroidLogTag, buf); | |
| 77 } | |
| 78 #endif | |
| 79 | |
| 48 } // namespace logger | 80 } // namespace logger |
| OLD | NEW |