Home | History | Annotate | Download | only in libdebuggerd
      1 /* system/debuggerd/utility.h
      2 **
      3 ** Copyright 2008, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #ifndef _DEBUGGERD_UTILITY_H
     19 #define _DEBUGGERD_UTILITY_H
     20 
     21 #include <signal.h>
     22 #include <stdbool.h>
     23 #include <sys/types.h>
     24 
     25 #include <string>
     26 
     27 #include <android-base/macros.h>
     28 #include <backtrace/Backtrace.h>
     29 
     30 struct log_t {
     31   // Tombstone file descriptor.
     32   int tfd;
     33   // Data to be sent to the Activity Manager.
     34   std::string* amfd_data;
     35   // The tid of the thread that crashed.
     36   pid_t crashed_tid;
     37   // The tid of the thread we are currently working with.
     38   pid_t current_tid;
     39   // logd daemon crash, can block asking for logcat data, allow suppression.
     40   bool should_retrieve_logcat;
     41 
     42   log_t()
     43       : tfd(-1),
     44         amfd_data(nullptr),
     45         crashed_tid(-1),
     46         current_tid(-1),
     47         should_retrieve_logcat(true) {}
     48 };
     49 
     50 // List of types of logs to simplify the logging decision in _LOG
     51 enum logtype {
     52   HEADER,
     53   THREAD,
     54   REGISTERS,
     55   FP_REGISTERS,
     56   BACKTRACE,
     57   MAPS,
     58   MEMORY,
     59   STACK,
     60   LOGS,
     61   OPEN_FILES
     62 };
     63 
     64 // Log information onto the tombstone.
     65 void _LOG(log_t* log, logtype ltype, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
     66 
     67 namespace unwindstack {
     68 class Memory;
     69 }
     70 
     71 void dump_memory(log_t* log, unwindstack::Memory* backtrace, uint64_t addr, const std::string&);
     72 
     73 void read_with_default(const char* path, char* buf, size_t len, const char* default_value);
     74 
     75 void drop_capabilities();
     76 
     77 bool signal_has_si_addr(int si_signo, int si_code);
     78 const char* get_signame(int sig);
     79 const char* get_sigcode(int signo, int code);
     80 
     81 #endif // _DEBUGGERD_UTILITY_H
     82