crashpad/snapshot/test/test_cpu_context.h
Mark Mentovai 52c2f6edfc Add MinidumpContextWriter::CreateFromSnapshot(), everything downstream,
and its test.

Minidump context structures now interoperate more easily with snapshot
CPUContext structures, while maintaining identical layout to before.
This is facilitated by reusing the Fxsave types for the substructures
which were completely identical, and by using compatible logic to
initialize the minidump and snapshot structures for testing.

TEST=minidump_test, snapshot_test
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/686353004
2014-11-03 17:43:39 -05:00

68 lines
2.8 KiB
C++

// Copyright 2014 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_TEST_TEST_CPU_CONTEXT_H_
#define CRASHPAD_SNAPSHOT_TEST_TEST_CPU_CONTEXT_H_
#include <stdint.h>
#include "snapshot/cpu_context.h"
namespace crashpad {
namespace test {
//! \brief Initializes a context structure for testing.
//!
//! Initialization is compatible with the initialization used by minidump
//! context test initialization functions such as InitializeMinidumpContextX86()
//! and InitializeMinidumpContextAMD64() for identical \a seed values.
//!
//! \param[out] context The structure to initialize.
//! \param[in] seed The seed value. Initializing two context structures of the
//! same type with identical seed values should produce identical context
//! structures. Initialization with a different seed value should produce
//! a different context structure. If \a seed is `0`, \a context is zeroed
//! out entirely except for the CPUContext::architecture field, which will
//! identify the context type. If \a seed is nonzero, \a context will be
//! populated entirely with nonzero values.
//!
//! \{
void InitializeCPUContextX86(CPUContext* context, uint32_t seed);
void InitializeCPUContextX86_64(CPUContext* context, uint32_t seed);
//! \}
//! \brief Initializes an `fxsave` context substructure for testing.
//!
//! \param[out] fxsave The structure to initialize.
//! \param[in,out] seed The seed value. Initializing two `fxsave` structures of
//! the same type with identical seed values should produce identical
//! structures. Initialization with a different seed value should produce
//! a different `fxsave` structure. If \a seed is `0`, \a fxsave is zeroed
//! out entirely. If \a seed is nonzero, \a fxsave will be populated
//! entirely with nonzero values. \a seed will be updated by this function
//! to allow the caller to perform subsequent initialization of the context
//! structure containing \a fxsave.
//!
//! \{
void InitializeCPUContextX86Fxsave(
CPUContextX86::Fxsave* fxsave, uint32_t* seed);
void InitializeCPUContextX86_64Fxsave(
CPUContextX86_64::Fxsave* fxsave, uint32_t* seed);
//! \}
} // namespace test
} // namespace crashpad
#endif // CRASHPAD_SNAPSHOT_TEST_TEST_CPU_CONTEXT_H_