Nicolas Capens | 68a8238 | 2018-10-02 13:16:55 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "DebugAndroid.hpp" |
| 16 | |
| 17 | #include <stdlib.h> |
| 18 | #include <unistd.h> |
| 19 | #include <sys/types.h> |
| 20 | #include <cutils/properties.h> |
| 21 | |
| 22 | void AndroidEnterDebugger() |
| 23 | { |
| 24 | ALOGE(__FUNCTION__); |
| 25 | #ifndef NDEBUG |
| 26 | static volatile int * const makefault = nullptr; |
| 27 | char value[PROPERTY_VALUE_MAX]; |
| 28 | property_get("debug.db.uid", value, "-1"); |
| 29 | int debug_uid = atoi(value); |
| 30 | if((debug_uid >= 0) && (geteuid() < static_cast<uid_t>(debug_uid))) |
| 31 | { |
| 32 | ALOGE("Waiting for debugger: gdbserver :${PORT} --attach %u. Look for thread %u", getpid(), gettid()); |
| 33 | volatile int waiting = 1; |
| 34 | while (waiting) { |
| 35 | sleep(1); |
| 36 | } |
| 37 | } |
| 38 | else |
| 39 | { |
| 40 | ALOGE("No debugger"); |
| 41 | } |
| 42 | #endif |
| 43 | } |
| 44 | |
| 45 | void trace(const char *format, ...) |
| 46 | { |
| 47 | #ifndef NDEBUG |
| 48 | va_list vararg; |
| 49 | va_start(vararg, format); |
| 50 | android_vprintLog(ANDROID_LOG_VERBOSE, NULL, LOG_TAG, format, vararg); |
| 51 | va_end(vararg); |
| 52 | #endif |
| 53 | } |