2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-10-21 14:15:07 -04:00
|
|
|
|
//
|
|
|
|
|
// 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 "minidump/test/minidump_writable_test_util.h"
|
|
|
|
|
|
2017-03-22 21:44:05 -04:00
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
2014-10-21 14:15:07 -04:00
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
2014-11-07 09:44:09 -05:00
|
|
|
|
#include "util/file/file_writer.h"
|
2015-09-14 11:09:46 -07:00
|
|
|
|
#include "util/misc/implicit_cast.h"
|
2022-06-02 12:27:37 -06:00
|
|
|
|
#include "util/numeric/in_range_cast.h"
|
2014-10-21 14:15:07 -04:00
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2014-11-06 16:47:57 -05:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
//! \brief Returns an untyped minidump object located within a minidump file’s
|
|
|
|
|
//! contents, where the offset of the object is known.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] file_contents The contents of the minidump file.
|
|
|
|
|
//! \param[in] rva The offset within the minidump file of the desired object.
|
|
|
|
|
//!
|
|
|
|
|
//! \return If \a rva is within the range of \a file_contents, returns a pointer
|
2020-05-06 20:39:19 -04:00
|
|
|
|
//! into \a file_contents at offset \a rva. Otherwise, raises a Google Test
|
2014-11-06 16:47:57 -05:00
|
|
|
|
//! assertion failure and returns `nullptr`.
|
|
|
|
|
//!
|
|
|
|
|
//! Do not call this function. Use the typed version, MinidumpWritableAtRVA<>(),
|
|
|
|
|
//! or another type-specific function.
|
2022-06-02 12:27:37 -06:00
|
|
|
|
template <typename RVAType>
|
2014-10-21 14:15:07 -04:00
|
|
|
|
const void* MinidumpWritableAtRVAInternal(const std::string& file_contents,
|
2022-06-02 12:27:37 -06:00
|
|
|
|
RVAType rva) {
|
|
|
|
|
const auto rva_offset = crashpad::InRangeCast(rva, file_contents.size());
|
|
|
|
|
if (rva_offset >= file_contents.size()) {
|
|
|
|
|
EXPECT_LT(rva_offset, file_contents.size());
|
2014-10-21 14:15:07 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 12:27:37 -06:00
|
|
|
|
return &file_contents[rva_offset];
|
2014-10-21 14:15:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 12:27:37 -06:00
|
|
|
|
template <typename RVAType, typename MinidumpLocationDescriptorType>
|
|
|
|
|
const void* TMinidumpWritableAtLocationDescriptorInternal(
|
2014-10-21 14:15:07 -04:00
|
|
|
|
const std::string& file_contents,
|
2022-06-02 12:27:37 -06:00
|
|
|
|
const MinidumpLocationDescriptorType& location,
|
2014-10-22 18:35:18 -04:00
|
|
|
|
size_t expected_size,
|
|
|
|
|
bool allow_oversized_data) {
|
2014-10-21 14:15:07 -04:00
|
|
|
|
if (location.DataSize == 0) {
|
2022-06-02 12:27:37 -06:00
|
|
|
|
EXPECT_EQ(location.Rva, RVAType(0));
|
2014-10-21 14:15:07 -04:00
|
|
|
|
return nullptr;
|
2014-10-22 18:35:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (allow_oversized_data) {
|
|
|
|
|
if (location.DataSize < expected_size) {
|
|
|
|
|
EXPECT_GE(location.DataSize, expected_size);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
} else if (location.DataSize != expected_size) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(location.DataSize, expected_size);
|
2014-10-21 14:15:07 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 12:27:37 -06:00
|
|
|
|
RVAType end = location.Rva + location.DataSize;
|
2014-10-21 14:15:07 -04:00
|
|
|
|
if (end > file_contents.size()) {
|
|
|
|
|
EXPECT_LE(end, file_contents.size());
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 12:27:37 -06:00
|
|
|
|
const void* rv =
|
|
|
|
|
MinidumpWritableAtRVAInternal<RVAType>(file_contents, location.Rva);
|
2014-10-21 14:15:07 -04:00
|
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 12:27:37 -06:00
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
const void* MinidumpWritableAtLocationDescriptorInternal(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location,
|
|
|
|
|
size_t expected_size,
|
|
|
|
|
bool allow_oversized_data) {
|
|
|
|
|
return TMinidumpWritableAtLocationDescriptorInternal<
|
|
|
|
|
RVA,
|
|
|
|
|
MINIDUMP_LOCATION_DESCRIPTOR>(
|
|
|
|
|
file_contents, location, expected_size, allow_oversized_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const void* MinidumpWritableAtLocationDescriptorInternal(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR64& location,
|
|
|
|
|
size_t expected_size,
|
|
|
|
|
bool allow_oversized_data) {
|
|
|
|
|
return TMinidumpWritableAtLocationDescriptorInternal<
|
|
|
|
|
RVA64,
|
|
|
|
|
MINIDUMP_LOCATION_DESCRIPTOR64>(
|
|
|
|
|
file_contents, location, expected_size, allow_oversized_data);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 18:35:18 -04:00
|
|
|
|
template <>
|
|
|
|
|
const IMAGE_DEBUG_MISC* MinidumpWritableAtLocationDescriptor<IMAGE_DEBUG_MISC>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
|
|
|
|
const IMAGE_DEBUG_MISC* misc =
|
|
|
|
|
TMinidumpWritableAtLocationDescriptor<IMAGE_DEBUG_MISC>(file_contents,
|
|
|
|
|
location);
|
|
|
|
|
if (!misc) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (misc->DataType != IMAGE_DEBUG_MISC_EXENAME) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(misc->DataType,
|
|
|
|
|
implicit_cast<uint32_t>(IMAGE_DEBUG_MISC_EXENAME));
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (misc->Length != location.DataSize) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(misc->Length, location.DataSize);
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (misc->Unicode == 0) {
|
|
|
|
|
size_t string_length = misc->Length - offsetof(IMAGE_DEBUG_MISC, Data) - 1;
|
|
|
|
|
if (misc->Data[string_length] != '\0') {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(misc->Data[string_length], '\0');
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
} else if (misc->Unicode == 1) {
|
2021-03-08 17:31:04 +01:00
|
|
|
|
if (misc->Length % sizeof(char16_t) != 0) {
|
|
|
|
|
EXPECT_EQ(misc->Length % sizeof(char16_t), 0u);
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 17:31:04 +01:00
|
|
|
|
size_t string_length =
|
|
|
|
|
(misc->Length - offsetof(IMAGE_DEBUG_MISC, Data)) / sizeof(char16_t) -
|
|
|
|
|
1;
|
|
|
|
|
const char16_t* data16 = reinterpret_cast<const char16_t*>(misc->Data);
|
2014-10-22 18:35:18 -04:00
|
|
|
|
if (data16[string_length] != '\0') {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(data16[string_length], '\0');
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ADD_FAILURE() << "misc->Unicode " << misc->Unicode;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return misc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
const MINIDUMP_HEADER* MinidumpWritableAtLocationDescriptor<MINIDUMP_HEADER>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
|
|
|
|
const MINIDUMP_HEADER* header =
|
|
|
|
|
TMinidumpWritableAtLocationDescriptor<MINIDUMP_HEADER>(file_contents,
|
|
|
|
|
location);
|
|
|
|
|
if (!header) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (header->Signature != MINIDUMP_SIGNATURE) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(header->Signature, implicit_cast<uint32_t>(MINIDUMP_SIGNATURE));
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (header->Version != MINIDUMP_VERSION) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(header->Version, implicit_cast<uint32_t>(MINIDUMP_VERSION));
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return header;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
struct MinidumpMemoryListTraits {
|
2014-11-05 14:09:01 -05:00
|
|
|
|
using ListType = MINIDUMP_MEMORY_LIST;
|
2015-02-05 09:13:13 -08:00
|
|
|
|
enum : size_t { kElementSize = sizeof(MINIDUMP_MEMORY_DESCRIPTOR) };
|
2014-10-22 18:35:18 -04:00
|
|
|
|
static size_t ElementCount(const ListType* list) {
|
|
|
|
|
return list->NumberOfMemoryRanges;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct MinidumpModuleListTraits {
|
2014-11-05 14:09:01 -05:00
|
|
|
|
using ListType = MINIDUMP_MODULE_LIST;
|
2015-02-05 09:13:13 -08:00
|
|
|
|
enum : size_t { kElementSize = sizeof(MINIDUMP_MODULE) };
|
2014-10-22 18:35:18 -04:00
|
|
|
|
static size_t ElementCount(const ListType* list) {
|
|
|
|
|
return list->NumberOfModules;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-11 17:19:30 -08:00
|
|
|
|
struct MinidumpUnloadedModuleListTraits {
|
|
|
|
|
using ListType = MINIDUMP_UNLOADED_MODULE_LIST;
|
|
|
|
|
enum : size_t { kElementSize = sizeof(MINIDUMP_UNLOADED_MODULE) };
|
|
|
|
|
static size_t ElementCount(const ListType* list) {
|
|
|
|
|
return list->NumberOfEntries;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-22 18:35:18 -04:00
|
|
|
|
struct MinidumpThreadListTraits {
|
2014-11-05 14:09:01 -05:00
|
|
|
|
using ListType = MINIDUMP_THREAD_LIST;
|
2015-02-05 09:13:13 -08:00
|
|
|
|
enum : size_t { kElementSize = sizeof(MINIDUMP_THREAD) };
|
2014-10-22 18:35:18 -04:00
|
|
|
|
static size_t ElementCount(const ListType* list) {
|
|
|
|
|
return list->NumberOfThreads;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-06 09:29:39 -06:00
|
|
|
|
struct MinidumpThreadNameListTraits {
|
|
|
|
|
using ListType = MINIDUMP_THREAD_NAME_LIST;
|
|
|
|
|
enum : size_t { kElementSize = sizeof(MINIDUMP_THREAD_NAME) };
|
|
|
|
|
static size_t ElementCount(const ListType* list) {
|
|
|
|
|
return list->NumberOfThreadNames;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-10-21 10:43:42 -07:00
|
|
|
|
struct MinidumpHandleDataStreamTraits {
|
|
|
|
|
using ListType = MINIDUMP_HANDLE_DATA_STREAM;
|
|
|
|
|
enum : size_t { kElementSize = sizeof(MINIDUMP_HANDLE_DESCRIPTOR) };
|
|
|
|
|
static size_t ElementCount(const ListType* list) {
|
|
|
|
|
return static_cast<size_t>(list->NumberOfDescriptors);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-10-13 13:15:44 -07:00
|
|
|
|
struct MinidumpMemoryInfoListTraits {
|
|
|
|
|
using ListType = MINIDUMP_MEMORY_INFO_LIST;
|
|
|
|
|
enum : size_t { kElementSize = sizeof(MINIDUMP_MEMORY_INFO) };
|
|
|
|
|
static size_t ElementCount(const ListType* list) {
|
|
|
|
|
return static_cast<size_t>(list->NumberOfEntries);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-03-04 10:53:34 -05:00
|
|
|
|
struct MinidumpModuleCrashpadInfoListTraits {
|
|
|
|
|
using ListType = MinidumpModuleCrashpadInfoList;
|
|
|
|
|
enum : size_t { kElementSize = sizeof(MinidumpModuleCrashpadInfoLink) };
|
2019-04-17 22:01:50 -07:00
|
|
|
|
static size_t ElementCount(const ListType* list) { return list->count; }
|
2014-10-24 14:44:55 -04:00
|
|
|
|
};
|
|
|
|
|
|
2014-10-22 18:35:18 -04:00
|
|
|
|
struct MinidumpSimpleStringDictionaryListTraits {
|
2014-11-05 14:09:01 -05:00
|
|
|
|
using ListType = MinidumpSimpleStringDictionary;
|
2015-02-05 09:13:13 -08:00
|
|
|
|
enum : size_t { kElementSize = sizeof(MinidumpSimpleStringDictionaryEntry) };
|
2019-04-17 22:01:50 -07:00
|
|
|
|
static size_t ElementCount(const ListType* list) { return list->count; }
|
2014-10-22 18:35:18 -04:00
|
|
|
|
};
|
|
|
|
|
|
2017-11-01 16:22:12 -04:00
|
|
|
|
struct MinidumpAnnotationListObjectsTraits {
|
|
|
|
|
using ListType = MinidumpAnnotationList;
|
|
|
|
|
enum : size_t { kElementSize = sizeof(MinidumpAnnotation) };
|
|
|
|
|
static size_t ElementCount(const ListType* list) { return list->count; }
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-22 18:35:18 -04:00
|
|
|
|
template <typename T>
|
|
|
|
|
const typename T::ListType* MinidumpListAtLocationDescriptor(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
|
|
|
|
const typename T::ListType* list =
|
|
|
|
|
TMinidumpWritableAtLocationDescriptor<typename T::ListType>(file_contents,
|
|
|
|
|
location);
|
|
|
|
|
if (!list) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t expected_size =
|
|
|
|
|
sizeof(typename T::ListType) + T::ElementCount(list) * T::kElementSize;
|
|
|
|
|
if (location.DataSize != expected_size) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(location.DataSize, expected_size);
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
template <>
|
2019-04-17 22:01:50 -07:00
|
|
|
|
const MINIDUMP_MEMORY_LIST*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_LIST>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return MinidumpListAtLocationDescriptor<MinidumpMemoryListTraits>(
|
|
|
|
|
file_contents, location);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
2019-04-17 22:01:50 -07:00
|
|
|
|
const MINIDUMP_MODULE_LIST*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<MINIDUMP_MODULE_LIST>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return MinidumpListAtLocationDescriptor<MinidumpModuleListTraits>(
|
|
|
|
|
file_contents, location);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-11 17:19:30 -08:00
|
|
|
|
template <>
|
|
|
|
|
const MINIDUMP_UNLOADED_MODULE_LIST*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<MINIDUMP_UNLOADED_MODULE_LIST>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
|
|
|
|
return MinidumpListAtLocationDescriptor<MinidumpUnloadedModuleListTraits>(
|
|
|
|
|
file_contents, location);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 18:35:18 -04:00
|
|
|
|
template <>
|
2019-04-17 22:01:50 -07:00
|
|
|
|
const MINIDUMP_THREAD_LIST*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_LIST>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return MinidumpListAtLocationDescriptor<MinidumpThreadListTraits>(
|
|
|
|
|
file_contents, location);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 09:29:39 -06:00
|
|
|
|
template <>
|
|
|
|
|
const MINIDUMP_THREAD_NAME_LIST*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<MINIDUMP_THREAD_NAME_LIST>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
|
|
|
|
return MinidumpListAtLocationDescriptor<MinidumpThreadNameListTraits>(
|
|
|
|
|
file_contents, location);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 10:43:42 -07:00
|
|
|
|
template <>
|
2019-04-17 22:01:50 -07:00
|
|
|
|
const MINIDUMP_HANDLE_DATA_STREAM*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<MINIDUMP_HANDLE_DATA_STREAM>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
2015-10-21 10:43:42 -07:00
|
|
|
|
return MinidumpListAtLocationDescriptor<MinidumpHandleDataStreamTraits>(
|
|
|
|
|
file_contents, location);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-13 13:15:44 -07:00
|
|
|
|
template <>
|
2019-04-17 22:01:50 -07:00
|
|
|
|
const MINIDUMP_MEMORY_INFO_LIST*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<MINIDUMP_MEMORY_INFO_LIST>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
2015-10-13 13:15:44 -07:00
|
|
|
|
return MinidumpListAtLocationDescriptor<MinidumpMemoryInfoListTraits>(
|
|
|
|
|
file_contents, location);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 14:44:55 -04:00
|
|
|
|
template <>
|
2015-03-04 10:53:34 -05:00
|
|
|
|
const MinidumpModuleCrashpadInfoList*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<MinidumpModuleCrashpadInfoList>(
|
2014-10-24 14:44:55 -04:00
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
2015-03-04 10:53:34 -05:00
|
|
|
|
return MinidumpListAtLocationDescriptor<MinidumpModuleCrashpadInfoListTraits>(
|
2014-10-24 14:44:55 -04:00
|
|
|
|
file_contents, location);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 18:35:18 -04:00
|
|
|
|
template <>
|
|
|
|
|
const MinidumpSimpleStringDictionary*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
|
|
|
|
return MinidumpListAtLocationDescriptor<
|
|
|
|
|
MinidumpSimpleStringDictionaryListTraits>(file_contents, location);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 16:22:12 -04:00
|
|
|
|
template <>
|
|
|
|
|
const MinidumpAnnotationList*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<MinidumpAnnotationList>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
|
|
|
|
return MinidumpListAtLocationDescriptor<MinidumpAnnotationListObjectsTraits>(
|
|
|
|
|
file_contents, location);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 18:35:18 -04:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
const T* MinidumpCVPDBAtLocationDescriptor(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
|
|
|
|
const T* cv_pdb =
|
|
|
|
|
TMinidumpWritableAtLocationDescriptor<T>(file_contents, location);
|
|
|
|
|
if (!cv_pdb) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cv_pdb->signature != T::kSignature) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(cv_pdb->signature, T::kSignature);
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t string_length = location.DataSize - offsetof(T, pdb_name) - 1;
|
|
|
|
|
if (cv_pdb->pdb_name[string_length] != '\0') {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
|
EXPECT_EQ(cv_pdb->pdb_name[string_length], '\0');
|
2014-10-22 18:35:18 -04:00
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cv_pdb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
template <>
|
2019-04-17 22:01:50 -07:00
|
|
|
|
const CodeViewRecordPDB20*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<CodeViewRecordPDB20>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
2015-09-01 09:32:09 -07:00
|
|
|
|
return MinidumpCVPDBAtLocationDescriptor<CodeViewRecordPDB20>(file_contents,
|
|
|
|
|
location);
|
2014-10-22 18:35:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <>
|
2019-04-17 22:01:50 -07:00
|
|
|
|
const CodeViewRecordPDB70*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<CodeViewRecordPDB70>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
2015-09-01 09:32:09 -07:00
|
|
|
|
return MinidumpCVPDBAtLocationDescriptor<CodeViewRecordPDB70>(file_contents,
|
|
|
|
|
location);
|
2014-10-22 18:35:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 22:01:50 -07:00
|
|
|
|
template <>
|
|
|
|
|
const CodeViewRecordBuildID*
|
|
|
|
|
MinidumpWritableAtLocationDescriptor<CodeViewRecordBuildID>(
|
|
|
|
|
const std::string& file_contents,
|
|
|
|
|
const MINIDUMP_LOCATION_DESCRIPTOR& location) {
|
|
|
|
|
const CodeViewRecordBuildID* cv =
|
|
|
|
|
reinterpret_cast<const CodeViewRecordBuildID*>(
|
|
|
|
|
MinidumpWritableAtLocationDescriptorInternal(
|
|
|
|
|
file_contents,
|
|
|
|
|
location,
|
|
|
|
|
offsetof(CodeViewRecordBuildID, build_id),
|
|
|
|
|
true));
|
|
|
|
|
|
|
|
|
|
if (!cv) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cv->signature != CodeViewRecordBuildID::kSignature) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2014-11-07 09:44:09 -05:00
|
|
|
|
|
2019-04-17 22:01:50 -07:00
|
|
|
|
return cv;
|
2014-11-07 09:44:09 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 22:01:50 -07:00
|
|
|
|
TestUInt32MinidumpWritable::TestUInt32MinidumpWritable(uint32_t value)
|
|
|
|
|
: MinidumpWritable(), value_(value) {}
|
|
|
|
|
|
|
|
|
|
TestUInt32MinidumpWritable::~TestUInt32MinidumpWritable() {}
|
|
|
|
|
|
2014-11-07 09:44:09 -05:00
|
|
|
|
size_t TestUInt32MinidumpWritable::SizeOfObject() {
|
|
|
|
|
return sizeof(value_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestUInt32MinidumpWritable::WriteObject(FileWriterInterface* file_writer) {
|
|
|
|
|
return file_writer->Write(&value_, sizeof(value_));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 14:15:07 -04:00
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace crashpad
|