1 /** @file
2 
3   A brief file description
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 #pragma once
25 
26 #include "tscore/ink_platform.h"
27 #include "tscore/ink_memory.h"
28 #include "tscore/Diags.h"
29 #include "tscore/TextBuffer.h"
30 #include "mgmtapi.h"
31 
32 // ucontext.h is deprecated on Darwin, and we really only need it on Linux, so only
33 // include it if we are planning to use it.
34 #if defined(__linux__)
35 #include <ucontext.h>
36 #endif
37 
38 // Printf format for crash log field labels.
39 #define LABELFMT "%-20s"
40 
41 // Printf format for memory addresses.
42 #if SIZEOF_VOIDP == 8
43 #define ADDRFMT "0x%016" PRIx64
44 #define ADDRCAST(x) ((uint64_t)(x))
45 #elif SIZEOF_VOIDP == 4
46 #define ADDRFMT "0x%08" PRIx32
47 #define ADDRCAST(x) ((uint32_t)(x))
48 #else
49 #error unsupported pointer size
50 #endif
51 
52 #define CRASHLOG_HAVE_THREADINFO 0x1u
53 
54 struct crashlog_target {
55   pid_t pid;
56   siginfo_t siginfo;
57 #if defined(__linux__)
58   ucontext_t ucontext;
59 #else
60   char ucontext; // just a placeholder ...
61 #endif
62   struct tm timestamp;
63   unsigned flags;
64 };
65 
66 bool crashlog_write_backtrace(FILE *, const crashlog_target &);
67 bool crashlog_write_datime(FILE *, const crashlog_target &);
68 bool crashlog_write_exename(FILE *, const crashlog_target &);
69 bool crashlog_write_proclimits(FILE *, const crashlog_target &);
70 bool crashlog_write_procname(FILE *, const crashlog_target &);
71 bool crashlog_write_procstatus(FILE *, const crashlog_target &);
72 bool crashlog_write_records(FILE *, const crashlog_target &);
73 bool crashlog_write_regions(FILE *, const crashlog_target &);
74 bool crashlog_write_registers(FILE *, const crashlog_target &);
75 bool crashlog_write_siginfo(FILE *, const crashlog_target &);
76 bool crashlog_write_uname(FILE *, const crashlog_target &);
77