fuchsia: Capture from SP (+slop) to stack base, rather than entire stack

Stack mappings can be enormous for some processes dwarfing all other
data and making the .dmp useless. It isn't useful to capture beyond the
stack pointer, so grab only from the stack base to the stack pointer.

In the default config (safestack enabled), this isn't a major problem.
However, Chromium has safestack disabled, along with a large stack size,
so dumps with many threads become very large.

Bug: https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=6425
Bug: chromium:821951
Change-Id: Iebefc5fe43e3d1bc4d8b66c107d3ab8ae5b3f68b
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1758702
Commit-Queue: Scott Graham <scottmg@chromium.org>
Reviewed-by: Francois Rousseau <frousseau@google.com>
This commit is contained in:
Scott Graham 2019-08-19 10:15:58 -07:00 committed by Commit Bot
parent 6b5e30db28
commit efaebfc482
2 changed files with 17 additions and 2 deletions

View File

@ -61,8 +61,22 @@ void GetStackRegions(
<< "stack range is unexpectedly marked executable, continuing anyway";
}
// The stack covers [range_with_sp.base, range_with_sp.base +
// range_with_sp.size). The stack pointer (sp) can be anywhere in that range.
// It starts at the end of the range (range_with_sp.base + range_with_sp.size)
// and goes downwards until range_with_sp.base. Capture the part of the stack
// that is currently used: [sp, range_with_sp.base + range_with_sp.size).
// Capture up to kExtraCaptureSize additional bytes of stack, but only if
// present in the region that was already found.
constexpr uint64_t kExtraCaptureSize = 128;
const uint64_t start_address =
std::max(sp >= kExtraCaptureSize ? sp - kExtraCaptureSize : sp,
range_with_sp.base);
const size_t region_size =
range_with_sp.size - (start_address - range_with_sp.base);
stack_regions->push_back(
CheckedRange<zx_vaddr_t, size_t>(range_with_sp.base, range_with_sp.size));
CheckedRange<zx_vaddr_t, size_t>(start_address, region_size));
// TODO(scottmg): https://crashpad.chromium.org/bug/196, once the retrievable
// registers include FS and similar for ARM, retrieve the region for the

View File

@ -174,7 +174,8 @@ class ThreadsChildTest : public MultiprocessExec {
for (size_t i = 1; i < 6; ++i) {
ASSERT_GT(threads[i].stack_regions.size(), 0u);
EXPECT_EQ(threads[i].stack_regions[0].size(), i * 4096u);
EXPECT_GT(threads[i].stack_regions[0].size(), 0u);
EXPECT_LE(threads[i].stack_regions[0].size(), i * 4096u);
}
}