blob: 2a6569caf5645afa893883f32972e10afa669e5e [file] [log] [blame]
Nicolas Capensc07dc4b2018-08-06 14:20:45 -04001// 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
22void 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;
Nicolas Capens81bc9d92019-12-16 15:05:57 -050034 while(waiting) {
Nicolas Capensc07dc4b2018-08-06 14:20:45 -040035 sleep(1);
36 }
37 }
38 else
39 {
40 ALOGE("No debugger");
41 }
42#endif
43}
44
45void 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}