Re: [Lldb-commits] [PATCH] D14591: Implement register context for mini dump debugging
This revision was automatically updated to reflect the committed changes. amccarth marked an inline comment as done. Closed by commit rL252950: Implement RegisterContext for Mini Dumps. (authored by amccarth). Changed prior to commit: http://reviews.llvm.org/D14591?vs=39978&id=40082#toc Repository: rL LLVM http://reviews.llvm.org/D14591 Files: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py lldb/trunk/source/Plugins/Process/Windows/Common/RegisterContextWindows.h lldb/trunk/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp lldb/trunk/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.h lldb/trunk/source/Plugins/Process/Windows/Live/x86/RegisterContextWindowsLive_x86.cpp lldb/trunk/source/Plugins/Process/Windows/Live/x86/RegisterContextWindowsLive_x86.h lldb/trunk/source/Plugins/Process/Windows/MiniDump/CMakeLists.txt lldb/trunk/source/Plugins/Process/Windows/MiniDump/ProcessWinMiniDump.cpp lldb/trunk/source/Plugins/Process/Windows/MiniDump/RegisterContextWindowsMiniDump.cpp lldb/trunk/source/Plugins/Process/Windows/MiniDump/RegisterContextWindowsMiniDump.h lldb/trunk/source/Plugins/Process/Windows/MiniDump/ThreadWinMiniDump.cpp lldb/trunk/source/Plugins/Process/Windows/MiniDump/ThreadWinMiniDump.h lldb/trunk/source/Plugins/Process/Windows/MiniDump/x64/RegisterContextWindowsMiniDump_x64.cpp lldb/trunk/source/Plugins/Process/Windows/MiniDump/x64/RegisterContextWindowsMiniDump_x64.h lldb/trunk/source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.cpp lldb/trunk/source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.h Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py === --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py @@ -32,6 +32,20 @@ stop_description = thread.GetStopDescription(256); self.assertTrue("0xc005" in stop_description); +@no_debug_info_test +def test_stack_info_in_mini_dump(self): +"""Test that we can see the stack.""" +self.assertEqual(self.process.GetNumThreads(), 1) +thread = self.process.GetThreadAtIndex(0) +# The crash is in main, so there should be one frame on the stack. +self.assertEqual(thread.GetNumFrames(), 1) +frame = thread.GetFrameAtIndex(0) +self.assertTrue(frame.IsValid()) +pc = frame.GetPC() +eip = frame.FindRegister("pc") +self.assertTrue(eip.IsValid()) +self.assertEqual(pc, eip.GetValueAsUnsigned()) + def setUp(self): # Call super's setUp(). TestBase.setUp(self) Index: lldb/trunk/source/Plugins/Process/Windows/Common/RegisterContextWindows.h === --- lldb/trunk/source/Plugins/Process/Windows/Common/RegisterContextWindows.h +++ lldb/trunk/source/Plugins/Process/Windows/Common/RegisterContextWindows.h @@ -60,8 +60,6 @@ virtual bool CacheAllRegisterValues(); CONTEXT m_context; - - private: bool m_context_stale; }; } Index: lldb/trunk/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp === --- lldb/trunk/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp +++ lldb/trunk/source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp @@ -121,3 +121,58 @@ return &g_register_sets[reg_set]; } +bool +RegisterContextWindows_x86::ReadRegister(const RegisterInfo *reg_info, RegisterValue ®_value) +{ +if (!CacheAllRegisterValues()) +return false; + +uint32_t reg = reg_info->kinds[eRegisterKindLLDB]; +switch (reg) +{ +case lldb_eax_i386: +WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Read value 0x%x from EAX", m_context.Eax); +reg_value.SetUInt32(m_context.Eax); +break; +case lldb_ebx_i386: +WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Read value 0x%x from EBX", m_context.Ebx); +reg_value.SetUInt32(m_context.Ebx); +break; +case lldb_ecx_i386: +WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Read value 0x%x from ECX", m_context.Ecx); +reg_value.SetUInt32(m_context.Ecx); +break; +case lldb_edx_i386: +WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Read value 0x%x from EDX", m_context.Edx); +reg_value.SetUInt32(m_context.Edx); +break; +case lldb_edi_i386: +WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Read value 0x%x from EDI", m_context.Edi); +reg_value.SetUInt32(m_context.Edi); +break; +case lldb_esi_i386: +
Re: [Lldb-commits] [PATCH] D14591: Implement register context for mini dump debugging
amccarth marked 3 inline comments as done. Comment at: packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py:40 @@ +39,3 @@ +thread = self.process.GetThreadAtIndex(0) +# The crash is in main, so there should be one frame on the stack. +self.assertEqual(thread.GetNumFrames(), 1) zturner wrote: > I remember us being able to get call stacks higher than main. But now that I > think about it I guess that's only true for live debugging since you have a > physical copy of the module loaded in your process, and you can read it's > EAT. In any case, this assumption probably won't be true anymore once we > understand PDBs and symbol servers. Although at that point hopefully we'll > have many more tests covering different scenarios. Yes, I recognize that this will need to change when we have more debug info available. but it's sufficient for testing at this point. Comment at: packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py:45 @@ +44,3 @@ +pc = frame.GetPC() +eip = frame.FindRegister("eip") +self.assertTrue(eip.IsValid()) zturner wrote: > Does this work if you change `eip` to `pc`? If so that would allow this test > to work in the presence of 64 bit. Indeed, "pc" works, so I'll use that. Comment at: source/Plugins/Process/Windows/MiniDump/ThreadWinMiniDump.h:42-44 @@ -44,4 +41,5 @@ protected: -std::string m_thread_name; lldb::RegisterContextSP m_reg_context_sp; +class Data; +std::unique_ptr m_data; // for WinAPI-specific data zturner wrote: > Why does this class need a separate `CONTEXT` than the one that is already > stored in `m_reg_context_sp`? It seems like now we're storing the `CONTEXT` > twice. Because the register context isn't created right away. It's lazily created later by this object, so this object needs a handle to it. Note that the CONTEXT in the Data is just a pointer, so it's not actually a second copy. The process object pulls the original CONTEXT from the mini dump, and it creates this thread object. This thread object will later be called to create the register context object, so it has to keep track of the CONTEXT in order to do that. http://reviews.llvm.org/D14591 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
Re: [Lldb-commits] [PATCH] D14591: Implement register context for mini dump debugging
zturner added inline comments. Comment at: packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py:40 @@ +39,3 @@ +thread = self.process.GetThreadAtIndex(0) +# The crash is in main, so there should be one frame on the stack. +self.assertEqual(thread.GetNumFrames(), 1) I remember us being able to get call stacks higher than main. But now that I think about it I guess that's only true for live debugging since you have a physical copy of the module loaded in your process, and you can read it's EAT. In any case, this assumption probably won't be true anymore once we understand PDBs and symbol servers. Although at that point hopefully we'll have many more tests covering different scenarios. Comment at: packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py:45 @@ +44,3 @@ +pc = frame.GetPC() +eip = frame.FindRegister("eip") +self.assertTrue(eip.IsValid()) Does this work if you change `eip` to `pc`? If so that would allow this test to work in the presence of 64 bit. Comment at: source/Plugins/Process/Windows/MiniDump/ProcessWinMiniDump.cpp:193 @@ +192,3 @@ +const auto &mini_dump_thread = thread_list_ptr->Threads[i]; +std::shared_ptr thread_sp(new ThreadWinMiniDump(*this, mini_dump_thread.ThreadId)); +if (mini_dump_thread.ThreadContext.DataSize >= sizeof(CONTEXT)) Can you change this to auto thread_sp = llvm::make_shared(*this, mini_dump_thread.ThreadId); Comment at: source/Plugins/Process/Windows/MiniDump/ThreadWinMiniDump.h:42-44 @@ -44,4 +41,5 @@ protected: -std::string m_thread_name; lldb::RegisterContextSP m_reg_context_sp; +class Data; +std::unique_ptr m_data; // for WinAPI-specific data Why does this class need a separate `CONTEXT` than the one that is already stored in `m_reg_context_sp`? It seems like now we're storing the `CONTEXT` twice. Comment at: source/Plugins/Process/Windows/MiniDump/x64/RegisterContextWindowsMiniDump_x64.h:14 @@ +13,3 @@ +#include "lldb/lldb-forward.h" +#include "../../Common/x64/RegisterContextWindows_x64.h" + Instead of using relative paths, I think you can write this as #include "Plugins/Process/Windows/Common/x64/RegisterContextWindows_x64.h" http://reviews.llvm.org/D14591 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D14591: Implement register context for mini dump debugging
amccarth created this revision. amccarth added a reviewer: zturner. amccarth added a subscriber: lldb-commits. The old RegisterContextWinMiniDump stub is replaced with x86 and x64 implementations that derive from the common windows register contexts. ProcessWindowsMiniDump grabs the WinAPI CONTEXT for each thread and stashes it in the thread object when building the thread list. The threads create the register context, stuffing in the saved CONTEXT. New test ensures we can see the stack and registers for the (single) frame in the fizzbuzz minidump. (No variables or function names, since that inferior doesn't have DWARF information.) You might also notice that I remove the thread names for MiniDump threads. Thread names are unavailable when port-mortem debugging Windows apps (since naming the thread requires having the debugger catch a special exception raised while the inferior is running). http://reviews.llvm.org/D14591 Files: packages/Python/lldbsuite/test/functionalities/postmortem/minidump/TestMiniDump.py source/Plugins/Process/Windows/Common/RegisterContextWindows.h source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.h source/Plugins/Process/Windows/Live/x86/RegisterContextWindowsLive_x86.cpp source/Plugins/Process/Windows/Live/x86/RegisterContextWindowsLive_x86.h source/Plugins/Process/Windows/MiniDump/CMakeLists.txt source/Plugins/Process/Windows/MiniDump/ProcessWinMiniDump.cpp source/Plugins/Process/Windows/MiniDump/RegisterContextWindowsMiniDump.cpp source/Plugins/Process/Windows/MiniDump/RegisterContextWindowsMiniDump.h source/Plugins/Process/Windows/MiniDump/ThreadWinMiniDump.cpp source/Plugins/Process/Windows/MiniDump/ThreadWinMiniDump.h source/Plugins/Process/Windows/MiniDump/x64/RegisterContextWindowsMiniDump_x64.cpp source/Plugins/Process/Windows/MiniDump/x64/RegisterContextWindowsMiniDump_x64.h source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.cpp source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.h Index: source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.h === --- /dev/null +++ source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.h @@ -0,0 +1,36 @@ +//===-- RegisterContextWindowsMiniDump_x86.h *- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#ifndef liblldb_RegisterContextWindowsMiniDump_x86_H_ +#define liblldb_RegisterContextWindowsMiniDump_x86_H_ + +#include "lldb/lldb-forward.h" +#include "../../Common/x86/RegisterContextWindows_x86.h" + +namespace lldb_private +{ + +class Thread; + +class RegisterContextWindowsMiniDump_x86 : public RegisterContextWindows_x86 +{ + public: +RegisterContextWindowsMiniDump_x86(Thread &thread, uint32_t concrete_frame_idx, const CONTEXT *context); + +virtual ~RegisterContextWindowsMiniDump_x86(); + +bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue ®_value) override; + + protected: +bool CacheAllRegisterValues() override; +}; + +} + +#endif // #ifndef liblldb_RegisterContextWindowsMiniDump_x86_H_ Index: source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.cpp === --- /dev/null +++ source/Plugins/Process/Windows/MiniDump/x86/RegisterContextWindowsMiniDump_x86.cpp @@ -0,0 +1,47 @@ +//===-- RegisterContextWindowsMiniDump_x86.cpp --*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "lldb/lldb-private-types.h" +#include "lldb/Host/windows/windows.h" + +#include "RegisterContextWindowsMiniDump_x86.h" + +using namespace lldb; + +namespace lldb_private +{ + +RegisterContextWindowsMiniDump_x86::RegisterContextWindowsMiniDump_x86(Thread &thread, uint32_t concrete_frame_idx, const CONTEXT *context) +: RegisterContextWindows_x86(thread, concrete_frame_idx) +{ +if (context) +{ +m_context = *context; +m_context_stale = false; +} +} + +RegisterContextWindowsMiniDump_x86::~RegisterContextWindowsMiniDump_x86() +{ +} + +bool +RegisterContextWindowsMiniDump_x86::WriteRegister(const RegisterInfo * /* reg_info */, const RegisterValue & /* reg_value */) +{ +return false; +} + +bool +RegisterContextWindowsMiniDump_x86::CacheAllRegisterValues() +{ +// Since this is post-mortem debugging, we e