| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2013 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 | """stack symbolizes native crash dumps.""" |
| 18 | |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 19 | import os |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 20 | import re |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 21 | import subprocess |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 22 | import symbol |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 23 | import tempfile |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 24 | import unittest |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 25 | |
| Elliott Hughes | c3166be | 2014-07-07 15:06:28 -0700 | [diff] [blame] | 26 | import example_crashes |
| 27 | |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 28 | def ConvertTrace(lines): |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 29 | tracer = TraceConverter() |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 30 | print("Reading symbols from", symbol.SYMBOLS_DIR) |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 31 | tracer.ConvertTrace(lines) |
| 32 | |
| 33 | class TraceConverter: |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 34 | process_info_line = re.compile(r"(pid: [0-9]+, tid: [0-9]+.*)") |
| 35 | revision_line = re.compile(r"(Revision: '(.*)')") |
| 36 | signal_line = re.compile(r"(signal [0-9]+ \(.*\).*)") |
| 37 | abort_message_line = re.compile(r"(Abort message: '.*')") |
| 38 | thread_line = re.compile(r"(.*)(--- ){15}---") |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 39 | dalvik_jni_thread_line = re.compile("(\".*\" prio=[0-9]+ tid=[0-9]+ NATIVE.*)") |
| 40 | dalvik_native_thread_line = re.compile("(\".*\" sysTid=[0-9]+ nice=[0-9]+.*)") |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 41 | register_line = re.compile("$a") |
| 42 | trace_line = re.compile("$a") |
| Andreas Gampe | d900d08 | 2015-08-21 15:25:03 -0700 | [diff] [blame] | 43 | sanitizer_trace_line = re.compile("$a") |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 44 | value_line = re.compile("$a") |
| 45 | code_line = re.compile("$a") |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 46 | zipinfo_central_directory_line = re.compile(r"Central\s+directory\s+entry") |
| Christopher Ferris | abe22f4 | 2016-03-16 12:17:59 -0700 | [diff] [blame] | 47 | zipinfo_central_info_match = re.compile( |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 48 | r"^\s*(\S+)$\s*offset of local header from start of archive:\s*(\d+)" |
| 49 | r".*^\s*compressed size:\s+(\d+)", re.M | re.S) |
| 50 | unreachable_line = re.compile(r"((\d+ bytes in \d+ unreachable allocations)|" |
| 51 | r"(\d+ bytes unreachable at [0-9a-f]+)|" |
| 52 | r"(referencing \d+ unreachable bytes in \d+ allocation(s)?)|" |
| 53 | r"(and \d+ similar unreachable bytes in \d+ allocation(s)?))") |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 54 | trace_lines = [] |
| 55 | value_lines = [] |
| 56 | last_frame = -1 |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 57 | width = "{8}" |
| Elliott Hughes | c3c8619 | 2014-08-29 13:49:57 -0700 | [diff] [blame] | 58 | spacing = "" |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 59 | apk_info = dict() |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 60 | |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 61 | register_names = { |
| 62 | "arm": "r0|r1|r2|r3|r4|r5|r6|r7|r8|r9|sl|fp|ip|sp|lr|pc|cpsr", |
| Elliott Hughes | be4de46 | 2014-07-14 17:15:41 -0700 | [diff] [blame] | 63 | "arm64": "x0|x1|x2|x3|x4|x5|x6|x7|x8|x9|x10|x11|x12|x13|x14|x15|x16|x17|x18|x19|x20|x21|x22|x23|x24|x25|x26|x27|x28|x29|x30|sp|pc|pstate", |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 64 | "mips": "zr|at|v0|v1|a0|a1|a2|a3|t0|t1|t2|t3|t4|t5|t6|t7|s0|s1|s2|s3|s4|s5|s6|s7|t8|t9|k0|k1|gp|sp|s8|ra|hi|lo|bva|epc", |
| Andreas Gampe | 5521841 | 2015-05-21 14:44:21 -0700 | [diff] [blame] | 65 | "mips64": "zr|at|v0|v1|a0|a1|a2|a3|a4|a5|a6|a7|t0|t1|t2|t3|s0|s1|s2|s3|s4|s5|s6|s7|t8|t9|k0|k1|gp|sp|s8|ra|hi|lo|bva|epc", |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 66 | "x86": "eax|ebx|ecx|edx|esi|edi|x?cs|x?ds|x?es|x?fs|x?ss|eip|ebp|esp|flags", |
| 67 | "x86_64": "rax|rbx|rcx|rdx|rsi|rdi|r8|r9|r10|r11|r12|r13|r14|r15|cs|ss|rip|rbp|rsp|eflags", |
| 68 | } |
| 69 | |
| 70 | def UpdateAbiRegexes(self): |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 71 | if symbol.ARCH == "arm64" or symbol.ARCH == "mips64" or symbol.ARCH == "x86_64": |
| 72 | self.width = "{16}" |
| Elliott Hughes | c3c8619 | 2014-08-29 13:49:57 -0700 | [diff] [blame] | 73 | self.spacing = " " |
| Brigid Smith | 15142f7 | 2014-07-15 13:47:07 -0700 | [diff] [blame] | 74 | else: |
| 75 | self.width = "{8}" |
| Elliott Hughes | c3c8619 | 2014-08-29 13:49:57 -0700 | [diff] [blame] | 76 | self.spacing = "" |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 77 | |
| Elliott Hughes | be4de46 | 2014-07-14 17:15:41 -0700 | [diff] [blame] | 78 | self.register_line = re.compile("(([ ]*\\b(" + self.register_names[symbol.ARCH] + ")\\b +[0-9a-f]" + self.width + "){2,5})") |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 79 | |
| 80 | # Note that both trace and value line matching allow for variable amounts of |
| 81 | # whitespace (e.g. \t). This is because the we want to allow for the stack |
| 82 | # tool to operate on AndroidFeedback provided system logs. AndroidFeedback |
| 83 | # strips out double spaces that are found in tombsone files and logcat output. |
| 84 | # |
| 85 | # Examples of matched trace lines include lines from tombstone files like: |
| 86 | # #00 pc 001cf42e /data/data/com.my.project/lib/libmyproject.so |
| 87 | # |
| 88 | # Or lines from AndroidFeedback crash report system logs like: |
| 89 | # 03-25 00:51:05.520 I/DEBUG ( 65): #00 pc 001cf42e /data/data/com.my.project/lib/libmyproject.so |
| 90 | # Please note the spacing differences. |
| Andreas Gampe | d900d08 | 2015-08-21 15:25:03 -0700 | [diff] [blame] | 91 | self.trace_line = re.compile( |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 92 | r".*" # Random start stuff. |
| 93 | r"\#(?P<frame>[0-9]+)" # Frame number. |
| 94 | r"[ \t]+..[ \t]+" # (space)pc(space). |
| 95 | r"(?P<offset>[0-9a-f]" + self.width + ")[ \t]+" # Offset (hex number given without |
| 96 | # 0x prefix). |
| 97 | r"(?P<dso>\[[^\]]+\]|[^\r\n \t]*)" # Library name. |
| 98 | r"( \(offset (?P<so_offset>0x[0-9a-fA-F]+)\))?" # Offset into the file to find the start of the shared so. |
| 99 | r"(?P<symbolpresent> \((?P<symbol>.*)\))?") # Is the symbol there? |
| 100 | # pylint: disable-msg=C6310 |
| Andreas Gampe | d900d08 | 2015-08-21 15:25:03 -0700 | [diff] [blame] | 101 | # Sanitizer output. This is different from debuggerd output, and it is easier to handle this as |
| 102 | # its own regex. Example: |
| 103 | # 08-19 05:29:26.283 397 403 I : #0 0xb6a15237 (/system/lib/libclang_rt.asan-arm-android.so+0x4f237) |
| 104 | self.sanitizer_trace_line = re.compile( |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 105 | r".*" # Random start stuff. |
| 106 | r"\#(?P<frame>[0-9]+)" # Frame number. |
| 107 | r"[ \t]+0x[0-9a-f]+[ \t]+" # PC, not interesting to us. |
| 108 | r"\(" # Opening paren. |
| 109 | r"(?P<dso>[^+]+)" # Library name. |
| 110 | r"\+" # '+' |
| 111 | r"0x(?P<offset>[0-9a-f]+)" # Offset (hex number given with |
| 112 | # 0x prefix). |
| 113 | r"\)") # Closing paren. |
| 114 | # pylint: disable-msg=C6310 |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 115 | # Examples of matched value lines include: |
| 116 | # bea4170c 8018e4e9 /data/data/com.my.project/lib/libmyproject.so |
| 117 | # bea4170c 8018e4e9 /data/data/com.my.project/lib/libmyproject.so (symbol) |
| 118 | # 03-25 00:51:05.530 I/DEBUG ( 65): bea4170c 8018e4e9 /data/data/com.my.project/lib/libmyproject.so |
| 119 | # Again, note the spacing differences. |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 120 | self.value_line = re.compile(r"(.*)([0-9a-f]" + self.width + r")[ \t]+([0-9a-f]" + self.width + r")[ \t]+([^\r\n \t]*)( \((.*)\))?") |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 121 | # Lines from 'code around' sections of the output will be matched before |
| 122 | # value lines because otheriwse the 'code around' sections will be confused as |
| 123 | # value lines. |
| 124 | # |
| 125 | # Examples include: |
| 126 | # 801cf40c ffffc4cc 00b2f2c5 00b2f1c7 00c1e1a8 |
| 127 | # 03-25 00:51:05.530 I/DEBUG ( 65): 801cf40c ffffc4cc 00b2f2c5 00b2f1c7 00c1e1a8 |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 128 | self.code_line = re.compile(r"(.*)[ \t]*[a-f0-9]" + self.width + |
| 129 | r"[ \t]*[a-f0-9]" + self.width + |
| 130 | r"[ \t]*[a-f0-9]" + self.width + |
| 131 | r"[ \t]*[a-f0-9]" + self.width + |
| 132 | r"[ \t]*[a-f0-9]" + self.width + |
| 133 | r"[ \t]*[ \r\n]") # pylint: disable-msg=C6310 |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 134 | |
| 135 | def CleanLine(self, ln): |
| 136 | # AndroidFeedback adds zero width spaces into its crash reports. These |
| 137 | # should be removed or the regular expresssions will fail to match. |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 138 | return ln.encode().decode(encoding='utf8', errors='ignore') |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 139 | |
| 140 | def PrintTraceLines(self, trace_lines): |
| 141 | """Print back trace.""" |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 142 | maxlen = max(len(tl[1]) for tl in trace_lines) |
| 143 | print("\nStack Trace:") |
| 144 | print(" RELADDR " + self.spacing + "FUNCTION".ljust(maxlen) + " FILE:LINE") |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 145 | for tl in self.trace_lines: |
| 146 | (addr, symbol_with_offset, location) = tl |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 147 | print(" %8s %s %s" % (addr, symbol_with_offset.ljust(maxlen), location)) |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 148 | |
| 149 | def PrintValueLines(self, value_lines): |
| 150 | """Print stack data values.""" |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 151 | maxlen = max(len(tl[2]) for tl in self.value_lines) |
| 152 | print("\nStack Data:") |
| 153 | print(" ADDR " + self.spacing + "VALUE " + "FUNCTION".ljust(maxlen) + " FILE:LINE") |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 154 | for vl in self.value_lines: |
| 155 | (addr, value, symbol_with_offset, location) = vl |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 156 | print(" %8s %8s %s %s" % (addr, value, symbol_with_offset.ljust(maxlen), location)) |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 157 | |
| 158 | def PrintOutput(self, trace_lines, value_lines): |
| 159 | if self.trace_lines: |
| 160 | self.PrintTraceLines(self.trace_lines) |
| 161 | if self.value_lines: |
| 162 | self.PrintValueLines(self.value_lines) |
| 163 | |
| 164 | def PrintDivider(self): |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 165 | print("\n-----------------------------------------------------\n") |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 166 | |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 167 | def DeleteApkTmpFiles(self): |
| Christopher Ferris | abe22f4 | 2016-03-16 12:17:59 -0700 | [diff] [blame] | 168 | for _, _, tmp_files in self.apk_info.values(): |
| 169 | for tmp_file in tmp_files.values(): |
| 170 | os.unlink(tmp_file) |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 171 | |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 172 | def ConvertTrace(self, lines): |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 173 | lines = [self.CleanLine(line) for line in lines] |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 174 | try: |
| Christopher Ferris | bf8a940 | 2016-03-11 15:50:46 -0800 | [diff] [blame] | 175 | if not symbol.ARCH: |
| 176 | symbol.SetAbi(lines) |
| 177 | self.UpdateAbiRegexes() |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 178 | for line in lines: |
| 179 | self.ProcessLine(line) |
| 180 | self.PrintOutput(self.trace_lines, self.value_lines) |
| 181 | finally: |
| 182 | # Delete any temporary files created while processing the lines. |
| 183 | self.DeleteApkTmpFiles() |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 184 | |
| Andreas Gampe | d900d08 | 2015-08-21 15:25:03 -0700 | [diff] [blame] | 185 | def MatchTraceLine(self, line): |
| 186 | if self.trace_line.match(line): |
| 187 | match = self.trace_line.match(line) |
| 188 | return {"frame": match.group("frame"), |
| 189 | "offset": match.group("offset"), |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 190 | "so_offset": match.group("so_offset"), |
| Andreas Gampe | d900d08 | 2015-08-21 15:25:03 -0700 | [diff] [blame] | 191 | "dso": match.group("dso"), |
| 192 | "symbol_present": bool(match.group("symbolpresent")), |
| 193 | "symbol_name": match.group("symbol")} |
| 194 | if self.sanitizer_trace_line.match(line): |
| 195 | match = self.sanitizer_trace_line.match(line) |
| 196 | return {"frame": match.group("frame"), |
| 197 | "offset": match.group("offset"), |
| Andreas Gampe | 57acd5f | 2015-09-17 11:44:21 -0700 | [diff] [blame] | 198 | "so_offset": None, |
| Andreas Gampe | d900d08 | 2015-08-21 15:25:03 -0700 | [diff] [blame] | 199 | "dso": match.group("dso"), |
| 200 | "symbol_present": False, |
| 201 | "symbol_name": None} |
| 202 | return None |
| 203 | |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 204 | def ExtractLibFromApk(self, apk, shared_lib_name): |
| 205 | # Create a temporary file containing the shared library from the apk. |
| 206 | tmp_file = None |
| 207 | try: |
| 208 | tmp_fd, tmp_file = tempfile.mkstemp() |
| 209 | if subprocess.call(["unzip", "-p", apk, shared_lib_name], stdout=tmp_fd) == 0: |
| 210 | os.close(tmp_fd) |
| 211 | shared_file = tmp_file |
| 212 | tmp_file = None |
| 213 | return shared_file |
| 214 | finally: |
| 215 | if tmp_file: |
| 216 | os.close(tmp_fd) |
| 217 | os.unlink(tmp_file) |
| 218 | return None |
| 219 | |
| Christopher Ferris | abe22f4 | 2016-03-16 12:17:59 -0700 | [diff] [blame] | 220 | def ProcessCentralInfo(self, offset_list, central_info): |
| 221 | match = self.zipinfo_central_info_match.search(central_info) |
| 222 | if not match: |
| 223 | raise Exception("Cannot find all info from zipinfo\n" + central_info) |
| 224 | name = match.group(1) |
| 225 | start = int(match.group(2)) |
| 226 | end = start + int(match.group(3)) |
| 227 | |
| 228 | offset_list.append([name, start, end]) |
| 229 | return name, start, end |
| 230 | |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 231 | def GetLibFromApk(self, apk, offset): |
| 232 | # Convert the string to hex. |
| 233 | offset = int(offset, 16) |
| 234 | |
| 235 | # Check if we already have information about this offset. |
| 236 | if apk in self.apk_info: |
| Christopher Ferris | abe22f4 | 2016-03-16 12:17:59 -0700 | [diff] [blame] | 237 | apk_full_path, offset_list, tmp_files = self.apk_info[apk] |
| 238 | for file_name, start, end in offset_list: |
| 239 | if offset >= start and offset < end: |
| 240 | if file_name in tmp_files: |
| 241 | return file_name, tmp_files[file_name] |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 242 | tmp_file = self.ExtractLibFromApk(apk_full_path, file_name) |
| 243 | if tmp_file: |
| Christopher Ferris | abe22f4 | 2016-03-16 12:17:59 -0700 | [diff] [blame] | 244 | tmp_files[file_name] = tmp_file |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 245 | return file_name, tmp_file |
| 246 | break |
| 247 | return None, None |
| 248 | |
| 249 | if not "ANDROID_PRODUCT_OUT" in os.environ: |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 250 | print("ANDROID_PRODUCT_OUT environment variable not set.") |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 251 | return None, None |
| 252 | out_dir = os.environ["ANDROID_PRODUCT_OUT"] |
| 253 | if not os.path.exists(out_dir): |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 254 | print("ANDROID_PRODUCT_OUT", out_dir, "does not exist.") |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 255 | return None, None |
| 256 | if apk.startswith("/"): |
| 257 | apk_full_path = out_dir + apk |
| 258 | else: |
| 259 | apk_full_path = os.path.join(out_dir, apk) |
| 260 | if not os.path.exists(apk_full_path): |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 261 | print("Cannot find apk", apk) |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 262 | return None, None |
| 263 | |
| Christopher Ferris | 7ea56f0 | 2021-10-21 00:20:18 +0000 | [diff] [blame^] | 264 | cmd = subprocess.Popen(["zipinfo", "-v", apk_full_path], stdout=subprocess.PIPE, |
| 265 | encoding='utf8') |
| Christopher Ferris | abe22f4 | 2016-03-16 12:17:59 -0700 | [diff] [blame] | 266 | # Find the first central info marker. |
| 267 | for line in cmd.stdout: |
| 268 | if self.zipinfo_central_directory_line.search(line): |
| 269 | break |
| 270 | |
| 271 | central_info = "" |
| 272 | file_name = None |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 273 | offset_list = [] |
| 274 | for line in cmd.stdout: |
| Christopher Ferris | abe22f4 | 2016-03-16 12:17:59 -0700 | [diff] [blame] | 275 | match = self.zipinfo_central_directory_line.search(line) |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 276 | if match: |
| Christopher Ferris | abe22f4 | 2016-03-16 12:17:59 -0700 | [diff] [blame] | 277 | cur_name, start, end = self.ProcessCentralInfo(offset_list, central_info) |
| 278 | if not file_name and offset >= start and offset < end: |
| 279 | file_name = cur_name |
| 280 | central_info = "" |
| 281 | else: |
| 282 | central_info += line |
| 283 | if central_info: |
| 284 | cur_name, start, end = self.ProcessCentralInfo(offset_list, central_info) |
| 285 | if not file_name and offset >= start and offset < end: |
| 286 | file_name = cur_name |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 287 | |
| Christopher Ferris | 7ea56f0 | 2021-10-21 00:20:18 +0000 | [diff] [blame^] | 288 | # Make sure the offset_list is sorted, the zip file does not guarantee |
| 289 | # that the entries are in order. |
| 290 | offset_list = sorted(offset_list, key=lambda entry: entry[1]) |
| 291 | |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 292 | # Save the information from the zip. |
| Christopher Ferris | abe22f4 | 2016-03-16 12:17:59 -0700 | [diff] [blame] | 293 | tmp_files = dict() |
| 294 | self.apk_info[apk] = [apk_full_path, offset_list, tmp_files] |
| 295 | if not file_name: |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 296 | return None, None |
| Christopher Ferris | abe22f4 | 2016-03-16 12:17:59 -0700 | [diff] [blame] | 297 | tmp_shared_lib = self.ExtractLibFromApk(apk_full_path, file_name) |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 298 | if tmp_shared_lib: |
| Christopher Ferris | abe22f4 | 2016-03-16 12:17:59 -0700 | [diff] [blame] | 299 | tmp_files[file_name] = tmp_shared_lib |
| 300 | return file_name, tmp_shared_lib |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 301 | return None, None |
| 302 | |
| Christopher Ferris | 1f2051d | 2021-09-10 14:41:00 -0700 | [diff] [blame] | 303 | def GetLibPath(self, lib): |
| 304 | symbol_dir = symbol.SYMBOLS_DIR |
| 305 | if os.path.isfile(symbol_dir + lib): |
| 306 | return lib |
| 307 | |
| 308 | # When using atest, test paths are different between the out/ directory |
| 309 | # and device. Apply fixups. |
| 310 | if not lib.startswith("/data/local/tests/") and not lib.startswith("/data/local/tmp/"): |
| 311 | print("WARNING: Cannot find %s in symbol directory" % lib) |
| 312 | return lib |
| 313 | |
| 314 | test_name = lib.rsplit("/", 1)[-1] |
| 315 | test_dir = "/data/nativetest" |
| 316 | test_dir_bitness = "" |
| 317 | if symbol.ARCH.endswith("64"): |
| 318 | bitness = "64" |
| 319 | test_dir_bitness = "64" |
| 320 | else: |
| 321 | bitness = "32" |
| 322 | |
| 323 | # Unfortunately, the location of the real symbol file is not |
| 324 | # standardized, so we need to go hunting for it. |
| 325 | |
| 326 | # This is in vendor, look for the value in: |
| 327 | # /data/nativetest{64}/vendor/test_name/test_name |
| 328 | if lib.startswith("/data/local/tests/vendor/"): |
| 329 | lib_path = os.path.join(test_dir + test_dir_bitness, "vendor", test_name, test_name) |
| 330 | if os.path.isfile(symbol_dir + lib_path): |
| 331 | return lib_path |
| 332 | |
| 333 | # Look for the path in: |
| 334 | # /data/nativetest{64}/test_name/test_name |
| 335 | lib_path = os.path.join(test_dir + test_dir_bitness, test_name, test_name) |
| 336 | if os.path.isfile(symbol_dir + lib_path): |
| 337 | return lib_path |
| 338 | |
| 339 | # CtsXXX tests are in really non-standard locations try: |
| 340 | # /data/nativetest/{test_name} |
| 341 | lib_path = os.path.join(test_dir, test_name) |
| 342 | if os.path.isfile(symbol_dir + lib_path): |
| 343 | return lib_path |
| 344 | # Try: |
| 345 | # /data/nativetest/{test_name}{32|64} |
| 346 | lib_path += bitness |
| 347 | if os.path.isfile(symbol_dir + lib_path): |
| 348 | return lib_path |
| 349 | |
| 350 | # Cannot find location, give up and return the original path |
| 351 | print("WARNING: Cannot find %s in symbol directory" % lib) |
| 352 | return lib |
| 353 | |
| 354 | |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 355 | def ProcessLine(self, line): |
| Brigid Smith | 9c2192a | 2014-07-07 10:33:21 -0700 | [diff] [blame] | 356 | ret = False |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 357 | process_header = self.process_info_line.search(line) |
| 358 | signal_header = self.signal_line.search(line) |
| 359 | abort_message_header = self.abort_message_line.search(line) |
| 360 | thread_header = self.thread_line.search(line) |
| 361 | register_header = self.register_line.search(line) |
| Brigid Smith | 0b30940 | 2014-07-07 14:34:00 -0700 | [diff] [blame] | 362 | revision_header = self.revision_line.search(line) |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 363 | dalvik_jni_thread_header = self.dalvik_jni_thread_line.search(line) |
| 364 | dalvik_native_thread_header = self.dalvik_native_thread_line.search(line) |
| Colin Cross | 807ec0e | 2016-03-04 17:29:01 -0800 | [diff] [blame] | 365 | unreachable_header = self.unreachable_line.search(line) |
| Christopher Ferris | bf8a940 | 2016-03-11 15:50:46 -0800 | [diff] [blame] | 366 | if process_header or signal_header or abort_message_header or thread_header or \ |
| Colin Cross | 807ec0e | 2016-03-04 17:29:01 -0800 | [diff] [blame] | 367 | register_header or dalvik_jni_thread_header or dalvik_native_thread_header or \ |
| 368 | revision_header or unreachable_header: |
| 369 | ret = True |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 370 | if self.trace_lines or self.value_lines: |
| 371 | self.PrintOutput(self.trace_lines, self.value_lines) |
| 372 | self.PrintDivider() |
| 373 | self.trace_lines = [] |
| 374 | self.value_lines = [] |
| 375 | self.last_frame = -1 |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 376 | if process_header: |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 377 | print(process_header.group(1)) |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 378 | if signal_header: |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 379 | print(signal_header.group(1)) |
| Elliott Hughes | d2471c8 | 2014-06-17 16:55:10 -0700 | [diff] [blame] | 380 | if abort_message_header: |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 381 | print(abort_message_header.group(1)) |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 382 | if register_header: |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 383 | print(register_header.group(1)) |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 384 | if thread_header: |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 385 | print(thread_header.group(1)) |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 386 | if dalvik_jni_thread_header: |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 387 | print(dalvik_jni_thread_header.group(1)) |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 388 | if dalvik_native_thread_header: |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 389 | print(dalvik_native_thread_header.group(1)) |
| Brigid Smith | 0b30940 | 2014-07-07 14:34:00 -0700 | [diff] [blame] | 390 | if revision_header: |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 391 | print(revision_header.group(1)) |
| Colin Cross | 807ec0e | 2016-03-04 17:29:01 -0800 | [diff] [blame] | 392 | if unreachable_header: |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 393 | print(unreachable_header.group(1)) |
| Christopher Ferris | bf8a940 | 2016-03-11 15:50:46 -0800 | [diff] [blame] | 394 | return True |
| Andreas Gampe | d900d08 | 2015-08-21 15:25:03 -0700 | [diff] [blame] | 395 | trace_line_dict = self.MatchTraceLine(line) |
| 396 | if trace_line_dict is not None: |
| Brigid Smith | 9c2192a | 2014-07-07 10:33:21 -0700 | [diff] [blame] | 397 | ret = True |
| Andreas Gampe | 48068ac | 2016-07-25 21:07:27 -0700 | [diff] [blame] | 398 | frame = int(trace_line_dict["frame"]) |
| Andreas Gampe | d900d08 | 2015-08-21 15:25:03 -0700 | [diff] [blame] | 399 | code_addr = trace_line_dict["offset"] |
| 400 | area = trace_line_dict["dso"] |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 401 | so_offset = trace_line_dict["so_offset"] |
| Andreas Gampe | d900d08 | 2015-08-21 15:25:03 -0700 | [diff] [blame] | 402 | symbol_present = trace_line_dict["symbol_present"] |
| 403 | symbol_name = trace_line_dict["symbol_name"] |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 404 | |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 405 | if frame <= self.last_frame and (self.trace_lines or self.value_lines): |
| 406 | self.PrintOutput(self.trace_lines, self.value_lines) |
| 407 | self.PrintDivider() |
| 408 | self.trace_lines = [] |
| 409 | self.value_lines = [] |
| 410 | self.last_frame = frame |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 411 | |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 412 | if area == "<unknown>" or area == "[heap]" or area == "[stack]": |
| 413 | self.trace_lines.append((code_addr, "", area)) |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 414 | else: |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 415 | # If this is an apk, it usually means that there is actually |
| 416 | # a shared so that was loaded directly out of it. In that case, |
| 417 | # extract the shared library and the name of the shared library. |
| 418 | lib = None |
| Christopher Ferris | 55a9699 | 2019-03-13 15:37:31 -0700 | [diff] [blame] | 419 | # The format of the map name: |
| 420 | # Some.apk!libshared.so |
| 421 | # or |
| 422 | # Some.apk |
| 423 | if so_offset: |
| 424 | # If it ends in apk, we are done. |
| 425 | apk = None |
| 426 | if area.endswith(".apk"): |
| 427 | apk = area |
| 428 | else: |
| Christopher Ferris | 5e4b372 | 2020-01-31 14:38:07 -0800 | [diff] [blame] | 429 | index = area.rfind(".so!") |
| Christopher Ferris | 55a9699 | 2019-03-13 15:37:31 -0700 | [diff] [blame] | 430 | if index != -1: |
| Christopher Ferris | 5e4b372 | 2020-01-31 14:38:07 -0800 | [diff] [blame] | 431 | # Sometimes we'll see something like: |
| 432 | # #01 pc abcd libart.so!libart.so (offset 0x134000) |
| 433 | # Remove everything after the ! and zero the offset value. |
| 434 | area = area[0:index + 3] |
| 435 | so_offset = 0 |
| 436 | else: |
| 437 | index = area.rfind(".apk!") |
| 438 | if index != -1: |
| 439 | apk = area[0:index + 4] |
| Christopher Ferris | ac90d1d | 2019-03-15 12:21:57 -0700 | [diff] [blame] | 440 | if apk: |
| Christopher Ferris | 55a9699 | 2019-03-13 15:37:31 -0700 | [diff] [blame] | 441 | lib_name, lib = self.GetLibFromApk(apk, so_offset) |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 442 | if not lib: |
| 443 | lib = area |
| 444 | lib_name = None |
| 445 | |
| Krzysztof Kosiński | dd45e18 | 2021-02-24 15:21:50 -0800 | [diff] [blame] | 446 | # When using atest, test paths are different between the out/ directory |
| 447 | # and device. Apply fixups. |
| Christopher Ferris | 1f2051d | 2021-09-10 14:41:00 -0700 | [diff] [blame] | 448 | lib = self.GetLibPath(lib) |
| Krzysztof Kosiński | dd45e18 | 2021-02-24 15:21:50 -0800 | [diff] [blame] | 449 | |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 450 | # If a calls b which further calls c and c is inlined to b, we want to |
| 451 | # display "a -> b -> c" in the stack trace instead of just "a -> c" |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 452 | info = symbol.SymbolInformation(lib, code_addr) |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 453 | nest_count = len(info) - 1 |
| 454 | for (source_symbol, source_location, object_symbol_with_offset) in info: |
| 455 | if not source_symbol: |
| 456 | if symbol_present: |
| 457 | source_symbol = symbol.CallCppFilt(symbol_name) |
| 458 | else: |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 459 | source_symbol = "<unknown>" |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 460 | if not source_location: |
| 461 | source_location = area |
| Christopher Ferris | ece64c4 | 2015-08-20 20:09:09 -0700 | [diff] [blame] | 462 | if lib_name: |
| 463 | source_location += "(" + lib_name + ")" |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 464 | if nest_count > 0: |
| 465 | nest_count = nest_count - 1 |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 466 | arrow = "v------>" |
| 467 | if symbol.ARCH == "arm64" or symbol.ARCH == "mips64" or symbol.ARCH == "x86_64": |
| 468 | arrow = "v-------------->" |
| 469 | self.trace_lines.append((arrow, source_symbol, source_location)) |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 470 | else: |
| 471 | if not object_symbol_with_offset: |
| 472 | object_symbol_with_offset = source_symbol |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 473 | self.trace_lines.append((code_addr, |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 474 | object_symbol_with_offset, |
| 475 | source_location)) |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 476 | if self.code_line.match(line): |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 477 | # Code lines should be ignored. If this were exluded the 'code around' |
| 478 | # sections would trigger value_line matches. |
| Brigid Smith | 9c2192a | 2014-07-07 10:33:21 -0700 | [diff] [blame] | 479 | return ret |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 480 | if self.value_line.match(line): |
| Brigid Smith | 9c2192a | 2014-07-07 10:33:21 -0700 | [diff] [blame] | 481 | ret = True |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 482 | match = self.value_line.match(line) |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 483 | (unused_, addr, value, area, symbol_present, symbol_name) = match.groups() |
| Brigid Smith | ea0a835 | 2014-06-30 16:01:40 -0700 | [diff] [blame] | 484 | if area == "<unknown>" or area == "[heap]" or area == "[stack]" or not area: |
| 485 | self.value_lines.append((addr, value, "", area)) |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 486 | else: |
| 487 | info = symbol.SymbolInformation(area, value) |
| 488 | (source_symbol, source_location, object_symbol_with_offset) = info.pop() |
| Christopher Ferris | 5f1b4f0 | 2016-09-19 13:24:37 -0700 | [diff] [blame] | 489 | # If there is no information, skip this. |
| 490 | if source_symbol or source_location or object_symbol_with_offset: |
| 491 | if not source_symbol: |
| 492 | if symbol_present: |
| 493 | source_symbol = symbol.CallCppFilt(symbol_name) |
| 494 | else: |
| 495 | source_symbol = "<unknown>" |
| 496 | if not source_location: |
| 497 | source_location = area |
| 498 | if not object_symbol_with_offset: |
| 499 | object_symbol_with_offset = source_symbol |
| 500 | self.value_lines.append((addr, |
| 501 | value, |
| 502 | object_symbol_with_offset, |
| 503 | source_location)) |
| Ben Cheng | b42dad0 | 2013-04-25 15:14:04 -0700 | [diff] [blame] | 504 | |
| Brigid Smith | 9c2192a | 2014-07-07 10:33:21 -0700 | [diff] [blame] | 505 | return ret |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 506 | |
| 507 | |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 508 | class RegisterPatternTests(unittest.TestCase): |
| 509 | def assert_register_matches(self, abi, example_crash, stupid_pattern): |
| 510 | tc = TraceConverter() |
| Christopher Ferris | bf8a940 | 2016-03-11 15:50:46 -0800 | [diff] [blame] | 511 | lines = example_crash.split('\n') |
| 512 | symbol.SetAbi(lines) |
| 513 | tc.UpdateAbiRegexes() |
| 514 | for line in lines: |
| Elliott Hughes | c3c8619 | 2014-08-29 13:49:57 -0700 | [diff] [blame] | 515 | tc.ProcessLine(line) |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 516 | is_register = (re.search(stupid_pattern, line) is not None) |
| 517 | matched = (tc.register_line.search(line) is not None) |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 518 | self.assertEqual(matched, is_register, line) |
| Elliott Hughes | c3c8619 | 2014-08-29 13:49:57 -0700 | [diff] [blame] | 519 | tc.PrintOutput(tc.trace_lines, tc.value_lines) |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 520 | |
| 521 | def test_arm_registers(self): |
| Elliott Hughes | c3166be | 2014-07-07 15:06:28 -0700 | [diff] [blame] | 522 | self.assert_register_matches("arm", example_crashes.arm, '\\b(r0|r4|r8|ip)\\b') |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 523 | |
| 524 | def test_arm64_registers(self): |
| Elliott Hughes | c3166be | 2014-07-07 15:06:28 -0700 | [diff] [blame] | 525 | self.assert_register_matches("arm64", example_crashes.arm64, '\\b(x0|x4|x8|x12|x16|x20|x24|x28|sp)\\b') |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 526 | |
| 527 | def test_mips_registers(self): |
| Elliott Hughes | c3166be | 2014-07-07 15:06:28 -0700 | [diff] [blame] | 528 | self.assert_register_matches("mips", example_crashes.mips, '\\b(zr|a0|t0|t4|s0|s4|t8|gp|hi)\\b') |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 529 | |
| Andreas Gampe | 820ca72 | 2015-06-01 15:43:52 -0700 | [diff] [blame] | 530 | def test_mips64_registers(self): |
| 531 | self.assert_register_matches("mips64", example_crashes.mips64, '\\b(zr|a0|a4|t0|s0|s4|t8|gp|hi)\\b') |
| 532 | |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 533 | def test_x86_registers(self): |
| Elliott Hughes | c3166be | 2014-07-07 15:06:28 -0700 | [diff] [blame] | 534 | self.assert_register_matches("x86", example_crashes.x86, '\\b(eax|esi|xcs|eip)\\b') |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 535 | |
| 536 | def test_x86_64_registers(self): |
| Elliott Hughes | c3166be | 2014-07-07 15:06:28 -0700 | [diff] [blame] | 537 | self.assert_register_matches("x86_64", example_crashes.x86_64, '\\b(rax|rsi|r8|r12|cs|rip)\\b') |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 538 | |
| Colin Cross | 807ec0e | 2016-03-04 17:29:01 -0800 | [diff] [blame] | 539 | class LibmemunreachablePatternTests(unittest.TestCase): |
| 540 | def test_libmemunreachable(self): |
| 541 | tc = TraceConverter() |
| 542 | lines = example_crashes.libmemunreachable.split('\n') |
| 543 | |
| 544 | symbol.SetAbi(lines) |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 545 | self.assertEqual(symbol.ARCH, "arm") |
| Colin Cross | 807ec0e | 2016-03-04 17:29:01 -0800 | [diff] [blame] | 546 | |
| 547 | tc.UpdateAbiRegexes() |
| 548 | header_lines = 0 |
| Colin Cross | 1127df9 | 2016-07-26 10:15:01 -0700 | [diff] [blame] | 549 | trace_lines = 0 |
| Colin Cross | 807ec0e | 2016-03-04 17:29:01 -0800 | [diff] [blame] | 550 | for line in lines: |
| 551 | tc.ProcessLine(line) |
| 552 | if re.search(tc.unreachable_line, line) is not None: |
| 553 | header_lines += 1 |
| Colin Cross | 1127df9 | 2016-07-26 10:15:01 -0700 | [diff] [blame] | 554 | if tc.MatchTraceLine(line) is not None: |
| 555 | trace_lines += 1 |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 556 | self.assertEqual(header_lines, 3) |
| 557 | self.assertEqual(trace_lines, 2) |
| Colin Cross | 807ec0e | 2016-03-04 17:29:01 -0800 | [diff] [blame] | 558 | tc.PrintOutput(tc.trace_lines, tc.value_lines) |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 559 | |
| Andreas Gampe | 48068ac | 2016-07-25 21:07:27 -0700 | [diff] [blame] | 560 | class LongASANStackTests(unittest.TestCase): |
| 561 | # Test that a long ASAN-style (non-padded frame numbers) stack trace is not split into two |
| 562 | # when the frame number becomes two digits. This happened before as the frame number was |
| 563 | # handled as a string and not converted to an integral. |
| 564 | def test_long_asan_crash(self): |
| 565 | tc = TraceConverter() |
| 566 | lines = example_crashes.long_asan_crash.splitlines() |
| 567 | symbol.SetAbi(lines) |
| 568 | tc.UpdateAbiRegexes() |
| 569 | # Test by making sure trace_line_count is monotonically non-decreasing. If the stack trace |
| 570 | # is split, a separator is printed and trace_lines is flushed. |
| 571 | trace_line_count = 0 |
| 572 | for line in lines: |
| 573 | tc.ProcessLine(line) |
| 574 | self.assertLessEqual(trace_line_count, len(tc.trace_lines)) |
| 575 | trace_line_count = len(tc.trace_lines) |
| 576 | # The split happened at transition of frame #9 -> #10. Make sure we have parsed (and stored) |
| 577 | # more than ten frames. |
| 578 | self.assertGreater(trace_line_count, 10) |
| 579 | tc.PrintOutput(tc.trace_lines, tc.value_lines) |
| 580 | |
| Christopher Ferris | 5f1b4f0 | 2016-09-19 13:24:37 -0700 | [diff] [blame] | 581 | class ValueLinesTest(unittest.TestCase): |
| 582 | def test_value_line_skipped(self): |
| 583 | tc = TraceConverter() |
| 584 | symbol.SetAbi(["ABI: 'arm'"]) |
| 585 | tc.UpdateAbiRegexes() |
| 586 | tc.ProcessLine(" 12345678 00001000 .") |
| 587 | self.assertEqual([], tc.value_lines) |
| 588 | |
| Elliott Hughes | a9e3417 | 2014-07-01 14:56:22 -0700 | [diff] [blame] | 589 | if __name__ == '__main__': |
| Krzysztof Kosiński | b136111 | 2021-03-11 18:05:01 -0800 | [diff] [blame] | 590 | unittest.main(verbosity=2) |