mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-27 15:32:10 +08:00
fuchsia: Capture general purpose registers in thread snapshot
Conversion to CPUContext is currently only implemented for x64. Bug: crashpad:196 Change-Id: I3fb8541f70a6f8d6f12c02e6b17c78e07e195056 Reviewed-on: https://chromium-review.googlesource.com/1007967 Commit-Queue: Scott Graham <scottmg@chromium.org> Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
parent
f5d5a41317
commit
c2583364a3
@ -176,6 +176,8 @@ static_library("snapshot") {
|
||||
|
||||
if (crashpad_is_fuchsia) {
|
||||
sources += [
|
||||
"fuchsia/cpu_context_fuchsia.cc",
|
||||
"fuchsia/cpu_context_fuchsia.h",
|
||||
"fuchsia/process_reader_fuchsia.cc",
|
||||
"fuchsia/process_reader_fuchsia.h",
|
||||
"fuchsia/process_snapshot_fuchsia.cc",
|
||||
|
51
snapshot/fuchsia/cpu_context_fuchsia.cc
Normal file
51
snapshot/fuchsia/cpu_context_fuchsia.cc
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright 2018 The Crashpad Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "snapshot/fuchsia/cpu_context_fuchsia.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
namespace crashpad {
|
||||
namespace internal {
|
||||
|
||||
#if defined(ARCH_CPU_X86_64)
|
||||
|
||||
void InitializeCPUContextX86_64(
|
||||
const zx_thread_state_general_regs_t& thread_context,
|
||||
CPUContextX86_64* context) {
|
||||
memset(context, 0, sizeof(*context));
|
||||
context->rax = thread_context.rax;
|
||||
context->rbx = thread_context.rbx;
|
||||
context->rcx = thread_context.rcx;
|
||||
context->rdx = thread_context.rdx;
|
||||
context->rdi = thread_context.rdi;
|
||||
context->rsi = thread_context.rsi;
|
||||
context->rbp = thread_context.rbp;
|
||||
context->rsp = thread_context.rsp;
|
||||
context->r8 = thread_context.r8;
|
||||
context->r9 = thread_context.r9;
|
||||
context->r10 = thread_context.r10;
|
||||
context->r11 = thread_context.r11;
|
||||
context->r12 = thread_context.r12;
|
||||
context->r13 = thread_context.r13;
|
||||
context->r14 = thread_context.r14;
|
||||
context->r15 = thread_context.r15;
|
||||
context->rip = thread_context.rip;
|
||||
context->rflags = thread_context.rflags;
|
||||
}
|
||||
|
||||
#endif // ARCH_CPU_X86_64
|
||||
|
||||
} // namespace internal
|
||||
} // namespace crashpad
|
46
snapshot/fuchsia/cpu_context_fuchsia.h
Normal file
46
snapshot/fuchsia/cpu_context_fuchsia.h
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright 2018 The Crashpad Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef CRASHPAD_SNAPSHOT_FUCHSIA_CPU_CONTEXT_FUCHSIA_H_
|
||||
#define CRASHPAD_SNAPSHOT_FUCHSIA_CPU_CONTEXT_FUCHSIA_H_
|
||||
|
||||
#include <zircon/syscall/debug.h>
|
||||
|
||||
#include "build/build_config.h"
|
||||
#include "snapshot/cpu_context.h"
|
||||
#include "snapshot/fuchsia/process_reader_fuchsia.h"
|
||||
|
||||
namespace crashpad {
|
||||
namespace internal {
|
||||
|
||||
#if defined(ARCH_CPU_X86_64) || DOXYGEN
|
||||
|
||||
//! \brief Initializes a CPUContextX86_64 structure from native context
|
||||
//! structures on Fuchsia.
|
||||
//!
|
||||
//! Floating point registers are currently initialized to zero.
|
||||
//! Segment registers are currently initialized to zero.
|
||||
//!
|
||||
//! \param[in] thread_context The native thread context.
|
||||
//! \param[out] context The CPUContextX86_64 structure to initialize.
|
||||
void InitializeCPUContextX86_64(
|
||||
const zx_thread_state_general_regs_t& thread_context,
|
||||
CPUContextX86_64* context);
|
||||
|
||||
#endif // ARCH_CPU_X86_64 || DOXYGEN
|
||||
|
||||
} // namespace internal
|
||||
} // namespace crashpad
|
||||
|
||||
#endif // CRASHPAD_SNAPSHOT_FUCHSIA_CPU_CONTEXT_FUCHSIA_H_
|
@ -224,6 +224,15 @@ void ProcessReaderFuchsia::InitializeThreads() {
|
||||
}
|
||||
}
|
||||
|
||||
zx_thread_state_general_regs_t regs;
|
||||
status = zx_thread_read_state(
|
||||
thread_handle.get(), ZX_THREAD_STATE_GENERAL_REGS, ®s, sizeof(regs));
|
||||
if (status != ZX_OK) {
|
||||
ZX_LOG(WARNING, status) << "zx_thread_read_state";
|
||||
} else {
|
||||
thread.general_registers = regs;
|
||||
}
|
||||
|
||||
threads_.push_back(thread);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
#ifndef CRASHPAD_SNAPSHOT_FUCHSIA_PROCESS_READER_H_
|
||||
#define CRASHPAD_SNAPSHOT_FUCHSIA_PROCESS_READER_H_
|
||||
|
||||
#include <zircon/syscalls/debug.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@ -68,6 +70,10 @@ class ProcessReaderFuchsia {
|
||||
|
||||
//! \brief The `ZX_PROP_NAME` property of the thread. This may be empty.
|
||||
std::string name;
|
||||
|
||||
//! \brief The raw architecture-specific `zx_thread_state_general_regs_t` as
|
||||
//! returned by `zx_thread_read_state()`.
|
||||
zx_thread_state_general_regs_t general_registers = {};
|
||||
};
|
||||
|
||||
ProcessReaderFuchsia();
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "snapshot/fuchsia/thread_snapshot_fuchsia.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "snapshot/fuchsia/cpu_context_fuchsia.h"
|
||||
|
||||
namespace crashpad {
|
||||
namespace internal {
|
||||
@ -38,11 +39,13 @@ bool ThreadSnapshotFuchsia::Initialize(
|
||||
#if defined(ARCH_CPU_X86_64)
|
||||
context_.architecture = kCPUArchitectureX86_64;
|
||||
context_.x86_64 = &context_arch_;
|
||||
// TODO(scottmg): Implement context capture for x64.
|
||||
// TODO(scottmg): Float context, once Fuchsia has a debug API to capture
|
||||
// floating point registers. ZX-1750 upstream.
|
||||
InitializeCPUContextX86_64(thread.general_registers, context_.x86_64);
|
||||
#elif defined(ARCH_CPU_ARM64)
|
||||
context_.architecture = kCPUArchitectureARM64;
|
||||
context_.arm64 = &context_arch_;
|
||||
// TODO(scottmg): Implement context capture for arm64.
|
||||
// TODO(scottmg): Implement context capture for arm64.
|
||||
#else
|
||||
#error Port.
|
||||
#endif
|
||||
|
@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef CRASHPAD_SNAPSHOT_LINUX_SNAPSHOT_CPU_CONTEXT_LINUX_H_
|
||||
#define CRASHPAD_SNAPSHOT_LINUX_SNAPSHOT_CPU_CONTEXT_LINUX_H_
|
||||
#ifndef CRASHPAD_SNAPSHOT_LINUX_CPU_CONTEXT_LINUX_H_
|
||||
#define CRASHPAD_SNAPSHOT_LINUX_CPU_CONTEXT_LINUX_H_
|
||||
|
||||
#include "build/build_config.h"
|
||||
#include "snapshot/cpu_context.h"
|
||||
@ -141,4 +141,4 @@ void InitializeCPUContextARM64_OnlyFPSIMD(
|
||||
} // namespace internal
|
||||
} // namespace crashpad
|
||||
|
||||
#endif // CRASHPAD_SNAPSHOT_LINUX_SNAPSHOT_CPU_CONTEXT_LINUX_H_
|
||||
#endif // CRASHPAD_SNAPSHOT_LINUX_CPU_CONTEXT_LINUX_H_
|
||||
|
@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef CRASHPAD_SNAPSHOT_MAC_SNAPSHOT_CPU_CONTEXT_MAC_H_
|
||||
#define CRASHPAD_SNAPSHOT_MAC_SNAPSHOT_CPU_CONTEXT_MAC_H_
|
||||
#ifndef CRASHPAD_SNAPSHOT_MAC_CPU_CONTEXT_MAC_H_
|
||||
#define CRASHPAD_SNAPSHOT_MAC_CPU_CONTEXT_MAC_H_
|
||||
|
||||
#include <mach/mach.h>
|
||||
|
||||
@ -113,4 +113,4 @@ void InitializeCPUContextX86_64(CPUContextX86_64* context,
|
||||
} // namespace internal
|
||||
} // namespace crashpad
|
||||
|
||||
#endif // CRASHPAD_SNAPSHOT_MAC_SNAPSHOT_CPU_CONTEXT_MAC_H_
|
||||
#endif // CRASHPAD_SNAPSHOT_MAC_CPU_CONTEXT_MAC_H_
|
||||
|
Loading…
x
Reference in New Issue
Block a user