16c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// Copyright (c) 2010 Google Inc.
26c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// All rights reserved.
36c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org//
46c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// Redistribution and use in source and binary forms, with or without
56c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// modification, are permitted provided that the following conditions are
66c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// met:
76c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org//
86c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org//     * Redistributions of source code must retain the above copyright
96c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// notice, this list of conditions and the following disclaimer.
106c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org//     * Redistributions in binary form must reproduce the above
116c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// copyright notice, this list of conditions and the following disclaimer
126c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// in the documentation and/or other materials provided with the
136c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// distribution.
146c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org//     * Neither the name of Google Inc. nor the names of its
156c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// contributors may be used to endorse or promote products derived from
166c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// this software without specific prior written permission.
176c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org//
186c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
196c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
206c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
216c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
226c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
236c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
246c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
256c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
266c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
276c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
286c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
296c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
306c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// stackwalk_common.cc: Module shared by the {micro,mini}dump_stackwalck
316c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// executables to print the content of dumps (w/ stack traces) on the console.
326c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org//
336c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// Author: Mark Mentovai
346c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
356c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include "processor/stackwalk_common.h"
366c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
376c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include <assert.h>
386c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include <stdio.h>
396c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include <stdlib.h>
406c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include <string.h>
416c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
426c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include <string>
436c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include <vector>
446c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
456c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include "common/using_std_string.h"
466c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include "google_breakpad/processor/call_stack.h"
476c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include "google_breakpad/processor/code_module.h"
486c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include "google_breakpad/processor/code_modules.h"
496c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include "google_breakpad/processor/process_state.h"
5099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org#include "google_breakpad/processor/source_line_resolver_interface.h"
516c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include "google_breakpad/processor/stack_frame_cpu.h"
526c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include "processor/logging.h"
536c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org#include "processor/pathname_stripper.h"
546c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
556c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgnamespace google_breakpad {
566c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
576c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgnamespace {
586c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
596c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgusing std::vector;
606c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
616c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// Separator character for machine readable output.
626c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgstatic const char kOutputSeparator = '|';
636c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
646c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// PrintRegister prints a register's name and value to stdout.  It will
656c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// print four registers on a line.  For the first register in a set,
666c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// pass 0 for |start_col|.  For registers in a set, pass the most recent
676c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// return value of PrintRegister.
686c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// The caller is responsible for printing the final newline after a set
696c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// of registers is completely printed, regardless of the number of calls
706c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// to PrintRegister.
716c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgstatic const int kMaxWidth = 80;  // optimize for an 80-column terminal
726c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgstatic int PrintRegister(const char *name, uint32_t value, int start_col) {
736c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  char buffer[64];
746c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  snprintf(buffer, sizeof(buffer), " %5s = 0x%08x", name, value);
756c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
766c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (start_col + static_cast<ssize_t>(strlen(buffer)) > kMaxWidth) {
776c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    start_col = 0;
786c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("\n ");
796c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
806c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  fputs(buffer, stdout);
816c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
826c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  return start_col + strlen(buffer);
836c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}
846c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
856c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// PrintRegister64 does the same thing, but for 64-bit registers.
866c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgstatic int PrintRegister64(const char *name, uint64_t value, int start_col) {
876c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  char buffer[64];
886c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  snprintf(buffer, sizeof(buffer), " %5s = 0x%016" PRIx64 , name, value);
896c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
906c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (start_col + static_cast<ssize_t>(strlen(buffer)) > kMaxWidth) {
916c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    start_col = 0;
926c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("\n ");
936c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
946c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  fputs(buffer, stdout);
956c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
966c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  return start_col + strlen(buffer);
976c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}
986c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
996c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// StripSeparator takes a string |original| and returns a copy
1006c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// of the string with all occurences of |kOutputSeparator| removed.
1016c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgstatic string StripSeparator(const string &original) {
1026c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  string result = original;
1036c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  string::size_type position = 0;
1046c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  while ((position = result.find(kOutputSeparator, position)) != string::npos) {
1056c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    result.erase(position, 1);
1066c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
1076c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  position = 0;
1086c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  while ((position = result.find('\n', position)) != string::npos) {
1096c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    result.erase(position, 1);
1106c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
1116c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  return result;
1126c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}
1136c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
11499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org// PrintStackContents prints the stack contents of the current frame to stdout.
11599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.orgstatic void PrintStackContents(const std::string &indent,
11699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                               const StackFrame *frame,
11799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                               const StackFrame *prev_frame,
11899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                               const std::string &cpu,
11999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                               const MemoryRegion *memory,
12099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                               const CodeModules* modules,
12199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                               SourceLineResolverInterface *resolver) {
12299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  // Find stack range.
12399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  int word_length = 0;
12499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  uint64_t stack_begin = 0, stack_end = 0;
12599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  if (cpu == "x86") {
12699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    word_length = 4;
12799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    const StackFrameX86 *frame_x86 = static_cast<const StackFrameX86*>(frame);
12899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    const StackFrameX86 *prev_frame_x86 =
12999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        static_cast<const StackFrameX86*>(prev_frame);
13099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    if ((frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_ESP) &&
13199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        (prev_frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_ESP)) {
13299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      stack_begin = frame_x86->context.esp;
13399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      stack_end = prev_frame_x86->context.esp;
13499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    }
13599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  } else if (cpu == "amd64") {
13699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    word_length = 8;
13799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    const StackFrameAMD64 *frame_amd64 =
13899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        static_cast<const StackFrameAMD64*>(frame);
13999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    const StackFrameAMD64 *prev_frame_amd64 =
14099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        static_cast<const StackFrameAMD64*>(prev_frame);
14199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    if ((frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RSP) &&
14299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        (prev_frame_amd64->context_validity &
14399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org         StackFrameAMD64::CONTEXT_VALID_RSP)) {
14499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      stack_begin = frame_amd64->context.rsp;
14599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      stack_end = prev_frame_amd64->context.rsp;
14699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    }
14799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  } else if (cpu == "arm") {
14899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    word_length = 4;
14999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    const StackFrameARM *frame_arm = static_cast<const StackFrameARM*>(frame);
15099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    const StackFrameARM *prev_frame_arm =
15199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        static_cast<const StackFrameARM*>(prev_frame);
15299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    if ((frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_SP) &&
15399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        (prev_frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_SP)) {
15499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      stack_begin = frame_arm->context.iregs[13];
15599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      stack_end = prev_frame_arm->context.iregs[13];
15699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    }
15799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  } else if (cpu == "arm64") {
15899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    word_length = 8;
15999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    const StackFrameARM64 *frame_arm64 =
16099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        static_cast<const StackFrameARM64*>(frame);
16199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    const StackFrameARM64 *prev_frame_arm64 =
16299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        static_cast<const StackFrameARM64*>(prev_frame);
16399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    if ((frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_SP) &&
16499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        (prev_frame_arm64->context_validity &
16599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org         StackFrameARM64::CONTEXT_VALID_SP)) {
16699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      stack_begin = frame_arm64->context.iregs[31];
16799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      stack_end = prev_frame_arm64->context.iregs[31];
16899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    }
16999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  }
17099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  if (!word_length || !stack_begin || !stack_end)
17199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    return;
17299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org
17399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  // Print stack contents.
17499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  printf("\n%sStack contents:", indent.c_str());
17599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  for(uint64_t address = stack_begin; address < stack_end; ) {
17699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    // Print the start address of this row.
17799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    if (word_length == 4)
17899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      printf("\n%s %08x", indent.c_str(), static_cast<uint32_t>(address));
17999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    else
18099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      printf("\n%s %016" PRIx64, indent.c_str(), address);
18199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org
18299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    // Print data in hex.
18399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    const int kBytesPerRow = 16;
18499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    std::string data_as_string;
18599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    for (int i = 0; i < kBytesPerRow; ++i, ++address) {
18699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      uint8_t value = 0;
18799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      if (address < stack_end &&
18899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org          memory->GetMemoryAtAddress(address, &value)) {
18999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        printf(" %02x", value);
19099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        data_as_string.push_back(isprint(value) ? value : '.');
19199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      } else {
19299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        printf("   ");
19399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        data_as_string.push_back(' ');
19499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      }
19599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    }
19699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    // Print data as string.
19799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    printf("  %s", data_as_string.c_str());
19899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  }
19999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org
20099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  // Try to find instruction pointers from stack.
20188d2296fd91d7ae3ca50978a7a65098f0af45b93ted.mielczarek@gmail.com  printf("\n%sPossible instruction pointers:\n", indent.c_str());
20299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  for (uint64_t address = stack_begin; address < stack_end;
20399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org       address += word_length) {
20499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    StackFrame pointee_frame;
20599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org
20699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    // Read a word (possible instruction pointer) from stack.
20799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    if (word_length == 4) {
20899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      uint32_t data32 = 0;
20999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      memory->GetMemoryAtAddress(address, &data32);
21099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      pointee_frame.instruction = data32;
21199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    } else {
21299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      uint64_t data64 = 0;
21399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      memory->GetMemoryAtAddress(address, &data64);
21499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      pointee_frame.instruction = data64;
21599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    }
21699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    pointee_frame.module =
21799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org        modules->GetModuleForAddress(pointee_frame.instruction);
21899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org
21999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    // Try to look up the function name.
22099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    if (pointee_frame.module)
22199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      resolver->FillSourceLineInfo(&pointee_frame);
22299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org
22399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    // Print function name.
22499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    if (!pointee_frame.function_name.empty()) {
22599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      if (word_length == 4) {
22688d2296fd91d7ae3ca50978a7a65098f0af45b93ted.mielczarek@gmail.com        printf("%s *(0x%08x) = 0x%08x", indent.c_str(),
22799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org               static_cast<uint32_t>(address),
22899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org               static_cast<uint32_t>(pointee_frame.instruction));
22999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      } else {
23088d2296fd91d7ae3ca50978a7a65098f0af45b93ted.mielczarek@gmail.com        printf("%s *(0x%016" PRIx64 ") = 0x%016" PRIx64,
23199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org               indent.c_str(), address, pointee_frame.instruction);
23299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      }
23388d2296fd91d7ae3ca50978a7a65098f0af45b93ted.mielczarek@gmail.com      printf(" <%s> [%s : %d + 0x%" PRIx64 "]\n",
23499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org             pointee_frame.function_name.c_str(),
23599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org             PathnameStripper::File(pointee_frame.source_file_name).c_str(),
23699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org             pointee_frame.source_line,
23799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org             pointee_frame.instruction - pointee_frame.source_line_base);
23899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    }
23999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org  }
24088d2296fd91d7ae3ca50978a7a65098f0af45b93ted.mielczarek@gmail.com  printf("\n");
24199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org}
24299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org
2436c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// PrintStack prints the call stack in |stack| to stdout, in a reasonably
2446c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// useful form.  Module, function, and source file names are displayed if
2456c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// they are available.  The code offset to the base code address of the
2466c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// source line, function, or module is printed, preferring them in that
2476c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// order.  If no source line, function, or module information is available,
2486c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// an absolute code offset is printed.
2496c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org//
2506c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// If |cpu| is a recognized CPU name, relevant register state for each stack
2516c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// frame printed is also output, if available.
25299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.orgstatic void PrintStack(const CallStack *stack,
25399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                       const string &cpu,
25499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                       bool output_stack_contents,
25599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                       const MemoryRegion* memory,
25699936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                       const CodeModules* modules,
25799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                       SourceLineResolverInterface* resolver) {
2586c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  int frame_count = stack->frames()->size();
2596c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (frame_count == 0) {
2606c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf(" <no frames>\n");
2616c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
2626c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  for (int frame_index = 0; frame_index < frame_count; ++frame_index) {
2636c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const StackFrame *frame = stack->frames()->at(frame_index);
2646c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("%2d  ", frame_index);
2656c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
2666c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    uint64_t instruction_address = frame->ReturnAddress();
2676c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
2686c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    if (frame->module) {
2696c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      printf("%s", PathnameStripper::File(frame->module->code_file()).c_str());
2706c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (!frame->function_name.empty()) {
2716c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        printf("!%s", frame->function_name.c_str());
2726c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        if (!frame->source_file_name.empty()) {
2736c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org          string source_file = PathnameStripper::File(frame->source_file_name);
2746c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org          printf(" [%s : %d + 0x%" PRIx64 "]",
2756c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 source_file.c_str(),
2766c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 frame->source_line,
2776c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 instruction_address - frame->source_line_base);
2786c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        } else {
2796c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org          printf(" + 0x%" PRIx64, instruction_address - frame->function_base);
2806c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        }
2816c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      } else {
2826c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        printf(" + 0x%" PRIx64,
2836c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org               instruction_address - frame->module->base_address());
2846c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
2856c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    } else {
2866c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      printf("0x%" PRIx64, instruction_address);
2876c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    }
2886c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("\n ");
2896c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
2906c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    int sequence = 0;
2916c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    if (cpu == "x86") {
2926c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      const StackFrameX86 *frame_x86 =
2936c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        reinterpret_cast<const StackFrameX86*>(frame);
2946c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
2956c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_EIP)
2966c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("eip", frame_x86->context.eip, sequence);
2976c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_ESP)
2986c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("esp", frame_x86->context.esp, sequence);
2996c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_EBP)
3006c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("ebp", frame_x86->context.ebp, sequence);
3016c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_EBX)
3026c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("ebx", frame_x86->context.ebx, sequence);
3036c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_ESI)
3046c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("esi", frame_x86->context.esi, sequence);
3056c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_x86->context_validity & StackFrameX86::CONTEXT_VALID_EDI)
3066c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("edi", frame_x86->context.edi, sequence);
3076c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_x86->context_validity == StackFrameX86::CONTEXT_VALID_ALL) {
3086c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("eax", frame_x86->context.eax, sequence);
3096c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("ecx", frame_x86->context.ecx, sequence);
3106c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("edx", frame_x86->context.edx, sequence);
3116c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("efl", frame_x86->context.eflags, sequence);
3126c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
3136c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    } else if (cpu == "ppc") {
3146c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      const StackFramePPC *frame_ppc =
3156c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        reinterpret_cast<const StackFramePPC*>(frame);
3166c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
3176c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_ppc->context_validity & StackFramePPC::CONTEXT_VALID_SRR0)
3186c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("srr0", frame_ppc->context.srr0, sequence);
3196c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_ppc->context_validity & StackFramePPC::CONTEXT_VALID_GPR1)
3206c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r1", frame_ppc->context.gpr[1], sequence);
3216c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    } else if (cpu == "amd64") {
3226c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      const StackFrameAMD64 *frame_amd64 =
3236c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        reinterpret_cast<const StackFrameAMD64*>(frame);
3246c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
3256c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RAX)
3266c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("rax", frame_amd64->context.rax, sequence);
3276c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RDX)
3286c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("rdx", frame_amd64->context.rdx, sequence);
3296c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RCX)
3306c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("rcx", frame_amd64->context.rcx, sequence);
3316c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RBX)
3326c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("rbx", frame_amd64->context.rbx, sequence);
3336c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RSI)
3346c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("rsi", frame_amd64->context.rsi, sequence);
3356c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RDI)
3366c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("rdi", frame_amd64->context.rdi, sequence);
3376c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RBP)
3386c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("rbp", frame_amd64->context.rbp, sequence);
3396c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RSP)
3406c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("rsp", frame_amd64->context.rsp, sequence);
3416c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R8)
3426c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("r8", frame_amd64->context.r8, sequence);
3436c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R9)
3446c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("r9", frame_amd64->context.r9, sequence);
3456c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R10)
3466c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("r10", frame_amd64->context.r10, sequence);
3476c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R11)
3486c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("r11", frame_amd64->context.r11, sequence);
3496c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R12)
3506c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("r12", frame_amd64->context.r12, sequence);
3516c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R13)
3526c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("r13", frame_amd64->context.r13, sequence);
3536c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R14)
3546c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("r14", frame_amd64->context.r14, sequence);
3556c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_R15)
3566c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("r15", frame_amd64->context.r15, sequence);
3576c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_amd64->context_validity & StackFrameAMD64::CONTEXT_VALID_RIP)
3586c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("rip", frame_amd64->context.rip, sequence);
3596c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    } else if (cpu == "sparc") {
3606c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      const StackFrameSPARC *frame_sparc =
3616c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        reinterpret_cast<const StackFrameSPARC*>(frame);
3626c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
3636c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_sparc->context_validity & StackFrameSPARC::CONTEXT_VALID_SP)
3646c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("sp", frame_sparc->context.g_r[14], sequence);
3656c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_sparc->context_validity & StackFrameSPARC::CONTEXT_VALID_FP)
3666c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("fp", frame_sparc->context.g_r[30], sequence);
3676c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_sparc->context_validity & StackFrameSPARC::CONTEXT_VALID_PC)
3686c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("pc", frame_sparc->context.pc, sequence);
3696c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    } else if (cpu == "arm") {
3706c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      const StackFrameARM *frame_arm =
3716c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        reinterpret_cast<const StackFrameARM*>(frame);
3726c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
3736c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      // Argument registers (caller-saves), which will likely only be valid
3746c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      // for the youngest frame.
3756c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R0)
3766c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r0", frame_arm->context.iregs[0], sequence);
3776c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R1)
3786c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r1", frame_arm->context.iregs[1], sequence);
3796c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R2)
3806c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r2", frame_arm->context.iregs[2], sequence);
3816c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R3)
3826c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r3", frame_arm->context.iregs[3], sequence);
3836c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
3846c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      // General-purpose callee-saves registers.
3856c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R4)
3866c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r4", frame_arm->context.iregs[4], sequence);
3876c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R5)
3886c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r5", frame_arm->context.iregs[5], sequence);
3896c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R6)
3906c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r6", frame_arm->context.iregs[6], sequence);
3916c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R7)
3926c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r7", frame_arm->context.iregs[7], sequence);
3936c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R8)
3946c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r8", frame_arm->context.iregs[8], sequence);
3956c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R9)
3966c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r9", frame_arm->context.iregs[9], sequence);
3976c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R10)
3986c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r10", frame_arm->context.iregs[10], sequence);
3996c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_R12)
4006c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("r12", frame_arm->context.iregs[12], sequence);
4016c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
4026c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      // Registers with a dedicated or conventional purpose.
4036c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_FP)
4046c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("fp", frame_arm->context.iregs[11], sequence);
4056c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_SP)
4066c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("sp", frame_arm->context.iregs[13], sequence);
4076c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_LR)
4086c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("lr", frame_arm->context.iregs[14], sequence);
4096c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm->context_validity & StackFrameARM::CONTEXT_VALID_PC)
4106c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister("pc", frame_arm->context.iregs[15], sequence);
4116c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    } else if (cpu == "arm64") {
4126c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      const StackFrameARM64 *frame_arm64 =
4136c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        reinterpret_cast<const StackFrameARM64*>(frame);
4146c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
4156c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X0) {
4166c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4176c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x0", frame_arm64->context.iregs[0], sequence);
4186c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4196c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X1) {
4206c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4216c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x1", frame_arm64->context.iregs[1], sequence);
4226c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4236c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X2) {
4246c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4256c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x2", frame_arm64->context.iregs[2], sequence);
4266c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4276c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X3) {
4286c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4296c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x3", frame_arm64->context.iregs[3], sequence);
4306c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4316c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X4) {
4326c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4336c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x4", frame_arm64->context.iregs[4], sequence);
4346c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4356c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X5) {
4366c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4376c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x5", frame_arm64->context.iregs[5], sequence);
4386c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4396c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X6) {
4406c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4416c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x6", frame_arm64->context.iregs[6], sequence);
4426c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4436c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X7) {
4446c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4456c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x7", frame_arm64->context.iregs[7], sequence);
4466c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4476c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X8) {
4486c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4496c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x8", frame_arm64->context.iregs[8], sequence);
4506c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4516c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X9) {
4526c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4536c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x9", frame_arm64->context.iregs[9], sequence);
4546c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4556c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X10) {
4566c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4576c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x10", frame_arm64->context.iregs[10], sequence);
4586c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4596c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X11) {
4606c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4616c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x11", frame_arm64->context.iregs[11], sequence);
4626c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4636c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X12) {
4646c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4656c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x12", frame_arm64->context.iregs[12], sequence);
4666c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4676c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X13) {
4686c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4696c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x13", frame_arm64->context.iregs[13], sequence);
4706c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4716c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X14) {
4726c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4736c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x14", frame_arm64->context.iregs[14], sequence);
4746c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4756c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X15) {
4766c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4776c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x15", frame_arm64->context.iregs[15], sequence);
4786c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4796c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X16) {
4806c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4816c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x16", frame_arm64->context.iregs[16], sequence);
4826c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4836c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X17) {
4846c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4856c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x17", frame_arm64->context.iregs[17], sequence);
4866c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4876c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X18) {
4886c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4896c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x18", frame_arm64->context.iregs[18], sequence);
4906c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4916c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X19) {
4926c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4936c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x19", frame_arm64->context.iregs[19], sequence);
4946c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4956c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X20) {
4966c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
4976c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x20", frame_arm64->context.iregs[20], sequence);
4986c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
4996c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X21) {
5006c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5016c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x21", frame_arm64->context.iregs[21], sequence);
5026c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5036c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X22) {
5046c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5056c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x22", frame_arm64->context.iregs[22], sequence);
5066c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5076c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X23) {
5086c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5096c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x23", frame_arm64->context.iregs[23], sequence);
5106c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5116c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X24) {
5126c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5136c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x24", frame_arm64->context.iregs[24], sequence);
5146c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5156c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X25) {
5166c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5176c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x25", frame_arm64->context.iregs[25], sequence);
5186c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5196c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X26) {
5206c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5216c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x26", frame_arm64->context.iregs[26], sequence);
5226c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5236c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X27) {
5246c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5256c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x27", frame_arm64->context.iregs[27], sequence);
5266c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5276c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_X28) {
5286c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5296c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("x28", frame_arm64->context.iregs[28], sequence);
5306c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5316c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
5326c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      // Registers with a dedicated or conventional purpose.
5336c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_FP) {
5346c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5356c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("fp", frame_arm64->context.iregs[29], sequence);
5366c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5376c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_LR) {
5386c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5396c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("lr", frame_arm64->context.iregs[30], sequence);
5406c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5416c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_SP) {
5426c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5436c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("sp", frame_arm64->context.iregs[31], sequence);
5446c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5456c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_arm64->context_validity & StackFrameARM64::CONTEXT_VALID_PC) {
5466c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence =
5476c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org            PrintRegister64("pc", frame_arm64->context.iregs[32], sequence);
5486c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
5496c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    } else if (cpu == "mips") {
5506c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      const StackFrameMIPS* frame_mips =
5516c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        reinterpret_cast<const StackFrameMIPS*>(frame);
5526c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
5536c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_GP)
5546c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("gp",
5556c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_GP],
5566c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
5576c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_SP)
5586c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("sp",
5596c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_SP],
5606c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
5616c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_FP)
5626c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("fp",
5636c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_FP],
5646c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
5656c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_RA)
5666c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("ra",
5676c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_RA],
5686c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
5696c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_PC)
5706c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("pc", frame_mips->context.epc, sequence);
5716c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
5726c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      // Save registers s0-s7
5736c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S0)
5746c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("s0",
5756c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S0],
5766c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
5776c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S1)
5786c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("s1",
5796c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S1],
5806c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
5816c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S2)
5826c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("s2",
5836c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S2],
5846c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
5856c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S3)
5866c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("s3",
5876c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S3],
5886c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
5896c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S4)
5906c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("s4",
5916c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S4],
5926c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
5936c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S5)
5946c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("s5",
5956c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S5],
5966c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
5976c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S6)
5986c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("s6",
5996c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S6],
6006c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
6016c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (frame_mips->context_validity & StackFrameMIPS::CONTEXT_VALID_S7)
6026c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        sequence = PrintRegister64("s7",
6036c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame_mips->context.iregs[MD_CONTEXT_MIPS_REG_S7],
6046c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     sequence);
6056c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    }
6066c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("\n    Found by: %s\n", frame->trust_description().c_str());
60799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org
60899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    // Print stack contents.
60999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    if (output_stack_contents && frame_index + 1 < frame_count) {
61099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      const std::string indent("    ");
61199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      PrintStackContents(indent, frame, stack->frames()->at(frame_index + 1),
61299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                         cpu, memory, modules, resolver);
61399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    }
6146c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
6156c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}
6166c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
6176c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// PrintStackMachineReadable prints the call stack in |stack| to stdout,
6186c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// in the following machine readable pipe-delimited text format:
6196c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// thread number|frame number|module|function|source file|line|offset
6206c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org//
6216c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// Module, function, source file, and source line may all be empty
6226c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// depending on availability.  The code offset follows the same rules as
6236c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// PrintStack above.
6246c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgstatic void PrintStackMachineReadable(int thread_num, const CallStack *stack) {
6256c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  int frame_count = stack->frames()->size();
6266c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  for (int frame_index = 0; frame_index < frame_count; ++frame_index) {
6276c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const StackFrame *frame = stack->frames()->at(frame_index);
6286c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("%d%c%d%c", thread_num, kOutputSeparator, frame_index,
6296c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           kOutputSeparator);
6306c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
6316c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    uint64_t instruction_address = frame->ReturnAddress();
6326c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
6336c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    if (frame->module) {
6346c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      assert(!frame->module->code_file().empty());
6356c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      printf("%s", StripSeparator(PathnameStripper::File(
6366c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                     frame->module->code_file())).c_str());
6376c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      if (!frame->function_name.empty()) {
6386c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        printf("%c%s", kOutputSeparator,
6396c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org               StripSeparator(frame->function_name).c_str());
6406c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        if (!frame->source_file_name.empty()) {
6416c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org          printf("%c%s%c%d%c0x%" PRIx64,
6426c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 kOutputSeparator,
6436c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 StripSeparator(frame->source_file_name).c_str(),
6446c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 kOutputSeparator,
6456c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 frame->source_line,
6466c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 kOutputSeparator,
6476c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 instruction_address - frame->source_line_base);
6486c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        } else {
6496c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org          printf("%c%c%c0x%" PRIx64,
6506c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 kOutputSeparator,  // empty source file
6516c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 kOutputSeparator,  // empty source line
6526c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 kOutputSeparator,
6536c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                 instruction_address - frame->function_base);
6546c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        }
6556c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      } else {
6566c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        printf("%c%c%c%c0x%" PRIx64,
6576c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org               kOutputSeparator,  // empty function name
6586c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org               kOutputSeparator,  // empty source file
6596c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org               kOutputSeparator,  // empty source line
6606c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org               kOutputSeparator,
6616c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org               instruction_address - frame->module->base_address());
6626c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      }
6636c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    } else {
6646c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      // the printf before this prints a trailing separator for module name
6656c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      printf("%c%c%c%c0x%" PRIx64,
6666c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org             kOutputSeparator,  // empty function name
6676c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org             kOutputSeparator,  // empty source file
6686c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org             kOutputSeparator,  // empty source line
6696c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org             kOutputSeparator,
6706c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org             instruction_address);
6716c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    }
6726c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("\n");
6736c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
6746c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}
6756c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
6766c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// ContainsModule checks whether a given |module| is in the vector
6776c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// |modules_without_symbols|.
6786c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgstatic bool ContainsModule(
6796c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const vector<const CodeModule*> *modules,
6806c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const CodeModule *module) {
6816c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  assert(modules);
6826c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  assert(module);
6836c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  vector<const CodeModule*>::const_iterator iter;
6846c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  for (iter = modules->begin(); iter != modules->end(); ++iter) {
6856c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    if (module->debug_file().compare((*iter)->debug_file()) == 0 &&
6866c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        module->debug_identifier().compare((*iter)->debug_identifier()) == 0) {
6876c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      return true;
6886c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    }
6896c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
6906c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  return false;
6916c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}
6926c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
6936c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// PrintModule prints a single |module| to stdout.
6946c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// |modules_without_symbols| should contain the list of modules that were
6956c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// confirmed to be missing their symbols during the stack walk.
6966c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgstatic void PrintModule(
6976c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const CodeModule *module,
6986c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const vector<const CodeModule*> *modules_without_symbols,
6996c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const vector<const CodeModule*> *modules_with_corrupt_symbols,
7006c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    uint64_t main_address) {
7016c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  string symbol_issues;
7026c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (ContainsModule(modules_without_symbols, module)) {
7036c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    symbol_issues = "  (WARNING: No symbols, " +
7046c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        PathnameStripper::File(module->debug_file()) + ", " +
7056c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        module->debug_identifier() + ")";
7066c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  } else if (ContainsModule(modules_with_corrupt_symbols, module)) {
7076c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    symbol_issues = "  (WARNING: Corrupt symbols, " +
7086c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        PathnameStripper::File(module->debug_file()) + ", " +
7096c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org        module->debug_identifier() + ")";
7106c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
7116c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  uint64_t base_address = module->base_address();
7126c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("0x%08" PRIx64 " - 0x%08" PRIx64 "  %s  %s%s%s\n",
7136c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         base_address, base_address + module->size() - 1,
7146c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         PathnameStripper::File(module->code_file()).c_str(),
7156c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         module->version().empty() ? "???" : module->version().c_str(),
7166c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         main_address != 0 && base_address == main_address ? "  (main)" : "",
7176c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         symbol_issues.c_str());
7186c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}
7196c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
7206c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// PrintModules prints the list of all loaded |modules| to stdout.
7216c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// |modules_without_symbols| should contain the list of modules that were
7226c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// confirmed to be missing their symbols during the stack walk.
7236c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgstatic void PrintModules(
7246c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const CodeModules *modules,
7256c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const vector<const CodeModule*> *modules_without_symbols,
7266c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const vector<const CodeModule*> *modules_with_corrupt_symbols) {
7276c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (!modules)
7286c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    return;
7296c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
7306c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("\n");
7316c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("Loaded modules:\n");
7326c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
7336c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  uint64_t main_address = 0;
7346c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  const CodeModule *main_module = modules->GetMainModule();
7356c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (main_module) {
7366c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    main_address = main_module->base_address();
7376c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
7386c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
7396c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  unsigned int module_count = modules->module_count();
7406c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  for (unsigned int module_sequence = 0;
7416c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org       module_sequence < module_count;
7426c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org       ++module_sequence) {
7436c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const CodeModule *module = modules->GetModuleAtSequence(module_sequence);
7446c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    PrintModule(module, modules_without_symbols, modules_with_corrupt_symbols,
7456c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                main_address);
7466c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
7476c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}
7486c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
7496c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// PrintModulesMachineReadable outputs a list of loaded modules,
7506c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// one per line, in the following machine-readable pipe-delimited
7516c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// text format:
7526c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// Module|{Module Filename}|{Version}|{Debug Filename}|{Debug Identifier}|
7536c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org// {Base Address}|{Max Address}|{Main}
7546c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgstatic void PrintModulesMachineReadable(const CodeModules *modules) {
7556c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (!modules)
7566c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    return;
7576c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
7586c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  uint64_t main_address = 0;
7596c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  const CodeModule *main_module = modules->GetMainModule();
7606c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (main_module) {
7616c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    main_address = main_module->base_address();
7626c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
7636c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
7646c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  unsigned int module_count = modules->module_count();
7656c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  for (unsigned int module_sequence = 0;
7666c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org       module_sequence < module_count;
7676c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org       ++module_sequence) {
7686c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    const CodeModule *module = modules->GetModuleAtSequence(module_sequence);
7696c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    uint64_t base_address = module->base_address();
7706c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("Module%c%s%c%s%c%s%c%s%c0x%08" PRIx64 "%c0x%08" PRIx64 "%c%d\n",
7716c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           kOutputSeparator,
7726c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           StripSeparator(PathnameStripper::File(module->code_file())).c_str(),
7736c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           kOutputSeparator, StripSeparator(module->version()).c_str(),
7746c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           kOutputSeparator,
7756c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           StripSeparator(PathnameStripper::File(module->debug_file())).c_str(),
7766c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           kOutputSeparator,
7776c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           StripSeparator(module->debug_identifier()).c_str(),
7786c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           kOutputSeparator, base_address,
7796c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           kOutputSeparator, base_address + module->size() - 1,
7806c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           kOutputSeparator,
7816c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           main_module != NULL && base_address == main_address ? 1 : 0);
7826c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
7836c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}
7846c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
7856c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}  // namespace
7866c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
78799936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.orgvoid PrintProcessState(const ProcessState& process_state,
78899936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                       bool output_stack_contents,
78999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                       SourceLineResolverInterface* resolver) {
7906c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // Print OS and CPU information.
7916c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  string cpu = process_state.system_info()->cpu;
7926c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  string cpu_info = process_state.system_info()->cpu_info;
7936c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("Operating system: %s\n", process_state.system_info()->os.c_str());
7946c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("                  %s\n",
7956c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         process_state.system_info()->os_version.c_str());
7966c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("CPU: %s\n", cpu.c_str());
7976c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (!cpu_info.empty()) {
7986c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    // This field is optional.
7996c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("     %s\n", cpu_info.c_str());
8006c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
8016c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("     %d CPU%s\n",
8026c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         process_state.system_info()->cpu_count,
8036c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         process_state.system_info()->cpu_count != 1 ? "s" : "");
8046c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("\n");
8056c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
8066c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // Print crash information.
8076c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (process_state.crashed()) {
8086c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("Crash reason:  %s\n", process_state.crash_reason().c_str());
8096c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("Crash address: 0x%" PRIx64 "\n", process_state.crash_address());
8106c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  } else {
8116c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("No crash\n");
8126c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
8136c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
8146c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  string assertion = process_state.assertion();
8156c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (!assertion.empty()) {
8166c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("Assertion: %s\n", assertion.c_str());
8176c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
8186c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
819ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org  // Compute process uptime if the process creation and crash times are
820ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org  // available in the dump.
821ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org  if (process_state.time_date_stamp() != 0 &&
822ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org      process_state.process_create_time() != 0 &&
823ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org      process_state.time_date_stamp() >= process_state.process_create_time()) {
824ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org    printf("Process uptime: %d seconds\n",
825ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org           process_state.time_date_stamp() -
826ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org               process_state.process_create_time());
827ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org  } else {
828ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org    printf("Process uptime: not available\n");
829ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org  }
830ea4b5be2a2b9a5d5e7a09150a1821b1db5698a45ivanpe@chromium.org
8316c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // If the thread that requested the dump is known, print it first.
8326c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  int requesting_thread = process_state.requesting_thread();
8336c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (requesting_thread != -1) {
8346c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("\n");
8356c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("Thread %d (%s)\n",
8366c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org          requesting_thread,
8376c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org          process_state.crashed() ? "crashed" :
8386c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                                    "requested dump, did not crash");
83999936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org    PrintStack(process_state.threads()->at(requesting_thread), cpu,
84099936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org               output_stack_contents,
84199936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org               process_state.thread_memory_regions()->at(requesting_thread),
84299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org               process_state.modules(), resolver);
8436c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
8446c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
8456c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // Print all of the threads in the dump.
8466c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  int thread_count = process_state.threads()->size();
8476c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  for (int thread_index = 0; thread_index < thread_count; ++thread_index) {
8486c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    if (thread_index != requesting_thread) {
8496c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      // Don't print the crash thread again, it was already printed.
8506c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      printf("\n");
8516c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      printf("Thread %d\n", thread_index);
85299936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org      PrintStack(process_state.threads()->at(thread_index), cpu,
85399936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                 output_stack_contents,
85499936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                 process_state.thread_memory_regions()->at(thread_index),
85599936a8790bb2aa900c065f38d5f3d543a8d34bfhashimoto@chromium.org                 process_state.modules(), resolver);
8566c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    }
8576c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
8586c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
8596c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  PrintModules(process_state.modules(),
8606c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org               process_state.modules_without_symbols(),
8616c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org               process_state.modules_with_corrupt_symbols());
8626c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}
8636c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
8646c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.orgvoid PrintProcessStateMachineReadable(const ProcessState& process_state) {
8656c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // Print OS and CPU information.
8666c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // OS|{OS Name}|{OS Version}
8676c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // CPU|{CPU Name}|{CPU Info}|{Number of CPUs}
8686c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("OS%c%s%c%s\n", kOutputSeparator,
8696c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         StripSeparator(process_state.system_info()->os).c_str(),
8706c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         kOutputSeparator,
8716c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         StripSeparator(process_state.system_info()->os_version).c_str());
8726c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("CPU%c%s%c%s%c%d\n", kOutputSeparator,
8736c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         StripSeparator(process_state.system_info()->cpu).c_str(),
8746c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         kOutputSeparator,
8756c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         // this may be empty
8766c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         StripSeparator(process_state.system_info()->cpu_info).c_str(),
8776c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         kOutputSeparator,
8786c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org         process_state.system_info()->cpu_count);
8796c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
8806c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  int requesting_thread = process_state.requesting_thread();
8816c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
8826c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // Print crash information.
8836c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // Crash|{Crash Reason}|{Crash Address}|{Crashed Thread}
8846c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("Crash%c", kOutputSeparator);
8856c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (process_state.crashed()) {
8866c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("%s%c0x%" PRIx64 "%c",
8876c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           StripSeparator(process_state.crash_reason()).c_str(),
8886c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org           kOutputSeparator, process_state.crash_address(), kOutputSeparator);
8896c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  } else {
8906c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    // print assertion info, if available, in place of crash reason,
8916c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    // instead of the unhelpful "No crash"
8926c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    string assertion = process_state.assertion();
8936c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    if (!assertion.empty()) {
8946c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      printf("%s%c%c", StripSeparator(assertion).c_str(),
8956c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org             kOutputSeparator, kOutputSeparator);
8966c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    } else {
8976c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      printf("No crash%c%c", kOutputSeparator, kOutputSeparator);
8986c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    }
8996c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
9006c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
9016c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (requesting_thread != -1) {
9026c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("%d\n", requesting_thread);
9036c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  } else {
9046c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    printf("\n");
9056c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
9066c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
9076c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  PrintModulesMachineReadable(process_state.modules());
9086c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
9096c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // blank line to indicate start of threads
9106c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  printf("\n");
9116c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
9126c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // If the thread that requested the dump is known, print it first.
9136c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  if (requesting_thread != -1) {
9146c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    PrintStackMachineReadable(requesting_thread,
9156c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                              process_state.threads()->at(requesting_thread));
9166c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
9176c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
9186c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  // Print all of the threads in the dump.
9196c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  int thread_count = process_state.threads()->size();
9206c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  for (int thread_index = 0; thread_index < thread_count; ++thread_index) {
9216c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    if (thread_index != requesting_thread) {
9226c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      // Don't print the crash thread again, it was already printed.
9236c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org      PrintStackMachineReadable(thread_index,
9246c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org                                process_state.threads()->at(thread_index));
9256c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org    }
9266c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org  }
9276c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}
9286c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org
9296c3174886cab07c86d05c29be5d19a2e5b16683dprimiano@chromium.org}  // namespace google_breakpad
930