Commit 5ad5f0ac authored by Irina Yatsenko's avatar Irina Yatsenko Committed by Commit Bot

Reland "Add Crash Keys support"

This is a reland of 02103b27

Fix for the original build break: build android with noop crashkeys for now

Original change's description:
> Add Crash Keys support
>
> This adds crash keys containing the isolate address and addresses of
> the read_only, map, and code spaces to crash report minidumps.
> When not compiling V8 with Chrome, a noop implementation is used.
>
> Bug: v8:9323
> Change-Id: I8523630e7a4ff792855163c06bf76dab35b1b9e5
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1641326
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Commit-Queue: Irina Yatsenko <irinayat@microsoft.com>
> Cr-Commit-Position: refs/heads/master@{#62059}

Bug: v8:9323
Change-Id: I6bb115ad14b2ce5865f4d8fb255245c38fb0cd14
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1658505
Commit-Queue: Irina Yatsenko <irinayat@microsoft.com>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62320}
parent f92d7196
......@@ -2151,6 +2151,7 @@ v8_source_set("v8_base_without_compiler") {
"src/diagnostics/code-tracer.h",
"src/diagnostics/compilation-statistics.cc",
"src/diagnostics/compilation-statistics.h",
"src/diagnostics/crash-key.h",
"src/diagnostics/disasm.h",
"src/diagnostics/disassembler.cc",
"src/diagnostics/disassembler.h",
......@@ -3292,10 +3293,33 @@ v8_source_set("v8_base_without_compiler") {
}
}
v8_source_set("v8_crash_keys") {
visibility = [ ":*" ] # Only targets in this file can depend on this.
# TODO(irinayat): crash_key brings dependency on //base and memory allocators,
# which causes linker errors picking up memory shims on Android. Figure out
# how to make this work so android could also collect crash keys.
if (build_with_chromium && !is_android) {
deps = [
"//components/crash/core/common:crash_key",
]
sources = [
"src/diagnostics/crash-key.cc",
]
} else {
sources = [
"src/diagnostics/crash-key-noop.cc",
]
}
configs = [ ":internal_config" ]
}
group("v8_base") {
public_deps = [
":v8_base_without_compiler",
":v8_compiler",
":v8_crash_keys",
]
}
......@@ -3777,6 +3801,7 @@ if (v8_use_snapshot && current_toolchain == v8_snapshot_toolchain) {
visibility = [ ":*" ] # Only targets in this file can depend on this.
sources = [
"src/diagnostics/crash-key-noop.cc",
"src/snapshot/embedded/embedded-file-writer.cc",
"src/snapshot/embedded/embedded-file-writer.h",
"src/snapshot/embedded/platform-embedded-file-writer-aix.cc",
......
include_rules = [
"+components/crash/core/common/crash_key.h",
]
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Noop implementation of crash keys to be used by targets that don't support
// crashpad.
#include "src/diagnostics/crash-key.h"
namespace v8 {
namespace internal {
namespace crash {
void AddCrashKey(int id, const char* name, uintptr_t value) {
}
} // namespace crash
} // namespace internal
} // namespace v8
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/diagnostics/crash-key.h"
#include "components/crash/core/common/crash_key.h"
#include <string>
#include <sstream>
namespace v8 {
namespace internal {
namespace crash {
using CrashKeyInstance = crash_reporter::CrashKeyString<kKeySize>;
static CrashKeyInstance crash_keys[] = {
{"v8-0", CrashKeyInstance::Tag::kArray},
{"v8-1", CrashKeyInstance::Tag::kArray},
{"v8-2", CrashKeyInstance::Tag::kArray},
{"v8-3", CrashKeyInstance::Tag::kArray},
{"v8-4", CrashKeyInstance::Tag::kArray},
{"v8-5", CrashKeyInstance::Tag::kArray},
{"v8-6", CrashKeyInstance::Tag::kArray},
{"v8-7", CrashKeyInstance::Tag::kArray},
{"v8-8", CrashKeyInstance::Tag::kArray},
{"v8-9", CrashKeyInstance::Tag::kArray},
{"v8-10", CrashKeyInstance::Tag::kArray},
{"v8-11", CrashKeyInstance::Tag::kArray},
{"v8-12", CrashKeyInstance::Tag::kArray},
{"v8-13", CrashKeyInstance::Tag::kArray},
{"v8-14", CrashKeyInstance::Tag::kArray},
{"v8-15", CrashKeyInstance::Tag::kArray},
};
void AddCrashKey(int id, const char* name, uintptr_t value) {
static int current = 0;
if (current > kMaxCrashKeysCount) {
return;
}
if (current == kMaxCrashKeysCount) {
static crash_reporter::CrashKeyString<1> over("v8-too-many-keys");
over.Set("1");
current++;
return;
}
auto& trace_key = crash_keys[current];
std::stringstream stream;
stream << name << " " << id << " 0x" << std::hex << value;
trace_key.Set(stream.str().substr(0, kKeySize));
current++;
}
} // namespace crash
} // namespace internal
} // namespace v8
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Conflicts between v8/src/base and base prevent from including
// components/crash/core/common/crash_key.h into most of v8's files, so have to
// provide wrappers to localize the include to v8/src/base/crash-key.cc only.
#ifndef V8_DIAGNOSTICS_CRASH_KEY_H_
#define V8_DIAGNOSTICS_CRASH_KEY_H_
#include <stdint.h>
namespace v8 {
namespace internal {
namespace crash {
// Crash keys must be statically allocated so we'll have a few slots for
// pointer values and will log if we run out of space. The pointer value will
// be combined with the given name and id. Names should be sufficiently short
// to fit key_size limit.
// The crash key in the dump will look similar to:
// {"v8-0", "isolate 0 0x21951a41d90"}
// (we assume a pointer is being logged and we convert it to hex).
constexpr int kKeySize = 64;
constexpr int kMaxCrashKeysCount = 16;
void AddCrashKey(int id, const char* name, uintptr_t value);
} // namespace crash
} // namespace internal
} // namespace v8
#endif // V8_DIAGNOSTICS_CRASH_KEY_H_
......@@ -32,6 +32,7 @@
#include "src/debug/debug.h"
#include "src/deoptimizer/deoptimizer.h"
#include "src/diagnostics/compilation-statistics.h"
#include "src/diagnostics/crash-key.h"
#include "src/execution/frames-inl.h"
#include "src/execution/isolate-inl.h"
#include "src/execution/messages.h"
......@@ -3284,6 +3285,19 @@ bool Isolate::InitWithSnapshot(ReadOnlyDeserializer* read_only_deserializer,
return Init(read_only_deserializer, startup_deserializer);
}
static void AddCrashKeysForIsolateAndHeapPointers(Isolate* isolate) {
const int id = isolate->id();
crash::AddCrashKey(id, "isolate", reinterpret_cast<uintptr_t>(isolate));
auto heap = isolate->heap();
crash::AddCrashKey(id, "ro_space",
reinterpret_cast<uintptr_t>(heap->read_only_space()->first_page()));
crash::AddCrashKey(id, "map_space",
reinterpret_cast<uintptr_t>(heap->map_space()->first_page()));
crash::AddCrashKey(id, "code_space",
reinterpret_cast<uintptr_t>(heap->code_space()->first_page()));
}
bool Isolate::Init(ReadOnlyDeserializer* read_only_deserializer,
StartupDeserializer* startup_deserializer) {
TRACE_ISOLATE(init);
......@@ -3529,6 +3543,7 @@ bool Isolate::Init(ReadOnlyDeserializer* read_only_deserializer,
PrintF("[Initializing isolate from scratch took %0.3f ms]\n", ms);
}
AddCrashKeysForIsolateAndHeapPointers(this);
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment