diff options
author | ted.mielczarek@gmail.com <ted.mielczarek@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2012-09-17 14:01:28 +0000 |
---|---|---|
committer | ted.mielczarek@gmail.com <ted.mielczarek@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2012-09-17 14:01:28 +0000 |
commit | 52935b4e812f413beaf294b24e5677c0324f98b6 (patch) | |
tree | 69bafaa55473940b8568f001ea068fde445a5452 /src/processor | |
parent | Make my_str_len/my_itos take uintmax_t (diff) | |
download | breakpad-52935b4e812f413beaf294b24e5677c0324f98b6.tar.xz |
Add a GetInstructionPointer method to MinidumpException
R=mark at https://breakpad.appspot.com/444003/
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1039 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/processor')
-rw-r--r-- | src/processor/minidump.cc | 35 | ||||
-rw-r--r-- | src/processor/minidump_unittest.cc | 10 |
2 files changed, 43 insertions, 2 deletions
diff --git a/src/processor/minidump.cc b/src/processor/minidump.cc index d88101f6..19ba0354 100644 --- a/src/processor/minidump.cc +++ b/src/processor/minidump.cc @@ -714,6 +714,41 @@ u_int32_t MinidumpContext::GetContextCPU() const { return context_flags_ & MD_CONTEXT_CPU_MASK; } +bool MinidumpContext::GetInstructionPointer(u_int64_t* ip) const { + BPLOG_IF(ERROR, !ip) << "MinidumpContext::GetInstructionPointer " + "requires |ip|"; + assert(ip); + *ip = 0; + + if (!valid_) { + BPLOG(ERROR) << "Invalid MinidumpContext for GetInstructionPointer"; + return false; + } + + switch (context_flags_ & MD_CONTEXT_CPU_MASK) { + case MD_CONTEXT_AMD64: + *ip = context_.amd64->rip; + break; + case MD_CONTEXT_ARM: + *ip = context_.arm->iregs[MD_CONTEXT_ARM_REG_PC]; + break; + case MD_CONTEXT_PPC: + *ip = context_.ppc->srr0; + break; + case MD_CONTEXT_SPARC: + *ip = context_.ctx_sparc->pc; + break; + case MD_CONTEXT_X86: + *ip = context_.x86->eip; + break; + default: + // This should never happen. + BPLOG(ERROR) << "Unknown CPU architecture in GetInstructionPointer"; + return false; + } + return true; +} + const MDRawContextX86* MinidumpContext::GetContextX86() const { if (GetContextCPU() != MD_CONTEXT_X86) { diff --git a/src/processor/minidump_unittest.cc b/src/processor/minidump_unittest.cc index ce142300..60cb37a6 100644 --- a/src/processor/minidump_unittest.cc +++ b/src/processor/minidump_unittest.cc @@ -213,6 +213,7 @@ TEST(Dump, OneThread) { stack.Append("stack for thread"); MDRawContextX86 raw_context; + const u_int32_t kExpectedEIP = 0x6913f540; raw_context.context_flags = MD_CONTEXT_X86_INTEGER | MD_CONTEXT_X86_CONTROL; raw_context.edi = 0x3ecba80d; raw_context.esi = 0x382583b9; @@ -221,7 +222,7 @@ TEST(Dump, OneThread) { raw_context.ecx = 0x46a6a6a8; raw_context.eax = 0x6a5025e2; raw_context.ebp = 0xd9fabb4a; - raw_context.eip = 0x6913f540; + raw_context.eip = kExpectedEIP; raw_context.cs = 0xbffe6eda; raw_context.eflags = 0xb2ce1e2d; raw_context.esp = 0x659caaa4; @@ -273,6 +274,11 @@ TEST(Dump, OneThread) { MinidumpContext *md_context = md_thread->GetContext(); ASSERT_TRUE(md_context != NULL); ASSERT_EQ((u_int32_t) MD_CONTEXT_X86, md_context->GetContextCPU()); + + u_int64_t eip; + ASSERT_TRUE(md_context->GetInstructionPointer(&eip)); + EXPECT_EQ(kExpectedEIP, eip); + const MDRawContextX86 *md_raw_context = md_context->GetContextX86(); ASSERT_TRUE(md_raw_context != NULL); ASSERT_EQ((u_int32_t) (MD_CONTEXT_X86_INTEGER | MD_CONTEXT_X86_CONTROL), @@ -285,7 +291,7 @@ TEST(Dump, OneThread) { EXPECT_EQ(0x46a6a6a8U, raw_context.ecx); EXPECT_EQ(0x6a5025e2U, raw_context.eax); EXPECT_EQ(0xd9fabb4aU, raw_context.ebp); - EXPECT_EQ(0x6913f540U, raw_context.eip); + EXPECT_EQ(kExpectedEIP, raw_context.eip); EXPECT_EQ(0xbffe6edaU, raw_context.cs); EXPECT_EQ(0xb2ce1e2dU, raw_context.eflags); EXPECT_EQ(0x659caaa4U, raw_context.esp); |