From faed21a2862529b4ebead8cf178427b56fcacdca Mon Sep 17 00:00:00 2001 From: Joshua Peraza Date: Tue, 18 Feb 2020 11:05:15 -0800 Subject: [PATCH] linux: Log register sizes on mismatch Bug:1051354 Change-Id: Ia7731a87420e61756b61d109f9c69970ec27c6cb Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2062776 Reviewed-by: Mark Mentovai --- util/linux/ptracer.cc | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/util/linux/ptracer.cc b/util/linux/ptracer.cc index c6c92299..557e0d36 100644 --- a/util/linux/ptracer.cc +++ b/util/linux/ptracer.cc @@ -44,7 +44,8 @@ bool GetRegisterSet(pid_t tid, int set, Destination* dest, bool can_log) { return false; } if (iov.iov_len != sizeof(*dest)) { - LOG_IF(ERROR, can_log) << "Unexpected registers size"; + LOG_IF(ERROR, can_log) << "Unexpected registers size " << iov.iov_len + << " != " << sizeof(*dest); return false; } return true; @@ -176,7 +177,8 @@ bool GetFloatingPointRegisters32(pid_t tid, } } else { if (iov.iov_len != sizeof(context->f32.fpregs)) { - LOG_IF(ERROR, can_log) << "Unexpected registers size"; + LOG_IF(ERROR, can_log) << "Unexpected registers size " << iov.iov_len + << " != " << sizeof(context->f32.fpregs); return false; } context->f32.have_fpregs = true; @@ -197,7 +199,8 @@ bool GetFloatingPointRegisters32(pid_t tid, } } else { if (iov.iov_len != kArmVfpSize && iov.iov_len != sizeof(context->f32.vfp)) { - LOG_IF(ERROR, can_log) << "Unexpected registers size"; + LOG_IF(ERROR, can_log) << "Unexpected registers size " << iov.iov_len + << " != " << sizeof(context->f32.vfp); return false; } context->f32.have_vfp = true; @@ -223,7 +226,8 @@ bool GetFloatingPointRegisters64(pid_t tid, return false; } if (iov.iov_len != sizeof(context->f64)) { - LOG_IF(ERROR, can_log) << "Unexpected registers size"; + LOG_IF(ERROR, can_log) << "Unexpected registers size " << iov.iov_len + << " != " << sizeof(context->f64); return false; } return true; @@ -425,9 +429,10 @@ size_t GetGeneralPurposeRegistersAndLength(pid_t tid, bool GetGeneralPurposeRegisters32(pid_t tid, ThreadContext* context, bool can_log) { - if (GetGeneralPurposeRegistersAndLength(tid, context, can_log) != - sizeof(context->t32)) { - LOG_IF(ERROR, can_log) << "Unexpected registers size"; + size_t length = GetGeneralPurposeRegistersAndLength(tid, context, can_log); + if (length != sizeof(context->t32)) { + LOG_IF(ERROR, can_log) << "Unexpected registers size " << length + << " != " << sizeof(context->t32); return false; } return true; @@ -436,9 +441,10 @@ bool GetGeneralPurposeRegisters32(pid_t tid, bool GetGeneralPurposeRegisters64(pid_t tid, ThreadContext* context, bool can_log) { - if (GetGeneralPurposeRegistersAndLength(tid, context, can_log) != - sizeof(context->t64)) { - LOG_IF(ERROR, can_log) << "Unexpected registers size"; + size_t length = GetGeneralPurposeRegistersAndLength(tid, context, can_log); + if (length != sizeof(context->t64)) { + LOG_IF(ERROR, can_log) << "Unexpected registers size " << length + << " != " << sizeof(context->t64); return false; } return true; @@ -467,7 +473,9 @@ bool Ptracer::Initialize(pid_t pid) { } else if (length == sizeof(context.t32)) { is_64_bit_ = false; } else { - LOG_IF(ERROR, can_log_) << "Unexpected registers size"; + LOG_IF(ERROR, can_log_) + << "Unexpected registers size " << length + << " != " << sizeof(context.t64) << ", " << sizeof(context.t32); return false; }