| File: | root/firefox-clang/obj-x86_64-pc-linux-gnu/toolkit/crashreporter/google-breakpad/src/processor/./../../../../../../toolkit/crashreporter/google-breakpad/src/processor/stackwalk_common.cc |
| Warning: | line 311, column 9 Value stored to 'sequence' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | // Copyright (c) 2010 Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | // stackwalk_common.cc: Module shared by the {micro,mini}dump_stackwalck |
| 31 | // executables to print the content of dumps (w/ stack traces) on the console. |
| 32 | // |
| 33 | // Author: Mark Mentovai |
| 34 | |
| 35 | #include "processor/stackwalk_common.h" |
| 36 | |
| 37 | #include <assert.h> |
| 38 | #include <stdlib.h> |
| 39 | #include <string.h> |
| 40 | |
| 41 | #include <string> |
| 42 | #include <vector> |
| 43 | |
| 44 | #include "common/stdio_wrapper.h" |
| 45 | #include "common/using_std_string.h" |
| 46 | #include "google_breakpad/processor/call_stack.h" |
| 47 | #include "google_breakpad/processor/code_module.h" |
| 48 | #include "google_breakpad/processor/code_modules.h" |
| 49 | #include "google_breakpad/processor/process_state.h" |
| 50 | #include "google_breakpad/processor/source_line_resolver_interface.h" |
| 51 | #include "google_breakpad/processor/stack_frame_cpu.h" |
| 52 | #include "processor/logging.h" |
| 53 | #include "processor/pathname_stripper.h" |
| 54 | |
| 55 | namespace google_breakpad { |
| 56 | |
| 57 | namespace { |
| 58 | |
| 59 | using std::vector; |
| 60 | |
| 61 | // Separator character for machine readable output. |
| 62 | static const char kOutputSeparator = '|'; |
| 63 | |
| 64 | // PrintRegister prints a register's name and value to stdout. It will |
| 65 | // print four registers on a line. For the first register in a set, |
| 66 | // pass 0 for |start_col|. For registers in a set, pass the most recent |
| 67 | // return value of PrintRegister. |
| 68 | // The caller is responsible for printing the final newline after a set |
| 69 | // of registers is completely printed, regardless of the number of calls |
| 70 | // to PrintRegister. |
| 71 | static const int kMaxWidth = 80; // optimize for an 80-column terminal |
| 72 | static int PrintRegister(const char *name, uint32_t value, int start_col) { |
| 73 | char buffer[64]; |
| 74 | snprintf(buffer, sizeof(buffer), " %5s = 0x%08x", name, value); |
| 75 | |
| 76 | if (start_col + static_cast<ssize_t>(strlen(buffer)) > kMaxWidth) { |
| 77 | start_col = 0; |
| 78 | printf("\n "); |
| 79 | } |
| 80 | fputs(buffer, stdoutstdout); |
| 81 | |
| 82 | return start_col + strlen(buffer); |
| 83 | } |
| 84 | |
| 85 | // PrintRegister64 does the same thing, but for 64-bit registers. |
| 86 | static int PrintRegister64(const char *name, uint64_t value, int start_col) { |
| 87 | char buffer[64]; |
| 88 | snprintf(buffer, sizeof(buffer), " %5s = 0x%016" PRIx64"l" "x" , name, value); |
| 89 | |
| 90 | if (start_col + static_cast<ssize_t>(strlen(buffer)) > kMaxWidth) { |
| 91 | start_col = 0; |
| 92 | printf("\n "); |
| 93 | } |
| 94 | fputs(buffer, stdoutstdout); |
| 95 | |
| 96 | return start_col + strlen(buffer); |
| 97 | } |
| 98 | |
| 99 | // StripSeparator takes a string |original| and returns a copy |
| 100 | // of the string with all occurences of |kOutputSeparator| removed. |
| 101 | static string StripSeparator(const string &original) { |
| 102 | string result = original; |
| 103 | string::size_type position = 0; |
| 104 | while ((position = result.find(kOutputSeparator, position)) != string::npos) { |
| 105 | result.erase(position, 1); |
| 106 | } |
| 107 | position = 0; |
| 108 | while ((position = result.find('\n', position)) != string::npos) { |
| 109 | result.erase(position, 1); |
| 110 | } |
| 111 | return result; |
| 112 | } |
| 113 | |
| 114 | // PrintStackContents prints the stack contents of the current frame to stdout. |
| 115 | static void PrintStackContents(const string &indent, |
| 116 | const StackFrame *frame, |
| 117 | const StackFrame *prev_frame, |
| 118 | const string &cpu, |
| 119 | const MemoryRegion *memory, |
| 120 | const CodeModules* modules, |
| 121 | SourceLineResolverInterface *resolver) { |
| 122 | // Find stack range. |
| 123 | int word_length = 0; |
| 124 | uint64_t stack_begin = 0, stack_end = 0; |
| 125 | if (cpu == "x86") { |
| 126 | word_length = 4; |
| 127 | const StackFrameX86 *frame_x86 = static_cast<const StackFrameX86*>(frame); |
| 128 | const StackFrameX86 *prev_frame_x86 = |
| 129 | static_cast<const StackFrameX86*>(prev_frame); |
| 130 | if ((frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_ESP) && |
| 131 | (prev_frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_ESP)) { |
| 132 | stack_begin = frame_x86->context.esp; |
| 133 | stack_end = prev_frame_x86->context.esp; |
| 134 | } |
| 135 | } else if (cpu == "amd64") { |
| 136 | word_length = 8; |
| 137 | const StackFrameAMD64 *frame_amd64 = |
| 138 | static_cast<const StackFrameAMD64*>(frame); |
| 139 | const StackFrameAMD64 *prev_frame_amd64 = |
| 140 | static_cast<const StackFrameAMD64*>(prev_frame); |
| 141 | if ((frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RSP) && |
| 142 | (prev_frame_amd64->context_validity & |
| 143 | StackFrameAMD64::CONTEXT_VALID_RSP)) { |
| 144 | stack_begin = frame_amd64->context.rsp; |
| 145 | stack_end = prev_frame_amd64->context.rsp; |
| 146 | } |
| 147 | } else if (cpu == "arm") { |
| 148 | word_length = 4; |
| 149 | const StackFrameARM *frame_arm = static_cast<const StackFrameARM*>(frame); |
| 150 | const StackFrameARM *prev_frame_arm = |
| 151 | static_cast<const StackFrameARM*>(prev_frame); |
| 152 | if ((frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_SP) && |
| 153 | (prev_frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_SP)) { |
| 154 | stack_begin = frame_arm->context.iregs[13]; |
| 155 | stack_end = prev_frame_arm->context.iregs[13]; |
| 156 | } |
| 157 | } else if (cpu == "arm64") { |
| 158 | word_length = 8; |
| 159 | const StackFrameARM64 *frame_arm64 = |
| 160 | static_cast<const StackFrameARM64*>(frame); |
| 161 | const StackFrameARM64 *prev_frame_arm64 = |
| 162 | static_cast<const StackFrameARM64*>(prev_frame); |
| 163 | if ((frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_SP) && |
| 164 | (prev_frame_arm64->context_validity & |
| 165 | StackFrameARM64::CONTEXT_VALID_SP)) { |
| 166 | stack_begin = frame_arm64->context.iregs[31]; |
| 167 | stack_end = prev_frame_arm64->context.iregs[31]; |
| 168 | } |
| 169 | } |
| 170 | if (!word_length || !stack_begin || !stack_end) |
| 171 | return; |
| 172 | |
| 173 | // Print stack contents. |
| 174 | printf("\n%sStack contents:", indent.c_str()); |
| 175 | for(uint64_t address = stack_begin; address < stack_end; ) { |
| 176 | // Print the start address of this row. |
| 177 | if (word_length == 4) |
| 178 | printf("\n%s %08x", indent.c_str(), static_cast<uint32_t>(address)); |
| 179 | else |
| 180 | printf("\n%s %016" PRIx64"l" "x", indent.c_str(), address); |
| 181 | |
| 182 | // Print data in hex. |
| 183 | const int kBytesPerRow = 16; |
| 184 | string data_as_string; |
| 185 | for (int i = 0; i < kBytesPerRow; ++i, ++address) { |
| 186 | uint8_t value = 0; |
| 187 | if (address < stack_end && |
| 188 | memory->GetMemoryAtAddress(address, &value)) { |
| 189 | printf(" %02x", value); |
| 190 | data_as_string.push_back(isprint(value) ? value : '.'); |
| 191 | } else { |
| 192 | printf(" "); |
| 193 | data_as_string.push_back(' '); |
| 194 | } |
| 195 | } |
| 196 | // Print data as string. |
| 197 | printf(" %s", data_as_string.c_str()); |
| 198 | } |
| 199 | |
| 200 | // Try to find instruction pointers from stack. |
| 201 | printf("\n%sPossible instruction pointers:\n", indent.c_str()); |
| 202 | for (uint64_t address = stack_begin; address < stack_end; |
| 203 | address += word_length) { |
| 204 | StackFrame pointee_frame; |
| 205 | |
| 206 | // Read a word (possible instruction pointer) from stack. |
| 207 | if (word_length == 4) { |
| 208 | uint32_t data32 = 0; |
| 209 | memory->GetMemoryAtAddress(address, &data32); |
| 210 | pointee_frame.instruction = data32; |
| 211 | } else { |
| 212 | uint64_t data64 = 0; |
| 213 | memory->GetMemoryAtAddress(address, &data64); |
| 214 | pointee_frame.instruction = data64; |
| 215 | } |
| 216 | pointee_frame.module = |
| 217 | modules->GetModuleForAddress(pointee_frame.instruction); |
| 218 | |
| 219 | // Try to look up the function name. |
| 220 | if (pointee_frame.module) |
| 221 | resolver->FillSourceLineInfo(&pointee_frame); |
| 222 | |
| 223 | // Print function name. |
| 224 | if (!pointee_frame.function_name.empty()) { |
| 225 | if (word_length == 4) { |
| 226 | printf("%s *(0x%08x) = 0x%08x", indent.c_str(), |
| 227 | static_cast<uint32_t>(address), |
| 228 | static_cast<uint32_t>(pointee_frame.instruction)); |
| 229 | } else { |
| 230 | printf("%s *(0x%016" PRIx64"l" "x" ") = 0x%016" PRIx64"l" "x", |
| 231 | indent.c_str(), address, pointee_frame.instruction); |
| 232 | } |
| 233 | printf(" <%s> [%s : %d + 0x%" PRIx64"l" "x" "]\n", |
| 234 | pointee_frame.function_name.c_str(), |
| 235 | PathnameStripper::File(pointee_frame.source_file_name).c_str(), |
| 236 | pointee_frame.source_line, |
| 237 | pointee_frame.instruction - pointee_frame.source_line_base); |
| 238 | } |
| 239 | } |
| 240 | printf("\n"); |
| 241 | } |
| 242 | |
| 243 | // PrintStack prints the call stack in |stack| to stdout, in a reasonably |
| 244 | // useful form. Module, function, and source file names are displayed if |
| 245 | // they are available. The code offset to the base code address of the |
| 246 | // source line, function, or module is printed, preferring them in that |
| 247 | // order. If no source line, function, or module information is available, |
| 248 | // an absolute code offset is printed. |
| 249 | // |
| 250 | // If |cpu| is a recognized CPU name, relevant register state for each stack |
| 251 | // frame printed is also output, if available. |
| 252 | static void PrintStack(const CallStack *stack, |
| 253 | const string &cpu, |
| 254 | bool output_stack_contents, |
| 255 | const MemoryRegion* memory, |
| 256 | const CodeModules* modules, |
| 257 | SourceLineResolverInterface* resolver) { |
| 258 | int frame_count = stack->frames()->size(); |
| 259 | if (frame_count == 0) { |
| 260 | printf(" <no frames>\n"); |
| 261 | } |
| 262 | for (int frame_index = 0; frame_index < frame_count; ++frame_index) { |
| 263 | const StackFrame *frame = stack->frames()->at(frame_index); |
| 264 | printf("%2d ", frame_index); |
| 265 | |
| 266 | uint64_t instruction_address = frame->ReturnAddress(); |
| 267 | |
| 268 | if (frame->module) { |
| 269 | printf("%s", PathnameStripper::File(frame->module->code_file()).c_str()); |
| 270 | if (!frame->function_name.empty()) { |
| 271 | printf("!%s", frame->function_name.c_str()); |
| 272 | if (!frame->source_file_name.empty()) { |
| 273 | string source_file = PathnameStripper::File(frame->source_file_name); |
| 274 | printf(" [%s : %d + 0x%" PRIx64"l" "x" "]", |
| 275 | source_file.c_str(), |
| 276 | frame->source_line, |
| 277 | instruction_address - frame->source_line_base); |
| 278 | } else { |
| 279 | printf(" + 0x%" PRIx64"l" "x", instruction_address - frame->function_base); |
| 280 | } |
| 281 | } else { |
| 282 | printf(" + 0x%" PRIx64"l" "x", |
| 283 | instruction_address - frame->module->base_address()); |
| 284 | } |
| 285 | } else { |
| 286 | printf("0x%" PRIx64"l" "x", instruction_address); |
| 287 | } |
| 288 | printf("\n "); |
| 289 | |
| 290 | int sequence = 0; |
| 291 | if (cpu == "x86") { |
| 292 | const StackFrameX86 *frame_x86 = |
| 293 | reinterpret_cast<const StackFrameX86*>(frame); |
| 294 | |
| 295 | if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_EIP) |
| 296 | sequence = PrintRegister("eip", frame_x86->context.eip, sequence); |
| 297 | if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_ESP) |
| 298 | sequence = PrintRegister("esp", frame_x86->context.esp, sequence); |
| 299 | if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_EBP) |
| 300 | sequence = PrintRegister("ebp", frame_x86->context.ebp, sequence); |
| 301 | if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_EBX) |
| 302 | sequence = PrintRegister("ebx", frame_x86->context.ebx, sequence); |
| 303 | if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_ESI) |
| 304 | sequence = PrintRegister("esi", frame_x86->context.esi, sequence); |
| 305 | if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_EDI) |
| 306 | sequence = PrintRegister("edi", frame_x86->context.edi, sequence); |
| 307 | if (frame_x86->context_validity == StackFrameX86::CONTEXT_VALID_ALL) { |
| 308 | sequence = PrintRegister("eax", frame_x86->context.eax, sequence); |
| 309 | sequence = PrintRegister("ecx", frame_x86->context.ecx, sequence); |
| 310 | sequence = PrintRegister("edx", frame_x86->context.edx, sequence); |
| 311 | sequence = PrintRegister("efl", frame_x86->context.eflags, sequence); |
Value stored to 'sequence' is never read | |
| 312 | } |
| 313 | } else if (cpu == "ppc") { |
| 314 | const StackFramePPC *frame_ppc = |
| 315 | reinterpret_cast<const StackFramePPC*>(frame); |
| 316 | |
| 317 | if (frame_ppc->context_validity & StackFramePPC::CONTEXT_VALID_SRR0) |
| 318 | sequence = PrintRegister("srr0", frame_ppc->context.srr0, sequence); |
| 319 | if (frame_ppc->context_validity & StackFramePPC::CONTEXT_VALID_GPR1) |
| 320 | sequence = PrintRegister("r1", frame_ppc->context.gpr[1], sequence); |
| 321 | } else if (cpu == "amd64") { |
| 322 | const StackFrameAMD64 *frame_amd64 = |
| 323 | reinterpret_cast<const StackFrameAMD64*>(frame); |
| 324 | |
| 325 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RAX) |
| 326 | sequence = PrintRegister64("rax", frame_amd64->context.rax, sequence); |
| 327 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RDX) |
| 328 | sequence = PrintRegister64("rdx", frame_amd64->context.rdx, sequence); |
| 329 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RCX) |
| 330 | sequence = PrintRegister64("rcx", frame_amd64->context.rcx, sequence); |
| 331 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RBX) |
| 332 | sequence = PrintRegister64("rbx", frame_amd64->context.rbx, sequence); |
| 333 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RSI) |
| 334 | sequence = PrintRegister64("rsi", frame_amd64->context.rsi, sequence); |
| 335 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RDI) |
| 336 | sequence = PrintRegister64("rdi", frame_amd64->context.rdi, sequence); |
| 337 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RBP) |
| 338 | sequence = PrintRegister64("rbp", frame_amd64->context.rbp, sequence); |
| 339 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RSP) |
| 340 | sequence = PrintRegister64("rsp", frame_amd64->context.rsp, sequence); |
| 341 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R8) |
| 342 | sequence = PrintRegister64("r8", frame_amd64->context.r8, sequence); |
| 343 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R9) |
| 344 | sequence = PrintRegister64("r9", frame_amd64->context.r9, sequence); |
| 345 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R10) |
| 346 | sequence = PrintRegister64("r10", frame_amd64->context.r10, sequence); |
| 347 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R11) |
| 348 | sequence = PrintRegister64("r11", frame_amd64->context.r11, sequence); |
| 349 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R12) |
| 350 | sequence = PrintRegister64("r12", frame_amd64->context.r12, sequence); |
| 351 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R13) |
| 352 | sequence = PrintRegister64("r13", frame_amd64->context.r13, sequence); |
| 353 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R14) |
| 354 | sequence = PrintRegister64("r14", frame_amd64->context.r14, sequence); |
| 355 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R15) |
| 356 | sequence = PrintRegister64("r15", frame_amd64->context.r15, sequence); |
| 357 | if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RIP) |
| 358 | sequence = PrintRegister64("rip", frame_amd64->context.rip, sequence); |
| 359 | } else if (cpu == "sparc") { |
| 360 | const StackFrameSPARC *frame_sparc = |
| 361 | reinterpret_cast<const StackFrameSPARC*>(frame); |
| 362 | |
| 363 | if (frame_sparc->context_validity & StackFrameSPARC::CONTEXT_VALID_SP) |
| 364 | sequence = PrintRegister("sp", frame_sparc->context.g_r[14], sequence); |
| 365 | if (frame_sparc->context_validity & StackFrameSPARC::CONTEXT_VALID_FP) |
| 366 | sequence = PrintRegister("fp", frame_sparc->context.g_r[30], sequence); |
| 367 | if (frame_sparc->context_validity & StackFrameSPARC::CONTEXT_VALID_PC) |
| 368 | sequence = PrintRegister("pc", frame_sparc->context.pc, sequence); |
| 369 | } else if (cpu == "arm") { |
| 370 | const StackFrameARM *frame_arm = |
| 371 | reinterpret_cast<const StackFrameARM*>(frame); |
| 372 | |
| 373 | // Argument registers (caller-saves), which will likely only be valid |
| 374 | // for the youngest frame. |
| 375 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R0) |
| 376 | sequence = PrintRegister("r0", frame_arm->context.iregs[0], sequence); |
| 377 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R1) |
| 378 | sequence = PrintRegister("r1", frame_arm->context.iregs[1], sequence); |
| 379 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R2) |
| 380 | sequence = PrintRegister("r2", frame_arm->context.iregs[2], sequence); |
| 381 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R3) |
| 382 | sequence = PrintRegister("r3", frame_arm->context.iregs[3], sequence); |
| 383 | |
| 384 | // General-purpose callee-saves registers. |
| 385 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R4) |
| 386 | sequence = PrintRegister("r4", frame_arm->context.iregs[4], sequence); |
| 387 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R5) |
| 388 | sequence = PrintRegister("r5", frame_arm->context.iregs[5], sequence); |
| 389 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R6) |
| 390 | sequence = PrintRegister("r6", frame_arm->context.iregs[6], sequence); |
| 391 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R7) |
| 392 | sequence = PrintRegister("r7", frame_arm->context.iregs[7], sequence); |
| 393 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R8) |
| 394 | sequence = PrintRegister("r8", frame_arm->context.iregs[8], sequence); |
| 395 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R9) |
| 396 | sequence = PrintRegister("r9", frame_arm->context.iregs[9], sequence); |
| 397 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R10) |
| 398 | sequence = PrintRegister("r10", frame_arm->context.iregs[10], sequence); |
| 399 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R12) |
| 400 | sequence = PrintRegister("r12", frame_arm->context.iregs[12], sequence); |
| 401 | |
| 402 | // Registers with a dedicated or conventional purpose. |
| 403 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_FP) |
| 404 | sequence = PrintRegister("fp", frame_arm->context.iregs[11], sequence); |
| 405 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_SP) |
| 406 | sequence = PrintRegister("sp", frame_arm->context.iregs[13], sequence); |
| 407 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_LR) |
| 408 | sequence = PrintRegister("lr", frame_arm->context.iregs[14], sequence); |
| 409 | if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_PC) |
| 410 | sequence = PrintRegister("pc", frame_arm->context.iregs[15], sequence); |
| 411 | } else if (cpu == "arm64") { |
| 412 | const StackFrameARM64 *frame_arm64 = |
| 413 | reinterpret_cast<const StackFrameARM64*>(frame); |
| 414 | |
| 415 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X0) { |
| 416 | sequence = |
| 417 | PrintRegister64("x0", frame_arm64->context.iregs[0], sequence); |
| 418 | } |
| 419 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X1) { |
| 420 | sequence = |
| 421 | PrintRegister64("x1", frame_arm64->context.iregs[1], sequence); |
| 422 | } |
| 423 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X2) { |
| 424 | sequence = |
| 425 | PrintRegister64("x2", frame_arm64->context.iregs[2], sequence); |
| 426 | } |
| 427 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X3) { |
| 428 | sequence = |
| 429 | PrintRegister64("x3", frame_arm64->context.iregs[3], sequence); |
| 430 | } |
| 431 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X4) { |
| 432 | sequence = |
| 433 | PrintRegister64("x4", frame_arm64->context.iregs[4], sequence); |
| 434 | } |
| 435 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X5) { |
| 436 | sequence = |
| 437 | PrintRegister64("x5", frame_arm64->context.iregs[5], sequence); |
| 438 | } |
| 439 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X6) { |
| 440 | sequence = |
| 441 | PrintRegister64("x6", frame_arm64->context.iregs[6], sequence); |
| 442 | } |
| 443 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X7) { |
| 444 | sequence = |
| 445 | PrintRegister64("x7", frame_arm64->context.iregs[7], sequence); |
| 446 | } |
| 447 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X8) { |
| 448 | sequence = |
| 449 | PrintRegister64("x8", frame_arm64->context.iregs[8], sequence); |
| 450 | } |
| 451 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X9) { |
| 452 | sequence = |
| 453 | PrintRegister64("x9", frame_arm64->context.iregs[9], sequence); |
| 454 | } |
| 455 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X10) { |
| 456 | sequence = |
| 457 | PrintRegister64("x10", frame_arm64->context.iregs[10], sequence); |
| 458 | } |
| 459 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X11) { |
| 460 | sequence = |
| 461 | PrintRegister64("x11", frame_arm64->context.iregs[11], sequence); |
| 462 | } |
| 463 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X12) { |
| 464 | sequence = |
| 465 | PrintRegister64("x12", frame_arm64->context.iregs[12], sequence); |
| 466 | } |
| 467 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X13) { |
| 468 | sequence = |
| 469 | PrintRegister64("x13", frame_arm64->context.iregs[13], sequence); |
| 470 | } |
| 471 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X14) { |
| 472 | sequence = |
| 473 | PrintRegister64("x14", frame_arm64->context.iregs[14], sequence); |
| 474 | } |
| 475 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X15) { |
| 476 | sequence = |
| 477 | PrintRegister64("x15", frame_arm64->context.iregs[15], sequence); |
| 478 | } |
| 479 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X16) { |
| 480 | sequence = |
| 481 | PrintRegister64("x16", frame_arm64->context.iregs[16], sequence); |
| 482 | } |
| 483 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X17) { |
| 484 | sequence = |
| 485 | PrintRegister64("x17", frame_arm64->context.iregs[17], sequence); |
| 486 | } |
| 487 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X18) { |
| 488 | sequence = |
| 489 | PrintRegister64("x18", frame_arm64->context.iregs[18], sequence); |
| 490 | } |
| 491 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X19) { |
| 492 | sequence = |
| 493 | PrintRegister64("x19", frame_arm64->context.iregs[19], sequence); |
| 494 | } |
| 495 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X20) { |
| 496 | sequence = |
| 497 | PrintRegister64("x20", frame_arm64->context.iregs[20], sequence); |
| 498 | } |
| 499 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X21) { |
| 500 | sequence = |
| 501 | PrintRegister64("x21", frame_arm64->context.iregs[21], sequence); |
| 502 | } |
| 503 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X22) { |
| 504 | sequence = |
| 505 | PrintRegister64("x22", frame_arm64->context.iregs[22], sequence); |
| 506 | } |
| 507 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X23) { |
| 508 | sequence = |
| 509 | PrintRegister64("x23", frame_arm64->context.iregs[23], sequence); |
| 510 | } |
| 511 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X24) { |
| 512 | sequence = |
| 513 | PrintRegister64("x24", frame_arm64->context.iregs[24], sequence); |
| 514 | } |
| 515 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X25) { |
| 516 | sequence = |
| 517 | PrintRegister64("x25", frame_arm64->context.iregs[25], sequence); |
| 518 | } |
| 519 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X26) { |
| 520 | sequence = |
| 521 | PrintRegister64("x26", frame_arm64->context.iregs[26], sequence); |
| 522 | } |
| 523 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X27) { |
| 524 | sequence = |
| 525 | PrintRegister64("x27", frame_arm64->context.iregs[27], sequence); |
| 526 | } |
| 527 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X28) { |
| 528 | sequence = |
| 529 | PrintRegister64("x28", frame_arm64->context.iregs[28], sequence); |
| 530 | } |
| 531 | |
| 532 | // Registers with a dedicated or conventional purpose. |
| 533 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_FP) { |
| 534 | sequence = |
| 535 | PrintRegister64("fp", frame_arm64->context.iregs[29], sequence); |
| 536 | } |
| 537 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_LR) { |
| 538 | sequence = |
| 539 | PrintRegister64("lr", frame_arm64->context.iregs[30], sequence); |
| 540 | } |
| 541 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_SP) { |
| 542 | sequence = |
| 543 | PrintRegister64("sp", frame_arm64->context.iregs[31], sequence); |
| 544 | } |
| 545 | if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_PC) { |
| 546 | sequence = |
| 547 | PrintRegister64("pc", frame_arm64->context.iregs[32], sequence); |
| 548 | } |
| 549 | } else if ((cpu == "mips") || (cpu == "mips64")) { |
| 550 | const StackFrameMIPS* frame_mips = |
| 551 | reinterpret_cast<const StackFrameMIPS*>(frame); |
| 552 | |
| 553 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_GP) |
| 554 | sequence = PrintRegister64("gp", |
| 555 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_GP], |
| 556 | sequence); |
| 557 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_SP) |
| 558 | sequence = PrintRegister64("sp", |
| 559 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_SP], |
| 560 | sequence); |
| 561 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_FP) |
| 562 | sequence = PrintRegister64("fp", |
| 563 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_FP], |
| 564 | sequence); |
| 565 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_RA) |
| 566 | sequence = PrintRegister64("ra", |
| 567 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_RA], |
| 568 | sequence); |
| 569 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_PC) |
| 570 | sequence = PrintRegister64("pc", frame_mips->context.epc, sequence); |
| 571 | |
| 572 | // Save registers s0-s7 |
| 573 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S0) |
| 574 | sequence = PrintRegister64("s0", |
| 575 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S0], |
| 576 | sequence); |
| 577 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S1) |
| 578 | sequence = PrintRegister64("s1", |
| 579 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S1], |
| 580 | sequence); |
| 581 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S2) |
| 582 | sequence = PrintRegister64("s2", |
| 583 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S2], |
| 584 | sequence); |
| 585 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S3) |
| 586 | sequence = PrintRegister64("s3", |
| 587 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S3], |
| 588 | sequence); |
| 589 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S4) |
| 590 | sequence = PrintRegister64("s4", |
| 591 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S4], |
| 592 | sequence); |
| 593 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S5) |
| 594 | sequence = PrintRegister64("s5", |
| 595 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S5], |
| 596 | sequence); |
| 597 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S6) |
| 598 | sequence = PrintRegister64("s6", |
| 599 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S6], |
| 600 | sequence); |
| 601 | if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S7) |
| 602 | sequence = PrintRegister64("s7", |
| 603 | frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S7], |
| 604 | sequence); |
| 605 | } |
| 606 | printf("\n Found by: %s\n", frame->trust_description().c_str()); |
| 607 | |
| 608 | // Print stack contents. |
| 609 | if (output_stack_contents && frame_index + 1 < frame_count) { |
| 610 | const string indent(" "); |
| 611 | PrintStackContents(indent, frame, stack->frames()->at(frame_index + 1), |
| 612 | cpu, memory, modules, resolver); |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | // PrintStackMachineReadable prints the call stack in |stack| to stdout, |
| 618 | // in the following machine readable pipe-delimited text format: |
| 619 | // thread number|frame number|module|function|source file|line|offset |
| 620 | // |
| 621 | // Module, function, source file, and source line may all be empty |
| 622 | // depending on availability. The code offset follows the same rules as |
| 623 | // PrintStack above. |
| 624 | static void PrintStackMachineReadable(int thread_num, const CallStack *stack) { |
| 625 | int frame_count = stack->frames()->size(); |
| 626 | for (int frame_index = 0; frame_index < frame_count; ++frame_index) { |
| 627 | const StackFrame *frame = stack->frames()->at(frame_index); |
| 628 | printf("%d%c%d%c", thread_num, kOutputSeparator, frame_index, |
| 629 | kOutputSeparator); |
| 630 | |
| 631 | uint64_t instruction_address = frame->ReturnAddress(); |
| 632 | |
| 633 | if (frame->module) { |
| 634 | assert(!frame->module->code_file().empty())(static_cast <bool> (!frame->module->code_file(). empty()) ? void (0) : __assert_fail ("!frame->module->code_file().empty()" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); |
| 635 | printf("%s", StripSeparator(PathnameStripper::File( |
| 636 | frame->module->code_file())).c_str()); |
| 637 | if (!frame->function_name.empty()) { |
| 638 | printf("%c%s", kOutputSeparator, |
| 639 | StripSeparator(frame->function_name).c_str()); |
| 640 | if (!frame->source_file_name.empty()) { |
| 641 | printf("%c%s%c%d%c0x%" PRIx64"l" "x", |
| 642 | kOutputSeparator, |
| 643 | StripSeparator(frame->source_file_name).c_str(), |
| 644 | kOutputSeparator, |
| 645 | frame->source_line, |
| 646 | kOutputSeparator, |
| 647 | instruction_address - frame->source_line_base); |
| 648 | } else { |
| 649 | printf("%c%c%c0x%" PRIx64"l" "x", |
| 650 | kOutputSeparator, // empty source file |
| 651 | kOutputSeparator, // empty source line |
| 652 | kOutputSeparator, |
| 653 | instruction_address - frame->function_base); |
| 654 | } |
| 655 | } else { |
| 656 | printf("%c%c%c%c0x%" PRIx64"l" "x", |
| 657 | kOutputSeparator, // empty function name |
| 658 | kOutputSeparator, // empty source file |
| 659 | kOutputSeparator, // empty source line |
| 660 | kOutputSeparator, |
| 661 | instruction_address - frame->module->base_address()); |
| 662 | } |
| 663 | } else { |
| 664 | // the printf before this prints a trailing separator for module name |
| 665 | printf("%c%c%c%c0x%" PRIx64"l" "x", |
| 666 | kOutputSeparator, // empty function name |
| 667 | kOutputSeparator, // empty source file |
| 668 | kOutputSeparator, // empty source line |
| 669 | kOutputSeparator, |
| 670 | instruction_address); |
| 671 | } |
| 672 | printf("\n"); |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | // ContainsModule checks whether a given |module| is in the vector |
| 677 | // |modules_without_symbols|. |
| 678 | static bool ContainsModule( |
| 679 | const vector<const CodeModule*> *modules, |
| 680 | const CodeModule *module) { |
| 681 | assert(modules)(static_cast <bool> (modules) ? void (0) : __assert_fail ("modules", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); |
| 682 | assert(module)(static_cast <bool> (module) ? void (0) : __assert_fail ("module", __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__)); |
| 683 | vector<const CodeModule*>::const_iterator iter; |
| 684 | for (iter = modules->begin(); iter != modules->end(); ++iter) { |
| 685 | if (module->debug_file().compare((*iter)->debug_file()) == 0 && |
| 686 | module->debug_identifier().compare((*iter)->debug_identifier()) == 0) { |
| 687 | return true; |
| 688 | } |
| 689 | } |
| 690 | return false; |
| 691 | } |
| 692 | |
| 693 | // PrintModule prints a single |module| to stdout. |
| 694 | // |modules_without_symbols| should contain the list of modules that were |
| 695 | // confirmed to be missing their symbols during the stack walk. |
| 696 | static void PrintModule( |
| 697 | const CodeModule *module, |
| 698 | const vector<const CodeModule*> *modules_without_symbols, |
| 699 | const vector<const CodeModule*> *modules_with_corrupt_symbols, |
| 700 | uint64_t main_address) { |
| 701 | string symbol_issues; |
| 702 | if (ContainsModule(modules_without_symbols, module)) { |
| 703 | symbol_issues = " (WARNING: No symbols, " + |
| 704 | PathnameStripper::File(module->debug_file()) + ", " + |
| 705 | module->debug_identifier() + ")"; |
| 706 | } else if (ContainsModule(modules_with_corrupt_symbols, module)) { |
| 707 | symbol_issues = " (WARNING: Corrupt symbols, " + |
| 708 | PathnameStripper::File(module->debug_file()) + ", " + |
| 709 | module->debug_identifier() + ")"; |
| 710 | } |
| 711 | uint64_t base_address = module->base_address(); |
| 712 | printf("0x%08" PRIx64"l" "x" " - 0x%08" PRIx64"l" "x" " %s %s%s%s\n", |
| 713 | base_address, base_address + module->size() - 1, |
| 714 | PathnameStripper::File(module->code_file()).c_str(), |
| 715 | module->version().empty() ? "???" : module->version().c_str(), |
| 716 | main_address != 0 && base_address == main_address ? " (main)" : "", |
| 717 | symbol_issues.c_str()); |
| 718 | } |
| 719 | |
| 720 | // PrintModules prints the list of all loaded |modules| to stdout. |
| 721 | // |modules_without_symbols| should contain the list of modules that were |
| 722 | // confirmed to be missing their symbols during the stack walk. |
| 723 | static void PrintModules( |
| 724 | const CodeModules *modules, |
| 725 | const vector<const CodeModule*> *modules_without_symbols, |
| 726 | const vector<const CodeModule*> *modules_with_corrupt_symbols) { |
| 727 | if (!modules) |
| 728 | return; |
| 729 | |
| 730 | printf("\n"); |
| 731 | printf("Loaded modules:\n"); |
| 732 | |
| 733 | uint64_t main_address = 0; |
| 734 | const CodeModule *main_module = modules->GetMainModule(); |
| 735 | if (main_module) { |
| 736 | main_address = main_module->base_address(); |
| 737 | } |
| 738 | |
| 739 | unsigned int module_count = modules->module_count(); |
| 740 | for (unsigned int module_sequence = 0; |
| 741 | module_sequence < module_count; |
| 742 | ++module_sequence) { |
| 743 | const CodeModule *module = modules->GetModuleAtSequence(module_sequence); |
| 744 | PrintModule(module, modules_without_symbols, modules_with_corrupt_symbols, |
| 745 | main_address); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | // PrintModulesMachineReadable outputs a list of loaded modules, |
| 750 | // one per line, in the following machine-readable pipe-delimited |
| 751 | // text format: |
| 752 | // Module|{Module Filename}|{Version}|{Debug Filename}|{Debug Identifier}| |
| 753 | // {Base Address}|{Max Address}|{Main} |
| 754 | static void PrintModulesMachineReadable(const CodeModules *modules) { |
| 755 | if (!modules) |
| 756 | return; |
| 757 | |
| 758 | uint64_t main_address = 0; |
| 759 | const CodeModule *main_module = modules->GetMainModule(); |
| 760 | if (main_module) { |
| 761 | main_address = main_module->base_address(); |
| 762 | } |
| 763 | |
| 764 | unsigned int module_count = modules->module_count(); |
| 765 | for (unsigned int module_sequence = 0; |
| 766 | module_sequence < module_count; |
| 767 | ++module_sequence) { |
| 768 | const CodeModule *module = modules->GetModuleAtSequence(module_sequence); |
| 769 | uint64_t base_address = module->base_address(); |
| 770 | printf("Module%c%s%c%s%c%s%c%s%c0x%08" PRIx64"l" "x" "%c0x%08" PRIx64"l" "x" "%c%d\n", |
| 771 | kOutputSeparator, |
| 772 | StripSeparator(PathnameStripper::File(module->code_file())).c_str(), |
| 773 | kOutputSeparator, StripSeparator(module->version()).c_str(), |
| 774 | kOutputSeparator, |
| 775 | StripSeparator(PathnameStripper::File(module->debug_file())).c_str(), |
| 776 | kOutputSeparator, |
| 777 | StripSeparator(module->debug_identifier()).c_str(), |
| 778 | kOutputSeparator, base_address, |
| 779 | kOutputSeparator, base_address + module->size() - 1, |
| 780 | kOutputSeparator, |
| 781 | main_module != NULL__null && base_address == main_address ? 1 : 0); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | // PrintUnloadedModulesMachineReadable outputs a list of loaded modules, |
| 786 | // one per line, in the following machine-readable pipe-delimited |
| 787 | // text format: |
| 788 | // UnloadedModule|{Module Filename}|{Base Address}|{Max Address}|{Main} |
| 789 | static void PrintUnloadedModulesMachineReadable(const CodeModules* modules) { |
| 790 | if (!modules) |
| 791 | return; |
| 792 | |
| 793 | uint64_t main_address = 0; |
| 794 | const CodeModule* main_module = modules->GetMainModule(); |
| 795 | if (main_module) { |
| 796 | main_address = main_module->base_address(); |
| 797 | } |
| 798 | |
| 799 | unsigned int module_count = modules->module_count(); |
| 800 | for (unsigned int module_sequence = 0; |
| 801 | module_sequence < module_count; |
| 802 | ++module_sequence) { |
| 803 | const CodeModule* module = modules->GetModuleAtSequence(module_sequence); |
| 804 | uint64_t base_address = module->base_address(); |
| 805 | printf("UnloadedModule%c%s%c0x%08" PRIx64"l" "x" "%c0x%08" PRIx64"l" "x" "%c%d\n", |
| 806 | kOutputSeparator, |
| 807 | StripSeparator(PathnameStripper::File(module->code_file())).c_str(), |
| 808 | kOutputSeparator, base_address, |
| 809 | kOutputSeparator, base_address + module->size() - 1, |
| 810 | kOutputSeparator, |
| 811 | main_module != NULL__null && base_address == main_address ? 1 : 0); |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | } // namespace |
| 816 | |
| 817 | void PrintProcessState(const ProcessState& process_state, |
| 818 | bool output_stack_contents, |
| 819 | SourceLineResolverInterface* resolver) { |
| 820 | // Print OS and CPU information. |
| 821 | string cpu = process_state.system_info()->cpu; |
| 822 | string cpu_info = process_state.system_info()->cpu_info; |
| 823 | printf("Operating system: %s\n", process_state.system_info()->os.c_str()); |
| 824 | printf(" %s\n", |
| 825 | process_state.system_info()->os_version.c_str()); |
| 826 | printf("CPU: %s\n", cpu.c_str()); |
| 827 | if (!cpu_info.empty()) { |
| 828 | // This field is optional. |
| 829 | printf(" %s\n", cpu_info.c_str()); |
| 830 | } |
| 831 | printf(" %d CPU%s\n", |
| 832 | process_state.system_info()->cpu_count, |
| 833 | process_state.system_info()->cpu_count != 1 ? "s" : ""); |
| 834 | printf("\n"); |
| 835 | |
| 836 | // Print GPU information |
| 837 | string gl_version = process_state.system_info()->gl_version; |
| 838 | string gl_vendor = process_state.system_info()->gl_vendor; |
| 839 | string gl_renderer = process_state.system_info()->gl_renderer; |
| 840 | printf("GPU:"); |
| 841 | if (!gl_version.empty() || !gl_vendor.empty() || !gl_renderer.empty()) { |
| 842 | printf(" %s\n", gl_version.c_str()); |
| 843 | printf(" %s\n", gl_vendor.c_str()); |
| 844 | printf(" %s\n", gl_renderer.c_str()); |
| 845 | } else { |
| 846 | printf(" UNKNOWN\n"); |
| 847 | } |
| 848 | printf("\n"); |
| 849 | |
| 850 | // Print crash information. |
| 851 | if (process_state.crashed()) { |
| 852 | printf("Crash reason: %s\n", process_state.crash_reason().c_str()); |
| 853 | printf("Crash address: 0x%" PRIx64"l" "x" "\n", process_state.crash_address()); |
| 854 | } else { |
| 855 | printf("No crash\n"); |
| 856 | } |
| 857 | |
| 858 | string assertion = process_state.assertion(); |
| 859 | if (!assertion.empty()) { |
| 860 | printf("Assertion: %s\n", assertion.c_str()); |
| 861 | } |
| 862 | |
| 863 | // Compute process uptime if the process creation and crash times are |
| 864 | // available in the dump. |
| 865 | if (process_state.time_date_stamp() != 0 && |
| 866 | process_state.process_create_time() != 0 && |
| 867 | process_state.time_date_stamp() >= process_state.process_create_time()) { |
| 868 | printf("Process uptime: %d seconds\n", |
| 869 | process_state.time_date_stamp() - |
| 870 | process_state.process_create_time()); |
| 871 | } else { |
| 872 | printf("Process uptime: not available\n"); |
| 873 | } |
| 874 | |
| 875 | if (!process_state.mac_crash_info().empty()) { |
| 876 | printf("\n"); |
| 877 | printf("Application-specific information:\n"); |
| 878 | printf("%s", process_state.mac_crash_info().c_str()); |
| 879 | } |
| 880 | |
| 881 | // If the thread that requested the dump is known, print it first. |
| 882 | int requesting_thread = process_state.requesting_thread(); |
| 883 | if (requesting_thread != -1) { |
| 884 | const CallStack* requesting_thread_callstack = |
| 885 | process_state.threads()->at(requesting_thread); |
| 886 | printf("\n" |
| 887 | "Thread %d tid %u (%s)", |
| 888 | requesting_thread, |
| 889 | requesting_thread_callstack->tid(), |
| 890 | process_state.crashed() ? "crashed" : |
| 891 | "requested dump, did not crash"); |
| 892 | if (!requesting_thread_callstack->name().empty()) { |
| 893 | printf(" - %s", requesting_thread_callstack->name().c_str()); |
| 894 | } |
| 895 | PrintStack(requesting_thread_callstack, cpu, |
| 896 | output_stack_contents, |
| 897 | process_state.thread_memory_regions()->at(requesting_thread), |
| 898 | process_state.modules(), resolver); |
| 899 | } |
| 900 | |
| 901 | // Print all of the threads in the dump. |
| 902 | int thread_count = process_state.threads()->size(); |
| 903 | for (int thread_index = 0; thread_index < thread_count; ++thread_index) { |
| 904 | if (thread_index != requesting_thread) { |
| 905 | // Don't print the crash thread again, it was already printed. |
| 906 | const CallStack* callstack = process_state.threads()->at(thread_index); |
| 907 | printf("\n" |
| 908 | "Thread %d tid %u", thread_index, callstack->tid()); |
| 909 | if (!callstack->name().empty()) { |
| 910 | printf(" - %s", callstack->name().c_str()); |
| 911 | } |
| 912 | printf("\n"); |
| 913 | PrintStack(callstack, cpu, |
| 914 | output_stack_contents, |
| 915 | process_state.thread_memory_regions()->at(thread_index), |
| 916 | process_state.modules(), resolver); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | PrintModules(process_state.modules(), |
| 921 | process_state.modules_without_symbols(), |
| 922 | process_state.modules_with_corrupt_symbols()); |
| 923 | } |
| 924 | |
| 925 | void PrintProcessStateMachineReadable(const ProcessState& process_state) { |
| 926 | // Print OS and CPU information. |
| 927 | // OS|{OS Name}|{OS Version} |
| 928 | // CPU|{CPU Name}|{CPU Info}|{Number of CPUs} |
| 929 | // GPU|{GPU version}|{GPU vendor}|{GPU renderer} |
| 930 | printf("OS%c%s%c%s\n", kOutputSeparator, |
| 931 | StripSeparator(process_state.system_info()->os).c_str(), |
| 932 | kOutputSeparator, |
| 933 | StripSeparator(process_state.system_info()->os_version).c_str()); |
| 934 | printf("CPU%c%s%c%s%c%d\n", kOutputSeparator, |
| 935 | StripSeparator(process_state.system_info()->cpu).c_str(), |
| 936 | kOutputSeparator, |
| 937 | // this may be empty |
| 938 | StripSeparator(process_state.system_info()->cpu_info).c_str(), |
| 939 | kOutputSeparator, |
| 940 | process_state.system_info()->cpu_count); |
| 941 | printf("GPU%c%s%c%s%c%s\n", kOutputSeparator, |
| 942 | StripSeparator(process_state.system_info()->gl_version).c_str(), |
| 943 | kOutputSeparator, |
| 944 | StripSeparator(process_state.system_info()->gl_vendor).c_str(), |
| 945 | kOutputSeparator, |
| 946 | StripSeparator(process_state.system_info()->gl_renderer).c_str()); |
| 947 | |
| 948 | int requesting_thread = process_state.requesting_thread(); |
| 949 | |
| 950 | // Print crash information. |
| 951 | // Crash|{Crash Reason}|{Crash Address}|{Crashed Thread} |
| 952 | printf("Crash%c", kOutputSeparator); |
| 953 | if (process_state.crashed()) { |
| 954 | printf("%s%c0x%" PRIx64"l" "x" "%c", |
| 955 | StripSeparator(process_state.crash_reason()).c_str(), |
| 956 | kOutputSeparator, process_state.crash_address(), kOutputSeparator); |
| 957 | } else { |
| 958 | // print assertion info, if available, in place of crash reason, |
| 959 | // instead of the unhelpful "No crash" |
| 960 | string assertion = process_state.assertion(); |
| 961 | if (!assertion.empty()) { |
| 962 | printf("%s%c%c", StripSeparator(assertion).c_str(), |
| 963 | kOutputSeparator, kOutputSeparator); |
| 964 | } else { |
| 965 | printf("No crash%c%c", kOutputSeparator, kOutputSeparator); |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | if (requesting_thread != -1) { |
| 970 | printf("%d\n", requesting_thread); |
| 971 | } else { |
| 972 | printf("\n"); |
| 973 | } |
| 974 | |
| 975 | const crash_info_record_t* crash_info_records = |
| 976 | process_state.mac_crash_info_records(); |
| 977 | size_t num_records = |
| 978 | process_state.mac_crash_info_records_count(); |
| 979 | for (size_t i = 0; i < num_records; ++i) { |
| 980 | char thread_str[32]; |
| 981 | if (crash_info_records[i].thread) { |
| 982 | snprintf(thread_str, sizeof(thread_str), "0x%llx", |
| 983 | crash_info_records[i].thread); |
| 984 | } else { |
| 985 | strncpy(thread_str, "0", sizeof(thread_str)); |
| 986 | } |
| 987 | char dialog_mode_str[32]; |
| 988 | if (crash_info_records[i].dialog_mode) { |
| 989 | snprintf(dialog_mode_str, sizeof(dialog_mode_str), "0x%x", |
| 990 | crash_info_records[i].dialog_mode); |
| 991 | } else { |
| 992 | strncpy(dialog_mode_str, "0", sizeof(dialog_mode_str)); |
| 993 | } |
| 994 | char abort_cause_str[32]; |
| 995 | if (crash_info_records[i].abort_cause) { |
| 996 | snprintf(abort_cause_str, sizeof(abort_cause_str), "%lld", |
| 997 | crash_info_records[i].abort_cause); |
| 998 | } else { |
| 999 | strncpy(abort_cause_str, "0", sizeof(abort_cause_str)); |
| 1000 | } |
| 1001 | printf("MacCrashInfo%c%s%c%lu%c%s%c%s%c%s%c%s%c%s%c%s%c%s\n", |
| 1002 | kOutputSeparator, crash_info_records[i].module_path.c_str(), |
| 1003 | kOutputSeparator, crash_info_records[i].version, |
| 1004 | kOutputSeparator, crash_info_records[i].message.c_str(), |
| 1005 | kOutputSeparator, crash_info_records[i].signature_string.c_str(), |
| 1006 | kOutputSeparator, crash_info_records[i].backtrace.c_str(), |
| 1007 | kOutputSeparator, crash_info_records[i].message2.c_str(), |
| 1008 | kOutputSeparator, thread_str, |
| 1009 | kOutputSeparator, dialog_mode_str, |
| 1010 | kOutputSeparator, abort_cause_str); |
| 1011 | } |
| 1012 | |
| 1013 | PrintModulesMachineReadable(process_state.modules()); |
| 1014 | PrintUnloadedModulesMachineReadable(process_state.unloaded_modules()); |
| 1015 | |
| 1016 | // blank line to indicate start of threads |
| 1017 | printf("\n"); |
| 1018 | |
| 1019 | // If the thread that requested the dump is known, print it first. |
| 1020 | if (requesting_thread != -1) { |
| 1021 | PrintStackMachineReadable(requesting_thread, |
| 1022 | process_state.threads()->at(requesting_thread)); |
| 1023 | } |
| 1024 | |
| 1025 | // Print all of the threads in the dump. |
| 1026 | int thread_count = process_state.threads()->size(); |
| 1027 | for (int thread_index = 0; thread_index < thread_count; ++thread_index) { |
| 1028 | if (thread_index != requesting_thread) { |
| 1029 | // Don't print the crash thread again, it was already printed. |
| 1030 | PrintStackMachineReadable(thread_index, |
| 1031 | process_state.threads()->at(thread_index)); |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | } // namespace google_breakpad |