2014-10-17 13:47:02 -04:00
|
|
|
|
// 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_CLIENT_CRASHPAD_INFO_H_
|
|
|
|
|
#define CRASHPAD_CLIENT_CRASHPAD_INFO_H_
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2016-01-06 12:22:50 -05:00
|
|
|
|
#include "base/macros.h"
|
2015-08-14 15:22:09 -07:00
|
|
|
|
#include "build/build_config.h"
|
2016-02-26 14:42:47 -08:00
|
|
|
|
#include "client/simple_address_range_bag.h"
|
2014-10-17 13:47:02 -04:00
|
|
|
|
#include "client/simple_string_dictionary.h"
|
2015-03-11 17:07:11 -04:00
|
|
|
|
#include "util/misc/tri_state.h"
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
2015-08-14 15:22:09 -07:00
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#endif // OS_WIN
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
2016-02-29 13:28:05 -08:00
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
//! \brief A linked list of blocks representing custom streams in the minidump,
|
|
|
|
|
//! with addresses (and size) stored as uint64_t to simplify reading from
|
|
|
|
|
//! the handler process.
|
|
|
|
|
struct UserDataMinidumpStreamListEntry {
|
|
|
|
|
//! \brief The address of the next entry in the linked list.
|
|
|
|
|
uint64_t next;
|
|
|
|
|
|
|
|
|
|
//! \brief The base address of the memory block in the target process' address
|
|
|
|
|
//! space that represents the user data stream.
|
|
|
|
|
uint64_t base_address;
|
|
|
|
|
|
|
|
|
|
//! \brief The size of memory block in the target process' address space that
|
|
|
|
|
//! represents the user data stream.
|
|
|
|
|
uint64_t size;
|
|
|
|
|
|
|
|
|
|
//! \brief The stream type identifier.
|
|
|
|
|
uint32_t stream_type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
//! \brief A structure that can be used by a Crashpad-enabled program to
|
|
|
|
|
//! provide information to the Crashpad crash handler.
|
|
|
|
|
//!
|
|
|
|
|
//! It is possible for one CrashpadInfo structure to appear in each loaded code
|
|
|
|
|
//! module in a process, but from the perspective of the user of the client
|
|
|
|
|
//! interface, there is only one global CrashpadInfo structure, located in the
|
|
|
|
|
//! module that contains the client interface code.
|
|
|
|
|
struct CrashpadInfo {
|
|
|
|
|
public:
|
|
|
|
|
//! \brief Returns the global CrashpadInfo structure.
|
|
|
|
|
static CrashpadInfo* GetCrashpadInfo();
|
|
|
|
|
|
|
|
|
|
CrashpadInfo();
|
|
|
|
|
|
2016-02-26 14:42:47 -08:00
|
|
|
|
//! \brief Sets the bag of extra memory ranges to be included in the snapshot.
|
|
|
|
|
//!
|
|
|
|
|
//! Extra memory ranges may exist in \a address_range_bag at the time that
|
|
|
|
|
//! this method is called, or they may be added, removed, or modified in \a
|
|
|
|
|
//! address_range_bag after this method is called.
|
|
|
|
|
//!
|
|
|
|
|
//! TODO(scottmg) This is currently only supported on Windows.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] address_range_bag A bag of address ranges. The CrashpadInfo
|
|
|
|
|
//! object does not take ownership of the SimpleAddressRangeBag object.
|
|
|
|
|
//! It is the caller’s responsibility to ensure that this pointer remains
|
|
|
|
|
//! valid while it is in effect for a CrashpadInfo object.
|
|
|
|
|
void set_extra_memory_ranges(SimpleAddressRangeBag* address_range_bag) {
|
|
|
|
|
extra_memory_ranges_ = address_range_bag;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-19 18:04:38 -04:00
|
|
|
|
//! \brief Sets the simple annotations dictionary.
|
|
|
|
|
//!
|
|
|
|
|
//! Simple annotations set on a CrashpadInfo structure are interpreted by
|
|
|
|
|
//! Crashpad as module-level annotations.
|
|
|
|
|
//!
|
|
|
|
|
//! Annotations may exist in \a simple_annotations at the time that this
|
|
|
|
|
//! method is called, or they may be added, removed, or modified in \a
|
|
|
|
|
//! simple_annotations after this method is called.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] simple_annotations A dictionary that maps string keys to string
|
|
|
|
|
//! values. The CrashpadInfo object does not take ownership of the
|
|
|
|
|
//! SimpleStringDictionary object. It is the caller’s responsibility to
|
|
|
|
|
//! ensure that this pointer remains valid while it is in effect for a
|
|
|
|
|
//! CrashpadInfo object.
|
2014-10-17 13:47:02 -04:00
|
|
|
|
void set_simple_annotations(SimpleStringDictionary* simple_annotations) {
|
|
|
|
|
simple_annotations_ = simple_annotations;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 17:07:11 -04:00
|
|
|
|
//! \brief Enables or disables Crashpad handler processing.
|
|
|
|
|
//!
|
|
|
|
|
//! When handling an exception, the Crashpad handler will scan all modules in
|
|
|
|
|
//! a process. The first one that has a CrashpadInfo structure populated with
|
|
|
|
|
//! a value other than #kUnset for this field will dictate whether the handler
|
|
|
|
|
//! is functional or not. If all modules with a CrashpadInfo structure specify
|
|
|
|
|
//! #kUnset, the handler will be enabled. If disabled, the Crashpad handler
|
|
|
|
|
//! will still run and receive exceptions, but will not take any action on an
|
|
|
|
|
//! exception on its own behalf, except for the action necessary to determine
|
|
|
|
|
//! that it has been disabled.
|
|
|
|
|
//!
|
|
|
|
|
//! The Crashpad handler should not normally be disabled. More commonly, it
|
2016-02-29 13:28:05 -08:00
|
|
|
|
//! is appropriate to disable crash report upload by calling
|
2015-03-11 17:07:11 -04:00
|
|
|
|
//! Settings::SetUploadsEnabled().
|
|
|
|
|
void set_crashpad_handler_behavior(TriState crashpad_handler_behavior) {
|
|
|
|
|
crashpad_handler_behavior_ = crashpad_handler_behavior;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! \brief Enables or disables Crashpad forwarding of exceptions to the
|
|
|
|
|
//! system’s crash reporter.
|
|
|
|
|
//!
|
|
|
|
|
//! When handling an exception, the Crashpad handler will scan all modules in
|
|
|
|
|
//! a process. The first one that has a CrashpadInfo structure populated with
|
|
|
|
|
//! a value other than #kUnset for this field will dictate whether the
|
|
|
|
|
//! exception is forwarded to the system’s crash reporter. If all modules with
|
|
|
|
|
//! a CrashpadInfo structure specify #kUnset, forwarding will be enabled.
|
|
|
|
|
//! Unless disabled, forwarding may still occur if the Crashpad handler is
|
|
|
|
|
//! disabled by SetCrashpadHandlerState(). Even when forwarding is enabled,
|
|
|
|
|
//! the Crashpad handler may choose not to forward all exceptions to the
|
|
|
|
|
//! system’s crash reporter in cases where it has reason to believe that the
|
|
|
|
|
//! system’s crash reporter would not normally have handled the exception in
|
|
|
|
|
//! Crashpad’s absence.
|
|
|
|
|
void set_system_crash_reporter_forwarding(
|
|
|
|
|
TriState system_crash_reporter_forwarding) {
|
|
|
|
|
system_crash_reporter_forwarding_ = system_crash_reporter_forwarding;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-14 15:12:28 -08:00
|
|
|
|
//! \brief Enables or disables Crashpad capturing indirectly referenced memory
|
|
|
|
|
//! in the minidump.
|
|
|
|
|
//!
|
|
|
|
|
//! When handling an exception, the Crashpad handler will scan all modules in
|
|
|
|
|
//! a process. The first one that has a CrashpadInfo structure populated with
|
|
|
|
|
//! a value other than #kUnset for this field will dictate whether the extra
|
|
|
|
|
//! memory is captured.
|
|
|
|
|
//!
|
|
|
|
|
//! This causes Crashpad to include pages of data referenced by locals or
|
|
|
|
|
//! other stack memory. Turning this on can increase the size of the minidump
|
|
|
|
|
//! significantly.
|
2016-04-21 22:19:31 -07:00
|
|
|
|
//!
|
|
|
|
|
//! \param[in] gather_indirectly_referenced_memory Whether extra memory should
|
|
|
|
|
//! be gathered.
|
|
|
|
|
//! \param[in] limit The amount of memory in bytes after which no more
|
|
|
|
|
//! indirectly gathered memory should be captured. This value is only used
|
|
|
|
|
//! when \a gather_indirectly_referenced_memory is TriState::kEnabled.
|
2016-01-14 15:12:28 -08:00
|
|
|
|
void set_gather_indirectly_referenced_memory(
|
2016-04-21 22:19:31 -07:00
|
|
|
|
TriState gather_indirectly_referenced_memory,
|
|
|
|
|
uint32_t limit) {
|
2016-01-14 15:12:28 -08:00
|
|
|
|
gather_indirectly_referenced_memory_ = gather_indirectly_referenced_memory;
|
2016-04-21 22:19:31 -07:00
|
|
|
|
indirectly_referenced_memory_cap_ = limit;
|
2016-01-14 15:12:28 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-29 13:28:05 -08:00
|
|
|
|
//! \brief Adds a custom stream to the minidump.
|
|
|
|
|
//!
|
|
|
|
|
//! The memory block referenced by \a data and \a size will added to the
|
|
|
|
|
//! minidump as separate stream with type \stream_type. The memory referred to
|
|
|
|
|
//! by \a data and \a size is owned by the caller and must remain valid while
|
|
|
|
|
//! it is in effect for the CrashpadInfo object.
|
|
|
|
|
//!
|
|
|
|
|
//! Note that streams will appear in the minidump in the reverse order to
|
|
|
|
|
//! which they are added.
|
|
|
|
|
//!
|
|
|
|
|
//! TODO(scottmg) This is currently only supported on Windows.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] stream_type The stream type identifier to use. This should be
|
|
|
|
|
//! normally be larger than `MINIDUMP_STREAM_TYPE::LastReservedStream`
|
|
|
|
|
//! which is `0xffff`.
|
|
|
|
|
//! \param[in] data The base pointer of the stream data.
|
|
|
|
|
//! \param[in] size The size of the stream data.
|
|
|
|
|
void AddUserDataMinidumpStream(uint32_t stream_type,
|
|
|
|
|
const void* data,
|
|
|
|
|
size_t size);
|
|
|
|
|
|
2015-05-04 16:02:28 -07:00
|
|
|
|
enum : uint32_t {
|
|
|
|
|
kSignature = 'CPad',
|
|
|
|
|
};
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// The compiler won’t necessarily see anyone using these fields, but it
|
|
|
|
|
// shouldn’t warn about that. These fields aren’t intended for use by the
|
|
|
|
|
// process they’re found in, they’re supposed to be read by the crash
|
|
|
|
|
// reporting process.
|
2014-12-15 16:01:16 -08:00
|
|
|
|
#if defined(__clang__)
|
2014-10-17 13:47:02 -04:00
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
|
#pragma clang diagnostic ignored "-Wunused-private-field"
|
2014-12-15 16:01:16 -08:00
|
|
|
|
#endif
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
// Fields present in version 1:
|
|
|
|
|
uint32_t signature_; // kSignature
|
|
|
|
|
uint32_t size_; // The size of the entire CrashpadInfo structure.
|
|
|
|
|
uint32_t version_; // kVersion
|
2016-04-21 22:19:31 -07:00
|
|
|
|
uint32_t indirectly_referenced_memory_cap_;
|
|
|
|
|
uint32_t padding_0_;
|
2015-03-11 17:07:11 -04:00
|
|
|
|
TriState crashpad_handler_behavior_;
|
|
|
|
|
TriState system_crash_reporter_forwarding_;
|
2016-01-14 15:12:28 -08:00
|
|
|
|
TriState gather_indirectly_referenced_memory_;
|
2016-04-21 22:19:31 -07:00
|
|
|
|
uint8_t padding_1_;
|
2016-02-26 14:42:47 -08:00
|
|
|
|
SimpleAddressRangeBag* extra_memory_ranges_; // weak
|
2014-10-17 13:47:02 -04:00
|
|
|
|
SimpleStringDictionary* simple_annotations_; // weak
|
2016-02-29 13:28:05 -08:00
|
|
|
|
internal::UserDataMinidumpStreamListEntry* user_data_minidump_stream_head_;
|
2014-12-15 16:01:16 -08:00
|
|
|
|
|
2015-09-22 10:37:11 -07:00
|
|
|
|
#if !defined(NDEBUG) && defined(OS_WIN)
|
|
|
|
|
uint32_t invalid_read_detection_;
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-12-15 16:01:16 -08:00
|
|
|
|
#if defined(__clang__)
|
2014-10-17 13:47:02 -04:00
|
|
|
|
#pragma clang diagnostic pop
|
2014-12-15 16:01:16 -08:00
|
|
|
|
#endif
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CrashpadInfo);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace crashpad
|
|
|
|
|
|
|
|
|
|
#endif // CRASHPAD_CLIENT_CRASHPAD_INFO_H_
|