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